android camera fragment,CameraFragment

初始化//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);

1-1F11Q60SUL.gif

切换Flash 模式enable / disabled ( AUTO / OFF / ON )cameraFragment.toggleFlashMode();

1484764100655029.gif

改变Camera类型(前置或者后置):cameraFragment.switchCameraTypeFrontBack();

1484764164125781.gif

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

1484764208126087.gif

还可以设置大小(分辨率):cameraFragment.openSettingDialog();

1484764262111960.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 ListenercameraFragment.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

1484764936499297.png

下载

In your modulecompile 'com.github.florent37:camerafragment:1.0.1'

Community

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值