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