CameraFragment
一个简单的易于集成的Android相机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();
Actions
你可以直接拍摄图片拍摄视频
cameraFragment.takePhotoOrCaptureVideo(callback);
闪光灯可以启动或则禁止:
cameraFragment.toggleFlashMode();
相机类型也可以修改:
cameraFragment.switchCameraTypeFrontBack();
相机动作可以修改:
cameraFragment.switchActionPhotoVideo();
你可以改变所拍摄的照片视频大小?
cameraFragment.openSettingDialog();
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使用CameraFragmentTextListener ping当前记录的持续时间
Widgets
CameraFragment带有一些默认视图
RecordButton,MediaActionSwitchView,FlashSwitchView,CameraSwitchView,CameraSettingsView
下载
在模块中
compile 'com.github.florent37:camerafragment:1.0.1'