An easy to use, yet very customizable search dialog

Overview

search-dialog

An awesome and customizable search dialog with built-in search options.

search_dialog

Usage

First add jitpack to your projects build.gradle file

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

Then add the dependency in modules build.gradle file

dependencies {
    implementation 'com.github.mirrajabi:search-dialog:1.2.4'
}

Simple usage

if you just want to use the simple search dialog first you need to provide searchable items. to achieve this you should implement Searchable in your model.

you can see the SampleSearchModel for example :

public class SampleSearchModel implements Searchable {
    private String mTitle;

    public SampleSearchModel(String title) {
        mTitle = title;
    }

    @Override
    public String getTitle() {
        return mTitle;
    }

    public SampleSearchModel setTitle(String title) {
        mTitle = title;
        return this;
    }
}

now generate some search options in your activity :

    private ArrayList<SampleSearchModel> createSampleData(){
        ArrayList<SampleSearchModel> items = new ArrayList<>();
        items.add(new SampleSearchModel("First item"));
        items.add(new SampleSearchModel("Second item"));
        items.add(new SampleSearchModel("Third item"));
        items.add(new SampleSearchModel("The ultimate item"));
        items.add(new SampleSearchModel("Last item"));
        items.add(new SampleSearchModel("Lorem ipsum"));
        items.add(new SampleSearchModel("Dolor sit"));
        items.add(new SampleSearchModel("Some random word"));
        items.add(new SampleSearchModel("guess who's back"));
        return items;
    }

then you just need to add the below lines where you want to show the dialog :

new SimpleSearchDialogCompat(MainActivity.this, "Search...",
                        "What are you looking for...?", null, createSampleData(),
                        new SearchResultListener<SampleSearchModel>() {
                            @Override
                            public void onSelected(BaseSearchDialogCompat dialog,
                                                   SampleSearchModel item, int position) {
                                // If filtering is enabled, [position] is the index of the item in the filtered result, not in the unfiltered source
                                Toast.makeText(MainActivity.this, item.getTitle(),
                                        Toast.LENGTH_SHORT).show();
                                dialog.dismiss();
                            }
                        }).show();

The constructor parameters are

SimpleSearchDialogCompat(Context context, String title, String searchHint,
                                    @Nullable Filter filter, ArrayList<T> items,
                                    SearchResultListener<T> searchResultListener)

Loading view(added to SimpleSearchDialogCompat in v1.1)

Just use setLoading(true) for showing and setLoading(false) for hiding it on an instance of SimpleSearchDialogCompat

Changing default adapters text colors(added in v1.2.1)

If you want to change the default colors just override these colors in your colors.xml or wherever you want like this.

    <color name="searchDialogResultColor"/>
    <color name="searchDialogResultHighlightColor"/>

Advanced usage

The layout

I used this layout for simple search dialog but you can use anything else. Of course your layout should have thse two views :

  • An EditText to use as search key input
  • A RecyclerView for showing the results in it

The search dialog

You can use your custom layouts, adapters and search options by creating a class inheriting the BaseSearchDialogCompat take a look at SimpleSearchDialogCompat to see an example of how it can be done You should implement the BaseSearchDialogCompat methods :

    // handle your view with this one
    protected abstract void getView(View view);
    // Id of your custom layout
    @LayoutRes protected abstract int getLayoutResId();
    // Id of the search edittext you used in your custom layout
    @IdRes protected abstract int getSearchBoxId();
    // Id of the recyclerview you used in your custom layout
    @IdRes protected abstract int getRecyclerViewId();

The search filter

You can use your custom filters for text searching. The one used in SimpleSearchDialogCompat is SimpleSearchFilter. It checks the search key and if an item and the key had partially exact same letters it will add that item to results and also if the CheckLCS was set to true, it will check if the amount of matching letters was bigger than the given AccuracyPercentage the item will be added to results

The adapter

the one used in SimpleSearchDialogCompat is so simple despite its too long. the main functionality is in initializeViews method. you can create your custom adapters and use it instead of this one

The StringsHelper

it has two methods which you can use for highlighting the results.

/*
 * Returns a SpannableString with 
 * highlighted LCS(Longest Common Subsequence)
 * of two strings with the givven color
 */
SpannableStringBuilder highlightLCS(String text1, String text2, int highlightColor);

// Returns the LCS(Longest Common Subsequence) of two strings
String lcs(String text1, String text2) 

See the sample app to get a better understanding of the advanced usage

Used in sample app

Changelog

1.2.4 - Added an option to SimpleSearchDialogCompat so that the dialog cancellation on touching outside the dialog can be customized.

1.2.3 - Changed minSdkVersion to 14. Added getter for the title textview of simple search dialog. Improved results sorting.

1.2.2 - Gradle tools version and dependencies were updated.

1.2.1 - Added an option for changing text color and highlight color of default adapter.

1.2 - Added getter for views in simple search dialog and an option to turn off the auto filtering on search edittext.

1.1.1 - Fixes drawable overriding issue.

1.1 - Added loading feature.

Comments
  • not getting filtered

    not getting filtered

    Hi

    I implemented your library in my app which have a activity and tow tabs using tab layout view pager and fragment but everything is working right but the list not getting filtered while typing in search box I why this happen any clue

    opened by yoonusc 5
  • The library overrides the search icon

    The library overrides the search icon

    Hey.

    Thanks for your library!

    I have a search icon in my app with name "ic_search". When I use your library, my search icon is being replaced with the icon included in the library. I guess you just need to add a prefix, like: search_dialog_ic_search.png.

    opened by alashow 5
  • Proguard

    Proguard

    i have implement this library in my entire project. but i have also added proguard in app.

    When i used sign apk it's not working...

    Can you please share proguard rules for that .

    Waiting for your quick replay.

    Thanks

    opened by ghost 3
  • Optional parameter to define whether touching the title closes the dialog or not

    Optional parameter to define whether touching the title closes the dialog or not

    Hello, this function would be perfect if you make it optional since it is uncomfortable for some users with large fingers, many times they close the dialogue by accident

    view.findViewById(R.id.dummy_background) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dismiss(); } });

    opened by juandfranco 3
  • How can I change row layout inside recyclerview?

    How can I change row layout inside recyclerview?

    I want to change the row layout of RecyclerView. I want to display more data instead of "title", Can you suggest me how can I change that layout?

    opened by pratikbutani 2
  • change the search dialog item's view/layout

    change the search dialog item's view/layout

    Hi

    I am new to android , Recently I used your search dialog and it is really amazing. but the problem is less documentation. the top pictures describes it can be done in many views. But i cant understand how to do it. Ex: adding images to the layout. And also cant make the position of the dialog

    Can you help me.

    Thanks

    opened by lahirudb 2
  • How do I change list item(Arraylist) specific  text color

    How do I change list item(Arraylist) specific text color

    Hello,

    First, thank you for this good library.

    I populate the list from the database(sqlite). I just want to change the color of some items value. For example; one of value from database is "RED" at the same time I should change that index text color to red. How can i do this.

    opened by molekulyazilim 1
  • Highlighting Position Issue

    Highlighting Position Issue

    There is a highlighting position issue. If you search for a whole word, it will start highlighting where it can find the first letter, doesn't matter where the word. In this example, I'm searching for dengue, it will mark the first d in the first word, the e in the second word, and the rest of the letters are found in the correct word: Screenshot_20210619-144022

    opened by ChrisSantiago82 0
  • Title is under search bar

    Title is under search bar

    The issue is that the title is not on top of the search bar like it should. I don't know why it occurs, but this issue is present in the latest version, but in version 1.1, it works correctly.

    On Version 1.2.4:

    Version_1_2_4

    Whereas on Version 1.1:

    Version_1_1

    opened by Amark18 0
Owner
Mad Mirrajabi
Awesome developer!
Mad Mirrajabi
Alert Dialog - You can use this extension instead of creating a separate Alert Dialog for each Activity or Fragment.

We show a warning message (Alert Dialog) to the user in many parts of our applications. You can use this extension instead of creating a separate Alert Dialog for each Activity or Fragment. Thanks to this extension, you can create a Dialog and call it in the Activity or Fragment you want and customize the component you want.

Gökmen Bayram 0 Jan 9, 2022
Android has a built in microphone through which you can capture audio and store it , or play it in your phone. There are many ways to do that but with this dialog you can do all thats with only one dialog.

# Media Recorder Dialog ![](https://img.shields.io/badge/Platform-Android-brightgreen.svg) ![](https://img.shields.io/badge/Android-CustomView-blue.sv

Abdullah Alhazmy 73 Nov 29, 2022
ionalert 1.3 1.6 Java Sweetalert, Dialog, Alert Dialog

ionalert - Android Alert Dialog A beautiful design Android Alert Dialog, alternative of Sweet Alert Dialog based on KAlertDialog using MaterialCompone

Excel Dwi Oktavianto 23 Sep 17, 2022
An beautiful and easy to use dialog library for Android

An beautiful and easy to use dialog library for Android

ShouHeng 22 Nov 8, 2022
[Deprecated] This project can make it easy to theme and custom Android's dialog. Also provides Holo and Material themes for old devices.

Deprecated Please use android.support.v7.app.AlertDialog of support-v7. AlertDialogPro Why AlertDialogPro? Theming Android's AlertDialog is not an eas

Feng Dai 468 Nov 10, 2022
AlertDialog for Android, a beautiful and material alert dialog to use in your android app.

AlertDialog for Android, a beautiful and material alert dialog to use in your android app. Older verion of this library has been removed

Akshay Masram 124 Dec 28, 2022
Advanced dialog solution for android

DialogPlus Simple and advanced dialog solution. Uses normal view as dialog Provides expandable option Multiple positioning Built-in options for easy i

Orhan Obut 5k Dec 29, 2022
SweetAlert for Android, a beautiful and clever alert dialog

Sweet Alert Dialog SweetAlert for Android, a beautiful and clever alert dialog 中文版 Inspired by JavaScript SweetAlert Demo Download ScreenShot Setup Th

书呆子 7.3k Dec 30, 2022
An Android Dialog Lib simplify customization.

FlycoDialog-Master 中文版 An Android Dialog Lib simplify customization. Supprot 2.2+. Features [Built-in Dialog, convenient to use](#Built-in Dialog) [Ab

Flyco 2.3k Dec 8, 2022
Android library to show "Rate this app" dialog

Android-RateThisApp Android-RateThisApp is an library to show "Rate this app" dialog. The library monitors the following status How many times is the

Keisuke Kobayashi 553 Nov 23, 2022
A simple file/ directory picker dialog for android

FileListerDialog FileListerDialog helps you to list and pick file/directory. Library is built for Android Getting Started Installing To use this libra

Yogesh S 446 Jan 7, 2023
a quick custom android dialog project

QustomDialog Qustom helps you make quick custom dialogs for Android. All this is, for the time being, is a way to make it easy to achieve the Holo loo

Daniel Smith 183 Nov 20, 2022
Android library that allows applications to add dialog-based slider widgets to their settings

Android Slider Preference Library Overview Slider represents a float between 0.0 and 1.0 Access with SliderPreference.getValue() or SharedPreferences.

Jay Petacat 135 Nov 29, 2022
An Android library for displaying a dialog where it presents new features in the app.

WhatIsNewDialog What is new dialog for Android is used for presenting new features in the the app. It can be used in the activity starts, from menu or

NonZeroApps 22 Aug 23, 2022
Android library to show "Rate this app" dialog

Android-RateThisApp Android-RateThisApp is an library to show "Rate this app" dialog. The library monitors the following status How many times is the

Keisuke Kobayashi 553 Nov 23, 2022
Common dialog fragments

Common dialog fragments

null 6 Aug 29, 2022
Custom Dialog

Custom Dialog use Lottie Dialog How To Use? If yow want specific lottie file you must put your assets to under app → src → main → assets folder Add li

DevHoony 16 Oct 10, 2022
Extremely useful library to validate EditText inputs whether by using just the validator for your custom view or using library's extremely resizable & customisable dialog

Extremely useful library for validating EditText inputs whether by using just the validator (OtpinVerification) for your custom view or using library's extremely resizable & customisable dialog (OtpinDialogCreator)

Ehma Ugbogo 17 Oct 25, 2022
A simple library to show custom dialog with animation in android

SmartDialog A simple library to show custom dialog in android Step 1. Add the JitPack repository to your build file allprojects { repositories {

claudysoft 9 Aug 18, 2022