Example usage for android.os FileObserver DELETE

List of usage examples for android.os FileObserver DELETE

Introduction

In this page you can find the example usage for android.os FileObserver DELETE.

Prototype

int DELETE

To view the source code for android.os FileObserver DELETE.

Click Source Link

Document

Event type: A file was deleted from the monitored directory

Usage

From source file:org.protocoderrunner.apprunner.api.PFileIO.java

@ProtoMethod(description = "Observer file changes in a folder", example = "")
@ProtoMethodParam(params = { "path", "function(action, file" })
public void observeFolder(String path, final FileObserverCB callback) {

    fileObserver = new FileObserver(
            ProjectManager.getInstance().getCurrentProject().getStoragePath() + "/" + path,
            FileObserver.CREATE | FileObserver.MODIFY | FileObserver.DELETE) {

        @Override/*from   www  .  ja  va2  s .  c  o m*/
        public void onEvent(int event, String file) {

            if ((FileObserver.CREATE & event) != 0) {
                callback.event("create", file);
            } else if ((FileObserver.DELETE & event) != 0) {
                callback.event("delete", file);
            } else if ((FileObserver.MODIFY & event) != 0) {
                callback.event("modify", file);
            }
        }

    };
    fileObserver.startWatching();
}

From source file:com.veniosg.dir.android.fragment.FileListFragment.java

private FileObserver generateFileObserver(String pathToObserve) {
    return new FileObserver(pathToObserve, FileObserver.CREATE | FileObserver.DELETE | FileObserver.CLOSE_WRITE // Removed since in case of continuous modification
                                                                                                                // (copy/compress) we would flood with events.
            | FileObserver.MOVED_FROM | FileObserver.MOVED_TO) {
        private static final long MIN_REFRESH_INTERVAL = 2 * 1000;

        private long lastUpdate = 0;

        @Override//from w  w w  .java  2s  .com
        public void onEvent(int event, String path) {
            if (System.currentTimeMillis() - lastUpdate <= MIN_REFRESH_INTERVAL || event == 32768) { // See https://code.google.com/p/android/issues/detail?id=29546
                return;
            }

            Logger.logV(Logger.TAG_OBSERVER, "Observed event " + event + ", refreshing list..");
            lastUpdate = System.currentTimeMillis();

            if (getActivity() != null) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        refresh();
                    }
                });
            }
        }
    };
}

From source file:com.dnielfe.manager.Browser.java

@Override
public void onEvent(int event, String path) {
    // this will automatically update the directory when an action like this
    // will be performed
    switch (event & FileObserver.ALL_EVENTS) {
    case FileObserver.CREATE:
    case FileObserver.CLOSE_WRITE:
    case FileObserver.MOVE_SELF:
    case FileObserver.MOVED_TO:
    case FileObserver.MOVED_FROM:
    case FileObserver.ATTRIB:
    case FileObserver.DELETE:
    case FileObserver.DELETE_SELF:
        sHandler.removeCallbacks(mLastRunnable);
        sHandler.post(mLastRunnable = new NavigateRunnable(mCurrentPath));
        break;//from ww  w.j  av a  2 s .  com
    }
}

From source file:com.alexlionne.apps.avatars.Utils.DirectoryChooserFragment.java

/**
 * Sets up a FileObserver to watch the current directory.
 *///from  w w  w.j ava 2 s  .c o  m
private FileObserver createFileObserver(String path) {
    return new FileObserver(path,
            FileObserver.CREATE | FileObserver.DELETE | FileObserver.MOVED_FROM | FileObserver.MOVED_TO) {

        @Override
        public void onEvent(int event, String path) {
            debug("FileObserver received event %d", event);
            final Activity activity = getActivity();

            if (activity != null) {
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        refreshDirectory();
                    }
                });
            }
        }
    };
}

From source file:com.andrada.sitracker.ui.fragment.DirectoryChooserFragment.java

/**
 * Sets up a FileObserver to watch the current directory.
 *//*from  w w w .j  a v  a 2 s.co  m*/
@NotNull
private FileObserver createFileObserver(String path) {
    return new FileObserver(path,
            FileObserver.CREATE | FileObserver.DELETE | FileObserver.MOVED_FROM | FileObserver.MOVED_TO) {

        @Override
        public void onEvent(int event, String path) {
            debug("FileObserver received event %d", event);
            final Activity activity = getActivity();

            if (activity != null) {
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        refreshDirectory();
                    }
                });
            }
        }
    };
}

From source file:org.protocoderrunner.apprunner.AppRunnerFragment.java

public void startFileObserver() {

    if (mIsProjectLoaded) {

        // set up mContext file observer to watch this directory on sd card
        fileObserver = new FileObserver(mCurrentProject.getStoragePath(),
                FileObserver.CREATE | FileObserver.DELETE) {

            @Override/*w  w  w.  j  a v  a  2  s  .co  m*/
            public void onEvent(int event, String file) {
                JSONObject msg = new JSONObject();
                String action = null;

                if ((FileObserver.CREATE & event) != 0) {
                    MLog.d(TAG, "created " + file);
                    action = "new_files_in_project";

                } else if ((FileObserver.DELETE & event) != 0) {
                    MLog.d(TAG, "deleted file " + file);
                    action = "deleted_files_in_project";
                }

                try {
                    msg.put("action", action);
                    msg.put("type", "ide");
                    IDEcommunication.getInstance(mActivity).send(msg);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        };
    }

}