I am trying implementation like SnapChat where the user clicks the button it captures photo and when user holds button video recording starts.
I am using CamerView of CWAC-Camera Library for my camera implementation.
This is in my onCreate Method where I have Assigned the button with CLickListeners and Boolean for TakingVideo
btnTakePhoto.setOnLongClickListener(takeVideoListener);
btnTakePhoto.setOnTouchListener(touchListener);
TakingVideo = false;
Here are the Methods for OnlongClickListeners and OnTouchListeners;
private View.OnLongClickListener takeVideoListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
TakingVideo = true;
try {
if (cameraView.record()) {
Toast.makeText(TakePhotoActivity.this,"Is Recording",Toast.LENGTH_SHORT).show();
} else {
//TODO: show an error to the user
try {
cameraView.stopRecording();
Toast.makeText(TakePhotoActivity.this,"Stopped Recording",Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
};
private View.OnTouchListener touchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (TakingVideo) {
Toast.makeText(TakePhotoActivity.this,"Finished Recording",
Toast.LENGTH_SHORT).show();
TakingVideo = false;
TakenVideo.start();
try {
cameraView.stopRecording();
Toast.makeText(TakePhotoActivity.this,"Stop Recording",
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(TakePhotoActivity.this,"Error Stop Recording",
Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
}
return false;
}
};
And the Button has also been assigned to Take Photo OnClick
@OnClick(R.id.btnTakePhoto)
public void onTakePhotoClick() {
btnTakePhoto.setEnabled(false);
cameraView.takePicture(true, true);
animateShutter();
}
So far the on TouchListener is working fine but onLongClick Listener doesn't work.
Here is the Link for CWAC-Camera's CameraView Class