PersistentSearch


Source link: https://github.com/KieronQuinn/PersistentSearch

This project is deprecated

It's not been maintained for well over half a year and is formally discontinued. There are better alternatives now, such as SearchView and FloatingSearchView

Android Persistent Search Library

A library that implements the persistent search bar seen on apps such as Google Now, Google Maps and Google Play

Usage

Android Studio: Add the Sonatype repository if you have not already:

maven {

url "https://oss.sonatype.org/content/repositories/snapshots"
  
}
 

Import it as a dependency:

compile 'com.quinny898.library.persistentsearch:library:1.1.0-SNAPSHOT' 

Eclipse: Import it as a library project

In your layout:

<com.quinny898.library.persistentsearch.SearchBox

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:id="@+id/searchbox"

/> 

Please include this after any elements you wish to be hidden by it in a releativelayout.

Absolute requirements in the activity code

In your onCreate/onCreateView (activity or fragment):

search.enableVoiceRecognition(this);
 

And in the same class:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

  if (isAdded() && requestCode == SearchBox.VOICE_RECOGNITION_CODE && resultCode == getActivity().RESULT_OK) {

 ArrayList<String> matches = data

  .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

 search.populateEditText(matches);

  
}

  super.onActivityResult(requestCode, resultCode, data);
 
}
 

More on implementation:

search = (SearchBox) findViewById(R.id.searchbox);
 for(int x = 0; x < 10; x++){
  SearchResult option = new SearchResult("Result " + Integer.toString(x), getResources().getDrawable(R.drawable.ic_history));
  search.addSearchable(option);
 
}

search.setLogoText("My App");
 search.setMenuListener(new MenuListener(){

 @Override
public void onMenuClick() {

 //Hamburger has been clicked
 Toast.makeText(MainActivity.this, "Menu click", Toast.LENGTH_LONG).show();

 
}

}
);
 search.setSearchListener(new SearchListener(){

@Override  public void onSearchOpened() {

//Use this to tint the screen  
}

@Override  public void onSearchClosed() {

//Use this to un-tint the screen  
}

@Override  public void onSearchTermChanged() {

//React to the search term changing
//Called after it has updated results  
}

@Override  public void onSearch(String searchTerm) {

Toast.makeText(MainActivity.this, searchTerm +" Searched", Toast.LENGTH_LONG).show();

  
}

 @Override  public void onResultClick(SearchResult result){

//React to a result being clicked  
}

@Override  public void onSearchCleared() {

 
}

  
}
);
 

##Showing from a MenuItem

search.revealFromMenuItem(R.id.action_search, this);
 

Note that when a search occurs, the box closes. You should react to this in onSearch, maybe set your toolbar title?

Custom

Set the logo text color:

search.setLogoTextColor(Color.parse("#000000"));
 

SearchResult

This is a class that holds two parameters - Title and icon
The title is displayed as a suggested result and will be used for searching, the icon is displayed to the left of the title in the suggestions (eg. a history icon)
You can make a SearchResult as follows

new SearchResult("Title", getResources().getDrawable(R.drawable.icon));
 

All usage methods

See here for the documentation: http://quinny898.co.uk/PersistentSearch/

Licence

Copyright 2015 Kieron Quinn

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Resources

A Loading View for Android.

The indirect-injector simplify confusion of communication between activity and fragment, and dependencies.

This project allows to add decoration element at the corner of view.

Android Utility classes.

  • Simple logging
  • AppCompatPreferenceActivity
  • Functional Interfaces

VerbalExpressions is a Java library that helps to construct difficult regular expressions.

The RecyclerView is one of the most used widgets in the Android world, and with it you have to implement an Adapter which provides the items for the view. Most use cases require the same base logic, but require you to write everything again and again.

The FastAdapter is here to simplify this process. You don't have to worry about the adapter anymore. Just write the logic for how your view should look like, and you are done.

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