Java Code Examples for android.os.FileObserver#CREATE

The following examples show how to use android.os.FileObserver#CREATE . 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: 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: ScreenshotService.java    From Panoramic-Screenshot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onEvent(int event, String path) {
	if (event != FileObserver.CREATE) return;
	
	if (path.endsWith(".png")) {
		String file = mScreenshotDir + "/" + path;
		mFiles.add(file);
		
		if (DEBUG) {
			Log.d(TAG, "Adding " + file);
		}
		
		//mIntent.putExtra(EXTRA_PATHS, mFiles.toArray(new String[mFiles.size()]));
		
		PendingIntent i = mFiles.size() >= 2 ? PendingIntent.getActivity(ScreenshotService.this, 0, mIntent, 0) : null;
		
		rebuildNotification(i, String.format(getString(R.string.notifi_count), mFiles.size() + 1), getString(R.string.notifi_tip));
		
		mNotificationManager.notify(R.drawable.ic_launcher, mNotification);
	}
}
 
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: 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 7
Source File: SDCardListener.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
public void onEvent(int event, String path) {
    switch(event) {
        case FileObserver.ALL_EVENTS:
            Log.d("all", "path:"+ path);
            break;
        case FileObserver.CREATE:
            Log.d("Create", "path:"+ path);
            break;
    }
}
 
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: ScreenshotService.java    From Panoramic-Screenshot with GNU General Public License v3.0 4 votes vote down vote up
public ScreenshotObserver() {
	// TODO: The path should be changable
	super(mScreenshotDir, FileObserver.CREATE);
}
 
Example 11
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);
    }
}