use of com.cjt2325.cameralibrary.listener.CaptureListener in project CameraView by CJT2325.
the class CaptureLayout method initView.
private void initView() {
setWillNotDraw(false);
// 拍照按钮
btn_capture = new CaptureButton(getContext(), button_size);
LayoutParams btn_capture_param = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
btn_capture_param.gravity = Gravity.CENTER;
btn_capture.setLayoutParams(btn_capture_param);
btn_capture.setCaptureLisenter(new CaptureListener() {
@Override
public void takePictures() {
if (captureLisenter != null) {
captureLisenter.takePictures();
}
}
@Override
public void recordShort(long time) {
if (captureLisenter != null) {
captureLisenter.recordShort(time);
}
startAlphaAnimation();
}
@Override
public void recordStart() {
if (captureLisenter != null) {
captureLisenter.recordStart();
}
startAlphaAnimation();
}
@Override
public void recordEnd(long time) {
if (captureLisenter != null) {
captureLisenter.recordEnd(time);
}
startAlphaAnimation();
startTypeBtnAnimator();
}
@Override
public void recordZoom(float zoom) {
if (captureLisenter != null) {
captureLisenter.recordZoom(zoom);
}
}
@Override
public void recordError() {
if (captureLisenter != null) {
captureLisenter.recordError();
}
}
});
// 取消按钮
btn_cancel = new TypeButton(getContext(), TypeButton.TYPE_CANCEL, button_size);
final LayoutParams btn_cancel_param = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
btn_cancel_param.gravity = Gravity.CENTER_VERTICAL;
btn_cancel_param.setMargins((layout_width / 4) - button_size / 2, 0, 0, 0);
btn_cancel.setLayoutParams(btn_cancel_param);
btn_cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (typeLisenter != null) {
typeLisenter.cancel();
}
startAlphaAnimation();
// resetCaptureLayout();
}
});
// 确认按钮
btn_confirm = new TypeButton(getContext(), TypeButton.TYPE_CONFIRM, button_size);
LayoutParams btn_confirm_param = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
btn_confirm_param.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT;
btn_confirm_param.setMargins(0, 0, (layout_width / 4) - button_size / 2, 0);
btn_confirm.setLayoutParams(btn_confirm_param);
btn_confirm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (typeLisenter != null) {
typeLisenter.confirm();
}
startAlphaAnimation();
// resetCaptureLayout();
}
});
// 返回按钮
btn_return = new ReturnButton(getContext(), (int) (button_size / 2.5f));
LayoutParams btn_return_param = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
btn_return_param.gravity = Gravity.CENTER_VERTICAL;
btn_return_param.setMargins(layout_width / 6, 0, 0, 0);
btn_return.setLayoutParams(btn_return_param);
btn_return.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (leftClickListener != null) {
leftClickListener.onClick();
}
}
});
// 左边自定义按钮
iv_custom_left = new ImageView(getContext());
LayoutParams iv_custom_param_left = new LayoutParams((int) (button_size / 2.5f), (int) (button_size / 2.5f));
iv_custom_param_left.gravity = Gravity.CENTER_VERTICAL;
iv_custom_param_left.setMargins(layout_width / 6, 0, 0, 0);
iv_custom_left.setLayoutParams(iv_custom_param_left);
iv_custom_left.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (leftClickListener != null) {
leftClickListener.onClick();
}
}
});
// 右边自定义按钮
iv_custom_right = new ImageView(getContext());
LayoutParams iv_custom_param_right = new LayoutParams((int) (button_size / 2.5f), (int) (button_size / 2.5f));
iv_custom_param_right.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT;
iv_custom_param_right.setMargins(0, 0, layout_width / 6, 0);
iv_custom_right.setLayoutParams(iv_custom_param_right);
iv_custom_right.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (rightClickListener != null) {
rightClickListener.onClick();
}
}
});
txt_tip = new TextView(getContext());
LayoutParams txt_param = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
txt_param.gravity = Gravity.CENTER_HORIZONTAL;
txt_param.setMargins(0, 0, 0, 0);
txt_tip.setText("轻触拍照,长按摄像");
txt_tip.setTextColor(0xFFFFFFFF);
txt_tip.setGravity(Gravity.CENTER);
txt_tip.setLayoutParams(txt_param);
this.addView(btn_capture);
this.addView(btn_cancel);
this.addView(btn_confirm);
this.addView(btn_return);
this.addView(iv_custom_left);
this.addView(iv_custom_right);
this.addView(txt_tip);
}
use of com.cjt2325.cameralibrary.listener.CaptureListener in project CameraView by CJT2325.
the class JCameraView method initView.
private void initView() {
setWillNotDraw(false);
View view = LayoutInflater.from(mContext).inflate(R.layout.camera_view, this);
mVideoView = (VideoView) view.findViewById(R.id.video_preview);
mPhoto = (ImageView) view.findViewById(R.id.image_photo);
mSwitchCamera = (ImageView) view.findViewById(R.id.image_switch);
mSwitchCamera.setImageResource(iconSrc);
mFlashLamp = (ImageView) view.findViewById(R.id.image_flash);
setFlashRes();
mFlashLamp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
type_flash++;
if (type_flash > 0x023)
type_flash = TYPE_FLASH_AUTO;
setFlashRes();
}
});
mCaptureLayout = (CaptureLayout) view.findViewById(R.id.capture_layout);
mCaptureLayout.setDuration(duration);
mCaptureLayout.setIconSrc(iconLeft, iconRight);
mFoucsView = (FoucsView) view.findViewById(R.id.fouce_view);
mVideoView.getHolder().addCallback(this);
// 切换摄像头
mSwitchCamera.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
machine.swtich(mVideoView.getHolder(), screenProp);
}
});
// 拍照 录像
mCaptureLayout.setCaptureLisenter(new CaptureListener() {
@Override
public void takePictures() {
mSwitchCamera.setVisibility(INVISIBLE);
mFlashLamp.setVisibility(INVISIBLE);
machine.capture();
}
@Override
public void recordStart() {
mSwitchCamera.setVisibility(INVISIBLE);
mFlashLamp.setVisibility(INVISIBLE);
machine.record(mVideoView.getHolder().getSurface(), screenProp);
}
@Override
public void recordShort(final long time) {
mCaptureLayout.setTextWithAnimation("录制时间过短");
mSwitchCamera.setVisibility(VISIBLE);
mFlashLamp.setVisibility(VISIBLE);
postDelayed(new Runnable() {
@Override
public void run() {
machine.stopRecord(true, time);
}
}, 1500 - time);
}
@Override
public void recordEnd(long time) {
machine.stopRecord(false, time);
}
@Override
public void recordZoom(float zoom) {
LogUtil.i("recordZoom");
machine.zoom(zoom, CameraInterface.TYPE_RECORDER);
}
@Override
public void recordError() {
if (errorLisenter != null) {
errorLisenter.AudioPermissionError();
}
}
});
// 确认 取消
mCaptureLayout.setTypeLisenter(new TypeListener() {
@Override
public void cancel() {
machine.cancle(mVideoView.getHolder(), screenProp);
}
@Override
public void confirm() {
machine.confirm();
}
});
// 退出
// mCaptureLayout.setReturnLisenter(new ReturnListener() {
// @Override
// public void onReturn() {
// if (jCameraLisenter != null) {
// jCameraLisenter.quit();
// }
// }
// });
mCaptureLayout.setLeftClickListener(new ClickListener() {
@Override
public void onClick() {
if (leftClickListener != null) {
leftClickListener.onClick();
}
}
});
mCaptureLayout.setRightClickListener(new ClickListener() {
@Override
public void onClick() {
if (rightClickListener != null) {
rightClickListener.onClick();
}
}
});
}
Aggregations