mirror of
				https://github.com/SimpleMobileTools/Simple-Camera.git
				synced 2025-06-27 09:02:59 +02:00 
			
		
		
		
	preparations for ACTION_VIDEO_CAPTURE handling
This commit is contained in:
		| @@ -30,6 +30,11 @@ | ||||
|                 <action android:name="android.media.action.IMAGE_CAPTURE"/> | ||||
|                 <category android:name="android.intent.category.DEFAULT"/> | ||||
|             </intent-filter> | ||||
|  | ||||
|             <intent-filter> | ||||
|                 <action android:name="android.media.action.VIDEO_CAPTURE"/> | ||||
|                 <category android:name="android.intent.category.DEFAULT"/> | ||||
|             </intent-filter> | ||||
|         </activity> | ||||
|  | ||||
|         <activity | ||||
|   | ||||
| @@ -37,7 +37,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen | ||||
|     @BindView(R.id.viewHolder) RelativeLayout viewHolder; | ||||
|     @BindView(R.id.toggle_camera) ImageView toggleCameraBtn; | ||||
|     @BindView(R.id.toggle_flash) ImageView toggleFlashBtn; | ||||
|     @BindView(R.id.toggle_videocam) ImageView togglePhotoVideoBtn; | ||||
|     @BindView(R.id.toggle_photo_video) ImageView togglePhotoVideoBtn; | ||||
|     @BindView(R.id.shutter) ImageView shutterBtn; | ||||
|     @BindView(R.id.video_rec_curr_timer) TextView recCurrTimer; | ||||
|     @BindView(R.id.about) View aboutBtn; | ||||
| @@ -51,6 +51,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen | ||||
|     private boolean isAskingPermissions; | ||||
|     private boolean isCameraAvailable; | ||||
|     private boolean isImageCaptureIntent; | ||||
|     private boolean isVideoCaptureIntent; | ||||
|     private int currVideoRecTimer; | ||||
|     private int orientation; | ||||
|     private int currCamera; | ||||
| @@ -64,18 +65,29 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen | ||||
|         tryInitCamera(); | ||||
|  | ||||
|         final Intent intent = getIntent(); | ||||
|         if (intent != null && intent.getExtras() != null && intent.getAction().equals(MediaStore.ACTION_IMAGE_CAPTURE)) { | ||||
|             isImageCaptureIntent = true; | ||||
|             togglePhotoVideoBtn.setVisibility(View.GONE); | ||||
|             aboutBtn.setVisibility(View.GONE); | ||||
|         if (intent != null) { | ||||
|             if (intent.getExtras() != null && intent.getAction().equals(MediaStore.ACTION_IMAGE_CAPTURE)) { | ||||
|                 isImageCaptureIntent = true; | ||||
|  | ||||
|             final Object output = intent.getExtras().get(MediaStore.EXTRA_OUTPUT); | ||||
|             if (output != null && output instanceof Uri) { | ||||
|                 preview.setTargetUri((Uri) output); | ||||
|                 hideToggleModeAbout(); | ||||
|                 final Object output = intent.getExtras().get(MediaStore.EXTRA_OUTPUT); | ||||
|                 if (output != null && output instanceof Uri) { | ||||
|                     preview.setTargetUri((Uri) output); | ||||
|                 } | ||||
|             } else if (intent.getAction().equals(MediaStore.ACTION_VIDEO_CAPTURE)) { | ||||
|                 isVideoCaptureIntent = true; | ||||
|                 hideToggleModeAbout(); | ||||
|                 preview.trySwitchToVideo(); | ||||
|                 shutterBtn.setImageDrawable(getResources().getDrawable(R.mipmap.video_rec)); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void hideToggleModeAbout() { | ||||
|         togglePhotoVideoBtn.setVisibility(View.GONE); | ||||
|         aboutBtn.setVisibility(View.GONE); | ||||
|     } | ||||
|  | ||||
|     private void tryInitCamera() { | ||||
|         if (hasCameraAndStoragePermission()) { | ||||
|             initializeCamera(); | ||||
| @@ -213,8 +225,12 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen | ||||
|         startActivity(intent); | ||||
|     } | ||||
|  | ||||
|     @OnClick(R.id.toggle_videocam) | ||||
|     public void toggleVideo() { | ||||
|     @OnClick(R.id.toggle_photo_video) | ||||
|     public void handleToggleVideo() { | ||||
|         toggleVideo(); | ||||
|     } | ||||
|  | ||||
|     private void toggleVideo() { | ||||
|         if (!checkCameraAvailable()) { | ||||
|             return; | ||||
|         } | ||||
| @@ -250,7 +266,9 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen | ||||
|             shutterBtn.setImageDrawable(res.getDrawable(R.mipmap.video_rec)); | ||||
|             toggleCameraBtn.setVisibility(View.VISIBLE); | ||||
|         } else { | ||||
|             Utils.showToast(getApplicationContext(), R.string.video_mode_error); | ||||
|             if (!isVideoCaptureIntent) { | ||||
|                 Utils.showToast(getApplicationContext(), R.string.video_mode_error); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -286,6 +304,10 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen | ||||
|         if (hasCameraAndStoragePermission()) { | ||||
|             resumeCameraItems(); | ||||
|         } | ||||
|  | ||||
|         if (isVideoCaptureIntent && isInPhotoMode) { | ||||
|             toggleVideo(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void resumeCameraItems() { | ||||
|   | ||||
| @@ -43,6 +43,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O | ||||
|     private static boolean isRecording; | ||||
|     private static boolean isVideoMode; | ||||
|     private static boolean isSurfaceCreated; | ||||
|     private static boolean switchToVideoAsap; | ||||
|     private static String curVideoPath; | ||||
|     private static int lastClickX; | ||||
|     private static int lastClickY; | ||||
| @@ -72,6 +73,14 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O | ||||
|         curVideoPath = ""; | ||||
|     } | ||||
|  | ||||
|     public void trySwitchToVideo() { | ||||
|         if (isSurfaceCreated) { | ||||
|             initRecorder(); | ||||
|         } else { | ||||
|             switchToVideoAsap = true; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public boolean setCamera(int cameraId) { | ||||
|         currCameraId = cameraId; | ||||
|         Camera newCamera; | ||||
| @@ -332,6 +341,9 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O | ||||
|             if (camera != null) { | ||||
|                 camera.setPreviewDisplay(surfaceHolder); | ||||
|             } | ||||
|  | ||||
|             if (switchToVideoAsap) | ||||
|                 initRecorder(); | ||||
|         } catch (IOException e) { | ||||
|             Log.e(TAG, "surfaceCreated IOException " + e.getMessage()); | ||||
|         } | ||||
| @@ -462,6 +474,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O | ||||
|         if (camera == null || recorder != null || !isSurfaceCreated) | ||||
|             return false; | ||||
|  | ||||
|         switchToVideoAsap = false; | ||||
|         final Camera.Size preferred = parameters.getPreferredPreviewSizeForVideo(); | ||||
|         if (preferred == null) | ||||
|             return false; | ||||
|   | ||||
| @@ -20,7 +20,7 @@ | ||||
|         android:src="@mipmap/about"/> | ||||
|  | ||||
|     <ImageView | ||||
|         android:id="@+id/toggle_videocam" | ||||
|         android:id="@+id/toggle_photo_video" | ||||
|         android:layout_width="@dimen/icon_size" | ||||
|         android:layout_height="@dimen/icon_size" | ||||
|         android:layout_alignParentRight="true" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user