9
0
mirror of https://gitee.com/shuto/customCamera.git synced 2026-05-02 00:07:24 +08:00

Ajout du flash à la camera

This commit is contained in:
Thomas BOY
2015-01-26 15:18:34 +01:00
parent 96a5da95ca
commit 5b2700ca68
4 changed files with 73 additions and 0 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

@@ -21,6 +21,24 @@
android:alpha="0.2"
android:scaleType="fitXY" />
<ImageButton
android:id="@+id/flash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="@android:color/transparent"
android:onClick="enableFlash"
android:src="@drawable/flash" />
<ImageButton
android:id="@+id/noFlash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="@android:color/transparent"
android:onClick="enableFlash"
android:src="@drawable/no_flash" />
<LinearLayout
android:id="@+id/beforePhoto"
android:layout_width="match_parent"
@@ -859,4 +859,59 @@ public class CameraActivity extends Activity {
this.setResult(3);
this.finish();
}
/**
* Allow to enable or disable the flash of the camera.
* @param view The current view.
*/
public void enableFlash(View view) {
ImageButton flash = (ImageButton)findViewById(R.id.flash);
ImageButton noFlash = (ImageButton)findViewById(R.id.noFlash);
Camera.Parameters params = customCamera.getParameters();
if (hasFlash()) {
if (params.getFlashMode().equals(Camera.Parameters.FLASH_MODE_ON)
|| params.getFlashMode().equals(Camera.Parameters.FLASH_MODE_AUTO)
|| params.getFlashMode().equals(Camera.Parameters.FLASH_MODE_RED_EYE)
|| params.getFlashMode().equals(Camera.Parameters.FLASH_MODE_TORCH)) {
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
noFlash.setVisibility(View.VISIBLE);
flash.setVisibility(View.INVISIBLE);
} else if (params.getFlashMode().equals(Camera.Parameters.FLASH_MODE_OFF)) {
params.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
noFlash.setVisibility(View.INVISIBLE);
flash.setVisibility(View.VISIBLE);
}
customCamera.setParameters(params);
} else {
flash.setVisibility(View.INVISIBLE);
noFlash.setVisibility(View.INVISIBLE);
}
}
/**
* Check if camera has a flash feature.
* @return boolean.
*/
public boolean hasFlash() {
if (customCamera == null) {
return false;
}
Camera.Parameters parameters = customCamera.getParameters();
if (parameters.getFlashMode() == null) {
return false;
}
List<String> supportedFlashModes = parameters.getSupportedFlashModes();
if (supportedFlashModes == null
|| supportedFlashModes.isEmpty()
|| supportedFlashModes.size() == 1
&& supportedFlashModes.get(0).equals(Camera.Parameters.FLASH_MODE_OFF)) {
return false;
}
return true;
}
}