├── SparkScreen ├── ic_launcher-web.png ├── libs │ └── android-support-v4.jar ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── values-sw600dp │ │ └── dimens.xml │ ├── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── menu │ │ └── main.xml │ ├── values-sw720dp-land │ │ └── dimens.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── layout │ │ └── activity_main.xml ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── src │ └── com │ │ └── dean │ │ └── sparkscreen │ │ ├── MainActivity.java │ │ ├── SparkView.java │ │ └── SparkManager.java ├── project.properties ├── .classpath ├── proguard-project.txt ├── AndroidManifest.xml ├── build.gradle ├── .project ├── gradlew.bat └── gradlew ├── README.md └── .gitignore /SparkScreen/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a396901990/SparkScreen/HEAD/SparkScreen/ic_launcher-web.png -------------------------------------------------------------------------------- /SparkScreen/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a396901990/SparkScreen/HEAD/SparkScreen/libs/android-support-v4.jar -------------------------------------------------------------------------------- /SparkScreen/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a396901990/SparkScreen/HEAD/SparkScreen/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /SparkScreen/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a396901990/SparkScreen/HEAD/SparkScreen/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /SparkScreen/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a396901990/SparkScreen/HEAD/SparkScreen/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /SparkScreen/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a396901990/SparkScreen/HEAD/SparkScreen/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /SparkScreen/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/a396901990/SparkScreen/HEAD/SparkScreen/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /SparkScreen/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/com/dean/sparkscreen/SparkManager.java=UTF-8 3 | encoding//src/com/dean/sparkscreen/SparkView.java=UTF-8 4 | -------------------------------------------------------------------------------- /SparkScreen/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /SparkScreen/res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SparkScreen/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /SparkScreen/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SparkScreen 5 | Settings 6 | Hello world! 7 | 8 | 9 | -------------------------------------------------------------------------------- /SparkScreen/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Jan 07 00:06:11 CST 2017 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-2.4-all.zip 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SparkScreen 2 | ============ 3 | 通过SurfaceView模拟火花粒子的滑动喷射效果 4 | 5 | 详细介绍请参考我的Blog[http://blog.csdn.net/a396901990/article/details/43944761] 6 | 7 | 效果如下: 8 | ![图1](http://img.my.csdn.net/uploads/201502/25/1424878762_9911.gif) 9 | ![图2](http://img.my.csdn.net/uploads/201502/25/1424878761_1845.gif) 10 | -------------------------------------------------------------------------------- /SparkScreen/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /SparkScreen/res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /SparkScreen/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | .metadata 28 | -------------------------------------------------------------------------------- /SparkScreen/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /SparkScreen/src/com/dean/sparkscreen/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.dean.sparkscreen; 2 | 3 | import android.os.Bundle; 4 | import android.app.Activity; 5 | 6 | /** 7 | * @author Dean Guo 8 | **/ 9 | public class MainActivity extends Activity { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | SparkView sparkView = new SparkView(this); 15 | setContentView(sparkView); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /SparkScreen/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | -------------------------------------------------------------------------------- /SparkScreen/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /SparkScreen/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /SparkScreen/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /SparkScreen/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /SparkScreen/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /SparkScreen/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:1.3.0' 7 | } 8 | } 9 | apply plugin: 'android' 10 | 11 | dependencies { 12 | compile fileTree(dir: 'libs', include: '*.jar') 13 | } 14 | 15 | android { 16 | compileSdkVersion 19 17 | buildToolsVersion "25.0.1" 18 | 19 | sourceSets { 20 | main { 21 | manifest.srcFile 'AndroidManifest.xml' 22 | java.srcDirs = ['src'] 23 | resources.srcDirs = ['src'] 24 | aidl.srcDirs = ['src'] 25 | renderscript.srcDirs = ['src'] 26 | res.srcDirs = ['res'] 27 | assets.srcDirs = ['assets'] 28 | } 29 | 30 | // Move the tests to tests/java, tests/res, etc... 31 | instrumentTest.setRoot('tests') 32 | 33 | // Move the build types to build-types/ 34 | // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... 35 | // This moves them out of them default location under src//... which would 36 | // conflict with src/ being used by the main source set. 37 | // Adding new build types or product flavors should be accompanied 38 | // by a similar customization. 39 | debug.setRoot('build-types/debug') 40 | release.setRoot('build-types/release') 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /SparkScreen/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | SparkScreen 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.andmore.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.andmore.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | com.android.ide.eclipse.adt.ResourceManagerBuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.PreCompilerBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.jdt.core.javabuilder 30 | 31 | 32 | 33 | 34 | com.android.ide.eclipse.adt.ApkBuilder 35 | 36 | 37 | 38 | 39 | org.eclipse.andmore.ApkBuilder 40 | 41 | 42 | 43 | 44 | 45 | org.eclipse.andmore.AndroidNature 46 | com.android.ide.eclipse.adt.AndroidNature 47 | org.eclipse.jdt.core.javanature 48 | 49 | 50 | -------------------------------------------------------------------------------- /SparkScreen/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 | -------------------------------------------------------------------------------- /SparkScreen/src/com/dean/sparkscreen/SparkView.java: -------------------------------------------------------------------------------- 1 | package com.dean.sparkscreen; 2 | 3 | import java.util.Date; 4 | 5 | import android.annotation.SuppressLint; 6 | import android.app.Activity; 7 | import android.content.Context; 8 | import android.graphics.Canvas; 9 | import android.graphics.Color; 10 | import android.graphics.PorterDuff; 11 | import android.util.DisplayMetrics; 12 | import android.view.MotionEvent; 13 | import android.view.SurfaceHolder; 14 | import android.view.SurfaceView; 15 | 16 | /** 17 | * @author Dean Guo 18 | **/ 19 | public class SparkView 20 | extends SurfaceView 21 | implements SurfaceHolder.Callback, Runnable 22 | { 23 | 24 | private SurfaceHolder mHolder; 25 | 26 | private Canvas mCanvas; 27 | 28 | private boolean isRun; 29 | 30 | private SparkManager sparkManager; 31 | 32 | // 当前触摸点X,Y坐标 33 | private double X, Y; 34 | 35 | // 屏幕宽高 36 | public static int WIDTH, HEIGHT; 37 | 38 | public SparkView( Context context ) 39 | { 40 | super(context); 41 | // 关闭硬件加速 42 | setLayerType(LAYER_TYPE_SOFTWARE, null); 43 | 44 | // 设置视图宽高(像素) 45 | DisplayMetrics metric = new DisplayMetrics(); 46 | ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metric); 47 | WIDTH = metric.widthPixels; 48 | HEIGHT = metric.heightPixels; 49 | 50 | // 火花管理器 51 | sparkManager = new SparkManager(); 52 | 53 | mHolder = this.getHolder(); 54 | mHolder.addCallback(this); 55 | } 56 | 57 | @Override 58 | public void run() 59 | { 60 | 61 | // 火花数组 62 | int[][] sparks = new int[400][10]; 63 | 64 | Date date = null; 65 | while (isRun) 66 | { 67 | date = new Date(); 68 | try 69 | { 70 | mCanvas = mHolder.lockCanvas(null); 71 | if (mCanvas != null) 72 | { 73 | synchronized (mHolder) 74 | { 75 | // 清屏 76 | mCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); 77 | 78 | // 循环绘制所有火花 79 | for (int[] n : sparks) 80 | { 81 | n = sparkManager.drawSpark(mCanvas, (int) X, (int) Y, n); 82 | } 83 | 84 | // 控制帧数 85 | Thread.sleep(Math.max(0, 30 - (new Date().getTime() - date.getTime()))); 86 | } 87 | } 88 | } 89 | catch (Exception e) 90 | { 91 | e.printStackTrace(); 92 | } 93 | finally 94 | { 95 | if (mCanvas != null) 96 | { 97 | mHolder.unlockCanvasAndPost(mCanvas); 98 | } 99 | } 100 | } 101 | } 102 | 103 | @SuppressLint("ClickableViewAccessibility") 104 | @Override 105 | public boolean onTouchEvent( MotionEvent event ) 106 | { 107 | switch (event.getPointerCount()) 108 | { 109 | // 单点触摸 110 | case 1: 111 | switch (event.getAction()) 112 | { 113 | case MotionEvent.ACTION_DOWN: 114 | case MotionEvent.ACTION_MOVE: 115 | sparkManager.isActive = true; 116 | X = event.getX(); 117 | Y = event.getY(); 118 | break; 119 | case MotionEvent.ACTION_UP: 120 | sparkManager.isActive = false; 121 | break; 122 | default: 123 | break; 124 | } 125 | break; 126 | } 127 | 128 | return true; 129 | } 130 | 131 | // Surface的大小发生改变时调用 132 | @Override 133 | public void surfaceChanged( SurfaceHolder holder, int format, int width, int height ) 134 | { 135 | drawBackgound(); 136 | } 137 | 138 | // Surface创建时激发,一般在这里调用画面的线程 139 | @Override 140 | public void surfaceCreated( SurfaceHolder holder ) 141 | { 142 | isRun = true; 143 | new Thread(this).start(); 144 | } 145 | 146 | // 销毁时激发,一般在这里将画面的线程停止、释放。 147 | @Override 148 | public void surfaceDestroyed( SurfaceHolder argholder0 ) 149 | { 150 | isRun = false; 151 | } 152 | 153 | private void drawBackgound() 154 | { 155 | mCanvas = mHolder.lockCanvas(); 156 | mCanvas.drawColor(Color.BLACK); 157 | mHolder.unlockCanvasAndPost(mCanvas); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /SparkScreen/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 | -------------------------------------------------------------------------------- /SparkScreen/src/com/dean/sparkscreen/SparkManager.java: -------------------------------------------------------------------------------- 1 | package com.dean.sparkscreen; 2 | 3 | import java.util.Random; 4 | 5 | import android.graphics.BlurMaskFilter; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.Paint; 9 | import android.graphics.Point; 10 | 11 | /** 12 | * @author Dean Guo 13 | **/ 14 | public class SparkManager 15 | { 16 | 17 | // 画笔对象 18 | private Paint mSparkPaint; 19 | 20 | // 当前触摸位置 21 | private int X, Y; 22 | 23 | // 花火半径 24 | private float radius = 0; 25 | 26 | // 火花喷射距离 27 | private float mDistance = 0; 28 | 29 | // 当前喷射距离 30 | private float mCurDistance = 0; 31 | 32 | // 火花半径 33 | private static final float SPARK_RADIUS = 2.0F; 34 | 35 | // 火花外侧阴影大小 36 | private static final float BLUR_SIZE = 5.0F; 37 | 38 | // 每帧速度 39 | private static final float PER_SPEED_SEC = 1.0F; 40 | 41 | // 随机数 42 | private Random mRandom = new Random(); 43 | 44 | // 火花的起始点,终点,塞贝儿曲线拐点1,塞贝儿曲线拐点2 45 | private Point start, end, c1, c2; 46 | 47 | // 是否是激活状态 48 | public boolean isActive = false; 49 | 50 | public SparkManager() 51 | { 52 | // 初始化画笔 53 | setSparkPaint(); 54 | } 55 | 56 | public int[] drawSpark( Canvas canvas, int x, int y, int[] store ) 57 | { 58 | 59 | this.X = x; 60 | this.Y = y; 61 | this.mCurDistance = store[0]; 62 | this.mDistance = store[1]; 63 | 64 | // 初始化火花 65 | if (mCurDistance == mDistance && isActive) 66 | { 67 | mDistance = getRandom(SparkView.WIDTH / 4, mRandom.nextInt(15)) + 1; 68 | mCurDistance = 0; 69 | 70 | start = new Point(X, Y); 71 | end = getRandomPoint(start.x, start.y, (int) mDistance); 72 | c1 = getRandomPoint(start.x, start.y, mRandom.nextInt(SparkView.WIDTH / 16)); 73 | c2 = getRandomPoint(end.x, end.y, mRandom.nextInt(SparkView.WIDTH / 16)); 74 | } 75 | // 恢复火花路径 76 | else 77 | { 78 | start.set(store[2], store[3]); 79 | end.set(store[4], store[5]); 80 | c1.set(store[6], store[7]); 81 | c2.set(store[8], store[9]); 82 | } 83 | 84 | // 更新火花路径 85 | updateSparkPath(); 86 | // 计算塞贝儿曲线的当前点 87 | Point bezierPoint = CalculateBezierPoint(mCurDistance / mDistance, start, c1, c2, end); 88 | // 设置随机颜色 89 | mSparkPaint.setColor(Color.argb(255, mRandom.nextInt(128) + 128, mRandom.nextInt(128) + 128, mRandom.nextInt(128) + 128)); 90 | // 画花火 91 | canvas.drawCircle(bezierPoint.x, bezierPoint.y, radius, mSparkPaint); 92 | 93 | 94 | // 重置火花状态 95 | if (mCurDistance == mDistance) 96 | { 97 | store[0] = 0; 98 | store[1] = 0; 99 | } 100 | // 保持花火的状态 101 | else 102 | { 103 | store[0] = (int) mCurDistance; 104 | store[1] = (int) mDistance; 105 | store[2] = (int) start.x; 106 | store[3] = (int) start.y; 107 | store[4] = (int) end.x; 108 | store[5] = (int) end.y; 109 | store[6] = (int) c1.x; 110 | store[7] = (int) c1.y; 111 | store[8] = (int) c2.x; 112 | store[9] = (int) c2.y; 113 | } 114 | 115 | return store; 116 | } 117 | 118 | /** 119 | * 更新火花路径 120 | */ 121 | private void updateSparkPath() 122 | { 123 | mCurDistance += PER_SPEED_SEC; 124 | // 前半段 125 | if (mCurDistance < (mDistance / 2) && (mCurDistance != 0)) 126 | { 127 | radius = SPARK_RADIUS * (mCurDistance / (mDistance / 2)); 128 | } 129 | // 后半段 130 | else if (mCurDistance > (mDistance / 2) && (mCurDistance < mDistance)) 131 | { 132 | radius = SPARK_RADIUS - SPARK_RADIUS * ((mCurDistance / (mDistance / 2)) - 1); 133 | } 134 | // 完成 135 | else if (mCurDistance >= mDistance) 136 | { 137 | mCurDistance = 0; 138 | mDistance = 0; 139 | radius = 0; 140 | } 141 | } 142 | 143 | /** 144 | * 根据基准点获取指定范围为半径的随机点 145 | */ 146 | private Point getRandomPoint( int baseX, int baseY, int r ) 147 | { 148 | if(r<=0){ 149 | r = 1 ; 150 | } 151 | int x = mRandom.nextInt(r); 152 | int y = (int) Math.sqrt(r * r - x * x); 153 | 154 | x = baseX + getRandomPNValue(x); 155 | y = baseY + getRandomPNValue(y); 156 | 157 | return new Point(x, y); 158 | } 159 | 160 | /** 161 | * 根据range范围,和chance几率。返回一个随机值 162 | */ 163 | private int getRandom( int range ,int chance) 164 | { 165 | int num = 0; 166 | switch (chance) 167 | { 168 | case 0: 169 | num = mRandom.nextInt(range); 170 | break; 171 | default: 172 | num = mRandom.nextInt(range / 4); 173 | break; 174 | } 175 | 176 | return num; 177 | } 178 | 179 | /** 180 | * 获取随机正负数 181 | */ 182 | private int getRandomPNValue( int value ) 183 | { 184 | return mRandom.nextBoolean() ? value : 0 - value; 185 | } 186 | 187 | /** 188 | * 计算塞贝儿曲线 189 | * 190 | * @param t 时间,范围0-1 191 | * @param s 起始点 192 | * @param c1 拐点1 193 | * @param c2 拐点2 194 | * @param e 终点 195 | * @return 塞贝儿曲线在当前时间下的点 196 | */ 197 | private Point CalculateBezierPoint( float t, Point s, Point c1, Point c2, Point e ) 198 | { 199 | float u = 1 - t; 200 | float tt = t * t; 201 | float uu = u * u; 202 | float uuu = uu * u; 203 | float ttt = tt * t; 204 | 205 | Point p = new Point((int) (s.x * uuu), (int) (s.y * uuu)); 206 | p.x += 3 * uu * t * c1.x; 207 | p.y += 3 * uu * t * c1.y; 208 | p.x += 3 * u * tt * c2.x; 209 | p.y += 3 * u * tt * c2.y; 210 | p.x += ttt * e.x; 211 | p.y += ttt * e.y; 212 | 213 | return p; 214 | } 215 | 216 | /** 217 | * 设置画笔 218 | */ 219 | private void setSparkPaint() 220 | { 221 | this.mSparkPaint = new Paint(); 222 | // 打开抗锯齿 223 | this.mSparkPaint.setAntiAlias(true); 224 | /* 225 | * 设置画笔样式为填充 Paint.Style.STROKE:描边 Paint.Style.FILL_AND_STROKE:描边并填充 226 | * Paint.Style.FILL:填充 227 | */ 228 | this.mSparkPaint.setDither(true); 229 | this.mSparkPaint.setStyle(Paint.Style.FILL); 230 | // 设置外围模糊效果 231 | this.mSparkPaint.setMaskFilter(new BlurMaskFilter(BLUR_SIZE, BlurMaskFilter.Blur.SOLID)); 232 | } 233 | } 234 | --------------------------------------------------------------------------------