From 08dd94f10f607b74e294f36ea360a83a9c9f4cb9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 15 Jun 2016 15:55:13 +0200 Subject: [PATCH] allow using the gallery as a video chooser --- app/src/main/AndroidManifest.xml | 6 ++++ .../simplemobiletools/gallery/Constants.java | 1 + .../gallery/activities/MainActivity.java | 33 +++++++++++++------ .../gallery/activities/MediaActivity.java | 13 +++++--- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3cc4ff78f..59a0a2ae8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,6 +24,12 @@ + + + + + + dirs; private int selectedItemsCnt; private Snackbar snackbar; @@ -55,14 +55,16 @@ public class MainActivity extends AppCompatActivity private List toBeDeleted; private ActionMode actionMode; private Parcelable state; - private boolean isImagePickIntent; + private boolean isPickImageIntent; + private boolean isPickVideoIntent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); - isImagePickIntent = isImagePickIntent(getIntent()); + isPickImageIntent = isPickImageIntent(getIntent()); + isPickVideoIntent = isPickVideoIntent(getIntent()); } @Override @@ -137,9 +139,12 @@ public class MainActivity extends AppCompatActivity final Map directories = new LinkedHashMap<>(); final List invalidFiles = new ArrayList<>(); for (int i = 0; i < 2; i++) { + if (isPickVideoIntent && i == 0) + continue; + Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; if (i == 1) { - if (isImagePickIntent) + if (isPickImageIntent) continue; uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; @@ -324,14 +329,21 @@ public class MainActivity extends AppCompatActivity }); } - private boolean isImagePickIntent(Intent intent) { - return intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_PICK) && - intent.getData().equals(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); + private boolean isPickImageIntent(Intent intent) { + return isPickIntent(intent) && intent.getData().equals(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); + } + + private boolean isPickVideoIntent(Intent intent) { + return isPickIntent(intent) && intent.getData().equals(MediaStore.Video.Media.EXTERNAL_CONTENT_URI); + } + + private boolean isPickIntent(Intent intent) { + return intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_PICK) && intent.getData() != null; } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == PICK_IMAGE && resultCode == RESULT_OK && data != null) { + if (requestCode == PICK_MEDIA && resultCode == RESULT_OK && data != null) { final Intent result = new Intent(); result.setData(data.getData()); setResult(RESULT_OK, result); @@ -344,8 +356,9 @@ public class MainActivity extends AppCompatActivity public void onItemClick(AdapterView parent, View view, int position, long id) { final Intent intent = new Intent(this, MediaActivity.class); intent.putExtra(Constants.DIRECTORY, dirs.get(position).getPath()); - intent.putExtra(Constants.PICK_IMAGE_INTENT, isImagePickIntent); - startActivityForResult(intent, PICK_IMAGE); + intent.putExtra(Constants.PICK_IMAGE_INTENT, isPickImageIntent); + intent.putExtra(Constants.PICK_VIDEO_INTENT, isPickVideoIntent); + startActivityForResult(intent, PICK_MEDIA); } @Override diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java index e30301361..ee2c9c842 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java @@ -47,14 +47,16 @@ public class MediaActivity extends AppCompatActivity private boolean isSnackbarShown; private List toBeDeleted; private Parcelable state; - private boolean isImagePickIntent; + private boolean isPickImageIntent; + private boolean isPickVideoIntent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_media); ButterKnife.bind(this); - isImagePickIntent = getIntent().getBooleanExtra(Constants.PICK_IMAGE_INTENT, false); + isPickImageIntent = getIntent().getBooleanExtra(Constants.PICK_IMAGE_INTENT, false); + isPickVideoIntent = getIntent().getBooleanExtra(Constants.PICK_VIDEO_INTENT, false); } @Override @@ -110,9 +112,12 @@ public class MediaActivity extends AppCompatActivity final List myMedia = new ArrayList<>(); final List invalidFiles = new ArrayList<>(); for (int i = 0; i < 2; i++) { + if (isPickVideoIntent && i == 0) + continue; + Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; if (i == 1) { - if (isImagePickIntent) + if (isPickImageIntent) continue; uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; @@ -239,7 +244,7 @@ public class MediaActivity extends AppCompatActivity @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - if (isImagePickIntent) { + if (isPickImageIntent || isPickVideoIntent) { final Intent result = new Intent(); result.setData(Uri.parse(media.get(position).getPath())); setResult(RESULT_OK, result);