Added buttons

pull/17/head
Florent CHAMPIGNY 8 years ago
parent 11d4958461
commit cd69904e59
  1. 10
      README.md
  2. 5
      app/src/main/java/com/github/florent37/camerafragment/sample/MainActivity.java
  3. 31
      app/src/main/res/layout/activity_fragment.xml
  4. 49
      app/src/main/res/layout/sample.xml
  5. 11
      camerafragment/src/main/java/com/github/florent37/camerafragment/configuration/Configuration.java
  6. 30
      camerafragment/src/main/java/com/github/florent37/camerafragment/internal/manager/impl/Camera1Manager.java
  7. 47
      camerafragment/src/main/java/com/github/florent37/camerafragment/internal/manager/impl/Camera2Manager.java
  8. 15
      camerafragment/src/main/java/com/github/florent37/camerafragment/widgets/CameraSettingsView.java
  9. 2
      camerafragment/src/main/java/com/github/florent37/camerafragment/widgets/CameraSwitchView.java
  10. 1
      camerafragment/src/main/java/com/github/florent37/camerafragment/widgets/FlashSwitchView.java
  11. 2
      camerafragment/src/main/java/com/github/florent37/camerafragment/widgets/MediaActionSwitchView.java
  12. 2
      camerafragment/src/main/java/com/github/florent37/camerafragment/widgets/RecordButton.java
  13. BIN
      media/buttons.png

@ -115,4 +115,12 @@ cameraFragment.setStateListener(new CameraFragmentStateListener() {
## Text ## Text
CameraFragment can ping you with the current record duration with `CameraFragmentTextListener` CameraFragment can ping you with the current record duration with `CameraFragmentTextListener`
# Widgets
CameraFragment comes with some default views
`RecordButton`, `MediaActionSwitchView`, `FlashSwitchView`, `CameraSwitchView`, `CameraSettingsView`
[![png](https://raw.githubusercontent.com/florent37/CameraFragment/master/media/buttons.png)](https://github.com/florent37/CameraFragment)

@ -302,11 +302,6 @@ public class MainActivity extends AppCompatActivity {
} }
cameraSwitchView.displayBackCamera();
flashSwitchView.displayFlashAuto();
recordButton.displayPhotoState();
mediaActionSwitchView.displayActionWillSwitchVideo();
} }
private CameraFragmentApi getCameraFragment() { private CameraFragmentApi getCameraFragment() {

@ -15,6 +15,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="15dp" android:layout_margin="15dp"
tools:visibility="gone"
android:text="Add camera" /> android:text="Add camera" />
<RelativeLayout <RelativeLayout
@ -40,9 +41,7 @@
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_marginLeft="15dp" android:layout_marginLeft="15dp"
android:background="@drawable/circle_frame_background_dark" />
android:scaleType="center"
android:src="@drawable/ic_settings_white_24dp" />
<com.github.florent37.camerafragment.widgets.FlashSwitchView <com.github.florent37.camerafragment.widgets.FlashSwitchView
android:id="@+id/flash_switch_view" android:id="@+id/flash_switch_view"
@ -66,8 +65,10 @@
android:id="@+id/record_panel" android:id="@+id/record_panel"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="150dp" android:layout_height="150dp"
android:background="@android:color/transparent"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:background="@android:color/transparent"> android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<com.github.florent37.camerafragment.widgets.RecordButton <com.github.florent37.camerafragment.widgets.RecordButton
android:id="@+id/record_button" android:id="@+id/record_button"
@ -77,16 +78,6 @@
android:layout_marginLeft="50dp" android:layout_marginLeft="50dp"
android:layout_marginRight="50dp" /> android:layout_marginRight="50dp" />
<com.github.florent37.camerafragment.widgets.MediaActionSwitchView
android:id="@+id/photo_video_camera_switcher"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="40dp"
android:checked="false"
android:gravity="center" />
<TextView <TextView
android:id="@+id/record_duration_text" android:id="@+id/record_duration_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -107,6 +98,18 @@
android:textSize="14dp" android:textSize="14dp"
android:visibility="invisible" /> android:visibility="invisible" />
<com.github.florent37.camerafragment.widgets.MediaActionSwitchView
android:id="@+id/photo_video_camera_switcher"
android:layout_width="40dp"
android:layout_height="40dp"
android:checked="false"
android:gravity="center"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/record_size_mb_text"
android:layout_toEndOf="@+id/record_size_mb_text"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp" />
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<com.github.florent37.camerafragment.widgets.RecordButton
android:id="@+id/record_button"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_centerInParent="true" android:layout_margin="10dp"
/>
<com.github.florent37.camerafragment.widgets.MediaActionSwitchView
android:id="@+id/photo_video_camera_switcher"
android:layout_width="40dp"
android:layout_height="40dp"
android:checked="false"
android:gravity="center"
android:layout_margin="10dp"
/>
<com.github.florent37.camerafragment.widgets.FlashSwitchView
android:id="@+id/flash_switch_view"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:layout_margin="10dp"
/>
<com.github.florent37.camerafragment.widgets.CameraSwitchView
android:id="@+id/front_back_camera_switcher"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
/>
<com.github.florent37.camerafragment.widgets.CameraSettingsView
android:id="@+id/settings_view"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
/>
</LinearLayout>

@ -45,17 +45,6 @@ public final class Configuration implements Serializable {
public static final int FLASH_MODE_OFF = 2; public static final int FLASH_MODE_OFF = 2;
public static final int FLASH_MODE_AUTO = 3; public static final int FLASH_MODE_AUTO = 3;
public interface Arguments {
String REQUEST_CODE = "io.memfis19.annca.request_code";
String MEDIA_ACTION = "io.memfis19.annca.media_action";
String MEDIA_QUALITY = "io.memfis19.annca.camera_media_quality";
String VIDEO_DURATION = "io.memfis19.annca.video_duration";
String MINIMUM_VIDEO_DURATION = "io.memfis19.annca.minimum.video_duration";
String VIDEO_FILE_SIZE = "io.memfis19.annca.camera_video_file_size";
String FLASH_MODE = "io.memfis19.annca.camera_flash_mode";
String FILE_PATH = "io.memfis19.annca.camera_video_file_path";
}
@IntDef({MEDIA_QUALITY_AUTO, MEDIA_QUALITY_LOWEST, MEDIA_QUALITY_LOW, MEDIA_QUALITY_MEDIUM, MEDIA_QUALITY_HIGH, MEDIA_QUALITY_HIGHEST}) @IntDef({MEDIA_QUALITY_AUTO, MEDIA_QUALITY_LOWEST, MEDIA_QUALITY_LOW, MEDIA_QUALITY_MEDIUM, MEDIA_QUALITY_HIGH, MEDIA_QUALITY_HIGHEST})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface MediaQuality { public @interface MediaQuality {

@ -230,7 +230,7 @@ public class Camera1Manager extends BaseCameraManager<Integer, SurfaceHolder.Cal
numberOfCameras = Camera.getNumberOfCameras(); numberOfCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numberOfCameras; ++i) { for (int i = 0; i < numberOfCameras; ++i) {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); final Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(i, cameraInfo); Camera.getCameraInfo(i, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
@ -256,8 +256,8 @@ public class Camera1Manager extends BaseCameraManager<Integer, SurfaceHolder.Cal
} else } else
camcorderProfile = CameraHelper.getCamcorderProfile(configurationProvider.getMediaQuality(), currentCameraId); camcorderProfile = CameraHelper.getCamcorderProfile(configurationProvider.getMediaQuality(), currentCameraId);
List<Size> previewSizes = Size.fromList(camera.getParameters().getSupportedPreviewSizes()); final List<Size> previewSizes = Size.fromList(camera.getParameters().getSupportedPreviewSizes());
List<Size> pictureSizes = Size.fromList(camera.getParameters().getSupportedPictureSizes()); final List<Size> pictureSizes = Size.fromList(camera.getParameters().getSupportedPictureSizes());
List<Size> videoSizes; List<Size> videoSizes;
if (Build.VERSION.SDK_INT > 10) if (Build.VERSION.SDK_INT > 10)
videoSizes = Size.fromList(camera.getParameters().getSupportedVideoSizes()); videoSizes = Size.fromList(camera.getParameters().getSupportedVideoSizes());
@ -360,11 +360,11 @@ public class Camera1Manager extends BaseCameraManager<Integer, SurfaceHolder.Cal
private void startPreview(SurfaceHolder surfaceHolder) { private void startPreview(SurfaceHolder surfaceHolder) {
try { try {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); final Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(currentCameraId, cameraInfo); Camera.getCameraInfo(currentCameraId, cameraInfo);
int cameraRotationOffset = cameraInfo.orientation; int cameraRotationOffset = cameraInfo.orientation;
Camera.Parameters parameters = camera.getParameters(); final Camera.Parameters parameters = camera.getParameters();
setAutoFocus(camera, parameters); setAutoFocus(camera, parameters);
setFlashMode(configurationProvider.getFlashMode()); setFlashMode(configurationProvider.getFlashMode());
@ -374,7 +374,7 @@ public class Camera1Manager extends BaseCameraManager<Integer, SurfaceHolder.Cal
else if (configurationProvider.getMediaAction() == Configuration.MEDIA_ACTION_PHOTO) else if (configurationProvider.getMediaAction() == Configuration.MEDIA_ACTION_PHOTO)
turnVideoCameraFeaturesOn(camera, parameters); turnVideoCameraFeaturesOn(camera, parameters);
int rotation = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); final int rotation = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
int degrees = 0; int degrees = 0;
switch (rotation) { switch (rotation) {
case Surface.ROTATION_0: case Surface.ROTATION_0:
@ -475,7 +475,7 @@ public class Camera1Manager extends BaseCameraManager<Integer, SurfaceHolder.Cal
} }
private void setCameraPhotoQuality(Camera camera) { private void setCameraPhotoQuality(Camera camera) {
Camera.Parameters parameters = camera.getParameters(); final Camera.Parameters parameters = camera.getParameters();
parameters.setPictureFormat(PixelFormat.JPEG); parameters.setPictureFormat(PixelFormat.JPEG);
@ -495,7 +495,7 @@ public class Camera1Manager extends BaseCameraManager<Integer, SurfaceHolder.Cal
@Override @Override
protected int getPhotoOrientation(@Configuration.SensorPosition int sensorPosition) { protected int getPhotoOrientation(@Configuration.SensorPosition int sensorPosition) {
int rotate; final int rotate;
if (currentCameraId.equals(faceFrontCameraId)) { if (currentCameraId.equals(faceFrontCameraId)) {
rotate = (360 + faceFrontCameraOrientation + configurationProvider.getDegrees()) % 360; rotate = (360 + faceFrontCameraOrientation + configurationProvider.getDegrees()) % 360;
} else { } else {
@ -534,7 +534,7 @@ public class Camera1Manager extends BaseCameraManager<Integer, SurfaceHolder.Cal
break;// Landscape right break;// Landscape right
} }
int rotate; final int rotate;
if (currentCameraId.equals(faceFrontCameraId)) { if (currentCameraId.equals(faceFrontCameraId)) {
rotate = (360 + faceFrontCameraOrientation + degrees) % 360; rotate = (360 + faceFrontCameraOrientation + degrees) % 360;
} else { } else {
@ -544,7 +544,7 @@ public class Camera1Manager extends BaseCameraManager<Integer, SurfaceHolder.Cal
} }
protected void onPictureTaken(final byte[] bytes, Camera camera, final CameraFragmentResultListener callback) { protected void onPictureTaken(final byte[] bytes, Camera camera, final CameraFragmentResultListener callback) {
File pictureFile = outputPath; final File pictureFile = outputPath;
if (pictureFile == null) { if (pictureFile == null) {
Log.d(TAG, "Error creating media file, check storage permissions."); Log.d(TAG, "Error creating media file, check storage permissions.");
return; return;
@ -563,7 +563,7 @@ public class Camera1Manager extends BaseCameraManager<Integer, SurfaceHolder.Cal
} }
try { try {
ExifInterface exif = new ExifInterface(pictureFile.getAbsolutePath()); final ExifInterface exif = new ExifInterface(pictureFile.getAbsolutePath());
exif.setAttribute(ExifInterface.TAG_ORIENTATION, "" + getPhotoOrientation(configurationProvider.getSensorPosition())); exif.setAttribute(ExifInterface.TAG_ORIENTATION, "" + getPhotoOrientation(configurationProvider.getSensorPosition()));
exif.saveAttributes(); exif.saveAttributes();
@ -582,7 +582,7 @@ public class Camera1Manager extends BaseCameraManager<Integer, SurfaceHolder.Cal
@Override @Override
public CharSequence[] getVideoQualityOptions() { public CharSequence[] getVideoQualityOptions() {
List<CharSequence> videoQualities = new ArrayList<>(); final List<CharSequence> videoQualities = new ArrayList<>();
if (configurationProvider.getMinimumVideoDuration() > 0) if (configurationProvider.getMinimumVideoDuration() > 0)
videoQualities.add(new VideoQualityOption(Configuration.MEDIA_QUALITY_AUTO, CameraHelper.getCamcorderProfile(Configuration.MEDIA_QUALITY_AUTO, getCurrentCameraId()), configurationProvider.getMinimumVideoDuration())); videoQualities.add(new VideoQualityOption(Configuration.MEDIA_QUALITY_AUTO, CameraHelper.getCamcorderProfile(Configuration.MEDIA_QUALITY_AUTO, getCurrentCameraId()), configurationProvider.getMinimumVideoDuration()));
@ -599,7 +599,7 @@ public class Camera1Manager extends BaseCameraManager<Integer, SurfaceHolder.Cal
videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, configurationProvider.getVideoFileSize()); videoDuration = CameraHelper.calculateApproximateVideoDuration(camcorderProfile, configurationProvider.getVideoFileSize());
videoQualities.add(new VideoQualityOption(Configuration.MEDIA_QUALITY_LOW, camcorderProfile, videoDuration)); videoQualities.add(new VideoQualityOption(Configuration.MEDIA_QUALITY_LOW, camcorderProfile, videoDuration));
CharSequence[] array = new CharSequence[videoQualities.size()]; final CharSequence[] array = new CharSequence[videoQualities.size()];
videoQualities.toArray(array); videoQualities.toArray(array);
return array; return array;
@ -607,13 +607,13 @@ public class Camera1Manager extends BaseCameraManager<Integer, SurfaceHolder.Cal
@Override @Override
public CharSequence[] getPhotoQualityOptions() { public CharSequence[] getPhotoQualityOptions() {
List<CharSequence> photoQualities = new ArrayList<>(); final List<CharSequence> photoQualities = new ArrayList<>();
photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_HIGHEST, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_HIGHEST))); photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_HIGHEST, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_HIGHEST)));
photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_HIGH, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_HIGH))); photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_HIGH, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_HIGH)));
photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_MEDIUM, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_MEDIUM))); photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_MEDIUM, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_MEDIUM)));
photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_LOWEST, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_LOWEST))); photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_LOWEST, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_LOWEST)));
CharSequence[] array = new CharSequence[photoQualities.size()]; final CharSequence[] array = new CharSequence[photoQualities.size()];
photoQualities.toArray(array); photoQualities.toArray(array);
return array; return array;

@ -122,8 +122,7 @@ public final class Camera2Manager extends BaseCameraManager<String, TextureView.
}); });
} }
}; };
private CameraCaptureSession.CaptureCallback captureCallback private CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback() {
= new CameraCaptureSession.CaptureCallback() {
@Override @Override
public void onCaptureProgressed(@NonNull CameraCaptureSession session, public void onCaptureProgressed(@NonNull CameraCaptureSession session,
@ -148,19 +147,19 @@ public final class Camera2Manager extends BaseCameraManager<String, TextureView.
this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay(); final Display display = windowManager.getDefaultDisplay();
Point size = new Point(); final Point size = new Point();
display.getSize(size); display.getSize(size);
windowSize = new Size(size.x, size.y); windowSize = new Size(size.x, size.y);
try { try {
String[] ids = manager.getCameraIdList(); final String[] ids = manager.getCameraIdList();
numberOfCameras = ids.length; numberOfCameras = ids.length;
for (String id : ids) { for (String id : ids) {
CameraCharacteristics characteristics = manager.getCameraCharacteristics(id); final CameraCharacteristics characteristics = manager.getCameraCharacteristics(id);
int orientation = characteristics.get(CameraCharacteristics.LENS_FACING); final int orientation = characteristics.get(CameraCharacteristics.LENS_FACING);
if (orientation == CameraCharacteristics.LENS_FACING_FRONT) { if (orientation == CameraCharacteristics.LENS_FACING_FRONT) {
faceFrontCameraId = id; faceFrontCameraId = id;
faceFrontCameraOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); faceFrontCameraOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
@ -253,7 +252,7 @@ public final class Camera2Manager extends BaseCameraManager<String, TextureView.
@Override @Override
public Size getPhotoSizeForQuality(@Configuration.MediaQuality int mediaQuality) { public Size getPhotoSizeForQuality(@Configuration.MediaQuality int mediaQuality) {
StreamConfigurationMap map = currentCameraId.equals(faceBackCameraId) ? backCameraStreamConfigurationMap : frontCameraStreamConfigurationMap; final StreamConfigurationMap map = currentCameraId.equals(faceBackCameraId) ? backCameraStreamConfigurationMap : frontCameraStreamConfigurationMap;
return CameraHelper.getPictureSize(Size.fromArray2(map.getOutputSizes(ImageFormat.JPEG)), mediaQuality); return CameraHelper.getPictureSize(Size.fromArray2(map.getOutputSizes(ImageFormat.JPEG)), mediaQuality);
} }
@ -271,14 +270,14 @@ public final class Camera2Manager extends BaseCameraManager<String, TextureView.
closePreviewSession(); closePreviewSession();
if (prepareVideoRecorder()) { if (prepareVideoRecorder()) {
SurfaceTexture texture = Camera2Manager.this.texture; final SurfaceTexture texture = Camera2Manager.this.texture;
texture.setDefaultBufferSize(videoSize.getWidth(), videoSize.getHeight()); texture.setDefaultBufferSize(videoSize.getWidth(), videoSize.getHeight());
try { try {
previewRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); previewRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
List<Surface> surfaces = new ArrayList<>(); final List<Surface> surfaces = new ArrayList<>();
Surface previewSurface = workingSurface; final Surface previewSurface = workingSurface;
surfaces.add(previewSurface); surfaces.add(previewSurface);
previewRequestBuilder.addTarget(previewSurface); previewRequestBuilder.addTarget(previewSurface);
@ -406,7 +405,7 @@ public final class Camera2Manager extends BaseCameraManager<String, TextureView.
@Override @Override
protected int getVideoOrientation(@Configuration.SensorPosition int sensorPosition) { protected int getVideoOrientation(@Configuration.SensorPosition int sensorPosition) {
int degrees = 0; final int degrees;
switch (sensorPosition) { switch (sensorPosition) {
case Configuration.SENSOR_POSITION_UP: case Configuration.SENSOR_POSITION_UP:
degrees = 0; degrees = 0;
@ -421,10 +420,12 @@ public final class Camera2Manager extends BaseCameraManager<String, TextureView.
degrees = 270; degrees = 270;
break;// Landscape right break;// Landscape right
case Configuration.SENSOR_POSITION_UNSPECIFIED: case Configuration.SENSOR_POSITION_UNSPECIFIED:
default:
degrees = 0;
break; break;
} }
int rotate; final int rotate;
if (Objects.equals(currentCameraId, faceFrontCameraId)) { if (Objects.equals(currentCameraId, faceFrontCameraId)) {
rotate = (360 + faceFrontCameraOrientation + degrees) % 360; rotate = (360 + faceFrontCameraOrientation + degrees) % 360;
} else { } else {
@ -465,14 +466,14 @@ public final class Camera2Manager extends BaseCameraManager<String, TextureView.
@Override @Override
protected void prepareCameraOutputs() { protected void prepareCameraOutputs() {
try { try {
CameraCharacteristics characteristics = currentCameraId.equals(faceBackCameraId) ? backCameraCharacteristics : frontCameraCharacteristics; final CameraCharacteristics characteristics = currentCameraId.equals(faceBackCameraId) ? backCameraCharacteristics : frontCameraCharacteristics;
if (currentCameraId.equals(faceFrontCameraId) && frontCameraStreamConfigurationMap == null) if (currentCameraId.equals(faceFrontCameraId) && frontCameraStreamConfigurationMap == null)
frontCameraStreamConfigurationMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); frontCameraStreamConfigurationMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
else if (currentCameraId.equals(faceBackCameraId) && backCameraStreamConfigurationMap == null) else if (currentCameraId.equals(faceBackCameraId) && backCameraStreamConfigurationMap == null)
backCameraStreamConfigurationMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); backCameraStreamConfigurationMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
StreamConfigurationMap map = currentCameraId.equals(faceBackCameraId) ? backCameraStreamConfigurationMap : frontCameraStreamConfigurationMap; final StreamConfigurationMap map = currentCameraId.equals(faceBackCameraId) ? backCameraStreamConfigurationMap : frontCameraStreamConfigurationMap;
if (configurationProvider.getMediaQuality() == Configuration.MEDIA_QUALITY_AUTO) { if (configurationProvider.getMediaQuality() == Configuration.MEDIA_QUALITY_AUTO) {
camcorderProfile = CameraHelper.getCamcorderProfile(currentCameraId, configurationProvider.getVideoFileSize(), configurationProvider.getMinimumVideoDuration()); camcorderProfile = CameraHelper.getCamcorderProfile(currentCameraId, configurationProvider.getVideoFileSize(), configurationProvider.getMinimumVideoDuration());
} else } else
@ -607,7 +608,7 @@ public final class Camera2Manager extends BaseCameraManager<String, TextureView.
break; break;
} }
case STATE_WAITING_LOCK: { case STATE_WAITING_LOCK: {
Integer afState = result.get(CaptureResult.CONTROL_AF_STATE); final Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
if (afState == null) { if (afState == null) {
captureStillPicture(); captureStillPicture();
} else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState } else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState
@ -626,7 +627,7 @@ public final class Camera2Manager extends BaseCameraManager<String, TextureView.
break; break;
} }
case STATE_WAITING_PRE_CAPTURE: { case STATE_WAITING_PRE_CAPTURE: {
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); final Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
if (aeState == null || if (aeState == null ||
aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE || aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE ||
aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) { aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
@ -635,7 +636,7 @@ public final class Camera2Manager extends BaseCameraManager<String, TextureView.
break; break;
} }
case STATE_WAITING_NON_PRE_CAPTURE: { case STATE_WAITING_NON_PRE_CAPTURE: {
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); final Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) { if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
previewState = STATE_PICTURE_TAKEN; previewState = STATE_PICTURE_TAKEN;
captureStillPicture(); captureStillPicture();
@ -732,7 +733,7 @@ public final class Camera2Manager extends BaseCameraManager<String, TextureView.
@Override @Override
public void onImageAvailable(ImageReader imageReader) { public void onImageAvailable(ImageReader imageReader) {
File outputFile = outputPath; final File outputFile = outputPath;
backgroundHandler.post(new ImageSaver(imageReader.acquireNextImage(), outputFile, new ImageSaver.ImageSaverCallback() { backgroundHandler.post(new ImageSaver(imageReader.acquireNextImage(), outputFile, new ImageSaver.ImageSaverCallback() {
@Override @Override
public void onSuccessFinish(final byte[] bytes) { public void onSuccessFinish(final byte[] bytes) {
@ -783,7 +784,7 @@ public final class Camera2Manager extends BaseCameraManager<String, TextureView.
@Override @Override
public CharSequence[] getVideoQualityOptions() { public CharSequence[] getVideoQualityOptions() {
List<CharSequence> videoQualities = new ArrayList<>(); final List<CharSequence> videoQualities = new ArrayList<>();
if (configurationProvider.getMinimumVideoDuration() > 0) if (configurationProvider.getMinimumVideoDuration() > 0)
videoQualities.add(new VideoQualityOption(Configuration.MEDIA_QUALITY_AUTO, CameraHelper.getCamcorderProfile(Configuration.MEDIA_QUALITY_AUTO, getCurrentCameraId()), configurationProvider.getMinimumVideoDuration())); videoQualities.add(new VideoQualityOption(Configuration.MEDIA_QUALITY_AUTO, CameraHelper.getCamcorderProfile(Configuration.MEDIA_QUALITY_AUTO, getCurrentCameraId()), configurationProvider.getMinimumVideoDuration()));
@ -809,13 +810,13 @@ public final class Camera2Manager extends BaseCameraManager<String, TextureView.
@Override @Override
public CharSequence[] getPhotoQualityOptions() { public CharSequence[] getPhotoQualityOptions() {
List<CharSequence> photoQualities = new ArrayList<>(); final List<CharSequence> photoQualities = new ArrayList<>();
photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_HIGHEST, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_HIGHEST))); photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_HIGHEST, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_HIGHEST)));
photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_HIGH, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_HIGH))); photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_HIGH, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_HIGH)));
photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_MEDIUM, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_MEDIUM))); photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_MEDIUM, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_MEDIUM)));
photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_LOWEST, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_LOWEST))); photoQualities.add(new PhotoQualityOption(Configuration.MEDIA_QUALITY_LOWEST, getPhotoSizeForQuality(Configuration.MEDIA_QUALITY_LOWEST)));
CharSequence[] array = new CharSequence[photoQualities.size()]; final CharSequence[] array = new CharSequence[photoQualities.size()];
photoQualities.toArray(array); photoQualities.toArray(array);
return array; return array;

@ -6,25 +6,36 @@ import android.os.Build;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.ImageButton; import android.widget.ImageButton;
import com.github.florent37.camerafragment.R;
/** /**
* Created by memfis on 8/23/16. * Created by memfis on 8/23/16.
*/ */
public class CameraSettingsView extends ImageButton { public class CameraSettingsView extends ImageButton {
public CameraSettingsView(Context context) { public CameraSettingsView(Context context) {
super(context); this(context, null);
} }
public CameraSettingsView(Context context, AttributeSet attrs) { public CameraSettingsView(Context context, AttributeSet attrs) {
super(context, attrs); this(context, attrs, 0);
} }
public CameraSettingsView(Context context, AttributeSet attrs, int defStyleAttr) { public CameraSettingsView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
init();
} }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @TargetApi(Build.VERSION_CODES.LOLLIPOP)
public CameraSettingsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { public CameraSettingsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
setBackgroundResource(R.drawable.circle_frame_background_dark);
setImageResource(R.drawable.ic_settings_white_24dp);
setScaleType(ScaleType.CENTER);
} }
@Override @Override

@ -50,6 +50,8 @@ public class CameraSwitchView extends AppCompatImageButton {
padding = Utils.convertDipToPixels(context, padding); padding = Utils.convertDipToPixels(context, padding);
setPadding(padding, padding, padding, padding); setPadding(padding, padding, padding, padding);
displayBackCamera();
} }
public void displayFrontCamera() { public void displayFrontCamera() {

@ -37,6 +37,7 @@ public class FlashSwitchView extends ImageButton {
private void init() { private void init() {
setBackgroundColor(Color.TRANSPARENT); setBackgroundColor(Color.TRANSPARENT);
displayFlashAuto();
} }
public void displayFlashOff() { public void displayFlashOff() {

@ -67,6 +67,8 @@ public class MediaActionSwitchView extends ImageButton {
padding = Utils.convertDipToPixels(context, padding); padding = Utils.convertDipToPixels(context, padding);
setPadding(padding, padding, padding, padding); setPadding(padding, padding, padding, padding);
displayActionWillSwitchVideo();
} }
public void displayActionWillSwitchPhoto(){ public void displayActionWillSwitchPhoto(){

@ -68,6 +68,8 @@ public class RecordButton extends ImageButton {
}); });
setSoundEffectsEnabled(false); setSoundEffectsEnabled(false);
setIconPadding(iconPadding); setIconPadding(iconPadding);
displayPhotoState();
} }
//public void setup(@Configuration.MediaAction int mediaAction) { //public void setup(@Configuration.MediaAction int mediaAction) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Loading…
Cancel
Save