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


Java FileObserver.startWatching方法代码示例

本文整理汇总了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);
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:22,代码来源:PFileIO.java

示例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();
        }
    }));
}
 
开发者ID:phajduk,项目名称:RxFileObserver,代码行数:27,代码来源:FileObservable.java

示例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();
    }
}
 
开发者ID:onepf,项目名称:Open-Store-Example,代码行数:23,代码来源:StoreApplication.java

示例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();
}
 
开发者ID:erfanoabdi,项目名称:BatteryModPercentage,代码行数:16,代码来源:EffEnhancer.java

示例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();

}
 
开发者ID:MartinRGB,项目名称:android_camera_experiment,代码行数:37,代码来源:CameraControlPanel.java

示例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();
}
 
开发者ID:sandrios,项目名称:sandriosCamera,代码行数:31,代码来源:CameraControlPanel.java

示例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();

}
 
开发者ID:memfis19,项目名称:Annca,代码行数:32,代码来源:CameraControlPanel.java

示例8: startPathUpdateObserver

import android.os.FileObserver; //导入方法依赖的package包/类
public static void startPathUpdateObserver(final FileObserver observer) {
    if (null == observer) {
        return;
    }

    observer.startWatching();
}
 
开发者ID:FrancescoJo,项目名称:MediaMonkey,代码行数:8,代码来源:FileUtils.java

示例9: stopPathUpdateObserver

import android.os.FileObserver; //导入方法依赖的package包/类
public static void stopPathUpdateObserver(final FileObserver observer) {
    if (null == observer) {
        return;
    }

    observer.startWatching();
}
 
开发者ID:FrancescoJo,项目名称:MediaMonkey,代码行数:8,代码来源:FileUtils.java

示例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);
    }
}
 
开发者ID:florent37,项目名称:CameraFragment,代码行数:44,代码来源:BaseAnncaFragment.java

示例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();
    }
}
 
开发者ID:xasos,项目名称:ScandIn-Glass,代码行数:51,代码来源:MainActivity.java

示例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();
    }
}
 
开发者ID:scheah,项目名称:eulexia,代码行数:51,代码来源:OCRActivity.java

示例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();
    }
}
 
开发者ID:stanzheng,项目名称:Google-Glass-Camera,代码行数:45,代码来源:MainActivity.java

示例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
}
 
开发者ID:coderoshi,项目名称:glass,代码行数:54,代码来源:LiveCardMenuActivity.java

示例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();
    }
}
 
开发者ID:vicmns,项目名称:BluetoothGlass,代码行数:68,代码来源:MainActivity.java


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