From d460fdf4ff7ef6039dbaa8104429ba67c300ebcf Mon Sep 17 00:00:00 2001 From: Sergio Gutierrez Date: Fri, 20 Nov 2015 17:13:39 +0100 Subject: [PATCH 1/5] Revert "Merge pull request #8 from anothem/master" This reverts commit d4e5a1879e23e23e35fd1b340ec738c4786e55da, reversing changes made to be049ab6d1ecbae9ec149a12586594b3d547cf48. --- .../com/karumi/dexter/DexterInstance.java | 14 ++--- .../DialogOnDeniedPermissionListener.java | 6 +- .../listener/EmptyPermissionListener.java | 7 ++- .../listener/MultiPermissionListener.java | 11 ++-- .../listener/PermissionDeniedResponse.java | 50 ---------------- .../listener/PermissionGrantedResponse.java | 43 -------------- .../dexter/listener/PermissionListener.java | 14 ++--- .../dexter/listener/PermissionRequest.java | 41 ------------- .../SnackbarOnDeniedPermissionListener.java | 8 +-- .../karumi/dexter/sample/SampleActivity.java | 59 +++++++------------ sample/src/main/res/values/strings.xml | 1 - 11 files changed, 47 insertions(+), 207 deletions(-) delete mode 100644 dexter/src/main/java/com/karumi/dexter/listener/PermissionDeniedResponse.java delete mode 100644 dexter/src/main/java/com/karumi/dexter/listener/PermissionGrantedResponse.java delete mode 100644 dexter/src/main/java/com/karumi/dexter/listener/PermissionRequest.java diff --git a/dexter/src/main/java/com/karumi/dexter/DexterInstance.java b/dexter/src/main/java/com/karumi/dexter/DexterInstance.java index 338bcf07..214a33cb 100644 --- a/dexter/src/main/java/com/karumi/dexter/DexterInstance.java +++ b/dexter/src/main/java/com/karumi/dexter/DexterInstance.java @@ -22,12 +22,7 @@ import android.content.pm.PackageManager; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; - -import com.karumi.dexter.listener.PermissionDeniedResponse; -import com.karumi.dexter.listener.PermissionGrantedResponse; import com.karumi.dexter.listener.PermissionListener; -import com.karumi.dexter.listener.PermissionRequest; - import java.util.concurrent.atomic.AtomicBoolean; /** @@ -119,13 +114,13 @@ void onCancelPermissionRequest(String permission) { */ void requestPermission(String permission) { int permissionCode = getPermissionCodeForPermission(permission); - ActivityCompat.requestPermissions(activity, new String[]{permission}, permissionCode); + ActivityCompat.requestPermissions(activity, new String[] {permission}, permissionCode); } private void handleDeniedPermission(String permission) { if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { PermissionRationaleToken permissionToken = new PermissionRationaleToken(this, permission); - listener.onPermissionRationaleShouldBeShown(new PermissionRequest(permission), permissionToken); + listener.onPermissionRationaleShouldBeShown(permission, permissionToken); } else { requestPermission(permission); } @@ -133,14 +128,13 @@ private void handleDeniedPermission(String permission) { private void finishWithGrantedPermission(String permission) { activity.finish(); - listener.onPermissionGranted(PermissionGrantedResponse.from(permission)); + listener.onPermissionGranted(permission); isRequestingPermission.set(false); } private void finishWithDeniedPermission(String permission) { activity.finish(); - listener.onPermissionDenied(PermissionDeniedResponse.from(permission, - !ActivityCompat.shouldShowRequestPermissionRationale(activity, permission))); + listener.onPermissionDenied(permission); isRequestingPermission.set(false); } diff --git a/dexter/src/main/java/com/karumi/dexter/listener/DialogOnDeniedPermissionListener.java b/dexter/src/main/java/com/karumi/dexter/listener/DialogOnDeniedPermissionListener.java index 283ec418..8544d932 100644 --- a/dexter/src/main/java/com/karumi/dexter/listener/DialogOnDeniedPermissionListener.java +++ b/dexter/src/main/java/com/karumi/dexter/listener/DialogOnDeniedPermissionListener.java @@ -25,7 +25,7 @@ public class DialogOnDeniedPermissionListener extends EmptyPermissionListener { private final Drawable icon; private DialogOnDeniedPermissionListener(Context context, String title, String message, - String positiveButtonText, Drawable icon) { + String positiveButtonText, Drawable icon) { this.context = context; this.title = title; this.message = message; @@ -33,8 +33,8 @@ private DialogOnDeniedPermissionListener(Context context, String title, String m this.icon = icon; } - @Override public void onPermissionDenied(PermissionDeniedResponse response) { - super.onPermissionDenied(response); + @Override public void onPermissionDenied(String permission) { + super.onPermissionDenied(permission); new AlertDialog.Builder(context) .setTitle(title) diff --git a/dexter/src/main/java/com/karumi/dexter/listener/EmptyPermissionListener.java b/dexter/src/main/java/com/karumi/dexter/listener/EmptyPermissionListener.java index 2990b66d..3f8054c2 100644 --- a/dexter/src/main/java/com/karumi/dexter/listener/EmptyPermissionListener.java +++ b/dexter/src/main/java/com/karumi/dexter/listener/EmptyPermissionListener.java @@ -24,15 +24,16 @@ */ public class EmptyPermissionListener implements PermissionListener { - @Override public void onPermissionGranted(PermissionGrantedResponse response) { + @Override public void onPermissionGranted(String permission) { } - @Override public void onPermissionDenied(PermissionDeniedResponse response) { + @Override public void onPermissionDenied(String permission) { } - @Override public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) { + @Override + public void onPermissionRationaleShouldBeShown(String permission, PermissionToken token) { } } diff --git a/dexter/src/main/java/com/karumi/dexter/listener/MultiPermissionListener.java b/dexter/src/main/java/com/karumi/dexter/listener/MultiPermissionListener.java index 4a60513d..a438eee3 100644 --- a/dexter/src/main/java/com/karumi/dexter/listener/MultiPermissionListener.java +++ b/dexter/src/main/java/com/karumi/dexter/listener/MultiPermissionListener.java @@ -17,7 +17,6 @@ package com.karumi.dexter.listener; import com.karumi.dexter.PermissionToken; - import java.util.Arrays; import java.util.Collection; @@ -47,20 +46,20 @@ public MultiPermissionListener(Collection listeners) { this.listeners = listeners; } - @Override public void onPermissionGranted(PermissionGrantedResponse response) { + @Override public void onPermissionGranted(String permission) { for (PermissionListener listener : listeners) { - listener.onPermissionGranted(response); + listener.onPermissionGranted(permission); } } - @Override public void onPermissionDenied(PermissionDeniedResponse response) { + @Override public void onPermissionDenied(String permission) { for (PermissionListener listener : listeners) { - listener.onPermissionDenied(response); + listener.onPermissionDenied(permission); } } @Override - public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) { + public void onPermissionRationaleShouldBeShown(String permission, PermissionToken token) { for (PermissionListener listener : listeners) { listener.onPermissionRationaleShouldBeShown(permission, token); } diff --git a/dexter/src/main/java/com/karumi/dexter/listener/PermissionDeniedResponse.java b/dexter/src/main/java/com/karumi/dexter/listener/PermissionDeniedResponse.java deleted file mode 100644 index e537ba26..00000000 --- a/dexter/src/main/java/com/karumi/dexter/listener/PermissionDeniedResponse.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2015 Karumi. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.karumi.dexter.listener; - -import android.support.annotation.NonNull; - -/** - * If a permission was denied, an instance of this class will be returned - * in the callback. - */ -public final class PermissionDeniedResponse { - - private final PermissionRequest requestedPermission; - private final boolean permanentlyDenied; - - public PermissionDeniedResponse(@NonNull PermissionRequest requestedPermission, boolean permanentlyDenied) { - this.requestedPermission = requestedPermission; - this.permanentlyDenied = permanentlyDenied; - } - - /** - * Builds a new instance of PermissionDeniedResponse from a given permission string - * and a permanently-denied boolean flag - */ - public static PermissionDeniedResponse from(@NonNull String permission, boolean permanentlyDenied) { - return new PermissionDeniedResponse(new PermissionRequest(permission), permanentlyDenied); - } - - public PermissionRequest getRequestedPermission() { - return requestedPermission; - } - - public boolean isPermanentlyDenied() { - return permanentlyDenied; - } -} diff --git a/dexter/src/main/java/com/karumi/dexter/listener/PermissionGrantedResponse.java b/dexter/src/main/java/com/karumi/dexter/listener/PermissionGrantedResponse.java deleted file mode 100644 index 4df51b13..00000000 --- a/dexter/src/main/java/com/karumi/dexter/listener/PermissionGrantedResponse.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2015 Karumi. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.karumi.dexter.listener; - -import android.support.annotation.NonNull; - -/** - * If a permission was granted, an instance of this class will be returned - * in the callback. - */ -public final class PermissionGrantedResponse { - - private final PermissionRequest requestedPermission; - - public PermissionGrantedResponse(@NonNull PermissionRequest requestedPermission) { - this.requestedPermission = requestedPermission; - } - - /** - * Builds a new instance of PermissionGrantedResponse from a given permission string - */ - public static PermissionGrantedResponse from(@NonNull String permission) { - return new PermissionGrantedResponse(new PermissionRequest(permission)); - } - - public PermissionRequest getRequestedPermission() { - return requestedPermission; - } -} diff --git a/dexter/src/main/java/com/karumi/dexter/listener/PermissionListener.java b/dexter/src/main/java/com/karumi/dexter/listener/PermissionListener.java index b2600e4e..3376fb7e 100644 --- a/dexter/src/main/java/com/karumi/dexter/listener/PermissionListener.java +++ b/dexter/src/main/java/com/karumi/dexter/listener/PermissionListener.java @@ -26,18 +26,18 @@ public interface PermissionListener { /** * Method called whenever a requested permission has been granted. * - * @param response A response object that contains the permission that has been requested and - * any additional flags relevant to this response + * @param permission The permission that has been requested. One of the values found in {@link + * android.Manifest.permission} */ - void onPermissionGranted(PermissionGrantedResponse response); + void onPermissionGranted(String permission); /** * Method called whenever a requested permission has been denied. * - * @param response A response object that contains the permission that has been requested and - * any additional flags relevant to this response + * @param permission The permission that has been requested. One of the values found in {@link + * android.Manifest.permission} */ - void onPermissionDenied(PermissionDeniedResponse response); + void onPermissionDenied(String permission); /** * Method called whenever Android asks the application to inform the user of the need for the @@ -48,5 +48,5 @@ public interface PermissionListener { * @param token Token used to continue or cancel the permission request process. The permission * request process will remain blocked until one of the token methods is called. */ - void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token); + void onPermissionRationaleShouldBeShown(String permission, PermissionToken token); } diff --git a/dexter/src/main/java/com/karumi/dexter/listener/PermissionRequest.java b/dexter/src/main/java/com/karumi/dexter/listener/PermissionRequest.java deleted file mode 100644 index 1b3c13a5..00000000 --- a/dexter/src/main/java/com/karumi/dexter/listener/PermissionRequest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2015 Karumi. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.karumi.dexter.listener; - -import android.support.annotation.NonNull; - -/** - * Wrapper class for a permission request - */ -public final class PermissionRequest { - private final String permission; - - public PermissionRequest(@NonNull String permission) { - this.permission = permission; - } - - /** - * One of the values found in {@link android.Manifest.permission} - */ - public String getPermission() { - return permission; - } - - @Override public String toString() { - return "Permission: " + permission; - } -} diff --git a/dexter/src/main/java/com/karumi/dexter/listener/SnackbarOnDeniedPermissionListener.java b/dexter/src/main/java/com/karumi/dexter/listener/SnackbarOnDeniedPermissionListener.java index 61af32b5..bd53f732 100644 --- a/dexter/src/main/java/com/karumi/dexter/listener/SnackbarOnDeniedPermissionListener.java +++ b/dexter/src/main/java/com/karumi/dexter/listener/SnackbarOnDeniedPermissionListener.java @@ -43,15 +43,15 @@ public class SnackbarOnDeniedPermissionListener extends EmptyPermissionListener * @param onButtonClickListener Action performed when the user clicks the snackbar button */ private SnackbarOnDeniedPermissionListener(ViewGroup rootView, String text, String buttonText, - View.OnClickListener onButtonClickListener) { + View.OnClickListener onButtonClickListener) { this.rootView = rootView; this.text = text; this.buttonText = buttonText; this.onButtonClickListener = onButtonClickListener; } - @Override public void onPermissionDenied(PermissionDeniedResponse response) { - super.onPermissionDenied(response); + @Override public void onPermissionDenied(String permission) { + super.onPermissionDenied(permission); Snackbar snackbar = Snackbar.make(rootView, text, Snackbar.LENGTH_LONG); if (buttonText != null && onButtonClickListener != null) { @@ -96,7 +96,7 @@ public Builder withButton(String buttonText, View.OnClickListener onClickListene * Adds a text button with the provided click listener */ public Builder withButton(@StringRes int buttonTextResourceId, - View.OnClickListener onClickListener) { + View.OnClickListener onClickListener) { return withButton(rootView.getContext().getString(buttonTextResourceId), onClickListener); } diff --git a/sample/src/main/java/com/karumi/dexter/sample/SampleActivity.java b/sample/src/main/java/com/karumi/dexter/sample/SampleActivity.java index 2775cfe7..dd0e4dc3 100644 --- a/sample/src/main/java/com/karumi/dexter/sample/SampleActivity.java +++ b/sample/src/main/java/com/karumi/dexter/sample/SampleActivity.java @@ -26,21 +26,16 @@ import android.support.v4.content.ContextCompat; import android.view.ViewGroup; import android.widget.TextView; - +import butterknife.Bind; +import butterknife.ButterKnife; +import butterknife.OnClick; import com.karumi.dexter.Dexter; import com.karumi.dexter.PermissionToken; import com.karumi.dexter.listener.DialogOnDeniedPermissionListener; import com.karumi.dexter.listener.MultiPermissionListener; -import com.karumi.dexter.listener.PermissionDeniedResponse; -import com.karumi.dexter.listener.PermissionGrantedResponse; import com.karumi.dexter.listener.PermissionListener; -import com.karumi.dexter.listener.PermissionRequest; import com.karumi.dexter.listener.SnackbarOnDeniedPermissionListener; -import butterknife.Bind; -import butterknife.ButterKnife; -import butterknife.OnClick; - /** * Sample activity showing the permission request process with Dexter. */ @@ -74,40 +69,28 @@ public class SampleActivity extends Activity implements PermissionListener { Dexter.checkPermission(Manifest.permission.RECORD_AUDIO, audioPermissionListener); } - @Override public void onPermissionGranted(PermissionGrantedResponse response) { - switch (response.getRequestedPermission().getPermission()) { - case Manifest.permission.CAMERA: - showPermissionGranted(cameraPermissionFeedbackView); - break; - case Manifest.permission.READ_CONTACTS: - showPermissionGranted(contactsPermissionFeedbackView); - break; - case Manifest.permission.RECORD_AUDIO: - showPermissionGranted(audioPermissionFeedbackView); - break; - default: - throw new RuntimeException("We didn't request this permission!"); + @Override public void onPermissionGranted(String permission) { + if (Manifest.permission.CAMERA.equals(permission)) { + showPermissionGranted(cameraPermissionFeedbackView); + } else if (Manifest.permission.READ_CONTACTS.equals(permission)) { + showPermissionGranted(contactsPermissionFeedbackView); + } else if (Manifest.permission.RECORD_AUDIO.equals(permission)) { + showPermissionGranted(audioPermissionFeedbackView); } } - @Override public void onPermissionDenied(PermissionDeniedResponse response) { - switch (response.getRequestedPermission().getPermission()) { - case Manifest.permission.CAMERA: - showPermissionDenied(cameraPermissionFeedbackView, response.isPermanentlyDenied()); - break; - case Manifest.permission.READ_CONTACTS: - showPermissionDenied(contactsPermissionFeedbackView, response.isPermanentlyDenied()); - break; - case Manifest.permission.RECORD_AUDIO: - showPermissionDenied(audioPermissionFeedbackView, response.isPermanentlyDenied()); - break; - default: - throw new RuntimeException("We didn't request this permission!"); + @Override public void onPermissionDenied(String permission) { + if (Manifest.permission.CAMERA.equals(permission)) { + showPermissionDenied(cameraPermissionFeedbackView); + } else if (Manifest.permission.READ_CONTACTS.equals(permission)) { + showPermissionDenied(contactsPermissionFeedbackView); + } else if (Manifest.permission.RECORD_AUDIO.equals(permission)) { + showPermissionDenied(audioPermissionFeedbackView); } } @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @Override - public void onPermissionRationaleShouldBeShown(PermissionRequest permission, final PermissionToken token) { + public void onPermissionRationaleShouldBeShown(String permission, final PermissionToken token) { new AlertDialog.Builder(this) .setTitle(R.string.permission_rationale_title) .setMessage(R.string.permission_rationale_message) @@ -136,10 +119,8 @@ private void showPermissionGranted(TextView feedbackView) { feedbackView.setTextColor(ContextCompat.getColor(this, R.color.permission_granted)); } - private void showPermissionDenied(TextView feedbackView, boolean isPermanentlyDenied) { - feedbackView.setText(isPermanentlyDenied - ? R.string.permission_permanently_denied_feedback - : R.string.permission_denied_feedback); + private void showPermissionDenied(TextView feedbackView) { + feedbackView.setText(R.string.permission_denied_feedback); feedbackView.setTextColor(ContextCompat.getColor(this, R.color.permission_denied)); } diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 5184aa8b..ee188fac 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -21,7 +21,6 @@ Audio GRANTED DENIED - PERMA-DENIED UNKNOWN Camera permission is needed for doing some magic Contacts permission is needed for doing some magic From be4ffb13da520ab3437b0cd32bdc6da56a4684e8 Mon Sep 17 00:00:00 2001 From: Bartosz Lipinski Date: Fri, 20 Nov 2015 18:10:51 +0100 Subject: [PATCH 2/5] Checking permissions sequentially made possible --- dexter/src/main/java/com/karumi/dexter/DexterInstance.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dexter/src/main/java/com/karumi/dexter/DexterInstance.java b/dexter/src/main/java/com/karumi/dexter/DexterInstance.java index 214a33cb..431c86a1 100644 --- a/dexter/src/main/java/com/karumi/dexter/DexterInstance.java +++ b/dexter/src/main/java/com/karumi/dexter/DexterInstance.java @@ -128,14 +128,14 @@ private void handleDeniedPermission(String permission) { private void finishWithGrantedPermission(String permission) { activity.finish(); - listener.onPermissionGranted(permission); isRequestingPermission.set(false); + listener.onPermissionGranted(permission); } private void finishWithDeniedPermission(String permission) { activity.finish(); - listener.onPermissionDenied(permission); isRequestingPermission.set(false); + listener.onPermissionDenied(permission); } private int getPermissionCodeForPermission(String permission) { From 9eac3f9f9327f4b2fe12469b8c877e4ec37cf470 Mon Sep 17 00:00:00 2001 From: Sergio Gutierrez Date: Fri, 20 Nov 2015 19:19:04 +0100 Subject: [PATCH 3/5] Prepare for release 1.0.3 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d843b825..acf4c326 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ POM_NAME=Dexter POM_ARTIFACT_ID=dexter POM_PACKAGING=aar -VERSION_NAME=1.0.3-SNAPSHOT +VERSION_NAME=1.0.3 VERSION_CODE=100003 GROUP=com.karumi From 95c2cb33b192f3d0e2206e8b45cc9f59b258589d Mon Sep 17 00:00:00 2001 From: Sergio Gutierrez Date: Fri, 20 Nov 2015 19:23:16 +0100 Subject: [PATCH 4/5] Prepare for development --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index acf4c326..3262b3ba 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,8 +2,8 @@ POM_NAME=Dexter POM_ARTIFACT_ID=dexter POM_PACKAGING=aar -VERSION_NAME=1.0.3 -VERSION_CODE=100003 +VERSION_NAME=1.0.4-SNAPSHOT +VERSION_CODE=100004 GROUP=com.karumi POM_DESCRIPTION=Dexter is an Android library to handle runtime permissions for Marshmallow easily From 143fc0089df76cdeabe36548bdcd23e75d034543 Mon Sep 17 00:00:00 2001 From: Serchinastico <54Cymru@gmail.com> Date: Sat, 21 Nov 2015 11:00:12 +0100 Subject: [PATCH 5/5] Update README.md for release 1.0.3 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ad3fb49a..8d124333 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ Include the library in your ``build.gradle`` ```groovy dependencies{ - compile 'com.karumi:dexter:1.0.2' + compile 'com.karumi:dexter:1.0.3' } ``` @@ -93,7 +93,7 @@ or to your ``pom.xml`` if you are using Maven com.karumi dexter - 1.0.2 + 1.0.3 aar