diff options
Diffstat (limited to 'src/org/cyanogenmod/wallpaperpicker/WallpaperPickerActivity.java')
-rw-r--r-- | src/org/cyanogenmod/wallpaperpicker/WallpaperPickerActivity.java | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/src/org/cyanogenmod/wallpaperpicker/WallpaperPickerActivity.java b/src/org/cyanogenmod/wallpaperpicker/WallpaperPickerActivity.java index a5c1d03..9ba2515 100644 --- a/src/org/cyanogenmod/wallpaperpicker/WallpaperPickerActivity.java +++ b/src/org/cyanogenmod/wallpaperpicker/WallpaperPickerActivity.java @@ -104,6 +104,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { private static final String ACTION_SET_KEYGUARD_WALLPAPER = "android.intent.action.SET_KEYGUARD_WALLPAPER"; + private static final int REQUEST_CODE_STORAGE_PERMISSION_CHECK = 100; + @Thunk View mSelectedTile; @Thunk boolean mIgnoreNextTap; @@ -147,9 +149,11 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { public static class PickImageInfo extends WallpaperTileInfo { @Override public void onClick(WallpaperPickerActivity a) { - Intent intent = new Intent(Intent.ACTION_GET_CONTENT); - intent.setType("image/*"); - a.startActivityForResultSafely(intent, IMAGE_PICK); + if (a.hasStoragePermissions()) { + a.startPickImageActivity(); + } else { + a.requestStoragePermissions(); + } } } @@ -511,6 +515,30 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } } + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, + int[] grantResults) { + if (requestCode == REQUEST_CODE_STORAGE_PERMISSION_CHECK) { + for (int i = 0; i < permissions.length; i++ ) { + final String permission = permissions[i]; + final int grantResult = grantResults[i]; + if (permission.equals(Manifest.permission.READ_EXTERNAL_STORAGE)) { + if (grantResult == PackageManager.PERMISSION_GRANTED) { + startPickImageActivity(); + } else { + Toast.makeText(this, getString(R.string.storage_permission_denied), + Toast.LENGTH_SHORT).show(); + } + } + } + } + } + // called by onCreate; this is subclassed to overwrite WallpaperCropActivity protected void init() { setContentView(R.layout.wallpaper_picker); @@ -1378,6 +1406,22 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { Utilities.startActivityForResultSafely(getActivity(), intent, requestCode); } + public void startPickImageActivity() { + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("image/*"); + startActivityForResultSafely(intent, IMAGE_PICK); + } + + public boolean hasStoragePermissions() { + return checkCallingOrSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) == + PackageManager.PERMISSION_GRANTED; + } + + public void requestStoragePermissions() { + requestPermissions(new String[] {android.Manifest.permission.READ_EXTERNAL_STORAGE}, + REQUEST_CODE_STORAGE_PERMISSION_CHECK); + } + private static class ThemeWallpapersAdapter extends BaseAdapter implements ListAdapter { private LayoutInflater mLayoutInflater; private ArrayList<ThemeWallpaperInfo> mWallpapers; |