Example usage for android.os FileObserver MODIFY

List of usage examples for android.os FileObserver MODIFY

Introduction

In this page you can find the example usage for android.os FileObserver MODIFY.

Prototype

int MODIFY

To view the source code for android.os FileObserver MODIFY.

Click Source Link

Document

Event type: Data was written to a file

Usage

From source file:org.arakhne.afc.ui.android.filechooser.AsyncFileLoader.java

/**
 * {@inheritDoc}/*from   w ww  .ja  v  a  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 w  w  w  . j a va 2  s .c o  m
    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.
 */// w  w  w  .  j  av  a 2  s . co  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:org.protocoderrunner.apprunner.api.PFileIO.java

@ProtoMethod(description = "Observer file changes in a folder", example = "")
@ProtoMethodParam(params = { "path", "function(action, file" })
public void observeFolder(String path, final FileObserverCB callback) {

    fileObserver = new FileObserver(
            ProjectManager.getInstance().getCurrentProject().getStoragePath() + "/" + path,
            FileObserver.CREATE | FileObserver.MODIFY | FileObserver.DELETE) {

        @Override//  ww w  .  jav a  2  s . c  om
        public void onEvent(int event, String file) {

            if ((FileObserver.CREATE & event) != 0) {
                callback.event("create", file);
            } else if ((FileObserver.DELETE & event) != 0) {
                callback.event("delete", file);
            } else if ((FileObserver.MODIFY & event) != 0) {
                callback.event("modify", file);
            }
        }

    };
    fileObserver.startWatching();
}