Skip to content

Commit fc0743a

Browse files
committed
Release v1.1.2
- Fix set re-selectable not work on some device - Fix dropdown width problem when visibility changed
1 parent 9740c01 commit fc0743a

File tree

7 files changed

+75
-14
lines changed

7 files changed

+75
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ The best Android spinner library for your android application with more customiz
113113

114114
```gradle
115115
dependencies {
116-
implementation 'com.github.chivorns:smartmaterialspinner:1.1.1'
116+
implementation 'com.github.chivorns:smartmaterialspinner:1.1.2'
117117
}
118118
```
119119

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected void onCreate(Bundle savedInstanceState) {
2626

2727
private void initSpinnerInJava() {
2828
spSearchable.setItem(provinceList);
29+
spReSelectable.setItem(provinceList);
2930
spProvince.setItem(provinceList);
3031
spProvinceNoHint.setItem(provinceList);
3132
spProvinceDialog.setItem(provinceList);
@@ -39,8 +40,8 @@ private void initSpinnerInJava() {
3940
spCustomColor.setItemListColor(ContextCompat.getColor(this, R.color.custom_item_list_color));
4041

4142
setOnEmptySpinnerClickListener(spEmptyItem);
42-
setOnItemSelectedListener(spSearchable, spProvince, spProvinceNoHint, spProvinceDialog, spCustomColor, spEmptyItem);
43-
setOnSpinnerEventListener(spSearchable, spProvince, spProvinceNoHint, spProvinceDialog, spCustomColor, spEmptyItem);
43+
setOnItemSelectedListener(spSearchable, spReSelectable, spProvince, spProvinceNoHint, spProvinceDialog, spCustomColor, spEmptyItem, spVisibilityChanged);
44+
setOnSpinnerEventListener(spSearchable, spReSelectable, spProvince, spProvinceNoHint, spProvinceDialog, spCustomColor, spEmptyItem);
4445
// setItemTextSize(90, spSearchable, spProvince, spProvinceNoHint, spProvinceDialog, spCustomColor, spEmptyItem);
4546
// setErrorTextSize(90, spSearchable, spProvince, spProvinceNoHint, spProvinceDialog, spCustomColor, spEmptyItem);
4647
// setSelection(3, spSearchable, spProvince, spProvinceNoHint, spProvinceDialog, spCustomColor);
@@ -54,6 +55,8 @@ private void setOnItemSelectedListener(SmartMaterialSpinner... spinners) {
5455
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
5556
if (spinner.getId() == R.id.sp_searchable) {
5657
spinner.setErrorText("Your selected item is \"" + spinner.getItem().get(position) + "\" .");
58+
} else if (spinner.getId() == R.id.sp_reselectable || spinner.getId() == R.id.sp_visibility_changed) {
59+
Toast.makeText(MainActivity.this, "Selected item is: " + spinner.getSelectedItem(), Toast.LENGTH_SHORT).show();
5760
} else {
5861
spinner.setErrorText("You are selecting on spinner item -> \"" + spinner.getItem().get(position) + "\" . You can show it both in XML and programmatically and you can display as single line or multiple lines");
5962
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,38 @@ public class MainApp<T> extends AppCompatActivity implements View.OnClickListene
1717
private final String repoUrl = "https://github.com/Chivorns/SmartMaterialSpinner";
1818

1919
protected SmartMaterialSpinner<String> spSearchable;
20+
protected SmartMaterialSpinner<String> spReSelectable;
2021
protected SmartMaterialSpinner<String> spProvince;
2122
protected SmartMaterialSpinner<String> spProvinceNoHint;
2223
protected SmartMaterialSpinner<String> spProvinceDialog;
2324
protected SmartMaterialSpinner<String> spCustomColor;
2425
protected SmartMaterialSpinner<String> spEmptyItem;
26+
protected SmartMaterialSpinner<String> spVisibilityChanged;
2527

2628
private LinearLayout githubRepo;
2729
private Button btnShowError;
2830
private Button btnGotoRuntimeRender;
2931
private Button githubRepoBtn;
32+
private Button visibilityBtn;
3033
protected Intent intent;
3134

3235
protected List<String> provinceList;
3336
protected List<String> countryList;
3437

3538
public void initBaseView() {
3639
spSearchable = findViewById(R.id.sp_searchable);
40+
spReSelectable = findViewById(R.id.sp_reselectable);
3741
spProvince = findViewById(R.id.sp_provinces);
3842
spProvinceNoHint = findViewById(R.id.sp_provinces_no_hint);
3943
spProvinceDialog = findViewById(R.id.sp_provinces_dialog);
4044
spCustomColor = findViewById(R.id.sp_custom_color);
4145
spEmptyItem = findViewById(R.id.sp_empty_item);
46+
spVisibilityChanged = findViewById(R.id.sp_visibility_changed);
4247
githubRepo = findViewById(R.id.git_repo_container);
4348
btnShowError = findViewById(R.id.btn_show_error);
4449
btnGotoRuntimeRender = findViewById(R.id.btn_goto_runtime_render);
4550
githubRepoBtn = findViewById(R.id.github_repo_btn);
51+
visibilityBtn = findViewById(R.id.btn_visibility);
4652
}
4753

4854
public void initItemList() {
@@ -98,6 +104,9 @@ public void onClickListener() {
98104
if (btnGotoRuntimeRender != null) {
99105
btnGotoRuntimeRender.setOnClickListener(this);
100106
}
107+
if (visibilityBtn != null) {
108+
visibilityBtn.setOnClickListener(this);
109+
}
101110
}
102111

103112
@Override
@@ -112,6 +121,15 @@ public void onClick(View v) {
112121
spProvinceNoHint.setErrorText(getResources().getString(R.string.sample_error_message));
113122
spProvinceDialog.setErrorText(getResources().getString(R.string.sample_error_message));
114123
spCustomColor.setErrorText(getResources().getString(R.string.sample_error_message));
124+
} else if (v.getId() == R.id.btn_visibility) {
125+
if (spVisibilityChanged.getVisibility() == View.VISIBLE) {
126+
spVisibilityChanged.setVisibility(View.GONE);
127+
visibilityBtn.setText(getResources().getString(R.string.show_spinner));
128+
} else {
129+
spVisibilityChanged.setVisibility(View.VISIBLE);
130+
visibilityBtn.setText(getResources().getString(R.string.hide_spinner));
131+
spVisibilityChanged.setItem(provinceList);
132+
}
115133
}
116134
}
117135
}

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626
app:smsp_searchHeaderText="Search/Select Province"
2727
app:smsp_searchHeaderTextColor="#ffff" />
2828

29+
<TextView
30+
style="@style/headerTextStyle"
31+
android:text="Re-Selectable Spinner" />
32+
33+
<com.chivorn.smartmaterialspinner.SmartMaterialSpinner
34+
android:id="@+id/sp_reselectable"
35+
style="@style/spinnerStyle"
36+
app:smsp_errorText="@string/sample_error_message"
37+
app:smsp_hint="Re-Selectable Spinner"
38+
app:smsp_isReSelectable="true" />
39+
2940
<TextView
3041
style="@style/headerTextStyle"
3142
android:text="@string/dropdown_spinner" />
@@ -35,7 +46,6 @@
3546
style="@style/spinnerStyle"
3647
app:smsp_errorText="@string/sample_error_message"
3748
app:smsp_hint="Province (Dropdown Mode)"
38-
app:smsp_isReSelectable="true"
3949
app:smsp_multilineError="false" />
4050

4151
<com.chivorn.smartmaterialspinner.SmartMaterialSpinner
@@ -84,6 +94,17 @@
8494
app:smsp_floatingLabelText="floating text"
8595
app:smsp_hint="Empty Item Spinner" />
8696

97+
<TextView
98+
style="@style/headerTextStyle"
99+
android:text="@string/test_visibility_changed" />
100+
101+
<com.chivorn.smartmaterialspinner.SmartMaterialSpinner
102+
android:id="@+id/sp_visibility_changed"
103+
style="@style/spinnerStyle"
104+
android:visibility="gone"
105+
app:smsp_hint="Test Visibility Changed and Re-Selectable"
106+
app:smsp_isReSelectable="true" />
107+
87108
<Button
88109
android:id="@+id/btn_show_error"
89110
android:layout_width="wrap_content"
@@ -98,6 +119,20 @@
98119
android:textAllCaps="false"
99120
android:textColor="@color/smsp_white_color" />
100121

122+
<Button
123+
android:id="@+id/btn_visibility"
124+
android:layout_width="wrap_content"
125+
android:layout_height="40dp"
126+
android:layout_gravity="center"
127+
android:layout_marginTop="10dp"
128+
android:layout_marginEnd="5dp"
129+
android:layout_marginRight="5dp"
130+
android:background="#6194EB"
131+
android:padding="10dp"
132+
android:text="@string/show_spinner"
133+
android:textAllCaps="false"
134+
android:textColor="@color/smsp_white_color" />
135+
101136
<Button
102137
android:id="@+id/btn_goto_runtime_render"
103138
android:layout_width="wrap_content"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
<string name="custom_color">Custom Color</string>
1313
<string name="clickable_spinner">Clickable Spinner</string>
1414
<string name="goto_runtime_render">Goto Runtime Render</string>
15+
<string name="test_visibility_changed">Test Visibility Changed</string>
16+
<string name="show_spinner">Show Spinner</string>
17+
<string name="hide_spinner">Hide Spinner</string>
1518
</resources>

smartmaterialspinner/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ext {
55
LIBRARY_NAME = 'SmartMaterialSpinner'
66
PUBLISH_GROUP_ID = 'com.github.chivorns'
77
PUBLISH_ARTIFACT_ID = LIBRARY_NAME.toLowerCase()
8-
PUBLISH_VERSION = '1.1.1'
8+
PUBLISH_VERSION = '1.1.2'
99

1010
// Bintray
1111
BINTRAY_REPO = 'maven'
@@ -32,7 +32,7 @@ android {
3232
defaultConfig {
3333
minSdkVersion 14
3434
targetSdkVersion 28
35-
versionCode 16
35+
versionCode 17
3636
versionName "$PUBLISH_VERSION"
3737

3838
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public void onGlobalLayout() {
310310
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
311311
SmartMaterialSpinner.this.getViewTreeObserver().removeOnGlobalLayoutListener(this);
312312
}
313-
if (getWidth() != 0 && getHeight() != 0 && getDropDownWidth() != 0) {
313+
if (getWidth() != 0 && getHeight() != 0) {
314314
SmartMaterialSpinner.this.setDropDownWidth(getWidth());
315315
SmartMaterialSpinner.this.setDropDownVerticalOffset(getHeight());
316316
}
@@ -791,14 +791,12 @@ public void setSelection(int position) {
791791
if (isShowing && !isSearchable && hint != null) {
792792
position -= 1;
793793
}
794-
if (isReSelectable) {
795-
ignoreOldSelectionByReflection();
796-
}
797794
final int finalPosition = position;
798795
this.post(new Runnable() {
799796
@Override
800797
public void run() {
801798
SmartMaterialSpinner.super.setSelection(hint != null ? finalPosition + 1 : finalPosition);
799+
checkReSelectable(finalPosition);
802800
}
803801
});
804802
}
@@ -808,11 +806,9 @@ public void setSelection(int position, boolean animate) {
808806
if (isShowing && !isSearchable && hint != null) {
809807
position -= 1;
810808
}
811-
if (isReSelectable) {
812-
ignoreOldSelectionByReflection();
813-
}
814809
final int finalPosition = position;
815810
super.setSelection(hint != null ? finalPosition + 1 : finalPosition, animate);
811+
checkReSelectable(finalPosition);
816812
}
817813

818814
public void clearSelection() {
@@ -824,7 +820,7 @@ public void setSelected(boolean selected) {
824820
isSelected = selected;
825821
}
826822

827-
private boolean ignoreOldSelectionByReflection() {
823+
private boolean clearOldSelectedPosition() {
828824
try {
829825
Class<?> c = this.getClass().getSuperclass().getSuperclass().getSuperclass().getSuperclass();
830826
Field reqField = c.getDeclaredField("mOldSelectedPosition");
@@ -836,6 +832,12 @@ private boolean ignoreOldSelectionByReflection() {
836832
return false;
837833
}
838834

835+
private void checkReSelectable(int position) {
836+
if (position == getSelectedItemPosition() && lastPosition != -1 && isReSelectable && onItemSelectedListener != null) {
837+
onItemSelectedListener.onItemSelected(this, getSelectedView(), position, getSelectedItemId());
838+
}
839+
}
840+
839841
@Override
840842
public void onAnimationUpdate(ValueAnimator animation) {
841843
invalidate();

0 commit comments

Comments
 (0)