-
-
-
-
-
+#### 效果演示
+
-----------
+#### 安装教程
-# See our [Wiki](https://github.com/mancj/MaterialSearchBar/wiki)
+1.下载library的har包library.har(位于:Returns a filter that can be used to constrain data with a filtering - * pattern.
- *- *
This method is usually implemented by {@link androidx.recyclerview.widget.RecyclerView.Adapter} - * classes.
- * - * @return a filter used to constrain data - */ - @Override - public Filter getFilter() { - return new Filter() { - @Override - protected FilterResults performFiltering(CharSequence constraint) { - FilterResults results = new FilterResults(); - String term = constraint.toString(); - if(term.isEmpty()) - suggestions = suggestions_clone; - else { - suggestions = new ArrayList<>(); - for (Product item: suggestions_clone) - if(item.getTitle().toLowerCase().contains(term.toLowerCase())) - suggestions.add(item); - } - results.values = suggestions; - return results; - } - - @Override - protected void publishResults(CharSequence constraint, FilterResults results) { - suggestions = (ArrayListList< String > will be returned if You don't use custom adapter.
- * - * @return array with the latest search queries - * @see #setLastSuggestions(List) - * @see #setMaxSuggestionCount(int) - */ - public List getLastSuggestions() { - return adapter.getSuggestions(); - } - - /** - * Sets the array of recent search queries. - * It is advisable to save the queries when the activity is destroyed - * and call this method when creating the activity. - *Pass a List< String > if You don't use custom adapter.
- * - * @param suggestions an array of queries - * @see #getLastSuggestions() - * @see #setMaxSuggestionCount(int) - */ - public void setLastSuggestions(List suggestions) { - adapter.setSuggestions(suggestions); - } - - /** - * Changes the array of recent search queries with animation. - *Pass a List< String > if You don't use custom adapter.
- * - * @param suggestions an array of queries - */ - public void updateLastSuggestions(List suggestions) { - int startHeight = getListHeight(false); - if (suggestions.size() > 0) { - List newSuggestions = new ArrayList<>(suggestions); - adapter.setSuggestions(newSuggestions); - animateSuggestions(startHeight, getListHeight(false)); - } else { - animateSuggestions(startHeight, 0); - } - } - - /** - * Allows you to intercept the suggestions click event - *This method will not work with custom Suggestion Adapter
- * - * @param listener click listener - */ - public void setSuggestionsClickListener(SuggestionsAdapter.OnItemViewClickListener listener) { - if (adapter instanceof DefaultSuggestionsAdapter) - ((DefaultSuggestionsAdapter) adapter).setListener(listener); - } - - /** - * Set search input text color - * - * @param textColor text color - */ - public void setTextColor(int textColor) { - this.textColor = textColor; - setupTextColors(); - } - - /** - * Set text input hintText color - * - * @param hintColor text hintText color - */ - public void setTextHintColor(int hintColor) { - this.hintColor = hintColor; - setupTextColors(); - } - - /** - * Set placeholder text color - * - * @param placeholderColor placeholder color - */ - public void setPlaceHolderColor(int placeholderColor) { - this.placeholderColor = placeholderColor; - setupTextColors(); - } - - /** - * Set the color of the highlight when text is selected - * - * @param highlightedTextColor selected text highlight color - */ - public void setTextHighlightColor(int highlightedTextColor) { - this.highlightedTextColor = highlightedTextColor; - searchEdit.setHighlightColor(highlightedTextColor); - } - - public void setDividerColor(int dividerColor) { - this.dividerColor = dividerColor; - setupDividerColor(); - } - - /** - * Set navigation drawer menu icon enabled - * - * @param navButtonEnabled icon enabled - */ - public void setNavButtonEnabled(boolean navButtonEnabled) { - this.navButtonEnabled = navButtonEnabled; - if (navButtonEnabled) { - navIcon.setVisibility(VISIBLE); - navIcon.setClickable(true); - arrowIcon.setVisibility(GONE); - } else { - navIcon.setVisibility(GONE); - navIcon.setClickable(false); - arrowIcon.setVisibility(VISIBLE); - } - navIcon.requestLayout(); - placeHolder.requestLayout(); - arrowIcon.requestLayout(); - } - - /** - * Enable capsule shaped SearchBar (API 21+) - * - * @param roundedSearchBarEnabled capsule shape enabled - * @ - */ - public void setRoundedSearchBarEnabled(boolean roundedSearchBarEnabled) { - this.roundedSearchBarEnabled = roundedSearchBarEnabled; - setupRoundedSearchBarEnabled(); - } - - /** - * Set CardView elevation - * - * @param elevation desired elevation - */ - public void setCardViewElevation(int elevation) { - CardView cardView = findViewById(R.id.mt_container); - cardView.setCardElevation(elevation); - } - - /** - * Get search text - * - * @return text - */ - public String getText() { - return searchEdit.getText().toString(); - } - - /** - * Set search text - * - * @param text text - */ - public void setText(String text) { - searchEdit.setText(text); - } - - /** - * Add text watcher to searchbar's EditText - * - * @param textWatcher textWatcher to add - */ - public void addTextChangeListener(TextWatcher textWatcher) { - searchEdit.addTextChangedListener(textWatcher); - } - - public EditText getSearchEditText() { - return searchEdit; - } - - public TextView getPlaceHolderView() { - return placeHolder; - } - - /** - * Set the place holder text - * - * @param placeholder placeholder text - */ - public void setPlaceHolder(CharSequence placeholder) { - this.placeholderText = placeholder; - placeHolder.setText(placeholder); - } - - private boolean listenerExists() { - return onSearchActionListener != null; - } - - @Override - public void onClick(View v) { - int id = v.getId(); - if (id == getId()) { - if (!searchOpened) { - openSearch(); - } - } else if (id == R.id.mt_arrow) { - closeSearch(); - } else if (id == R.id.mt_search) { - if (listenerExists()) - onSearchActionListener.onButtonClicked(BUTTON_SPEECH); - } else if (id == R.id.mt_clear) { - searchEdit.setText(""); - } else if (id == R.id.mt_menu) { - popupMenu.show(); - } else if (id == R.id.mt_nav) { - int button = searchOpened ? BUTTON_BACK : BUTTON_NAVIGATION; - if (searchOpened) { - closeSearch(); - } - if (listenerExists()) { - onSearchActionListener.onButtonClicked(button); - } - } - } - - @Override - public void onAnimationStart(Animation animation) { - } - - @Override - public void onAnimationEnd(Animation animation) { - if (!searchOpened) { - inputContainer.setVisibility(GONE); - searchEdit.setText(""); - } else { - searchIcon.setVisibility(GONE); - searchEdit.requestFocus(); - if (!suggestionsVisible && isSuggestionsEnabled) - showSuggestionsList(); - } - } - - @Override - public void onAnimationRepeat(Animation animation) { - - } - - @Override - public void onFocusChange(View v, boolean hasFocus) { - InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - if (hasFocus) { - imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT); - } else { - imm.hideSoftInputFromWindow(v.getWindowToken(), 0); - } - } - - @Override - public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { - if (listenerExists()) - onSearchActionListener.onSearchConfirmed(searchEdit.getText()); - if (suggestionsVisible) - hideSuggestionsList(); - if (adapter instanceof DefaultSuggestionsAdapter) - adapter.addSuggestion(searchEdit.getText().toString()); - return true; - } - - /** - * For calculate the height change when item delete or add animation - * false is return the full height of item, - * true is return the height of position subtraction one - * - * @param isSubtraction is subtraction enabled - */ - private int getListHeight(boolean isSubtraction) { - if (!isSubtraction) - return (int) (adapter.getListHeight() * destiny); - return (int) (((adapter.getItemCount() - 1) * adapter.getSingleViewHeight()) * destiny); - } - - @Override - public void OnItemClickListener(int position, View v) { - if (v.getTag() instanceof String) { - searchEdit.setText((String) v.getTag()); - } - } - - @Override - public void OnItemDeleteListener(int position, View v) { - if (v.getTag() instanceof String) { - /*Order of two line should't be change, - because should calculate the height of item first*/ - animateSuggestions(getListHeight(false), getListHeight(true)); - adapter.deleteSuggestion(position, v.getTag()); - } - } - - @Override - protected Parcelable onSaveInstanceState() { - SavedState savedState = new SavedState(super.onSaveInstanceState()); - savedState.isSearchBarVisible = searchOpened ? VIEW_VISIBLE : VIEW_INVISIBLE; - savedState.suggestionsVisible = suggestionsVisible ? VIEW_VISIBLE : VIEW_INVISIBLE; - savedState.speechMode = speechMode ? VIEW_VISIBLE : VIEW_INVISIBLE; - savedState.navIconResId = navIconResId; - savedState.searchIconRes = searchIconRes; - savedState.suggestions = getLastSuggestions(); - savedState.maxSuggestions = maxSuggestionCount; - if (hintText != null) savedState.hint = hintText.toString(); - return savedState; - } - - @Override - protected void onRestoreInstanceState(Parcelable state) { - SavedState savedState = (SavedState) state; - super.onRestoreInstanceState(savedState.getSuperState()); - searchOpened = savedState.isSearchBarVisible == VIEW_VISIBLE; - suggestionsVisible = savedState.suggestionsVisible == VIEW_VISIBLE; - setLastSuggestions(savedState.suggestions); - if (suggestionsVisible) - animateSuggestions(0, getListHeight(false)); - if (searchOpened) { - inputContainer.setVisibility(VISIBLE); - placeHolder.setVisibility(GONE); - searchIcon.setVisibility(GONE); - } - } - - @Override - public boolean dispatchKeyEvent(KeyEvent event) { - if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && searchOpened) { - animateSuggestions(getListHeight(false), 0); - closeSearch(); - return true; - } - return super.dispatchKeyEvent(event); - } - - /** - * Interface definition for MaterialSearchBar callbacks. - */ - public interface OnSearchActionListener { - /** - * Invoked when SearchBar opened or closed - * - * @param enabled state - */ - void onSearchStateChanged(boolean enabled); - - /** - * Invoked when search confirmed and "search" button is clicked on the soft keyboard - * - * @param text search input - */ - void onSearchConfirmed(CharSequence text); - - /** - * Invoked when "speech" or "navigation" buttons clicked. - * - * @param buttonCode {@link #BUTTON_NAVIGATION}, {@link #BUTTON_SPEECH} or {@link #BUTTON_BACK} will be passed - */ - void onButtonClicked(int buttonCode); - } - - private static class SavedState extends BaseSavedState { - public static final CreatorReturns a filter that can be used to constrain data with a filtering - * pattern.
- *- *
This method is usually implemented by {@link Adapter} - * classes.
- * - * @return a filter used to constrain data - */ - @Override - public Filter getFilter() { - return null; - } - - public interface OnItemViewClickListener{ - void OnItemClickListener(int position,View v); - void OnItemDeleteListener(int position,View v); - } - -} diff --git a/library/src/main/java/com/mancj/materialsearchbar/bean/HistoryBean.java b/library/src/main/java/com/mancj/materialsearchbar/bean/HistoryBean.java new file mode 100644 index 0000000000000000000000000000000000000000..fc4e6648a768569c33aa60fdab7968f742cbf185 --- /dev/null +++ b/library/src/main/java/com/mancj/materialsearchbar/bean/HistoryBean.java @@ -0,0 +1,16 @@ +package com.mancj.materialsearchbar.bean; + +public class HistoryBean { + + private String name; + public HistoryBean(String name) { + this.name = name; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + +} diff --git a/library/src/main/res/anim/fade_in_left.xml b/library/src/main/res/anim/fade_in_left.xml deleted file mode 100644 index 05c455caf6bbc66ed27638072b70d029d25667ee..0000000000000000000000000000000000000000 --- a/library/src/main/res/anim/fade_in_left.xml +++ /dev/null @@ -1,6 +0,0 @@ - -