35
35
import androidx .preference .PreferenceFragmentCompat ;
36
36
import androidx .recyclerview .widget .RecyclerView ;
37
37
import androidx .viewpager .widget .ViewPager .OnPageChangeListener ;
38
+
38
39
import de .mrapp .android .dialog .EditTextDialog ;
39
40
import de .mrapp .android .dialog .MaterialDialog ;
40
41
import de .mrapp .android .dialog .ProgressDialog ;
@@ -177,7 +178,16 @@ private void initializeListDialog() {
177
178
MaterialDialog .Builder builder = new MaterialDialog .Builder (getActivity ());
178
179
configureHeaderDialogBuilder (builder );
179
180
configureButtonBarDialogBuilder (builder );
180
- builder .setItems (R .array .list_items , createSingleChoiceListener ());
181
+
182
+ if (shouldListItemIconsBeShown ()) {
183
+ int [] iconResourceIds = new int []{R .drawable .ic_info_24dp , R .drawable .ic_info_24dp ,
184
+ R .drawable .ic_info_24dp };
185
+ builder .setItems (R .array .list_items , iconResourceIds , createSingleChoiceListener ());
186
+ builder .setItemIconTint (ContextCompat .getColor (getActivity (), R .color .color_accent ));
187
+ } else {
188
+ builder .setItems (R .array .list_items , createSingleChoiceListener ());
189
+ }
190
+
181
191
listDialog = builder .create ();
182
192
}
183
193
@@ -188,7 +198,17 @@ private void initializeSingleChoiceListDialog() {
188
198
MaterialDialog .Builder builder = new MaterialDialog .Builder (getActivity ());
189
199
configureHeaderDialogBuilder (builder );
190
200
configureButtonBarDialogBuilder (builder );
191
- builder .setSingleChoiceItems (R .array .list_items , 0 , createSingleChoiceListener ());
201
+
202
+ if (shouldListItemIconsBeShown ()) {
203
+ int [] iconResourceIds = new int []{R .drawable .ic_info_24dp , R .drawable .ic_info_24dp ,
204
+ R .drawable .ic_info_24dp };
205
+ builder .setSingleChoiceItems (R .array .list_items , iconResourceIds , 0 ,
206
+ createSingleChoiceListener ());
207
+ builder .setItemIconTint (ContextCompat .getColor (getActivity (), R .color .color_accent ));
208
+ } else {
209
+ builder .setSingleChoiceItems (R .array .list_items , 0 , createSingleChoiceListener ());
210
+ }
211
+
192
212
singleChoiceListDialog = builder .create ();
193
213
}
194
214
@@ -199,8 +219,18 @@ private void initializeMultipleChoiceListDialog() {
199
219
MaterialDialog .Builder builder = new MaterialDialog .Builder (getActivity ());
200
220
configureHeaderDialogBuilder (builder );
201
221
configureButtonBarDialogBuilder (builder );
202
- builder .setMultiChoiceItems (R .array .list_items , new boolean []{true , false , false },
203
- createMultiChoiceListener ());
222
+
223
+ if (shouldListItemIconsBeShown ()) {
224
+ int [] iconResourceIds = new int []{R .drawable .ic_info_24dp , R .drawable .ic_info_24dp ,
225
+ R .drawable .ic_info_24dp };
226
+ builder .setMultiChoiceItems (R .array .list_items , iconResourceIds ,
227
+ new boolean []{true , false , false }, createMultiChoiceListener ());
228
+ builder .setItemIconTint (ContextCompat .getColor (getActivity (), R .color .color_accent ));
229
+ } else {
230
+ builder .setMultiChoiceItems (R .array .list_items , new boolean []{true , false , false },
231
+ createMultiChoiceListener ());
232
+ }
233
+
204
234
multipleChoiceListDialog = builder .create ();
205
235
}
206
236
@@ -435,9 +465,8 @@ public boolean onPreferenceClick(final Preference preference) {
435
465
* Creates and returns the rectangular reveal animation, which should be used to show or hide
436
466
* dialogs.
437
467
*
438
- * @param preference
439
- * The preference, which is used to show the dialog, as an instance of the class {@link
440
- * Preference}
468
+ * @param preference The preference, which is used to show the dialog, as an instance of the class {@link
469
+ * Preference}
441
470
* @return The animation, which has been created, as an instance of the type {@link
442
471
* DialogAnimation}
443
472
*/
@@ -468,8 +497,7 @@ private DialogAnimation createRectangularRevealAnimation(@NonNull final Preferen
468
497
* Creates and returns the circle reveal animation, which should be used to show or hide
469
498
* dialogs.
470
499
*
471
- * @param view
472
- * The view, which is used to show the dialog, as an instance of the class {@link View}
500
+ * @param view The view, which is used to show the dialog, as an instance of the class {@link View}
473
501
* @return The animation, which has been created, as an instance of the type {@link
474
502
* DialogAnimation}
475
503
*/
@@ -576,9 +604,8 @@ public boolean onPreferenceClick(final Preference preference) {
576
604
* Creates and returns a listener, which allows to change the background color of the wizard
577
605
* dialog, when its view pager is scrolled.
578
606
*
579
- * @param wizardDialog
580
- * The wizard dialog as an instance of the class {@link WizardDialog}. The wizard dialog
581
- * may not be null
607
+ * @param wizardDialog The wizard dialog as an instance of the class {@link WizardDialog}. The wizard dialog
608
+ * may not be null
582
609
* @return The listener, which has been created, as an instance of the type {@link
583
610
* OnPageChangeListener}
584
611
*/
@@ -626,8 +653,7 @@ public void onPageScrollStateChanged(final int state) {
626
653
* Creates and returns a listener, which allows to reset a wizard dialog's header background to
627
654
* default, when its animation is finished.
628
655
*
629
- * @param wizardDialog
630
- * The wizard dialog as an instance of the class {@link WizardDialog}
656
+ * @param wizardDialog The wizard dialog as an instance of the class {@link WizardDialog}
631
657
* @return The listener, which has been created, as an instance of the type {@link
632
658
* AnimationListener}
633
659
*/
@@ -655,11 +681,9 @@ public void onAnimationEnd() {
655
681
/**
656
682
* Adds a new fragment to a builder, which allows to create wizard dialogs.
657
683
*
658
- * @param builder
659
- * The builder, the fragment should be added to, as an instance of the class {@link
660
- * WizardDialog.Builder}
661
- * @param index
662
- * The index of the fragment, which should be added
684
+ * @param builder The builder, the fragment should be added to, as an instance of the class {@link
685
+ * WizardDialog.Builder}
686
+ * @param index The index of the fragment, which should be added
663
687
*/
664
688
private void addFragment (@ NonNull final WizardDialog .Builder builder , final int index ) {
665
689
Bundle arguments = new Bundle ();
@@ -672,9 +696,8 @@ private void addFragment(@NonNull final WizardDialog.Builder builder, final int
672
696
/**
673
697
* Shows a specific toast and cancels a previous one, if existing.
674
698
*
675
- * @param text
676
- * The text of the toast, which should be shown, as a {@link String}, or null, if no
677
- * toast should be shown
699
+ * @param text The text of the toast, which should be shown, as a {@link String}, or null, if no
700
+ * toast should be shown
678
701
*/
679
702
private void showToast (@ Nullable final String text ) {
680
703
if (toast != null ) {
@@ -689,9 +712,8 @@ private void showToast(@Nullable final String text) {
689
712
* Configures a builder, which allows to create header dialogs, depending on the app's
690
713
* settings.
691
714
*
692
- * @param builder
693
- * The builder, which should be configured, as an instance of the class {@link
694
- * AbstractHeaderDialogBuilder}
715
+ * @param builder The builder, which should be configured, as an instance of the class {@link
716
+ * AbstractHeaderDialogBuilder}
695
717
*/
696
718
private void configureHeaderDialogBuilder (@ NonNull final AbstractHeaderDialogBuilder builder ) {
697
719
builder .setFullscreen (shouldUseFullscreen ());
@@ -721,9 +743,8 @@ private void configureHeaderDialogBuilder(@NonNull final AbstractHeaderDialogBui
721
743
* Configures a builder, which allows to create button bar dialogs, depending on the app's
722
744
* settings.
723
745
*
724
- * @param builder
725
- * The builder, which should be configured as an instance of the class {@link
726
- * AbstractButtonBarDialogBuilder}
746
+ * @param builder The builder, which should be configured as an instance of the class {@link
747
+ * AbstractButtonBarDialogBuilder}
727
748
*/
728
749
private void configureButtonBarDialogBuilder (
729
750
@ NonNull final AbstractButtonBarDialogBuilder builder ) {
@@ -841,6 +862,20 @@ private boolean shouldIconBeShown() {
841
862
return sharedPreferences .getBoolean (key , defaultValue );
842
863
}
843
864
865
+ /**
866
+ * Returns, whether the list items of the example dialogs should have an icon, or not.
867
+ *
868
+ * @return True, if the list items should have an icon, false otherwise
869
+ */
870
+ private boolean shouldListItemIconsBeShown () {
871
+ SharedPreferences sharedPreferences =
872
+ PreferenceManager .getDefaultSharedPreferences (getActivity ());
873
+ String key = getString (R .string .show_list_item_icon_preference_key );
874
+ boolean defaultValue =
875
+ getResources ().getBoolean (R .bool .show_list_item_icon_preference_default_value );
876
+ return sharedPreferences .getBoolean (key , defaultValue );
877
+ }
878
+
844
879
/**
845
880
* Returns, whether the message of the example dialog should be shown, or not.
846
881
*
@@ -1022,8 +1057,7 @@ private boolean shouldUseFullscreen() {
1022
1057
/**
1023
1058
* Shows an alert dialog using a circle reveal animation.
1024
1059
*
1025
- * @param view
1026
- * The view, which is used to show the dialog, as an instance of the class {@link View}
1060
+ * @param view The view, which is used to show the dialog, as an instance of the class {@link View}
1027
1061
*/
1028
1062
public final void showAlertDialog (@ NonNull final View view ) {
1029
1063
initializeAlertDialog ();
0 commit comments