CameraFragment

  • 相机 (Camera)
  • ★★★★★
  • 2017-01-19 02:40
  • 35406 kb
  • Android Studio

介绍:

一个集成了拍照功能的Fragment 。

运行效果:

使用说明:

初始化

//you can configure the fragment by the configuration builder
CameraFragment cameraFragment = CameraFragment.newInstance(new Configuration.Builder().build());

getSupportFragmentManager().beginTransaction()
                .replace(R.id.content, cameraFragment, FRAGMENT_TAG)
                .commit();

你可以直接使用下面的代码拍照或者录制视频:

cameraFragment.takePhotoOrCaptureVideo(callback);

切换Flash 模式enable / disabled ( AUTO / OFF / ON )

cameraFragment.toggleFlashMode();

switch_flash.gif

改变Camera类型(前置或者后置):

cameraFragment.switchCameraTypeFrontBack();

switch_camera.gif

设置Camera行为(拍照还是录制视频):

cameraFragment.switchActionPhotoVideo();

switch_action.gif

还可以设置大小(分辨率):

cameraFragment.openSettingDialog();

settings.gif

Listeners

Result

在CameraFragmentResultListener中得到录制(或者拍照)的结果

cameraFragment.setResultListener(new CameraFragmentResultListener() {
       @Override
       public void onVideoRecorded(byte[] bytes, String filePath) {
                //called when the video record is finished and saved

                startActivityForResult(PreviewActivity.newIntentVideo(MainActivity.this, filePath));
       }

       @Override
       public void onPhotoTaken(byte[] bytes, String filePath) {
                //called when the photo is taken and saved

                startActivity(PreviewActivity.newIntentPhoto(MainActivity.this, filePath));
       }
});

Camera Listener

cameraFragment.setStateListener(new CameraFragmentStateListener() {

    //when the current displayed camera is the back
    void onCurrentCameraBack();
    //when the current displayed camera is the front
    void onCurrentCameraFront();

    //when the flash is at mode auto
    void onFlashAuto();
    //when the flash is at on
    void onFlashOn();
    //when the flash is off
    void onFlashOff();

    //if the camera is ready to take a photo
    void onCameraSetupForPhoto();
    //if the camera is ready to take a video
    void onCameraSetupForVideo();

    //when the camera state is "ready to record a video"
    void onRecordStateVideoReadyForRecord();
    //when the camera state is "recording a video"
    void onRecordStateVideoInProgress();
    //when the camera state is "ready to take a photo"
    void onRecordStatePhoto();

    //after the rotation of the screen / camera
    void shouldRotateControls(int degrees);

    void onStartVideoRecord(File outputFile);
    void onStopVideoRecord();
});

Text

CameraFragment can ping you with the current record duration with CameraFragmentTextListener

Widgets

CameraFragment的默认视图:

RecordButton, MediaActionSwitchView, FlashSwitchView, CameraSwitchView, CameraSettingsView

buttons.png

下载

In your module

compile 'com.github.florent37:camerafragment:1.0.1'

Community

Forked fromhttps://github.com/memfis19/Annca