Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="pub.devrel.easypermissions.sample">

<uses-permission android:name="android.permission.CAMERA" />
Expand All @@ -14,7 +16,8 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,7 @@ public void onPermissionsDenied(int requestCode, List<String> perms) {
// (Optional) Check whether the user denied any permissions and checked "NEVER ASK AGAIN."
// This will display a dialog directing them to enable the permission in app settings.
if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
new AppSettingsDialog.Builder(this, getString(R.string.rationale_ask_again))
.setTitle(getString(R.string.title_settings_dialog))
.setPositiveButton(getString(R.string.setting))
.setNegativeButton(getString(R.string.cancel))
.build()
.show();
new AppSettingsDialog.Builder(this).build().show();
}
}

Expand Down
10 changes: 6 additions & 4 deletions app/src/main/res/layout/activity_basic.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".BasicActivity">

<Button
android:id="@+id/button_request"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Request" />
android:text="Request"
tools:ignore="HardcodedText"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to add @string resources in other places let's do it here as well rather than ignoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't do that because BasicActivity isn't part of the sample so it shouldn't pollute the strings.xml file. Do you agree with this or should I add it to the strings file anyway?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, that's fine either way then.


</LinearLayout>
</LinearLayout>
7 changes: 4 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -13,13 +14,13 @@
android:id="@+id/button_camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Camera" />
android:text="@string/camera" />

<Button
android:id="@+id/button_location_and_wifi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location and Contacts" />
android:text="@string/location_and_contacts" />

<fragment
android:id="@+id/fragment"
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<Button
android:id="@+id/button_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SMS" />
android:text="@string/sms" />

</FrameLayout>
11 changes: 4 additions & 7 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<resources>
<string name="app_name">PermissionsTest</string>
<string name="app_name">Easy Permissions</string>
<string name="rationale_camera">This app needs access to your camera so you can take pictures.</string>
<string name="rationale_location_contacts">This app needs access to your location and contacts to know where and who you are.</string>
<string name="rationale_sms">This app needs access to your sms to read all your great messages.</string>
<string name="rationale_ask_again">This app may not work correctly without the requested permissions. Open the app settings screen to modify app permissions.</string>
<string name="title_settings_dialog">Permissions Required</string>
<string name="setting">Settings</string>
<string name="cancel">Cancel</string>
<string name="settings_dialog_canceled">Settings dialog canceled</string>
<string name="returned_from_app_settings_to_activity">Returned from app settings to MainActivity</string>
<string name="has_read_sms_permission">Has read sms permission: %b</string>
<string name="camera">Camera</string>
<string name="location_and_contacts">Location and Contacts</string>
<string name="sms">SMS</string>
</resources>
4 changes: 0 additions & 4 deletions easypermissions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

lintOptions {
abortOnError false
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.annotation.RestrictTo;
import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
Expand Down Expand Up @@ -61,7 +62,7 @@ private AppSettingsDialog(Parcel in) {

private AppSettingsDialog(@NonNull final Object activityOrFragment,
@NonNull final Context context,
@NonNull String rationale,
@Nullable String rationale,
@Nullable String title,
@Nullable String positiveButtonText,
@Nullable String negativeButtonText,
Expand Down Expand Up @@ -174,7 +175,10 @@ public static class Builder {
*
* @param activity the {@link Activity} in which to display the dialog.
* @param rationale text explaining why the user should launch the app settings screen.
* @deprecated Use {@link #Builder(Activity)} with {@link #setRationale(String)} or {@link
* #setRationale(int)}.
*/
@Deprecated
public Builder(@NonNull Activity activity, @NonNull String rationale) {
mActivityOrFragment = activity;
mContext = activity;
Expand All @@ -186,7 +190,10 @@ public Builder(@NonNull Activity activity, @NonNull String rationale) {
*
* @param fragment the {@link Fragment} in which to display the dialog.
* @param rationale text explaining why the user should launch the app settings screen.
* @deprecated Use {@link #Builder(Fragment)} with {@link #setRationale(String)} or {@link
* #setRationale(int)}.
*/
@Deprecated
public Builder(@NonNull Fragment fragment, @NonNull String rationale) {
mActivityOrFragment = fragment;
mContext = fragment.getContext();
Expand All @@ -198,23 +205,85 @@ public Builder(@NonNull Fragment fragment, @NonNull String rationale) {
*
* @param fragment the {@link android.app.Fragment} in which to display the dialog.
* @param rationale text explaining why the user should launch the app settings screen.
* @deprecated Use {@link #Builder(android.app.Fragment)} with {@link #setRationale(String)}
* or {@link #setRationale(int)}.
*/
@Deprecated
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public Builder(@NonNull android.app.Fragment fragment, @NonNull String rationale) {
mActivityOrFragment = fragment;
mContext = fragment.getActivity();
mRationale = rationale;
}

/**
* Create a new Builder for an {@link AppSettingsDialog}.
*
* @param activity the {@link Activity} in which to display the dialog.
*/
public Builder(@NonNull Activity activity) {
mActivityOrFragment = activity;
mContext = activity;
}

/**
* Create a new Builder for an {@link AppSettingsDialog}.
*
* @param fragment the {@link Fragment} in which to display the dialog.
*/
public Builder(@NonNull Fragment fragment) {
mActivityOrFragment = fragment;
mContext = fragment.getContext();
}

/**
* Create a new Builder for an {@link AppSettingsDialog}.
*
* @param fragment the {@link android.app.Fragment} in which to display the dialog.
*/
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public Builder(@NonNull android.app.Fragment fragment) {
mActivityOrFragment = fragment;
mContext = fragment.getActivity();
}


/**
* Set the title dialog. Default is no title.
* Set the title dialog. Default is "Permissions Required".
*/
public Builder setTitle(String title) {
mTitle = title;
return this;
}

/**
* Set the title dialog. Default is "Permissions Required".
*/
public Builder setTitle(@StringRes int title) {
mTitle = mContext.getString(title);
return this;
}

/**
* Set the rationale dialog. Default is
* "This app may not work correctly without the requested permissions.
* Open the app settings screen to modify app permissions."
*/
public Builder setRationale(String rationale) {
mRationale = rationale;
return this;
}

/**
* Set the rationale dialog. Default is
* "This app may not work correctly without the requested permissions.
* Open the app settings screen to modify app permissions."
*/
public Builder setRationale(@StringRes int rationale) {
mRationale = mContext.getString(rationale);
return this;
}

/**
* Set the positive button text, default is {@link android.R.string#ok}.
*/
Expand All @@ -223,6 +292,14 @@ public Builder setPositiveButton(String positiveButton) {
return this;
}

/**
* Set the positive button text, default is {@link android.R.string#ok}.
*/
public Builder setPositiveButton(@StringRes int positiveButton) {
mPositiveButton = mContext.getString(positiveButton);
return this;
}

/**
* Set the negative button text and click listener, default text is
* {@link android.R.string#cancel}.
Expand Down Expand Up @@ -250,6 +327,14 @@ public Builder setNegativeButton(String negativeButton) {
return this;
}

/**
* Set the negative button text, default is {@link android.R.string#cancel}.
*/
public Builder setNegativeButton(@StringRes int negativeButton) {
mNegativeButton = mContext.getString(negativeButton);
return this;
}

/**
* Set the request code use when launching the Settings screen for result, can be retrieved
* in the calling Activity's {@link Activity#onActivityResult(int, int, Intent)} method.
Expand All @@ -265,6 +350,10 @@ public Builder setRequestCode(int requestCode) {
* call to {@link AppSettingsDialog#show()}.
*/
public AppSettingsDialog build() {
mRationale = TextUtils.isEmpty(mRationale) ?
mContext.getString(R.string.rationale_ask_again) : mRationale;
mTitle = TextUtils.isEmpty(mTitle) ?
mContext.getString(R.string.title_settings_dialog) : mTitle;
mPositiveButton = TextUtils.isEmpty(mPositiveButton) ?
mContext.getString(android.R.string.ok) : mPositiveButton;
mNegativeButton = TextUtils.isEmpty(mNegativeButton) ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package pub.devrel.easypermissions;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -112,7 +113,7 @@ public static void requestPermissions(@NonNull Activity activity,
* @param perms a set of permissions to be requested.
* @see Manifest.permission
*/
@SuppressWarnings("NewApi")
@SuppressLint("NewApi")
public static void requestPermissions(@NonNull Activity activity,
@NonNull String rationale,
@StringRes int positiveButton,
Expand Down Expand Up @@ -162,7 +163,7 @@ public static void requestPermissions(@NonNull Fragment fragment,
* Fragment#onRequestPermissionsResult(int, String[], int[])}.
* @see #requestPermissions(Activity, String, int, int, int, String...)
*/
@SuppressWarnings("NewApi")
@SuppressLint("NewApi")
public static void requestPermissions(@NonNull Fragment fragment,
@NonNull String rationale,
@StringRes int positiveButton,
Expand Down Expand Up @@ -209,7 +210,7 @@ public static void requestPermissions(@NonNull android.app.Fragment fragment,
* android.app.Fragment#onRequestPermissionsResult(int, String[], int[])}.
* @see #requestPermissions(Activity, String, int, int, int, String...)
*/
@SuppressWarnings("NewApi")
@SuppressLint("NewApi")
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public static void requestPermissions(@NonNull android.app.Fragment fragment,
@NonNull String rationale,
Expand Down
4 changes: 4 additions & 0 deletions easypermissions/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="rationale_ask_again">This app may not work correctly without the requested permissions. Open the app settings screen to modify app permissions.</string>
<string name="title_settings_dialog">Permissions Required</string>
</resources>