allow using the app as both an image and video picker, related to #15
This commit is contained in:
parent
2ce5c90204
commit
605a4a29c3
|
@ -5,6 +5,7 @@ public class Constants {
|
|||
public static final String MEDIUM = "medium";
|
||||
public static final String GET_IMAGE_INTENT = "get_image_intent";
|
||||
public static final String GET_VIDEO_INTENT = "get_video_intent";
|
||||
public static final String GET_ANY_INTENT = "get_any_intent";
|
||||
public static final String SET_WALLPAPER_INTENT = "set_wallpaper_intent";
|
||||
|
||||
// shared preferences
|
||||
|
|
|
@ -67,6 +67,7 @@ public class MainActivity extends SimpleActivity
|
|||
private static boolean mIsPickVideoIntent;
|
||||
private static boolean mIsGetImageContentIntent;
|
||||
private static boolean mIsGetVideoContentIntent;
|
||||
private static boolean mIsGetAnyContentIntent;
|
||||
private static boolean mIsSetWallpaperIntent;
|
||||
private static boolean mIsThirdPartyIntent;
|
||||
private static int mSelectedItemsCnt;
|
||||
|
@ -82,9 +83,10 @@ public class MainActivity extends SimpleActivity
|
|||
mIsPickVideoIntent = isPickVideoIntent(intent);
|
||||
mIsGetImageContentIntent = isGetImageContentIntent(intent);
|
||||
mIsGetVideoContentIntent = isGetVideoContentIntent(intent);
|
||||
mIsGetAnyContentIntent = isGetAnyContentIntent(intent);
|
||||
mIsSetWallpaperIntent = isSetWallpaperIntent(intent);
|
||||
mIsThirdPartyIntent = mIsPickImageIntent || mIsPickVideoIntent || mIsGetImageContentIntent || mIsGetVideoContentIntent ||
|
||||
mIsSetWallpaperIntent;
|
||||
mIsGetAnyContentIntent || mIsSetWallpaperIntent;
|
||||
|
||||
mToBeDeleted = new ArrayList<>();
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
|
@ -427,6 +429,10 @@ public class MainActivity extends SimpleActivity
|
|||
(intent.getType().startsWith("video/") || intent.getType().equals(MediaStore.Video.Media.CONTENT_TYPE));
|
||||
}
|
||||
|
||||
private boolean isGetAnyContentIntent(Intent intent) {
|
||||
return isGetContentIntent(intent) && intent.getType().equals("*/*");
|
||||
}
|
||||
|
||||
private boolean isSetWallpaperIntent(Intent intent) {
|
||||
return intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_SET_WALLPAPER);
|
||||
}
|
||||
|
@ -458,7 +464,7 @@ public class MainActivity extends SimpleActivity
|
|||
final Intent result = new Intent();
|
||||
final String path = data.getData().getPath();
|
||||
final Uri uri = Uri.fromFile(new File(path));
|
||||
if (mIsGetImageContentIntent || mIsGetVideoContentIntent) {
|
||||
if (mIsGetImageContentIntent || mIsGetVideoContentIntent || mIsGetAnyContentIntent) {
|
||||
final String type = Utils.getMimeType(path);
|
||||
result.setDataAndTypeAndNormalize(uri, type);
|
||||
result.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
|
@ -488,6 +494,7 @@ public class MainActivity extends SimpleActivity
|
|||
} else {
|
||||
intent.putExtra(Constants.GET_IMAGE_INTENT, mIsPickImageIntent || mIsGetImageContentIntent);
|
||||
intent.putExtra(Constants.GET_VIDEO_INTENT, mIsPickVideoIntent || mIsGetVideoContentIntent);
|
||||
intent.putExtra(Constants.GET_ANY_INTENT, mIsGetAnyContentIntent);
|
||||
startActivityForResult(intent, PICK_MEDIA);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ public class MediaActivity extends SimpleActivity
|
|||
private static boolean mIsSnackbarShown;
|
||||
private static boolean mIsGetImageIntent;
|
||||
private static boolean mIsGetVideoIntent;
|
||||
private static boolean mIsGetAnyIntent;
|
||||
private static int mSelectedItemsCnt;
|
||||
|
||||
@Override
|
||||
|
@ -70,6 +71,7 @@ public class MediaActivity extends SimpleActivity
|
|||
ButterKnife.bind(this);
|
||||
mIsGetImageIntent = getIntent().getBooleanExtra(Constants.GET_IMAGE_INTENT, false);
|
||||
mIsGetVideoIntent = getIntent().getBooleanExtra(Constants.GET_VIDEO_INTENT, false);
|
||||
mIsGetAnyIntent = getIntent().getBooleanExtra(Constants.GET_ANY_INTENT, false);
|
||||
mToBeDeleted = new ArrayList<>();
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
mPath = getIntent().getStringExtra(Constants.DIRECTORY);
|
||||
|
@ -358,7 +360,7 @@ public class MediaActivity extends SimpleActivity
|
|||
finish();
|
||||
}
|
||||
});
|
||||
} else if (mIsGetImageIntent || mIsGetVideoIntent) {
|
||||
} else if (mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent) {
|
||||
final Intent result = new Intent();
|
||||
result.setData(Uri.parse(curItemPath));
|
||||
setResult(RESULT_OK, result);
|
||||
|
|
Loading…
Reference in New Issue