14
14
import android .support .annotation .RequiresApi ;
15
15
import android .support .annotation .RestrictTo ;
16
16
import android .support .annotation .StringRes ;
17
+ import android .support .annotation .StyleRes ;
17
18
import android .support .v4 .app .Fragment ;
18
19
import android .support .v7 .app .AlertDialog ;
19
20
import android .text .TextUtils ;
@@ -43,6 +44,8 @@ public AppSettingsDialog[] newArray(int size) {
43
44
44
45
static final String EXTRA_APP_SETTINGS = "extra_app_settings" ;
45
46
47
+ @ StyleRes
48
+ private final int mThemeResId ;
46
49
private final String mRationale ;
47
50
private final String mTitle ;
48
51
private final String mPositiveButtonText ;
@@ -53,6 +56,7 @@ public AppSettingsDialog[] newArray(int size) {
53
56
private DialogInterface .OnClickListener mNegativeListener ;
54
57
55
58
private AppSettingsDialog (Parcel in ) {
59
+ mThemeResId = in .readInt ();
56
60
mRationale = in .readString ();
57
61
mTitle = in .readString ();
58
62
mPositiveButtonText = in .readString ();
@@ -62,6 +66,7 @@ private AppSettingsDialog(Parcel in) {
62
66
63
67
private AppSettingsDialog (@ NonNull final Object activityOrFragment ,
64
68
@ NonNull final Context context ,
69
+ @ StyleRes int themeResId ,
65
70
@ Nullable String rationale ,
66
71
@ Nullable String title ,
67
72
@ Nullable String positiveButtonText ,
@@ -70,6 +75,7 @@ private AppSettingsDialog(@NonNull final Object activityOrFragment,
70
75
int requestCode ) {
71
76
mActivityOrFragment = activityOrFragment ;
72
77
mContext = context ;
78
+ mThemeResId = themeResId ;
73
79
mRationale = rationale ;
74
80
mTitle = title ;
75
81
mPositiveButtonText = positiveButtonText ;
@@ -98,7 +104,7 @@ private void startForResult(Intent intent) {
98
104
((Fragment ) mActivityOrFragment ).startActivityForResult (intent , mRequestCode );
99
105
} else if (mActivityOrFragment instanceof android .app .Fragment ) {
100
106
((android .app .Fragment ) mActivityOrFragment ).startActivityForResult (intent ,
101
- mRequestCode );
107
+ mRequestCode );
102
108
}
103
109
}
104
110
@@ -120,7 +126,13 @@ public void show() {
120
126
* Show the dialog. {@link #show()} is a wrapper to ensure backwards compatibility
121
127
*/
122
128
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
124
136
.setCancelable (false )
125
137
.setTitle (mTitle )
126
138
.setMessage (mRationale )
@@ -148,6 +160,7 @@ public int describeContents() {
148
160
149
161
@ Override
150
162
public void writeToParcel (@ NonNull Parcel dest , int flags ) {
163
+ dest .writeInt (mThemeResId );
151
164
dest .writeString (mRationale );
152
165
dest .writeString (mTitle );
153
166
dest .writeString (mPositiveButtonText );
@@ -162,6 +175,8 @@ public static class Builder {
162
175
163
176
private Object mActivityOrFragment ;
164
177
private Context mContext ;
178
+ @ StyleRes
179
+ private int mThemeResId = -1 ;
165
180
private String mRationale ;
166
181
private String mTitle ;
167
182
private String mPositiveButton ;
@@ -246,6 +261,13 @@ public Builder(@NonNull android.app.Fragment fragment) {
246
261
mContext = fragment .getActivity ();
247
262
}
248
263
264
+ /**
265
+ * Set the dialog theme.
266
+ */
267
+ public Builder setThemeResId (@ StyleRes int themeResId ) {
268
+ mThemeResId = themeResId ;
269
+ return this ;
270
+ }
249
271
250
272
/**
251
273
* Set the title dialog. Default is "Permissions Required".
@@ -362,6 +384,7 @@ public AppSettingsDialog build() {
362
384
return new AppSettingsDialog (
363
385
mActivityOrFragment ,
364
386
mContext ,
387
+ mThemeResId ,
365
388
mRationale ,
366
389
mTitle ,
367
390
mPositiveButton ,
0 commit comments