├── sample
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-nodpi
│ │ │ ├── avatar_jen.png
│ │ │ ├── avatar_moss.png
│ │ │ ├── avatar_roy.png
│ │ │ ├── avatar_denholm.png
│ │ │ ├── avatar_douglas.png
│ │ │ ├── avatar_internet.png
│ │ │ ├── avatar_richmond.png
│ │ │ └── avatar_industries.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ ├── colors_items.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ ├── colors_theme.xml
│ │ │ ├── themes.xml
│ │ │ ├── styles.xml
│ │ │ └── arrays.xml
│ │ ├── drawable
│ │ │ └── custom_cursor.xml
│ │ ├── layout
│ │ │ ├── fragment_dummy.xml
│ │ │ ├── activity_default.xml
│ │ │ ├── activity_sticky.xml
│ │ │ ├── activity_input_type.xml
│ │ │ ├── activity_colored.xml
│ │ │ ├── activity_voice.xml
│ │ │ ├── activity_appbarlayout.xml
│ │ │ ├── activity_main.xml
│ │ │ └── mok_items.xml
│ │ └── menu
│ │ │ └── menu_main.xml
│ │ ├── java
│ │ └── com
│ │ │ └── miguelcatalan
│ │ │ └── materialsearchview
│ │ │ └── sample
│ │ │ ├── DummyFragment.java
│ │ │ ├── ViewPagerAdapter.java
│ │ │ ├── MainActivity.java
│ │ │ ├── StickyActivity.java
│ │ │ ├── VoiceActivity.java
│ │ │ ├── ColoredActivity.java
│ │ │ ├── InputTypeActivity.java
│ │ │ ├── DefaultActivity.java
│ │ │ └── TabActivity.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── library
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── styles.xml
│ │ │ └── attrs.xml
│ │ ├── drawable-hdpi
│ │ │ ├── ic_suggestion.png
│ │ │ ├── ic_action_action_search.png
│ │ │ ├── ic_action_voice_search.png
│ │ │ ├── ic_action_navigation_close.png
│ │ │ ├── ic_action_navigation_arrow_back.png
│ │ │ ├── ic_action_voice_search_inverted.png
│ │ │ ├── ic_action_navigation_close_inverted.png
│ │ │ └── ic_action_navigation_arrow_back_inverted.png
│ │ ├── drawable-mdpi
│ │ │ ├── ic_suggestion.png
│ │ │ ├── ic_action_action_search.png
│ │ │ ├── ic_action_voice_search.png
│ │ │ ├── ic_action_navigation_close.png
│ │ │ ├── ic_action_navigation_arrow_back.png
│ │ │ ├── ic_action_voice_search_inverted.png
│ │ │ ├── ic_action_navigation_close_inverted.png
│ │ │ └── ic_action_navigation_arrow_back_inverted.png
│ │ ├── drawable-xhdpi
│ │ │ ├── ic_suggestion.png
│ │ │ ├── ic_action_voice_search.png
│ │ │ ├── ic_action_action_search.png
│ │ │ ├── ic_action_navigation_close.png
│ │ │ ├── ic_action_navigation_arrow_back.png
│ │ │ ├── ic_action_voice_search_inverted.png
│ │ │ ├── ic_action_navigation_close_inverted.png
│ │ │ └── ic_action_navigation_arrow_back_inverted.png
│ │ ├── drawable-xxhdpi
│ │ │ ├── ic_suggestion.png
│ │ │ ├── ic_action_action_search.png
│ │ │ ├── ic_action_voice_search.png
│ │ │ ├── ic_action_navigation_close.png
│ │ │ ├── ic_action_navigation_arrow_back.png
│ │ │ ├── ic_action_voice_search_inverted.png
│ │ │ ├── ic_action_navigation_close_inverted.png
│ │ │ └── ic_action_navigation_arrow_back_inverted.png
│ │ ├── drawable-xxxhdpi
│ │ │ ├── ic_suggestion.png
│ │ │ ├── ic_action_action_search.png
│ │ │ ├── ic_action_voice_search.png
│ │ │ ├── ic_action_navigation_close.png
│ │ │ ├── ic_action_navigation_arrow_back.png
│ │ │ ├── ic_action_voice_search_inverted.png
│ │ │ ├── ic_action_navigation_close_inverted.png
│ │ │ └── ic_action_navigation_arrow_back_inverted.png
│ │ ├── drawable
│ │ │ └── color_cursor_white.xml
│ │ ├── values-v21
│ │ │ └── styles.xml
│ │ └── layout
│ │ │ ├── suggest_item.xml
│ │ │ └── search_view.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── miguelcatalan
│ │ └── materialsearchview
│ │ ├── SearchAdapter.java
│ │ ├── utils
│ │ └── AnimationUtil.java
│ │ └── MaterialSearchView.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── art
├── default.gif
└── voice.gif
├── .gitignore
├── gradle.properties
├── README.md
└── LICENSE
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':library', ':sample'
2 |
--------------------------------------------------------------------------------
/art/default.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/art/default.gif
--------------------------------------------------------------------------------
/art/voice.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/art/voice.gif
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Search
3 |
4 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #50000000
4 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-nodpi/avatar_jen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/sample/src/main/res/drawable-nodpi/avatar_jen.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-nodpi/avatar_moss.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/sample/src/main/res/drawable-nodpi/avatar_moss.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-nodpi/avatar_roy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/sample/src/main/res/drawable-nodpi/avatar_roy.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_suggestion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-hdpi/ic_suggestion.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_suggestion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-mdpi/ic_suggestion.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_suggestion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xhdpi/ic_suggestion.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_suggestion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxhdpi/ic_suggestion.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_suggestion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxxhdpi/ic_suggestion.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-nodpi/avatar_denholm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/sample/src/main/res/drawable-nodpi/avatar_denholm.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-nodpi/avatar_douglas.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/sample/src/main/res/drawable-nodpi/avatar_douglas.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-nodpi/avatar_internet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/sample/src/main/res/drawable-nodpi/avatar_internet.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-nodpi/avatar_richmond.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/sample/src/main/res/drawable-nodpi/avatar_richmond.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-nodpi/avatar_industries.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/sample/src/main/res/drawable-nodpi/avatar_industries.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_action_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-hdpi/ic_action_action_search.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_action_voice_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-hdpi/ic_action_voice_search.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_action_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-mdpi/ic_action_action_search.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_action_voice_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-mdpi/ic_action_voice_search.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_action_voice_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xhdpi/ic_action_voice_search.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_action_navigation_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-hdpi/ic_action_navigation_close.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_action_navigation_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-mdpi/ic_action_navigation_close.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_action_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xhdpi/ic_action_action_search.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_action_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxhdpi/ic_action_action_search.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_action_voice_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxhdpi/ic_action_voice_search.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_action_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxxhdpi/ic_action_action_search.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_action_voice_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxxhdpi/ic_action_voice_search.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_action_navigation_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xhdpi/ic_action_navigation_close.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_action_navigation_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxhdpi/ic_action_navigation_close.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_action_navigation_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-hdpi/ic_action_navigation_arrow_back.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_action_voice_search_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-hdpi/ic_action_voice_search_inverted.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_action_navigation_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-mdpi/ic_action_navigation_arrow_back.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_action_voice_search_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-mdpi/ic_action_voice_search_inverted.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_action_navigation_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxxhdpi/ic_action_navigation_close.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_action_navigation_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xhdpi/ic_action_navigation_arrow_back.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_action_voice_search_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xhdpi/ic_action_voice_search_inverted.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_action_navigation_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxhdpi/ic_action_navigation_arrow_back.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_action_voice_search_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxhdpi/ic_action_voice_search_inverted.png
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_action_navigation_close_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-hdpi/ic_action_navigation_close_inverted.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_action_navigation_close_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-mdpi/ic_action_navigation_close_inverted.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_action_navigation_close_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xhdpi/ic_action_navigation_close_inverted.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_action_navigation_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxxhdpi/ic_action_navigation_arrow_back.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_action_voice_search_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxxhdpi/ic_action_voice_search_inverted.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_action_navigation_close_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxhdpi/ic_action_navigation_close_inverted.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_action_navigation_close_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxxhdpi/ic_action_navigation_close_inverted.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_action_navigation_arrow_back_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-hdpi/ic_action_navigation_arrow_back_inverted.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_action_navigation_arrow_back_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-mdpi/ic_action_navigation_arrow_back_inverted.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_action_navigation_arrow_back_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xhdpi/ic_action_navigation_arrow_back_inverted.png
--------------------------------------------------------------------------------
/library/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 12dp
4 | 65dp
5 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_action_navigation_arrow_back_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxhdpi/ic_action_navigation_arrow_back_inverted.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_action_navigation_arrow_back_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiguelCatalan/MaterialSearchView/HEAD/library/src/main/res/drawable-xxxhdpi/ic_action_navigation_arrow_back_inverted.png
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors_items.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ECECEC
4 | #222222
5 | #999999
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/custom_cursor.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/color_cursor_white.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/fragment_dummy.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
12 |
--------------------------------------------------------------------------------
/library/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/library/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MaterialSearchView
3 |
4 | ColoredActivity
5 | DefaultActivity
6 | VoiceActivity
7 | StickyActivity
8 | TabActivity
9 | InputTypeActivity
10 |
11 | Settings
12 |
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #Android generated
2 | bin
3 | gen
4 | lint.xml
5 | lint
6 |
7 | #Eclipse
8 | .project
9 | .classpath
10 | .settings
11 | .checkstyle
12 |
13 | #IntelliJ IDEA
14 | .idea
15 | *.iml
16 | *.ipr
17 | *.iws
18 | classes
19 | gen-external-apklibs
20 |
21 | #gradle
22 | .gradle
23 | local.properties
24 | gradlew
25 | gradlew.bat
26 | gradle/
27 | build/
28 |
29 | #vi
30 | *.swp
31 |
32 | #other editors
33 | *.bak
34 |
35 | #Maven
36 | target
37 | release.properties
38 | pom.xml.*
39 |
40 | #Ant
41 | build.xml
42 | ant.properties
43 | local.properties
44 | proguard.cfg
45 | proguard-project.txt
46 |
47 | #Other
48 | .DS_Store
49 | Thumbs.db
50 | tmp
51 | *.tgz
52 | *.lock
53 | *.lck
54 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/miguel/Android/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/miguel/Android/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.miguelcatalan.materialsearchview.sample"
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 6
12 | versionName "1.3.1"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile project(':library')
25 | compile 'com.android.support:appcompat-v7:23.1.0'
26 | compile 'com.android.support:design:23.1.0'
27 | }
28 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors_theme.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #2196F3
4 | #1976D2
5 | #BBDEFB
6 |
7 | #FFFFFF
8 | #212121
9 |
10 | #212121
11 |
12 | #99212121
13 |
14 | #212121
15 | #727272
16 | #ffffff
17 | #8affffff
18 | #FFFFFF
19 | #B6B6B6
20 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/sample/src/main/java/com/miguelcatalan/materialsearchview/sample/DummyFragment.java:
--------------------------------------------------------------------------------
1 | package com.miguelcatalan.materialsearchview.sample;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | /**
10 | * @author Miguel Catalan Bañuls
11 | */
12 | public class DummyFragment extends Fragment {
13 |
14 | public DummyFragment() {
15 | // Required empty public constructor
16 | }
17 |
18 | @Override
19 | public void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | }
22 |
23 | @Override
24 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
25 | Bundle savedInstanceState) {
26 | // Inflate the layout for this fragment
27 | return inflater.inflate(R.layout.fragment_dummy, container, false);
28 | }
29 | }
--------------------------------------------------------------------------------
/library/src/main/res/layout/suggest_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
16 |
17 |
27 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | buildscript {
5 | repositories {
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.novoda:bintray-release:0.3.4'
10 | }
11 | }
12 |
13 | android {
14 | compileSdkVersion 23
15 | buildToolsVersion "23.0.1"
16 |
17 | defaultConfig {
18 | minSdkVersion 14
19 | targetSdkVersion 23
20 | versionCode 1
21 | versionName "1.4.0"
22 | }
23 | buildTypes {
24 | release {
25 | minifyEnabled false
26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
27 | }
28 | }
29 | }
30 |
31 | dependencies {
32 | compile fileTree(dir: 'libs', include: ['*.jar'])
33 | compile 'com.android.support:appcompat-v7:23.1.1'
34 | compile 'com.android.support:design:23.1.1'
35 | }
36 |
37 | publish {
38 | userOrg = 'miguelcatalan'
39 | groupId = 'com.miguelcatalan'
40 | artifactId = 'materialsearchview'
41 | publishVersion = '1.4.0'
42 | desc = 'Cute library to implement SearchView in a Material Design Approach'
43 | website = 'https://github.com/MiguelCatalan/MaterialSearchView'
44 | }
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_default.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
12 |
13 |
14 |
18 |
19 |
24 |
25 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_sticky.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
12 |
13 |
14 |
18 |
19 |
24 |
25 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/miguelcatalan/materialsearchview/sample/ViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.miguelcatalan.materialsearchview.sample;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentPagerAdapter;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | /**
11 | * @author Miguel Catalan Bañuls
12 | */
13 | class ViewPagerAdapter extends FragmentPagerAdapter {
14 | private final List mFragmentList = new ArrayList<>();
15 | private final List mFragmentTitleList = new ArrayList<>();
16 |
17 | public ViewPagerAdapter(FragmentManager manager) {
18 | super(manager);
19 | }
20 |
21 | @Override
22 | public Fragment getItem(int position) {
23 | return mFragmentList.get(position);
24 | }
25 |
26 | @Override
27 | public int getCount() {
28 | return mFragmentList.size();
29 | }
30 |
31 | public void addFragment(Fragment fragment, String title) {
32 | mFragmentList.add(fragment);
33 | mFragmentTitleList.add(title);
34 | }
35 |
36 | @Override
37 | public CharSequence getPageTitle(int position) {
38 | return mFragmentTitleList.get(position);
39 | }
40 | }
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_input_type.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
12 |
13 |
14 |
18 |
19 |
24 |
25 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_colored.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
12 |
13 |
14 |
18 |
19 |
24 |
25 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_voice.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
12 |
13 |
14 |
18 |
19 |
24 |
25 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
31 |
32 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - A very very long suggestion that would span multiple lines.
5 | - Android
6 | - iOS
7 | - SCALA
8 | - Ruby
9 | - JavaScript
10 | - C#
11 | - Python
12 | - C
13 | - C++
14 | - PHP
15 | - Go
16 | - Perl
17 | - Bash
18 | - Lua
19 | - R
20 | - TCL
21 | - Haskell
22 | - Objective C
23 | - Swift
24 | - Kotlin
25 | - jQuery
26 | - Development
27 | - Web
28 | - Ajax
29 | - Test
30 | - Testing
31 | - CookBook
32 | - Beagle
33 | - VMware
34 | - Less.js
35 | - IDE
36 | - Arduino
37 | - Xamarin
38 | - UI
39 | - Microsoft
40 | - Application
41 | - Development
42 | - JUnit
43 | - SQL
44 | - Beagle
45 |
46 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
26 |
27 |
30 |
31 |
34 |
35 |
38 |
39 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_appbarlayout.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
14 |
15 |
16 |
21 |
22 |
26 |
27 |
32 |
33 |
38 |
39 |
40 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
9 |
10 |
15 |
16 |
22 |
23 |
29 |
30 |
36 |
37 |
43 |
44 |
50 |
51 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/miguelcatalan/materialsearchview/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.miguelcatalan.materialsearchview.sample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
10 |
11 | private Button defaultButton;
12 | private Button themedButton;
13 | private Button voiceButton;
14 | private Button stickyButton;
15 | private Button tabButton;
16 | private Button inputTypeButton;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 |
23 | defaultButton = (Button) findViewById(R.id.button_default);
24 | defaultButton.setOnClickListener(this);
25 | themedButton = (Button) findViewById(R.id.button_themed);
26 | themedButton.setOnClickListener(this);
27 | voiceButton = (Button) findViewById(R.id.button_voice);
28 | voiceButton.setOnClickListener(this);
29 | stickyButton = (Button) findViewById(R.id.button_sticky);
30 | stickyButton.setOnClickListener(this);
31 | tabButton = (Button) findViewById(R.id.button_tab);
32 | tabButton.setOnClickListener(this);
33 | inputTypeButton = (Button) findViewById(R.id.button_input_type);
34 | inputTypeButton.setOnClickListener(this);
35 | }
36 |
37 | @Override
38 | public void onClick(View view) {
39 | Intent intent = null;
40 | switch (view.getId()) {
41 | case R.id.button_default:
42 | intent = new Intent(this, DefaultActivity.class);
43 | break;
44 | case R.id.button_themed:
45 | intent = new Intent(this, ColoredActivity.class);
46 | break;
47 | case R.id.button_voice:
48 | intent = new Intent(this, VoiceActivity.class);
49 | break;
50 | case R.id.button_sticky:
51 | intent = new Intent(this, StickyActivity.class);
52 | break;
53 | case R.id.button_tab:
54 | intent = new Intent(this, TabActivity.class);
55 | break;
56 | case R.id.button_input_type:
57 | intent = new Intent(this, InputTypeActivity.class);
58 | break;
59 | }
60 | if (intent != null) {
61 | startActivity(intent);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/search_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
20 |
21 |
26 |
27 |
41 |
42 |
47 |
48 |
54 |
55 |
62 |
63 |
69 |
70 |
71 |
72 |
78 |
79 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/miguelcatalan/materialsearchview/sample/StickyActivity.java:
--------------------------------------------------------------------------------
1 | package com.miguelcatalan.materialsearchview.sample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.speech.RecognizerIntent;
6 | import android.support.design.widget.Snackbar;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 | import android.text.TextUtils;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 |
13 | import com.miguelcatalan.materialsearchview.MaterialSearchView;
14 |
15 | import java.util.ArrayList;
16 |
17 | public class StickyActivity extends AppCompatActivity {
18 |
19 | private MaterialSearchView searchView;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_sticky);
25 |
26 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
27 | setSupportActionBar(toolbar);
28 |
29 | searchView = (MaterialSearchView) findViewById(R.id.search_view);
30 | searchView.setVoiceSearch(false);
31 | searchView.setCursorDrawable(R.drawable.custom_cursor);
32 | searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
33 | @Override
34 | public boolean onQueryTextSubmit(String query) {
35 | Snackbar.make(findViewById(R.id.container), "Query: " + query, Snackbar.LENGTH_LONG)
36 | .show();
37 | return false;
38 | }
39 |
40 | @Override
41 | public boolean onQueryTextChange(String newText) {
42 | //Do some magic
43 | return false;
44 | }
45 | });
46 |
47 | searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
48 | @Override
49 | public void onSearchViewShown() {
50 | //Do some magic
51 | }
52 |
53 | @Override
54 | public void onSearchViewClosed() {
55 | //Do some magic
56 | }
57 | });
58 | }
59 |
60 | @Override
61 | public boolean onCreateOptionsMenu(Menu menu) {
62 | getMenuInflater().inflate(R.menu.menu_main, menu);
63 |
64 | MenuItem item = menu.findItem(R.id.action_search);
65 | searchView.setMenuItem(item);
66 |
67 | return true;
68 | }
69 |
70 | @Override
71 | public void onBackPressed() {
72 | if (searchView.isSearchOpen()) {
73 | searchView.closeSearch();
74 | } else {
75 | super.onBackPressed();
76 | }
77 | }
78 |
79 | @Override
80 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
81 | if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == RESULT_OK) {
82 | ArrayList matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
83 | if (matches != null && matches.size() > 0) {
84 | String searchWrd = matches.get(0);
85 | if (!TextUtils.isEmpty(searchWrd)) {
86 | searchView.setQuery(searchWrd, false);
87 | }
88 | }
89 |
90 | return;
91 | }
92 | super.onActivityResult(requestCode, resultCode, data);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/miguelcatalan/materialsearchview/sample/VoiceActivity.java:
--------------------------------------------------------------------------------
1 | package com.miguelcatalan.materialsearchview.sample;
2 |
3 | import android.content.Intent;
4 | import android.speech.RecognizerIntent;
5 | import android.support.design.widget.Snackbar;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.support.v7.widget.Toolbar;
9 | import android.text.TextUtils;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 |
13 | import com.miguelcatalan.materialsearchview.MaterialSearchView;
14 |
15 | import java.util.ArrayList;
16 |
17 | public class VoiceActivity extends AppCompatActivity {
18 |
19 | private MaterialSearchView searchView;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_voice);
25 |
26 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
27 | setSupportActionBar(toolbar);
28 |
29 | searchView = (MaterialSearchView) findViewById(R.id.search_view);
30 | searchView.setVoiceSearch(true);
31 | searchView.setCursorDrawable(R.drawable.color_cursor_white);
32 | searchView.setSuggestions(getResources().getStringArray(R.array.query_suggestions));
33 | searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
34 | @Override
35 | public boolean onQueryTextSubmit(String query) {
36 | Snackbar.make(findViewById(R.id.container), "Query: " + query, Snackbar.LENGTH_LONG)
37 | .show();
38 | return false;
39 | }
40 |
41 | @Override
42 | public boolean onQueryTextChange(String newText) {
43 | //Do some magic
44 | return false;
45 | }
46 | });
47 |
48 | searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
49 | @Override
50 | public void onSearchViewShown() {
51 | //Do some magic
52 | }
53 |
54 | @Override
55 | public void onSearchViewClosed() {
56 | //Do some magic
57 | }
58 | });
59 | }
60 |
61 | @Override
62 | public boolean onCreateOptionsMenu(Menu menu) {
63 | getMenuInflater().inflate(R.menu.menu_main, menu);
64 |
65 | MenuItem item = menu.findItem(R.id.action_search);
66 | searchView.setMenuItem(item);
67 |
68 | return true;
69 | }
70 |
71 | @Override
72 | public void onBackPressed() {
73 | if (searchView.isSearchOpen()) {
74 | searchView.closeSearch();
75 | } else {
76 | super.onBackPressed();
77 | }
78 | }
79 |
80 | @Override
81 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
82 | if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == RESULT_OK) {
83 | ArrayList matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
84 | if (matches != null && matches.size() > 0) {
85 | String searchWrd = matches.get(0);
86 | if (!TextUtils.isEmpty(searchWrd)) {
87 | searchView.setQuery(searchWrd, false);
88 | }
89 | }
90 |
91 | return;
92 | }
93 | super.onActivityResult(requestCode, resultCode, data);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/miguelcatalan/materialsearchview/sample/ColoredActivity.java:
--------------------------------------------------------------------------------
1 | package com.miguelcatalan.materialsearchview.sample;
2 |
3 | import android.content.Intent;
4 | import android.speech.RecognizerIntent;
5 | import android.support.design.widget.Snackbar;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.support.v7.widget.Toolbar;
9 | import android.text.TextUtils;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 |
13 | import com.miguelcatalan.materialsearchview.MaterialSearchView;
14 |
15 | import java.util.ArrayList;
16 |
17 | public class ColoredActivity extends AppCompatActivity {
18 |
19 | private MaterialSearchView searchView;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_colored);
25 |
26 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
27 | setSupportActionBar(toolbar);
28 |
29 | searchView = (MaterialSearchView) findViewById(R.id.search_view);
30 | searchView.setVoiceSearch(false);
31 | searchView.setCursorDrawable(R.drawable.color_cursor_white);
32 | searchView.setSuggestions(getResources().getStringArray(R.array.query_suggestions));
33 | searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
34 | @Override
35 | public boolean onQueryTextSubmit(String query) {
36 | Snackbar.make(findViewById(R.id.container), "Query: " + query, Snackbar.LENGTH_LONG)
37 | .show();
38 | return false;
39 | }
40 |
41 | @Override
42 | public boolean onQueryTextChange(String newText) {
43 | //Do some magic
44 | return false;
45 | }
46 | });
47 |
48 | searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
49 | @Override
50 | public void onSearchViewShown() {
51 | //Do some magic
52 | }
53 |
54 | @Override
55 | public void onSearchViewClosed() {
56 | //Do some magic
57 | }
58 | });
59 | }
60 |
61 | @Override
62 | public boolean onCreateOptionsMenu(Menu menu) {
63 | getMenuInflater().inflate(R.menu.menu_main, menu);
64 |
65 | MenuItem item = menu.findItem(R.id.action_search);
66 | searchView.setMenuItem(item);
67 |
68 | return true;
69 | }
70 |
71 | @Override
72 | public void onBackPressed() {
73 | if (searchView.isSearchOpen()) {
74 | searchView.closeSearch();
75 | } else {
76 | super.onBackPressed();
77 | }
78 | }
79 |
80 | @Override
81 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
82 | if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == RESULT_OK) {
83 | ArrayList matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
84 | if (matches != null && matches.size() > 0) {
85 | String searchWrd = matches.get(0);
86 | if (!TextUtils.isEmpty(searchWrd)) {
87 | searchView.setQuery(searchWrd, false);
88 | }
89 | }
90 |
91 | return;
92 | }
93 | super.onActivityResult(requestCode, resultCode, data);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/miguelcatalan/materialsearchview/sample/InputTypeActivity.java:
--------------------------------------------------------------------------------
1 | package com.miguelcatalan.materialsearchview.sample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.speech.RecognizerIntent;
6 | import android.support.design.widget.Snackbar;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 | import android.text.TextUtils;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 | import com.miguelcatalan.materialsearchview.MaterialSearchView;
13 | import java.util.ArrayList;
14 |
15 | public class InputTypeActivity extends AppCompatActivity {
16 |
17 | private MaterialSearchView searchView;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_input_type);
23 |
24 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
25 | setSupportActionBar(toolbar);
26 |
27 | searchView = (MaterialSearchView) findViewById(R.id.search_view);
28 | searchView.setVoiceSearch(false);
29 | searchView.setCursorDrawable(R.drawable.custom_cursor);
30 | searchView.setEllipsize(true);
31 | searchView.setSuggestions(getResources().getStringArray(R.array.query_suggestions));
32 | searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
33 | @Override
34 | public boolean onQueryTextSubmit(String query) {
35 | Snackbar.make(findViewById(R.id.container), "Query: " + query, Snackbar.LENGTH_LONG)
36 | .show();
37 | return false;
38 | }
39 |
40 | @Override
41 | public boolean onQueryTextChange(String newText) {
42 | //Do some magic
43 | return false;
44 | }
45 | });
46 |
47 | searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
48 | @Override
49 | public void onSearchViewShown() {
50 | //Do some magic
51 | }
52 |
53 | @Override
54 | public void onSearchViewClosed() {
55 | //Do some magic
56 | }
57 | });
58 | }
59 |
60 | @Override
61 | public boolean onCreateOptionsMenu(Menu menu) {
62 | getMenuInflater().inflate(R.menu.menu_main, menu);
63 |
64 | MenuItem item = menu.findItem(R.id.action_search);
65 | searchView.setMenuItem(item);
66 |
67 | return true;
68 | }
69 |
70 | @Override
71 | public void onBackPressed() {
72 | if (searchView.isSearchOpen()) {
73 | searchView.closeSearch();
74 | } else {
75 | super.onBackPressed();
76 | }
77 | }
78 |
79 | @Override
80 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
81 | if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == RESULT_OK) {
82 | ArrayList matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
83 | if (matches != null && matches.size() > 0) {
84 | String searchWrd = matches.get(0);
85 | if (!TextUtils.isEmpty(searchWrd)) {
86 | searchView.setQuery(searchWrd, false);
87 | }
88 | }
89 |
90 | return;
91 | }
92 | super.onActivityResult(requestCode, resultCode, data);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/miguelcatalan/materialsearchview/sample/DefaultActivity.java:
--------------------------------------------------------------------------------
1 | package com.miguelcatalan.materialsearchview.sample;
2 |
3 | import android.content.Intent;
4 | import android.speech.RecognizerIntent;
5 | import android.support.design.widget.Snackbar;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.support.v7.widget.Toolbar;
9 | import android.text.TextUtils;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 |
13 | import com.miguelcatalan.materialsearchview.MaterialSearchView;
14 |
15 | import java.util.ArrayList;
16 |
17 | public class DefaultActivity extends AppCompatActivity {
18 |
19 | private MaterialSearchView searchView;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_default);
25 |
26 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
27 | setSupportActionBar(toolbar);
28 |
29 | searchView = (MaterialSearchView) findViewById(R.id.search_view);
30 | searchView.setVoiceSearch(false);
31 | searchView.setCursorDrawable(R.drawable.custom_cursor);
32 | searchView.setEllipsize(true);
33 | searchView.setSuggestions(getResources().getStringArray(R.array.query_suggestions));
34 | searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
35 | @Override
36 | public boolean onQueryTextSubmit(String query) {
37 | Snackbar.make(findViewById(R.id.container), "Query: " + query, Snackbar.LENGTH_LONG)
38 | .show();
39 | return false;
40 | }
41 |
42 | @Override
43 | public boolean onQueryTextChange(String newText) {
44 | //Do some magic
45 | return false;
46 | }
47 | });
48 |
49 | searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
50 | @Override
51 | public void onSearchViewShown() {
52 | //Do some magic
53 | }
54 |
55 | @Override
56 | public void onSearchViewClosed() {
57 | //Do some magic
58 | }
59 | });
60 | }
61 |
62 | @Override
63 | public boolean onCreateOptionsMenu(Menu menu) {
64 | getMenuInflater().inflate(R.menu.menu_main, menu);
65 |
66 | MenuItem item = menu.findItem(R.id.action_search);
67 | searchView.setMenuItem(item);
68 |
69 | return true;
70 | }
71 |
72 | @Override
73 | public void onBackPressed() {
74 | if (searchView.isSearchOpen()) {
75 | searchView.closeSearch();
76 | } else {
77 | super.onBackPressed();
78 | }
79 | }
80 |
81 | @Override
82 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
83 | if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == RESULT_OK) {
84 | ArrayList matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
85 | if (matches != null && matches.size() > 0) {
86 | String searchWrd = matches.get(0);
87 | if (!TextUtils.isEmpty(searchWrd)) {
88 | searchView.setQuery(searchWrd, false);
89 | }
90 | }
91 |
92 | return;
93 | }
94 | super.onActivityResult(requestCode, resultCode, data);
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/miguelcatalan/materialsearchview/sample/TabActivity.java:
--------------------------------------------------------------------------------
1 | package com.miguelcatalan.materialsearchview.sample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.speech.RecognizerIntent;
6 | import android.support.design.widget.Snackbar;
7 | import android.support.design.widget.TabLayout;
8 | import android.support.v4.view.ViewPager;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.support.v7.widget.Toolbar;
11 | import android.text.TextUtils;
12 | import android.view.Menu;
13 | import android.view.MenuItem;
14 |
15 | import com.miguelcatalan.materialsearchview.MaterialSearchView;
16 |
17 | import java.util.ArrayList;
18 |
19 | public class TabActivity extends AppCompatActivity {
20 |
21 | private MaterialSearchView searchView;
22 | private ViewPager viewPager;
23 | private TabLayout tabLayout;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_appbarlayout);
29 |
30 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
31 | setSupportActionBar(toolbar);
32 |
33 | viewPager = (ViewPager) findViewById(R.id.viewpager);
34 | setupViewPager(viewPager);
35 |
36 | tabLayout = (TabLayout) findViewById(R.id.tabs);
37 | tabLayout.setupWithViewPager(viewPager);
38 |
39 | searchView = (MaterialSearchView) findViewById(R.id.search_view);
40 | searchView.setVoiceSearch(false);
41 | searchView.setCursorDrawable(R.drawable.custom_cursor);
42 | searchView.setSuggestions(getResources().getStringArray(R.array.query_suggestions));
43 | searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
44 | @Override
45 | public boolean onQueryTextSubmit(String query) {
46 | Snackbar.make(findViewById(R.id.container), "Query: " + query, Snackbar.LENGTH_LONG)
47 | .show();
48 | return false;
49 | }
50 |
51 | @Override
52 | public boolean onQueryTextChange(String newText) {
53 | //Do some magic
54 | return false;
55 | }
56 | });
57 |
58 | searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
59 | @Override
60 | public void onSearchViewShown() {
61 | //Do some magic
62 | }
63 |
64 | @Override
65 | public void onSearchViewClosed() {
66 | //Do some magic
67 | }
68 | });
69 | }
70 |
71 | private void setupViewPager(ViewPager viewPager) {
72 | ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
73 | adapter.addFragment(new DummyFragment(), "ONE");
74 | adapter.addFragment(new DummyFragment(), "TWO");
75 | viewPager.setAdapter(adapter);
76 | }
77 |
78 | @Override
79 | public boolean onCreateOptionsMenu(Menu menu) {
80 | getMenuInflater().inflate(R.menu.menu_main, menu);
81 |
82 | MenuItem item = menu.findItem(R.id.action_search);
83 | searchView.setMenuItem(item);
84 |
85 | return true;
86 | }
87 |
88 | @Override
89 | public void onBackPressed() {
90 | if (searchView.isSearchOpen()) {
91 | searchView.closeSearch();
92 | } else {
93 | super.onBackPressed();
94 | }
95 | }
96 |
97 | @Override
98 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
99 | if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == RESULT_OK) {
100 | ArrayList matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
101 | if (matches != null && matches.size() > 0) {
102 | String searchWrd = matches.get(0);
103 | if (!TextUtils.isEmpty(searchWrd)) {
104 | searchView.setQuery(searchWrd, false);
105 | }
106 | }
107 |
108 | return;
109 | }
110 | super.onActivityResult(requestCode, resultCode, data);
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/library/src/main/java/com/miguelcatalan/materialsearchview/SearchAdapter.java:
--------------------------------------------------------------------------------
1 | package com.miguelcatalan.materialsearchview;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 | import android.text.TextUtils;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.BaseAdapter;
10 | import android.widget.Filter;
11 | import android.widget.Filterable;
12 | import android.widget.ImageView;
13 | import android.widget.TextView;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | /**
19 | * Suggestions Adapter.
20 | *
21 | * @author Miguel Catalan Bañuls
22 | */
23 | public class SearchAdapter extends BaseAdapter implements Filterable {
24 |
25 | private ArrayList data;
26 | private String[] suggestions;
27 | private Drawable suggestionIcon;
28 | private LayoutInflater inflater;
29 | private boolean ellipsize;
30 |
31 | public SearchAdapter(Context context, String[] suggestions) {
32 | inflater = LayoutInflater.from(context);
33 | data = new ArrayList<>();
34 | this.suggestions = suggestions;
35 | }
36 |
37 | public SearchAdapter(Context context, String[] suggestions, Drawable suggestionIcon, boolean ellipsize) {
38 | inflater = LayoutInflater.from(context);
39 | data = new ArrayList<>();
40 | this.suggestions = suggestions;
41 | this.suggestionIcon = suggestionIcon;
42 | this.ellipsize = ellipsize;
43 | }
44 |
45 | @Override
46 | public Filter getFilter() {
47 | Filter filter = new Filter() {
48 | @Override
49 | protected FilterResults performFiltering(CharSequence constraint) {
50 | FilterResults filterResults = new FilterResults();
51 | if (!TextUtils.isEmpty(constraint)) {
52 |
53 | // Retrieve the autocomplete results.
54 | List searchData = new ArrayList<>();
55 |
56 | for (String string : suggestions) {
57 | if (string.toLowerCase().startsWith(constraint.toString().toLowerCase())) {
58 | searchData.add(string);
59 | }
60 | }
61 |
62 | // Assign the data to the FilterResults
63 | filterResults.values = searchData;
64 | filterResults.count = searchData.size();
65 | }
66 | return filterResults;
67 | }
68 |
69 | @Override
70 | protected void publishResults(CharSequence constraint, FilterResults results) {
71 | if (results.values != null) {
72 | data = (ArrayList) results.values;
73 | notifyDataSetChanged();
74 | }
75 | }
76 | };
77 | return filter;
78 | }
79 |
80 | @Override
81 | public int getCount() {
82 | return data.size();
83 | }
84 |
85 | @Override
86 | public Object getItem(int position) {
87 | return data.get(position);
88 | }
89 |
90 | @Override
91 | public long getItemId(int position) {
92 | return position;
93 | }
94 |
95 | @Override
96 | public View getView(int position, View convertView, ViewGroup parent) {
97 |
98 | SuggestionsViewHolder viewHolder;
99 |
100 | if (convertView == null) {
101 | convertView = inflater.inflate(R.layout.suggest_item, parent, false);
102 | viewHolder = new SuggestionsViewHolder(convertView);
103 | convertView.setTag(viewHolder);
104 | } else {
105 | viewHolder = (SuggestionsViewHolder) convertView.getTag();
106 | }
107 |
108 | String currentListData = (String) getItem(position);
109 |
110 | viewHolder.textView.setText(currentListData);
111 | if (ellipsize) {
112 | viewHolder.textView.setSingleLine();
113 | viewHolder.textView.setEllipsize(TextUtils.TruncateAt.END);
114 | }
115 |
116 | return convertView;
117 | }
118 |
119 | private class SuggestionsViewHolder {
120 |
121 | TextView textView;
122 | ImageView imageView;
123 |
124 | public SuggestionsViewHolder(View convertView) {
125 | textView = (TextView) convertView.findViewById(R.id.suggestion_text);
126 | if (suggestionIcon != null) {
127 | imageView = (ImageView) convertView.findViewById(R.id.suggestion_icon);
128 | imageView.setImageDrawable(suggestionIcon);
129 | }
130 | }
131 | }
132 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/miguelcatalan/materialsearchview/utils/AnimationUtil.java:
--------------------------------------------------------------------------------
1 | package com.miguelcatalan.materialsearchview.utils;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.annotation.TargetApi;
6 | import android.os.Build;
7 | import android.support.v4.view.ViewCompat;
8 | import android.support.v4.view.ViewPropertyAnimatorListener;
9 | import android.util.TypedValue;
10 | import android.view.View;
11 | import android.view.ViewAnimationUtils;
12 |
13 | /**
14 | * @author Miguel Catalan Bañuls
15 | */
16 | public class AnimationUtil {
17 |
18 | public static int ANIMATION_DURATION_SHORT = 150;
19 | public static int ANIMATION_DURATION_MEDIUM = 400;
20 | public static int ANIMATION_DURATION_LONG = 800;
21 |
22 | public interface AnimationListener {
23 | /**
24 | * @return true to override parent. Else execute Parent method
25 | */
26 | boolean onAnimationStart(View view);
27 |
28 | boolean onAnimationEnd(View view);
29 |
30 | boolean onAnimationCancel(View view);
31 | }
32 |
33 | public static void crossFadeViews(View showView, View hideView) {
34 | crossFadeViews(showView, hideView, ANIMATION_DURATION_SHORT);
35 | }
36 |
37 | public static void crossFadeViews(View showView, final View hideView, int duration) {
38 | fadeInView(showView, duration);
39 | fadeOutView(hideView, duration);
40 | }
41 |
42 | public static void fadeInView(View view) {
43 | fadeInView(view, ANIMATION_DURATION_SHORT);
44 | }
45 |
46 | public static void fadeInView(View view, int duration) {
47 | fadeInView(view, duration, null);
48 | }
49 |
50 | public static void fadeInView(View view, int duration, final AnimationListener listener) {
51 | view.setVisibility(View.VISIBLE);
52 | view.setAlpha(0f);
53 | ViewPropertyAnimatorListener vpListener = null;
54 |
55 | if (listener != null) {
56 | vpListener = new ViewPropertyAnimatorListener() {
57 | @Override
58 | public void onAnimationStart(View view) {
59 | if (!listener.onAnimationStart(view)) {
60 | view.setDrawingCacheEnabled(true);
61 | }
62 | }
63 |
64 | @Override
65 | public void onAnimationEnd(View view) {
66 | if (!listener.onAnimationEnd(view)) {
67 | view.setDrawingCacheEnabled(false);
68 | }
69 | }
70 |
71 | @Override
72 | public void onAnimationCancel(View view) {
73 | }
74 | };
75 | }
76 | ViewCompat.animate(view).alpha(1f).setDuration(duration).setListener(vpListener);
77 | }
78 |
79 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
80 | public static void reveal(final View view, final AnimationListener listener) {
81 | int cx = view.getWidth() - (int) TypedValue.applyDimension(
82 | TypedValue.COMPLEX_UNIT_DIP, 24, view.getResources().getDisplayMetrics());
83 | int cy = view.getHeight() / 2;
84 | int finalRadius = Math.max(view.getWidth(), view.getHeight());
85 |
86 | Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
87 | view.setVisibility(View.VISIBLE);
88 | anim.addListener(new AnimatorListenerAdapter() {
89 | @Override
90 | public void onAnimationStart(Animator animation) {
91 | listener.onAnimationStart(view);
92 | }
93 |
94 | @Override
95 | public void onAnimationEnd(Animator animation) {
96 | listener.onAnimationEnd(view);
97 | }
98 |
99 | @Override
100 | public void onAnimationCancel(Animator animation) {
101 | listener.onAnimationCancel(view);
102 | }
103 |
104 | @Override
105 | public void onAnimationRepeat(Animator animation) {
106 |
107 | }
108 | });
109 | anim.start();
110 | }
111 |
112 | public static void fadeOutView(View view) {
113 | fadeOutView(view, ANIMATION_DURATION_SHORT);
114 | }
115 |
116 | public static void fadeOutView(View view, int duration) {
117 | fadeOutView(view, duration, null);
118 | }
119 |
120 | public static void fadeOutView(View view, int duration, final AnimationListener listener) {
121 | ViewCompat.animate(view).alpha(0f).setDuration(duration).setListener(new ViewPropertyAnimatorListener() {
122 | @Override
123 | public void onAnimationStart(View view) {
124 | if (listener == null || !listener.onAnimationStart(view)) {
125 | view.setDrawingCacheEnabled(true);
126 | }
127 | }
128 |
129 | @Override
130 | public void onAnimationEnd(View view) {
131 | if (listener == null || !listener.onAnimationEnd(view)) {
132 | view.setVisibility(View.GONE);
133 | view.setDrawingCacheEnabled(false);
134 | }
135 | }
136 |
137 | @Override
138 | public void onAnimationCancel(View view) {
139 | }
140 | });
141 | }
142 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MaterialSearchView
2 | Cute library to implement SearchView in a Material Design Approach. *Works from Android API 14 (ICS) and above*.
3 |
4 |  
5 |
6 |
7 |
9 |
10 |
11 | #Native version
12 | Maybe it would be useful to take a look into the new official approach
13 | http://www.materialdoc.com/search-filter/
14 |
15 | # Usage
16 | **Add the dependencies to your gradle file:**
17 | ```javascript
18 | dependencies {
19 | compile 'com.miguelcatalan:materialsearchview:1.4.0'
20 | }
21 | ```
22 | **Add MaterialSearchView to your layout file along with the Toolbar** *(Add this block at the bottom of your layout, in order to display it over the rest of the view)*:
23 |
24 | ```xml
25 |
26 |
30 |
31 |
36 |
37 |
41 |
42 | ```
43 |
44 | **Add the search item into the menu file:**
45 | ```xml
46 |
52 | ```
53 | **Add define it in the *onCreateOptionsMenu*:**
54 | ```java
55 | @Override
56 | public boolean onCreateOptionsMenu(Menu menu) {
57 | getMenuInflater().inflate(R.menu.menu_main, menu);
58 |
59 | MenuItem item = menu.findItem(R.id.action_search);
60 | searchView.setMenuItem(item);
61 |
62 | return true;
63 | }
64 | ```
65 | **Set the listeners:**
66 | ```java
67 | MaterialSearchView searchView = (MaterialSearchView) findViewById(R.id.search_view);
68 | searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
69 | @Override
70 | public boolean onQueryTextSubmit(String query) {
71 | //Do some magic
72 | return false;
73 | }
74 |
75 | @Override
76 | public boolean onQueryTextChange(String newText) {
77 | //Do some magic
78 | return false;
79 | }
80 | });
81 |
82 | searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
83 | @Override
84 | public void onSearchViewShown() {
85 | //Do some magic
86 | }
87 |
88 | @Override
89 | public void onSearchViewClosed() {
90 | //Do some magic
91 | }
92 | });
93 | ```
94 | # Use VoiceSearch
95 | **Allow/Disable it in the code:**
96 | ```java
97 | searchView.setVoiceSearch(true); //or false
98 | ```
99 | **Handle the response:**
100 | ```java
101 | @Override
102 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
103 | if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == RESULT_OK) {
104 | ArrayList matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
105 | if (matches != null && matches.size() > 0) {
106 | String searchWrd = matches.get(0);
107 | if (!TextUtils.isEmpty(searchWrd)) {
108 | searchView.setQuery(searchWrd, false);
109 | }
110 | }
111 |
112 | return;
113 | }
114 | super.onActivityResult(requestCode, resultCode, data);
115 | }
116 | ```
117 | # Add suggestions
118 | **Define them in the resources as a *string-array*:**
119 | ```xml
120 |
121 | - Android
122 | - iOS
123 | - SCALA
124 | - Ruby
125 | - JavaScript
126 |
127 | ```
128 | **Add them to the object:**
129 | ```java
130 | searchView.setSuggestions(getResources().getStringArray(R.array.query_suggestions));
131 | ```
132 | # Style it!
133 | ```xml
134 |
162 | ```
163 | #Custom cursor
164 | **Create the drawable:**
165 | ```xml
166 |
167 |
168 |
169 |
170 | ```
171 | **And add it to the object:**
172 | ```java
173 | searchView.setCursorDrawable(R.drawable.custom_cursor);
174 | ```
175 |
176 | # Using AppBarLayout?
177 | It is a little bit tricky but can be achieved using this:
178 | ```xml
179 |
184 |
185 |
186 |
192 |
193 |
194 |
199 |
200 |
204 |
205 |
210 |
211 |
216 |
217 |
218 |
225 |
226 |
227 |
228 |
229 | ```
230 | # Bonus
231 | **Close on backpressed:**
232 | ```java
233 | @Override
234 | public void onBackPressed() {
235 | if (searchView.isSearchOpen()) {
236 | searchView.closeSearch();
237 | } else {
238 | super.onBackPressed();
239 | }
240 | }
241 | ```
242 | # Help me
243 | Pull requests are more than welcome, help me and others improve this awesome library.
244 |
245 | The code is based in the Krishnakapil original concept.
246 |
247 | # License
248 | Copyright 2015 Miguel Catalan Bañuls
249 |
250 | Licensed under the Apache License, Version 2.0 (the "License");
251 | you may not use this file except in compliance with the License.
252 | You may obtain a copy of the License at
253 |
254 | http://www.apache.org/licenses/LICENSE-2.0
255 |
256 | Unless required by applicable law or agreed to in writing, software
257 | distributed under the License is distributed on an "AS IS" BASIS,
258 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
259 | See the License for the specific language governing permissions and
260 | limitations under the License.
261 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/library/src/main/java/com/miguelcatalan/materialsearchview/MaterialSearchView.java:
--------------------------------------------------------------------------------
1 | package com.miguelcatalan.materialsearchview;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.pm.PackageManager;
7 | import android.content.pm.ResolveInfo;
8 | import android.content.res.TypedArray;
9 | import android.graphics.Rect;
10 | import android.graphics.drawable.Drawable;
11 | import android.os.Build;
12 | import android.os.Parcel;
13 | import android.os.Parcelable;
14 | import android.speech.RecognizerIntent;
15 | import android.text.Editable;
16 | import android.text.TextUtils;
17 | import android.text.TextWatcher;
18 | import android.util.AttributeSet;
19 | import android.util.Log;
20 | import android.view.KeyEvent;
21 | import android.view.LayoutInflater;
22 | import android.view.MenuItem;
23 | import android.view.View;
24 | import android.view.inputmethod.EditorInfo;
25 | import android.view.inputmethod.InputMethodManager;
26 | import android.widget.AdapterView;
27 | import android.widget.EditText;
28 | import android.widget.Filter;
29 | import android.widget.Filterable;
30 | import android.widget.FrameLayout;
31 | import android.widget.ImageButton;
32 | import android.widget.ListAdapter;
33 | import android.widget.ListView;
34 | import android.widget.RelativeLayout;
35 | import android.widget.TextView;
36 |
37 | import com.miguelcatalan.materialsearchview.utils.AnimationUtil;
38 |
39 | import java.lang.reflect.Field;
40 | import java.util.List;
41 |
42 | /**
43 | * @author Miguel Catalan Bañuls
44 | */
45 | public class MaterialSearchView extends FrameLayout implements Filter.FilterListener {
46 | public static final int REQUEST_VOICE = 9999;
47 |
48 | private MenuItem mMenuItem;
49 | private boolean mIsSearchOpen = false;
50 | private int mAnimationDuration;
51 | private boolean mClearingFocus;
52 |
53 | //Views
54 | private View mSearchLayout;
55 | private View mTintView;
56 | private ListView mSuggestionsListView;
57 | private EditText mSearchSrcTextView;
58 | private ImageButton mBackBtn;
59 | private ImageButton mVoiceBtn;
60 | private ImageButton mEmptyBtn;
61 | private RelativeLayout mSearchTopBar;
62 |
63 | private CharSequence mOldQueryText;
64 | private CharSequence mUserQuery;
65 |
66 | private OnQueryTextListener mOnQueryChangeListener;
67 | private SearchViewListener mSearchViewListener;
68 |
69 | private ListAdapter mAdapter;
70 |
71 | private SavedState mSavedState;
72 | private boolean submit = false;
73 |
74 | private boolean ellipsize = false;
75 |
76 | private boolean allowVoiceSearch;
77 | private Drawable suggestionIcon;
78 |
79 | private Context mContext;
80 |
81 | public MaterialSearchView(Context context) {
82 | this(context, null);
83 | }
84 |
85 | public MaterialSearchView(Context context, AttributeSet attrs) {
86 | this(context, attrs, 0);
87 | }
88 |
89 | public MaterialSearchView(Context context, AttributeSet attrs, int defStyleAttr) {
90 | super(context, attrs);
91 |
92 | mContext = context;
93 |
94 | initiateView();
95 |
96 | initStyle(attrs, defStyleAttr);
97 | }
98 |
99 | private void initStyle(AttributeSet attrs, int defStyleAttr) {
100 | TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.MaterialSearchView, defStyleAttr, 0);
101 |
102 | if (a != null) {
103 | if (a.hasValue(R.styleable.MaterialSearchView_searchBackground)) {
104 | setBackground(a.getDrawable(R.styleable.MaterialSearchView_searchBackground));
105 | }
106 |
107 | if (a.hasValue(R.styleable.MaterialSearchView_android_textColor)) {
108 | setTextColor(a.getColor(R.styleable.MaterialSearchView_android_textColor, 0));
109 | }
110 |
111 | if (a.hasValue(R.styleable.MaterialSearchView_android_textColorHint)) {
112 | setHintTextColor(a.getColor(R.styleable.MaterialSearchView_android_textColorHint, 0));
113 | }
114 |
115 | if (a.hasValue(R.styleable.MaterialSearchView_android_hint)) {
116 | setHint(a.getString(R.styleable.MaterialSearchView_android_hint));
117 | }
118 |
119 | if (a.hasValue(R.styleable.MaterialSearchView_searchVoiceIcon)) {
120 | setVoiceIcon(a.getDrawable(R.styleable.MaterialSearchView_searchVoiceIcon));
121 | }
122 |
123 | if (a.hasValue(R.styleable.MaterialSearchView_searchCloseIcon)) {
124 | setCloseIcon(a.getDrawable(R.styleable.MaterialSearchView_searchCloseIcon));
125 | }
126 |
127 | if (a.hasValue(R.styleable.MaterialSearchView_searchBackIcon)) {
128 | setBackIcon(a.getDrawable(R.styleable.MaterialSearchView_searchBackIcon));
129 | }
130 |
131 | if (a.hasValue(R.styleable.MaterialSearchView_searchSuggestionBackground)) {
132 | setSuggestionBackground(a.getDrawable(R.styleable.MaterialSearchView_searchSuggestionBackground));
133 | }
134 |
135 | if (a.hasValue(R.styleable.MaterialSearchView_searchSuggestionIcon)) {
136 | setSuggestionIcon(a.getDrawable(R.styleable.MaterialSearchView_searchSuggestionIcon));
137 | }
138 |
139 | if (a.hasValue(R.styleable.MaterialSearchView_android_inputType)) {
140 | setInputType(a.getInt(R.styleable.MaterialSearchView_android_inputType, EditorInfo.TYPE_NULL));
141 | }
142 |
143 | a.recycle();
144 | }
145 | }
146 |
147 | private void initiateView() {
148 | LayoutInflater.from(mContext).inflate(R.layout.search_view, this, true);
149 | mSearchLayout = findViewById(R.id.search_layout);
150 |
151 | mSearchTopBar = (RelativeLayout) mSearchLayout.findViewById(R.id.search_top_bar);
152 | mSuggestionsListView = (ListView) mSearchLayout.findViewById(R.id.suggestion_list);
153 | mSearchSrcTextView = (EditText) mSearchLayout.findViewById(R.id.searchTextView);
154 | mBackBtn = (ImageButton) mSearchLayout.findViewById(R.id.action_up_btn);
155 | mVoiceBtn = (ImageButton) mSearchLayout.findViewById(R.id.action_voice_btn);
156 | mEmptyBtn = (ImageButton) mSearchLayout.findViewById(R.id.action_empty_btn);
157 | mTintView = mSearchLayout.findViewById(R.id.transparent_view);
158 |
159 | mSearchSrcTextView.setOnClickListener(mOnClickListener);
160 | mBackBtn.setOnClickListener(mOnClickListener);
161 | mVoiceBtn.setOnClickListener(mOnClickListener);
162 | mEmptyBtn.setOnClickListener(mOnClickListener);
163 | mTintView.setOnClickListener(mOnClickListener);
164 |
165 | allowVoiceSearch = false;
166 |
167 | showVoice(true);
168 |
169 | initSearchView();
170 |
171 | mSuggestionsListView.setVisibility(GONE);
172 | setAnimationDuration(AnimationUtil.ANIMATION_DURATION_MEDIUM);
173 | }
174 |
175 | private void initSearchView() {
176 | mSearchSrcTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
177 | @Override
178 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
179 | onSubmitQuery();
180 | return true;
181 | }
182 | });
183 |
184 | mSearchSrcTextView.addTextChangedListener(new TextWatcher() {
185 | @Override
186 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {
187 |
188 | }
189 |
190 | @Override
191 | public void onTextChanged(CharSequence s, int start, int before, int count) {
192 | mUserQuery = s;
193 | startFilter(s);
194 | MaterialSearchView.this.onTextChanged(s);
195 | }
196 |
197 | @Override
198 | public void afterTextChanged(Editable s) {
199 |
200 | }
201 | });
202 |
203 | mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() {
204 | @Override
205 | public void onFocusChange(View v, boolean hasFocus) {
206 | if (hasFocus) {
207 | showKeyboard(mSearchSrcTextView);
208 | showSuggestions();
209 | }
210 | }
211 | });
212 | }
213 |
214 | private void startFilter(CharSequence s) {
215 | if (mAdapter != null && mAdapter instanceof Filterable) {
216 | ((Filterable) mAdapter).getFilter().filter(s, MaterialSearchView.this);
217 | }
218 | }
219 |
220 | private final OnClickListener mOnClickListener = new OnClickListener() {
221 |
222 | public void onClick(View v) {
223 | if (v == mBackBtn) {
224 | closeSearch();
225 | } else if (v == mVoiceBtn) {
226 | onVoiceClicked();
227 | } else if (v == mEmptyBtn) {
228 | mSearchSrcTextView.setText(null);
229 | } else if (v == mSearchSrcTextView) {
230 | showSuggestions();
231 | } else if (v == mTintView) {
232 | closeSearch();
233 | }
234 | }
235 | };
236 |
237 | private void onVoiceClicked() {
238 | Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
239 | //intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak an item name or number"); // user hint
240 | intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); // setting recognition model, optimized for short phrases – search queries
241 | intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1); // quantity of results we want to receive
242 | if (mContext instanceof Activity) {
243 | ((Activity) mContext).startActivityForResult(intent, REQUEST_VOICE);
244 | }
245 | }
246 |
247 | private void onTextChanged(CharSequence newText) {
248 | CharSequence text = mSearchSrcTextView.getText();
249 | mUserQuery = text;
250 | boolean hasText = !TextUtils.isEmpty(text);
251 | if (hasText) {
252 | mEmptyBtn.setVisibility(VISIBLE);
253 | showVoice(false);
254 | } else {
255 | mEmptyBtn.setVisibility(GONE);
256 | showVoice(true);
257 | }
258 |
259 | if (mOnQueryChangeListener != null && !TextUtils.equals(newText, mOldQueryText)) {
260 | mOnQueryChangeListener.onQueryTextChange(newText.toString());
261 | }
262 | mOldQueryText = newText.toString();
263 | }
264 |
265 | private void onSubmitQuery() {
266 | CharSequence query = mSearchSrcTextView.getText();
267 | if (query != null && TextUtils.getTrimmedLength(query) > 0) {
268 | if (mOnQueryChangeListener == null || !mOnQueryChangeListener.onQueryTextSubmit(query.toString())) {
269 | closeSearch();
270 | mSearchSrcTextView.setText(null);
271 | }
272 | }
273 | }
274 |
275 | private boolean isVoiceAvailable() {
276 | if (isInEditMode()) {
277 | return true;
278 | }
279 | PackageManager pm = getContext().getPackageManager();
280 | List activities = pm.queryIntentActivities(
281 | new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
282 | return activities.size() == 0;
283 | }
284 |
285 | public void hideKeyboard(View view) {
286 | InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
287 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
288 | }
289 |
290 | public void showKeyboard(View view) {
291 | if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1 && view.hasFocus()) {
292 | view.clearFocus();
293 | }
294 | view.requestFocus();
295 | InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
296 | imm.showSoftInput(view, 0);
297 | }
298 |
299 | //Public Attributes
300 |
301 | @Override
302 | public void setBackground(Drawable background) {
303 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
304 | mSearchTopBar.setBackground(background);
305 | } else {
306 | mSearchTopBar.setBackgroundDrawable(background);
307 | }
308 | }
309 |
310 | @Override
311 | public void setBackgroundColor(int color) {
312 | mSearchTopBar.setBackgroundColor(color);
313 | }
314 |
315 | public void setTextColor(int color) {
316 | mSearchSrcTextView.setTextColor(color);
317 | }
318 |
319 | public void setHintTextColor(int color) {
320 | mSearchSrcTextView.setHintTextColor(color);
321 | }
322 |
323 | public void setHint(CharSequence hint) {
324 | mSearchSrcTextView.setHint(hint);
325 | }
326 |
327 | public void setVoiceIcon(Drawable drawable) {
328 | mVoiceBtn.setImageDrawable(drawable);
329 | }
330 |
331 | public void setCloseIcon(Drawable drawable) {
332 | mEmptyBtn.setImageDrawable(drawable);
333 | }
334 |
335 | public void setBackIcon(Drawable drawable) {
336 | mBackBtn.setImageDrawable(drawable);
337 | }
338 |
339 | public void setSuggestionIcon(Drawable drawable) {
340 | suggestionIcon = drawable;
341 | }
342 |
343 | public void setInputType(int inputType) {
344 | mSearchSrcTextView.setInputType(inputType);
345 | }
346 |
347 | public void setSuggestionBackground(Drawable background) {
348 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
349 | mSuggestionsListView.setBackground(background);
350 | } else {
351 | mSuggestionsListView.setBackgroundDrawable(background);
352 | }
353 | }
354 |
355 | public void setCursorDrawable(int drawable) {
356 | try {
357 | // https://github.com/android/platform_frameworks_base/blob/kitkat-release/core/java/android/widget/TextView.java#L562-564
358 | Field f = TextView.class.getDeclaredField("mCursorDrawableRes");
359 | f.setAccessible(true);
360 | f.set(mSearchSrcTextView, drawable);
361 | } catch (Exception ignored) {
362 | Log.e("MaterialSearchView", ignored.toString());
363 | }
364 | }
365 |
366 | public void setVoiceSearch(boolean voiceSearch) {
367 | allowVoiceSearch = voiceSearch;
368 | }
369 |
370 | //Public Methods
371 |
372 | /**
373 | * Call this method to show suggestions list. This shows up when adapter is set. Call {@link #setAdapter(ListAdapter)} before calling this.
374 | */
375 | public void showSuggestions() {
376 | if (mAdapter != null && mAdapter.getCount() > 0 && mSuggestionsListView.getVisibility() == GONE) {
377 | mSuggestionsListView.setVisibility(VISIBLE);
378 | }
379 | }
380 |
381 | /**
382 | * Submit the query as soon as the user clicks the item.
383 | *
384 | * @param submit submit state
385 | */
386 | public void setSubmitOnClick(boolean submit) {
387 | this.submit = submit;
388 | }
389 |
390 | /**
391 | * Set Suggest List OnItemClickListener
392 | *
393 | * @param listener
394 | */
395 | public void setOnItemClickListener(AdapterView.OnItemClickListener listener) {
396 | mSuggestionsListView.setOnItemClickListener(listener);
397 | }
398 |
399 | /**
400 | * Set Adapter for suggestions list. Should implement Filterable.
401 | *
402 | * @param adapter
403 | */
404 | public void setAdapter(ListAdapter adapter) {
405 | mAdapter = adapter;
406 | mSuggestionsListView.setAdapter(adapter);
407 | startFilter(mSearchSrcTextView.getText());
408 | }
409 |
410 | /**
411 | * Set Adapter for suggestions list with the given suggestion array
412 | *
413 | * @param suggestions array of suggestions
414 | */
415 | public void setSuggestions(String[] suggestions) {
416 | if (suggestions != null && suggestions.length > 0) {
417 | mTintView.setVisibility(VISIBLE);
418 | final SearchAdapter adapter = new SearchAdapter(mContext, suggestions, suggestionIcon, ellipsize);
419 | setAdapter(adapter);
420 |
421 | setOnItemClickListener(new AdapterView.OnItemClickListener() {
422 | @Override
423 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
424 | setQuery((String) adapter.getItem(position), submit);
425 | }
426 | });
427 | } else {
428 | mTintView.setVisibility(GONE);
429 | }
430 | }
431 |
432 | /**
433 | * Dismiss the suggestions list.
434 | */
435 | public void dismissSuggestions() {
436 | if (mSuggestionsListView.getVisibility() == VISIBLE) {
437 | mSuggestionsListView.setVisibility(GONE);
438 | }
439 | }
440 |
441 |
442 | /**
443 | * Calling this will set the query to search text box. if submit is true, it'll submit the query.
444 | *
445 | * @param query
446 | * @param submit
447 | */
448 | public void setQuery(CharSequence query, boolean submit) {
449 | mSearchSrcTextView.setText(query);
450 | if (query != null) {
451 | mSearchSrcTextView.setSelection(mSearchSrcTextView.length());
452 | mUserQuery = query;
453 | }
454 | if (submit && !TextUtils.isEmpty(query)) {
455 | onSubmitQuery();
456 | }
457 | }
458 |
459 | /**
460 | * if show is true, this will enable voice search. If voice is not available on the device, this method call has not effect.
461 | *
462 | * @param show
463 | */
464 | public void showVoice(boolean show) {
465 | if (show && isVoiceAvailable() && allowVoiceSearch) {
466 | mVoiceBtn.setVisibility(VISIBLE);
467 | } else {
468 | mVoiceBtn.setVisibility(GONE);
469 | }
470 | }
471 |
472 | /**
473 | * Call this method and pass the menu item so this class can handle click events for the Menu Item.
474 | *
475 | * @param menuItem
476 | */
477 | public void setMenuItem(MenuItem menuItem) {
478 | this.mMenuItem = menuItem;
479 | mMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
480 | @Override
481 | public boolean onMenuItemClick(MenuItem item) {
482 | showSearch();
483 | return true;
484 | }
485 | });
486 | }
487 |
488 | /**
489 | * Return true if search is open
490 | *
491 | * @return
492 | */
493 | public boolean isSearchOpen() {
494 | return mIsSearchOpen;
495 | }
496 |
497 | /**
498 | * Sets animation duration. ONLY FOR PRE-LOLLIPOP!!
499 | *
500 | * @param duration duration of the animation
501 | */
502 | public void setAnimationDuration(int duration) {
503 | mAnimationDuration = duration;
504 | }
505 |
506 | /**
507 | * Open Search View. This will animate the showing of the view.
508 | */
509 | public void showSearch() {
510 | showSearch(true);
511 | }
512 |
513 | /**
514 | * Open Search View. If animate is true, Animate the showing of the view.
515 | *
516 | * @param animate true for animate
517 | */
518 | public void showSearch(boolean animate) {
519 | if (isSearchOpen()) {
520 | return;
521 | }
522 |
523 | //Request Focus
524 | mSearchSrcTextView.setText(null);
525 | mSearchSrcTextView.requestFocus();
526 |
527 | if (animate) {
528 | setVisibleWithAnimation();
529 |
530 | } else {
531 | mSearchLayout.setVisibility(VISIBLE);
532 | if (mSearchViewListener != null) {
533 | mSearchViewListener.onSearchViewShown();
534 | }
535 | }
536 | mIsSearchOpen = true;
537 | }
538 |
539 | private void setVisibleWithAnimation() {
540 | AnimationUtil.AnimationListener animationListener = new AnimationUtil.AnimationListener() {
541 | @Override
542 | public boolean onAnimationStart(View view) {
543 | return false;
544 | }
545 |
546 | @Override
547 | public boolean onAnimationEnd(View view) {
548 | if (mSearchViewListener != null) {
549 | mSearchViewListener.onSearchViewShown();
550 | }
551 | return false;
552 | }
553 |
554 | @Override
555 | public boolean onAnimationCancel(View view) {
556 | return false;
557 | }
558 | };
559 |
560 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
561 | mSearchLayout.setVisibility(View.VISIBLE);
562 | AnimationUtil.reveal(mSearchTopBar, animationListener);
563 |
564 | } else {
565 | AnimationUtil.fadeInView(mSearchLayout, mAnimationDuration, animationListener);
566 | }
567 | }
568 |
569 | /**
570 | * Close search view.
571 | */
572 | public void closeSearch() {
573 | if (!isSearchOpen()) {
574 | return;
575 | }
576 |
577 | mSearchSrcTextView.setText(null);
578 | dismissSuggestions();
579 | clearFocus();
580 |
581 | mSearchLayout.setVisibility(GONE);
582 | if (mSearchViewListener != null) {
583 | mSearchViewListener.onSearchViewClosed();
584 | }
585 | mIsSearchOpen = false;
586 |
587 | }
588 |
589 | /**
590 | * Set this listener to listen to Query Change events.
591 | *
592 | * @param listener
593 | */
594 | public void setOnQueryTextListener(OnQueryTextListener listener) {
595 | mOnQueryChangeListener = listener;
596 | }
597 |
598 | /**
599 | * Set this listener to listen to Search View open and close events
600 | *
601 | * @param listener
602 | */
603 | public void setOnSearchViewListener(SearchViewListener listener) {
604 | mSearchViewListener = listener;
605 | }
606 |
607 | /**
608 | * Ellipsize suggestions longer than one line.
609 | *
610 | * @param ellipsize
611 | */
612 | public void setEllipsize(boolean ellipsize) {
613 | this.ellipsize = ellipsize;
614 | }
615 |
616 | @Override
617 | public void onFilterComplete(int count) {
618 | if (count > 0) {
619 | showSuggestions();
620 | } else {
621 | dismissSuggestions();
622 | }
623 | }
624 |
625 | @Override
626 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
627 | // Don't accept focus if in the middle of clearing focus
628 | if (mClearingFocus) return false;
629 | // Check if SearchView is focusable.
630 | if (!isFocusable()) return false;
631 | return mSearchSrcTextView.requestFocus(direction, previouslyFocusedRect);
632 | }
633 |
634 | @Override
635 | public void clearFocus() {
636 | mClearingFocus = true;
637 | hideKeyboard(this);
638 | super.clearFocus();
639 | mSearchSrcTextView.clearFocus();
640 | mClearingFocus = false;
641 | }
642 |
643 | @Override
644 | public Parcelable onSaveInstanceState() {
645 | Parcelable superState = super.onSaveInstanceState();
646 |
647 | mSavedState = new SavedState(superState);
648 | mSavedState.query = mUserQuery != null ? mUserQuery.toString() : null;
649 | mSavedState.isSearchOpen = this.mIsSearchOpen;
650 |
651 | return mSavedState;
652 | }
653 |
654 | @Override
655 | public void onRestoreInstanceState(Parcelable state) {
656 | if (!(state instanceof SavedState)) {
657 | super.onRestoreInstanceState(state);
658 | return;
659 | }
660 |
661 | mSavedState = (SavedState) state;
662 |
663 | if (mSavedState.isSearchOpen) {
664 | showSearch(false);
665 | setQuery(mSavedState.query, false);
666 | }
667 |
668 | super.onRestoreInstanceState(mSavedState.getSuperState());
669 | }
670 |
671 | static class SavedState extends BaseSavedState {
672 | String query;
673 | boolean isSearchOpen;
674 |
675 | SavedState(Parcelable superState) {
676 | super(superState);
677 | }
678 |
679 | private SavedState(Parcel in) {
680 | super(in);
681 | this.query = in.readString();
682 | this.isSearchOpen = in.readInt() == 1;
683 | }
684 |
685 | @Override
686 | public void writeToParcel(Parcel out, int flags) {
687 | super.writeToParcel(out, flags);
688 | out.writeString(query);
689 | out.writeInt(isSearchOpen ? 1 : 0);
690 | }
691 |
692 | //required field that makes Parcelables from a Parcel
693 | public static final Creator CREATOR =
694 | new Creator() {
695 | public SavedState createFromParcel(Parcel in) {
696 | return new SavedState(in);
697 | }
698 |
699 | public SavedState[] newArray(int size) {
700 | return new SavedState[size];
701 | }
702 | };
703 | }
704 |
705 | public interface OnQueryTextListener {
706 |
707 | /**
708 | * Called when the user submits the query. This could be due to a key press on the
709 | * keyboard or due to pressing a submit button.
710 | * The listener can override the standard behavior by returning true
711 | * to indicate that it has handled the submit request. Otherwise return false to
712 | * let the SearchView handle the submission by launching any associated intent.
713 | *
714 | * @param query the query text that is to be submitted
715 | * @return true if the query has been handled by the listener, false to let the
716 | * SearchView perform the default action.
717 | */
718 | boolean onQueryTextSubmit(String query);
719 |
720 | /**
721 | * Called when the query text is changed by the user.
722 | *
723 | * @param newText the new content of the query text field.
724 | * @return false if the SearchView should perform the default action of showing any
725 | * suggestions if available, true if the action was handled by the listener.
726 | */
727 | boolean onQueryTextChange(String newText);
728 | }
729 |
730 | public interface SearchViewListener {
731 | void onSearchViewShown();
732 |
733 | void onSearchViewClosed();
734 | }
735 |
736 |
737 | }
--------------------------------------------------------------------------------
/sample/src/main/res/layout/mok_items.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
16 |
17 |
22 |
23 |
33 |
34 |
40 |
41 |
49 |
50 |
51 |
52 |
60 |
61 |
62 |
63 |
68 |
69 |
74 |
75 |
85 |
86 |
92 |
93 |
101 |
102 |
103 |
104 |
112 |
113 |
114 |
115 |
120 |
121 |
126 |
127 |
137 |
138 |
144 |
145 |
153 |
154 |
155 |
156 |
164 |
165 |
166 |
167 |
172 |
173 |
178 |
179 |
189 |
190 |
196 |
197 |
205 |
206 |
207 |
208 |
216 |
217 |
218 |
219 |
224 |
225 |
230 |
231 |
241 |
242 |
248 |
249 |
257 |
258 |
259 |
260 |
268 |
269 |
270 |
271 |
276 |
277 |
282 |
283 |
293 |
294 |
300 |
301 |
309 |
310 |
311 |
312 |
320 |
321 |
322 |
323 |
328 |
329 |
334 |
335 |
345 |
346 |
352 |
353 |
361 |
362 |
363 |
364 |
372 |
373 |
374 |
375 |
380 |
381 |
386 |
387 |
397 |
398 |
404 |
405 |
413 |
414 |
415 |
416 |
424 |
425 |
426 |
427 |
432 |
433 |
438 |
439 |
449 |
450 |
456 |
457 |
465 |
466 |
467 |
468 |
476 |
477 |
478 |
479 |
484 |
485 |
490 |
491 |
501 |
502 |
508 |
509 |
517 |
518 |
519 |
520 |
528 |
529 |
530 |
531 |
536 |
537 |
542 |
543 |
553 |
554 |
560 |
561 |
569 |
570 |
571 |
572 |
580 |
581 |
582 |
583 |
588 |
589 |
594 |
595 |
605 |
606 |
612 |
613 |
621 |
622 |
623 |
624 |
632 |
633 |
634 |
635 |
640 |
641 |
646 |
647 |
657 |
658 |
664 |
665 |
673 |
674 |
675 |
676 |
684 |
685 |
686 |
687 |
692 |
693 |
698 |
699 |
709 |
710 |
716 |
717 |
725 |
726 |
727 |
728 |
736 |
737 |
738 |
739 |
744 |
745 |
750 |
751 |
761 |
762 |
768 |
769 |
777 |
778 |
779 |
780 |
788 |
789 |
790 |
791 |
796 |
797 |
802 |
803 |
813 |
814 |
820 |
821 |
829 |
830 |
831 |
832 |
840 |
841 |
842 |
843 |
844 |
--------------------------------------------------------------------------------