diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..19e173b --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..1593062 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 75e23a2..e72daf6 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,13 @@ then add SearchBar to your activity: app:mt_maxSuggestionsCount="10" android:layout_width="match_parent" android:layout_height="wrap_content" - android:id="@+id/searchBar" /> + android:id="@+id/searchBar" + app:mt_marquee="true" + app:mt_hintStyle="normal|bold" + app:mt_marqueeRepeatLimit="1" + app:mt_placeholder="Search" + android:fontFamily="@font/ariana" +/> ``` ---------- @@ -90,8 +96,15 @@ then add SearchBar to your activity: | mt_hintColor | set hint color | | mt_placeholderColor | set placeholder color | | mt_textCursorTint | set text cursors tint | -| mt_highlightedTextColor | set the text highlight tint color | - +| mt_highlightedTextColor | set the text highlight tint color | +| mt_highlightedTextColor | set the text highlight tint color | + +| mt_textSize | set the text size | +| mt_marquee | set marquee | +| mt_marqueeRepeatLimit | set marquee repeat rate | +| fontFamily | set custom font family | +| mt_searchStyle | set search view textStyle | +| mt_hintStyle | set placeholder textStyle | ---------- **public methods:** diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index 4021437..b989721 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -31,7 +31,12 @@ android:layout_height="wrap_content" android:layout_margin="8dp" app:mt_navIconEnabled="true" - app:mt_placeholder="Google Play" /> + app:mt_textSize="12sp" + app:mt_marquee="true" + app:mt_hintStyle="normal" + app:mt_marqueeRepeatLimit="1" + android:fontFamily="@font/ariana" + app:mt_placeholder="Search" /> 0) { + placeHolder.setTypeface(ResourcesCompat.getFont(getContext(), fontFamily)); + searchEdit.setTypeface(ResourcesCompat.getFont(getContext(), fontFamily)); + } + } + + + private void setupText(){ + setupTextColors(); + setupTextSize(); + setupEffects(); } + /** * Capsule shaped searchbar enabled * Only works on SDK V21+ due to odd behavior on lower @@ -276,12 +335,72 @@ private void setupDividerColor() { suggestionDivider.setBackgroundColor(dividerColor); } + private void setupEffects(){ + setupMarquee(); + setupPlaceHolderFontStyle(); + setupSearchViewStyle(); + } + + + + private void setupSearchViewStyle() { + + if(searchStyle==0){ + searchEdit.setTypeface(null, Typeface.NORMAL); + return; + } + if((searchStyle & PrefixStyle.BOLD) == PrefixStyle.BOLD) { + searchEdit.setTypeface(null, Typeface.BOLD); + + } + if((searchStyle & PrefixStyle.ITALIC) == PrefixStyle.ITALIC) { + searchEdit.setTypeface(null, Typeface.ITALIC); + } + if((searchStyle & PrefixStyle.NORMAL) == PrefixStyle.NORMAL) { + searchEdit.setTypeface(null, Typeface.NORMAL); + } + } + + private void setupPlaceHolderFontStyle() { + + if(hintStyle==0){ + placeHolder.setTypeface(null, Typeface.NORMAL); + return; + } + if((hintStyle & PrefixStyle.BOLD) == PrefixStyle.BOLD) { + placeHolder.setTypeface(null, Typeface.BOLD); + + } + if((hintStyle & PrefixStyle.ITALIC) == PrefixStyle.ITALIC) { + placeHolder.setTypeface(null, Typeface.ITALIC); + } + if((hintStyle & PrefixStyle.NORMAL) == PrefixStyle.NORMAL) { + placeHolder.setTypeface(null, Typeface.NORMAL); + } + } + + private void setupMarquee(){ + if(isMarquee){ + placeHolder.setHorizontallyScrolling(true); + placeHolder.setEllipsize(TextUtils.TruncateAt.MARQUEE); + placeHolder.setMarqueeRepeatLimit(marqueeRepeatLimit); + placeHolder.setSelected(true); + } + } + private void setupTextColors() { searchEdit.setHintTextColor(hintColor); searchEdit.setTextColor(textColor); placeHolder.setTextColor(placeholderColor); } + private void setupTextSize(){ + searchEdit.setTextSize(textSize); + placeHolder.setTextSize(textSize); + } + + + /** * Setup editText coloring and drawables */ diff --git a/library/src/main/java/com/mancj/materialsearchbar/adapter/DefaultSuggestionsAdapter.java b/library/src/main/java/com/mancj/materialsearchbar/adapter/DefaultSuggestionsAdapter.java index c766aef..c63dca8 100644 --- a/library/src/main/java/com/mancj/materialsearchbar/adapter/DefaultSuggestionsAdapter.java +++ b/library/src/main/java/com/mancj/materialsearchbar/adapter/DefaultSuggestionsAdapter.java @@ -1,11 +1,13 @@ package com.mancj.materialsearchbar.adapter; +import android.graphics.Typeface; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import androidx.core.content.res.ResourcesCompat; import androidx.recyclerview.widget.RecyclerView; import com.mancj.materialsearchbar.R; @@ -16,9 +18,18 @@ public class DefaultSuggestionsAdapter extends SuggestionsAdapter { private SuggestionsAdapter.OnItemViewClickListener listener; + int fontFamily = 0; - public DefaultSuggestionsAdapter(LayoutInflater inflater) { + public DefaultSuggestionsAdapter(LayoutInflater inflater, int fontFamily) { super(inflater); + this.fontFamily=fontFamily; + } + + + private void setFontFamily(TextView view) { + if (fontFamily > 0) { + view.setTypeface(ResourcesCompat.getFont(view.getContext(), fontFamily)); + } } public void setListener(SuggestionsAdapter.OnItemViewClickListener listener) { @@ -39,6 +50,7 @@ public DefaultSuggestionsAdapter.SuggestionHolder onCreateViewHolder(ViewGroup p @Override public void onBindSuggestionHolder(String suggestion, SuggestionHolder holder, int position) { holder.text.setText(getSuggestions().get(position)); + setFontFamily(holder.text); } public interface OnItemViewClickListener { diff --git a/library/src/main/java/com/mancj/materialsearchbar/util/PrefixStyle.java b/library/src/main/java/com/mancj/materialsearchbar/util/PrefixStyle.java new file mode 100644 index 0000000..b0a55e1 --- /dev/null +++ b/library/src/main/java/com/mancj/materialsearchbar/util/PrefixStyle.java @@ -0,0 +1,7 @@ +package com.mancj.materialsearchbar.util; + +public class PrefixStyle { + public static final int BOLD = 1; + public static final int ITALIC = 2; + public static final int NORMAL = 4; +} diff --git a/library/src/main/res/font/ariana.ttf b/library/src/main/res/font/ariana.ttf new file mode 100644 index 0000000..6bc7c9b Binary files /dev/null and b/library/src/main/res/font/ariana.ttf differ diff --git a/library/src/main/res/layout/searchbar.xml b/library/src/main/res/layout/searchbar.xml index ede0c66..765ead4 100644 --- a/library/src/main/res/layout/searchbar.xml +++ b/library/src/main/res/layout/searchbar.xml @@ -36,24 +36,25 @@ + tools:text="PlaceHolder" + /> //Text + + + + + + + + + + + + + + + + + + + + + + + diff --git a/library/src/main/res/values/styles.xml b/library/src/main/res/values/styles.xml index 8a57e50..6d1908e 100644 --- a/library/src/main/res/values/styles.xml +++ b/library/src/main/res/values/styles.xml @@ -22,6 +22,7 @@ @color/searchBarHintColor @color/searchBarPlaceholderColor @color/searchBarTextHighlightColor +