List of usage examples for android.os FileObserver DELETE
int DELETE
To view the source code for android.os FileObserver DELETE.
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 ava 2 s . c om */ @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}//www . j a va 2 s. 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 ww w. j a va2 s. c om 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:org.protocoder.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forfragments); c = this;// w ww .j av a 2s . c o m // Create the action bar programmatically if (!isWear()) { Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar); setSupportActionBar(toolbar); //ActionBar actionBar = getSupportActionBar(); //actionBar.setHomeButtonEnabled(true); } mProtocoder = Protocoder.getInstance(this); mProtocoder.init(); /* * Views */ if (savedInstanceState == null) { addFragments(); } else { mProtocoder.protoScripts.reinitScriptList(); } // Check when a file is changed in the protocoder dir observer = new FileObserver(ProjectManager.FOLDER_USER_PROJECTS, FileObserver.CREATE | FileObserver.DELETE) { @Override public void onEvent(int event, String file) { if ((FileObserver.CREATE & event) != 0) { MLog.d(TAG, "File created [" + ProjectManager.FOLDER_USER_PROJECTS + "/" + file + "]"); // check if its a "create" and not equal to probe because // thats created every time camera is // launched } else if ((FileObserver.DELETE & event) != 0) { MLog.d(TAG, "File deleted [" + ProjectManager.FOLDER_USER_PROJECTS + "/" + file + "]"); } } }; connectivityChangeReceiver = new ConnectivityChangeReceiver(); }
From source file:com.ihelp101.instagram.FilePickerFragment.java
/** * Get a loader that lists the Files in the current path, * and monitors changes.// w w w. ja va 2 s .c om */ @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.// w w w .j a v a 2 s. c o m */ @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./*from ww w. j av a 2 s .c om*/ */ @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;//from ww w. ja v a 2s .co m } }
From source file:com.docd.purefm.adapters.BrowserBaseAdapter.java
/** * {@link android.os.FileObserver} event that should be ran only on UI thread * * @param event The type of event which happened * @param file The modified file, relative to the main monitored file or directory, * of the file or directory which triggered the event *///w w w . j a v a2s .c om void onEventUIThread(final int event, @NonNull final GenericFile file) { switch (event & FileObserver.ALL_EVENTS) { case FileObserver.CREATE: //Do nothing. The event is handled in Browser break; case FileObserver.DELETE: case FileObserver.DELETE_SELF: case FileObserver.MOVED_FROM: onFileDeleted(file); break; default: onFileModified(file); break; } }