Java Code Examples for android.hardware.Camera.Parameters#FLASH_MODE_ON
The following examples show how to use
android.hardware.Camera.Parameters#FLASH_MODE_ON .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraSource.java From fast_qr_reader_view with MIT License | 5 votes |
@SuppressLint("MissingPermission") @RequiresPermission(Manifest.permission.CAMERA) public void toggleFlash() { Camera.Parameters p = camera.getParameters(); if(p.getFlashMode() == Parameters.FLASH_MODE_ON){ p.setFlashMode(Parameters.FLASH_MODE_OFF); } else if(p.getFlashMode() == Parameters.FLASH_MODE_OFF){ p.setFlashMode(Parameters.FLASH_MODE_TORCH); } else if(p.getFlashMode().equals("off")){ p.setFlashMode(Parameters.FLASH_MODE_TORCH); } else if(p.getFlashMode().equals("torch")){ p.setFlashMode(Parameters.FLASH_MODE_OFF); } else if(p.getFlashMode() == Parameters.FLASH_MODE_AUTO){ p.setFlashMode(Parameters.FLASH_MODE_ON); } else if(p.getFlashMode() == Parameters.FLASH_MODE_TORCH){ p.setFlashMode(Parameters.FLASH_MODE_OFF); } else{ p.setFlashMode(Parameters.FLASH_MODE_AUTO); } camera.setParameters(p); camera.startPreview(); }
Example 2
Source File: Camera1Handler.java From Augendiagnose with GNU General Public License v2.0 | 5 votes |
@Override public final void setFlashlightMode(@Nullable final FlashMode flashlightMode) { if (flashlightMode == null) { mCurrentFlashlightMode = null; return; } switch (flashlightMode) { case OFF: case EXT: if (SystemUtil.hasFlashlight()) { mCurrentFlashlightMode = Parameters.FLASH_MODE_OFF; } else { mCurrentFlashlightMode = null; } break; case ON: mCurrentFlashlightMode = Parameters.FLASH_MODE_ON; break; case TORCH: mCurrentFlashlightMode = Parameters.FLASH_MODE_TORCH; break; default: mCurrentFlashlightMode = Parameters.FLASH_MODE_OFF; break; } mUseExternalFlash = flashlightMode == FlashMode.EXT; if (mUseExternalFlash && mExternalFlashBeep == null) { mExternalFlashBeep = new AudioUtil.Beep(); } updateFlashlight(); }
Example 3
Source File: LegacyRequestMapper.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private static void mapAeAndFlashMode(CaptureRequest r, /*out*/Parameters p) { int flashMode = ParamsUtils.getOrDefault(r, FLASH_MODE, FLASH_MODE_OFF); int aeMode = ParamsUtils.getOrDefault(r, CONTROL_AE_MODE, CONTROL_AE_MODE_ON); List<String> supportedFlashModes = p.getSupportedFlashModes(); String flashModeSetting = null; // Flash is OFF by default, on cameras that support flash if (ListUtils.listContains(supportedFlashModes, Parameters.FLASH_MODE_OFF)) { flashModeSetting = Parameters.FLASH_MODE_OFF; } /* * Map all of the control.aeMode* enums, but ignore AE_MODE_OFF since we never support it */ // Ignore flash.mode controls unless aeMode == ON if (aeMode == CONTROL_AE_MODE_ON) { if (flashMode == FLASH_MODE_TORCH) { if (ListUtils.listContains(supportedFlashModes, Parameters.FLASH_MODE_TORCH)) { flashModeSetting = Parameters.FLASH_MODE_TORCH; } else { Log.w(TAG, "mapAeAndFlashMode - Ignore flash.mode == TORCH;" + "camera does not support it"); } } else if (flashMode == FLASH_MODE_SINGLE) { if (ListUtils.listContains(supportedFlashModes, Parameters.FLASH_MODE_ON)) { flashModeSetting = Parameters.FLASH_MODE_ON; } else { Log.w(TAG, "mapAeAndFlashMode - Ignore flash.mode == SINGLE;" + "camera does not support it"); } } else { // Use the default FLASH_MODE_OFF } } else if (aeMode == CONTROL_AE_MODE_ON_ALWAYS_FLASH) { if (ListUtils.listContains(supportedFlashModes, Parameters.FLASH_MODE_ON)) { flashModeSetting = Parameters.FLASH_MODE_ON; } else { Log.w(TAG, "mapAeAndFlashMode - Ignore control.aeMode == ON_ALWAYS_FLASH;" + "camera does not support it"); } } else if (aeMode == CONTROL_AE_MODE_ON_AUTO_FLASH) { if (ListUtils.listContains(supportedFlashModes, Parameters.FLASH_MODE_AUTO)) { flashModeSetting = Parameters.FLASH_MODE_AUTO; } else { Log.w(TAG, "mapAeAndFlashMode - Ignore control.aeMode == ON_AUTO_FLASH;" + "camera does not support it"); } } else if (aeMode == CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE) { if (ListUtils.listContains(supportedFlashModes, Parameters.FLASH_MODE_RED_EYE)) { flashModeSetting = Parameters.FLASH_MODE_RED_EYE; } else { Log.w(TAG, "mapAeAndFlashMode - Ignore control.aeMode == ON_AUTO_FLASH_REDEYE;" + "camera does not support it"); } } else { // Default to aeMode == ON, flash = OFF } if (flashModeSetting != null) { p.setFlashMode(flashModeSetting); } if (DEBUG) { Log.v(TAG, "mapAeAndFlashMode - set flash.mode (api1) to " + flashModeSetting + ", requested (api2) " + flashMode + ", supported (api1) " + ListUtils.listToString(supportedFlashModes)); } }
Example 4
Source File: LegacyResultMapper.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** Map results for control.aeMode, flash.mode, flash.state */ private static void mapAeAndFlashMode(CameraMetadataNative m, CameraCharacteristics characteristics, Parameters p) { // Default: AE mode on but flash never fires int flashMode = FLASH_MODE_OFF; // If there is no flash on this camera, the state is always unavailable // , otherwise it's only known for TORCH/SINGLE modes Integer flashState = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE) ? null : FLASH_STATE_UNAVAILABLE; int aeMode = CONTROL_AE_MODE_ON; String flashModeSetting = p.getFlashMode(); if (flashModeSetting != null) { switch (flashModeSetting) { case Parameters.FLASH_MODE_OFF: break; // ok, using default case Parameters.FLASH_MODE_AUTO: aeMode = CONTROL_AE_MODE_ON_AUTO_FLASH; break; case Parameters.FLASH_MODE_ON: // flashMode = SINGLE + aeMode = ON is indistinguishable from ON_ALWAYS_FLASH flashMode = FLASH_MODE_SINGLE; aeMode = CONTROL_AE_MODE_ON_ALWAYS_FLASH; flashState = FLASH_STATE_FIRED; break; case Parameters.FLASH_MODE_RED_EYE: aeMode = CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE; break; case Parameters.FLASH_MODE_TORCH: flashMode = FLASH_MODE_TORCH; flashState = FLASH_STATE_FIRED; break; default: Log.w(TAG, "mapAeAndFlashMode - Ignoring unknown flash mode " + p.getFlashMode()); } } // flash.state m.set(FLASH_STATE, flashState); // flash.mode m.set(FLASH_MODE, flashMode); // control.aeMode m.set(CONTROL_AE_MODE, aeMode); }