use of com.cjt2325.cameralibrary.listener.ClickListener in project CameraView by CJT2325.
the class CameraActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_camera);
jCameraView = (JCameraView) findViewById(R.id.jcameraview);
// 设置视频保存路径
jCameraView.setSaveVideoPath(Environment.getExternalStorageDirectory().getPath() + File.separator + "JCamera");
jCameraView.setFeatures(JCameraView.BUTTON_STATE_BOTH);
jCameraView.setTip("JCameraView Tip");
jCameraView.setMediaQuality(JCameraView.MEDIA_QUALITY_MIDDLE);
jCameraView.setErrorLisenter(new ErrorListener() {
@Override
public void onError() {
// 错误监听
Log.i("CJT", "camera error");
Intent intent = new Intent();
setResult(103, intent);
finish();
}
@Override
public void AudioPermissionError() {
Toast.makeText(CameraActivity.this, "给点录音权限可以?", Toast.LENGTH_SHORT).show();
}
});
// JCameraView监听
jCameraView.setJCameraLisenter(new JCameraListener() {
@Override
public void captureSuccess(Bitmap bitmap) {
// 获取图片bitmap
// Log.i("JCameraView", "bitmap = " + bitmap.getWidth());
String path = FileUtil.saveBitmap("JCamera", bitmap);
Intent intent = new Intent();
intent.putExtra("path", path);
setResult(101, intent);
finish();
}
@Override
public void recordSuccess(String url, Bitmap firstFrame) {
// 获取视频路径
String path = FileUtil.saveBitmap("JCamera", firstFrame);
Log.i("CJT", "url = " + url + ", Bitmap = " + path);
Intent intent = new Intent();
intent.putExtra("path", path);
setResult(101, intent);
finish();
}
});
jCameraView.setLeftClickListener(new ClickListener() {
@Override
public void onClick() {
CameraActivity.this.finish();
}
});
jCameraView.setRightClickListener(new ClickListener() {
@Override
public void onClick() {
Toast.makeText(CameraActivity.this, "Right", Toast.LENGTH_SHORT).show();
}
});
Log.i("CJT", DeviceUtil.getDeviceModel());
}
use of com.cjt2325.cameralibrary.listener.ClickListener 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