Skip to content

Commit 7f34ec0

Browse files
committed
Merge remote-tracking branch 'guger/master'
2 parents 6dee606 + 23081de commit 7f34ec0

File tree

2 files changed

+78
-42
lines changed

2 files changed

+78
-42
lines changed

icondialog/src/main/java/com/maltaisn/icondialog/IconDialog.java

+38-13
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ public class IconDialog extends DialogFragment {
7878

7979
@Retention(RetentionPolicy.SOURCE)
8080
@IntDef(value = {VISIBILITY_ALWAYS, VISIBILITY_NEVER, VISIBILITY_IF_LANG_AVAILABLE})
81-
public @interface SearchVisibility {}
81+
public @interface SearchVisibility {
82+
}
8283

8384
@Retention(RetentionPolicy.SOURCE)
8485
@IntDef(value = {VISIBILITY_ALWAYS, VISIBILITY_NEVER, VISIBILITY_IF_NO_SEARCH})
85-
public @interface TitleVisibility {}
86+
public @interface TitleVisibility {
87+
}
8688

8789
public static final int MAX_SELECTION_NONE = -1;
8890

@@ -101,23 +103,29 @@ public class IconDialog extends DialogFragment {
101103
private int iconSize;
102104
private int[] iconColors;
103105

104-
private @SearchVisibility int searchVisibility;
105-
private @Nullable Locale searchLanguage;
106+
private @SearchVisibility
107+
int searchVisibility;
108+
private @Nullable
109+
Locale searchLanguage;
106110
private boolean showHeaders;
107111
private boolean stickyHeaders;
108112
private boolean showSelectBtn;
109113
private int maxSelection;
110114
private boolean maxSelShowMessage;
111-
private @Nullable String maxSelMessage;
115+
private @Nullable
116+
String maxSelMessage;
112117
private boolean showClearBtn;
113-
private @TitleVisibility int dialogTitleVisibility;
114-
private @Nullable String dialogTitle;
118+
private @TitleVisibility
119+
int dialogTitleVisibility;
120+
private @Nullable
121+
String dialogTitle;
115122
private BaseIconFilter iconFilter;
116123
private boolean loadIconDrawables;
117124

118125
private List<Item> listItems;
119126
private List<Item> selectedItems;
120-
private @Nullable int[] selectedIconsId;
127+
private @Nullable
128+
int[] selectedIconsId;
121129
private String searchText;
122130

123131
private boolean searchIgnoreDelay;
@@ -155,9 +163,9 @@ public void onCreate(Bundle savedInstanceState) {
155163
iconHelper = IconHelper.getInstance(getActivity());
156164
iconHelper.addLoadCallback(new IconHelper.LoadCallback() {
157165
@Override
158-
public void onDataLoaded() {
166+
public void onDataLoaded(IconHelper helper) {
159167
if (loadIconDrawables) {
160-
iconHelper.loadIconDrawables();
168+
helper.loadIconDrawables();
161169
}
162170
}
163171
});
@@ -258,7 +266,7 @@ public void onClick(View v) {
258266

259267
iconHelper.addLoadCallback(new IconHelper.LoadCallback() {
260268
@Override
261-
public void onDataLoaded() {
269+
public void onDataLoaded(IconHelper helper) {
262270
loadPb.setVisibility(View.GONE);
263271

264272
final EditText searchEdt = view.findViewById(R.id.icd_edt_search);
@@ -305,10 +313,12 @@ public void run() {
305313
searchEdt.setText(searchText);
306314
searchEdt.addTextChangedListener(new TextWatcher() {
307315
@Override
308-
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
316+
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
317+
}
309318

310319
@Override
311-
public void onTextChanged(CharSequence s, int start, int before, int count) { }
320+
public void onTextChanged(CharSequence s, int start, int before, int count) {
321+
}
312322

313323
@Override
314324
public void afterTextChanged(Editable text) {
@@ -507,6 +517,7 @@ private Object getCaller() {
507517

508518
/**
509519
* Get the list of icons matching search with category headers
520+
*
510521
* @param search null to get whole list, or text to search among icon labels to filter icons
511522
* @return the list of items
512523
*/
@@ -597,6 +608,7 @@ public int compare(Item i1, Item i2) {
597608

598609
/**
599610
* Get the position of items in the adapter
611+
*
600612
* @param items array of icon items (varargs)
601613
* @return the array of positions
602614
*/
@@ -622,6 +634,7 @@ private int[] getItemsPosition(Item... items) {
622634
/**
623635
* Depending on the setting set at {@link #setSearchEnabled(int, Locale)}, checks
624636
* whether search will be enabled or not
637+
*
625638
* @return true if search is enabled
626639
*/
627640
public boolean isSearchAvailable() {
@@ -658,6 +671,7 @@ public boolean isSearchAvailable() {
658671
* Set whether search is enabled or not
659672
* By default, search is only enabled if device's language is available
660673
* When search is not enabled, a title will be shown on the dialog instead of the search bar
674+
*
661675
* @param visibility {@link #VISIBILITY_ALWAYS} to always enable search.
662676
* {@link #VISIBILITY_NEVER} to always disable search.
663677
* {@link #VISIBILITY_IF_LANG_AVAILABLE} to enable search only if the language is available
@@ -676,6 +690,7 @@ public IconDialog setSearchEnabled(@SearchVisibility int visibility, @Nullable L
676690

677691
/**
678692
* Set the title of the dialog and when it is shown
693+
*
679694
* @param visibility {@link #VISIBILITY_ALWAYS} to always show the title
680695
* {@link #VISIBILITY_NEVER} to never show the title
681696
* {@link #VISIBILITY_IF_NO_SEARCH} to only show the title if search is not available
@@ -691,6 +706,7 @@ public IconDialog setTitle(@TitleVisibility int visibility, @Nullable String tit
691706
/**
692707
* Set list header options
693708
* By default, headers are shown and are sticky
709+
*
694710
* @param show whether to show the headers or not
695711
* @param sticky if headers are shown, whether they appear on top of the list when scrolling down
696712
* @return the dialog
@@ -705,6 +721,7 @@ public IconDialog setShowHeaders(boolean show, boolean sticky) {
705721
* Set whether the select button and the other dialog dialog buttons are shown
706722
* If not, dialog will be dismissed immediately after an icon is clicked.
707723
* By default, selection is shown. It is always shown if multiple selection is allowed
724+
*
708725
* @param show whether select button is shown or not
709726
* @return the dialog
710727
*/
@@ -715,6 +732,7 @@ public IconDialog setShowSelectButton(boolean show) {
715732

716733
/**
717734
* Set initial selected icons
735+
*
718736
* @param iconIds varargs of icons id, null or empty array for no initial selection
719737
* @return the dialog
720738
*/
@@ -729,6 +747,7 @@ public IconDialog setSelectedIcons(@Nullable int... iconIds) {
729747

730748
/**
731749
* Set initial selected icons
750+
*
732751
* @param icons varargs of icons, null or empty array for no initial selection
733752
* @return the dialog
734753
*/
@@ -750,6 +769,7 @@ public IconDialog setSelectedIcons(@Nullable Icon... icons) {
750769

751770
/**
752771
* Set maximum number of icons that can be selected
772+
*
753773
* @param max maximum number
754774
* @param showMessage If true, a message will be shown when maximum selection is reached
755775
* User will need to deselect icons to select others
@@ -774,6 +794,7 @@ public IconDialog setMaxSelection(int max, boolean showMessage) {
774794
/**
775795
* Set whether to show the neutral clear button to unselect all icons
776796
* By default, this button is not shown.
797+
*
777798
* @param show whether to show it or not
778799
* @return the dialog
779800
*/
@@ -788,6 +809,7 @@ public IconDialog setShowClearButton(boolean show) {
788809
* and will be sorted by category, then by labels and then by ID
789810
* in its value. Multiple search terms can be separated with either " ", "," or ";"
790811
* A custom icon searcher can be set by subclassing {@link IconFilter}
812+
*
791813
* @param filter icon filter
792814
* @return the dialog
793815
*/
@@ -802,6 +824,7 @@ public IconDialog setIconFilter(BaseIconFilter filter) {
802824
/**
803825
* Get the IconFilter used to search and sort icons.
804826
* You can set additionnal settings with it
827+
*
805828
* @return the icon searcher
806829
* @see IconFilter#setDisabledCategories(int...)
807830
* @see IconFilter#setDisabledIcons(int...)
@@ -814,6 +837,7 @@ public BaseIconFilter getIconFilter() {
814837
/**
815838
* Set whether all icon drawables will be preloaded when dialog is shown to allow a smoother
816839
* scrolling in the icon list. By default, drawables are preloaded.
840+
*
817841
* @param load whether to load them or not
818842
* @return the dialog
819843
* @see IconHelper#loadIconDrawables()
@@ -1053,6 +1077,7 @@ public interface Callback {
10531077
/**
10541078
* Called on the target fragment, parent fragment or parent activity when
10551079
* icons are selected and user confirms the selection.
1080+
*
10561081
* @param icons selected icons, never null.
10571082
*/
10581083
void onIconDialogIconsSelected(@NonNull Icon[] icons);

icondialog/src/main/java/com/maltaisn/icondialog/IconHelper.java

+40-29
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424

2525
import android.annotation.SuppressLint;
2626
import android.content.Context;
27-
import androidx.annotation.NonNull;
28-
import androidx.annotation.Nullable;
29-
import androidx.annotation.XmlRes;
3027
import android.util.Log;
3128
import android.util.SparseArray;
3229

@@ -39,6 +36,10 @@
3936
import java.util.Collections;
4037
import java.util.List;
4138

39+
import androidx.annotation.NonNull;
40+
import androidx.annotation.Nullable;
41+
import androidx.annotation.XmlRes;
42+
4243
@SuppressWarnings({"WeakerAccess", "unused"})
4344
public class IconHelper {
4445

@@ -55,25 +56,25 @@ public class IconHelper {
5556
private static final String XML_ATTR_PATH = "path";
5657
private static final String XML_ATTR_CATEGORY = "category";
5758

58-
public static final int CATEGORY_PEOPLE = 0;
59-
public static final int CATEGORY_HOME = 1;
59+
public static final int CATEGORY_PEOPLE = 0;
60+
public static final int CATEGORY_HOME = 1;
6061
public static final int CATEGORY_TECHNOLOGY = 2;
61-
public static final int CATEGORY_FINANCE = 3;
62-
public static final int CATEGORY_LEISURE = 4;
63-
public static final int CATEGORY_TRANSPORT = 5;
64-
public static final int CATEGORY_FOOD = 6;
65-
public static final int CATEGORY_BUILDINGS = 7;
66-
public static final int CATEGORY_ARTS = 8;
67-
public static final int CATEGORY_SPORTS = 9;
68-
public static final int CATEGORY_AUDIO = 10;
69-
public static final int CATEGORY_PHOTO = 11;
70-
public static final int CATEGORY_NATURE = 12;
71-
public static final int CATEGORY_SCIENCE = 13;
72-
public static final int CATEGORY_TIME = 14;
73-
public static final int CATEGORY_TOOLS = 15;
74-
public static final int CATEGORY_COMPUTER = 16;
75-
public static final int CATEGORY_ARROWS = 17;
76-
public static final int CATEGORY_SYMBOLS = 18;
62+
public static final int CATEGORY_FINANCE = 3;
63+
public static final int CATEGORY_LEISURE = 4;
64+
public static final int CATEGORY_TRANSPORT = 5;
65+
public static final int CATEGORY_FOOD = 6;
66+
public static final int CATEGORY_BUILDINGS = 7;
67+
public static final int CATEGORY_ARTS = 8;
68+
public static final int CATEGORY_SPORTS = 9;
69+
public static final int CATEGORY_AUDIO = 10;
70+
public static final int CATEGORY_PHOTO = 11;
71+
public static final int CATEGORY_NATURE = 12;
72+
public static final int CATEGORY_SCIENCE = 13;
73+
public static final int CATEGORY_TIME = 14;
74+
public static final int CATEGORY_TOOLS = 15;
75+
public static final int CATEGORY_COMPUTER = 16;
76+
public static final int CATEGORY_ARROWS = 17;
77+
public static final int CATEGORY_SYMBOLS = 18;
7778

7879
// Warning here is ignored see: http://stackoverflow.com/a/40235834/5288316
7980
@SuppressLint("StaticFieldLeak")
@@ -85,8 +86,10 @@ public class IconHelper {
8586
private List<Label> groupLabels;
8687
private SparseArray<Category> categories;
8788

88-
private @XmlRes int extraIconsXml;
89-
private @XmlRes int extraLabelsXml;
89+
private @XmlRes
90+
int extraIconsXml;
91+
private @XmlRes
92+
int extraLabelsXml;
9093
private boolean extraIconsSet;
9194
private boolean extraIconsLoadPending;
9295

@@ -128,6 +131,7 @@ public void onDone() {
128131

129132
/**
130133
* Get the instance of IconHelper
134+
*
131135
* @param context any context
132136
* @return the instance
133137
*/
@@ -147,6 +151,7 @@ public boolean isDataLoaded() {
147151

148152
/**
149153
* Get an icon
154+
*
150155
* @param id id of the icon
151156
* @return the icon, null if it doesn't exist or if data isn't loaded
152157
*/
@@ -162,6 +167,7 @@ SparseArray<Icon> getIcons() {
162167

163168
/**
164169
* Get a label by name
170+
*
165171
* @param name name of the label
166172
* @return the label, null if it doesn't exist or if data isn't loaded
167173
*/
@@ -187,6 +193,7 @@ public Label getLabel(String name) {
187193

188194
/**
189195
* Get a category
196+
*
190197
* @param id id of the category
191198
* @return the category or null if it doesn't exist or if data isn't loaded
192199
*/
@@ -198,7 +205,7 @@ public Category getCategory(int id) {
198205

199206
/**
200207
* @return the number of loaded icons
201-
* Returns 0 if data is not loaded
208+
* Returns 0 if data is not loaded
202209
*/
203210
public int getIconCount() {
204211
if (!dataLoaded) return 0;
@@ -209,7 +216,8 @@ public int getIconCount() {
209216
* Add extra icons for the dialog.
210217
* This can only be called once, subsequent calls will have no effect
211218
* Both XML resources must be valid, no error checking is done
212-
* @param iconXml xml file containing the icons
219+
*
220+
* @param iconXml xml file containing the icons
213221
* @param labelXml xml file containing the labels used by the icons
214222
*/
215223
public synchronized void addExtraIcons(@XmlRes int iconXml, @XmlRes int labelXml) {
@@ -435,8 +443,9 @@ private class GroupLabelRef {
435443

436444
/**
437445
* Load labels from XML
446+
*
438447
* @param xmlFile xml file to load from
439-
* @param append if true, new labels will be appended to old ones
448+
* @param append if true, new labels will be appended to old ones
440449
*/
441450
@SuppressWarnings({"ConstantConditions", "unchecked"})
442451
private void loadLabels(@XmlRes int xmlFile, boolean append) {
@@ -589,6 +598,7 @@ private static class LabelRef {
589598

590599
/**
591600
* Create new reference to a label
601+
*
592602
* @param name name of the label to be created. If null, parent mustn't be null
593603
* @param parent label to add alias to. If null, name musn't be null
594604
* @param refText reference raw text
@@ -617,6 +627,7 @@ private static class LabelRef {
617627
/**
618628
* Normalize given text, removing all diacritics, all
619629
* unicode characters, hyphens, apostrophes and more
630+
*
620631
* @param text text
621632
* @return normalized text
622633
*/
@@ -674,7 +685,7 @@ public void freeIconDrawables() {
674685
public void addLoadCallback(@NonNull LoadCallback cb) {
675686
if (dataLoaded) {
676687
// Data is already loaded: call callback without adding it
677-
cb.onDataLoaded();
688+
cb.onDataLoaded(this);
678689
return;
679690
}
680691

@@ -690,7 +701,7 @@ public void removeLoadCallback(@NonNull LoadCallback cb) {
690701
private void callLoadCallbacks() {
691702
if (loadCallbacks != null) {
692703
for (LoadCallback cb : loadCallbacks) {
693-
cb.onDataLoaded();
704+
cb.onDataLoaded(this);
694705
}
695706
loadCallbacks.clear();
696707
}
@@ -701,7 +712,7 @@ public interface LoadCallback {
701712
* Called when icon data is done loading.
702713
* All calls to get icons, labels and categories will return null before this is called.
703714
*/
704-
void onDataLoaded();
715+
void onDataLoaded(IconHelper helper);
705716
}
706717

707718
}

0 commit comments

Comments
 (0)