diff --git a/README.md b/README.md
index db59d50..165ce20 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ getSupportFragmentManager().beginTransaction()
You can directly take a photo / video with
```java
-cameraFragment.takePhotoOrCaptureVideo();
+cameraFragment.takePhotoOrCaptureVideo(callback);
```
[![gif](https://raw.githubusercontent.com/florent37/CameraFragment/master/media/take_photo.gif)](https://github.com/florent37/CameraFragment)
@@ -39,7 +39,7 @@ cameraFragment.switchCameraType();
Camera action ( `PHOTO` / `VIDEO` ) can be modified with
```java
-cameraFragment.switchAction();
+cameraFragment.switchActionPhotoVideo();
```
[![gif](https://raw.githubusercontent.com/florent37/CameraFragment/master/media/switch_action.gif)](https://github.com/florent37/CameraFragment)
diff --git a/app/src/main/java/com/github/florent37/camerafragment/sample/MainActivity.java b/app/src/main/java/com/github/florent37/camerafragment/sample/MainActivity.java
index 4cfb750..96adc0b 100644
--- a/app/src/main/java/com/github/florent37/camerafragment/sample/MainActivity.java
+++ b/app/src/main/java/com/github/florent37/camerafragment/sample/MainActivity.java
@@ -21,6 +21,7 @@ import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.github.florent37.camerafragment.CameraFragment;
+import com.github.florent37.camerafragment.CameraFragmentApi;
import com.github.florent37.camerafragment.configuration.Configuration;
import com.github.florent37.camerafragment.PreviewActivity;
import com.github.florent37.camerafragment.listeners.CameraFragmentStateListener;
@@ -57,74 +58,56 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
ButterKnife.bind(this);
+ }
- recordButton.setVisibility(View.GONE);
- settingsView.setVisibility(View.GONE);
- flashSwitchView.setVisibility(View.GONE);
- cameraSwitchView.setVisibility(View.GONE);
- mediaActionSwitchView.setVisibility(View.GONE);
-
- setupViewListeners();
+ @OnClick(R.id.flash_switch_view)
+ public void onFlashSwitcClicked(){
+ final CameraFragmentApi cameraFragment = getCameraFragment();
+ if (cameraFragment != null) {
+ cameraFragment.toggleFlashMode();
+ }
}
- @OnClick(R.id.take_photo)
- public void takePhotoClicked(){
- final CameraFragment cameraFragment = getCameraFragment();
+ @OnClick(R.id.front_back_camera_switcher)
+ public void onSwitchCameraClicked(){
+ final CameraFragmentApi cameraFragment = getCameraFragment();
if (cameraFragment != null) {
- cameraFragment.takePhotoOrCaptureVideo();
+ cameraFragment.switchCameraType();
}
}
- private void setupViewListeners() {
- flashSwitchView.setFlashSwitchListener(new FlashSwitchView.FlashModeSwitchListener() {
- @Override
- public void toggleFlashMode() {
- final CameraFragment cameraFragment = getCameraFragment();
- if (cameraFragment != null) {
- cameraFragment.toggleFlashMode();
- }
- }
- });
-
- cameraSwitchView.setOnCameraTypeChangeListener(new CameraSwitchView.OnCameraTypeChangeListener() {
- @Override
- public void switchCameraType() {
- final CameraFragment cameraFragment = getCameraFragment();
- if (cameraFragment != null) {
- cameraFragment.switchCameraType();
- }
- }
- });
-
- recordButton.setRecordButtonListener(new RecordButton.RecordButtonListener() {
- @Override
- public void onRecordButtonClicked() {
- final CameraFragment cameraFragment = getCameraFragment();
- if (cameraFragment != null) {
- cameraFragment.takePhotoOrCaptureVideo();
- }
- }
- });
-
- mediaActionSwitchView.setOnMediaActionStateChangeListener(new MediaActionSwitchView.OnMediaActionStateChangeListener() {
- @Override
- public void switchAction() {
- final CameraFragment cameraFragment = getCameraFragment();
- if (cameraFragment != null) {
- cameraFragment.switchAction();
+ @OnClick(R.id.record_button)
+ public void onRecordButtonClicked(){
+ final CameraFragmentApi cameraFragment = getCameraFragment();
+ if (cameraFragment != null) {
+ cameraFragment.takePhotoOrCaptureVideo(new CameraFragmentResultListener() {
+ @Override
+ public void onVideoRecorded(String filePath) {
+
}
- }
- });
-
- settingsView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- final CameraFragment cameraFragment = getCameraFragment();
- if (cameraFragment != null) {
- cameraFragment.openSettingDialog();
+
+ @Override
+ public void onPhotoTaken(byte[] bytes, String filePath) {
+
}
- }
- });
+ });
+ }
+ }
+
+ @OnClick(R.id.settings_view)
+ public void onSettingsClicked(){
+ final CameraFragmentApi cameraFragment = getCameraFragment();
+ if (cameraFragment != null) {
+ cameraFragment.openSettingDialog();
+ }
+ }
+
+ @OnClick(R.id.settings_view)
+ public void onMediaActionSwitchClicked(){
+ final CameraFragmentApi cameraFragment = getCameraFragment();
+ if (cameraFragment != null) {
+ cameraFragment.switchActionPhotoVideo();
+ }
}
@OnClick(R.id.addCameraButton)
@@ -169,7 +152,6 @@ public class MainActivity extends AppCompatActivity {
.commit();
if (cameraFragment != null) {
-
cameraFragment.setResultListener(new CameraFragmentResultListener() {
@Override
public void onVideoRecorded(String filePath) {
@@ -327,7 +309,7 @@ public class MainActivity extends AppCompatActivity {
mediaActionSwitchView.displayActionWillSwitchVideo();
}
- private CameraFragment getCameraFragment() {
- return (CameraFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
+ private CameraFragmentApi getCameraFragment() {
+ return (CameraFragmentApi) getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
}
}
diff --git a/app/src/main/res/layout/activity_fragment.xml b/app/src/main/res/layout/activity_fragment.xml
index 7b73767..fc650d7 100644
--- a/app/src/main/res/layout/activity_fragment.xml
+++ b/app/src/main/res/layout/activity_fragment.xml
@@ -73,18 +73,10 @@
android:id="@+id/record_button"
android:layout_width="75dp"
android:layout_height="75dp"
- android:visibility="gone"
android:layout_centerInParent="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp" />
-
-
{
void onDestroy();
- void takePhoto();
+ void takePhoto(CameraFragmentResultListener resultListener);
void startVideoRecord();
- void stopVideoRecord();
+ void stopVideoRecord(CameraFragmentResultListener callback);
boolean isVideoRecording();
diff --git a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/impl/Camera1Controller.java b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/impl/Camera1Controller.java
index 159866b..eb618d2 100644
--- a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/impl/Camera1Controller.java
+++ b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/impl/Camera1Controller.java
@@ -2,6 +2,7 @@ package com.github.florent37.camerafragment.internal.controller.impl;
import android.content.Context;
import android.os.Bundle;
+import android.support.annotation.Nullable;
import android.util.Log;
import android.view.SurfaceHolder;
@@ -20,6 +21,7 @@ import com.github.florent37.camerafragment.internal.manager.listener.CameraVideo
import com.github.florent37.camerafragment.internal.ui.view.AutoFitSurfaceView;
import com.github.florent37.camerafragment.internal.utils.CameraHelper;
import com.github.florent37.camerafragment.internal.utils.Size;
+import com.github.florent37.camerafragment.listeners.CameraFragmentResultListener;
/**
* Created by memfis on 7/7/16.
@@ -48,7 +50,7 @@ public class Camera1Controller implements CameraController,
@Override
public void onCreate(Bundle savedInstanceState) {
- cameraManager = Camera1Manager.getInstance();
+ cameraManager = new Camera1Manager();
cameraManager.initializeCameraManager(configurationProvider, context);
setCurrentCameraId(cameraManager.getFaceBackCameraId());
}
@@ -74,9 +76,9 @@ public class Camera1Controller implements CameraController,
}
@Override
- public void takePhoto() {
+ public void takePhoto(CameraFragmentResultListener callback) {
outputFile = CameraHelper.getOutputMediaFile(context, Configuration.MEDIA_ACTION_PHOTO);
- cameraManager.takePhoto(outputFile, this);
+ cameraManager.takePhoto(outputFile, this, callback);
}
@Override
@@ -86,8 +88,8 @@ public class Camera1Controller implements CameraController,
}
@Override
- public void stopVideoRecord() {
- cameraManager.stopVideoRecord();
+ public void stopVideoRecord(CameraFragmentResultListener callback) {
+ cameraManager.stopVideoRecord(callback);
}
@Override
@@ -154,8 +156,8 @@ public class Camera1Controller implements CameraController,
}
@Override
- public void onPhotoTaken(byte[] bytes, File photoFile) {
- cameraView.onPhotoTaken(bytes);
+ public void onPhotoTaken(byte[] bytes, File photoFile, CameraFragmentResultListener callback) {
+ cameraView.onPhotoTaken(bytes, callback);
}
@Override
@@ -168,8 +170,8 @@ public class Camera1Controller implements CameraController,
}
@Override
- public void onVideoRecordStopped(File videoFile) {
- cameraView.onVideoRecordStop();
+ public void onVideoRecordStopped(File videoFile, @Nullable CameraFragmentResultListener callback) {
+ cameraView.onVideoRecordStop(callback);
}
@Override
diff --git a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/impl/Camera2Controller.java b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/impl/Camera2Controller.java
index 081ec13..10994f4 100644
--- a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/impl/Camera2Controller.java
+++ b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/impl/Camera2Controller.java
@@ -4,6 +4,7 @@ import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.Nullable;
import android.util.Log;
import android.view.TextureView;
@@ -22,6 +23,7 @@ import com.github.florent37.camerafragment.internal.manager.listener.CameraVideo
import com.github.florent37.camerafragment.internal.ui.view.AutoFitTextureView;
import com.github.florent37.camerafragment.internal.utils.CameraHelper;
import com.github.florent37.camerafragment.internal.utils.Size;
+import com.github.florent37.camerafragment.listeners.CameraFragmentResultListener;
/**
* Created by memfis on 7/6/16.
@@ -49,7 +51,7 @@ public class Camera2Controller implements CameraController,
@Override
public void onCreate(Bundle savedInstanceState) {
- camera2Manager = Camera2Manager.getInstance();
+ camera2Manager = new Camera2Manager();
camera2Manager.initializeCameraManager(configurationProvider, context);
setCurrentCameraId(camera2Manager.getFaceBackCameraId());
}
@@ -71,9 +73,9 @@ public class Camera2Controller implements CameraController,
}
@Override
- public void takePhoto() {
+ public void takePhoto(CameraFragmentResultListener callback) {
outputFile = CameraHelper.getOutputMediaFile(context, Configuration.MEDIA_ACTION_PHOTO);
- camera2Manager.takePhoto(outputFile, this);
+ camera2Manager.takePhoto(outputFile, this, callback);
}
@Override
@@ -83,8 +85,8 @@ public class Camera2Controller implements CameraController,
}
@Override
- public void stopVideoRecord() {
- camera2Manager.stopVideoRecord();
+ public void stopVideoRecord(CameraFragmentResultListener callback) {
+ camera2Manager.stopVideoRecord(callback);
}
@Override
@@ -155,8 +157,8 @@ public class Camera2Controller implements CameraController,
}
@Override
- public void onPhotoTaken(byte[] bytes, File photoFile) {
- cameraView.onPhotoTaken(bytes);
+ public void onPhotoTaken(byte[] bytes, File photoFile, CameraFragmentResultListener callback) {
+ cameraView.onPhotoTaken(bytes, callback);
}
@Override
@@ -169,8 +171,8 @@ public class Camera2Controller implements CameraController,
}
@Override
- public void onVideoRecordStopped(File videoFile) {
- cameraView.onVideoRecordStop();
+ public void onVideoRecordStopped(File videoFile, @Nullable CameraFragmentResultListener callback) {
+ cameraView.onVideoRecordStop(callback);
}
@Override
diff --git a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/view/CameraView.java b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/view/CameraView.java
index 9a6adb5..c73a0c9 100644
--- a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/view/CameraView.java
+++ b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/controller/view/CameraView.java
@@ -1,9 +1,11 @@
package com.github.florent37.camerafragment.internal.controller.view;
+import android.support.annotation.Nullable;
import android.view.View;
import com.github.florent37.camerafragment.configuration.Configuration;
import com.github.florent37.camerafragment.internal.utils.Size;
+import com.github.florent37.camerafragment.listeners.CameraFragmentResultListener;
/**
* Created by memfis on 7/6/16.
@@ -16,11 +18,11 @@ public interface CameraView {
void updateCameraSwitcher(int numberOfCameras);
- void onPhotoTaken(byte[] bytes);
+ void onPhotoTaken(byte[] bytes, @Nullable CameraFragmentResultListener callback);
void onVideoRecordStart(int width, int height);
- void onVideoRecordStop();
+ void onVideoRecordStop(@Nullable CameraFragmentResultListener callback);
void releaseCameraPreview();
diff --git a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/manager/CameraManager.java b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/manager/CameraManager.java
index d909343..9a27309 100644
--- a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/manager/CameraManager.java
+++ b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/manager/CameraManager.java
@@ -11,6 +11,7 @@ import com.github.florent37.camerafragment.internal.manager.listener.CameraOpenL
import com.github.florent37.camerafragment.internal.manager.listener.CameraPhotoListener;
import com.github.florent37.camerafragment.internal.manager.listener.CameraVideoListener;
import com.github.florent37.camerafragment.internal.utils.Size;
+import com.github.florent37.camerafragment.listeners.CameraFragmentResultListener;
/**
* Created by memfis on 8/14/16.
@@ -25,13 +26,13 @@ public interface CameraManager {
void setFlashMode(@Configuration.FlashMode int flashMode);
- void takePhoto(File photoFile, CameraPhotoListener cameraPhotoListener);
+ void takePhoto(File photoFile, CameraPhotoListener cameraPhotoListener, CameraFragmentResultListener callback);
void startVideoRecord(File videoFile, CameraVideoListener cameraVideoListener);
Size getPhotoSizeForQuality(@Configuration.MediaQuality int mediaQuality);
- void stopVideoRecord();
+ void stopVideoRecord(CameraFragmentResultListener callback);
void releaseCameraManager();
diff --git a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/manager/impl/Camera1Manager.java b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/manager/impl/Camera1Manager.java
index e7d0843..19a8895 100644
--- a/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/manager/impl/Camera1Manager.java
+++ b/camerafragment/src/main/java/com/github/florent37/camerafragment/internal/manager/impl/Camera1Manager.java
@@ -7,6 +7,7 @@ import android.media.CamcorderProfile;
import android.media.ExifInterface;
import android.media.MediaRecorder;
import android.os.Build;
+import android.support.annotation.Nullable;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
@@ -29,21 +30,19 @@ import com.github.florent37.camerafragment.internal.ui.model.PhotoQualityOption;
import com.github.florent37.camerafragment.internal.ui.model.VideoQualityOption;
import com.github.florent37.camerafragment.internal.utils.CameraHelper;
import com.github.florent37.camerafragment.internal.utils.Size;
+import com.github.florent37.camerafragment.listeners.CameraFragmentResultListener;
/**
* Created by memfis on 8/14/16.
*/
@SuppressWarnings("deprecation")
-public class Camera1Manager extends BaseCameraManager
- implements SurfaceHolder.Callback, Camera.PictureCallback {
+public class Camera1Manager extends BaseCameraManager {
private static final String TAG = "Camera1Manager";
private Camera camera;
private Surface surface;
- private static Camera1Manager currentInstance;
-
private int orientation;
private int displayRotation = 0;
@@ -51,15 +50,6 @@ public class Camera1Manager extends BaseCameraManager cameraOpenListener) {
@@ -74,7 +64,44 @@ public class Camera1Manager extends BaseCameraManager cameraOpenListener;
private CameraPhotoListener cameraPhotoListener;
private CameraVideoListener cameraVideoListener;
-
private File outputPath;
-
@CameraPreviewState
private int previewState = STATE_PREVIEW;
- private static final int STATE_PREVIEW = 0;
- private static final int STATE_WAITING_LOCK = 1;
- private static final int STATE_WAITING_PRE_CAPTURE = 2;
- private static final int STATE_WAITING_NON_PRE_CAPTURE = 3;
- private static final int STATE_PICTURE_TAKEN = 4;
-
- @IntDef({STATE_PREVIEW, STATE_WAITING_LOCK, STATE_WAITING_PRE_CAPTURE, STATE_WAITING_NON_PRE_CAPTURE, STATE_PICTURE_TAKEN})
- @Retention(RetentionPolicy.SOURCE)
- @interface CameraPreviewState {
- }
-
private CameraManager manager;
private CameraDevice cameraDevice;
private CaptureRequest previewRequest;
private CaptureRequest.Builder previewRequestBuilder;
private CameraCaptureSession captureSession;
-
private CameraCharacteristics frontCameraCharacteristics;
private CameraCharacteristics backCameraCharacteristics;
private StreamConfigurationMap frontCameraStreamConfigurationMap;
private StreamConfigurationMap backCameraStreamConfigurationMap;
-
private SurfaceTexture texture;
-
private Surface workingSurface;
private ImageReader imageReader;
-
private CameraDevice.StateCallback stateCallback = new CameraDevice.StateCallback() {
@Override
public void onOpened(CameraDevice cameraDevice) {
- currentInstance.cameraDevice = cameraDevice;
+ Camera2Manager.this.cameraDevice = cameraDevice;
if (cameraOpenListener != null) {
uiHandler.post(new Runnable() {
@Override
public void run() {
- if (!TextUtils.isEmpty(currentCameraId) && previewSize != null && currentInstance != null)
- cameraOpenListener.onCameraOpened(currentCameraId, previewSize, currentInstance);
+ if (!TextUtils.isEmpty(currentCameraId) && previewSize != null)
+ cameraOpenListener.onCameraOpened(currentCameraId, previewSize, Camera2Manager.this);
}
});
}
@@ -113,7 +99,7 @@ public final class Camera2Manager extends BaseCameraManager extends Fragment {
+public abstract class BaseAnncaFragment extends Fragment implements CameraFragmentApi {
public static final String ARG_CONFIGURATION = "configuration";
public static final int MIN_VERSION_ICECREAM = Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1;
@@ -191,22 +192,25 @@ public abstract class BaseAnncaFragment extends Fragment {
}
@Override
- public void onPhotoTaken(byte[] bytes) {
+ public void onPhotoTaken(byte[] bytes, CameraFragmentResultListener callback) {
if (cameraFragmentResultListener != null) {
- final String filePath = getCameraController().getOutputFile().toString();
+ final String filePath = cameraController.getOutputFile().toString();
cameraFragmentResultListener.onPhotoTaken(bytes, filePath);
+ if (callback != null) {
+ callback.onPhotoTaken(bytes, filePath);
+ }
}
}
@Override
public void onVideoRecordStart(int width, int height) {
- final File outputFile = getCameraController().getOutputFile();
+ final File outputFile = cameraController.getOutputFile();
onStartVideoRecord(outputFile);
}
@Override
- public void onVideoRecordStop() {
- BaseAnncaFragment.this.onStopVideoRecord();
+ public void onVideoRecordStop(@Nullable CameraFragmentResultListener callback) {
+ BaseAnncaFragment.this.onStopVideoRecord(callback);
}
@Override
@@ -252,15 +256,16 @@ public abstract class BaseAnncaFragment extends Fragment {
}
- public void takePhotoOrCaptureVideo() {
+ @Override
+ public void takePhotoOrCaptureVideo(final CameraFragmentResultListener resultListener) {
switch (currentMediaActionState) {
case MediaAction.ACTION_PHOTO:
- takePhoto();
+ takePhoto(resultListener);
break;
case MediaAction.ACTION_VIDEO:
switch (currentRecordState) {
case Record.RECORD_IN_PROGRESS_STATE:
- stopRecording();
+ stopRecording(resultListener);
break;
default:
startRecording();
@@ -303,11 +308,11 @@ public abstract class BaseAnncaFragment extends Fragment {
cameraController.onDestroy();
}
- public void setMaxVideoFileSize(long maxVideoFileSize) {
+ protected void setMaxVideoFileSize(long maxVideoFileSize) {
this.maxVideoFileSize = maxVideoFileSize;
}
- public void setMaxVideoDuration(int maxVideoDurationInMillis) {
+ protected void setMaxVideoDuration(int maxVideoDurationInMillis) {
final TimerTaskBase.Callback callback = new TimerTaskBase.Callback() {
@Override
public void setText(String text) {
@@ -331,19 +336,30 @@ public abstract class BaseAnncaFragment extends Fragment {
}
}
+ @Override
public void openSettingDialog() {
final Context context = getContext();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
if (currentMediaActionState == MediaAction.ACTION_VIDEO) {
- builder.setSingleChoiceItems(videoQualities, getVideoOptionCheckedIndex(), getVideoOptionSelectedListener());
+ builder.setSingleChoiceItems(videoQualities, getVideoOptionCheckedIndex(), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int index) {
+ newQuality = ((VideoQualityOption) videoQualities[index]).getMediaQuality();
+ }
+ });
if (configurationProvider.getVideoFileSize() > 0)
builder.setTitle(String.format(getString(R.string.settings_video_quality_title),
"(Max " + String.valueOf(configurationProvider.getVideoFileSize() / (1024 * 1024) + " MB)")));
else
builder.setTitle(String.format(getString(R.string.settings_video_quality_title), ""));
} else {
- builder.setSingleChoiceItems(photoQualities, getPhotoOptionCheckedIndex(), getPhotoOptionSelectedListener());
+ builder.setSingleChoiceItems(photoQualities, getPhotoOptionCheckedIndex(), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int index) {
+ newQuality = ((PhotoQualityOption) photoQualities[index]).getMediaQuality();
+ }
+ });
builder.setTitle(R.string.settings_photo_quality_title);
}
@@ -356,7 +372,7 @@ public abstract class BaseAnncaFragment extends Fragment {
if (cameraFragmentControlsListener != null) {
cameraFragmentControlsListener.lockControls();
}
- getCameraController().switchQuality();
+ cameraController.switchQuality();
}
}
});
@@ -375,6 +391,7 @@ public abstract class BaseAnncaFragment extends Fragment {
settingsDialog.getWindow().setAttributes(layoutParams);
}
+ @Override
public void switchCameraType() {
if (cameraFragmentControlsListener != null) {
cameraFragmentControlsListener.lockControls();
@@ -399,10 +416,11 @@ public abstract class BaseAnncaFragment extends Fragment {
break;
}
- getCameraController().switchCamera(cameraFace);
+ this.cameraController.switchCamera(cameraFace);
}
- public void switchAction() {
+ @Override
+ public void switchActionPhotoVideo() {
switch (currentMediaActionState) {
case MediaAction.ACTION_PHOTO:
currentMediaActionState = MediaAction.ACTION_VIDEO;
@@ -419,6 +437,7 @@ public abstract class BaseAnncaFragment extends Fragment {
}
}
+ @Override
public void toggleFlashMode() {
switch (currentFlashMode) {
case Flash.FLASH_AUTO:
@@ -439,17 +458,17 @@ public abstract class BaseAnncaFragment extends Fragment {
case Flash.FLASH_AUTO:
if (cameraFragmentStateListener != null) cameraFragmentStateListener.onFlashAuto();
configurationProvider.setFlashMode(Configuration.FLASH_MODE_AUTO);
- getCameraController().setFlashMode(Configuration.FLASH_MODE_AUTO);
+ this.cameraController.setFlashMode(Configuration.FLASH_MODE_AUTO);
break;
case Flash.FLASH_ON:
if (cameraFragmentStateListener != null) cameraFragmentStateListener.onFlashOn();
configurationProvider.setFlashMode(Configuration.FLASH_MODE_ON);
- getCameraController().setFlashMode(Configuration.FLASH_MODE_ON);
+ this.cameraController.setFlashMode(Configuration.FLASH_MODE_ON);
break;
case Flash.FLASH_OFF:
if (cameraFragmentStateListener != null) cameraFragmentStateListener.onFlashOff();
configurationProvider.setFlashMode(Configuration.FLASH_MODE_OFF);
- getCameraController().setFlashMode(Configuration.FLASH_MODE_OFF);
+ this.cameraController.setFlashMode(Configuration.FLASH_MODE_OFF);
break;
}
}
@@ -461,12 +480,7 @@ public abstract class BaseAnncaFragment extends Fragment {
rotateSettingsDialog(degrees);
}
- @Record.RecordState
- public int getRecordState() {
- return currentRecordState;
- }
-
- public void setRecordState(@Record.RecordState int recordState) {
+ protected void setRecordState(@Record.RecordState int recordState) {
this.currentRecordState = recordState;
}
@@ -493,12 +507,12 @@ public abstract class BaseAnncaFragment extends Fragment {
// }
//}
- public void setFlashMode(@Flash.FlashMode int mode) {
+ protected void setFlashMode(@Flash.FlashMode int mode) {
this.currentFlashMode = mode;
onFlashModeChanged();
}
- private void rotateSettingsDialog(int degrees) {
+ protected void rotateSettingsDialog(int degrees) {
if (settingsDialog != null && settingsDialog.isShowing() && Build.VERSION.SDK_INT > 10) {
ViewGroup dialogView = (ViewGroup) settingsDialog.getWindow().getDecorView();
for (int i = 0; i < dialogView.getChildCount(); i++) {
@@ -535,73 +549,51 @@ public abstract class BaseAnncaFragment extends Fragment {
return checkedIndex;
}
- protected DialogInterface.OnClickListener getVideoOptionSelectedListener() {
- return new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int index) {
- newQuality = ((VideoQualityOption) videoQualities[index]).getMediaQuality();
- }
- };
- }
-
- protected DialogInterface.OnClickListener getPhotoOptionSelectedListener() {
- return new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int index) {
- newQuality = ((PhotoQualityOption) photoQualities[index]).getMediaQuality();
- }
- };
- }
-
- public void takePhoto() {
+ protected void takePhoto(CameraFragmentResultListener callback) {
if (Build.VERSION.SDK_INT > MIN_VERSION_ICECREAM) {
new MediaActionSound().play(MediaActionSound.SHUTTER_CLICK);
}
setRecordState(Record.TAKE_PHOTO_STATE);
- getCameraController().takePhoto();
+ this.cameraController.takePhoto(callback);
if (cameraFragmentStateListener != null) {
cameraFragmentStateListener.onRecordStatePhoto();
}
}
- public void startRecording() {
+ protected void startRecording() {
if (Build.VERSION.SDK_INT > MIN_VERSION_ICECREAM) {
new MediaActionSound().play(MediaActionSound.START_VIDEO_RECORDING);
}
setRecordState(Record.RECORD_IN_PROGRESS_STATE);
- getCameraController().startVideoRecord();
+ this.cameraController.startVideoRecord();
if (cameraFragmentStateListener != null) {
cameraFragmentStateListener.onRecordStateVideoInProgress();
}
}
- public void stopRecording() {
+ protected void stopRecording(CameraFragmentResultListener callback) {
if (Build.VERSION.SDK_INT > MIN_VERSION_ICECREAM) {
new MediaActionSound().play(MediaActionSound.STOP_VIDEO_RECORDING);
}
setRecordState(Record.READY_FOR_RECORD_STATE);
- getCameraController().stopVideoRecord();
+ this.cameraController.stopVideoRecord(callback);
- this.onStopVideoRecord();
+ this.onStopVideoRecord(callback);
if (cameraFragmentStateListener != null) {
cameraFragmentStateListener.onRecordStateVideoReadyForRecord();
}
}
- public CameraController getCameraController() {
- return cameraController;
- }
-
- public void clearCameraPreview() {
+ protected void clearCameraPreview() {
if (previewContainer != null)
previewContainer.removeAllViews();
}
- public void setCameraPreview(View preview, Size previewSize) {
+ protected void setCameraPreview(View preview, Size previewSize) {
//onCameraControllerReady()
videoQualities = cameraController.getVideoQualityOptions();
photoQualities = cameraController.getPhotoQualityOptions();
@@ -613,11 +605,11 @@ public abstract class BaseAnncaFragment extends Fragment {
previewContainer.setAspectRatio(previewSize.getHeight() / (double) previewSize.getWidth());
}
- public void setMediaFilePath(final File mediaFile) {
+ protected void setMediaFilePath(final File mediaFile) {
this.mediaFilePath = mediaFile.toString();
}
- public void onStartVideoRecord(final File mediaFile) {
+ protected void onStartVideoRecord(final File mediaFile) {
setMediaFilePath(mediaFile);
if (maxVideoFileSize > 0) {
@@ -657,7 +649,7 @@ public abstract class BaseAnncaFragment extends Fragment {
}
}
- public void onStopVideoRecord() {
+ protected void onStopVideoRecord(@Nullable CameraFragmentResultListener callback) {
if (cameraFragmentControlsListener != null) {
cameraFragmentControlsListener.allowRecord(false);
}
@@ -679,24 +671,32 @@ public abstract class BaseAnncaFragment extends Fragment {
}
}
+ final String filePath = this.cameraController.getOutputFile().toString();
if (cameraFragmentResultListener != null) {
- final String filePath = getCameraController().getOutputFile().toString();
cameraFragmentResultListener.onVideoRecorded(filePath);
}
+
+ if (callback != null) {
+ callback.onVideoRecorded(filePath);
+ }
}
+ @Override
public void setStateListener(CameraFragmentStateListener cameraFragmentStateListener) {
this.cameraFragmentStateListener = cameraFragmentStateListener;
}
+ @Override
public void setTextListener(CameraFragmentVideoRecordTextListener cameraFragmentVideoRecordTextListener) {
this.cameraFragmentVideoRecordTextListener = cameraFragmentVideoRecordTextListener;
}
+ @Override
public void setControlsListener(CameraFragmentControlsListener cameraFragmentControlsListener) {
this.cameraFragmentControlsListener = cameraFragmentControlsListener;
}
+ @Override
public void setResultListener(CameraFragmentResultListener cameraFragmentResultListener) {
this.cameraFragmentResultListener = cameraFragmentResultListener;
}
diff --git a/camerafragment/src/main/java/com/github/florent37/camerafragment/widgets/CameraSwitchView.java b/camerafragment/src/main/java/com/github/florent37/camerafragment/widgets/CameraSwitchView.java
index 14d1064..c07797f 100644
--- a/camerafragment/src/main/java/com/github/florent37/camerafragment/widgets/CameraSwitchView.java
+++ b/camerafragment/src/main/java/com/github/florent37/camerafragment/widgets/CameraSwitchView.java
@@ -18,13 +18,6 @@ import com.github.florent37.camerafragment.internal.utils.Utils;
*/
public class CameraSwitchView extends AppCompatImageButton {
- @Nullable
- private OnCameraTypeChangeListener onCameraTypeChangeListener;
-
- public interface OnCameraTypeChangeListener {
- void switchCameraType();
- }
-
private Drawable frontCameraDrawable;
private Drawable rearCameraDrawable;
private int padding = 5;
@@ -53,14 +46,6 @@ public class CameraSwitchView extends AppCompatImageButton {
DrawableCompat.setTintList(rearCameraDrawable.mutate(), ContextCompat.getColorStateList(context, R.drawable.switch_camera_mode_selector));
setBackgroundResource(R.drawable.circle_frame_background_dark);
- setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- if (onCameraTypeChangeListener != null) {
- onCameraTypeChangeListener.switchCameraType();
- }
- }
- });
displayBackCamera();
padding = Utils.convertDipToPixels(context, padding);
@@ -86,8 +71,4 @@ public class CameraSwitchView extends AppCompatImageButton {
}
}
}
-
- public void setOnCameraTypeChangeListener(OnCameraTypeChangeListener listener) {
- this.onCameraTypeChangeListener = listener;
- }
}
diff --git a/camerafragment/src/main/java/com/github/florent37/camerafragment/widgets/FlashSwitchView.java b/camerafragment/src/main/java/com/github/florent37/camerafragment/widgets/FlashSwitchView.java
index 029fc38..fd1ef47 100644
--- a/camerafragment/src/main/java/com/github/florent37/camerafragment/widgets/FlashSwitchView.java
+++ b/camerafragment/src/main/java/com/github/florent37/camerafragment/widgets/FlashSwitchView.java
@@ -19,17 +19,10 @@ import com.github.florent37.camerafragment.R;
*/
public class FlashSwitchView extends ImageButton {
- @Nullable
- private FlashModeSwitchListener switchListener;
-
private Drawable flashOnDrawable;
private Drawable flashOffDrawable;
private Drawable flashAutoDrawable;
- public interface FlashModeSwitchListener {
- void toggleFlashMode();
- }
-
public FlashSwitchView(@NonNull Context context) {
this(context, null);
}
@@ -44,14 +37,6 @@ public class FlashSwitchView extends ImageButton {
private void init() {
setBackgroundColor(Color.TRANSPARENT);
- setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- if (switchListener != null) {
- switchListener.toggleFlashMode();
- }
- }
- });
}
public void displayFlashOff() {
@@ -66,10 +51,6 @@ public class FlashSwitchView extends ImageButton {
setImageDrawable(flashAutoDrawable);
}
- public void setFlashSwitchListener(@NonNull FlashModeSwitchListener switchListener) {
- this.switchListener = switchListener;
- }
-
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);