当前位置: 首页>>代码示例>>Java>>正文


Java FileObserver类代码示例

本文整理汇总了Java中android.os.FileObserver的典型用法代码示例。如果您正苦于以下问题:Java FileObserver类的具体用法?Java FileObserver怎么用?Java FileObserver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileObserver类属于android.os包,在下文中一共展示了FileObserver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onEvent

import android.os.FileObserver; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:Arjun-sna,项目名称:Android-AudioRecorder-App,代码行数:20,代码来源:PlayListFragment.java

示例2: startWatching

import android.os.FileObserver; //导入依赖的package包/类
private void startWatching() {
    final String pathToWatch = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath();

    observer = new RecursiveFileObserver(pathToWatch, FileObserver.CLOSE_WRITE| FileObserver.MOVED_TO) { // set up a file observer to watch this directory on sd card
        @Override
        public void onEvent(int event, final String mediaPath) {
            if (mediaPath != null && (!mediaPath.equals(".probe"))) { // check that it's not equal to .probe because thats created every time camera is launched

                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {

                        if (mediaPath.endsWith(".mp4"))
                            handleNewVideo(mediaPath);
                    }
                });
            }
        }
    };
    observer.startWatching();


}
 
开发者ID:guardianproject,项目名称:proofmode,代码行数:24,代码来源:MediaListenerService.java

示例3: PFileObserver

import android.os.FileObserver; //导入依赖的package包/类
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);
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:22,代码来源:PFileIO.java

示例4: onEvent

import android.os.FileObserver; //导入依赖的package包/类
@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()
                + "/Facebook Videos" + file + "]";

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

        // remove file from database and recyclerview
        mFileViewerAdapter.removeOutOfApp(filePath);
    }
}
 
开发者ID:adarshgumashta,项目名称:Facebook-Video-Downloader,代码行数:17,代码来源:FileViewerFragment.java

示例5: onEvent

import android.os.FileObserver; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:tortuvshin,项目名称:health,代码行数:17,代码来源:FileViewerFragment.java

示例6: onEvent

import android.os.FileObserver; //导入依赖的package包/类
@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((MyBrowserActivity) getActivity(), path));
            break;
    }
}
 
开发者ID:wade-fs,项目名称:MediaManager,代码行数:20,代码来源:AbstractBrowserFragment.java

示例7: onEvent

import android.os.FileObserver; //导入依赖的package包/类
@Override
public synchronized void onEvent(int event, String path) {
    if (path.equals(tabuPath)) {
        return;
    }

    long delay = 0;
    switch (event) {
        case FileObserver.MODIFY:
            delay = Math.max(0,
                    lastUpdateTime + MODIFICATION_INTERVAL - SystemClock.elapsedRealtime());
            modified.add(path);
            break;
        case FileObserver.CREATE:
        case FileObserver.MOVED_TO:
            added.add(path);
            break;
        case FileObserver.DELETE:
        case FileObserver.MOVED_FROM:
            deleted.add(path);
            break;
    }

    schedule(delay);
}
 
开发者ID:mrwojtek,项目名称:sens-rec,代码行数:26,代码来源:Records.java

示例8: call

import android.os.FileObserver; //导入依赖的package包/类
@Override
public void call(final Subscriber<? super FileEvent> subscriber) {
    final FileObserver observer = new FileObserver(pathToWatch) {
        @Override
        public void onEvent(int event, String file) {
            if(subscriber.isUnsubscribed()) {
                return;
            }

            FileEvent fileEvent = FileEvent.create(event, file);
            subscriber.onNext(fileEvent);

            if(fileEvent.isDeleteSelf()) {
                subscriber.onCompleted();
            }
        }
    };
    observer.startWatching(); //START OBSERVING

    subscriber.add(Subscriptions.create(new Action0() {
        @Override
        public void call() {
            observer.stopWatching();
        }
    }));
}
 
开发者ID:phajduk,项目名称:RxFileObserver,代码行数:27,代码来源:FileObservable.java

示例9: stopObservers

import android.os.FileObserver; //导入依赖的package包/类
public void stopObservers(final String path) {
    final String mpath = FileUtils.invertMountPrefix(path);
    final String ap = path + "/";
    final String mp = mpath != null ? mpath + "/" : null;

    synchronized (observers) {
        final Iterator<Entry<File, FileObserver>> iter = observers.entrySet().iterator();
        while (iter.hasNext()) {
            final Entry<File, FileObserver> next = iter.next();
            final File file = next.getKey();
            final String filePath = file.getAbsolutePath();
            final boolean eq = filePath.startsWith(ap) || filePath.equals(path) || mpath != null
                    && (filePath.startsWith(mp) || filePath.equals(mpath));
            if (eq) {
                next.getValue().stopWatching();
                iter.remove();
            }
        }
    }
}
 
开发者ID:Git-tl,项目名称:appcan-plugin-pdfreader-android,代码行数:21,代码来源:FileSystemScanner.java

示例10: onEvent

import android.os.FileObserver; //导入依赖的package包/类
/**
 * This method is invoked when a registered event occur.
 *
 * @param event The type of event which happened
 * @param path  The path, relative to the main monitored file or directory,
 *              of the file or directory which triggered the event
 */
@Override
public void onEvent(int event, String path) {
	switch (event & FileObserver.ALL_EVENTS) {
		case FileObserver.CREATE:
			checkAutoRenameTask(path);
			break;
		case FileObserver.DELETE:
		case FileObserver.DELETE_SELF:
		case FileObserver.MODIFY:
		case FileObserver.MOVED_FROM:
		case FileObserver.MOVED_TO:
		case FileObserver.MOVE_SELF:
			checkForFolder(path);
			break;
	}
}
 
开发者ID:ciubex,项目名称:dscautorename,代码行数:24,代码来源:FolderObserver.java

示例11: onEvent

import android.os.FileObserver; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:PaperAirplane-Dev-Team,项目名称:Panoramic-Screenshot,代码行数:22,代码来源:ScreenshotService.java

示例12: onEvent

import android.os.FileObserver; //导入依赖的package包/类
@Override
public void onEvent(int event, String path) {
	if (DebugLog.DEBUG) Log.d(TAG, "FileAccessService.AccessObserver.onEvent - access triggered");
	switch (event) {
		case FileObserver.ACCESS:
			values[READS] = Long.valueOf(values[READS].longValue() + 1);
			break;
		case FileObserver.MODIFY:
			values[WRITES] = Long.valueOf(values[WRITES].longValue() + 1);
			break;
		case FileObserver.CREATE:
			values[CREATES] = Long.valueOf(values[CREATES].longValue() + 1);
			break;
		case FileObserver.DELETE:
			values[DELETES] = Long.valueOf(values[DELETES].longValue() + 1);
			break;
		default:
			return;
	}
	updateMetric = new UpdateMetric();	// is this needed (nothing static)?
	metricHandler.post(updateMetric);
}
 
开发者ID:Sean1988,项目名称:CIMON_Android,代码行数:23,代码来源:FileAccessService.java

示例13: performUpdates

import android.os.FileObserver; //导入依赖的package包/类
@Override
protected void performUpdates() {
	long nextUpdate = updateValueNodes();
	if (nextUpdate < 0) {
		if (accessObserver != null) {
			accessObserver.stopWatching();
			accessObserver = null;
		}
	}
	else {
		if (accessObserver == null) {
			accessObserver = new AccessObserver(Environment.getExternalStorageDirectory().getPath(), 
					FileObserver.ACCESS | FileObserver.MODIFY | FileObserver.CREATE | FileObserver.DELETE);
			accessObserver.startWatching();
		}
	}
	updateObservable();
}
 
开发者ID:Sean1988,项目名称:CIMON_Android,代码行数:19,代码来源:FileAccessService.java

示例14: onCreate

import android.os.FileObserver; //导入依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();

    copyConfigFromAssets(GOOGLE_CONFIG_FILE);
    copyConfigFromAssets(AMAZON_CONFIG_FILE);
    copyConfigFromAssets(ONEPF_CONFIG_FILE);

    if (createDbFromConfig()) {
        _configObserver = new FileObserver(getConfigDir()) {
            @Override
            public void onEvent(int event, String file) {
                switch (event) {
                    case FileObserver.CLOSE_WRITE:
                        createDbFromConfig();
                        break;
                }
            }
        };
        _configObserver.startWatching();
    }
}
 
开发者ID:onepf,项目名称:Open-Store-Example,代码行数:23,代码来源:StoreApplication.java

示例15: LockPasswordUtils

import android.os.FileObserver; //导入依赖的package包/类
public LockPasswordUtils(Context context) {
	mSharedPreferences = context.getSharedPreferences(
			LOCK_PASSWORD_SALT_FILE, Context.MODE_PRIVATE);
	mEditor = mSharedPreferences.edit();
	if (sLockPasswordFilename == null) {
		String dataSystemDirectory = context.getCacheDir()
				.getAbsolutePath();
		sLockPasswordFilename = new File(dataSystemDirectory,
				LOCK_PASSWORD_FILE);
		sHaveNonZeroPasswordFile.set(sLockPasswordFilename.length() > 0);
		int fileObserverMask = FileObserver.CLOSE_WRITE
				| FileObserver.DELETE | FileObserver.MOVED_TO
				| FileObserver.CREATE;
		sPasswordObserver = new PasswordFileObserver(dataSystemDirectory,
				fileObserverMask);
		sPasswordObserver.startWatching();
	}
}
 
开发者ID:971758118,项目名称:git_wowodai,代码行数:19,代码来源:LockPasswordUtils.java


注:本文中的android.os.FileObserver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。