Skip to content

Commit

Permalink
Release v1.1.6
Browse files Browse the repository at this point in the history
- Fix layout issue for first selected item
- Check if spinner is disabled before call performClick()
- Add new attrs and method to update search text color, search hint color and search background
  • Loading branch information
Chivorns committed Aug 19, 2019
1 parent 8a8d022 commit 407ac31
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ The best Android spinner library for your android application with more customiz

```gradle
dependencies {
implementation 'com.github.chivorns:smartmaterialspinner:1.1.5'
implementation 'com.github.chivorns:smartmaterialspinner:1.1.6'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
app:smsp_multilineError="true"
app:smsp_searchHeaderBackgroundColor="@color/smsp_search_header_background"
app:smsp_searchHeaderText="Search/Select Province"
app:smsp_searchHeaderTextColor="#ffff" />
app:smsp_searchHeaderTextColor="#ffff"
app:smsp_searchHintColor="@color/search_hint_color"
app:smsp_searchTextColor="@color/search_text_color" />

<TextView
style="@style/headerTextStyle"
Expand Down
3 changes: 3 additions & 0 deletions resources/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
<color name="custom_item_list_color">#3F51B5</color>
<color name="custom_selected_item_color">#E91E63</color>
<color name="error_color">#9C27B0</color>

<color name="search_hint_color">#F00051</color>
<color name="search_text_color">#8300D6</color>
</resources>
4 changes: 2 additions & 2 deletions smartmaterialspinner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ext {
LIBRARY_NAME = 'SmartMaterialSpinner'
PUBLISH_GROUP_ID = 'com.github.chivorns'
PUBLISH_ARTIFACT_ID = LIBRARY_NAME.toLowerCase()
PUBLISH_VERSION = '1.1.5'
PUBLISH_VERSION = '1.1.6'

// Bintray
BINTRAY_REPO = 'maven'
Expand All @@ -32,7 +32,7 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 20
versionCode 21
versionName "$PUBLISH_VERSION"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@ public class SearchableSpinnerDialog extends DialogFragment implements SearchVie
private ViewGroup searchHeaderView;
private AppCompatTextView tvSearchHeader;
private SearchView searchView;
private TextView tvSearch;
private ListView searchListView;
private TextView tvListItem;

private boolean isEnableSearchHeader = true;
private int headerBackgroundColor;
private Drawable headerBackgroundDrawable;

private int searchBackgroundColor;
private Drawable searchBackgroundDrawable;
private int searchHintColor;
private int searchTextColor;

private int searchListItemColor;
private int selectedSearchItemColor;
private int selectedPosition = -1;
Expand Down Expand Up @@ -129,6 +136,7 @@ private void initSearchDialog(View rootView, Bundle savedInstanceState) {
searchHeaderView = rootView.findViewById(R.id.search_header_layout);
tvSearchHeader = rootView.findViewById(R.id.tv_search_header);
searchView = rootView.findViewById(R.id.search_view);
tvSearch = searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchListView = rootView.findViewById(R.id.search_list_item);

if (getActivity() != null) {
Expand Down Expand Up @@ -216,6 +224,21 @@ private void initSearchBody() {
if (searchHint != null) {
searchView.setQueryHint(searchHint);
}
if (searchBackgroundColor != 0) {
searchView.setBackgroundColor(searchBackgroundColor);
} else if (searchBackgroundDrawable != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
searchView.setBackground(searchBackgroundDrawable);
}
}
if (tvSearch != null) {
if (searchTextColor != 0) {
tvSearch.setTextColor(searchTextColor);
}
if (searchHintColor != 0) {
tvSearch.setHintTextColor(searchHintColor);
}
}
}

@Override
Expand Down Expand Up @@ -298,10 +321,29 @@ public void setSearchHeaderBackgroundColor(Drawable drawable) {
headerBackgroundColor = 0;
}

public void setSearchBackgroundColor(int color) {
searchBackgroundColor = color;
searchBackgroundDrawable = null;
}

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
public void setSearchBackgroundColor(Drawable drawable) {
searchBackgroundDrawable = drawable;
searchBackgroundColor = 0;
}

public void setSearchHint(String searchHint) {
this.searchHint = searchHint;
}

public void setSearchTextColor(int color) {
searchTextColor = color;
}

public void setSearchHintColor(int color) {
searchHintColor = color;
}

public void setSearchListItemColor(int searchListItemColor) {
this.searchListItemColor = searchListItemColor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public class SmartMaterialSpinner<T> extends AppCompatSpinner implements Adapter
private int itemColor;
private int itemListColor;
private int selectedItemListColor;
private int searchHintColor;
private int searchTextColor;
private float hintSize;
private CharSequence floatingLabelText;
private float floatingLabelSize;
Expand Down Expand Up @@ -271,6 +273,9 @@ private void initAttributes(Context context, AttributeSet attrs) {
setSearchHeaderBackgroundColor(typedArray.getColor(R.styleable.SmartMaterialSpinner_smsp_searchHeaderBackgroundColor, ContextCompat.getColor(context, R.color.smsp_search_header_background)));
}
searchHint = typedArray.getString(R.styleable.SmartMaterialSpinner_smsp_searchHint);
searchHintColor = typedArray.getColor(R.styleable.SmartMaterialSpinner_smsp_searchHintColor, 0);
searchTextColor = typedArray.getColor(R.styleable.SmartMaterialSpinner_smsp_searchTextColor, 0);

//isEnableDefaultSelect = typedArray.getBoolean(R.styleable.SmartMaterialSpinner_smsp_enableDefaultSelect, true);
isReSelectable = typedArray.getBoolean(R.styleable.SmartMaterialSpinner_smsp_isReSelectable, false);

Expand All @@ -292,6 +297,8 @@ private void configSearchableDialog() {
setSearchHint(searchHint);
setSearchListItemColor(itemListColor);
setSelectedSearchItemColor(selectedItemListColor);
setSearchHintColor(searchHintColor);
setSearchTextColor(searchTextColor);
}

private void removeDefaultSelector(Drawable drawable) {
Expand Down Expand Up @@ -1365,6 +1372,21 @@ public String getSearchHint() {
return searchHint;
}

public void setSearchBackgroundColor(int color) {
if (searchableSpinnerDialog != null) {
searchableSpinnerDialog.setSearchBackgroundColor(color);
}
invalidate();
}

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
public void setSearchBackgroundColor(Drawable drawable) {
if (searchableSpinnerDialog != null) {
searchableSpinnerDialog.setSearchBackgroundColor(drawable);
}
invalidate();
}

public void setSearchHint(String searchHint) {
this.searchHint = searchHint;
if (searchableSpinnerDialog != null) {
Expand All @@ -1373,6 +1395,22 @@ public void setSearchHint(String searchHint) {
invalidate();
}

public void setSearchTextColor(int color) {
this.searchTextColor = color;
if (searchableSpinnerDialog != null) {
searchableSpinnerDialog.setSearchTextColor(color);
}
invalidate();
}

public void setSearchHintColor(int color) {
this.searchHintColor = color;
if (searchableSpinnerDialog != null) {
searchableSpinnerDialog.setSearchHintColor(color);
}
invalidate();
}

public void setSearchListItemColor(int searchListItemColor) {
if (searchableSpinnerDialog != null) {
searchableSpinnerDialog.setSearchListItemColor(searchListItemColor);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
Expand All @@ -26,23 +27,23 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:paddingBottom="8dp">
android:orientation="vertical">

<android.support.v7.widget.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:iconifiedByDefault="false"
android:queryHint="Search..." />
app:iconifiedByDefault="false"
app:queryHint="Search..." />

<ListView
android:id="@+id/search_list_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:divider="@null"
android:dividerHeight="0dp" />
android:dividerHeight="0dp"
android:paddingBottom="5dp" />
</LinearLayout>
</LinearLayout>
2 changes: 2 additions & 0 deletions smartmaterialspinner/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<attr name="smsp_searchHeaderTextColor" format="color|reference" />
<attr name="smsp_searchHeaderBackgroundColor" format="color|reference" />
<attr name="smsp_searchHint" format="string" />
<attr name="smsp_searchHintColor" format="color" />
<attr name="smsp_searchTextColor" format="color" />

<attr name="smsp_itemSize" format="dimension" />
<attr name="smsp_itemColor" format="color|reference" />
Expand Down

0 comments on commit 407ac31

Please sign in to comment.