List of usage examples for android.os FileObserver MOVED_TO
int MOVED_TO
To view the source code for android.os FileObserver MOVED_TO.
Click Source Link
From source file:com.nononsenseapps.filepicker.local.LocalFilePickerFragment.java
/** * Get a loader that lists the Files in the current path, * and monitors changes./*from w ww .j av a 2s . c o m*/ */ @Override protected Loader<List<FileSystemObjectInterface>> getLoader() { return new AsyncTaskLoader<List<FileSystemObjectInterface>>(getActivity()) { FileObserver fileObserver; @Override public List<FileSystemObjectInterface> loadInBackground() { ArrayList<FileSystemObjectInterface> files = new ArrayList<FileSystemObjectInterface>(); File[] listFiles = ((LocalFileSystemObject) currentPath).getFile().listFiles(); if (listFiles != null) { for (java.io.File f : listFiles) { if ((mode == SelectionMode.MODE_FILE || mode == SelectionMode.MODE_FILE_AND_DIR) || f.isDirectory()) { LocalFileSystemObject obj = new LocalFileSystemObject(f); files.add(obj); } } } return files; } /** * Handles a request to start the Loader. */ @Override protected void onStartLoading() { super.onStartLoading(); // handle if directory does not exist. Fall back to root. if (currentPath == null || !currentPath.isDir()) { currentPath = getRoot(); } // Start watching for changes fileObserver = new FileObserver(currentPath.getFullPath(), FileObserver.CREATE | FileObserver.DELETE | FileObserver.MOVED_FROM | FileObserver.MOVED_TO) { @Override public void onEvent(int event, String path) { // Reload onContentChanged(); } }; fileObserver.startWatching(); forceLoad(); } /** * Handles a request to completely reset the Loader. */ @Override protected void onReset() { super.onReset(); // Stop watching if (fileObserver != null) { fileObserver.stopWatching(); fileObserver = null; } } }; }
From source file:org.arakhne.afc.ui.android.filechooser.AsyncFileLoader.java
/** * {@inheritDoc}//w w w . j a v a 2s.c o m */ @Override protected void onStartLoading() { // A list is already available. Publish it. if (this.discoveredFiles != null) deliverResult(this.discoveredFiles); if (this.fileObserver == null) { this.fileObserver = new FileObserver(this.path.getAbsolutePath(), FileObserver.CREATE | FileObserver.DELETE | FileObserver.DELETE_SELF | FileObserver.MOVED_FROM | FileObserver.MOVED_TO | FileObserver.MODIFY | FileObserver.MOVE_SELF) { @Override public void onEvent(int event, String path) { onContentChanged(); } }; } this.fileObserver.startWatching(); if (takeContentChanged() || this.discoveredFiles == null) forceLoad(); }
From source file:org.ado.minesync.minecraft.MinecraftWorldObserver.java
private String getFileAction(int event) { String fileAction = null;/*from w ww .ja v a 2s. com*/ switch (event) { case FileObserver.ACCESS: fileAction = "ACCESS"; break; case FileObserver.ALL_EVENTS: fileAction = "ALL_EVENTS"; break; case FileObserver.ATTRIB: fileAction = "ATTRIB"; break; case FileObserver.CLOSE_NOWRITE: fileAction = "CLOSE_NOWRITE"; break; case FileObserver.CLOSE_WRITE: fileAction = "CLOSE_WRITE"; break; case FileObserver.CREATE: fileAction = "CREATE"; break; case FileObserver.DELETE: fileAction = "DELETE"; break; case FileObserver.DELETE_SELF: fileAction = "DELETE_SELF"; break; case FileObserver.MODIFY: fileAction = "MODIFY"; break; case FileObserver.MOVE_SELF: fileAction = "MOVE_SELF"; break; case FileObserver.MOVED_FROM: fileAction = "MOVED_FROM"; break; case FileObserver.MOVED_TO: fileAction = "MOVED_TO"; break; case FileObserver.OPEN: fileAction = "OPEN"; break; } return fileAction; }
From source file:com.owncloud.android.services.observer.InstantUploadsObserver.java
/** * Receives and processes events about updates of the monitored folder. * * This is almost heuristic. Do no expect it works magically with any camera. * * For instance, Google Camera creates a new video file when the user enters in "video mode", before * start to record, and saves it empty if the user leaves recording nothing. True store. Life is magic. * * @param event Kind of event occurred. * @param path Relative path of the file referred by the event. *///from ww w.java 2 s . c o m @Override public void onEvent(int event, String path) { Log_OC.d(TAG, "Got event " + event + " on FOLDER " + mConfiguration.getSourcePath() + " about " + ((path != null) ? path : "") + " (in thread '" + Thread.currentThread().getName() + "')"); if (path != null && path.length() > 0) { synchronized (mLock) { if ((event & FileObserver.CREATE) != 0) { // new file created, let's watch it; false -> not modified yet mObservedChildren.put(path, false); } if (((event & FileObserver.MODIFY) != 0) && mObservedChildren.containsKey(path) && !mObservedChildren.get(path)) { // watched file was written for the first time after creation mObservedChildren.put(path, true); } if ((event & FileObserver.CLOSE_WRITE) != 0 && mObservedChildren.containsKey(path) && mObservedChildren.get(path)) { // a file that was previously created and written has been closed; // testing for FileObserver.MODIFY is needed because some apps // close the video file right after creating it when the recording // is started, and reopen it to write with the first chunk of video // to save; for instance, Camera MX does so. mObservedChildren.remove(path); handleNewFile(path); } if ((event & FileObserver.MOVED_TO) != 0) { // a file has been moved or renamed into the folder; // for instance, Google Camera does so right after // saving a video recording handleNewFile(path); } } } if ((event & IN_IGNORE) != 0 && (path == null || path.length() == 0)) { Log_OC.d(TAG, "Stopping the observance on " + mConfiguration.getSourcePath()); } }
From source file:com.glasshack.checkmymath.CheckMyMath.java
private void processPictureWhenReady(final String picturePath) { final File pictureFile = new File(picturePath); if (pictureFile.exists()) { // The picture is ready; process it. Log.e("Picture Path", picturePath); List<NameValuePair> postData = new ArrayList<NameValuePair>(); postData.add(new BasicNameValuePair("file", picturePath)); postData.add(new BasicNameValuePair("answer", "1")); postData.add(new BasicNameValuePair("submit", "Submit")); String postResp = post("http://54.187.58.53/glassmath.php", postData); evaluateResponse(postResp);//ww w .j a v a 2 s. c o m } else { // The file does not exist yet. Before starting the file observer, you // can update your UI to let the user know that the application is // waiting for the picture (for example, by displaying the thumbnail // image and a progress indicator). final File parentDirectory = pictureFile.getParentFile(); FileObserver observer = new FileObserver(parentDirectory.getPath(), FileObserver.CLOSE_WRITE | FileObserver.MOVED_TO) { // Protect against additional pending events after CLOSE_WRITE // or MOVED_TO is handled. private boolean isFileWritten; @Override public void onEvent(int event, String path) { if (!isFileWritten) { // For safety, make sure that the file that was created in // the directory is actually the one that we're expecting. File affectedFile = new File(parentDirectory, path); isFileWritten = affectedFile.equals(pictureFile); if (isFileWritten) { stopWatching(); // Now that the file is ready, recursively call // processPictureWhenReady again (on the UI thread). runOnUiThread(new Runnable() { @Override public void run() { processPictureWhenReady(picturePath); } }); } } } }; observer.startWatching(); } }
From source file:com.ihelp101.instagram.FilePickerFragment.java
/** * Get a loader that lists the Files in the current path, * and monitors changes./*from w w w .java2 s .c o m*/ */ @Override public Loader<SortedList<File>> getLoader() { return new AsyncTaskLoader<SortedList<File>>(getActivity()) { FileObserver fileObserver; @Override public SortedList<File> loadInBackground() { File[] listFiles = mCurrentPath.listFiles(); final int initCap = listFiles == null ? 0 : listFiles.length; SortedList<File> files = new SortedList<>(File.class, new SortedListAdapterCallback<File>(getDummyAdapter()) { @Override public int compare(File lhs, File rhs) { return compareFiles(lhs, rhs); } @Override public boolean areContentsTheSame(File file, File file2) { return file.getAbsolutePath().equals(file2.getAbsolutePath()) && (file.isFile() == file2.isFile()); } @Override public boolean areItemsTheSame(File file, File file2) { return areContentsTheSame(file, file2); } }, initCap); files.beginBatchedUpdates(); if (listFiles != null) { for (File f : listFiles) { if (isItemVisible(f)) { files.add(f); } } } files.endBatchedUpdates(); return files; } /** * Handles a request to start the Loader. */ @Override protected void onStartLoading() { super.onStartLoading(); // handle if directory does not exist. Fall back to root. if (mCurrentPath == null || !mCurrentPath.isDirectory()) { mCurrentPath = getRoot(); } // Start watching for changes fileObserver = new FileObserver(mCurrentPath.getPath(), FileObserver.CREATE | FileObserver.DELETE | FileObserver.MOVED_FROM | FileObserver.MOVED_TO) { @Override public void onEvent(int event, String path) { // Reload onContentChanged(); } }; fileObserver.startWatching(); forceLoad(); } /** * Handles a request to completely reset the Loader. */ @Override protected void onReset() { super.onReset(); // Stop watching if (fileObserver != null) { fileObserver.stopWatching(); fileObserver = null; } } }; }
From source file:com.home.young.filepicker.FilePickerFragment.java
/** * Get a loader that lists the Files in the current path, * and monitors changes.//from w w w. j a v a 2 s . c om */ @NonNull @Override public Loader<SortedList<File>> getLoader() { return new AsyncTaskLoader<SortedList<File>>(getActivity()) { FileObserver fileObserver; @Override public SortedList<File> loadInBackground() { File[] listFiles = mCurrentPath.listFiles(); final int initCap = listFiles == null ? 0 : listFiles.length; SortedList<File> files = new SortedList<>(File.class, new SortedListAdapterCallback<File>(getDummyAdapter()) { @Override public int compare(File lhs, File rhs) { return compareFiles(lhs, rhs); } @Override public boolean areContentsTheSame(File file, File file2) { return file.getAbsolutePath().equals(file2.getAbsolutePath()) && (file.isFile() == file2.isFile()); } @Override public boolean areItemsTheSame(File file, File file2) { return areContentsTheSame(file, file2); } }, initCap); files.beginBatchedUpdates(); if (listFiles != null) { for (java.io.File f : listFiles) { if (isItemVisible(f)) { files.add(f); } } } files.endBatchedUpdates(); return files; } /** * Handles a request to start the Loader. */ @Override protected void onStartLoading() { super.onStartLoading(); // handle if directory does not exist. Fall back to root. if (mCurrentPath == null || !mCurrentPath.isDirectory()) { mCurrentPath = getRoot(); } // Start watching for changes fileObserver = new FileObserver(mCurrentPath.getPath(), FileObserver.CREATE | FileObserver.DELETE | FileObserver.MOVED_FROM | FileObserver.MOVED_TO) { @Override public void onEvent(int event, String path) { // Reload onContentChanged(); } }; fileObserver.startWatching(); forceLoad(); } /** * Handles a request to completely reset the Loader. */ @Override protected void onReset() { super.onReset(); // Stop watching if (fileObserver != null) { fileObserver.stopWatching(); fileObserver = null; } } }; }
From source file:cn.tycoon.lighttrans.fileManager.FilePickerFragment.java
/** * Get a loader that lists the Files in the current path, * and monitors changes.// w w w. ja v a2 s. c o m */ @Override public Loader<SortedList<File>> getLoader() { return new AsyncTaskLoader<SortedList<File>>(getActivity()) { FileObserver fileObserver; @Override public SortedList<File> loadInBackground() { File[] listFiles = mCurrentPath.listFiles(); final int initCap = listFiles == null ? 0 : listFiles.length; SortedList<File> files = new SortedList<>(File.class, new SortedListAdapterCallback<File>(getDummyAdapter()) { @Override public int compare(File lhs, File rhs) { return compareFiles(lhs, rhs); } @Override public boolean areContentsTheSame(File file, File file2) { return file.getAbsolutePath().equals(file2.getAbsolutePath()) && (file.isFile() == file2.isFile()); } @Override public boolean areItemsTheSame(File file, File file2) { return areContentsTheSame(file, file2); } }, initCap); files.beginBatchedUpdates(); if (listFiles != null) { for (java.io.File f : listFiles) { //if (isItemVisible(f)) { files.add(f); //} } } files.endBatchedUpdates(); return files; } /** * Handles a request to start the Loader. */ @Override protected void onStartLoading() { super.onStartLoading(); // handle if directory does not exist. Fall back to root. if (mCurrentPath == null || !mCurrentPath.isDirectory()) { mCurrentPath = getRoot(); } // Start watching for changes fileObserver = new FileObserver(mCurrentPath.getPath(), FileObserver.CREATE | FileObserver.DELETE | FileObserver.MOVED_FROM | FileObserver.MOVED_TO) { @Override public void onEvent(int event, String path) { // Reload onContentChanged(); } }; fileObserver.startWatching(); forceLoad(); } /** * Handles a request to completely reset the Loader. */ @Override protected void onReset() { super.onReset(); // Stop watching if (fileObserver != null) { fileObserver.stopWatching(); fileObserver = null; } } }; }
From source file:com.lovejoy777sarootool.rootool.fragments.BrowserFragment.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(path)); break;// w ww . j a v a2s . c o m } }