SearchView


Source link: https://github.com/lapism/SearchView

SearchView

Persistent SearchView Library from Play Store.
Features: Material Design, Toolbar/MenuItem version, History, Styling.

Google Material Design Pattern:
https://material.io/guidelines/patterns/search.html

Version History:
https://bintray.com/lapism/maven/searchview/view

Material colors in the project:
https://gist.github.com/lapism/3b417142300d9dbde3b4

Donations:

Please support me!


Apps using this library:
Because I have done firstly this library as a private project, I would like to know if someone of you use my library in your application. If yes, please send me the name of your app and the link to Play Store and I will promote your app in ReadMe.

Service Notes
Business Card Reader
Toiletto
Zikobot
AllWeather
Karaoke Online Sing & Record
Playbuzz
MovieTracker
MaxTorz
RealTime Subscriber YouTube
Lucidity - Lucid Dream Journal
Guide COC


Usage

Add the dependencies to your gradle file:

dependencies {

  implementation 'com.lapism:searchview:5.0.0-alpha7'

 implementation 'com.android.support:cardview-v7:26.1.0'
  implementation 'com.google.android:flexbox:0.3.1' 
}

Versions:

SearchView identifies its layout style through versions. Currently, there are two values, namely SearchView.Version.TOOLBAR for the persistent view, and SearchView.Version.MENU_ITEM for the view that appears on a MenuItem press. The version can be defined through setVersion.

SearchView.Version.MENU_ITEM and SearchView.Version.TOOLBAR:

SearchHistoryTable mHistoryDatabase = new SearchHistoryTable(this);
  SearchView mSearchView = (SearchView) findViewById(R.id.searchView);
 // to API 25 SearchView mSearchView = findViewById(R.id.searchView);
 // from API 26 if (mSearchView != null) {

  mSearchView.setVersionMargins(SearchView.VersionMargins.TOOLBAR_SMALL);

  mSearchView.setHint(R.string.search);

  mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

@Override

public boolean onQueryTextSubmit(String query) {

 mHistoryDatabase.addItem(new SearchItem(query));

 mSearchView.close(false);

 return true;

}

 @Override

public boolean onQueryTextChange(String newText) {

 return false;

}

  
}
);

  mSearchView.setOnOpenCloseListener(new SearchView.OnOpenCloseListener() {

@Override

public boolean onOpen() {

 if (mFab != null) {

  mFab.hide();

 
}

 return true;

}

 @Override

public boolean onClose() {

 if (mFab != null && !mDrawerLayout.isDrawerOpen(GravityCompat.START)) {

  mFab.show();

 
}

 return true;

}

  
}
);

  mSearchView.setVoiceText("Set permission on Android 6.0+ !");

  searchView.setOnVoiceIconClickListener(new SearchView.OnVoiceIconClickListener() {

@Override

public void onVoiceIconClick() {

 // permission

}

  
}
);

List<SearchItem> suggestionsList = new ArrayList<>();

  suggestionsList.add(new SearchItem("search1"));

  suggestionsList.add(new SearchItem("search2"));

  suggestionsList.add(new SearchItem("search3"));

SearchAdapter searchAdapter = new SearchAdapter(this, suggestionsList);

  searchAdapter.setOnSearchItemClickListener(new SearchAdapter.OnSearchItemClickListener() {

@Override

public void onSearchItemClick(View view, int position, String text) {

 mHistoryDatabase.addItem(new SearchItem(text));

 mSearchView.close(false);

}

  
}
);

  mSearchView.setAdapter(searchAdapter);

suggestionsList.add(new SearchItem("search1"));

  suggestionsList.add(new SearchItem("search2"));

  suggestionsList.add(new SearchItem("search3"));

  searchAdapter.notifyDataSetChanged();

List<SearchFilter> filter = new ArrayList<>();

  filter.add(new SearchFilter("Filter1", true));

  filter.add(new SearchFilter("Filter2", true));

  mSearchView.setFilters(filter);

  //use mSearchView.getFiltersStates() to consider filter when performing search 
}

SearchView.Version.MENU_ITEM:

@Override public boolean onOptionsItemSelected(MenuItem item) {

  switch (item.getItemId()) {

case R.id.action_search: {

 mSearchView.open(true/false);
 // enable or disable animation

 return true;

}

default:

 return super.onOptionsItemSelected(item);

  
}
 
}

XML:

<com.lapism.searchview.SearchView
  android:id="@+id/searchView"
  android:layout_width="match_parent"
  android:layout_height="match_parent" />

 // will be new

XML with CoordinatorLayout:

<com.lapism.searchview.SearchView
  android:id="@+id/searchView"
  android:layout_width="match_parent"
  android:layout_height="match_parent"

app:layout_behavior="com.lapism.searchview.SearchBehavior" />

// will be new

Styling SearchView:

<attr name="search_version" format="enum">
  <enum name="toolbar" value="1000" />
  <enum name="menu_item" value="1001" /> </attr> <attr name="search_version_margins" format="enum">
  <enum name="toolbar_small" value="2000" />
  <enum name="toolbar_big" value="2001" />
  <enum name="menu_item" value="2002" /> </attr> <attr name="search_theme" format="enum">
  <enum name="light" value="3000" />
  <enum name="dark" value="3001" />
  <enum name="play_store" value="3002" /> </attr> <attr name="search_height" format="dimension" /> <attr name="search_navigation_icon" format="integer" /> <attr name="search_icon_color" format="color" /> <attr name="search_background_color" format="color" /> <attr name="search_text_color" format="color" /> <attr name="search_text_highlight_color" format="color" /> <attr name="search_text_size" format="dimension" /> <attr name="search_text_style" format="enum">
  <enum name="normal" value="0" />
  <enum name="bold" value="1" />
  <enum name="italic" value="2" />
  <enum name="bold_italic" value="3" /> </attr> <attr name="search_hint" format="string" /> <attr name="search_hint_color" format="color" /> <attr name="search_voice" format="boolean" /> <attr name="search_voice_text" format="string" /> <attr name="search_animation_duration" format="integer" /> <attr name="search_shadow" format="boolean" /> <attr name="search_shadow_color" format="boolean" /> <attr name="search_elevation" format="dimension" /> <attr name="search_clear_on_open" format="boolean" /> <attr name="search_clear_on_close" format="boolean" /> <attr name="search_hide_on_keyboard_close" format="boolean" /> <attr name="search_show_progress" format="boolean" /> <attr name="search_cursor_drawable" format="integer" />

Resources

A cool ViewPager.

A swipe layout similar to iOS Mail app.

This library allows you to send simple data from WebView to Java. Sends the data via url.

Arc Layout is a view group with which you can add a arc-shaped container in your layout. Two main variables are the direction and the curvature of the arc.

Custom implementation of NavigationView for using custom layout for navigation items and header.

Getting location updates requires lots of bolierplate code in Android, You need to take care of

  • Google Play services availablity Check
  • Update Google play Service Dialog
  • Creation of GoogleApiClient and its callbacks connected,disconnected etc.
  • Stopping and releasing resources for location updates
  • Handling Location permission scenarios
  • Checking Location services are On or Off
  • Getting lastknown location is not so easy either
  • Fallback to last known location if not getting location after certain duration

Android-EasyLocation does all this stuff in background, so that you can concentrate on your business logic than handling all above

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes