Search Filter


Source link: https://github.com/Yalantis/SearchFilter

SearchFilter

Live DEMO on appetize.io

Check this project on dribbble

Read how we did it on our blog

##Requirements

  • Android SDK 18+

##Usage

Add to your root build.gradle:

allprojects {
  repositories {
  ...  maven {
 url "https://jitpack.io" 
}
  
}
 
}

Add the dependency:

dependencies {

 compile 'com.github.Yalantis:SearchFilter:v1.0.4' 
}

How to use this library

Firstly you need to place Filter above your RecyclerView in the layout file

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout

android:layout_width="match_parent"

android:layout_height="wrap_content">

 <android.support.v7.widget.Toolbar

 android:layout_width="match_parent"

 android:layout_height="?attr/actionBarSize"

 android:background="@color/colorPrimary"

 android:elevation="4dp"

 android:paddingRight="16dp">

  <RelativeLayout

  android:layout_width="match_parent"

  android:layout_height="match_parent">

<android.support.v7.widget.AppCompatImageView

android:layout_width="24dp"

android:layout_height="24dp"

android:layout_centerVertical="true"

android:src="@drawable/ic_alarm"

android:tint="@android:color/white" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:text="Questions"

android:textColor="@android:color/white"

android:textSize="20sp" />

<android.support.v7.widget.AppCompatImageView

android:layout_width="24dp"

android:layout_height="24dp"

android:layout_alignParentRight="true"

android:layout_centerVertical="true"

android:src="@drawable/ic_search"

android:tint="@android:color/white" />

  </RelativeLayout>

 </android.support.v7.widget.Toolbar>
  </android.support.design.widget.AppBarLayout>

<FrameLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#E4E6E3"

app:layout_behavior="@string/appbar_scrolling_view_behavior">

 <android.support.v7.widget.RecyclerView

 android:id="@+id/list"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 android:layout_marginTop="@dimen/container_height"

 tools:listitem="@layout/item_list" />

 <com.yalantis.filter.widget.Filter

 android:id="@+id/filter"

 android:layout_width="match_parent"

 android:layout_height="wrap_content" />

</FrameLayout> </android.support.design.widget.CoordinatorLayout> 

After that you need to create a class that extends FilterAdapter and to pass your model class as a generic. Here you can easily customize the appearance of filter items. For the sample app I created Tag model to represent the category of a question in the conversation.

class Adapter extends FilterAdapter<Tag> {

 Adapter(@NotNull List<? extends Tag> items) {

 super(items);

}

 @NotNull

@Override

public FilterItem createView(int position, Tag item) {

 FilterItem filterItem = new FilterItem(ExampleActivity.this);

  filterItem.setStrokeColor(mColors[0]);

 filterItem.setTextColor(mColors[0]);

 filterItem.setCheckedTextColor(ContextCompat.getColor(ExampleActivity.this, android.R.color.white));

 filterItem.setColor(ContextCompat.getColor(ExampleActivity.this, android.R.color.white));

 filterItem.setCheckedColor(mColors[position]);

 filterItem.setText(item.getText());

 filterItem.deselect();

  return filterItem;

}

  
}
 

To receive all the events from the Filter such as selection or deselection of a filter item it's necessary to add a FilterListener with the same model class passed as a generic

private FilterListener<Tag> mListener = new FilterListener<Tag>() {

 @Override

public void onFiltersSelected(@NotNull ArrayList<Tag> filters) {

 
}

 @Override

public void onNothingSelected() {

 
}

 @Override

public void onFilterSelected(Tag item) {

 
}

 @Override

public void onFilterDeselected(Tag item) {

 
}

}
; 

Basically Filter setup looks like that

 mFilter = (Filter<Tag>) findViewById(R.id.filter);
  mFilter.setAdapter(new Adapter(getTags()));
  mFilter.setListener(this);

//the text to show when there's no selected items  mFilter.setNoSelectedItemText(getString(R.string.str_all_selected));
  mFilter.build();
 

For more usage examples please review sample app

Let us know!

We’d be really happy if you sent us links to your projects where you use our component. Just send an email to [email protected] And do let us know if you have any questions or suggestion regarding the animation.

P.S. We’re going to publish more awesomeness wrapped in code and a tutorial on how to make UI for iOS (Android) better than better. Stay tuned!

License

The MIT License (MIT)  Copyright © 2016 Yalantis, https://yalantis.com  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 

Resources

A ViewPager implementation base on RecyclerView's code.

A simple Android library for implementing Bluetooth Serial Port Profile (SPP) communication.

This library imitates Google Inbox mailbox effect on the drop-down return.

A tool for mocking HTTP services.

Features:

  • HTTP response stubbing, matchable on URL, header and body content patterns
  • Request verification
  • Runs in unit tests, as a standalone process or as a WAR app
  • Configurable via a fluent Java API, JSON files and JSON over HTTP
  • Record/playback of stubs
  • Fault injection
  • Per-request conditional proxying
  • Browser proxying for request inspection and replacement
  • Stateful behaviour simulation
  • Configurable response delays

Mock your HTTP responses to test your REST API.

Mocky is a simple app which allows to generate custom HTTP responses. It's helpful when you have to request a build-in-progress WS, when you want to mock the backend response in a single app, or when you want to test your WS client.

Get a full fake REST API with zero coding in less than 30 seconds.

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