├── settings.gradle ├── docs └── sample.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── sample ├── src │ └── main │ │ ├── ic_launcher-web.png │ │ ├── res │ │ ├── drawable-hdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ └── styles.xml │ │ └── layout │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── me │ │ └── panpf │ │ └── scratch │ │ └── sample │ │ └── MainActivity.java ├── proguard-rules.pro └── build.gradle ├── scratch-award-view ├── project.properties ├── proguard-rules.pro ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── me │ └── panpf │ └── scratch │ └── ScratchAwardView.java ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', "scratch-award-view" 2 | -------------------------------------------------------------------------------- /docs/sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/panpf/scratch-award-view/HEAD/docs/sample.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/panpf/scratch-award-view/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sample/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/panpf/scratch-award-view/HEAD/sample/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/panpf/scratch-award-view/HEAD/sample/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/panpf/scratch-award-view/HEAD/sample/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/panpf/scratch-award-view/HEAD/sample/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/panpf/scratch-award-view/HEAD/sample/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 08 15:20:19 CST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /scratch-award-view/project.properties: -------------------------------------------------------------------------------- 1 | #project 2 | project.name=scratch-award-view 3 | project.groupId=me.panpf 4 | project.artifactId=scratch-award-view 5 | project.packaging=aar 6 | project.siteUrl=https://github.com/panpf/scratch-award-view 7 | project.gitUrl=https://github.com/panpf/scratch-award-view.git 8 | 9 | #javadoc 10 | javadoc.name=ScratchAwardView -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | #*.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Local configuration file (sdk path, etc) 12 | local.properties 13 | 14 | # Eclipse project files 15 | #.classpath 16 | #.project 17 | #.settings/ 18 | bin/ 19 | gen/ 20 | 21 | # Idea files 22 | .idea/ 23 | 24 | # Gradle files 25 | .gradle/ 26 | build/ 27 | 28 | *.iml -------------------------------------------------------------------------------- /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 D:\Program Files\Android\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 | -------------------------------------------------------------------------------- /scratch-award-view/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 D:\Program Files\Android\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 | -------------------------------------------------------------------------------- /scratch-award-view/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion COMPILE_SDK_VERSION.toInteger() 5 | 6 | defaultConfig { 7 | minSdkVersion MIN_SDK_VERSION.toInteger() 8 | targetSdkVersion TARGET_SDK_VERSION.toInteger() 9 | versionCode VERSION_CODE.toInteger() 10 | versionName VERSION_NAME 11 | 12 | consumerProguardFiles 'proguard-rules.pro' 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | apply from: "https://raw.githubusercontent.com/panpf/android-library-publish-to-jcenter/master/bintrayUpload.gradle" 24 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | ScratchAwardView 14 | 15 | -------------------------------------------------------------------------------- /scratch-award-view/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion COMPILE_SDK_VERSION.toInteger() 5 | 6 | defaultConfig { 7 | applicationId "me.panpf.scratch.sample" 8 | 9 | minSdkVersion MIN_SDK_VERSION.toInteger() 10 | targetSdkVersion TARGET_SDK_VERSION.toInteger() 11 | versionCode VERSION_CODE.toInteger() 12 | versionName VERSION_NAME 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | implementation "com.android.support:appcompat-v7:${ANDROID_SUPPORT_LIBRARY_VERSION}" 25 | implementation project(':scratch-award-view') 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | #3F51B5 14 | #303F9F 15 | #FF4081 16 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Settings specified in this file will override any Gradle settings 5 | # configured through the IDE. 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 19 | 20 | COMPILE_SDK_VERSION=25 21 | MIN_SDK_VERSION=10 22 | TARGET_SDK_VERSION=22 23 | 24 | VERSION_CODE=120 25 | VERSION_NAME=1.2.0 26 | 27 | ANDROID_SUPPORT_LIBRARY_VERSION=25.3.0 -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 14 | 15 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 18 | 25 | 26 | 31 | -------------------------------------------------------------------------------- /sample/src/main/java/me/panpf/scratch/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Peng fei Pan 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 me.panpf.scratch.sample; 18 | 19 | import android.os.Bundle; 20 | import android.support.v7.app.AppCompatActivity; 21 | import android.view.View; 22 | 23 | import me.panpf.scratch.ScratchAwardView; 24 | 25 | public class MainActivity extends AppCompatActivity { 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_main); 31 | 32 | final ScratchAwardView scratchAwardView = (ScratchAwardView) findViewById(R.id.rubberView_main); 33 | scratchAwardView.enableAcrossMonitor(findViewById(R.id.text_main), new ScratchAwardView.OnAcrossHintViewListener() { 34 | private boolean across; 35 | 36 | @Override 37 | public void onAcrossHintView(View hintView) { 38 | if (!across) { 39 | across = true; 40 | scratchAwardView.setOnClickListener(new View.OnClickListener() { 41 | @Override 42 | public void onClick(View v) { 43 | finish(); 44 | } 45 | }); 46 | } 47 | } 48 | }); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 停止维护 仅供查考 2 | 3 | # ![logo_image] ScratchAwardView 4 | 5 | ![Platform][platform_image] 6 | [![API][min_api_image]][min_api_link] 7 | 8 | 这是一个刮刮卡组件,用于实现刮奖效果 9 | 10 | ![Sample](docs/sample.png) 11 | 12 | ## 开始使用 13 | 14 | 你只需将 ScratchAwardView 覆盖在中奖提示语之上即可,这样的用法很灵活,因此你可以决定你的中奖提示语是一段文字或者一张图片,如下所示: 15 | 16 | ```xml 17 | 22 | 28 | 29 | 34 | 35 | ``` 36 | 37 | 扩展功能: 38 | * 调用 setMaskImage() 方法自定义遮罩图片,默认的是灰色 39 | * 调用 setStrokeWidth() 方法自定义画笔宽度 40 | * 调用 enableAcrossMonitor() 方法监听用户划过的区域,你可以指定一个隐藏在 ScratchAwardView 下面的视图,当用户划过这个视图的时候就会触发回调 41 | 42 | ## License 43 | Copyright (C) 2017 Peng fei Pan 44 | 45 | Licensed under the Apache License, Version 2.0 (the "License"); 46 | you may not use this file except in compliance with the License. 47 | You may obtain a copy of the License at 48 | 49 | http://www.apache.org/licenses/LICENSE-2.0 50 | 51 | Unless required by applicable law or agreed to in writing, software 52 | distributed under the License is distributed on an "AS IS" BASIS, 53 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 54 | See the License for the specific language governing permissions and 55 | limitations under the License. 56 | 57 | [logo_image]: sample/src/main/res/drawable-mdpi/ic_launcher.png 58 | [platform_image]: https://img.shields.io/badge/Platform-Android-brightgreen.svg 59 | [min_api_image]: https://img.shields.io/badge/API-10%2B-orange.svg 60 | [min_api_link]: https://android-arsenal.com/api?level=10 61 | -------------------------------------------------------------------------------- /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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 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 Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /scratch-award-view/src/main/java/me/panpf/scratch/ScratchAwardView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Peng fei Pan 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 me.panpf.scratch; 18 | 19 | import android.annotation.SuppressLint; 20 | import android.content.Context; 21 | import android.graphics.Bitmap; 22 | import android.graphics.Canvas; 23 | import android.graphics.Color; 24 | import android.graphics.Paint; 25 | import android.graphics.Point; 26 | import android.graphics.PorterDuff; 27 | import android.graphics.PorterDuffXfermode; 28 | import android.graphics.Rect; 29 | import android.graphics.Xfermode; 30 | import android.util.AttributeSet; 31 | import android.view.GestureDetector; 32 | import android.view.MotionEvent; 33 | import android.view.View; 34 | import android.widget.ImageView; 35 | 36 | public class ScratchAwardView extends View { 37 | private Paint drawPaint; 38 | private Bitmap trackBitmap; // 轨迹图片,一会儿要在此图片上画滑动轨迹,然后通过 Xfermode 技术同遮罩层图片融合就能实现涂抹的效果 39 | private Canvas trackBitmapCanvas; 40 | private Xfermode xfermode; 41 | private Paint linePaint; // 触摸轨迹线画笔 42 | 43 | private int defaultMaskColor = Color.LTGRAY; 44 | private Bitmap maskBitmap; // 遮罩层图片 45 | private Rect dstRect; 46 | private Rect srcRect; 47 | 48 | private View hintView; 49 | private OnAcrossHintViewListener onAcrossHintViewListener; 50 | 51 | private GestureDetector gestureDetector; 52 | 53 | public ScratchAwardView(Context context) { 54 | this(context, null, 0); 55 | } 56 | 57 | public ScratchAwardView(Context context, AttributeSet attrs) { 58 | this(context, attrs, 0); 59 | } 60 | 61 | public ScratchAwardView(Context context, AttributeSet attrs, int defStyleAttr) { 62 | super(context, attrs, defStyleAttr); 63 | 64 | drawPaint = new Paint(); 65 | drawPaint.setColor(Color.BLACK); 66 | drawPaint.setFilterBitmap(true); 67 | 68 | linePaint = new Paint(); 69 | linePaint.setColor(Color.BLACK); 70 | linePaint.setStyle(Paint.Style.STROKE); 71 | linePaint.setStrokeJoin(Paint.Join.ROUND); // 前圆角 72 | linePaint.setStrokeCap(Paint.Cap.ROUND); // 后圆角 73 | linePaint.setStrokeWidth(30); // 笔宽 74 | 75 | xfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT); 76 | 77 | gestureDetector = new GestureDetector(getContext(), new EventHandleListener()); 78 | } 79 | 80 | public static Rect computeSrcRect(Point sourceSize, Point targetSize, ImageView.ScaleType scaleType) { 81 | if (scaleType == ImageView.ScaleType.CENTER_INSIDE || scaleType == ImageView.ScaleType.MATRIX || scaleType == ImageView.ScaleType.FIT_XY) { 82 | return new Rect(0, 0, sourceSize.x, sourceSize.y); 83 | } else { 84 | float scale; 85 | if (Math.abs(sourceSize.x - targetSize.x) < Math.abs(sourceSize.y - targetSize.y)) { 86 | scale = (float) sourceSize.x / targetSize.x; 87 | if ((int) (targetSize.y * scale) > sourceSize.y) { 88 | scale = (float) sourceSize.y / targetSize.y; 89 | } 90 | } else { 91 | scale = (float) sourceSize.y / targetSize.y; 92 | if ((int) (targetSize.x * scale) > sourceSize.x) { 93 | scale = (float) sourceSize.x / targetSize.x; 94 | } 95 | } 96 | int srcLeft; 97 | int srcTop; 98 | int srcWidth = (int) (targetSize.x * scale); 99 | int srcHeight = (int) (targetSize.y * scale); 100 | if (scaleType == ImageView.ScaleType.FIT_START) { 101 | srcLeft = 0; 102 | srcTop = 0; 103 | } else if (scaleType == ImageView.ScaleType.FIT_END) { 104 | if (sourceSize.x > sourceSize.y) { 105 | srcLeft = sourceSize.x - srcWidth; 106 | srcTop = 0; 107 | } else { 108 | srcLeft = 0; 109 | srcTop = sourceSize.y - srcHeight; 110 | } 111 | } else { 112 | if (sourceSize.x > sourceSize.y) { 113 | srcLeft = (sourceSize.x - srcWidth) / 2; 114 | srcTop = 0; 115 | } else { 116 | srcLeft = 0; 117 | srcTop = (sourceSize.y - srcHeight) / 2; 118 | } 119 | } 120 | return new Rect(srcLeft, srcTop, srcLeft + srcWidth, srcTop + srcHeight); 121 | } 122 | } 123 | 124 | @Override 125 | protected void onDraw(Canvas canvas) { 126 | super.onDraw(canvas); 127 | @SuppressLint("WrongConstant") 128 | int layerCount = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, 129 | Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); 130 | canvas.drawBitmap(trackBitmap, getPaddingLeft(), getPaddingTop(), drawPaint); 131 | drawPaint.setXfermode(xfermode); 132 | canvas.drawBitmap(maskBitmap, srcRect, dstRect, drawPaint); 133 | drawPaint.setXfermode(null); 134 | if (!isInEditMode()) { 135 | canvas.restoreToCount(layerCount); 136 | } 137 | } 138 | 139 | @Override 140 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 141 | super.onLayout(changed, left, top, right, bottom); 142 | 143 | int width = right - left; 144 | int height = bottom - top; 145 | 146 | // 初始化轨迹图片,稍后将在此图上绘制触摸轨迹 147 | if (trackBitmap == null) { 148 | trackBitmap = Bitmap.createBitmap(width - getPaddingRight() - getPaddingLeft(), height - getPaddingBottom() - getPaddingTop(), Bitmap.Config.ARGB_8888); 149 | trackBitmapCanvas = new Canvas(trackBitmap); 150 | // 如果已经创建了但是宽高有变化就重新创建 151 | } else if (trackBitmap.getWidth() != width - getPaddingRight() - getPaddingLeft() || trackBitmap.getHeight() != height - getPaddingBottom() - getPaddingTop()) { 152 | trackBitmap.recycle(); 153 | trackBitmap = Bitmap.createBitmap(width - getPaddingRight() - getPaddingLeft(), height - getPaddingBottom() - getPaddingTop(), Bitmap.Config.ARGB_8888); 154 | trackBitmapCanvas.setBitmap(trackBitmap); 155 | } 156 | 157 | // 初始化遮罩图片 158 | if (maskBitmap == null) { 159 | maskBitmap = Bitmap.createBitmap(width - getPaddingRight() - getPaddingLeft(), height - getPaddingBottom() - getPaddingTop(), Bitmap.Config.ARGB_8888); 160 | new Canvas(maskBitmap).drawColor(defaultMaskColor); 161 | } 162 | 163 | // 初始化dst位置 164 | if (dstRect == null) { 165 | dstRect = new Rect(getPaddingLeft(), getPaddingTop(), width - getPaddingRight(), height - getPaddingBottom()); 166 | } else { 167 | dstRect.set(getPaddingLeft(), getPaddingTop(), width - getPaddingRight(), height - getPaddingBottom()); 168 | } 169 | 170 | srcRect = computeSrcRect(new Point(maskBitmap.getWidth(), maskBitmap.getHeight()), new Point(dstRect.width(), dstRect.height()), ImageView.ScaleType.CENTER_CROP); 171 | } 172 | 173 | @Override 174 | public boolean onTouchEvent(MotionEvent event) { 175 | return isEnabled() && gestureDetector.onTouchEvent(event); 176 | } 177 | 178 | /** 179 | * 设置遮罩图片 180 | * 181 | * @param maskBitmap 遮罩图片 182 | */ 183 | @SuppressWarnings("unused") 184 | public void setMaskImage(Bitmap maskBitmap) { 185 | this.maskBitmap = maskBitmap; 186 | requestLayout(); 187 | } 188 | 189 | /** 190 | * 设置遮罩图片 191 | * 192 | * @param color 遮罩图片的颜色,稍后将使用此颜色创建一张图片 193 | */ 194 | @SuppressWarnings("unused") 195 | public void setMaskImage(int color) { 196 | this.defaultMaskColor = color; 197 | if (maskBitmap != null) { 198 | if (!maskBitmap.isRecycled()) { 199 | maskBitmap.recycle(); 200 | } 201 | maskBitmap = null; 202 | } 203 | requestLayout(); 204 | } 205 | 206 | /** 207 | * 设置画笔的宽度 208 | * 209 | * @param strokeWidth 画笔的宽度 210 | */ 211 | @SuppressWarnings("unused") 212 | public void setStrokeWidth(int strokeWidth) { 213 | this.linePaint.setStrokeWidth(strokeWidth); 214 | } 215 | 216 | /** 217 | * 激活监听划过提示视图的功能 218 | * 219 | * @param hintView 提示视图,当用户划过此视图的时候就会回调监听器,一般来说此视图应该是隐藏在 {@link ScratchAwardView} 之下的中奖提示视图 220 | * @param onAcrossHintViewListener 当用户划过提示视图的时候就会回调此监听器 221 | */ 222 | public void enableAcrossMonitor(View hintView, OnAcrossHintViewListener onAcrossHintViewListener) { 223 | this.hintView = hintView; 224 | this.onAcrossHintViewListener = onAcrossHintViewListener; 225 | } 226 | 227 | public interface OnAcrossHintViewListener { 228 | void onAcrossHintView(View hintView); 229 | } 230 | 231 | private class EventHandleListener implements GestureDetector.OnGestureListener { 232 | private float downX; 233 | private float downY; 234 | private float moveX; 235 | private float moveY; 236 | private boolean allowAcrossCallback; 237 | private Rect hintViewGlobalVisibleRect; 238 | 239 | @Override 240 | public boolean onDown(MotionEvent event) { 241 | if (getParent() != null) { 242 | getParent().requestDisallowInterceptTouchEvent(true); 243 | } 244 | downX = event.getX(); 245 | downY = event.getY(); 246 | allowAcrossCallback = hintView != null && onAcrossHintViewListener != null; 247 | return true; 248 | } 249 | 250 | @Override 251 | public void onShowPress(MotionEvent e) { 252 | 253 | } 254 | 255 | @Override 256 | public boolean onSingleTapUp(MotionEvent e) { 257 | if (isEnabled() && isClickable()) { 258 | performClick(); 259 | } 260 | return true; 261 | } 262 | 263 | @Override 264 | public boolean onScroll(MotionEvent e1, MotionEvent event, float distanceX, float distanceY) { 265 | moveX = event.getX(); 266 | moveY = event.getY(); 267 | trackBitmapCanvas.drawLine(downX, downY, moveX, moveY, linePaint); 268 | downX = moveX; 269 | downY = moveY; 270 | invalidate(); 271 | 272 | if (allowAcrossCallback) { 273 | if (hintViewGlobalVisibleRect == null) { 274 | hintViewGlobalVisibleRect = new Rect(); 275 | hintView.getGlobalVisibleRect(hintViewGlobalVisibleRect); 276 | } 277 | if (hintViewGlobalVisibleRect.contains((int) event.getRawX(), (int) event.getRawY())) { 278 | onAcrossHintViewListener.onAcrossHintView(hintView); 279 | allowAcrossCallback = false; 280 | } 281 | } 282 | return true; 283 | } 284 | 285 | @Override 286 | public void onLongPress(MotionEvent e) { 287 | } 288 | 289 | @Override 290 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 291 | return false; 292 | } 293 | } 294 | } 295 | --------------------------------------------------------------------------------