All Projects → Ferfalk → Simplesearchview

Ferfalk / Simplesearchview

Licence: apache-2.0
A simple SearchView for Android based on Material Design

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Simplesearchview

Browser Base
Modern and feature-rich web browser base based on Electron
Stars: ✭ 2,417 (+988.74%)
Mutual labels:  material
Angular Material Design Lite
A tiny Angular wrapper for Material Design Lite
Stars: ✭ 203 (-8.56%)
Mutual labels:  material
Shrine Materialdesign2
implementation of Material Design 2 Shrine project
Stars: ✭ 215 (-3.15%)
Mutual labels:  material
Ngx Material File Input
File input for Angular Material form-field
Stars: ✭ 193 (-13.06%)
Mutual labels:  material
Iconshowcase Dashboard
A full-of-features, easy-to-customize, free and open source, Material Design dashboard for icon packs.
Stars: ✭ 197 (-11.26%)
Mutual labels:  material
Hubuntu Ui
Material Admin Dashboard Starter UI ( Ubuntu style ) - https://720kb.github.io/hubuntu-ui/
Stars: ✭ 207 (-6.76%)
Mutual labels:  material
Password Strength
Angular UI library to illustrate and validate a password's strength with material design - Angular V9 supported
Stars: ✭ 186 (-16.22%)
Mutual labels:  material
Material Admin
Free Material Admin Template
Stars: ✭ 219 (-1.35%)
Mutual labels:  material
Material Singleinputform
A single EditText instead of a classical form. Library that implements flavienlaurent's singleinputform
Stars: ✭ 202 (-9.01%)
Mutual labels:  material
Matblazor
Material Design components for Blazor and Razor Components
Stars: ✭ 2,599 (+1070.72%)
Mutual labels:  material
React Md
React material design - An accessible React component library built from the Material Design guidelines in Sass
Stars: ✭ 2,284 (+928.83%)
Mutual labels:  material
Materialcalendar
A Material design calendar inspired by the CalendarView of School Diary.
Stars: ✭ 196 (-11.71%)
Mutual labels:  material
Flutter Shapeofview
Give a custom shape to any flutter widget, Material Design 2 ready
Stars: ✭ 211 (-4.95%)
Mutual labels:  material
Covalent
Teradata UI Platform built on Angular Material
Stars: ✭ 2,230 (+904.5%)
Mutual labels:  material
Rplibs
Refs.cn 原型设计元件库,基于Axure RP 10/9/8,支持 Android、Apple、Windows、微信,移动、桌面平台的应用和网站原型设计。五年历程 2.6k+ star,感谢大家使用。
Stars: ✭ 2,622 (+1081.08%)
Mutual labels:  material
Vuetify Daterange Picker
The missing date range picker for Vuetify JS you have been looking for.
Stars: ✭ 192 (-13.51%)
Mutual labels:  material
Android Switchicon
Google launcher-style implementation of switch (enable/disable) icon
Stars: ✭ 2,337 (+952.7%)
Mutual labels:  material
Material Backdrop
A simple solution for implementing Backdrop pattern for Android
Stars: ✭ 221 (-0.45%)
Mutual labels:  material
Aaf Easydiary
📘 A diary application optimized for user experience.
Stars: ✭ 216 (-2.7%)
Mutual labels:  material
Materialize Blog
redesign blog using material design
Stars: ✭ 212 (-4.5%)
Mutual labels:  material

SimpleSearchView

API Release Android Arsenal

A simple SearchView for Android based on Material Design

  • API 16+ (Reveal animation for API 21 and above, fade animation otherwise)
  • Two styles
  • Option to hide TabLayout automatically when it opens
  • Text and animations listeners
  • Customization options

Card sample        Bar sample

Download

Add the JitPack repository to the build.gradle file:

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

Add the Gradle dependency:

implementation 'com.github.Ferfalk:SimpleSearchView:0.1.6'

Usage

Add SimpleSearchView to your AppBarLayout:

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:theme="@style/AppTheme.AppBarOverlay">

    <FrameLayout
        android:id="@+id/toolbar_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:subtitle="@string/app_subtitle"
            app:title="Example" />

        <com.ferfalk.simplesearchview.SimpleSearchView
            android:id="@+id/searchView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimary" />
    </FrameLayout>

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

Setup with an MenuItem or Open manually

Setup the listener:
Return true to override default behaviour

simpleSearchView.setOnQueryTextListener(new SimpleSearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                Log.d("SimpleSearchView", "Submit:" + query);
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                Log.d("SimpleSearchView", "Text changed:" + newText);
                return false;
            }

            @Override
            public boolean onQueryTextCleared() {
                Log.d("SimpleSearchView", "Text cleared");
                return false;
            }
        });

Options

MenuItem

Open when the MenuItem is clicked
Add the search item to the menu xml:

<item
    android:id="@+id/action_search"
    android:icon="@drawable/ic_search_black_24dp"
    android:title="@string/search_hint"
    app:iconTint="@android:color/white"
    app:showAsAction="ifRoom" />

Setup the MenuItem :

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);

    MenuItem item = menu.findItem(R.id.action_search);
    searchView.setMenuItem(item);

    return true;
}

TabLayout

Hides the TabLayout when the SimpleSearchView opens
Add it to the layout with a TabLayout:

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:theme="@style/AppTheme.AppBarOverlay">

    <FrameLayout
        android:id="@+id/toolbar_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:subtitle="@string/app_subtitle"
            app:title="Example" />

        <com.ferfalk.simplesearchview.SimpleSearchView
            android:id="@+id/searchView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimary" />
    </FrameLayout>
  
    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="fixed">

        <android.support.design.widget.TabItem
            android:id="@+id/tabItem1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/tab_text_1" />

        <android.support.design.widget.TabItem
            android:id="@+id/tabItem2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/tab_text_2" />

        <android.support.design.widget.TabItem
            android:id="@+id/tabItem3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/tab_text_3" />

    </android.support.design.widget.TabLayout>

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

Setup the TabLayout:

simpleSearchView.setTabLayout(findViewById(R.id.tabLayout));

Open and close manually

simpleSearchView.showSearch();
simpleSearchView.closeSearch();

OnBackPressed

Closes the SimpleSearchView automatically

@Override
public void onBackPressed() {
    if (searchView.onBackPressed()) {
        return;
    }

    super.onBackPressed();
}

Voice search

app:voiceSearch="true"

or

simpleSearchView.enableVoiceSearch(true);

Handle the result:
Will set the query automatically

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (searchView.onActivityResult(requestCode, resultCode, data)) {
        return;
    }

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

Style

Bar style (default):

app:type="bar"

Card style:

app:type="card"

Open and close listener

simpleSearchView.setOnSearchViewListener(new SimpleSearchView.SearchViewListener() {
    @Override
    public void onSearchViewShown() {
        Log.d("SimpleSearchView", "onSearchViewShown");
    }

    @Override
    public void onSearchViewClosed() {
        Log.d("SimpleSearchView", "onSearchViewClosed");
    }

    @Override
    public void onSearchViewShownAnimation() {
        Log.d("SimpleSearchView", "onSearchViewShownAnimation");
    }

    @Override
    public void onSearchViewClosedAnimation() {
        Log.d("SimpleSearchView", "onSearchViewClosedAnimation");
    }
});

Changing the reveal animation starting point

// Adding padding to the animation because of the hidden menu item
Point revealCenter = simpleSearchView.getRevealAnimationCenter();
revealCenter.x -= DimensUtils.convertDpToPx(EXTRA_REVEAL_CENTER_PADDING, this);

Attributes

<style name="SimpleSearchViewStyle">
    <!-- Change search style -->
    <item name="type">card</item>

    <!-- Change search hint -->
    <item name="android:hint">Sample</item>

    <!-- Change search inputType -->
    <item name="android:inputType">text</item>

    <!-- Change search textColor -->
    <item name="android:textColor">@color/sample</item>

    <!-- Search bar/card background -->
    <item name="searchBackground">@drawable/sample</item>

    <!-- Change icons -->
    <item name="searchBackIcon">@drawable/sample</item>
    <item name="searchClearIcon">@drawable/sample</item>
    <item name="searchVoiceIcon">@drawable/sample</item>

    <!-- Change icons tint -->
    <item name="backIconTint">1</item>
    <item name="iconsTint">1</item>

    <!-- Change icons alpha -->
    <item name="backIconAlpha">0.8</item>
    <item name="iconsAlpha">0.8</item>

    <!-- Change search input colors -->
    <item name="cursorColor">@color/sample</item>
    <item name="hintColor">@color/sample</item>

    <!-- Enable voice search -->
    <item name="voiceSearch">true</item>

    <!-- Set voice search prompt -->
    <item name="voiceSearchPrompt">Sample</item>
</style>

License

Copyright (C) 2018 Fernando Augusto Heeren Falkiewicz

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.
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].