|
|
@ -74,16 +74,28 @@ public abstract class BaseAnncaFragment<CameraId> extends Fragment implements Ca |
|
|
|
private AlertDialog settingsDialog; |
|
|
|
private AlertDialog settingsDialog; |
|
|
|
private CameraFragmentControlsListener cameraFragmentControlsListener; |
|
|
|
private CameraFragmentControlsListener cameraFragmentControlsListener; |
|
|
|
private CameraFragmentVideoRecordTextListener cameraFragmentVideoRecordTextListener; |
|
|
|
private CameraFragmentVideoRecordTextListener cameraFragmentVideoRecordTextListener; |
|
|
|
|
|
|
|
final TimerTaskBase.Callback timerCallBack = new TimerTaskBase.Callback() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void setText(String text) { |
|
|
|
|
|
|
|
if (cameraFragmentVideoRecordTextListener != null) { |
|
|
|
|
|
|
|
cameraFragmentVideoRecordTextListener.setRecordDurationText(text); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void setTextVisible(boolean visible) { |
|
|
|
|
|
|
|
if (cameraFragmentVideoRecordTextListener != null) { |
|
|
|
|
|
|
|
cameraFragmentVideoRecordTextListener.setRecordDurationTextVisible(visible); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
private CameraFragmentStateListener cameraFragmentStateListener; |
|
|
|
private CameraFragmentStateListener cameraFragmentStateListener; |
|
|
|
@Flash.FlashMode |
|
|
|
@Flash.FlashMode |
|
|
|
private int currentFlashMode = Flash.FLASH_AUTO; |
|
|
|
private int currentFlashMode = Flash.FLASH_AUTO; |
|
|
|
|
|
|
|
|
|
|
|
@Camera.CameraType |
|
|
|
@Camera.CameraType |
|
|
|
private int currentCameraType = Camera.CAMERA_TYPE_REAR; |
|
|
|
private int currentCameraType = Camera.CAMERA_TYPE_REAR; |
|
|
|
|
|
|
|
|
|
|
|
@MediaAction.MediaActionState |
|
|
|
@MediaAction.MediaActionState |
|
|
|
private int currentMediaActionState = MediaAction.ACTION_PHOTO; |
|
|
|
private int currentMediaActionState = MediaAction.ACTION_PHOTO; |
|
|
|
|
|
|
|
|
|
|
|
@Record.RecordState |
|
|
|
@Record.RecordState |
|
|
|
private int currentRecordState = Record.TAKE_PHOTO_STATE; |
|
|
|
private int currentRecordState = Record.TAKE_PHOTO_STATE; |
|
|
|
private String mediaFilePath; |
|
|
|
private String mediaFilePath; |
|
|
@ -157,15 +169,7 @@ public abstract class BaseAnncaFragment<CameraId> extends Fragment implements Ca |
|
|
|
this.configurationProvider = new ConfigurationProviderImpl(); |
|
|
|
this.configurationProvider = new ConfigurationProviderImpl(); |
|
|
|
this.configurationProvider.setupWithAnnaConfiguration(configuration); |
|
|
|
this.configurationProvider.setupWithAnnaConfiguration(configuration); |
|
|
|
|
|
|
|
|
|
|
|
//onProcessBundle
|
|
|
|
this.sensorManager = (SensorManager) getContext().getSystemService(Activity.SENSOR_SERVICE); |
|
|
|
currentMediaActionState = configurationProvider.getMediaAction() == Configuration.MEDIA_ACTION_VIDEO ? |
|
|
|
|
|
|
|
MediaAction.ACTION_VIDEO : MediaAction.ACTION_PHOTO; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
|
|
|
|
|
|
|
super.onViewCreated(view, savedInstanceState); |
|
|
|
|
|
|
|
previewContainer = (AspectFrameLayout) view.findViewById(R.id.previewContainer); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final CameraView cameraView = new CameraView() { |
|
|
|
final CameraView cameraView = new CameraView() { |
|
|
|
|
|
|
|
|
|
|
@ -210,7 +214,7 @@ public abstract class BaseAnncaFragment<CameraId> extends Fragment implements Ca |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onVideoRecordStop(@Nullable CameraFragmentResultListener callback) { |
|
|
|
public void onVideoRecordStop(@Nullable CameraFragmentResultListener callback) { |
|
|
|
BaseAnncaFragment.this.onStopVideoRecord(callback); |
|
|
|
//BaseAnncaFragment.this.onStopVideoRecord(callback);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -220,13 +224,22 @@ public abstract class BaseAnncaFragment<CameraId> extends Fragment implements Ca |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if (CameraHelper.hasCamera2(getContext())) { |
|
|
|
if (CameraHelper.hasCamera2(getContext())) { |
|
|
|
cameraController = new Camera2Controller(getActivity(), cameraView, configurationProvider); |
|
|
|
cameraController = new Camera2Controller(getContext(), cameraView, configurationProvider); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
cameraController = new Camera1Controller(getActivity(), cameraView, configurationProvider); |
|
|
|
cameraController = new Camera1Controller(getContext(), cameraView, configurationProvider); |
|
|
|
} |
|
|
|
} |
|
|
|
cameraController.onCreate(savedInstanceState); |
|
|
|
cameraController.onCreate(savedInstanceState); |
|
|
|
|
|
|
|
|
|
|
|
sensorManager = (SensorManager) getContext().getSystemService(Activity.SENSOR_SERVICE); |
|
|
|
//onProcessBundle
|
|
|
|
|
|
|
|
currentMediaActionState = configurationProvider.getMediaAction() == Configuration.MEDIA_ACTION_VIDEO ? |
|
|
|
|
|
|
|
MediaAction.ACTION_VIDEO : MediaAction.ACTION_PHOTO; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
|
|
|
|
|
|
|
super.onViewCreated(view, savedInstanceState); |
|
|
|
|
|
|
|
previewContainer = (AspectFrameLayout) view.findViewById(R.id.previewContainer); |
|
|
|
|
|
|
|
|
|
|
|
final int defaultOrientation = Utils.getDeviceDefaultOrientation(getContext()); |
|
|
|
final int defaultOrientation = Utils.getDeviceDefaultOrientation(getContext()); |
|
|
|
switch (defaultOrientation) { |
|
|
|
switch (defaultOrientation) { |
|
|
|
case android.content.res.Configuration.ORIENTATION_LANDSCAPE: |
|
|
|
case android.content.res.Configuration.ORIENTATION_LANDSCAPE: |
|
|
@ -254,6 +267,16 @@ public abstract class BaseAnncaFragment<CameraId> extends Fragment implements Ca |
|
|
|
setMaxVideoFileSize(configurationProvider.getVideoFileSize()); |
|
|
|
setMaxVideoFileSize(configurationProvider.getVideoFileSize()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setCameraTypeFrontBack(configurationProvider.getCameraFace()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notifyListeners(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void notifyListeners() { |
|
|
|
|
|
|
|
onFlashModeChanged(); |
|
|
|
|
|
|
|
onActionPhotoVideoChanged(); |
|
|
|
|
|
|
|
onCameraTypeFrontBackChanged(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -313,26 +336,10 @@ public abstract class BaseAnncaFragment<CameraId> extends Fragment implements Ca |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void setMaxVideoDuration(int maxVideoDurationInMillis) { |
|
|
|
protected void setMaxVideoDuration(int maxVideoDurationInMillis) { |
|
|
|
final TimerTaskBase.Callback callback = new TimerTaskBase.Callback() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void setText(String text) { |
|
|
|
|
|
|
|
if (cameraFragmentVideoRecordTextListener != null) { |
|
|
|
|
|
|
|
cameraFragmentVideoRecordTextListener.setRecordDurationText(text); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void setTextVisible(boolean visible) { |
|
|
|
|
|
|
|
if (cameraFragmentVideoRecordTextListener != null) { |
|
|
|
|
|
|
|
cameraFragmentVideoRecordTextListener.setRecordDurationTextVisible(visible); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (maxVideoDurationInMillis > 0) { |
|
|
|
if (maxVideoDurationInMillis > 0) { |
|
|
|
this.countDownTimer = new CountdownTask(callback, maxVideoDurationInMillis); |
|
|
|
this.countDownTimer = new CountdownTask(timerCallBack, maxVideoDurationInMillis); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.countDownTimer = new TimerTask(callback); |
|
|
|
this.countDownTimer = new TimerTask(timerCallBack); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -392,7 +399,7 @@ public abstract class BaseAnncaFragment<CameraId> extends Fragment implements Ca |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void switchCameraType() { |
|
|
|
public void switchCameraTypeFrontBack() { |
|
|
|
if (cameraFragmentControlsListener != null) { |
|
|
|
if (cameraFragmentControlsListener != null) { |
|
|
|
cameraFragmentControlsListener.lockControls(); |
|
|
|
cameraFragmentControlsListener.lockControls(); |
|
|
|
cameraFragmentControlsListener.allowRecord(false); |
|
|
|
cameraFragmentControlsListener.allowRecord(false); |
|
|
@ -403,38 +410,70 @@ public abstract class BaseAnncaFragment<CameraId> extends Fragment implements Ca |
|
|
|
case Camera.CAMERA_TYPE_FRONT: |
|
|
|
case Camera.CAMERA_TYPE_FRONT: |
|
|
|
currentCameraType = Camera.CAMERA_TYPE_REAR; |
|
|
|
currentCameraType = Camera.CAMERA_TYPE_REAR; |
|
|
|
cameraFace = Configuration.CAMERA_FACE_REAR; |
|
|
|
cameraFace = Configuration.CAMERA_FACE_REAR; |
|
|
|
if (cameraFragmentStateListener != null) { |
|
|
|
|
|
|
|
cameraFragmentStateListener.onCurrentCameraBack(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case Camera.CAMERA_TYPE_REAR: |
|
|
|
case Camera.CAMERA_TYPE_REAR: |
|
|
|
currentCameraType = Camera.CAMERA_TYPE_FRONT; |
|
|
|
currentCameraType = Camera.CAMERA_TYPE_FRONT; |
|
|
|
cameraFace = Configuration.CAMERA_FACE_FRONT; |
|
|
|
cameraFace = Configuration.CAMERA_FACE_FRONT; |
|
|
|
if (cameraFragmentStateListener != null) { |
|
|
|
|
|
|
|
cameraFragmentStateListener.onCurrentCameraFront(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onCameraTypeFrontBackChanged(); |
|
|
|
this.cameraController.switchCamera(cameraFace); |
|
|
|
this.cameraController.switchCamera(cameraFace); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void setCameraTypeFrontBack(@Configuration.CameraFace int cameraFace){ |
|
|
|
|
|
|
|
switch (cameraFace) { |
|
|
|
|
|
|
|
case Configuration.CAMERA_FACE_FRONT: |
|
|
|
|
|
|
|
currentCameraType = Camera.CAMERA_TYPE_FRONT; |
|
|
|
|
|
|
|
cameraFace = Configuration.CAMERA_FACE_FRONT; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Configuration.CAMERA_FACE_REAR: |
|
|
|
|
|
|
|
currentCameraType = Camera.CAMERA_TYPE_REAR; |
|
|
|
|
|
|
|
cameraFace = Configuration.CAMERA_FACE_REAR; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
onCameraTypeFrontBackChanged(); |
|
|
|
|
|
|
|
this.cameraController.switchCamera(cameraFace); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void onCameraTypeFrontBackChanged() { |
|
|
|
|
|
|
|
if (cameraFragmentStateListener != null) { |
|
|
|
|
|
|
|
switch (currentCameraType) { |
|
|
|
|
|
|
|
case Camera.CAMERA_TYPE_REAR: |
|
|
|
|
|
|
|
cameraFragmentStateListener.onCurrentCameraBack(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Camera.CAMERA_TYPE_FRONT: |
|
|
|
|
|
|
|
cameraFragmentStateListener.onCurrentCameraFront(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void switchActionPhotoVideo() { |
|
|
|
public void switchActionPhotoVideo() { |
|
|
|
switch (currentMediaActionState) { |
|
|
|
switch (currentMediaActionState) { |
|
|
|
case MediaAction.ACTION_PHOTO: |
|
|
|
case MediaAction.ACTION_PHOTO: |
|
|
|
currentMediaActionState = MediaAction.ACTION_VIDEO; |
|
|
|
currentMediaActionState = MediaAction.ACTION_VIDEO; |
|
|
|
if (cameraFragmentStateListener != null) { |
|
|
|
|
|
|
|
cameraFragmentStateListener.onCameraSetupForVideo(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case MediaAction.ACTION_VIDEO: |
|
|
|
case MediaAction.ACTION_VIDEO: |
|
|
|
currentMediaActionState = MediaAction.ACTION_PHOTO; |
|
|
|
currentMediaActionState = MediaAction.ACTION_PHOTO; |
|
|
|
if (cameraFragmentStateListener != null) { |
|
|
|
|
|
|
|
cameraFragmentStateListener.onCameraSetupForPhoto(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onActionPhotoVideoChanged(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void onActionPhotoVideoChanged() { |
|
|
|
|
|
|
|
if (cameraFragmentStateListener != null) { |
|
|
|
|
|
|
|
switch (currentMediaActionState) { |
|
|
|
|
|
|
|
case MediaAction.ACTION_VIDEO: |
|
|
|
|
|
|
|
cameraFragmentStateListener.onCameraSetupForVideo(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case MediaAction.ACTION_PHOTO: |
|
|
|
|
|
|
|
cameraFragmentStateListener.onCameraSetupForPhoto(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -484,6 +523,7 @@ public abstract class BaseAnncaFragment<CameraId> extends Fragment implements Ca |
|
|
|
this.currentRecordState = recordState; |
|
|
|
this.currentRecordState = recordState; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//@Override
|
|
|
|
//@Override
|
|
|
|
//public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
//public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
// if (resultCode == Activity.RESULT_OK) {
|
|
|
|
// if (resultCode == Activity.RESULT_OK) {
|
|
|
@ -642,6 +682,10 @@ public abstract class BaseAnncaFragment<CameraId> extends Fragment implements Ca |
|
|
|
Log.e("FileObserver", "setMediaFilePath: ", e); |
|
|
|
Log.e("FileObserver", "setMediaFilePath: ", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (countDownTimer == null) { |
|
|
|
|
|
|
|
this.countDownTimer = new TimerTask(timerCallBack); |
|
|
|
|
|
|
|
} |
|
|
|
countDownTimer.start(); |
|
|
|
countDownTimer.start(); |
|
|
|
|
|
|
|
|
|
|
|
if (cameraFragmentStateListener != null) { |
|
|
|
if (cameraFragmentStateListener != null) { |
|
|
@ -660,7 +704,10 @@ public abstract class BaseAnncaFragment<CameraId> extends Fragment implements Ca |
|
|
|
|
|
|
|
|
|
|
|
if (fileObserver != null) |
|
|
|
if (fileObserver != null) |
|
|
|
fileObserver.stopWatching(); |
|
|
|
fileObserver.stopWatching(); |
|
|
|
countDownTimer.stop(); |
|
|
|
|
|
|
|
|
|
|
|
if(countDownTimer != null) { |
|
|
|
|
|
|
|
countDownTimer.stop(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final int mediaAction = configurationProvider.getMediaAction(); |
|
|
|
final int mediaAction = configurationProvider.getMediaAction(); |
|
|
|
if (cameraFragmentControlsListener != null) { |
|
|
|
if (cameraFragmentControlsListener != null) { |
|
|
|