本文整理汇总了Java中android.os.FileObserver.startWatching方法的典型用法代码示例。如果您正苦于以下问题:Java FileObserver.startWatching方法的具体用法?Java FileObserver.startWatching怎么用?Java FileObserver.startWatching使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.FileObserver
的用法示例。
在下文中一共展示了FileObserver.startWatching方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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();
}
}));
}
示例3: 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();
}
}
示例4: registerFileObserver
import android.os.FileObserver; //导入方法依赖的package包/类
private void registerFileObserver() {
mFileObserver = new FileObserver(context.getDataDir() + "/shared_prefs",
FileObserver.ATTRIB | FileObserver.CLOSE_WRITE) {
@Override
public void onEvent(int event, String path) {
for (FileObserverListener l : mFileObserverListeners) {
if ((event & FileObserver.ATTRIB) != 0)
l.onFileAttributesChanged(path);
if ((event & FileObserver.CLOSE_WRITE) != 0)
l.onFileUpdated(path);
}
}
};
mFileObserver.startWatching();
}
示例5: onStartVideoRecord
import android.os.FileObserver; //导入方法依赖的package包/类
public void onStartVideoRecord(final File mediaFile) {
setMediaFilePath(mediaFile);
CircleAngleAnimation animation = new CircleAngleAnimation(circleProgressView, 360);
animation.setDuration(10700);
circleProgressView.startAnimation(animation);
if (maxVideoFileSize > 0) {
recordSizeText.setText("1Mb" + " / " + maxVideoFileSize / (1024 * 1024) + "Mb");
recordSizeText.setVisibility(VISIBLE);
try {
fileObserver = new FileObserver(this.mediaFilePath) {
private long lastUpdateSize = 0;
@Override
public void onEvent(int event, String path) {
final long fileSize = mediaFile.length() / (1024 * 1024);
if ((fileSize - lastUpdateSize) >= 1) {
lastUpdateSize = fileSize;
recordSizeText.post(new Runnable() {
@Override
public void run() {
recordSizeText.setText(fileSize + "Mb" + " / " + maxVideoFileSize / (1024 * 1024) + "Mb");
}
});
}
}
};
fileObserver.startWatching();
} catch (Exception e) {
Log.e("FileObserver", "setMediaFilePath: ", e);
}
}
countDownTimer.start();
}
示例6: onStartVideoRecord
import android.os.FileObserver; //导入方法依赖的package包/类
public void onStartVideoRecord(final File mediaFile) {
setMediaFilePath(mediaFile);
if (maxVideoFileSize > 0) {
recordSizeText.setText("1Mb" + " / " + maxVideoFileSize / (1024 * 1024) + "Mb");
recordSizeText.setVisibility(VISIBLE);
try {
fileObserver = new FileObserver(this.mediaFilePath) {
private long lastUpdateSize = 0;
@Override
public void onEvent(int event, String path) {
final long fileSize = mediaFile.length() / (1024 * 1024);
if ((fileSize - lastUpdateSize) >= 1) {
lastUpdateSize = fileSize;
recordSizeText.post(new Runnable() {
@Override
public void run() {
recordSizeText.setText(fileSize + "Mb" + " / " + maxVideoFileSize / (1024 * 1024) + "Mb");
}
});
}
}
};
fileObserver.startWatching();
} catch (Exception e) {
Log.e("FileObserver", "setMediaFilePath: ", e);
}
}
countDownTimer.start();
}
示例7: onStartVideoRecord
import android.os.FileObserver; //导入方法依赖的package包/类
public void onStartVideoRecord(final File mediaFile) {
setMediaFilePath(mediaFile);
if (maxVideoFileSize > 0) {
recordSizeText.setText("1Mb" + " / " + maxVideoFileSize / (1024 * 1024) + "Mb");
recordSizeText.setVisibility(VISIBLE);
try {
fileObserver = new FileObserver(this.mediaFilePath) {
private long lastUpdateSize = 0;
@Override
public void onEvent(int event, String path) {
final long fileSize = mediaFile.length() / (1024 * 1024);
if ((fileSize - lastUpdateSize) >= 1) {
lastUpdateSize = fileSize;
recordSizeText.post(new Runnable() {
@Override
public void run() {
recordSizeText.setText(fileSize + "Mb" + " / " + maxVideoFileSize / (1024 * 1024) + "Mb");
}
});
}
}
};
fileObserver.startWatching();
} catch (Exception e) {
Log.e("FileObserver", "setMediaFilePath: ", e);
}
}
countDownTimer.start();
}
示例8: startPathUpdateObserver
import android.os.FileObserver; //导入方法依赖的package包/类
public static void startPathUpdateObserver(final FileObserver observer) {
if (null == observer) {
return;
}
observer.startWatching();
}
示例9: stopPathUpdateObserver
import android.os.FileObserver; //导入方法依赖的package包/类
public static void stopPathUpdateObserver(final FileObserver observer) {
if (null == observer) {
return;
}
observer.startWatching();
}
示例10: onStartVideoRecord
import android.os.FileObserver; //导入方法依赖的package包/类
protected void onStartVideoRecord(final File mediaFile) {
setMediaFilePath(mediaFile);
if (maxVideoFileSize > 0) {
if (cameraFragmentVideoRecordTextListener != null) {
cameraFragmentVideoRecordTextListener.setRecordSizeText(maxVideoFileSize, "1Mb" + " / " + maxVideoFileSize / (1024 * 1024) + "Mb");
cameraFragmentVideoRecordTextListener.setRecordSizeTextVisible(true);
}
try {
fileObserver = new FileObserver(this.mediaFilePath) {
private long lastUpdateSize = 0;
@Override
public void onEvent(int event, String path) {
final long fileSize = mediaFile.length() / (1024 * 1024);
if ((fileSize - lastUpdateSize) >= 1) {
lastUpdateSize = fileSize;
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
if (cameraFragmentVideoRecordTextListener != null) {
cameraFragmentVideoRecordTextListener.setRecordSizeText(maxVideoFileSize, fileSize + "Mb" + " / " + maxVideoFileSize / (1024 * 1024) + "Mb");
}
}
});
}
}
};
fileObserver.startWatching();
} catch (Exception e) {
Log.e("FileObserver", "setMediaFilePath: ", e);
}
}
if (countDownTimer == null) {
this.countDownTimer = new TimerTask(timerCallBack);
}
countDownTimer.start();
if (cameraFragmentStateListener != null) {
cameraFragmentStateListener.onStartVideoRecord(mediaFile);
}
}
示例11: processPictureWhenReady
import android.os.FileObserver; //导入方法依赖的package包/类
private void processPictureWhenReady(final String picturePath) throws Exception {
final File pictureFile = new File(picturePath);
if (pictureFile.exists()) {
// The picture is ready; process it.
System.out.println("picture exists??");
downloadTask(pictureFile);
} else {
// The file does not exist yet. Before starting the file observer, you
// can update your UI to let the user know that the application is
// waiting for the picture (for example, by displaying the thumbnail
// image and a progress indicator).
final File parentDirectory = pictureFile.getParentFile();
FileObserver observer = new FileObserver(parentDirectory.getPath(),
FileObserver.CLOSE_WRITE | FileObserver.MOVED_TO) {
// Protect against additional pending events after CLOSE_WRITE
// or MOVED_TO is handled.
private boolean isFileWritten;
@Override
public void onEvent(int event, String path) {
if (!isFileWritten) {
// For safety, make sure that the file that was created in
// the directory is actually the one that we're expecting.
File affectedFile = new File(parentDirectory, path);
isFileWritten = affectedFile.equals(pictureFile);
if (isFileWritten) {
stopWatching();
// Now that the file is ready, recursively call
// processPictureWhenReady again (on the UI thread).
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
processPictureWhenReady(picturePath);
} catch(Exception e) {
}
}
});
}
}
}
};
observer.startWatching();
}
}
示例12: processPictureWhenReady
import android.os.FileObserver; //导入方法依赖的package包/类
private void processPictureWhenReady(final String picturePath) {
final File pictureFile = new File(picturePath);
if (pictureFile.exists()) {
// The picture is ready; process it.
// SEBTEST: DO OCR HERE
mProgressDialog.hide();
Log.d("OCR", "Picture ready");
OCRRequest request = new OCRRequest(this, getApplicationContext());
request.execute(picturePath);
} else {
// The file does not exist yet. Before starting the file observer, you
// can update your UI to let the user know that the application is
// waiting for the picture (for example, by displaying the thumbnail
// image and a progress indicator).
final File parentDirectory = pictureFile.getParentFile();
FileObserver observer = new FileObserver(parentDirectory.getPath(),
FileObserver.CLOSE_WRITE | FileObserver.MOVED_TO) {
// Protect against additional pending events after CLOSE_WRITE
// or MOVED_TO is handled.
private boolean isFileWritten;
@Override
public void onEvent(int event, String path) {
if (!isFileWritten) {
// For safety, make sure that the file that was created in
// the directory is actually the one that we're expecting.
File affectedFile = new File(parentDirectory, path);
isFileWritten = affectedFile.equals(pictureFile);
if (isFileWritten) {
stopWatching();
// Now that the file is ready, recursively call
// processPictureWhenReady again (on the UI thread).
runOnUiThread(new Runnable() {
@Override
public void run() {
processPictureWhenReady(picturePath);
}
});
}
}
}
};
observer.startWatching();
}
}
示例13: processPictureWhenReady
import android.os.FileObserver; //导入方法依赖的package包/类
private void processPictureWhenReady(final String picturePath) {
final File pictureFile = new File(picturePath);
if (pictureFile.exists()) {
// The picture is ready; process it.
} else {
// The file does not exist yet. Before starting the file observer, you
// can update your UI to let the user know that the application is
// waiting for the picture (for example, by displaying the thumbnail
// image and a progress indicator).
final File parentDirectory = pictureFile.getParentFile();
FileObserver observer = new FileObserver(parentDirectory.getPath()) {
// Protect against additional pending events after CLOSE_WRITE is
// handled.
private boolean isFileWritten;
@Override
public void onEvent(int event, String path) {
if (!isFileWritten) {
// For safety, make sure that the file that was created in
// the directory is actually the one that we're expecting.
File affectedFile = new File(parentDirectory, path);
isFileWritten = (event == FileObserver.CLOSE_WRITE
&& affectedFile.equals(pictureFile));
if (isFileWritten) {
stopWatching();
// Now that the file is ready, recursively call
// processPictureWhenReady again (on the UI thread).
runOnUiThread(new Runnable() {
@Override
public void run() {
processPictureWhenReady(picturePath);
}
});
}
}
}
};
observer.startWatching();
}
}
示例14: onActivityResult
import android.os.FileObserver; //导入方法依赖的package包/类
@Override
// START:ballooncount2
public void onActivityResult(int requestCode, int resultCode, Intent intent){
// END:ballooncount2
d("onActivityResult");
// START:ballooncount2
if( resultCode != RESULT_OK ) {
finish();
return;
}
switch( requestCode ) {
// END:ballooncount2
// START:camera2
case REQ_CODE_TAKE_PICTURE:
String picFilePath =
intent.getStringExtra(Intents.EXTRA_PICTURE_FILE_PATH);
final File pictureFile = new File(picFilePath);
final String picFileName = pictureFile.getName();
// set up a file observer to watch this directory on sd card
observer = new FileObserver(pictureFile.getParentFile().getAbsolutePath()){
public void onEvent(int event, String file) {
// END:camera2
d("File " + file + ", event " + event);
// START:camera2
if( event == FileObserver.CLOSE_WRITE && file.equals(picFileName) ) {
// END:camera2
d("Image file written " + file);
// START:camera2
service.setImageFileName(pictureFile.getAbsolutePath());
stopWatching();
waitingForResult = false;
finish();
}
}
};
observer.startWatching();
waitingForResult = false;
// END:camera2
return;
// START:ballooncount2
case REQ_CODE_BALLOON_COUNT:
int balloonCount =
intent.getIntExtra(BalloonCountActivity.EXTRA_BALLOON_COUNT, 3);
service.setBalloonCount(balloonCount);
waitingForResult = false;
finish();
// END:ballooncount2
return;
default:
finish();
}
// START:ballooncount2
}
示例15: processPictureWhenReady
import android.os.FileObserver; //导入方法依赖的package包/类
private void processPictureWhenReady(final String picturePath)
{
final File pictureFile = new File(picturePath);
if (pictureFile.exists())
{
Intent shareIntent = new Intent(this, BluetoothClient.class);
shareIntent.putExtra(SHARE_PICTURE, picturePath);
startActivity(shareIntent);
finish();
}
else
{
// The file does not exist yet. Before starting the file observer, you
// can update your UI to let the user know that the application is
// waiting for the picture (for example, by displaying the thumbnail
// image and a progress indicator).
ViewGroup vg = (ViewGroup)(cameraView.getParent());
vg.removeAllViews();
RelativeLayout layout = new RelativeLayout(this);
ProgressBar progressBar = new ProgressBar(this,null,android.R.attr.progressBarStyleLarge);
progressBar.setIndeterminate(true);
progressBar.setVisibility(View.VISIBLE);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT
, ViewGroup.LayoutParams.MATCH_PARENT);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.addView(progressBar,params);
setContentView(layout);
final File parentDirectory = pictureFile.getParentFile();
observer = new FileObserver(parentDirectory.getPath()) {
// Protect against additional pending events after CLOSE_WRITE is
// handled.
private boolean isFileWritten;
@Override
public void onEvent(int event, String path) {
if (!isFileWritten) {
// For safety, make sure that the file that was created in
// the directory is actually the one that we're expecting.
File affectedFile = new File(parentDirectory, path);
isFileWritten = (event == FileObserver.CLOSE_WRITE
&& affectedFile.equals(pictureFile));
if (isFileWritten) {
stopWatching();
// Now that the file is ready, recursively call
// processPictureWhenReady again (on the UI thread).
runOnUiThread(new Runnable() {
@Override
public void run() {
processPictureWhenReady(picturePath);
}
});
}
}
}
};
observer.startWatching();
}
}