├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── jove │ │ │ │ └── starsky │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── jove │ │ │ └── starsky │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── jove │ │ └── starsky │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── starskylib ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ ├── strings.xml │ │ │ │ └── attrs.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── jove │ │ │ └── starskylib │ │ │ ├── model │ │ │ ├── Meteor.java │ │ │ └── Star.java │ │ │ └── StarSkyView.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── jove │ │ │ └── starskylib │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── jove │ │ └── starskylib │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── pictures └── demo.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /starskylib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':starskylib' 2 | -------------------------------------------------------------------------------- /pictures/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianwuch/StarSky/HEAD/pictures/demo.gif -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | StarSky 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianwuch/StarSky/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /starskylib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Star Sky Lib 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianwuch/StarSky/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianwuch/StarSky/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianwuch/StarSky/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianwuch/StarSky/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianwuch/StarSky/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianwuch/StarSky/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianwuch/StarSky/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /starskylib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianwuch/StarSky/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianwuch/StarSky/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianwuch/StarSky/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /starskylib/src/main/java/com/jove/starskylib/model/Meteor.java: -------------------------------------------------------------------------------- 1 | package com.jove.starskylib.model; 2 | 3 | /** 4 | * Created by jianw on 18-4-21. 5 | */ 6 | 7 | public class Meteor { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3f51b5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Apr 24 20:59:11 CST 2018 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-4.4-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/jove/starsky/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jove.starsky; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | public class MainActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_main); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /starskylib/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/test/java/com/jove/starsky/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.jove.starsky; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /starskylib/src/test/java/com/jove/starskylib/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.jove.starskylib; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /starskylib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/jove/starsky/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.jove.starsky; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.jove.starsky", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /starskylib/src/androidTest/java/com/jove/starskylib/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.jove.starskylib; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.jove.starskylib.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /starskylib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | group='com.github.jianwuch' 5 | 6 | android { 7 | compileSdkVersion 26 8 | 9 | 10 | 11 | defaultConfig { 12 | minSdkVersion 15 13 | targetSdkVersion 26 14 | versionCode 1 15 | versionName "1.0" 16 | 17 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 18 | 19 | } 20 | 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | 28 | } 29 | 30 | dependencies { 31 | implementation fileTree(dir: 'libs', include: ['*.jar']) 32 | 33 | implementation 'com.android.support:appcompat-v7:26.0.0-beta1' 34 | testImplementation 'junit:junit:4.12' 35 | androidTestImplementation 'com.android.support.test:runner:0.5' 36 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2' 37 | } 38 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.jove.starsky" 7 | minSdkVersion 15 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(include: ['*.jar'], dir: 'libs') 23 | implementation 'com.android.support:appcompat-v7:26.0.0-beta1' 24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:0.5' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2' 28 | implementation project(':starskylib') 29 | } 30 | -------------------------------------------------------------------------------- /starskylib/src/main/java/com/jove/starskylib/model/Star.java: -------------------------------------------------------------------------------- 1 | package com.jove.starskylib.model; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Color; 5 | import android.graphics.Paint; 6 | import android.graphics.Point; 7 | 8 | /** 9 | * Created by jianw on 18-4-21. 10 | */ 11 | 12 | public class Star { 13 | 14 | //星星大小 15 | public int size; 16 | 17 | //星星的初始化位置 18 | public Point position; 19 | 20 | //动画之后需要画的真实位置 21 | public Point realPosition; 22 | 23 | public Star(int size, Point position) { 24 | this.size = size; 25 | this.position = position; 26 | realPosition = new Point(position); 27 | } 28 | 29 | public void setPosition(Point position) { 30 | this.position = position; 31 | } 32 | 33 | public void draw(Canvas canvas) { 34 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 35 | paint.setColor(Color.WHITE); 36 | paint.setStyle(Paint.Style.FILL); 37 | 38 | //设置光晕 39 | paint.setShadowLayer(2, realPosition.x, realPosition.y, Color.WHITE); 40 | canvas.drawCircle(realPosition.x, realPosition.y, size, paint); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 24 | 25 | 37 | 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 带流星的星空动图 2 | ### 效果 3 | ![image](https://github.com/jianwuch/StarSky/blob/master/pictures/demo.gif?raw=true) 4 | * 两种星星类型(远和近的效果),两种星星大小不一样,移动速度也不一样 5 | * 流星划过的效果 6 | >没有强制背景,这个可以让设计提供,使用场景灵活 7 | 8 | ## 如何使用/How to 9 | ### 1. 在项目build.gradle repositories中使用 10 | Add it in your root build.gradle at the end of repositories: 11 | ``` 12 | allprojects { 13 | repositories { 14 | ... 15 | maven { url 'https://jitpack.io' } 16 | } 17 | } 18 | ``` 19 | ### 2. 增加依赖/Add the dependency 20 | ``` 21 | dependencies { 22 | implementation 'com.github.jianwuch:StarSky:v1.1.0' 23 | } 24 | ``` 25 | 26 | ### 3.XML布局中使用/ Use in layout xml 27 | ```xml 28 | 36 | ``` 37 | >注意:background必须要指定/background is needed 38 | 39 | ### 4.属性介绍 40 | 属性 | 解释 41 | ---|--- 42 | one_cycle_time_ms | 远点星星循环一趟的时间 43 | star_nums | 星星的数量,分为远点星星和近点星星,都是您设置的数量 44 | meteor_head_size | 流星头部火球的大小,不要太大,建议2或4 45 | 46 | ### 5.代码接口/interface 47 | 使用场景:页面切换过程中合理使用以下两个接口,避免页面切换动画造成流星视觉不连续 48 | #### `pauseAnim()`--暂停动画 49 | #### `resumeAnim`--继续动画 50 | #### 接口使用示例 51 | ```java 52 | @Override 53 | protected void onPause() { 54 | super.onPause(); 55 | skyView.canclerAnim(); 56 | } 57 | 58 | @Override 59 | protected void onResume() { 60 | super.onResume(); 61 | skyView.resumeAnim(); 62 | } 63 | ``` 64 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /starskylib/src/main/java/com/jove/starskylib/StarSkyView.java: -------------------------------------------------------------------------------- 1 | package com.jove.starskylib; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.Paint; 9 | import android.graphics.Path; 10 | import android.graphics.Point; 11 | import android.support.annotation.NonNull; 12 | import android.support.annotation.Nullable; 13 | import android.util.AttributeSet; 14 | import android.view.animation.LinearInterpolator; 15 | import android.widget.FrameLayout; 16 | import com.jove.starskylib.model.Star; 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | import java.util.Random; 20 | 21 | /** 22 | * Created by jianw on 18-4-21. 23 | */ 24 | 25 | public class StarSkyView extends FrameLayout { 26 | 27 | private static final int DEFAULT_FAR_STAR_TRANS_TIMES_SECOND = 40 * 1000; 28 | private static final int DEFAULT_METEOR_SPEED = 4;//每次刷新移动的距离 29 | private static final int DEFAULT_METEOR_STAR_SIZE = 2; 30 | private static final int DEFAULT_STAR_NUMS = 10; 31 | private int mHeight, mWidth; 32 | 33 | private ValueAnimator mFarStarAnimator; 34 | private float mTranslationY; 35 | private int meteorTran;//流星水平移动的距离 36 | 37 | //近点和远点星星分别多少个 38 | private int mStarNums; 39 | 40 | //移动一个循环需要的时间 41 | private int mTimes; 42 | private List mNearStarList; 43 | private List mFarStarList; 44 | 45 | //流星 46 | private Paint mMeteorPaint; 47 | private int meteorSize = 100; 48 | private int meteorRadius = DEFAULT_METEOR_STAR_SIZE; 49 | private float mRandomPosition;//流星开始的随机位置 50 | private Random mMeteorRandom; 51 | 52 | private android.os.Handler mHandler; 53 | 54 | public StarSkyView(@NonNull Context context) { 55 | this(context, null); 56 | } 57 | 58 | public StarSkyView(@NonNull Context context, @Nullable AttributeSet attrs) { 59 | this(context, attrs, 0); 60 | } 61 | 62 | public StarSkyView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 63 | super(context, attrs, defStyleAttr); 64 | init(); 65 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.StarSkyView); 66 | meteorRadius = typedArray.getInt(R.styleable.StarSkyView_meteor_head_size, 67 | DEFAULT_METEOR_STAR_SIZE); 68 | mStarNums = typedArray.getInt(R.styleable.StarSkyView_star_nums, DEFAULT_STAR_NUMS); 69 | 70 | mTimes = typedArray.getInt(R.styleable.StarSkyView_one_cycle_time_ms, 71 | DEFAULT_FAR_STAR_TRANS_TIMES_SECOND); 72 | typedArray.recycle(); 73 | } 74 | 75 | private void init() { 76 | mNearStarList = new ArrayList<>(); 77 | mFarStarList = new ArrayList<>(); 78 | 79 | mMeteorPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 80 | mMeteorPaint.setColor(Color.WHITE); 81 | mMeteorPaint.setStyle(Paint.Style.FILL); 82 | mMeteorRandom = new Random(); 83 | 84 | mHandler = new android.os.Handler(); 85 | } 86 | 87 | @Override 88 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 89 | super.onSizeChanged(w, h, oldw, oldh); 90 | //拿到布局的高宽 91 | mHeight = getMeasuredHeight(); 92 | mWidth = getMeasuredWidth(); 93 | 94 | randomNewStar(); 95 | 96 | mHandler.postDelayed(new Runnable() { 97 | @Override 98 | public void run() { 99 | starAnim(); 100 | } 101 | }, 1000); 102 | } 103 | 104 | private void drawMeteor(Canvas canvas) { 105 | 106 | //meteorSize流星的宽度,最开始的时候流星不显示,需要移出去流星的长度距离 107 | float needTransX; 108 | float needTransY; 109 | //float scal = 1; 110 | meteorTran += DEFAULT_METEOR_SPEED; 111 | 112 | //mHeight+metrorSize是为了让流星整个完全的滑出去 113 | if (meteorTran >= mHeight + meteorSize) { 114 | 115 | //为了保证流星能够全屏分布,需要考虑左下角的情况 116 | mRandomPosition = mMeteorRandom.nextInt(mWidth + mHeight); 117 | mRandomPosition -= mHeight; 118 | meteorTran = 0; 119 | } 120 | needTransX = (meteorTran + mRandomPosition); 121 | needTransY = meteorTran - meteorSize; 122 | //if (meteorTran <= mHeight * (2 / 3.0f)) { 123 | // scal = (float) (0.5 + 0.5 * meteorTran / (mHeight * (2 / 3.0f))); 124 | //} 125 | 126 | canvas.save(); 127 | //canvas.scale(scal, scal, meteorSize / 2, meteorSize / 2); 128 | canvas.translate(needTransX, needTransY); 129 | 130 | canvas.drawCircle(meteorSize - meteorRadius, meteorSize - meteorRadius, meteorRadius, 131 | mMeteorPaint); 132 | Path triangle = new Path(); 133 | triangle.lineTo(meteorSize - meteorRadius, (meteorSize - (meteorRadius * 2))); 134 | triangle.lineTo((meteorSize - (meteorRadius * 2)), meteorSize - meteorRadius); 135 | triangle.close(); 136 | 137 | canvas.drawPath(triangle, mMeteorPaint); 138 | 139 | canvas.restore(); 140 | } 141 | 142 | /** 143 | * 实现星星的从右往左动画 144 | */ 145 | private void starAnim() { 146 | if (null == mFarStarAnimator) { 147 | mFarStarAnimator = ValueAnimator.ofFloat(0, 1); 148 | mFarStarAnimator.setRepeatCount(ValueAnimator.INFINITE);//设置无限重复 149 | mFarStarAnimator.setRepeatMode(ValueAnimator.RESTART);//设置重复模式 150 | mFarStarAnimator.setInterpolator(new LinearInterpolator()); 151 | mFarStarAnimator.setDuration(mTimes); 152 | mFarStarAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 153 | @Override 154 | public void onAnimationUpdate(ValueAnimator animation) { 155 | mTranslationY = (float) animation.getAnimatedValue() * mWidth; 156 | invalidate(); 157 | } 158 | }); 159 | } 160 | mFarStarAnimator.cancel(); 161 | mFarStarAnimator.start(); 162 | } 163 | 164 | @Override 165 | protected void onDraw(Canvas canvas) { 166 | super.onDraw(canvas); 167 | 168 | //绘制星星 169 | DrawStar(canvas); 170 | 171 | //绘制流星 172 | drawMeteor(canvas); 173 | } 174 | 175 | private void DrawStar(Canvas canvas) { 176 | for (int i = 0; i < mNearStarList.size(); i++) { 177 | reComputerStarPosition(mNearStarList.get(i), 2).draw(canvas); 178 | } 179 | 180 | for (int i = 0; i < mFarStarList.size(); i++) { 181 | reComputerStarPosition(mFarStarList.get(i), 1).draw(canvas); 182 | } 183 | } 184 | 185 | @NonNull 186 | private Star reComputerStarPosition(Star star, float rate) { 187 | float realTrans = mTranslationY * rate; 188 | int currentY; 189 | if (realTrans > star.position.x) { 190 | currentY = (int) (mWidth - (realTrans - star.position.x)); 191 | } else { 192 | currentY = (int) (star.position.x - realTrans); 193 | } 194 | 195 | star.realPosition.x = currentY; 196 | 197 | if (star.realPosition.x < 0) { 198 | star.realPosition.x = mWidth + star.realPosition.x; 199 | } 200 | return star; 201 | } 202 | 203 | private void randomNewStar() { 204 | mNearStarList.clear(); 205 | mFarStarList.clear(); 206 | Random rand = new Random(); 207 | for (int i = 0; i < mStarNums; i++) { 208 | int x = rand.nextInt(mWidth); 209 | int y = rand.nextInt(mHeight); 210 | Star star = new Star(2, new Point(x, y)); 211 | mFarStarList.add(star); 212 | } 213 | 214 | for (int i = 0; i < mStarNums; i++) { 215 | int x = rand.nextInt(mWidth); 216 | int y = rand.nextInt(mHeight); 217 | Star star = new Star(4, new Point(x, y)); 218 | mNearStarList.add(star); 219 | } 220 | } 221 | 222 | /** 223 | * 暂停动画 224 | */ 225 | public void pauseAnim() { 226 | if (mFarStarAnimator == null) return; 227 | mFarStarAnimator.pause(); 228 | } 229 | 230 | /** 231 | * 继续动画 232 | */ 233 | public void resumeAnim() { 234 | if (mFarStarAnimator == null) return; 235 | mHandler.postDelayed(new Runnable() { 236 | @Override 237 | public void run() { 238 | mFarStarAnimator.resume(); 239 | } 240 | }, 500); 241 | } 242 | 243 | @Override 244 | protected void onDetachedFromWindow() { 245 | super.onDetachedFromWindow(); 246 | if (mHandler != null) { 247 | mHandler.removeCallbacksAndMessages(null); 248 | } 249 | 250 | if (mFarStarAnimator != null) { 251 | mFarStarAnimator.removeAllUpdateListeners(); 252 | } 253 | } 254 | } 255 | --------------------------------------------------------------------------------