android-searchbox
v0.0.1
A multi-purpose search widget which works both with offline and online databases(Appbase or ElasticSearch cluster). The search widget contains multiple functionalities like Voice Search, Smart Search, Analytics, etc.
|
Classes | |
interface | ItemClickListener |
interface | OnSearchActionListener |
interface | TextChangeListener |
Public Member Functions | |
SearchBar (Context context, AttributeSet attributeSet) | |
SearchBar (Context context, AttributeSet attributeSet, int defStyleAttr) | |
SearchBar (Context context, AttributeSet attributeSet, int defStyleAttr, int defStyleRes) | |
void | inflateMenu (int menuResource) |
void | inflateMenu (int menuResource, int icon) |
PopupMenu | getMenu () |
void | setOnSearchActionListener (OnSearchActionListener onSearchActionListener) |
void | disableSearch () |
void | enableSearch () |
void | showSuggestionsList () |
void | hideSuggestionsList () |
void | clearSuggestions () |
boolean | areSuggestionsVisible () |
boolean | areSuggestionsEnabled () |
void | setSuggestionsEnabled (boolean suggestionsEnabled) |
void | setMenuIcon (int menuIconResId) |
void | setSearchIcon (int searchIconResId) |
void | setSearchIconVisibility (boolean state) |
void | setArrowIcon (int arrowIconResId) |
void | setClearIcon (int clearIconResId) |
void | setClearIconVisibility (boolean state) |
void | setNavIconTint (int navIconTint) |
void | setMenuIconTint (int menuIconTint) |
void | setSearchIconTint (int searchIconTint) |
void | setArrowIconTint (int arrowIconTint) |
void | setClearIconTint (int clearIconTint) |
void | setIconRippleStyle (boolean borderlessRippleEnabled) |
void | setHint (CharSequence hintText) |
void | setPlaceHolderText (CharSequence placeHolderText) |
CharSequence | getPlaceHolderText () |
void | setMenuDividerEnabled (boolean menuDividerEnabled) |
void | setSpeechMode (boolean speechMode) |
boolean | isVoicePermissionGranted () |
void | setVoicePermissionGranted (boolean state) |
boolean | isSpeechModeEnabled () |
boolean | isSearchEnabled () |
void | setMaxSuggestionCount (int maxSuggestionsCount) |
void | setCustomSuggestionAdapter (SuggestionsAdapter suggestionAdapter) |
List | getLastSuggestions () |
void | setLastSuggestions (List suggestions) |
void | updateLastSuggestions (List suggestions) |
void | setSuggestionsClickListener (SuggestionsAdapter.OnItemViewClickListener listener) |
void | setTextColor (int textColor) |
void | setTextHintColor (int hintColor) |
void | setPlaceHolderColor (int placeholderColor) |
void | setTextHighlightColor (int highlightedTextColor) |
void | setDividerColor (int dividerColor) |
void | setNavButtonEnabled (boolean navButtonEnabled) |
void | setRoundedSearchBarEnabled (boolean roundedSearchBarEnabled) |
void | setCardViewElevation (int elevation) |
String | getText () |
void | setText (String text) |
void | setTextWithoutActivatingTextWatcher (String text) |
void | addTextChangeListener (TextWatcher textWatcher) |
EditText | getSearchEditText () |
TextView | getPlaceHolderView () |
void | onClick (View v) |
void | onAnimationStart (Animation animation) |
void | onAnimationEnd (Animation animation) |
void | onAnimationRepeat (Animation animation) |
void | onFocusChange (View v, boolean hasFocus) |
boolean | onEditorAction (TextView v, int actionId, KeyEvent event) |
void | OnItemClickListener (int position, View v) |
void | OnItemDeleteListener (int position, View v) |
boolean | dispatchKeyEvent (KeyEvent event) |
void | setAppbaseClient (String url, String appName, String username, String password, String type) |
void | setAppbaseClient (String url, String appName, String username, String password) |
String | search (SearchPropModel searchPropModel, String query) throws ExecutionException, InterruptedException |
String | search (SearchPropModel searchPropModel, String query, String category, boolean isCategoricalSearch) throws ExecutionException, InterruptedException |
SearchProp | setSearchProp (String componentId, ArrayList< String > dataFields) |
String | getRequestedQuery (SearchPropModel searchPropModel) |
String | getCategoricalSearchQuery (SearchPropModel searchPropModel, String category) |
void | setLoggingQuery (boolean state) |
RecyclerView | getRecyclerView () |
void | setOnTextChangeListener (TextChangeListener textChangeListener) |
void | setSearchPropModel (SearchPropModel searchPropModel) |
void | startSearch (final SearchPropModel searchPropModel, final ItemClickListener itemClickListener) |
void | startVoiceSearch (final SearchPropModel searchPropModel, final ItemClickListener itemClickListener) |
DefaultClientSuggestions | buildCustomSuggestions (SearchPropModel searchPropModel, ArrayList< String > suggestions) |
Analytics | setAnalyticsProps () |
String | getAnalytics (AnalyticsModel analyticsModel) |
Protected Member Functions | |
Parcelable | onSaveInstanceState () |
void | onRestoreInstanceState (Parcelable state) |
void com.harsh.searchwidget.SearchBar.addTextChangeListener | ( | TextWatcher | textWatcher | ) |
Add text watcher to searchbar's EditText
textWatcher | textWatcher to add |
boolean com.harsh.searchwidget.SearchBar.areSuggestionsEnabled | ( | ) |
Check if suggestions are enabled
boolean com.harsh.searchwidget.SearchBar.areSuggestionsVisible | ( | ) |
Check if suggestions are shown
DefaultClientSuggestions com.harsh.searchwidget.SearchBar.buildCustomSuggestions | ( | SearchPropModel | searchPropModel, |
ArrayList< String > | suggestions | ||
) |
Returns object of DefaultClientSuggestions model to modify the search results as required before setting the DefaultClientSuggestionsAdapter
searchPropModel | Model which is returned on building the search prop |
suggestions | List of suggestions |
void com.harsh.searchwidget.SearchBar.clearSuggestions | ( | ) |
Clears the suggestions list
void com.harsh.searchwidget.SearchBar.disableSearch | ( | ) |
Hides search input and close arrow
void com.harsh.searchwidget.SearchBar.enableSearch | ( | ) |
Shows search input and close arrow
String com.harsh.searchwidget.SearchBar.getAnalytics | ( | AnalyticsModel | analyticsModel | ) |
Provides analytics for the given search id (previous search id by default)
analyticsModel | Analytics Model with all the necessary properties |
String com.harsh.searchwidget.SearchBar.getCategoricalSearchQuery | ( | SearchPropModel | searchPropModel, |
String | category | ||
) |
Search query for making a categorical search
searchPropModel | Model which is returned on building the search prop |
List com.harsh.searchwidget.SearchBar.getLastSuggestions | ( | ) |
Returns the last search queries. The queries are stored only for the duration of one activity session. When the activity is destroyed, the queries will be deleted. To save queries, use the method getLastSuggestions(). To recover the queries use the method setLastSuggestions().
List< String > will be returned if You don't use custom adapter.
PopupMenu com.harsh.searchwidget.SearchBar.getMenu | ( | ) |
Get popup menu
CharSequence com.harsh.searchwidget.SearchBar.getPlaceHolderText | ( | ) |
Returns the place holder text
RecyclerView com.harsh.searchwidget.SearchBar.getRecyclerView | ( | ) |
Provides recycler view for attaching custom adapter
String com.harsh.searchwidget.SearchBar.getRequestedQuery | ( | SearchPropModel | searchPropModel | ) |
The query built using search prop parameters and which can be directly passed into Appbase search client
searchPropModel | Model which is returned on building the search prop |
String com.harsh.searchwidget.SearchBar.getText | ( | ) |
Get search text
void com.harsh.searchwidget.SearchBar.inflateMenu | ( | int | menuResource | ) |
Inflate menu for searchBar
menuResource | - menu resource |
void com.harsh.searchwidget.SearchBar.inflateMenu | ( | int | menuResource, |
int | icon | ||
) |
Inflate menu for searchBar with custom Icon
menuResource | - menu resource |
icon | - icon resource id |
boolean com.harsh.searchwidget.SearchBar.isSearchEnabled | ( | ) |
Check if search bar is in edit mode
boolean com.harsh.searchwidget.SearchBar.isSpeechModeEnabled | ( | ) |
True if MaterialSearchBar is in speech mode
boolean com.harsh.searchwidget.SearchBar.isVoicePermissionGranted | ( | ) |
Checks if the voice recording permission is granted for the device Also sets the state of speechPermissionGranted variable
String com.harsh.searchwidget.SearchBar.search | ( | SearchPropModel | searchPropModel, |
String | query | ||
) | throws ExecutionException, InterruptedException |
Gives response for the requested query using Appbase client
searchPropModel | Model which is returned on building the search prop |
query | Query Text |
ExecutionException | |
InterruptedException |
String com.harsh.searchwidget.SearchBar.search | ( | SearchPropModel | searchPropModel, |
String | query, | ||
String | category, | ||
boolean | isCategoricalSearch | ||
) | throws ExecutionException, InterruptedException |
Gives response for the requested query using Appbase client
searchPropModel | Model which is returned on building the search prop |
query | Query Text |
category | Category to search in |
isCategoricalSearch | If the search query should be categorical |
ExecutionException | |
InterruptedException |
Analytics com.harsh.searchwidget.SearchBar.setAnalyticsProps | ( | ) |
Initiates Analytics Prop
void com.harsh.searchwidget.SearchBar.setAppbaseClient | ( | String | url, |
String | appName, | ||
String | username, | ||
String | password | ||
) |
Initiates the Appbase client for giving additional functionality to search bar - with default type
url | URL of the ElasticSearch host server (If application is hosted on appbase.io, url should be https://scalr.api.appbase.io) |
appName | Name of the app (aka search index) |
username | Username for basic auth (String before ':' in credentials string) |
password | Password for given username (String after ':' in credentials string) |
void com.harsh.searchwidget.SearchBar.setAppbaseClient | ( | String | url, |
String | appName, | ||
String | username, | ||
String | password, | ||
String | type | ||
) |
Initiates the Appbase client for giving additional functionality to search bar
url | URL of the ElasticSearch host server (If application is hosted on appbase.io, url should be https://scalr.api.appbase.io) |
appName | Name of the app (aka search index) |
username | Username for basic auth (String before ':' in credentials string) |
password | Password for given username (String after ':' in credentials string) |
type | Type to be queried |
void com.harsh.searchwidget.SearchBar.setArrowIcon | ( | int | arrowIconResId | ) |
Set back arrow icon drawable
arrowIconResId | icon resource id |
void com.harsh.searchwidget.SearchBar.setArrowIconTint | ( | int | arrowIconTint | ) |
Set the tint color of the back arrow icon
arrowIconTint | arrow icon color |
void com.harsh.searchwidget.SearchBar.setCardViewElevation | ( | int | elevation | ) |
Set CardView elevation
elevation | desired elevation |
void com.harsh.searchwidget.SearchBar.setClearIcon | ( | int | clearIconResId | ) |
Set clear icon drawable
clearIconResId | icon resource id |
void com.harsh.searchwidget.SearchBar.setClearIconTint | ( | int | clearIconTint | ) |
Set the tint color of the clear icon
clearIconTint | clear icon tint |
void com.harsh.searchwidget.SearchBar.setClearIconVisibility | ( | boolean | state | ) |
Sets visibility of clear icon in search bar
state | Boolean state visibility for clear icon |
void com.harsh.searchwidget.SearchBar.setCustomSuggestionAdapter | ( | SuggestionsAdapter | suggestionAdapter | ) |
Sets a custom adapter for suggestions list view.
suggestionAdapter | customized adapter |
void com.harsh.searchwidget.SearchBar.setHint | ( | CharSequence | hintText | ) |
Sets search bar hintText
hintText | hintText text |
void com.harsh.searchwidget.SearchBar.setIconRippleStyle | ( | boolean | borderlessRippleEnabled | ) |
Show a borderless ripple(circular) when icon is pressed Borderless only available on SDK V21+
borderlessRippleEnabled | true for borderless, false for default |
void com.harsh.searchwidget.SearchBar.setLastSuggestions | ( | List | suggestions | ) |
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.
suggestions | an array of queries |
void com.harsh.searchwidget.SearchBar.setLoggingQuery | ( | boolean | state | ) |
Sets the value of parameter used for checking whether to log requested query for debugging
state | Boolean state of the logging parameter |
void com.harsh.searchwidget.SearchBar.setMaxSuggestionCount | ( | int | maxSuggestionsCount | ) |
Specifies the maximum number of search queries stored until the activity is destroyed
maxSuggestionsCount | maximum queries |
void com.harsh.searchwidget.SearchBar.setMenuIcon | ( | int | menuIconResId | ) |
Set Menu Icon Drawable
menuIconResId | icon resource id |
void com.harsh.searchwidget.SearchBar.setMenuIconTint | ( | int | menuIconTint | ) |
Set the tint color of the menu icon
menuIconTint | menu icon color |
void com.harsh.searchwidget.SearchBar.setNavButtonEnabled | ( | boolean | navButtonEnabled | ) |
Set navigation drawer menu icon enabled
navButtonEnabled | icon enabled |
void com.harsh.searchwidget.SearchBar.setNavIconTint | ( | int | navIconTint | ) |
Set the tint color of the navigation icon
navIconTint | nav icon color |
void com.harsh.searchwidget.SearchBar.setOnSearchActionListener | ( | OnSearchActionListener | onSearchActionListener | ) |
Register listener for search bar callbacks.
onSearchActionListener | the callback listener |
void com.harsh.searchwidget.SearchBar.setOnTextChangeListener | ( | TextChangeListener | textChangeListener | ) |
Registers listener for text change callbacks
textChangeListener | Text change callbacks |
void com.harsh.searchwidget.SearchBar.setPlaceHolderColor | ( | int | placeholderColor | ) |
Set placeholder text color
placeholderColor | placeholder color |
void com.harsh.searchwidget.SearchBar.setPlaceHolderText | ( | CharSequence | placeHolderText | ) |
Sets search bar placeholder text
placeHolderText | Text to be shown while search bar is disabled |
void com.harsh.searchwidget.SearchBar.setRoundedSearchBarEnabled | ( | boolean | roundedSearchBarEnabled | ) |
Enable capsule shaped SearchBar (API 21+)
roundedSearchBarEnabled | capsule shape enabled @ |
void com.harsh.searchwidget.SearchBar.setSearchIcon | ( | int | searchIconResId | ) |
Set search icon drawable
searchIconResId | icon resource id |
void com.harsh.searchwidget.SearchBar.setSearchIconTint | ( | int | searchIconTint | ) |
Set the tint color of the search/speech icon
searchIconTint | search icon color |
void com.harsh.searchwidget.SearchBar.setSearchIconVisibility | ( | boolean | state | ) |
Sets visibility of search icon in search bar
state | Boolean state visibility for search icon |
SearchProp com.harsh.searchwidget.SearchBar.setSearchProp | ( | String | componentId, |
ArrayList< String > | dataFields | ||
) |
Initiates Search prop
componentId | Unique identifier of the component |
dataFields | Data field(s) on which search query is to be applied to |
void com.harsh.searchwidget.SearchBar.setSearchPropModel | ( | SearchPropModel | searchPropModel | ) |
Sets new SearchPropModel which is used by startSearch method
searchPropModel | SearchPropModel object |
void com.harsh.searchwidget.SearchBar.setSpeechMode | ( | boolean | speechMode | ) |
sets the speechMode for the search bar. If set to true, microphone icon will display instead of the search icon. Also clicking on this icon will trigger the callback method onButtonClicked()
speechMode | enable speech |
void com.harsh.searchwidget.SearchBar.setSuggestionsClickListener | ( | SuggestionsAdapter.OnItemViewClickListener | listener | ) |
Allows you to intercept the suggestions click event
This method will not work with custom Suggestion Adapter
listener | click listener |
void com.harsh.searchwidget.SearchBar.setSuggestionsEnabled | ( | boolean | suggestionsEnabled | ) |
Set suggestions enabled
void com.harsh.searchwidget.SearchBar.setText | ( | String | text | ) |
Set search text
text | Text value |
void com.harsh.searchwidget.SearchBar.setTextColor | ( | int | textColor | ) |
Set search input text color
textColor | text color |
void com.harsh.searchwidget.SearchBar.setTextHighlightColor | ( | int | highlightedTextColor | ) |
Set the color of the highlight when text is selected
highlightedTextColor | selected text highlight color |
void com.harsh.searchwidget.SearchBar.setTextHintColor | ( | int | hintColor | ) |
Set text input hintText color
hintColor | text hintText color |
void com.harsh.searchwidget.SearchBar.setTextWithoutActivatingTextWatcher | ( | String | text | ) |
Sets text in search bar without activating onTextChangeListener
text | Text value |
void com.harsh.searchwidget.SearchBar.setVoicePermissionGranted | ( | boolean | state | ) |
Sets the state of speechPermissionGranted variable
state | Whether voice recording permission is granted or not |
void com.harsh.searchwidget.SearchBar.startSearch | ( | final SearchPropModel | searchPropModel, |
final ItemClickListener | itemClickListener | ||
) |
Starts on text change callbacks to be handled by the listener. Call this method after setting TextChangeListener to start its functionality
searchPropModel | Model which is returned on building the search prop |
itemClickListener | Listener to handle callbacks from click and long click events |
void com.harsh.searchwidget.SearchBar.startVoiceSearch | ( | final SearchPropModel | searchPropModel, |
final ItemClickListener | itemClickListener | ||
) |
Starts voice search functionality The method first checks whether voice recording permission is given for the device
searchPropModel | Model which is returned on building the search prop |
itemClickListener | Listener to handle callbacks from click and long click events |
void com.harsh.searchwidget.SearchBar.updateLastSuggestions | ( | List | suggestions | ) |
Changes the array of recent search queries with animation.
Pass a List< String > if You don't use custom adapter.
suggestions | an array of queries |