diff --git a/checkstyle.xml b/checkstyle.xml
index 55273de62b2b88213fdc1384a0b6f576a53cd843..ec3f4a74d3c3cc4c1e9cd7f0f1764ce2bfd57762 100644
--- a/checkstyle.xml
+++ b/checkstyle.xml
@@ -127,7 +127,9 @@
-
+
+
+
diff --git a/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/MainActivity.java b/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/MainActivity.java
index f600840b1be3db7002eaa93814fffcb5cf1cd9b6..cf315b106c4bf5c812a11d129db24705e5556e53 100644
--- a/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/MainActivity.java
+++ b/samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/MainActivity.java
@@ -1,7 +1,16 @@
package com.bumptech.glide.samples.gallery;
+import android.Manifest.permission;
+import android.annotation.TargetApi;
+import android.content.pm.PackageManager;
+import android.os.Build;
import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v4.app.ActivityCompat;
+import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
+import android.support.v4.content.ContextCompat;
+import android.widget.Toast;
import com.bumptech.glide.MemoryCategory;
/**
@@ -9,10 +18,53 @@ import com.bumptech.glide.MemoryCategory;
*/
public class MainActivity extends FragmentActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main_activity);
- GlideApp.get(this).setMemoryCategory(MemoryCategory.HIGH);
+ private static final int REQUEST_READ_STORAGE = 0;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main_activity);
+ GlideApp.get(this).setMemoryCategory(MemoryCategory.HIGH);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
+ && ContextCompat.checkSelfPermission(this, permission.READ_EXTERNAL_STORAGE)
+ != PackageManager.PERMISSION_GRANTED) {
+ requestStoragePermission();
+ } else {
+ replaceFragment();
+ }
+ }
+
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
+ private void requestStoragePermission() {
+ ActivityCompat.requestPermissions(this,
+ new String[]{permission.READ_EXTERNAL_STORAGE},
+ REQUEST_READ_STORAGE);
+ }
+
+ private void replaceFragment() {
+ Fragment fragment = new HorizontalGalleryFragment();
+ getSupportFragmentManager()
+ .beginTransaction()
+ .replace(R.id.fragment_container, fragment)
+ .commit();
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
+ @NonNull int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ switch (requestCode) {
+ case REQUEST_READ_STORAGE: {
+ // If request is cancelled, the result arrays are empty.
+ if (grantResults.length > 0
+ && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ replaceFragment();
+ } else {
+ Toast.makeText(this, "Storage permission is required", Toast.LENGTH_LONG)
+ .show();
+ requestStoragePermission();
+ }
+ }
}
+ }
}
diff --git a/samples/gallery/src/main/res/layout/main_activity.xml b/samples/gallery/src/main/res/layout/main_activity.xml
index 18c1a634f007d15198658101403c7820741ae140..8a31cf241223b63d7e1fec3f5b515a5e1c9e805d 100644
--- a/samples/gallery/src/main/res/layout/main_activity.xml
+++ b/samples/gallery/src/main/res/layout/main_activity.xml
@@ -1,8 +1,7 @@
-
-
-
+
+