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,18 +124,23 @@ 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) {
|
||||
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();
|
||||
} else {
|
||||
initVideo();
|
||||
}
|
||||
}
|
||||
|
||||
private void initVideo() {
|
||||
|
|
|
@ -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