if in video mode, turning on the flash turns it into a flashlight
This commit is contained in:
parent
dff62f66d9
commit
00835946c6
|
@ -61,6 +61,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||
|
||||
@OnClick(R.id.toggle_camera)
|
||||
public void toggleCamera() {
|
||||
disableFlash();
|
||||
hideTimer();
|
||||
if (currCamera == Camera.CameraInfo.CAMERA_FACING_BACK) {
|
||||
currCamera = Camera.CameraInfo.CAMERA_FACING_FRONT;
|
||||
|
@ -123,20 +124,25 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||
|
||||
@OnClick(R.id.toggle_videocam)
|
||||
public void toggleVideo() {
|
||||
disableFlash();
|
||||
hideTimer();
|
||||
isPhoto = !isPhoto;
|
||||
toggleCameraBtn.setVisibility(View.VISIBLE);
|
||||
|
||||
if (isPhoto) {
|
||||
final Resources res = getResources();
|
||||
togglePhotoVideoBtn.setImageDrawable(res.getDrawable(R.mipmap.videocam));
|
||||
shutterBtn.setImageDrawable(res.getDrawable(R.mipmap.camera));
|
||||
preview.initPhotoMode();
|
||||
initPhoto();
|
||||
} else {
|
||||
initVideo();
|
||||
}
|
||||
}
|
||||
|
||||
private void initPhoto() {
|
||||
final Resources res = getResources();
|
||||
togglePhotoVideoBtn.setImageDrawable(res.getDrawable(R.mipmap.videocam));
|
||||
shutterBtn.setImageDrawable(res.getDrawable(R.mipmap.camera));
|
||||
preview.initPhotoMode();
|
||||
}
|
||||
|
||||
private void initVideo() {
|
||||
final Resources res = getResources();
|
||||
togglePhotoVideoBtn.setImageDrawable(res.getDrawable(R.mipmap.photo));
|
||||
|
|
|
@ -323,13 +323,19 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean enableFlash() {
|
||||
public void enableFlash() {
|
||||
if (isVideoMode) {
|
||||
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
|
||||
camera.setParameters(parameters);
|
||||
}
|
||||
|
||||
isFlashEnabled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void disableFlash() {
|
||||
isFlashEnabled = false;
|
||||
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
|
||||
camera.setParameters(parameters);
|
||||
}
|
||||
|
||||
public void initPhotoMode() {
|
||||
|
|
Loading…
Reference in New Issue