All Projects → mars885 → Persistent Search View

mars885 / Persistent Search View

Licence: apache-2.0
An Android library designed to simplify the process of implementing search-related functionality.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Persistent Search View

Algoliasearch Netlify
Official Algolia Plugin for Netlify. Index your website to Algolia when deploying your project to Netlify with the Algolia Crawler
Stars: ✭ 208 (-10.34%)
Mutual labels:  search
Angular Instantsearch
⚡️Lightning-fast search for Angular apps, by Algolia
Stars: ✭ 219 (-5.6%)
Mutual labels:  search
Grab
experimental and very fast implementation of a grep
Stars: ✭ 230 (-0.86%)
Mutual labels:  search
Scout
RESTful search server written in Python, powered by SQLite.
Stars: ✭ 213 (-8.19%)
Mutual labels:  search
Search Engine Parser
Lightweight package to query popular search engines and scrape for result titles, links and descriptions
Stars: ✭ 216 (-6.9%)
Mutual labels:  search
Sitedorks
Search Google/Bing/Ecosia/DuckDuckGo/Yandex/Yahoo for a search term with a default set of websites, bug bounty programs or a custom collection.
Stars: ✭ 221 (-4.74%)
Mutual labels:  search
Book Elastic Search In Action
Elastic 搜索开发实战
Stars: ✭ 205 (-11.64%)
Mutual labels:  search
Elastix
A simple Elasticsearch REST client written in Elixir.
Stars: ✭ 231 (-0.43%)
Mutual labels:  search
Hiddensearchwithrecyclerview
Simple library to have a hidden/shown search bar
Stars: ✭ 220 (-5.17%)
Mutual labels:  search
Trinity
Trinity IR Infrastructure
Stars: ✭ 227 (-2.16%)
Mutual labels:  search
Tldrstory
AI-powered understanding of headlines and story text
Stars: ✭ 214 (-7.76%)
Mutual labels:  search
Fuzzysort
Fast SublimeText-like fuzzy search for JavaScript.
Stars: ✭ 2,569 (+1007.33%)
Mutual labels:  search
Scoper
Fuzzy and semantic search for captioned YouTube videos.
Stars: ✭ 225 (-3.02%)
Mutual labels:  search
Tntsearch
A fully featured full text search engine written in PHP
Stars: ✭ 2,693 (+1060.78%)
Mutual labels:  search
Amber
A code search / replace tool
Stars: ✭ 230 (-0.86%)
Mutual labels:  search
Shsearchbar
The search bar that doesn't suck.
Stars: ✭ 206 (-11.21%)
Mutual labels:  search
Bower Components
[DEPRECATED] Site to discover Bower components
Stars: ✭ 220 (-5.17%)
Mutual labels:  search
Image Match
🎇 Quickly search over billions of images
Stars: ✭ 2,662 (+1047.41%)
Mutual labels:  search
Search Omnifocus
Alfred workflow that allows free text searching of OmniFocus tasks
Stars: ✭ 231 (-0.43%)
Mutual labels:  search
Engine Mode
Minor mode for defining and querying search engines through Emacs.
Stars: ✭ 225 (-3.02%)
Mutual labels:  search

PersistentSearchView

An android library designed to simplify the process of implementing search-related functionality.

Platform Download Build Android Arsenal License

Contents

Demo (YouTube)

Getting Started

  1. Make sure that you've added the jcenter() repository to your top-level build.gradle file.
buildscript {
    //...
    repositories {
        //...
        jcenter()
    }
    //...
}
  1. Add the library dependency to your module-level build.gradle file.
ext {
    //...
    psvVersion = "1.1.3"
}

dependencies {
    //...
    implementation "com.paulrybitskyi.persistentsearchview:persistentsearchview:$psvVersion"
}
  1. Enable the jetifier and androidX support in the top-level gradle.properties file.
//...
android.enableJetifier=true
android.useAndroidX=true
//....
  1. Update your compileSdkVersion in the module-level build.gradle file to 29.
//...
android {
    //...
    compileSdkVersion 29
    //...
}
//...
  1. Update your com.android.support.appcompat.* dependency to the new androidx.appcompat.* alternative.
//...
dependencies {
    //...
    implementation "androidx.appcompat:appcompat:1.1.0"
    //...
}
//...
  1. If your targetSdk is 30 and you want to use the voice search feature, add these lines to your app's AndroidManifest.xml:
<manifest ...>

    //...
    <queries>
        <intent>
            <action android:name="android.speech.RecognitionService"/>
        </intent>
    </queries>
    //...

</manifest>
  1. Proceed with the implementation of your own search view.

Basic Implementation

Implementation of a PersistentSearchView with basic functionality involves 2 main steps - declaring a widget inside the XML file of your choice and configuring it in one of the Java/Kotlin classes.

Let's implement a PersistentSearchView with basic functionality by following the steps listed above:

  1. Declaring a widget inside the XML file.

    XML (click to expand)

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <!-- Other widgets here -->
    
        <com.paulrybitskyi.persistentsearchview.PersistentSearchView
            android:id="@+id/persistentSearchView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="4dp"
            android:paddingLeft="4dp"
            android:paddingStart="4dp"
            android:paddingRight="4dp"
            android:paddingEnd="4dp"/>
    
    </RelativeLayout>
    
  2. Configuring the widget in one of the Java/Kotlin classes.

    Kotlin (click to expand)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.demo_activity_layout)
    
        //...
    
        with(persistentSearchView) {
            setOnLeftBtnClickListener {
                // Handle the left button click
            }
            setOnClearInputBtnClickListener {
                // Handle the clear input button click
            }
    
            // Setting a delegate for the voice recognition input
            setVoiceRecognitionDelegate(VoiceRecognitionDelegate(this@DemoActivity))
    
            setOnSearchConfirmedListener { searchView, query ->
                // Handle a search confirmation. This is the place where you'd
                // want to perform a search against your data provider.
            }
    
            // Disabling the suggestions since they are unused in
            // the simple implementation
            setSuggestionsDisabled(true)
        }
    }
    
    
    //...
    
    
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
    
        // Calling the voice recognition delegate to properly handle voice input results
        VoiceRecognitionDelegate.handleResult(persistentSearchView, requestCode, resultCode, data)
    }
    
    Java (click to expand)

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.demo_activity_layout);
    
        //...
    
        persistentSearchView.setOnLeftBtnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View view) {
                // Handle the left button click
            }
    
        });
    
        persistentSearchView.setOnClearInputBtnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View view) {
                // Handle the clear input button click
            }
    
        });
    
        // Setting a delegate for the voice recognition input
        persistentSearchView.setVoiceRecognitionDelegate(new VoiceRecognitionDelegate(this));
    
        persistentSearchView.setOnSearchConfirmedListener(new OnSearchConfirmedListener() {
    
            @Override
            public void onSearchConfirmed(PersistentSearchView searchView, String query) {
                // Handle a search confirmation. This is the place where you'd
                // want to perform a search against your data provider.
            }
    
        });
    
        // Disabling the suggestions since they are unused in
        // the simple implementation
        persistentSearchView.setSuggestionsDisabled();
    }
    
    
    //...
    
    
    @Override
    protected fun onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    
        // Calling the voice recognition delegate to properly handle voice input results
        VoiceRecognitionDelegate.handleResult(persistentSearchView, requestCode, resultCode, data);
    }
    

Basic Recent Suggestions Implementation

Implementation of a PersistentSearchView with recent suggestions is pretty much the same as Basic Implementation with one exception: the view configuration.

In this implementation you'll need to provide a bit more configuration for the widget in order to show recent suggestions to the user, such as providing implementation for a couple of listeners as well as fetching suggestions from your data provider and setting them to the search view.

For example, here is the configuration of the widget with recent suggestions functionality:

Java (click to expand)

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.demo_activity_layout);

    //...

    persistentSearchView.setOnLeftBtnClickListener(new OnClickListener() {
        
        @Override
        public void onClick(View view) {
            // Handle the left button click
        }

    });

    persistentSearchView.setOnClearInputBtnClickListener(new OnClickListener() {
        
        @Override
        public void onClick(View view) {
            // Handle the clear input button click
        }

    });

    // Setting a delegate for the voice recognition input
    persistentSearchView.setVoiceRecognitionDelegate(new VoiceRecognitionDelegate(this));

    persistentSearchView.setOnSearchConfirmedListener(new OnSearchConfirmedListener() {

        @Override
        public void onSearchConfirmed(PersistentSearchView searchView, String query) {
            // Handle a search confirmation. This is the place where you'd
            // want to save a new query and perform a search against your
            // data provider.
        }

    });

    persistentSearchView.setOnSearchQueryChangeListener(new OnSearchQueryChangeListener() {
        
        @Override
        public void onSearchQueryChanged(PersistentSearchView searchView, String oldQuery, String newQuery) {
            // Handle a search query change. This is the place where you'd
            // want load new suggestions based on the newQuery parameter.
        }

    });

    persistentSearchView.setOnSuggestionChangeListener(new OnSuggestionChangeListener() {

        @Override
        public void onSuggestionPicked(SuggestionItem suggestion) {
            // Handle a suggestion pick event. This is the place where you'd
            // want to perform a search against your data provider.
        }

        @Override
        public void onSuggestionRemoved(SuggestionItem suggestion) {
            // Handle a suggestion remove event. This is the place where
            // you'd want to remove the suggestion from your data provider.
        }

    });
}
	

//...


@Override
public void onResume() {
    super.onResume();

    List<String> searchQueries = null;

    // Fetching the search queries from the data provider
    if(persistentSearchView.isInputQueryEmpty) {
        searchQueries = mDataProvider.getInitialSearchQueries();
    } else {
        searchQueries = mDataProvider.getSuggestionsForQuery(persistentSearchView.inputQuery);
    }

    // Converting them to recent suggestions and setting them to the widget
    persistentSearchView.setSuggestions(SuggestionCreationUtil.asRecentSearchSuggestions(searchQueries), false);
}

	
//...


@Override
protected fun onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Calling the voice recognition delegate to properly handle voice input results
    VoiceRecognitionDelegate.handleResult(persistentSearchView, requestCode, resultCode, data);
}
Kotlin (click to expand)

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.demo_activity_layout)

    //...

    with(persistentSearchView) {
        setOnLeftBtnClickListener {
            // Handle the left button click
        }
        setOnClearInputBtnClickListener {
            // Handle the clear input button click
        }

        // Setting a delegate for the voice recognition input
        setVoiceRecognitionDelegate(VoiceRecognitionDelegate(this@DemoActivity))

        setOnSearchConfirmedListener { searchView, query ->
            // Handle a search confirmation. This is the place where you'd
            // want to save a new query and perform a search against your
            // data provider.
        }

        setOnSearchQueryChangeListener { searchView, oldQuery, newQuery ->
            // Handle a search query change. This is the place where you'd
            // want load new suggestions based on the newQuery parameter.
        }

        setOnSuggestionChangeListener(object : OnSuggestionChangeListener {

            override fun onSuggestionPicked(suggestion: SuggestionItem) {
                // Handle a suggestion pick event. This is the place where you'd
                // want to perform a search against your data provider.
            }

            override fun onSuggestionRemoved(suggestion: SuggestionItem) {
                // Handle a suggestion remove event. This is the place where
                // you'd want to remove the suggestion from your data provider.
            }

        })
    }
}


//...


override fun onResume() {
    super.onResume()

    // Fetching the search queries from the data provider
    val searchQueries = if(persistentSearchView.isInputQueryEmpty) {
        mDataProvider.getInitialSearchQueries()
    } else {
        mDataProvider.getSuggestionsForQuery(persistentSearchView.inputQuery)
    }

    // Converting them to recent suggestions and setting them to the widget
    persistentSearchView.setSuggestions(SuggestionCreationUtil.asRecentSearchSuggestions(searchQueries), false)
}


//...


override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)

    // Calling the voice recognition delegate to properly handle voice input results
    VoiceRecognitionDelegate.handleResult(persistentSearchView, requestCode, resultCode, data)
}

Basic Regular Suggestions Implementation

Implementation of a PersistentSearchView with regular suggestions is identical to the Basic Recent Suggestions Implementation with one exception: suggestions creation method asRecentSearchSuggestions(searchQueries) should be replaced with asRegularSearchSuggestions(searchQueries).

Advanced Use

See the Sample app.

Difference between recent and regular suggestions

The difference between recent and regular suggestions is that a user can remove recent suggestions from the list while regular suggestions cannot be removed (there is no remove button on the regular suggestions).

For example, here are screenshots of recent suggestions compared to regular:

Recent Regular

Contribution

See the CONTRIBUTING.md file.

Hall of Fame

Owly

Using PersistentSearchView in your app and want it to get listed here? Email me at [email protected]!

License

PersistentSearchView is licensed under the Apache 2.0 License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].