mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-05-11 04:18:41 +02:00
properly handle M permissions at video_capture action
This commit is contained in:
parent
78002aa70f
commit
ef993c3930
@ -63,35 +63,20 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
tryInitCamera();
|
tryInitCamera();
|
||||||
|
|
||||||
final Intent intent = getIntent();
|
|
||||||
if (intent != null) {
|
|
||||||
if (intent.getExtras() != null && intent.getAction().equals(MediaStore.ACTION_IMAGE_CAPTURE)) {
|
|
||||||
isImageCaptureIntent = true;
|
|
||||||
|
|
||||||
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();
|
|
||||||
preview.setIsVideoCaptureIntent();
|
|
||||||
shutterBtn.setImageDrawable(getResources().getDrawable(R.mipmap.video_rec));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideToggleModeAbout() {
|
private void hideToggleModeAbout() {
|
||||||
|
if (togglePhotoVideoBtn != null)
|
||||||
togglePhotoVideoBtn.setVisibility(View.GONE);
|
togglePhotoVideoBtn.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
if (aboutBtn != null)
|
||||||
aboutBtn.setVisibility(View.GONE);
|
aboutBtn.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryInitCamera() {
|
private void tryInitCamera() {
|
||||||
if (hasCameraAndStoragePermission()) {
|
if (hasCameraAndStoragePermission()) {
|
||||||
initializeCamera();
|
initializeCamera();
|
||||||
|
handleIntent();
|
||||||
} else {
|
} else {
|
||||||
final List<String> permissions = new ArrayList<>(2);
|
final List<String> permissions = new ArrayList<>(2);
|
||||||
if (!Utils.hasCameraPermission(getApplicationContext())) {
|
if (!Utils.hasCameraPermission(getApplicationContext())) {
|
||||||
@ -104,6 +89,25 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleIntent() {
|
||||||
|
final Intent intent = getIntent();
|
||||||
|
if (intent != null) {
|
||||||
|
if (intent.getExtras() != null && intent.getAction().equals(MediaStore.ACTION_IMAGE_CAPTURE)) {
|
||||||
|
isImageCaptureIntent = true;
|
||||||
|
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.setIsVideoCaptureIntent();
|
||||||
|
shutterBtn.setImageDrawable(getResources().getDrawable(R.mipmap.video_rec));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void initializeCamera() {
|
private void initializeCamera() {
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
@ -129,6 +133,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
if (requestCode == CAMERA_STORAGE_PERMISSION) {
|
if (requestCode == CAMERA_STORAGE_PERMISSION) {
|
||||||
if (hasCameraAndStoragePermission()) {
|
if (hasCameraAndStoragePermission()) {
|
||||||
initializeCamera();
|
initializeCamera();
|
||||||
|
handleIntent();
|
||||||
} else {
|
} else {
|
||||||
Utils.showToast(getApplicationContext(), R.string.no_permissions);
|
Utils.showToast(getApplicationContext(), R.string.no_permissions);
|
||||||
finish();
|
finish();
|
||||||
@ -138,6 +143,8 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
toggleVideo();
|
toggleVideo();
|
||||||
} else {
|
} else {
|
||||||
Utils.showToast(getApplicationContext(), R.string.no_audio_permissions);
|
Utils.showToast(getApplicationContext(), R.string.no_audio_permissions);
|
||||||
|
if (isVideoCaptureIntent)
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,6 +248,10 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
isAskingPermissions = true;
|
isAskingPermissions = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isVideoCaptureIntent)
|
||||||
|
preview.trySwitchToVideo();
|
||||||
|
|
||||||
disableFlash();
|
disableFlash();
|
||||||
hideTimer();
|
hideTimer();
|
||||||
isInPhotoMode = !isInPhotoMode;
|
isInPhotoMode = !isInPhotoMode;
|
||||||
@ -304,12 +315,12 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
if (hasCameraAndStoragePermission()) {
|
if (hasCameraAndStoragePermission()) {
|
||||||
resumeCameraItems();
|
resumeCameraItems();
|
||||||
}
|
|
||||||
|
|
||||||
if (isVideoCaptureIntent && isInPhotoMode) {
|
if (isVideoCaptureIntent && isInPhotoMode) {
|
||||||
toggleVideo();
|
toggleVideo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void resumeCameraItems() {
|
private void resumeCameraItems() {
|
||||||
final int cnt = Camera.getNumberOfCameras();
|
final int cnt = Camera.getNumberOfCameras();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user