Skip to content

Commit 23ece08

Browse files
committed
Merge remote-tracking branch 'origin/master' into AndroidX
2 parents 0be0764 + 8ae99f7 commit 23ece08

File tree

8 files changed

+48
-2
lines changed

8 files changed

+48
-2
lines changed

demojava/src/main/java/com/chivorn/demojava/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ private void initSpinnerInJava() {
3434
spProvinceNoHint.setItem(provinceList);
3535
spProvinceDialog.setItem(provinceList);
3636
spCustomColor.setItem(provinceList);
37+
spCustomView.setItem(provinceList);
3738

3839
spSearchable.setSearchDialogGravity(Gravity.TOP);
3940
spSearchable.setErrorTextAlignment(SmartMaterialSpinner.TextAlignment.ALIGN_LEFT);

resources/src/main/java/com/chivorn/resourcemodule/MainApp.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class MainApp<T> extends AppCompatActivity implements View.OnClickListene
2424
protected SmartMaterialSpinner<String> spProvinceDialog;
2525
protected SmartMaterialSpinner<String> spCustomColor;
2626
protected SmartMaterialSpinner<String> spEmptyItem;
27+
protected SmartMaterialSpinner<String> spCustomView;
2728
protected SmartMaterialSpinner<String> spVisibilityChanged;
2829

2930
private LinearLayout githubRepo;
@@ -44,6 +45,7 @@ public void initBaseView() {
4445
spProvinceDialog = findViewById(R.id.sp_provinces_dialog);
4546
spCustomColor = findViewById(R.id.sp_custom_color);
4647
spEmptyItem = findViewById(R.id.sp_empty_item);
48+
spCustomView = findViewById(R.id.sp_custom_search_item_layout);
4749
spVisibilityChanged = findViewById(R.id.sp_visibility_changed);
4850
githubRepo = findViewById(R.id.git_repo_container);
4951
btnShowError = findViewById(R.id.btn_show_error);
@@ -67,6 +69,7 @@ public void initItemList() {
6769
provinceList.add("Kep");
6870
provinceList.add("Koh Kong");
6971
provinceList.add("Kratie");
72+
provinceList.add("Some very very very very very very very very very very very very big province");
7073
provinceList.add("Mondulkiri");
7174
provinceList.add("Oddar Meanchey");
7275
provinceList.add("Pailin");
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="wrap_content"
5+
android:ellipsize="none"
6+
android:padding="20dp"
7+
android:singleLine="false" />

resources/src/main/res/layout/smart_material_spinner_sample_layout.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@
9999
app:smsp_floatingLabelText="floating text"
100100
app:smsp_hint="Empty Item Spinner" />
101101

102+
<TextView
103+
style="@style/headerTextStyle"
104+
android:text="@string/custom_search_item_layout" />
105+
106+
<com.chivorn.smartmaterialspinner.SmartMaterialSpinner
107+
android:id="@+id/sp_custom_search_item_layout"
108+
style="@style/spinnerStyle"
109+
app:smsp_isSearchable="true"
110+
app:smsp_searchDropdownView="@layout/search_list_item_custom_layout"
111+
app:smsp_alwaysShowFloatingLabel="false"
112+
app:smsp_floatingLabelText="floating text"
113+
app:smsp_hint="Custom search item layout" />
114+
102115
<TextView
103116
style="@style/headerTextStyle"
104117
android:text="@string/test_visibility_changed" />

resources/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<string name="dialog_spinner">Dialog Spinner</string>
1212
<string name="custom_color">Custom Color</string>
1313
<string name="clickable_spinner">Clickable Spinner</string>
14+
<string name="custom_search_item_layout">Custom search item layout</string>
1415
<string name="goto_runtime_render">Goto Runtime Render</string>
1516
<string name="test_visibility_changed">Test Visibility Changed</string>
1617
<string name="show_spinner">Show Spinner</string>

smartmaterialspinner/src/main/java/com/chivorn/smartmaterialspinner/SearchableSpinnerDialog.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class SearchableSpinnerDialog extends DialogFragment implements SearchVie
5151
private int headerBackgroundColor;
5252
private Drawable headerBackgroundDrawable;
5353

54+
private int searchDropdownView;
5455
private int searchBackgroundColor;
5556
private Drawable searchBackgroundDrawable;
5657
private int searchHintColor;
@@ -170,12 +171,12 @@ private void initSearchDialog(View rootView, Bundle savedInstanceState) {
170171
searchView.requestFocusFromTouch();
171172
List items = savedInstanceState != null ? (List) savedInstanceState.getSerializable(INSTANCE_LIST_ITEMS) : null;
172173
if (items != null) {
173-
searchArrayAdapter = new ArrayAdapter<Object>(getActivity(), R.layout.smart_material_spinner_search_list_item_layout, items) {
174+
searchArrayAdapter = new ArrayAdapter<Object>(getActivity(), searchDropdownView, items) {
174175
@NonNull
175176
@Override
176177
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
177178
View listView = super.getView(position, convertView, parent);
178-
tvListItem = listView.findViewById(R.id.tv_search_list_item);
179+
tvListItem = (TextView)listView;
179180
tvListItem.setTypeface(typeface);
180181
if (searchListItemBackgroundColor != 0) {
181182
itemListContainer.setBackgroundColor(searchListItemBackgroundColor);
@@ -368,6 +369,14 @@ public void setSearchHeaderBackgroundColor(Drawable drawable) {
368369
headerBackgroundColor = 0;
369370
}
370371

372+
public int getSearchDropdownView() {
373+
return searchDropdownView;
374+
}
375+
376+
public void setSearchDropdownView(int searchDropdownView) {
377+
this.searchDropdownView = searchDropdownView;
378+
}
379+
371380
public void setSearchBackgroundColor(int color) {
372381
searchBackgroundColor = color;
373382
searchBackgroundDrawable = null;

smartmaterialspinner/src/main/java/com/chivorn/smartmaterialspinner/SmartMaterialSpinner.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public class SmartMaterialSpinner<T> extends AppCompatSpinner implements Adapter
152152
private int searchTextColor;
153153
private int searchBackgroundColor;
154154
private Drawable searchBackgroundDrawable;
155+
private int searchDropdownView;
155156
private float hintSize;
156157
private CharSequence floatingLabelText;
157158
private float floatingLabelSize;
@@ -303,6 +304,8 @@ private void initAttributes(Context context, AttributeSet attrs) {
303304
setSearchBackgroundColor(typedArray.getColor(R.styleable.SmartMaterialSpinner_smsp_searchBackgroundColor, ContextCompat.getColor(context, R.color.smsp_search_background)));
304305
}
305306

307+
searchDropdownView = typedArray.getResourceId(R.styleable.SmartMaterialSpinner_smsp_searchDropdownView, R.layout.smart_material_spinner_search_list_item_layout);
308+
306309
//isEnableDefaultSelect = typedArray.getBoolean(R.styleable.SmartMaterialSpinner_smsp_enableDefaultSelect, true);
307310
isReSelectable = typedArray.getBoolean(R.styleable.SmartMaterialSpinner_smsp_isReSelectable, false);
308311

@@ -330,6 +333,7 @@ private void configSearchableDialog() {
330333
setSelectedSearchItemColor(selectedItemListColor);
331334
setSearchHintColor(searchHintColor);
332335
setSearchTextColor(searchTextColor);
336+
setSearchDropdownView(searchDropdownView);
333337
setSearchTypeFace(typeface);
334338
setSearchListItemBackgroundColor(itemListBackground);
335339
if (searchBackgroundColor != 0)
@@ -1433,6 +1437,13 @@ public String getSearchHint() {
14331437
return searchHint;
14341438
}
14351439

1440+
public void setSearchDropdownView(int viewId) {
1441+
if (searchableSpinnerDialog != null) {
1442+
searchableSpinnerDialog.setSearchDropdownView(viewId);
1443+
}
1444+
invalidate();
1445+
}
1446+
14361447
public void setSearchBackgroundColor(int color) {
14371448
if (searchableSpinnerDialog != null) {
14381449
searchableSpinnerDialog.setSearchBackgroundColor(color);

smartmaterialspinner/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
<attr name="smsp_itemView" format="reference" />
1010
<attr name="smsp_dropdownView" format="reference" />
11+
<attr name="smsp_searchDropdownView" format="reference" />
1112

1213
<attr name="smsp_isSearchable" format="boolean" />
1314
<attr name="smsp_enableSearchHeader" format="boolean" />

0 commit comments

Comments
 (0)