Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit 61a89b3

Browse files
danke77samtstern
authored andcommitted
custom dialog theme (#146)
1 parent 7d3d459 commit 61a89b3

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

easypermissions/src/main/java/pub/devrel/easypermissions/AppSettingsDialog.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.support.annotation.RequiresApi;
1515
import android.support.annotation.RestrictTo;
1616
import android.support.annotation.StringRes;
17+
import android.support.annotation.StyleRes;
1718
import android.support.v4.app.Fragment;
1819
import android.support.v7.app.AlertDialog;
1920
import android.text.TextUtils;
@@ -43,6 +44,8 @@ public AppSettingsDialog[] newArray(int size) {
4344

4445
static final String EXTRA_APP_SETTINGS = "extra_app_settings";
4546

47+
@StyleRes
48+
private final int mThemeResId;
4649
private final String mRationale;
4750
private final String mTitle;
4851
private final String mPositiveButtonText;
@@ -53,6 +56,7 @@ public AppSettingsDialog[] newArray(int size) {
5356
private DialogInterface.OnClickListener mNegativeListener;
5457

5558
private AppSettingsDialog(Parcel in) {
59+
mThemeResId = in.readInt();
5660
mRationale = in.readString();
5761
mTitle = in.readString();
5862
mPositiveButtonText = in.readString();
@@ -62,6 +66,7 @@ private AppSettingsDialog(Parcel in) {
6266

6367
private AppSettingsDialog(@NonNull final Object activityOrFragment,
6468
@NonNull final Context context,
69+
@StyleRes int themeResId,
6570
@Nullable String rationale,
6671
@Nullable String title,
6772
@Nullable String positiveButtonText,
@@ -70,6 +75,7 @@ private AppSettingsDialog(@NonNull final Object activityOrFragment,
7075
int requestCode) {
7176
mActivityOrFragment = activityOrFragment;
7277
mContext = context;
78+
mThemeResId = themeResId;
7379
mRationale = rationale;
7480
mTitle = title;
7581
mPositiveButtonText = positiveButtonText;
@@ -98,7 +104,7 @@ private void startForResult(Intent intent) {
98104
((Fragment) mActivityOrFragment).startActivityForResult(intent, mRequestCode);
99105
} else if (mActivityOrFragment instanceof android.app.Fragment) {
100106
((android.app.Fragment) mActivityOrFragment).startActivityForResult(intent,
101-
mRequestCode);
107+
mRequestCode);
102108
}
103109
}
104110

@@ -120,7 +126,13 @@ public void show() {
120126
* Show the dialog. {@link #show()} is a wrapper to ensure backwards compatibility
121127
*/
122128
AlertDialog showDialog() {
123-
return new AlertDialog.Builder(mContext)
129+
AlertDialog.Builder builder;
130+
if (mThemeResId > 0) {
131+
builder = new AlertDialog.Builder(mContext, mThemeResId);
132+
} else {
133+
builder = new AlertDialog.Builder(mContext);
134+
}
135+
return builder
124136
.setCancelable(false)
125137
.setTitle(mTitle)
126138
.setMessage(mRationale)
@@ -148,6 +160,7 @@ public int describeContents() {
148160

149161
@Override
150162
public void writeToParcel(@NonNull Parcel dest, int flags) {
163+
dest.writeInt(mThemeResId);
151164
dest.writeString(mRationale);
152165
dest.writeString(mTitle);
153166
dest.writeString(mPositiveButtonText);
@@ -162,6 +175,8 @@ public static class Builder {
162175

163176
private Object mActivityOrFragment;
164177
private Context mContext;
178+
@StyleRes
179+
private int mThemeResId = -1;
165180
private String mRationale;
166181
private String mTitle;
167182
private String mPositiveButton;
@@ -246,6 +261,13 @@ public Builder(@NonNull android.app.Fragment fragment) {
246261
mContext = fragment.getActivity();
247262
}
248263

264+
/**
265+
* Set the dialog theme.
266+
*/
267+
public Builder setThemeResId(@StyleRes int themeResId) {
268+
mThemeResId = themeResId;
269+
return this;
270+
}
249271

250272
/**
251273
* Set the title dialog. Default is "Permissions Required".
@@ -362,6 +384,7 @@ public AppSettingsDialog build() {
362384
return new AppSettingsDialog(
363385
mActivityOrFragment,
364386
mContext,
387+
mThemeResId,
365388
mRationale,
366389
mTitle,
367390
mPositiveButton,

0 commit comments

Comments
 (0)