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.
All Classes Functions
com.harsh.searchwidget.SearchBar Class Reference
Inheritance diagram for com.harsh.searchwidget.SearchBar:
com.harsh.searchwidget.Adapter.SuggestionsAdapter< S, V extends RecyclerView.ViewHolder >.OnItemViewClickListener

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)
 

Static Public Attributes

static final int BUTTON_SPEECH = 1
 
static final int BUTTON_NAVIGATION = 2
 
static final int BUTTON_BACK = 3
 
static final int VIEW_VISIBLE = 1
 
static final int VIEW_INVISIBLE = 0
 

Protected Member Functions

Parcelable onSaveInstanceState ()
 
void onRestoreInstanceState (Parcelable state)
 

Member Function Documentation

◆ addTextChangeListener()

void com.harsh.searchwidget.SearchBar.addTextChangeListener ( TextWatcher  textWatcher)

Add text watcher to searchbar's EditText

Parameters
textWatchertextWatcher to add

◆ areSuggestionsEnabled()

boolean com.harsh.searchwidget.SearchBar.areSuggestionsEnabled ( )

Check if suggestions are enabled

◆ areSuggestionsVisible()

boolean com.harsh.searchwidget.SearchBar.areSuggestionsVisible ( )

Check if suggestions are shown

Returns
return result

◆ buildCustomSuggestions()

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

Parameters
searchPropModelModel which is returned on building the search prop
suggestionsList of suggestions
Returns
Object of DefaultClientSuggestions Model

◆ clearSuggestions()

void com.harsh.searchwidget.SearchBar.clearSuggestions ( )

Clears the suggestions list

◆ disableSearch()

void com.harsh.searchwidget.SearchBar.disableSearch ( )

Hides search input and close arrow

◆ enableSearch()

void com.harsh.searchwidget.SearchBar.enableSearch ( )

Shows search input and close arrow

◆ getAnalytics()

String com.harsh.searchwidget.SearchBar.getAnalytics ( AnalyticsModel  analyticsModel)

Provides analytics for the given search id (previous search id by default)

Parameters
analyticsModelAnalytics Model with all the necessary properties
Returns
Analytics received for the given search id

◆ getCategoricalSearchQuery()

String com.harsh.searchwidget.SearchBar.getCategoricalSearchQuery ( SearchPropModel  searchPropModel,
String  category 
)

Search query for making a categorical search

Parameters
searchPropModelModel which is returned on building the search prop
Returns
Returns the query built by search prop parameters

◆ getLastSuggestions()

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.

Returns
array with the latest search queries
See also
setLastSuggestions(List)
setMaxSuggestionCount(int)

◆ getMenu()

PopupMenu com.harsh.searchwidget.SearchBar.getMenu ( )

Get popup menu

Returns
PopupMenu

◆ getPlaceHolderText()

CharSequence com.harsh.searchwidget.SearchBar.getPlaceHolderText ( )

Returns the place holder text

Returns
placeholder text

◆ getRecyclerView()

RecyclerView com.harsh.searchwidget.SearchBar.getRecyclerView ( )

Provides recycler view for attaching custom adapter

Returns
Search results recycler view

◆ getRequestedQuery()

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

Parameters
searchPropModelModel which is returned on building the search prop
Returns
Returns the query built by search prop parameters

◆ getText()

String com.harsh.searchwidget.SearchBar.getText ( )

Get search text

Returns
text

◆ inflateMenu() [1/2]

void com.harsh.searchwidget.SearchBar.inflateMenu ( int  menuResource)

Inflate menu for searchBar

Parameters
menuResource- menu resource

◆ inflateMenu() [2/2]

void com.harsh.searchwidget.SearchBar.inflateMenu ( int  menuResource,
int  icon 
)

Inflate menu for searchBar with custom Icon

Parameters
menuResource- menu resource
icon- icon resource id

◆ isSearchEnabled()

boolean com.harsh.searchwidget.SearchBar.isSearchEnabled ( )

Check if search bar is in edit mode

Returns
true if search bar is in edit mode

◆ isSpeechModeEnabled()

boolean com.harsh.searchwidget.SearchBar.isSpeechModeEnabled ( )

True if MaterialSearchBar is in speech mode

Returns
speech mode

◆ isVoicePermissionGranted()

boolean com.harsh.searchwidget.SearchBar.isVoicePermissionGranted ( )

Checks if the voice recording permission is granted for the device Also sets the state of speechPermissionGranted variable

Returns

◆ search() [1/2]

String com.harsh.searchwidget.SearchBar.search ( SearchPropModel  searchPropModel,
String  query 
) throws ExecutionException, InterruptedException

Gives response for the requested query using Appbase client

Parameters
searchPropModelModel which is returned on building the search prop
queryQuery Text
Returns
Response received for the requested query
Exceptions
ExecutionException
InterruptedException

◆ search() [2/2]

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

Parameters
searchPropModelModel which is returned on building the search prop
queryQuery Text
categoryCategory to search in
isCategoricalSearchIf the search query should be categorical
Returns
Response received for the requested query
Exceptions
ExecutionException
InterruptedException

◆ setAnalyticsProps()

Analytics com.harsh.searchwidget.SearchBar.setAnalyticsProps ( )

Initiates Analytics Prop

Returns
Analytics builder to set available properties

◆ setAppbaseClient() [1/2]

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

Parameters
urlURL of the ElasticSearch host server (If application is hosted on appbase.io, url should be https://scalr.api.appbase.io)
appNameName of the app (aka search index)
usernameUsername for basic auth (String before ':' in credentials string)
passwordPassword for given username (String after ':' in credentials string)

◆ setAppbaseClient() [2/2]

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

Parameters
urlURL of the ElasticSearch host server (If application is hosted on appbase.io, url should be https://scalr.api.appbase.io)
appNameName of the app (aka search index)
usernameUsername for basic auth (String before ':' in credentials string)
passwordPassword for given username (String after ':' in credentials string)
typeType to be queried

◆ setArrowIcon()

void com.harsh.searchwidget.SearchBar.setArrowIcon ( int  arrowIconResId)

Set back arrow icon drawable

Parameters
arrowIconResIdicon resource id

◆ setArrowIconTint()

void com.harsh.searchwidget.SearchBar.setArrowIconTint ( int  arrowIconTint)

Set the tint color of the back arrow icon

Parameters
arrowIconTintarrow icon color

◆ setCardViewElevation()

void com.harsh.searchwidget.SearchBar.setCardViewElevation ( int  elevation)

Set CardView elevation

Parameters
elevationdesired elevation

◆ setClearIcon()

void com.harsh.searchwidget.SearchBar.setClearIcon ( int  clearIconResId)

Set clear icon drawable

Parameters
clearIconResIdicon resource id

◆ setClearIconTint()

void com.harsh.searchwidget.SearchBar.setClearIconTint ( int  clearIconTint)

Set the tint color of the clear icon

Parameters
clearIconTintclear icon tint

◆ setClearIconVisibility()

void com.harsh.searchwidget.SearchBar.setClearIconVisibility ( boolean  state)

Sets visibility of clear icon in search bar

Parameters
stateBoolean state visibility for clear icon

◆ setCustomSuggestionAdapter()

void com.harsh.searchwidget.SearchBar.setCustomSuggestionAdapter ( SuggestionsAdapter  suggestionAdapter)

Sets a custom adapter for suggestions list view.

Parameters
suggestionAdaptercustomized adapter

◆ setHint()

void com.harsh.searchwidget.SearchBar.setHint ( CharSequence  hintText)

Sets search bar hintText

Parameters
hintTexthintText text

◆ setIconRippleStyle()

void com.harsh.searchwidget.SearchBar.setIconRippleStyle ( boolean  borderlessRippleEnabled)

Show a borderless ripple(circular) when icon is pressed Borderless only available on SDK V21+

Parameters
borderlessRippleEnabledtrue for borderless, false for default

◆ setLastSuggestions()

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.

Parameters
suggestionsan array of queries
See also
getLastSuggestions()
setMaxSuggestionCount(int)

◆ setLoggingQuery()

void com.harsh.searchwidget.SearchBar.setLoggingQuery ( boolean  state)

Sets the value of parameter used for checking whether to log requested query for debugging

Parameters
stateBoolean state of the logging parameter

◆ setMaxSuggestionCount()

void com.harsh.searchwidget.SearchBar.setMaxSuggestionCount ( int  maxSuggestionsCount)

Specifies the maximum number of search queries stored until the activity is destroyed

Parameters
maxSuggestionsCountmaximum queries

◆ setMenuIcon()

void com.harsh.searchwidget.SearchBar.setMenuIcon ( int  menuIconResId)

Set Menu Icon Drawable

Parameters
menuIconResIdicon resource id

◆ setMenuIconTint()

void com.harsh.searchwidget.SearchBar.setMenuIconTint ( int  menuIconTint)

Set the tint color of the menu icon

Parameters
menuIconTintmenu icon color

◆ setNavButtonEnabled()

void com.harsh.searchwidget.SearchBar.setNavButtonEnabled ( boolean  navButtonEnabled)

Set navigation drawer menu icon enabled

Parameters
navButtonEnabledicon enabled

◆ setNavIconTint()

void com.harsh.searchwidget.SearchBar.setNavIconTint ( int  navIconTint)

Set the tint color of the navigation icon

Parameters
navIconTintnav icon color

◆ setOnSearchActionListener()

void com.harsh.searchwidget.SearchBar.setOnSearchActionListener ( OnSearchActionListener  onSearchActionListener)

Register listener for search bar callbacks.

Parameters
onSearchActionListenerthe callback listener

◆ setOnTextChangeListener()

void com.harsh.searchwidget.SearchBar.setOnTextChangeListener ( TextChangeListener  textChangeListener)

Registers listener for text change callbacks

Parameters
textChangeListenerText change callbacks

◆ setPlaceHolderColor()

void com.harsh.searchwidget.SearchBar.setPlaceHolderColor ( int  placeholderColor)

Set placeholder text color

Parameters
placeholderColorplaceholder color

◆ setPlaceHolderText()

void com.harsh.searchwidget.SearchBar.setPlaceHolderText ( CharSequence  placeHolderText)

Sets search bar placeholder text

Parameters
placeHolderTextText to be shown while search bar is disabled

◆ setRoundedSearchBarEnabled()

void com.harsh.searchwidget.SearchBar.setRoundedSearchBarEnabled ( boolean  roundedSearchBarEnabled)

Enable capsule shaped SearchBar (API 21+)

Parameters
roundedSearchBarEnabledcapsule shape enabled @

◆ setSearchIcon()

void com.harsh.searchwidget.SearchBar.setSearchIcon ( int  searchIconResId)

Set search icon drawable

Parameters
searchIconResIdicon resource id

◆ setSearchIconTint()

void com.harsh.searchwidget.SearchBar.setSearchIconTint ( int  searchIconTint)

Set the tint color of the search/speech icon

Parameters
searchIconTintsearch icon color

◆ setSearchIconVisibility()

void com.harsh.searchwidget.SearchBar.setSearchIconVisibility ( boolean  state)

Sets visibility of search icon in search bar

Parameters
stateBoolean state visibility for search icon

◆ setSearchProp()

SearchProp com.harsh.searchwidget.SearchBar.setSearchProp ( String  componentId,
ArrayList< String >  dataFields 
)

Initiates Search prop

Parameters
componentIdUnique identifier of the component
dataFieldsData field(s) on which search query is to be applied to

◆ setSearchPropModel()

void com.harsh.searchwidget.SearchBar.setSearchPropModel ( SearchPropModel  searchPropModel)

Sets new SearchPropModel which is used by startSearch method

Parameters
searchPropModelSearchPropModel object

◆ setSpeechMode()

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()

Parameters
speechModeenable speech
See also
#BUTTON_SPEECH
OnSearchActionListener::onButtonClicked(int)

◆ setSuggestionsClickListener()

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

Parameters
listenerclick listener

◆ setSuggestionsEnabled()

void com.harsh.searchwidget.SearchBar.setSuggestionsEnabled ( boolean  suggestionsEnabled)

Set suggestions enabled

◆ setText()

void com.harsh.searchwidget.SearchBar.setText ( String  text)

Set search text

Parameters
textText value

◆ setTextColor()

void com.harsh.searchwidget.SearchBar.setTextColor ( int  textColor)

Set search input text color

Parameters
textColortext color

◆ setTextHighlightColor()

void com.harsh.searchwidget.SearchBar.setTextHighlightColor ( int  highlightedTextColor)

Set the color of the highlight when text is selected

Parameters
highlightedTextColorselected text highlight color

◆ setTextHintColor()

void com.harsh.searchwidget.SearchBar.setTextHintColor ( int  hintColor)

Set text input hintText color

Parameters
hintColortext hintText color

◆ setTextWithoutActivatingTextWatcher()

void com.harsh.searchwidget.SearchBar.setTextWithoutActivatingTextWatcher ( String  text)

Sets text in search bar without activating onTextChangeListener

Parameters
textText value

◆ setVoicePermissionGranted()

void com.harsh.searchwidget.SearchBar.setVoicePermissionGranted ( boolean  state)

Sets the state of speechPermissionGranted variable

Parameters
stateWhether voice recording permission is granted or not

◆ startSearch()

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

Parameters
searchPropModelModel which is returned on building the search prop
itemClickListenerListener to handle callbacks from click and long click events

◆ startVoiceSearch()

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

Parameters
searchPropModelModel which is returned on building the search prop
itemClickListenerListener to handle callbacks from click and long click events

◆ updateLastSuggestions()

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.

Parameters
suggestionsan array of queries

The documentation for this class was generated from the following file: