Java Code Examples for android.os.FileObserver#MOVED_TO

The following examples show how to use android.os.FileObserver#MOVED_TO . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ControlObserver.java    From ClashForMagisk with GNU General Public License v3.0 6 votes vote down vote up
private void restart() {
    //noinspection ResultOfMethodCallIgnored
    dataDir.mkdirs();

    fileObserver = new FileObserver(dataDir.getAbsolutePath(), FileObserver.CREATE | FileObserver.DELETE_SELF | FileObserver.MOVED_FROM | FileObserver.MOVED_TO) {
        @Override
        public void onEvent(int event, String file) {
            Log.d(Constants.TAG, "Control Directory Changed " + file);

            if ((event & FileObserver.DELETE_SELF) != 0) {
                restart();
            } else {
                file = file.toUpperCase();

                switch (file) {
                    case "STOP":
                    case "START":
                    case "RESTART":
                        callback.onUserControl(file);
                }
            }
        }
    };

    fileObserver.startWatching();
}
 
Example 2
Source File: PhonkServerService.java    From PHONK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onEvent(int event, String file) {
    MLog.d(TAG, "qq -> " + event);
    MLog.d(TAG, "qq2 -> " + file);

    if ((FileObserver.CREATE & event) != 0) {
        MLog.d(TAG, "File created [" + PhonkSettings.getBaseDir() + file + "]");
        EventBus.getDefault().postSticky(new Events.ProjectEvent(Events.PROJECT_REFRESH_LIST, null));
    } else if ((FileObserver.DELETE & event) != 0) {
        MLog.d(TAG, "File deleted [" + PhonkSettings.getBaseDir() + file + "]");
        EventBus.getDefault().postSticky(new Events.ProjectEvent(Events.PROJECT_REFRESH_LIST, null));
    } else if ((FileObserver.MOVED_FROM & event) != 0) {
        MLog.d(TAG, "File moved from [" + PhonkSettings.getBaseDir() + file + "]");
        EventBus.getDefault().postSticky(new Events.ProjectEvent(Events.PROJECT_REFRESH_LIST, null));
    } else if ((FileObserver.MOVED_TO & event) != 0) {
        MLog.d(TAG, "File moved to [" + PhonkSettings.getBaseDir() + file + "]");
        EventBus.getDefault().postSticky(new Events.ProjectEvent(Events.PROJECT_REFRESH_LIST, null));
    }
}
 
Example 3
Source File: MediaListenerService.java    From proofmode with GNU General Public License v3.0 6 votes vote down vote up
private void startWatching() {
    final String pathToWatch = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath();

    observer = new RecursiveFileObserver(pathToWatch, FileObserver.CLOSE_WRITE| FileObserver.MOVED_TO) { // set up a file observer to watch this directory on sd card
        @Override
        public void onEvent(int event, final String mediaPath) {
            if (mediaPath != null && (!mediaPath.equals(".probe"))) { // check that it's not equal to .probe because thats created every time camera is launched

                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {

                        if (mediaPath.endsWith(".mp4"))
                            handleNewVideo(mediaPath);
                    }
                });
            }
        }
    };
    observer.startWatching();


}
 
Example 4
Source File: AbstractBrowserFragment.java    From SimpleExplorer with GNU General Public License v3.0 6 votes vote down vote up
@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((AbstractBrowserActivity) getActivity(), path));
            break;
    }
}
 
Example 5
Source File: Enhancement.java    From EdXposedManager with GNU General Public License v3.0 5 votes vote down vote up
private static List<String> getModulesList(final int user) {
    final int index = modulesList.indexOfKey(user);
    if (index >= 0) {
        return modulesList.valueAt(index);
    }

    final String filename = String.format("/data/user_de/%s/%s/conf/enabled_modules.list", user, APPLICATION_ID);
    final FileObserver observer = new FileObserver(filename) {
        @Override
        public void onEvent(int event, @Nullable String path) {
            switch (event) {
                case FileObserver.MODIFY:
                    modulesList.put(user, readModulesList(filename));
                    break;
                case FileObserver.MOVED_FROM:
                case FileObserver.MOVED_TO:
                case FileObserver.MOVE_SELF:
                case FileObserver.DELETE:
                case FileObserver.DELETE_SELF:
                    modulesList.remove(user);
                    modulesListObservers.remove(user);
                    break;
            }
        }
    };
    modulesListObservers.put(user, observer);
    final List<String> list = readModulesList(filename);
    modulesList.put(user, list);
    observer.startWatching();
    return list;
}
 
Example 6
Source File: FolderObserver.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Receives and processes events about updates of the monitor folder and its children files.
 * 
 * @param event     Kind of event occurred.
 * @param path      Relative path of the file referred by the event.
 */
@Override
public void onEvent(int event, String path) {
    Log_OC.d(TAG, "Got event " + event + " on FOLDER " + mPath + " about "
            + ((path != null) ? path : ""));
    
    boolean shouldSynchronize = false;
    synchronized(mObservedChildren) {
        if (path != null && path.length() > 0 && mObservedChildren.containsKey(path)) {
            
            if (    ((event & FileObserver.MODIFY) != 0) ||
                    ((event & FileObserver.ATTRIB) != 0) ||
                    ((event & FileObserver.MOVED_TO) != 0) ) {
                
                if (!mObservedChildren.get(path)) {
                    mObservedChildren.put(path, Boolean.valueOf(true));
                }
            }
            
            if ((event & FileObserver.CLOSE_WRITE) != 0 && mObservedChildren.get(path)) {
                mObservedChildren.put(path, Boolean.valueOf(false));
                shouldSynchronize = true;
            }
        }
    }
    if (shouldSynchronize) {
        startSyncOperation(path);
    }
    
    if ((event & IN_IGNORE) != 0 &&
            (path == null || path.length() == 0)) {
        Log_OC.d(TAG, "Stopping the observance on " + mPath);
    }
    
}
 
Example 7
Source File: SettingsProvider.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public SettingsFileObserver(int userHandle, String path) {
    super(path, FileObserver.CLOSE_WRITE |
          FileObserver.CREATE | FileObserver.DELETE |
          FileObserver.MOVED_TO | FileObserver.MODIFY);
    mUserHandle = userHandle;
    mPath = path;
}
 
Example 8
Source File: FileSystemScanner.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
public static String toString(final int event) {
    switch (event) {
        case FileObserver.ACCESS:
            return "ACCESS";
        case FileObserver.MODIFY:
            return "MODIFY";
        case FileObserver.ATTRIB:
            return "ATTRIB";
        case FileObserver.CLOSE_WRITE:
            return "CLOSE_WRITE";
        case FileObserver.CLOSE_NOWRITE:
            return "CLOSE_NOWRITE";
        case FileObserver.OPEN:
            return "OPEN";
        case FileObserver.MOVED_FROM:
            return "MOVED_FROM";
        case FileObserver.MOVED_TO:
            return "MOVED_TO";
        case FileObserver.CREATE:
            return "CREATE";
        case FileObserver.DELETE:
            return "DELETE";
        case FileObserver.DELETE_SELF:
            return "DELETE_SELF";
        case FileObserver.MOVE_SELF:
            return "MOVE_SELF";
        default:
            return "0x" + Integer.toHexString(event);
    }
}
 
Example 9
Source File: Utils.java    From ploggy with GNU General Public License v3.0 5 votes vote down vote up
public FileInitializedObserver(File directory, String ... filenames) {
    // MOVED_TO is required for the Tor case where the Tor process creates <target>.tmp,
    // writes to that file, then renames to <target>. There's no CLOSE_WRITE event for <target>.
    super(
        directory.getAbsolutePath(),
        FileObserver.MOVED_TO | FileObserver.CLOSE_WRITE);
    mTargetFilenames = new ArrayList<String>(Arrays.asList(filenames));
    mLatch = new CountDownLatch(mTargetFilenames.size());
}
 
Example 10
Source File: MinidumpDirectoryObserver.java    From delion with Apache License 2.0 4 votes vote down vote up
public MinidumpDirectoryObserver() {
    // The file observer detects MOVED_TO for child processes.
    super(new File(PathUtils.getCacheDirectory(sContext),
            CrashFileManager.CRASH_DUMP_DIR).toString(), FileObserver.MOVED_TO);
}
 
Example 11
Source File: MinidumpDirectoryObserver.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
public MinidumpDirectoryObserver() {
    // The file observer detects MOVED_TO for child processes.
    super(new File(PathUtils.getCacheDirectory(),
            CrashFileManager.CRASH_DUMP_DIR).toString(), FileObserver.MOVED_TO);
}