├── .gitignore ├── CHANGELOG.md ├── LICENSE.txt ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── material-searchview ├── .gitignore ├── build.gradle ├── material-searchview.iml ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── ru │ │ └── shmakinv │ │ └── android │ │ └── widget │ │ └── material │ │ └── searchview │ │ ├── BaseFloatingSearchView.java │ │ ├── BaseRestoreInstanceFragment.java │ │ ├── FloatingSearchView.java │ │ ├── NotAllowedToEditCallBack.java │ │ ├── QueryTextWatcher.java │ │ ├── SearchEditText.java │ │ ├── SearchView.java │ │ ├── SuggestionDismissListener.java │ │ ├── VerticalLinearLayoutManager.java │ │ └── transition │ │ ├── EmptyTransition.java │ │ └── SizeTransition.java │ └── res │ ├── drawable │ └── search_text_cursor.xml │ ├── layout │ ├── layout_view_search_view.xml │ └── search_view_layout.xml │ ├── mipmap-hdpi │ ├── ic_arrow_back.png │ ├── ic_close.png │ └── ic_keyboard_voice.png │ ├── mipmap-mdpi │ ├── ic_arrow_back.png │ ├── ic_close.png │ └── ic_keyboard_voice.png │ ├── mipmap-xhdpi │ ├── ic_arrow_back.png │ ├── ic_close.png │ └── ic_keyboard_voice.png │ ├── mipmap-xxhdpi │ ├── ic_arrow_back.png │ ├── ic_close.png │ └── ic_keyboard_voice.png │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── drawables.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | #IntelliJ IDEA 2 | .idea 3 | *.iml 4 | 5 | # Built application files 6 | *.apk 7 | *.ap_ 8 | 9 | # Files for the Dalvik VM 10 | *.dex 11 | 12 | # Java class files 13 | *.class 14 | 15 | # Generated files 16 | bin/ 17 | gen/ 18 | 19 | # Gradle files 20 | .gradle/ 21 | build/ 22 | /*/build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | /material-searchview/material-searchview.iml 33 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ========== 3 | ## Version 1.1.2 4 | 5 | _2017-05-08_ 6 | * Libraries were updated. 7 | 8 | 9 | ## Version 1.1.1 10 | 11 | _2016-12-16_ 12 | * Added FloatingSearchView widget. 13 | * Libraries were updated. 14 | 15 | 16 | ## Version 1.0.9 17 | 18 | _2016-03-21_ 19 | * Annotations were added. 20 | * Libraries was updated. 21 | * Small bugfix and refactoring. 22 | 23 | 24 | ## Version 1.0.8 25 | 26 | _2016-01-04_ 27 | * Speech recognition processing was moved from Activity to SearchView. 28 | * Suggestions list now will be shown on the top of soft keyboard. 29 | 30 | 31 | ## Version 1.0.7 32 | 33 | _2016-01-03_ 34 | * Added ability to set item decoration for suggestions. 35 | * Suggestions list now will be shown on the top of soft keyboard. 36 | 37 | 38 | ## Version 1.0.6 39 | 40 | _2016-01-02_ 41 | 42 | * Fixed on dismiss click behaviour. 43 | 44 | 45 | ## Version 1.0.5 46 | 47 | _2016-01-01_ 48 | 49 | * Some refactoring and bugfix happened. 50 | 51 | 52 | ## Version 1.0.4 53 | 54 | _2015-12-27_ 55 | 56 | * Suggestion adapter updating was implemented. 57 | 58 | 59 | ## Version 1.0.3 60 | 61 | _2015-12-22_ 62 | 63 | * EditText npe was fixed. 64 | 65 | 66 | ## Version 1.0.1 67 | 68 | _2015-12-20_ 69 | 70 | * Suggestion list size update animation was implemented. 71 | 72 | 73 | ## Version 1.0 74 | 75 | _2015-12-19_ 76 | 77 | * Initial commit. 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Material-SearchView 2 | SearchView library based on DialogFragment 3 | 4 | Download 5 | -------- 6 | 7 | Gradle: 8 | 9 | ```groovy 10 | compile 'com.github.VyacheslavShmakin.material-searchview:1.1.3' 11 | ``` 12 | 13 | Maven: 14 | 15 | ```xml 16 | 17 | com.github.VyacheslavShmakin 18 | material-searchview 19 | 1.1.3 20 | aar 21 | 22 | ``` 23 | 24 | 25 | Usage 26 | ----- 27 | #### In Code 28 | ``` java 29 | SearchView searchView = SearchView.getInstance(this); 30 | DataAdapter adapter = new DataAdapter(this, getItems()); 31 | searchView.setSuggestionAdapter(adapter); 32 | searchView.setOnVisibilityChangeListener(this); 33 | searchView.setQuery("queryTest", false); 34 | ``` 35 | 36 | SearchView should be called by using your menu item: 37 | ``` java 38 | ... 39 | @Override 40 | public boolean onOptionsItemSelected(MenuItem item) { 41 | switch(item.getItemId()) { 42 | case R.id.yourItemId: 43 | return searchView.onOptionsItemSelected(getFragmentManager(), item); 44 | default: 45 | return super.onOptionsItemSelected(item); 46 | } 47 | } 48 | ... 49 | ``` 50 | 51 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.3.1' 9 | // NOTE: Do not place your application dependencies here; they belong 10 | // in the individual module build.gradle files 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | jcenter() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VyacheslavShmakin/Material-SearchView/59b3edb0f19b1486eeea9304a757a11c0bc91985/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon May 08 16:28:42 MSK 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /material-searchview/.gitignore: -------------------------------------------------------------------------------- 1 | #IntelliJ IDEA 2 | .idea 3 | *.iml 4 | 5 | # Built application files 6 | *.apk 7 | *.ap_ 8 | 9 | # Files for the Dalvik VM 10 | *.dex 11 | 12 | # Java class files 13 | *.class 14 | 15 | # Generated files 16 | bin/ 17 | gen/ 18 | 19 | # Gradle files 20 | .gradle/ 21 | build/ 22 | /*/build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | -------------------------------------------------------------------------------- /material-searchview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 13 11 | versionName "1.1.2" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | } 17 | } 18 | 19 | lintOptions { 20 | abortOnError false 21 | } 22 | } 23 | 24 | dependencies { 25 | compile 'com.android.support:appcompat-v7:25.3.1' 26 | compile 'com.android.support:cardview-v7:25.3.1' 27 | compile 'com.android.support:recyclerview-v7:25.3.1' 28 | compile 'com.andkulikov:transitionseverywhere:1.7.1' 29 | compile 'com.github.johnkil.android-robototextview:robototextview:3.0.0' 30 | } 31 | -------------------------------------------------------------------------------- /material-searchview/material-searchview.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /material-searchview/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 C:\android_sdk/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 | -------------------------------------------------------------------------------- /material-searchview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /material-searchview/src/main/java/ru/shmakinv/android/widget/material/searchview/BaseFloatingSearchView.java: -------------------------------------------------------------------------------- 1 | package ru.shmakinv.android.widget.material.searchview; 2 | 3 | import android.annotation.TargetApi; 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.os.Build; 9 | import android.os.Parcel; 10 | import android.os.Parcelable; 11 | import android.speech.RecognizerIntent; 12 | import android.support.annotation.NonNull; 13 | import android.support.annotation.Nullable; 14 | import android.support.v7.widget.CardView; 15 | import android.text.Editable; 16 | import android.util.AttributeSet; 17 | import android.view.View; 18 | import android.view.inputmethod.InputMethodManager; 19 | import android.widget.FrameLayout; 20 | import android.widget.ImageButton; 21 | import android.widget.RelativeLayout; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * BaseFixedSearchView 27 | * 28 | * @author Vyacheslav Shmakin 29 | * @version 20.11.2016 30 | */ 31 | 32 | abstract class BaseFloatingSearchView extends FrameLayout implements 33 | View.OnKeyListener, 34 | View.OnClickListener { 35 | 36 | private final NotAllowedToEditCallBack mNotAllowedToEditCallback = new NotAllowedToEditCallBack(); 37 | 38 | protected RelativeLayout mRoot; 39 | protected CardView mSearchOverlay; 40 | protected ImageButton mNavBackBtn; 41 | protected ImageButton mCloseVoiceBtn; 42 | protected SearchEditText mSearchEditText; 43 | 44 | protected boolean mSpeechRecognized = false; 45 | 46 | public BaseFloatingSearchView(Context context) { 47 | super(context); 48 | init(context, null); 49 | } 50 | 51 | public BaseFloatingSearchView(Context context, AttributeSet attrs) { 52 | super(context, attrs); 53 | init(context, attrs); 54 | } 55 | 56 | public BaseFloatingSearchView(Context context, AttributeSet attrs, int defStyleAttr) { 57 | super(context, attrs, defStyleAttr); 58 | init(context, attrs); 59 | } 60 | 61 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 62 | public BaseFloatingSearchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 63 | super(context, attrs, defStyleAttr, defStyleRes); 64 | init(context, attrs); 65 | } 66 | 67 | private void init(Context context, AttributeSet attrs) { 68 | inflate(context, R.layout.layout_view_search_view, this); 69 | initViews(this); 70 | } 71 | 72 | private void initViews(@NonNull View layout) { 73 | mRoot = (RelativeLayout) layout.findViewById(R.id.root); 74 | mSearchOverlay = (CardView) layout.findViewById(R.id.search_overlay); 75 | mNavBackBtn = (ImageButton) layout.findViewById(R.id.ibtn_navigation_back); 76 | mCloseVoiceBtn = (ImageButton) layout.findViewById(R.id.ibtn_voice_close); 77 | mSearchEditText = (SearchEditText) layout.findViewById(R.id.et_search_text); 78 | 79 | setUpListeners(); 80 | } 81 | 82 | private void setUpListeners() { 83 | mSearchEditText.addTextChangedListener(mSearchTextWatcher); 84 | mSearchEditText.setOnKeyListener(this); 85 | mCloseVoiceBtn.setOnClickListener(this); 86 | mNavBackBtn.setOnClickListener(this); 87 | mSearchEditText.setCustomSelectionActionModeCallback(mNotAllowedToEditCallback); 88 | } 89 | 90 | protected void updateCloseVoiceState(@Nullable String searchText) { 91 | if (searchText != null && searchText.length() != 0) { 92 | mCloseVoiceBtn.setVisibility(View.VISIBLE); 93 | mCloseVoiceBtn.setImageResource(R.drawable.searchview_button_close); 94 | } else if (!isSpeechRecognitionToolAvailable()) { 95 | mCloseVoiceBtn.setVisibility(View.INVISIBLE); 96 | } else { 97 | mCloseVoiceBtn.setImageResource(R.drawable.searchview_button_voice); 98 | } 99 | } 100 | 101 | protected abstract void onCloseVoiceClicked(); 102 | 103 | public abstract void setQuery(@NonNull String query, boolean submit); 104 | 105 | protected abstract void onQueryChanged(@NonNull String query); 106 | 107 | protected void submitQuery() { 108 | mSearchEditText.clearFocus(); 109 | hideKeyboard(); 110 | } 111 | 112 | protected boolean isSpeechRecognitionToolAvailable() { 113 | PackageManager pm = getContext().getPackageManager(); 114 | List activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); 115 | return activities.size() != 0; 116 | } 117 | 118 | protected void hideKeyboard() { 119 | ((InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE)) 120 | .toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); 121 | } 122 | 123 | protected final QueryTextWatcher mSearchTextWatcher = new QueryTextWatcher() { 124 | @Override 125 | public void onQueryTextChanged(Editable s) { 126 | onQueryChanged(s.toString()); 127 | } 128 | }; 129 | 130 | @Override 131 | public Parcelable onSaveInstanceState() { 132 | Parcelable superState = super.onSaveInstanceState(); 133 | SavedState ss = new SavedState(superState); 134 | ss.value = mSearchEditText.getText().toString(); 135 | ss.speechRecognized = this.mSpeechRecognized; 136 | return ss; 137 | } 138 | 139 | @Override 140 | public void onRestoreInstanceState(Parcelable state) { 141 | if (!(state instanceof SavedState)) { 142 | super.onRestoreInstanceState(state); 143 | return; 144 | } 145 | 146 | SavedState ss = (SavedState) state; 147 | super.onRestoreInstanceState(ss.getSuperState()); 148 | mSearchEditText.setText(ss.value); 149 | mSpeechRecognized = ss.speechRecognized; 150 | } 151 | 152 | static class SavedState extends BaseSavedState { 153 | String value; 154 | boolean speechRecognized; 155 | 156 | SavedState(Parcelable superState) { 157 | super(superState); 158 | } 159 | 160 | private SavedState(Parcel in) { 161 | super(in); 162 | this.value = in.readString(); 163 | this.speechRecognized = in.readInt() == 1; 164 | } 165 | 166 | @Override 167 | public void writeToParcel(Parcel out, int flags) { 168 | super.writeToParcel(out, flags); 169 | out.writeString(this.value); 170 | out.writeInt(this.speechRecognized ? 1 : 0); 171 | } 172 | 173 | public static final Parcelable.Creator CREATOR = 174 | new Parcelable.Creator() { 175 | public SavedState createFromParcel(Parcel in) { 176 | return new SavedState(in); 177 | } 178 | 179 | public SavedState[] newArray(int size) { 180 | return new SavedState[size]; 181 | } 182 | }; 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /material-searchview/src/main/java/ru/shmakinv/android/widget/material/searchview/BaseRestoreInstanceFragment.java: -------------------------------------------------------------------------------- 1 | package ru.shmakinv.android.widget.material.searchview; 2 | 3 | import android.animation.Animator; 4 | import android.app.DialogFragment; 5 | import android.app.Fragment; 6 | import android.app.FragmentManager; 7 | import android.app.FragmentTransaction; 8 | import android.content.Context; 9 | import android.content.DialogInterface; 10 | import android.content.Intent; 11 | import android.content.pm.PackageManager; 12 | import android.content.pm.ResolveInfo; 13 | import android.graphics.Point; 14 | import android.os.Build; 15 | import android.os.Bundle; 16 | import android.speech.RecognizerIntent; 17 | import android.support.annotation.NonNull; 18 | import android.text.Editable; 19 | import android.view.Display; 20 | import android.view.MotionEvent; 21 | import android.view.View; 22 | import android.view.ViewAnimationUtils; 23 | import android.view.ViewGroup; 24 | import android.view.WindowManager; 25 | import android.view.animation.LinearInterpolator; 26 | import android.view.inputmethod.InputMethodManager; 27 | 28 | import com.devspark.robototextview.RobotoTypefaces; 29 | 30 | import java.util.List; 31 | 32 | /** 33 | * BaseRestoreInstanceFragment 34 | * 35 | * @author Vyacheslav Shmakin 36 | * @version 19.04.2017 37 | */ 38 | abstract class BaseRestoreInstanceFragment extends DialogFragment { 39 | 40 | private static final String KEY_CLOSE_REQUESTED = "is-close-requested"; 41 | private static final String KEY_VISIBLE = "is-visible"; 42 | private static final String KEY_QUERY = "last-query"; 43 | private static final String KEY_HINT = "hint"; 44 | private static final String KEY_CURSOR_POSITION = "last-cursor-position"; 45 | private static final String KEY_TYPEFACE = "last-typeface"; 46 | private static final long ANIMATOR_DURATION_SHOW = 300L; 47 | protected static final String DIALOG_TAG = "BaseRestoreInstanceFragment"; 48 | protected static final long ANIMATOR_MIN_SUGGESTION_DURATION = 50L; 49 | protected static final long ANIMATOR_MAX_SUGGESTION_DURATION = 200L; 50 | 51 | protected Integer mMenuItemId = null; 52 | @SuppressWarnings("FieldCanBeLocal") 53 | private float mAnimProportionX = -1; 54 | 55 | protected boolean mVisible = false; 56 | protected boolean mCloseRequested = false; 57 | protected boolean mCloseAnimationRunning = false; 58 | 59 | protected String mQuery = null; 60 | protected String mHint = null; 61 | protected int mSelection = -1; 62 | protected int mTypefaceValue = RobotoTypefaces.TYPEFACE_ROBOTO_REGULAR; 63 | 64 | @Override 65 | public void onCreate(Bundle savedInstanceState) { 66 | super.onCreate(savedInstanceState); 67 | setRetainInstance(true); 68 | if (savedInstanceState != null) { 69 | this.mVisible = savedInstanceState.getBoolean(KEY_VISIBLE); 70 | this.mCloseRequested = savedInstanceState.getBoolean(KEY_CLOSE_REQUESTED); 71 | this.mQuery = savedInstanceState.getString(KEY_QUERY, null); 72 | this.mHint = savedInstanceState.getString(KEY_HINT, null); 73 | this.mSelection = savedInstanceState.getInt(KEY_CURSOR_POSITION, mSelection); 74 | this.mTypefaceValue = savedInstanceState.getInt(KEY_TYPEFACE, mTypefaceValue); 75 | } 76 | } 77 | 78 | public void show(@NonNull final FragmentManager manager) { 79 | FragmentTransaction transaction = manager.beginTransaction(); 80 | Fragment prev = manager.findFragmentByTag(DIALOG_TAG); 81 | if (prev != null) { 82 | transaction.remove(prev); 83 | } 84 | 85 | transaction.add(this, DIALOG_TAG); 86 | transaction.commitAllowingStateLoss(); 87 | manager.executePendingTransactions(); 88 | } 89 | 90 | protected void setupTypeface(int typefaceValue) { 91 | this.mTypefaceValue = typefaceValue; 92 | } 93 | 94 | @Override 95 | public void onSaveInstanceState(Bundle outState) { 96 | super.onSaveInstanceState(outState); 97 | outState.putBoolean(KEY_VISIBLE, this.mVisible); 98 | outState.putBoolean(KEY_CLOSE_REQUESTED, this.mCloseRequested); 99 | outState.putString(KEY_QUERY, this.mQuery); 100 | outState.putString(KEY_HINT, this.mHint); 101 | outState.putInt(KEY_CURSOR_POSITION, this.mSelection); 102 | outState.putInt(KEY_TYPEFACE, this.mTypefaceValue); 103 | } 104 | 105 | @Override 106 | public void onDestroyView() { 107 | // removes the dismiss intent to avoid shown dialogs being dismissed. 108 | if (getDialog() != null && getRetainInstance()) { 109 | getDialog().setDismissMessage(null); 110 | } 111 | super.onDestroyView(); 112 | } 113 | 114 | @Override 115 | public void onDismiss(DialogInterface dialog) { 116 | super.onDismiss(dialog); 117 | this.mVisible = false; 118 | this.mCloseRequested = false; 119 | this.mQuery = null; 120 | this.mHint = null; 121 | this.mSelection = -1; 122 | this.mTypefaceValue = RobotoTypefaces.TYPEFACE_ROBOTO_REGULAR; 123 | } 124 | 125 | public boolean isShown() { 126 | return mVisible; 127 | } 128 | 129 | protected void animateShow(@NonNull final View view, @NonNull final View metricsView, final int itemId) { 130 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 131 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 132 | int centerX = calculateCenterX(itemId); 133 | int centerY = (metricsView.getHeight() / 2) - lp.topMargin; 134 | int endRadius = metricsView.getWidth(); 135 | 136 | final Animator animatorShow = ViewAnimationUtils.createCircularReveal( 137 | view, 138 | centerX, 139 | centerY, 140 | 0.0F, 141 | endRadius); 142 | 143 | animatorShow.addListener(new Animator.AnimatorListener() { 144 | @Override 145 | public void onAnimationStart(Animator animation) { 146 | view.setVisibility(View.VISIBLE); 147 | showKeyboard(); 148 | } 149 | 150 | @Override 151 | public void onAnimationEnd(Animator animation) { 152 | //noinspection ConstantConditions 153 | getDialog().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); 154 | onShowSearchAnimationEnd(); 155 | } 156 | 157 | @Override 158 | public void onAnimationCancel(Animator animation) { 159 | } 160 | 161 | @Override 162 | public void onAnimationRepeat(Animator animation) { 163 | } 164 | }); 165 | 166 | animatorShow.setDuration(ANIMATOR_DURATION_SHOW); 167 | animatorShow.setInterpolator(new LinearInterpolator()); 168 | animatorShow.start(); 169 | } else { 170 | view.setVisibility(View.VISIBLE); 171 | showKeyboard(); 172 | //noinspection ConstantConditions 173 | getDialog().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); 174 | onShowSearchAnimationEnd(); 175 | } 176 | } 177 | 178 | protected void animateDismiss(@NonNull final View view, @NonNull final View metricsView, final int itemId) { 179 | if (!mCloseAnimationRunning) { 180 | mCloseAnimationRunning = true; 181 | } else { 182 | return; 183 | } 184 | 185 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 186 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 187 | int centerX = calculateCenterX(itemId); 188 | int centerY = (metricsView.getHeight() / 2) - lp.topMargin; 189 | int startRadius = metricsView.getWidth(); 190 | 191 | final Animator animatorHide = ViewAnimationUtils.createCircularReveal( 192 | view, 193 | centerX, 194 | centerY, 195 | startRadius, 196 | 0.0F); 197 | 198 | animatorHide.addListener(new Animator.AnimatorListener() { 199 | @Override 200 | public void onAnimationStart(Animator animation) { 201 | } 202 | 203 | @Override 204 | public void onAnimationEnd(Animator animation) { 205 | finishClosing(view); 206 | } 207 | 208 | @Override 209 | public void onAnimationCancel(Animator animation) { 210 | } 211 | 212 | @Override 213 | public void onAnimationRepeat(Animator animation) { 214 | } 215 | }); 216 | animatorHide.setInterpolator(new LinearInterpolator()); 217 | animatorHide.setDuration(ANIMATOR_DURATION_SHOW); 218 | animatorHide.start(); 219 | } else { 220 | finishClosing(view); 221 | } 222 | } 223 | 224 | protected void finishClosing(@NonNull View view) { 225 | //noinspection ConstantConditions 226 | getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); 227 | hideKeyboard(); 228 | view.setVisibility(View.INVISIBLE); 229 | mCloseRequested = false; 230 | mCloseAnimationRunning = false; 231 | dismissAllowingStateLoss(); 232 | } 233 | 234 | protected void onShowSearchAnimationEnd() { 235 | } 236 | 237 | protected void onSuggestionsDismissed() { 238 | } 239 | 240 | protected void onQueryTextChanged(Editable s) { 241 | } 242 | 243 | protected boolean isSpeechRecognitionToolAvailable() { 244 | PackageManager pm = getActivity().getPackageManager(); 245 | List activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); 246 | return activities.size() != 0; 247 | } 248 | 249 | protected final NotAllowedToEditCallBack mNotAllowedToEditCallback = new NotAllowedToEditCallBack(); 250 | 251 | protected final SuggestionDismissListener mSuggestionsDismissListener = new SuggestionDismissListener() { 252 | @Override 253 | public void onSuggestionDismissed() { 254 | onSuggestionsDismissed(); 255 | } 256 | }; 257 | 258 | protected final QueryTextWatcher mSearchTextWatcher = new QueryTextWatcher() { 259 | @Override 260 | public void onQueryTextChanged(Editable s) { 261 | BaseRestoreInstanceFragment.this.onQueryTextChanged(s); 262 | } 263 | }; 264 | 265 | protected void onCloseVoiceClicked() { 266 | } 267 | 268 | protected final View.OnClickListener mCloseVoiceClickListener = new View.OnClickListener() { 269 | @Override 270 | public void onClick(View v) { 271 | onCloseVoiceClicked(); 272 | } 273 | }; 274 | 275 | protected void onNavigationBackClicked() { 276 | } 277 | 278 | protected final View.OnClickListener mNavigationBackClickListener = new View.OnClickListener() { 279 | @Override 280 | public void onClick(View v) { 281 | onNavigationBackClicked(); 282 | } 283 | }; 284 | 285 | protected void onOutsideTouch(@NonNull View v, @NonNull MotionEvent event) { 286 | } 287 | 288 | protected final View.OnTouchListener mOnOutsideTouchListener = new View.OnTouchListener() { 289 | @Override 290 | public boolean onTouch(View v, MotionEvent event) { 291 | onOutsideTouch(v, event); 292 | return false; 293 | } 294 | }; 295 | 296 | private float calculateProportionX(int xPosition) { 297 | return (float) xPosition / getDisplayWidth(); 298 | } 299 | 300 | private int getDisplayWidth() { 301 | Display display = getActivity().getWindowManager().getDefaultDisplay(); 302 | Point size = new Point(); 303 | display.getSize(size); 304 | return size.x; 305 | } 306 | 307 | private int calculateCenterX(int itemId) { 308 | View view = getActivity().findViewById(itemId); 309 | //3. Calculate Animation Position: 310 | mAnimProportionX = calculateProportionX(getAnimationPositionX(view)); 311 | return (int) (mAnimProportionX * getDisplayWidth()); 312 | } 313 | 314 | private int getAnimationPositionX(View view) { 315 | // If view is null then will be used current screen width parameter 316 | if (view == null) { 317 | return getDisplayWidth(); 318 | } 319 | 320 | int[] position = new int[2]; 321 | view.getLocationInWindow(position); 322 | // x = View.x + View.width / 2 323 | // y = View.y + View.height / 2 324 | return position[0] + view.getWidth() / 2; 325 | } 326 | 327 | void showKeyboard() { 328 | ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) 329 | .toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); 330 | } 331 | 332 | void hideKeyboard() { 333 | ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) 334 | .toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); 335 | } 336 | } 337 | -------------------------------------------------------------------------------- /material-searchview/src/main/java/ru/shmakinv/android/widget/material/searchview/FloatingSearchView.java: -------------------------------------------------------------------------------- 1 | package ru.shmakinv.android.widget.material.searchview; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.speech.RecognizerIntent; 7 | import android.support.annotation.NonNull; 8 | import android.support.v7.widget.CardView; 9 | import android.text.TextUtils; 10 | import android.util.AttributeSet; 11 | import android.view.KeyEvent; 12 | import android.view.View; 13 | import android.widget.ImageButton; 14 | import android.widget.RelativeLayout; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * FloatingSearchView 20 | * 21 | * @author Vyacheslav Shmakin 22 | * @version 20.11.2016 23 | */ 24 | 25 | public class FloatingSearchView extends BaseFloatingSearchView { 26 | 27 | public static final int RECOGNIZER_CODE = 1024; 28 | 29 | private OnQueryTextListener mListener; 30 | 31 | public FloatingSearchView(Context context) { 32 | super(context); 33 | } 34 | 35 | public FloatingSearchView(Context context, AttributeSet attrs) { 36 | super(context, attrs); 37 | } 38 | 39 | public FloatingSearchView(Context context, AttributeSet attrs, int defStyleAttr) { 40 | super(context, attrs, defStyleAttr); 41 | } 42 | 43 | public FloatingSearchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 44 | super(context, attrs, defStyleAttr, defStyleRes); 45 | } 46 | 47 | @NonNull 48 | public RelativeLayout getRoot() { 49 | return mRoot; 50 | } 51 | 52 | @NonNull 53 | public CardView getSearchOverlay() { 54 | return mSearchOverlay; 55 | } 56 | 57 | @NonNull 58 | public ImageButton getNavigationBackButton() { 59 | return mNavBackBtn; 60 | } 61 | 62 | @NonNull 63 | public ImageButton getCloseVoiceButton() { 64 | return mCloseVoiceBtn; 65 | } 66 | 67 | @NonNull 68 | public SearchEditText getSearchEditText() { 69 | return mSearchEditText; 70 | } 71 | 72 | public void setQuery(@NonNull String query, boolean submit) { 73 | mSearchEditText.setText(query); 74 | mSearchEditText.setSelection(query.length()); 75 | 76 | if (mListener != null) { 77 | mListener.onQueryTextChanged(query); 78 | submit = submit && mListener.onQueryTextSubmit(query); 79 | } 80 | if (submit) { 81 | submitQuery(); 82 | } 83 | } 84 | 85 | public void recognizeSpeech() { 86 | Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 87 | intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 88 | mListener 89 | .onSpeechRecognitionIntentCalled() 90 | .startActivityForResult(intent, RECOGNIZER_CODE); 91 | } 92 | 93 | @Override 94 | public boolean onKey(View v, int keyCode, KeyEvent event) { 95 | if (keyCode == KeyEvent.KEYCODE_ENTER 96 | && event.getAction() == KeyEvent.ACTION_UP 97 | && mListener != null) { 98 | 99 | String query = mSearchEditText.getText().toString(); 100 | setQuery(query, true); 101 | } 102 | return false; 103 | } 104 | 105 | @Override 106 | protected void onCloseVoiceClicked() { 107 | if (mSearchEditText != null && !TextUtils.isEmpty(mSearchEditText.getText())) { 108 | mSearchEditText.getText().clear(); 109 | } else if (isSpeechRecognitionToolAvailable() && mListener != null) { 110 | recognizeSpeech(); 111 | } 112 | } 113 | 114 | public void setOnQueryTextListener(OnQueryTextListener listener) { 115 | this.mListener = listener; 116 | } 117 | 118 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 119 | if (requestCode == RECOGNIZER_CODE && resultCode == Activity.RESULT_OK) { 120 | List results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); 121 | if (results != null && results.size() > 0) { 122 | mSearchEditText.setText(results.get(0)); 123 | mSpeechRecognized = true; 124 | } 125 | } 126 | } 127 | 128 | public interface OnQueryTextListener { 129 | boolean onQueryTextSubmit(@NonNull String query); 130 | void onQueryTextChanged(@NonNull String newText); 131 | void onNavigationBack(); 132 | Activity onSpeechRecognitionIntentCalled(); 133 | } 134 | 135 | @Override 136 | public void onClick(View view) { 137 | int id = view.getId(); 138 | if (id == R.id.ibtn_voice_close) { 139 | onCloseVoiceClicked(); 140 | } else if (id == R.id.ibtn_navigation_back && mListener != null) { 141 | mListener.onNavigationBack(); 142 | } 143 | } 144 | 145 | @Override 146 | protected void onQueryChanged(@NonNull String query) { 147 | updateCloseVoiceState(query); 148 | if (mListener != null) { 149 | mListener.onQueryTextChanged(query); 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /material-searchview/src/main/java/ru/shmakinv/android/widget/material/searchview/NotAllowedToEditCallBack.java: -------------------------------------------------------------------------------- 1 | package ru.shmakinv.android.widget.material.searchview; 2 | 3 | import android.view.ActionMode; 4 | import android.view.Menu; 5 | import android.view.MenuItem; 6 | 7 | /** 8 | * NotAllowedToEditCallBack 9 | * 10 | * @author Vyacheslav Shmakin 11 | * @version 27.12.2015 12 | */ 13 | class NotAllowedToEditCallBack implements ActionMode.Callback { 14 | @Override 15 | public boolean onCreateActionMode(ActionMode mode, Menu menu) { 16 | return false; 17 | } 18 | 19 | @Override 20 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) { 21 | return false; 22 | } 23 | 24 | @Override 25 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) { 26 | return false; 27 | } 28 | 29 | @Override 30 | public void onDestroyActionMode(ActionMode mode) { 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /material-searchview/src/main/java/ru/shmakinv/android/widget/material/searchview/QueryTextWatcher.java: -------------------------------------------------------------------------------- 1 | package ru.shmakinv.android.widget.material.searchview; 2 | 3 | import android.text.Editable; 4 | import android.text.TextWatcher; 5 | 6 | /** 7 | * QueryTextWatcher 8 | * 9 | * @author Vyacheslav Shmakin 10 | * @version 27.12.2015 11 | */ 12 | abstract class QueryTextWatcher implements TextWatcher { 13 | @Override 14 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 15 | 16 | } 17 | 18 | @Override 19 | public void onTextChanged(CharSequence s, int start, int before, int count) { 20 | 21 | } 22 | 23 | @Override 24 | public void afterTextChanged(Editable s) { 25 | onQueryTextChanged(s); 26 | } 27 | 28 | public abstract void onQueryTextChanged(Editable s); 29 | } 30 | -------------------------------------------------------------------------------- /material-searchview/src/main/java/ru/shmakinv/android/widget/material/searchview/SearchEditText.java: -------------------------------------------------------------------------------- 1 | package ru.shmakinv.android.widget.material.searchview; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.KeyEvent; 6 | 7 | import com.devspark.robototextview.widget.RobotoEditText; 8 | 9 | /** 10 | * SearchEditText 11 | * 12 | * @author Vyacheslav Shmakin 13 | * @version 20.12.2015 14 | */ 15 | public class SearchEditText extends RobotoEditText { 16 | 17 | private OnBackKeyPressListener mOnBackKeyPressListener; 18 | 19 | public SearchEditText(Context context) { 20 | super(context); 21 | } 22 | 23 | public SearchEditText(Context context, AttributeSet attrs) { 24 | super(context, attrs); 25 | } 26 | 27 | public SearchEditText(Context context, AttributeSet attrs, int defStyleAttr) { 28 | super(context, attrs, defStyleAttr); 29 | } 30 | 31 | @Override 32 | public boolean onKeyPreIme(int keyCode, KeyEvent event) { 33 | if (keyCode == KeyEvent.KEYCODE_BACK && mOnBackKeyPressListener != null) { 34 | return mOnBackKeyPressListener.OnBackKeyEvent(keyCode, event); 35 | } 36 | return super.onKeyPreIme(keyCode, event); 37 | } 38 | 39 | public void setOnBackKeyListener(OnBackKeyPressListener onBackKeyPressListener) { 40 | this.mOnBackKeyPressListener = onBackKeyPressListener; 41 | } 42 | 43 | public interface OnBackKeyPressListener { 44 | boolean OnBackKeyEvent(int keyCode, KeyEvent event); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /material-searchview/src/main/java/ru/shmakinv/android/widget/material/searchview/SearchView.java: -------------------------------------------------------------------------------- 1 | package ru.shmakinv.android.widget.material.searchview; 2 | 3 | import android.app.Activity; 4 | import android.app.Dialog; 5 | import android.app.FragmentManager; 6 | import android.content.DialogInterface; 7 | import android.content.Intent; 8 | import android.graphics.Rect; 9 | import android.graphics.Typeface; 10 | import android.graphics.drawable.ColorDrawable; 11 | import android.os.Build; 12 | import android.os.Bundle; 13 | import android.os.Handler; 14 | import android.speech.RecognizerIntent; 15 | import android.support.annotation.NonNull; 16 | import android.support.annotation.Nullable; 17 | import android.support.v7.widget.CardView; 18 | import android.support.v7.widget.RecyclerView; 19 | import android.text.Editable; 20 | import android.view.Gravity; 21 | import android.view.KeyEvent; 22 | import android.view.LayoutInflater; 23 | import android.view.MenuItem; 24 | import android.view.MotionEvent; 25 | import android.view.View; 26 | import android.view.ViewGroup; 27 | import android.view.Window; 28 | import android.view.WindowManager; 29 | import android.view.animation.LinearInterpolator; 30 | import android.widget.FrameLayout; 31 | import android.widget.ImageButton; 32 | import android.widget.LinearLayout; 33 | import android.widget.RelativeLayout; 34 | 35 | import com.devspark.robototextview.RobotoTypefaces; 36 | import com.transitionseverywhere.TransitionManager; 37 | import com.transitionseverywhere.TransitionSet; 38 | 39 | import java.util.List; 40 | 41 | import ru.shmakinv.android.widget.material.searchview.transition.SizeTransition; 42 | 43 | /** 44 | * SearchView 45 | * 46 | * @author Vyacheslav Shmakin 47 | * @version 19.04.2017 48 | */ 49 | public class SearchView extends BaseRestoreInstanceFragment implements 50 | DialogInterface.OnShowListener, 51 | SearchEditText.OnBackKeyPressListener, 52 | View.OnKeyListener { 53 | 54 | public static final int RECOGNIZER_CODE = 1024; 55 | private static final long SPEECH_RECOGNITION_DELAY = 300L; 56 | 57 | private RelativeLayout mRoot; 58 | private RelativeLayout mSearchRegion; 59 | private LinearLayout mSuggestionsRegion; 60 | private CardView mSearchOverlay; 61 | private ImageButton mNavBackBtn; 62 | private ImageButton mCloseVoiceBtn; 63 | private SearchEditText mSearchEditText; 64 | private RecyclerView mSuggestionsView; 65 | private RecyclerView.Adapter mAdapter; 66 | private RecyclerView.ItemDecoration mDecoration; 67 | 68 | private OnQueryTextListener mOnQueryTextListener; 69 | private OnVisibilityChangeListener mOnVisibilityChangeListener; 70 | 71 | private boolean mShowSearchAnimationFinished = false; 72 | private boolean mSpeechRecognized = false; 73 | 74 | @NonNull 75 | public static SearchView getInstance(@NonNull Activity activity) { 76 | SearchView searchView = (SearchView) activity.getFragmentManager().findFragmentByTag(DIALOG_TAG); 77 | return searchView != null ? searchView : new SearchView(); 78 | } 79 | 80 | public SearchView() { 81 | } 82 | 83 | @Override 84 | public View onCreateView(final LayoutInflater inflater, final ViewGroup container, 85 | final Bundle savedInstanceState) { 86 | final View dialogLayout = inflater.inflate(R.layout.search_view_layout, container, true); 87 | initViews(dialogLayout); 88 | initWindowParams(); 89 | return dialogLayout; 90 | } 91 | 92 | private void initViews(@NonNull final View layout) { 93 | mRoot = (RelativeLayout) layout.findViewById(R.id.root); 94 | mSearchOverlay = (CardView) layout.findViewById(R.id.search_overlay); 95 | mNavBackBtn = (ImageButton) layout.findViewById(R.id.ibtn_navigation_back); 96 | mCloseVoiceBtn = (ImageButton) layout.findViewById(R.id.ibtn_voice_close); 97 | mSearchEditText = (SearchEditText) layout.findViewById(R.id.et_search_text); 98 | mSearchRegion = (RelativeLayout) layout.findViewById(R.id.search_region); 99 | mSuggestionsRegion = (LinearLayout) layout.findViewById(R.id.suggestions_region); 100 | mSuggestionsView = (RecyclerView) layout.findViewById(R.id.suggestion_list); 101 | if (mAdapter != null) { 102 | mSuggestionsView.setAdapter(mAdapter); 103 | } 104 | mSuggestionsView.setLayoutManager(new VerticalLinearLayoutManager(getActivity())); 105 | 106 | if (mDecoration != null) { 107 | mSuggestionsView.removeItemDecoration(mDecoration); 108 | mSuggestionsView.addItemDecoration(mDecoration); 109 | } 110 | 111 | Typeface typeface = RobotoTypefaces.obtainTypeface( 112 | getActivity().getApplicationContext(), 113 | this.mTypefaceValue); 114 | RobotoTypefaces.setUpTypeface(mSearchEditText, typeface); 115 | 116 | mSearchEditText.setText(mQuery); 117 | mSearchEditText.setHint(mHint); 118 | if (mSelection == -1) { 119 | if (mQuery != null) { 120 | mSearchEditText.setSelection(mQuery.length()); 121 | } 122 | } else { 123 | mSearchEditText.setSelection(mSelection); 124 | } 125 | } 126 | 127 | private void initWindowParams() { 128 | Dialog dialog = getDialog(); 129 | Window window = null; 130 | if (dialog != null) { 131 | window = dialog.getWindow(); 132 | } 133 | 134 | if (dialog == null || window == null) { 135 | return; 136 | } 137 | 138 | window.requestFeature(Window.FEATURE_NO_TITLE); 139 | window.setBackgroundDrawable(new ColorDrawable()); 140 | window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); 141 | 142 | WindowManager.LayoutParams params = window.getAttributes(); 143 | params.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL; 144 | params.x = 0; 145 | params.y = 0; 146 | params.width = ViewGroup.LayoutParams.MATCH_PARENT; 147 | params.height = ViewGroup.LayoutParams.MATCH_PARENT; 148 | params.windowAnimations = R.style.NoAnimationWindow; 149 | 150 | window.setAttributes(params); 151 | window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 152 | dialog.setCanceledOnTouchOutside(false); 153 | dialog.setOnShowListener(this); 154 | } 155 | 156 | @Override 157 | public void onShow(DialogInterface dialog) { 158 | if (!mVisible) { 159 | mVisible = true; 160 | if (mOnVisibilityChangeListener != null) { 161 | mOnVisibilityChangeListener.onShow(); 162 | } 163 | } 164 | animateShow(mSearchOverlay, mSearchRegion, mMenuItemId); 165 | } 166 | 167 | @Override 168 | public void dismiss() { 169 | onClose(); 170 | } 171 | 172 | @Override 173 | public void onDismiss(DialogInterface dialog) { 174 | super.onDismiss(dialog); 175 | this.mSearchEditText.getText().clear(); 176 | this.mAdapter = null; 177 | } 178 | 179 | @Override 180 | public void onResume() { 181 | super.onResume(); 182 | mSearchEditText.addTextChangedListener(mSearchTextWatcher); 183 | mSearchEditText.setOnBackKeyListener(this); 184 | mSearchEditText.setOnKeyListener(this); 185 | mCloseVoiceBtn.setOnClickListener(mCloseVoiceClickListener); 186 | mNavBackBtn.setOnClickListener(mNavigationBackClickListener); 187 | mSearchEditText.setCustomSelectionActionModeCallback(mNotAllowedToEditCallback); 188 | setUpDialogTouchListener(mOnOutsideTouchListener); 189 | 190 | updateCloseVoiceState(mQuery); 191 | if (mSpeechRecognized) { 192 | mSpeechRecognized = false; 193 | new Handler().postDelayed(new Runnable() { 194 | @Override 195 | public void run() { 196 | setQuery(mQuery, true); 197 | } 198 | }, SPEECH_RECOGNITION_DELAY); 199 | } 200 | } 201 | 202 | @Override 203 | public void onPause() { 204 | super.onPause(); 205 | mSearchEditText.setOnKeyListener(null); 206 | mSearchEditText.removeTextChangedListener(mSearchTextWatcher); 207 | mSearchEditText.setOnBackKeyListener(null); 208 | mCloseVoiceBtn.setOnClickListener(null); 209 | mNavBackBtn.setOnClickListener(null); 210 | mSearchEditText.setCustomSelectionActionModeCallback(null); 211 | setUpDialogTouchListener(null); 212 | } 213 | 214 | @Nullable 215 | private View getDecorView() { 216 | Dialog dialog = getDialog(); 217 | if (dialog != null) { 218 | Window window = dialog.getWindow(); 219 | if (window != null) { 220 | return window.getDecorView(); 221 | } 222 | } 223 | return null; 224 | } 225 | 226 | private void setUpDialogTouchListener(View.OnTouchListener listener) { 227 | View view = getDecorView(); 228 | if (view != null) { 229 | view.setOnTouchListener(listener); 230 | } 231 | } 232 | 233 | @Override 234 | public void onSaveInstanceState(Bundle outState) { 235 | mSelection = mSearchEditText.getSelectionStart(); 236 | super.onSaveInstanceState(outState); 237 | } 238 | 239 | private void onClose() { 240 | if (mOnVisibilityChangeListener != null) { 241 | mOnVisibilityChangeListener.onDismiss(); 242 | } 243 | 244 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP 245 | && mAdapter != null && mAdapter.getItemCount() > 0) { 246 | 247 | TransitionSet transition = new SizeTransition() 248 | .setDuration(ANIMATOR_MIN_SUGGESTION_DURATION) 249 | .setInterpolator(new LinearInterpolator()) 250 | .addListener(mSuggestionsDismissListener); 251 | 252 | TransitionManager.beginDelayedTransition(mSearchOverlay, transition); 253 | 254 | mSuggestionsRegion.setLayoutParams(new FrameLayout.LayoutParams( 255 | FrameLayout.LayoutParams.MATCH_PARENT, 256 | 0)); 257 | } else { 258 | animateDismiss(mSearchOverlay, mSearchRegion, mMenuItemId); 259 | } 260 | } 261 | 262 | @Override 263 | public boolean OnBackKeyEvent(int keyCode, KeyEvent event) { 264 | if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { 265 | onClose(); 266 | return true; 267 | } 268 | return false; 269 | } 270 | 271 | @Override 272 | public void show(@NonNull FragmentManager manager) { 273 | if (isShown()) { 274 | dismissAllowingStateLoss(); 275 | } 276 | super.show(manager); 277 | } 278 | 279 | public void setTypeface(int typefaceValue) { 280 | setupTypeface(typefaceValue); 281 | 282 | Typeface typeface = RobotoTypefaces.obtainTypeface( 283 | getActivity().getApplicationContext(), 284 | typefaceValue); 285 | 286 | if (mSearchEditText != null) { 287 | RobotoTypefaces.setUpTypeface(mSearchEditText, typeface); 288 | } 289 | } 290 | 291 | @SuppressWarnings("SameParameterValue") 292 | public void setSuggestionAdapter(@Nullable RecyclerView.Adapter adapter) { 293 | this.mAdapter = adapter; 294 | if (mSuggestionsView != null) { 295 | mSuggestionsView.setAdapter(this.mAdapter); 296 | if (isShown() && mShowSearchAnimationFinished) { 297 | onShowSearchAnimationEnd(); 298 | } 299 | } 300 | } 301 | 302 | public void addItemDecoration(@NonNull RecyclerView.ItemDecoration decoration) { 303 | if (mSuggestionsView != null) { 304 | if (this.mDecoration != null) { 305 | mSuggestionsView.removeItemDecoration(this.mDecoration); 306 | } 307 | mSuggestionsView.addItemDecoration(decoration); 308 | } 309 | this.mDecoration = decoration; 310 | } 311 | 312 | @Nullable 313 | public RecyclerView.ItemDecoration getItemDecoration() { 314 | return this.mDecoration; 315 | } 316 | 317 | @Nullable 318 | public RecyclerView.Adapter getSuggestionAdapter() { 319 | return this.mAdapter; 320 | } 321 | 322 | public void setQuery(int id) { 323 | setQuery(getString(id)); 324 | } 325 | 326 | public void setQuery(@NonNull String query) { 327 | setQuery(query, false); 328 | } 329 | 330 | public void setQuery(@NonNull String query, boolean submit) { 331 | this.mQuery = query; 332 | this.mSelection = query.length(); 333 | if (mSearchEditText == null) { 334 | return; 335 | } 336 | mSearchEditText.setText(query); 337 | mSearchEditText.setSelection(mSelection); 338 | 339 | if (mOnQueryTextListener != null) { 340 | mOnQueryTextListener.onQueryTextChanged(query); 341 | submit = submit && mOnQueryTextListener.onQueryTextSubmit(query); 342 | } 343 | if (submit) { 344 | submitQuery(); 345 | } 346 | } 347 | 348 | @Nullable 349 | public String getQuery() { 350 | return mQuery; 351 | } 352 | 353 | @Nullable 354 | public String getHint() { 355 | if (mSearchEditText == null) { 356 | return mHint; 357 | } 358 | return mSearchEditText.getHint().toString(); 359 | } 360 | 361 | public void setHint(int id) { 362 | setHint(getString(id)); 363 | } 364 | 365 | public void setHint(@NonNull String hint) { 366 | this.mHint = hint; 367 | if (mSearchEditText != null) { 368 | mSearchEditText.setHint(hint); 369 | } 370 | } 371 | 372 | @Override 373 | protected void animateShow(@NonNull View view, @NonNull View metricsView, int itemId) { 374 | mShowSearchAnimationFinished = false; 375 | super.animateShow(view, metricsView, itemId); 376 | } 377 | 378 | @Override 379 | protected void onShowSearchAnimationEnd() { 380 | mShowSearchAnimationFinished = true; 381 | 382 | if (mAdapter != null && mAdapter.getItemCount() > 0) { 383 | mSuggestionsView.setAdapter(mAdapter); 384 | 385 | int itemHeight = ((VerticalLinearLayoutManager) mSuggestionsView.getLayoutManager()).getChildHeight(); 386 | int itemCount = mAdapter.getItemCount(); 387 | 388 | long duration = Math.max( 389 | ANIMATOR_MIN_SUGGESTION_DURATION, 390 | Math.min(ANIMATOR_MAX_SUGGESTION_DURATION, itemCount * itemHeight)); 391 | 392 | TransitionSet transition = new SizeTransition() 393 | .setDuration(duration) 394 | .setInterpolator(new LinearInterpolator()); 395 | 396 | TransitionManager.beginDelayedTransition(mRoot, transition); 397 | 398 | mSuggestionsRegion.setLayoutParams(new FrameLayout.LayoutParams( 399 | FrameLayout.LayoutParams.MATCH_PARENT, 400 | FrameLayout.LayoutParams.WRAP_CONTENT)); 401 | } 402 | } 403 | 404 | @Override 405 | protected void onSuggestionsDismissed() { 406 | animateDismiss(mSearchOverlay, mSearchRegion, mMenuItemId); 407 | } 408 | 409 | @Override 410 | public boolean onKey(View v, int keyCode, KeyEvent event) { 411 | if (keyCode == KeyEvent.KEYCODE_ENTER 412 | && event.getAction() == KeyEvent.ACTION_UP 413 | && mOnQueryTextListener != null) { 414 | 415 | String query = mSearchEditText.getText().toString(); 416 | setQuery(query, true); 417 | } 418 | return false; 419 | } 420 | 421 | @Override 422 | protected void onQueryTextChanged(@NonNull Editable s) { 423 | mQuery = s.toString(); 424 | updateCloseVoiceState(mQuery); 425 | 426 | if (mOnQueryTextListener != null) { 427 | mOnQueryTextListener.onQueryTextChanged(mQuery); 428 | } 429 | } 430 | 431 | private void updateCloseVoiceState(@Nullable String searchText) { 432 | if (searchText != null && searchText.length() != 0) { 433 | mCloseVoiceBtn.setVisibility(View.VISIBLE); 434 | mCloseVoiceBtn.setImageResource(R.drawable.searchview_button_close); 435 | } else if (!isSpeechRecognitionToolAvailable()) { 436 | mCloseVoiceBtn.setVisibility(View.INVISIBLE); 437 | } else { 438 | mCloseVoiceBtn.setImageResource(R.drawable.searchview_button_voice); 439 | } 440 | } 441 | 442 | @Override 443 | protected void onCloseVoiceClicked() { 444 | if (mSearchEditText != null && mSearchEditText.getText() != null && mSearchEditText.getText().toString().length() != 0) { 445 | mSearchEditText.getText().clear(); 446 | mQuery = ""; 447 | } else if (isSpeechRecognitionToolAvailable()) { 448 | Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 449 | intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 450 | startActivityForResult(intent, RECOGNIZER_CODE); 451 | } 452 | } 453 | 454 | @Override 455 | protected void onNavigationBackClicked() { 456 | onClose(); 457 | } 458 | 459 | @Override 460 | protected void onOutsideTouch(@NonNull View v, @NonNull MotionEvent event) { 461 | if (!mCloseRequested) { 462 | Rect rect = new Rect(); 463 | mSearchOverlay.getHitRect(rect); 464 | 465 | if (!rect.contains((int) event.getX(), (int) event.getY())) { 466 | mCloseRequested = true; 467 | onClose(); 468 | } 469 | } 470 | } 471 | 472 | public void setOnVisibilityChangeListener(OnVisibilityChangeListener listener) { 473 | this.mOnVisibilityChangeListener = listener; 474 | } 475 | 476 | public interface OnVisibilityChangeListener { 477 | void onShow(); 478 | void onDismiss(); 479 | } 480 | 481 | @SuppressWarnings("SameReturnValue") 482 | public boolean onOptionsItemSelected(FragmentManager manager, MenuItem item) { 483 | this.mMenuItemId = item.getItemId(); 484 | show(manager); 485 | return true; 486 | } 487 | 488 | public interface OnQueryTextListener { 489 | boolean onQueryTextSubmit(@NonNull String query); 490 | void onQueryTextChanged(@NonNull String newText); 491 | } 492 | 493 | public void setOnQueryTextListener(OnQueryTextListener listener) { 494 | this.mOnQueryTextListener = listener; 495 | } 496 | 497 | private void submitQuery() { 498 | setSuggestionAdapter(null); 499 | mSearchEditText.clearFocus(); 500 | hideKeyboard(); 501 | dismiss(); 502 | } 503 | 504 | @Override 505 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 506 | if (requestCode == RECOGNIZER_CODE && resultCode == Activity.RESULT_OK) { 507 | List results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); 508 | if (results != null && results.size() > 0) { 509 | mQuery = results.get(0); 510 | mSpeechRecognized = true; 511 | } 512 | } 513 | super.onActivityResult(requestCode, resultCode, data); 514 | } 515 | } -------------------------------------------------------------------------------- /material-searchview/src/main/java/ru/shmakinv/android/widget/material/searchview/SuggestionDismissListener.java: -------------------------------------------------------------------------------- 1 | package ru.shmakinv.android.widget.material.searchview; 2 | 3 | import com.transitionseverywhere.Transition; 4 | 5 | /** 6 | * SuggestionDismissListener 7 | * 8 | * @author Vyacheslav Shmakin 9 | * @version 27.12.2015 10 | */ 11 | abstract class SuggestionDismissListener implements Transition.TransitionListener { 12 | 13 | @Override 14 | public void onTransitionStart(Transition transition) { 15 | 16 | } 17 | 18 | @Override 19 | public void onTransitionEnd(Transition transition) { 20 | onSuggestionDismissed(); 21 | } 22 | 23 | @Override 24 | public void onTransitionCancel(Transition transition) { 25 | 26 | } 27 | 28 | @Override 29 | public void onTransitionPause(Transition transition) { 30 | 31 | } 32 | 33 | @Override 34 | public void onTransitionResume(Transition transition) { 35 | 36 | } 37 | 38 | public abstract void onSuggestionDismissed(); 39 | } 40 | -------------------------------------------------------------------------------- /material-searchview/src/main/java/ru/shmakinv/android/widget/material/searchview/VerticalLinearLayoutManager.java: -------------------------------------------------------------------------------- 1 | package ru.shmakinv.android.widget.material.searchview; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.LinearLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.View; 7 | 8 | /** 9 | * WrapContentLinearLayoutManager 10 | * 11 | * @author Vyacheslav Shmakin 12 | * @version 01.01.2016 13 | */ 14 | class VerticalLinearLayoutManager extends LinearLayoutManager { 15 | 16 | private int mChildHeight; 17 | 18 | public VerticalLinearLayoutManager(Context context) { 19 | super(context, LinearLayoutManager.VERTICAL, false); 20 | } 21 | 22 | @Override 23 | public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, 24 | int widthSpec, int heightSpec) { 25 | super.onMeasure(recycler, state, widthSpec, heightSpec); 26 | mChildHeight = View.MeasureSpec.getSize(heightSpec); 27 | } 28 | 29 | public int getChildHeight() { 30 | return mChildHeight; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /material-searchview/src/main/java/ru/shmakinv/android/widget/material/searchview/transition/EmptyTransition.java: -------------------------------------------------------------------------------- 1 | package ru.shmakinv.android.widget.material.searchview.transition; 2 | 3 | import com.transitionseverywhere.Transition; 4 | import com.transitionseverywhere.TransitionValues; 5 | 6 | /** 7 | * EmptyTransition 8 | * 9 | * @author Vyacheslav Shmakin 10 | * @version 19.04.2017 11 | */ 12 | 13 | public class EmptyTransition extends Transition { 14 | 15 | @Override 16 | public void captureStartValues(TransitionValues transitionValues) { 17 | // ignore 18 | } 19 | 20 | @Override 21 | public void captureEndValues(TransitionValues transitionValues) { 22 | // ignore 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /material-searchview/src/main/java/ru/shmakinv/android/widget/material/searchview/transition/SizeTransition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package ru.shmakinv.android.widget.material.searchview.transition; 18 | 19 | import android.content.Context; 20 | import android.util.AttributeSet; 21 | 22 | import com.transitionseverywhere.ChangeBounds; 23 | import com.transitionseverywhere.TransitionSet; 24 | 25 | /** 26 | * SizeTransition 27 | * 28 | * @author Vyacheslav Shmakin 29 | * @version 19.04.2017 30 | */ 31 | public class SizeTransition extends TransitionSet { 32 | 33 | /** 34 | * Constructs an SizeTransition object, which is a TransitionSet which 35 | * first fades out disappearing targets, then moves and resizes existing 36 | * targets, and finally fades in appearing targets. 37 | */ 38 | public SizeTransition() { 39 | init(); 40 | } 41 | 42 | public SizeTransition(Context context, AttributeSet attrs) { 43 | super(context, attrs); 44 | init(); 45 | } 46 | 47 | private void init() { 48 | setOrdering(ORDERING_TOGETHER); 49 | addTransition(new ChangeBounds()). 50 | addTransition(new EmptyTransition()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /material-searchview/src/main/res/drawable/search_text_cursor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /material-searchview/src/main/res/layout/layout_view_search_view.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 21 | 22 | 26 | 27 | 37 | 38 | 54 | 55 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /material-searchview/src/main/res/layout/search_view_layout.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 22 | 23 | 27 | 28 | 32 | 33 | 45 | 46 | 65 | 66 | 78 | 79 | 82 | 88 | 89 | 94 | 95 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /material-searchview/src/main/res/mipmap-hdpi/ic_arrow_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VyacheslavShmakin/Material-SearchView/59b3edb0f19b1486eeea9304a757a11c0bc91985/material-searchview/src/main/res/mipmap-hdpi/ic_arrow_back.png -------------------------------------------------------------------------------- /material-searchview/src/main/res/mipmap-hdpi/ic_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VyacheslavShmakin/Material-SearchView/59b3edb0f19b1486eeea9304a757a11c0bc91985/material-searchview/src/main/res/mipmap-hdpi/ic_close.png -------------------------------------------------------------------------------- /material-searchview/src/main/res/mipmap-hdpi/ic_keyboard_voice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VyacheslavShmakin/Material-SearchView/59b3edb0f19b1486eeea9304a757a11c0bc91985/material-searchview/src/main/res/mipmap-hdpi/ic_keyboard_voice.png -------------------------------------------------------------------------------- /material-searchview/src/main/res/mipmap-mdpi/ic_arrow_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VyacheslavShmakin/Material-SearchView/59b3edb0f19b1486eeea9304a757a11c0bc91985/material-searchview/src/main/res/mipmap-mdpi/ic_arrow_back.png -------------------------------------------------------------------------------- /material-searchview/src/main/res/mipmap-mdpi/ic_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VyacheslavShmakin/Material-SearchView/59b3edb0f19b1486eeea9304a757a11c0bc91985/material-searchview/src/main/res/mipmap-mdpi/ic_close.png -------------------------------------------------------------------------------- /material-searchview/src/main/res/mipmap-mdpi/ic_keyboard_voice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VyacheslavShmakin/Material-SearchView/59b3edb0f19b1486eeea9304a757a11c0bc91985/material-searchview/src/main/res/mipmap-mdpi/ic_keyboard_voice.png -------------------------------------------------------------------------------- /material-searchview/src/main/res/mipmap-xhdpi/ic_arrow_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VyacheslavShmakin/Material-SearchView/59b3edb0f19b1486eeea9304a757a11c0bc91985/material-searchview/src/main/res/mipmap-xhdpi/ic_arrow_back.png -------------------------------------------------------------------------------- /material-searchview/src/main/res/mipmap-xhdpi/ic_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VyacheslavShmakin/Material-SearchView/59b3edb0f19b1486eeea9304a757a11c0bc91985/material-searchview/src/main/res/mipmap-xhdpi/ic_close.png -------------------------------------------------------------------------------- /material-searchview/src/main/res/mipmap-xhdpi/ic_keyboard_voice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VyacheslavShmakin/Material-SearchView/59b3edb0f19b1486eeea9304a757a11c0bc91985/material-searchview/src/main/res/mipmap-xhdpi/ic_keyboard_voice.png -------------------------------------------------------------------------------- /material-searchview/src/main/res/mipmap-xxhdpi/ic_arrow_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VyacheslavShmakin/Material-SearchView/59b3edb0f19b1486eeea9304a757a11c0bc91985/material-searchview/src/main/res/mipmap-xxhdpi/ic_arrow_back.png -------------------------------------------------------------------------------- /material-searchview/src/main/res/mipmap-xxhdpi/ic_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VyacheslavShmakin/Material-SearchView/59b3edb0f19b1486eeea9304a757a11c0bc91985/material-searchview/src/main/res/mipmap-xxhdpi/ic_close.png -------------------------------------------------------------------------------- /material-searchview/src/main/res/mipmap-xxhdpi/ic_keyboard_voice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VyacheslavShmakin/Material-SearchView/59b3edb0f19b1486eeea9304a757a11c0bc91985/material-searchview/src/main/res/mipmap-xxhdpi/ic_keyboard_voice.png -------------------------------------------------------------------------------- /material-searchview/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | @android:color/white 4 | @android:color/black 5 | #80ff0000 6 | @android:color/holo_red_light 7 | 8 | -------------------------------------------------------------------------------- /material-searchview/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4dp 4 | 16dp 5 | 48dp 6 | 1dp 7 | 8 | -------------------------------------------------------------------------------- /material-searchview/src/main/res/values/drawables.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | @drawable/search_text_cursor 4 | @mipmap/ic_arrow_back 5 | @mipmap/ic_close 6 | @mipmap/ic_keyboard_voice 7 | -------------------------------------------------------------------------------- /material-searchview/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Back 3 | Voice Cancel 4 | Hint 5 | 6 | -------------------------------------------------------------------------------- /material-searchview/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':material-searchview' 2 | --------------------------------------------------------------------------------