Convert Figma logo to code with AI

KieronQuinn logoPersistentSearch

A clone of the Google Now/Maps/Play persistent search bar

2,005
425
2,005
28

Top Related Projects

Android Search View based on Material design guidelines.

2,232

Material You Search component for Android, SearchView

A search view that implements a floating search bar also known as persistent search

Material Design Search Bar for Android

A clone of the Google Now/Maps/Play persistent search bar

Quick Overview

PersistentSearch is an Android library that implements a persistent search bar similar to the one found in Google Now and Google Maps. It provides a customizable search interface that can be easily integrated into Android applications, offering a smooth transition between a search icon and an expanded search bar.

Pros

  • Easy integration with existing Android projects
  • Customizable appearance and behavior
  • Smooth animations for a polished user experience
  • Compatible with Android 4.0 (API level 14) and above

Cons

  • Limited documentation and examples
  • Not actively maintained (last update was in 2015)
  • May require additional work to adapt to modern Android development practices
  • Potential compatibility issues with newer Android versions

Code Examples

  1. Adding the PersistentSearch view to your layout:
<com.quinny898.library.persistentsearch.SearchBox
    android:id="@+id/searchbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />
  1. Initializing and customizing the SearchBox in your Activity:
SearchBox search = (SearchBox) findViewById(R.id.searchbox);
search.setLogoText("Search");
search.setMenuListener(new SearchBox.MenuListener(){
    @Override
    public void onMenuClick() {
        // Handle menu click
    }
});
  1. Adding search results and handling item selection:
search.addSearchable(new SearchResult("Item 1", getResources().getDrawable(R.drawable.ic_item1)));
search.setSearchListener(new SearchBox.SearchListener(){
    @Override
    public void onSearchOpened() {
        // Search opened
    }
    @Override
    public void onSearchCleared() {
        // Search cleared
    }
    @Override
    public void onSearchClosed() {
        // Search closed
    }
    @Override
    public void onSearchTermChanged(String term) {
        // Search term changed
    }
    @Override
    public void onSearch(String searchTerm) {
        // Search submitted
    }
    @Override
    public void onResultClick(SearchResult result) {
        // Result clicked
    }
});

Getting Started

  1. Add the library to your project's build.gradle file:
dependencies {
    implementation 'com.quinny898.library.persistentsearch:library:1.1.0'
}
  1. Add the SearchBox to your layout XML file:
<com.quinny898.library.persistentsearch.SearchBox
    android:id="@+id/searchbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
  1. Initialize and customize the SearchBox in your Activity:
SearchBox search = (SearchBox) findViewById(R.id.searchbox);
search.setLogoText("Search");
search.setSearchListener(new SearchBox.SearchListener() {
    // Implement search listener methods
});

Competitor Comparisons

Android Search View based on Material design guidelines.

Pros of MaterialSearchView

  • More customization options for the search view appearance
  • Includes built-in voice search functionality
  • Supports both toolbar and floating search views

Cons of MaterialSearchView

  • Less seamless integration with the action bar compared to PersistentSearch
  • May require more setup and configuration
  • Limited animation options for search view transitions

Code Comparison

PersistentSearch:

PersistentSearchView searchView = (PersistentSearchView) findViewById(R.id.searchview);
searchView.setOnSearchListener(new PersistentSearchView.OnSearchListener() {
    @Override
    public void onSearchOpened() {
        // Search opened
    }
});

MaterialSearchView:

MaterialSearchView searchView = (MaterialSearchView) findViewById(R.id.search_view);
searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextSubmit(String query) {
        // Handle search query
        return false;
    }
});

Both libraries offer easy-to-use search functionality for Android applications. PersistentSearch focuses on seamless integration with the action bar and smooth animations, while MaterialSearchView provides more customization options and additional features like voice search. The choice between the two depends on specific project requirements and desired user experience.

2,232

Material You Search component for Android, SearchView

Pros of Search

  • More comprehensive search functionality with multiple search types (toolbar, dialog, floating)
  • Extensive customization options for appearance and behavior
  • Active development with frequent updates and bug fixes

Cons of Search

  • Larger codebase may be more complex to integrate and maintain
  • Potentially higher resource usage due to additional features

Code Comparison

PersistentSearch:

public class PersistentSearchView extends FrameLayout {
    private EditText mSearchEditText;
    private ImageView mSearchIcon;
    private ImageView mMicIcon;
    private ImageView mClearIcon;
}

Search:

public class SearchView extends FrameLayout implements View.OnClickListener {
    private CardView mCardView;
    private LinearLayout mLinearLayout;
    private ImageView mImageViewLogo;
    private EditText mEditText;
    private ImageView mImageViewMic;
}

Summary

PersistentSearch focuses on providing a simple, persistent search bar, while Search offers a more feature-rich and customizable search experience. PersistentSearch may be easier to implement for basic search functionality, but Search provides more options for advanced use cases and UI customization. The code comparison shows that Search includes additional UI elements like a CardView and logo, reflecting its broader feature set.

A search view that implements a floating search bar also known as persistent search

Pros of FloatingSearchView

  • More customizable UI with built-in suggestions and filters
  • Supports voice search functionality out of the box
  • Actively maintained with recent updates and bug fixes

Cons of FloatingSearchView

  • Larger library size and potentially higher resource usage
  • Steeper learning curve due to more complex implementation
  • Less native Android look and feel compared to PersistentSearch

Code Comparison

FloatingSearchView:

mSearchView = findViewById(R.id.floating_search_view);
mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {
    @Override
    public void onSearchTextChanged(String oldQuery, String newQuery) {
        // Handle search query changes
    }
});

PersistentSearch:

PersistentSearchView searchView = findViewById(R.id.persistentSearchView);
searchView.setOnSearchListener(new PersistentSearchView.OnSearchListener() {
    @Override
    public void onSearchOpened() {
        // Handle search opened
    }
});

Both libraries offer search functionality for Android applications, but FloatingSearchView provides more advanced features and customization options at the cost of complexity and resource usage. PersistentSearch offers a simpler, more native-looking implementation that may be sufficient for basic search needs.

Material Design Search Bar for Android

Pros of MaterialSearchBar

  • More customizable appearance with various styling options
  • Includes additional features like voice search and suggestions
  • Actively maintained with recent updates

Cons of MaterialSearchBar

  • Larger library size, potentially impacting app performance
  • Steeper learning curve due to more complex implementation

Code Comparison

MaterialSearchBar:

MaterialSearchBar searchBar = findViewById(R.id.searchBar);
searchBar.setHint("Search");
searchBar.setOnSearchActionListener(new MaterialSearchBar.OnSearchActionListener() {
    @Override
    public void onSearchStateChanged(boolean enabled) {
        // Handle search state change
    }
});

PersistentSearch:

PersistentSearchView searchView = findViewById(R.id.searchView);
searchView.setOnSearchListener(new PersistentSearchView.OnSearchListener() {
    @Override
    public void onSearchOpened() {
        // Handle search opened
    }
});

Summary

MaterialSearchBar offers more features and customization options, making it suitable for complex search implementations. However, this comes at the cost of a larger library size and potentially more complex setup. PersistentSearch, while simpler, may be more suitable for basic search functionality with a focus on performance and ease of implementation.

A clone of the Google Now/Maps/Play persistent search bar

Pros of PersistentSearch

  • Identical functionality and features
  • Same codebase and implementation
  • Consistent user experience

Cons of PersistentSearch

  • No unique advantages over the other repository
  • Potential confusion due to duplicate repositories
  • Redundant maintenance efforts

Code Comparison

Both repositories contain identical code, so there are no differences to highlight. Here's a sample from both:

class PersistentSearchView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

    private var searchBox: EditText? = null
    private var logo: ImageView? = null
    private var micButton: ImageView? = null
    private var searchButton: ImageView? = null

This code snippet is present in both repositories, demonstrating their identical nature.

Summary

The comparison between PersistentSearch and PersistentSearch reveals that they are essentially the same repository. There are no significant differences in terms of functionality, features, or codebase. This situation might lead to confusion for users and developers, as well as unnecessary duplication of efforts in maintenance and updates. It would be beneficial to consolidate these repositories or clarify the purpose of having two identical projects.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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

GIF of its use

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.