Java Code Examples for android.os.FileObserver#DELETE

The following examples show how to use android.os.FileObserver#DELETE . 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: PlayListFragment.java    From Android-AudioRecorder-App with Apache License 2.0 6 votes vote down vote up
@Override public void onEvent(int event, String file) {
  if (event == FileObserver.DELETE) {
    // user deletes a recording file out of the app

    String filePath = android.os.Environment.getExternalStorageDirectory().toString()
        + "/SoundRecorder"
        + file
        + "]";

    Log.d(LOG_TAG, "File deleted ["
        + android.os.Environment.getExternalStorageDirectory().toString()
        + "/SoundRecorder"
        + file
        + "]");

    // remove file from database and recyclerview
    mPlayListAdapter.removeOutOfApp(filePath);
  }
}
 
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: PFileIO.java    From PHONK with GNU General Public License v3.0 6 votes vote down vote up
PFileObserver(AppRunner appRunner, String path) {
    fileObserver = new FileObserver(appRunner.getProject().getFullPathForFile(path), FileObserver.CREATE | FileObserver.MODIFY | FileObserver.DELETE) {

        @Override
        public void onEvent(int event, String file) {
            ReturnObject ret = new ReturnObject();
            if ((FileObserver.CREATE & event) != 0) {
                ret.put("action", "created");
            } else if ((FileObserver.DELETE & event) != 0) {
                ret.put("action", "deleted");
            } else if ((FileObserver.MODIFY & event) != 0) {
                ret.put("action", "modified");
            }
            ret.put("file", file);
            if (callback != null) callback.event(ret);
        }

    };
    fileObserver.startWatching();
    getAppRunner().whatIsRunning.add(this);
}
 
Example 4
Source File: FileViewerFragment.java    From SoundRecorder with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onEvent(int event, String file) {
    if(event == FileObserver.DELETE){
        // user deletes a recording file out of the app

        String filePath = android.os.Environment.getExternalStorageDirectory().toString()
                + "/SoundRecorder" + file + "]";

        Log.d(LOG_TAG, "File deleted ["
                + android.os.Environment.getExternalStorageDirectory().toString()
                + "/SoundRecorder" + file + "]");

        // remove file from database and recyclerview
        mFileViewerAdapter.removeOutOfApp(filePath);
    }
}
 
Example 5
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 6
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 7
Source File: AppRunnerFragment.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
public void startFileObserver() {

        if (mAppRunner.mIsProjectLoaded) {
            // set up a file observer to watch this directory on sd card
            fileObserver = new FileObserver(mAppRunner.getProject().getFullPath(), FileObserver.CREATE | FileObserver.DELETE) {

                @Override
                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");
                        //TODO change to events
                        //IDEcommunication.getInstance(mActivity).send(msg);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }


                }
            };
        }
    }
 
Example 8
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 9
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 10
Source File: OfflineVideoManager.java    From android-viewer-for-khan-academy with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEvent(int event, final String path) {
	if (path == null) {
		return;
	}
	
	switch (event & FileObserver.ALL_EVENTS) {
	case FileObserver.CLOSE_WRITE:
		// Download complete, or paused when wifi is disconnected. Possibly reported more than once in a row.
		// Useful for noticing when a download has been paused. For completions, register a receiver for 
		// DownloadManager.ACTION_DOWNLOAD_COMPLETE.
		break;
	case FileObserver.OPEN:
		// Called for both read and write modes.
		// Useful for noticing a download has been started or resumed.
		break;
	case FileObserver.DELETE:
	case FileObserver.MOVED_FROM:
		// This video is lost never to return. Remove it.
		handler.post(new Runnable() {
			@Override
			public void run() {
				DatabaseHelper helper = dataService.getHelper();
				helper.removeDownloadFromDownloadManager(helper.getVideoForFilename(path));
			}
		});
		break;
	case FileObserver.MODIFY:
		// Called very frequently while a download is ongoing (~1 per ms).
		// This could be used to trigger a progress update, but that should probably be done less often than this.
		shouldPoll = true;
		break;
	}
}
 
Example 11
Source File: DeviceStorageMonitorService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public CacheFileDeletedObserver() {
    super(Environment.getDownloadCacheDirectory().getAbsolutePath(), FileObserver.DELETE);
}
 
Example 12
Source File: DeviceSucker.java    From CameraV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onEvent(int event, String path) {
    String parse = null;

    switch(event) {
        case FileObserver.CREATE:
            parse = "file created";
            break;
        case FileObserver.MODIFY:
            parse = "file modified";
            break;
        case FileObserver.CLOSE_WRITE:
            parse = "file closed/writen";
            break;
        case FileObserver.ACCESS:
            //parse = "file accessed";
            break;
        case FileObserver.DELETE:
            parse = "file deleted";
            break;
        case FileObserver.OPEN:
            //parse = "file opened";
            break;
        case FileObserver.CLOSE_NOWRITE:
            //parse = "file closed/not writen";
            break;
        case FileObserver.ATTRIB:
            parse = "file attribs changed";
            break;
    }

    if(parse != null) {
        Logger.d(LOG, String.format("EVENT %d ON %s: %s", event, path, parse));
        //lsof_r1(path);

        ILogPack logPack = new ILogPack();
        logPack.put(Keys.FILE_EFFECTED, path);
        logPack.put(Keys.ACCESS_TYPE, parse);
        logPack.put(Keys.ACCESS_CODE, event);

        DeviceSucker.this.sendToBuffer(logPack);
    }
}