├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── assets │ └── weather_scene_slight_snow_day.xml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── harmonywisdom │ │ └── weather │ │ └── animation │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── kit │ │ │ └── weather │ │ │ └── animation │ │ │ ├── MainActivity.java │ │ │ ├── base │ │ │ └── ActorInfo.java │ │ │ ├── utils │ │ │ ├── Actor.java │ │ │ ├── RandomUtils.java │ │ │ ├── RenderThread.java │ │ │ ├── SaxService.java │ │ │ ├── Scene.java │ │ │ ├── SnowFall.java │ │ │ ├── SnowShine.java │ │ │ ├── XMLActorData.java │ │ │ └── XMLContentHandler.java │ │ │ └── view │ │ │ └── SceneSurfaceView.java │ └── res │ │ ├── drawable-hdpi │ │ ├── ic_launcher.png │ │ ├── snowflake_l.png │ │ ├── snowflake_m.png │ │ ├── snowflake_xl.png │ │ └── snowflake_xxl.png │ │ ├── drawable-mdpi │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ │ ├── drawable-xxhdpi │ │ ├── bg_snow_night.jpg │ │ ├── ic_launcher.png │ │ └── snow_light.png │ │ ├── layout │ │ └── activity_main.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── harmonywisdom │ └── weather │ └── animation │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── snowdemo └── snow_demo.gif /.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 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 26 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 53 | 54 | C:\Users\ZhouJing\AppData\Roaming\Subversion 55 | 56 | 57 | 58 | 59 | 60 | 1.8 61 | 62 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WeatherAnimationDemo 2 | 3 | 4 | 模仿墨迹下雪效果 5 | 6 | ![](https://github.com/KitTak/WeatherAnimationDemo/blob/master/snowdemo/snow_demo.gif) 7 | 8 | * 在布局中直接通过自定义 SurfaceView 来绘制提高效率 9 | 10 | 11 | 16 | 17 | 21 | 22 | 23 | 24 | * 通过配置文件来控制雪花降落速度、位置 25 | ``` java 26 | weather_scene_slight_snow_day.xml 27 | ``` 28 | 29 | * SnowFall.java 30 | ``` java 31 | 32 | protected SnowFall(Context context) { 33 | super(context); 34 | // 设置是否使用抗锯齿功能,会消耗较大资源,绘制图形速度会变慢 35 | paint.setAntiAlias(false); 36 | // 如果该项设置为true,则图像在动画进行中会滤掉对Bitmap图像的优化操作,加快显示速度,本设置项依赖于dither和xfermode的设置 37 | paint.setFilterBitmap(true); 38 | // 设定是否使用图像抖动处理,会使绘制出来的图片颜色更加平滑和饱满,图像更加清晰 39 | paint.setDither(true); 40 | try { 41 | listXMLData = SaxService.getInstance().readXML(context, "weather_scene_slight_snow_day.xml"); 42 | } catch (Exception e) { 43 | e.printStackTrace(); 44 | } 45 | getViewSize(context); 46 | loadRainImage(context); 47 | addRandomRain(); 48 | } 49 | 50 | private void snowDown(ActorInfo snow) { 51 | // 雪花的落出屏幕后又让它从顶上下落 52 | if (snow.getX() > screenWidth || snow.getY() > screenHeiht) { 53 | snow.setY(0); 54 | snow.setX(random.nextFloat() * screenWidth); 55 | } 56 | snow.setX(snow.getX() + snow.getOffset());// 下落飘的偏移量 57 | snow.setY(snow.getY() + snow.getSpeed());// 下落的速度 58 | } 59 | ``` 60 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/assets/weather_scene_slight_snow_day.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 13 | 14 | 15 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | defaultConfig { 7 | applicationId "com.kit.weather.animation" 8 | minSdkVersion 14 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | 15 | sourceSets { 16 | main { 17 | manifest.srcFile 'src/main/AndroidManifest.xml' 18 | java.srcDirs = ['src/main/java/'] 19 | res.srcDirs = ['src/main/res'] 20 | jniLibs.srcDirs 'libs' 21 | jni.srcDirs = [] 22 | assets.srcDirs = ['assets'] 23 | } 24 | } 25 | 26 | buildTypes { 27 | release { 28 | minifyEnabled false 29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 30 | } 31 | } 32 | } 33 | 34 | dependencies { 35 | compile fileTree(dir: 'libs', include: ['*.jar']) 36 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 37 | exclude group: 'com.android.support', module: 'support-annotations' 38 | }) 39 | compile 'com.android.support:appcompat-v7:23.4.0' 40 | testCompile 'junit:junit:4.12' 41 | } 42 | -------------------------------------------------------------------------------- /app/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:\adt-bundle-windows-x86_64-20130522\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 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/harmonywisdom/weather/animation/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.harmonywisdom.weather.animation; 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 | * Instrumentation 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.harmonywisdom.weather.animation", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/kit/weather/animation/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.kit.weather.animation; 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/java/com/kit/weather/animation/base/ActorInfo.java: -------------------------------------------------------------------------------- 1 | package com.kit.weather.animation.base; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.Paint; 5 | 6 | /** 7 | * Desc:描述模块内容 8 | * User: ZhouJing 9 | * Date: 2016/11/3 10:56 10 | */ 11 | public class ActorInfo { 12 | 13 | //图片 14 | Bitmap bitmap; 15 | //定义一个画笔 16 | Paint paint; 17 | //开始飘落的横坐标 18 | float x; 19 | //开始飘落的纵坐标 20 | float y; 21 | //下落的速度 22 | float speed; 23 | //下落时偏移的值 24 | float offset; 25 | 26 | public ActorInfo(Bitmap bitmap, float x, float y, float speed, float offset) { 27 | this.bitmap = bitmap; 28 | this.x = x; 29 | this.y = y; 30 | this.speed = speed; 31 | this.offset = offset; 32 | } 33 | 34 | public Bitmap getBitmap() { 35 | return bitmap; 36 | } 37 | 38 | public void setBitmap(Bitmap bitmap) { 39 | this.bitmap = bitmap; 40 | } 41 | 42 | public Paint getPaint() { 43 | return paint; 44 | } 45 | 46 | public void setPaint(Paint paint) { 47 | this.paint = paint; 48 | } 49 | 50 | public float getX() { 51 | return x; 52 | } 53 | 54 | public void setX(float x) { 55 | this.x = x; 56 | } 57 | 58 | public float getY() { 59 | return y; 60 | } 61 | 62 | public void setY(float y) { 63 | this.y = y; 64 | } 65 | 66 | public float getSpeed() { 67 | return speed; 68 | } 69 | 70 | public void setSpeed(float speed) { 71 | this.speed = speed; 72 | } 73 | 74 | public float getOffset() { 75 | return offset; 76 | } 77 | 78 | public void setOffset(float offset) { 79 | this.offset = offset; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /app/src/main/java/com/kit/weather/animation/utils/Actor.java: -------------------------------------------------------------------------------- 1 | package com.kit.weather.animation.utils; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Matrix; 6 | import android.util.DisplayMetrics; 7 | import android.view.WindowManager; 8 | 9 | /** 10 | * Desc:描述模块内容 11 | * User: ZhouJing 12 | * Date: 2016/11/3 10:52 13 | */ 14 | public abstract class Actor { 15 | 16 | protected Context context; 17 | 18 | /** 19 | * 定义一个矩阵对象 20 | */ 21 | protected Matrix matrix = new Matrix(); 22 | 23 | /** 24 | * 获取屏幕宽度 25 | */ 26 | protected float screenWidth; 27 | 28 | /** 29 | * 获取屏幕高度 30 | */ 31 | protected float screenHeiht; 32 | 33 | protected Actor(Context context) { 34 | this.context = context; 35 | } 36 | 37 | /** 38 | * 获取屏幕的分辨率 39 | * 40 | * @param context 41 | */ 42 | @SuppressWarnings("unused") 43 | protected void getViewSize(Context context) { 44 | DisplayMetrics metrics = new DisplayMetrics(); 45 | WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 46 | windowManager.getDefaultDisplay().getMetrics(metrics); 47 | this.screenHeiht = metrics.heightPixels; 48 | this.screenWidth = metrics.widthPixels; 49 | } 50 | 51 | public abstract void draw(Canvas canvas, int width, int height); 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/kit/weather/animation/utils/RandomUtils.java: -------------------------------------------------------------------------------- 1 | package com.kit.weather.animation.utils; 2 | 3 | import java.util.Random; 4 | 5 | /** 6 | * Desc:描述模块内容 7 | * User: ZhouJing 8 | * Date: 2016/11/3 10:35 9 | */ 10 | public class RandomUtils { 11 | 12 | private static final Random RANDOM = new Random(); 13 | 14 | public float getRandom(float lower, float upper) { 15 | float min = Math.min(lower, upper); 16 | float max = Math.max(lower, upper); 17 | return getRandom(max - min) + min; 18 | } 19 | 20 | public float getRandom(float upper) { 21 | return RANDOM.nextFloat() * upper; 22 | } 23 | 24 | public int getRandom(int upper) { 25 | return RANDOM.nextInt(upper); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/kit/weather/animation/utils/RenderThread.java: -------------------------------------------------------------------------------- 1 | package com.kit.weather.animation.utils; 2 | 3 | import android.content.Context; 4 | import android.graphics.BitmapFactory; 5 | import android.graphics.Canvas; 6 | import android.os.Handler; 7 | import android.os.Looper; 8 | import android.os.Message; 9 | import android.util.Log; 10 | import android.view.SurfaceHolder; 11 | 12 | import com.kit.weather.animation.R; 13 | 14 | 15 | /** 16 | * Desc:描述模块内容 17 | * User: ZhouJing 18 | * Date: 2016/11/3 11:09 19 | */ 20 | public class RenderThread extends Thread { 21 | 22 | private Context context; 23 | private SurfaceHolder surfaceHolder; 24 | private RenderHandler renderHandler; 25 | private Scene scene; 26 | 27 | public RenderThread(SurfaceHolder surfaceHolder, Context context) { 28 | this.context = context; 29 | this.surfaceHolder = surfaceHolder; 30 | scene = new Scene(context); 31 | //add scene/actor 32 | scene.setBg(BitmapFactory.decodeResource(context.getResources(), R.drawable.bg_snow_night)); 33 | scene.add(new SnowShine(context)); 34 | scene.add(new SnowFall(context)); 35 | } 36 | 37 | @Override 38 | public void run() { 39 | Log.d("weather", "run"); 40 | //在非主线程使用消息队列 41 | Looper.prepare(); 42 | renderHandler = new RenderHandler(); 43 | renderHandler.sendEmptyMessage(0); 44 | Looper.loop(); 45 | } 46 | 47 | public RenderHandler getRenderHandler() { 48 | return renderHandler; 49 | } 50 | 51 | public class RenderHandler extends Handler { 52 | @Override 53 | public void handleMessage(Message msg) { 54 | switch (msg.what) { 55 | case 0: 56 | if (scene.getWidth() != 0 && scene.getHeight() != 0) { 57 | draw(); 58 | } 59 | renderHandler.sendEmptyMessage(0); 60 | break; 61 | case 1: 62 | Looper.myLooper().quit(); 63 | break; 64 | } 65 | } 66 | } 67 | 68 | private void draw() { 69 | Canvas canvas = surfaceHolder.lockCanvas(); 70 | if (canvas != null) { 71 | scene.draw(canvas); 72 | surfaceHolder.unlockCanvasAndPost(canvas); 73 | } 74 | } 75 | 76 | 77 | public void setWidth(int width) { 78 | scene.setWidth(width); 79 | } 80 | 81 | public void setHeight(int height) { 82 | scene.setHeight(height); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/kit/weather/animation/utils/SaxService.java: -------------------------------------------------------------------------------- 1 | package com.kit.weather.animation.utils; 2 | 3 | import android.content.Context; 4 | import android.content.res.AssetManager; 5 | 6 | import org.xml.sax.InputSource; 7 | import org.xml.sax.XMLReader; 8 | 9 | import java.io.InputStream; 10 | import java.util.List; 11 | 12 | import javax.xml.parsers.SAXParser; 13 | import javax.xml.parsers.SAXParserFactory; 14 | 15 | /** 16 | * Desc:描述模块内容 17 | * User: ZhouJing 18 | * Date: 2016/11/3 10:56 19 | */ 20 | public class SaxService { 21 | 22 | private static SaxService ourInstance = new SaxService(); 23 | 24 | public static SaxService getInstance() { 25 | return ourInstance; 26 | } 27 | 28 | private SaxService() { 29 | 30 | } 31 | 32 | /** 33 | * 使用SAX解析器解析XML文件的方法,返回XMLActorData对象 34 | * 35 | * @param context 36 | * @param pathName 37 | * @return 38 | * @throws Exception 39 | */ 40 | public static List readXML(Context context, String pathName) throws Exception { 41 | InputStream is = null; 42 | XMLContentHandler contentHandler = null; 43 | try { 44 | // 获取AssetManager管理器对象 45 | AssetManager as = context.getAssets(); 46 | // 通过AssetManager的open方法获取到beauties.xml文件的输入流 47 | is = as.open(pathName); 48 | // 通过获取到的InputStream来得到InputSource实例 49 | InputSource is2 = new InputSource(is); 50 | // 使用工厂方法初始化SAXParserFactory变量spf 51 | SAXParserFactory spf = SAXParserFactory.newInstance(); 52 | // 通过SAXParserFactory得到SAXParser的实例 53 | SAXParser sp = spf.newSAXParser(); 54 | // 通过SAXParser得到XMLReader的实例 55 | XMLReader xr = sp.getXMLReader(); 56 | // 初始化自定义的类MySaxHandler的变量msh,将beautyList传递给它,以便装载数据 57 | contentHandler = new XMLContentHandler(); 58 | // 将对象msh传递给xr 59 | xr.setContentHandler(contentHandler); 60 | // 调用xr的parse方法解析输入流 61 | xr.parse(is2); 62 | } catch (Exception e) { 63 | e.printStackTrace(); 64 | } finally { 65 | if (is != null) { 66 | is.close(); 67 | } 68 | } 69 | return contentHandler.getXMLActorData(); //返回XML文档中的数据列表 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/com/kit/weather/animation/utils/Scene.java: -------------------------------------------------------------------------------- 1 | package com.kit.weather.animation.utils; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Canvas; 6 | import android.graphics.Paint; 7 | import android.graphics.Rect; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * Desc:描述模块内容 14 | * User: ZhouJing 15 | * Date: 2016/11/3 11:09 16 | */ 17 | public class Scene { 18 | 19 | private Context context; 20 | private int width; 21 | private int height; 22 | 23 | private Bitmap bg; 24 | private List actors = new ArrayList(); 25 | private Paint paint; 26 | 27 | public Scene(Context context) { 28 | this.context = context; 29 | paint = new Paint(); 30 | paint.setAntiAlias(true); 31 | } 32 | 33 | public void setBg(Bitmap bg) { 34 | this.bg = bg; 35 | } 36 | 37 | public void add(Actor actor) { 38 | actors.add(actor); 39 | } 40 | 41 | public void draw(Canvas canvas) { 42 | canvas.drawBitmap(bg, new Rect(0, 0, bg.getWidth(), bg.getHeight()), new Rect(0, 0, width, height), paint); 43 | for (Actor actor : actors) { 44 | actor.draw(canvas, width, height); 45 | } 46 | } 47 | 48 | public void setWidth(int width) { 49 | this.width = width; 50 | } 51 | 52 | public void setHeight(int height) { 53 | this.height = height; 54 | } 55 | 56 | public int getWidth() { 57 | return width; 58 | } 59 | 60 | public int getHeight() { 61 | return height; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/com/kit/weather/animation/utils/SnowFall.java: -------------------------------------------------------------------------------- 1 | package com.kit.weather.animation.utils; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.content.res.Resources; 6 | import android.graphics.Bitmap; 7 | import android.graphics.BitmapFactory; 8 | import android.graphics.Canvas; 9 | import android.graphics.Paint; 10 | 11 | import com.kit.weather.animation.base.ActorInfo; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.Random; 16 | 17 | /** 18 | * Desc:描述模块内容 19 | * User: ZhouJing 20 | * Date: 2016/11/3 10:53 21 | */ 22 | public class SnowFall extends Actor { 23 | 24 | private List listXMLData = null; 25 | Paint paint = new Paint(); 26 | private Bitmap bitmap_snows[] = null; 27 | private static Random random = new Random(); 28 | //随机位置的雪花对象 29 | private static final int NUM_SNOWFLAKES = 55; 30 | 31 | private ArrayList snowflake = new ArrayList(); 32 | 33 | private ArrayList snowflake_xl = new ArrayList(); 34 | private ArrayList snowflake_m = new ArrayList(); 35 | private ArrayList snowflake_s = new ArrayList(); 36 | private ArrayList snowflake_l = new ArrayList(); 37 | 38 | @SuppressWarnings("static-access") 39 | protected SnowFall(Context context) { 40 | super(context); 41 | // 设置是否使用抗锯齿功能,会消耗较大资源,绘制图形速度会变慢 42 | paint.setAntiAlias(false); 43 | // 如果该项设置为true,则图像在动画进行中会滤掉对Bitmap图像的优化操作,加快显示速度,本设置项依赖于dither和xfermode的设置 44 | paint.setFilterBitmap(true); 45 | // 设定是否使用图像抖动处理,会使绘制出来的图片颜色更加平滑和饱满,图像更加清晰 46 | paint.setDither(true); 47 | try { 48 | listXMLData = SaxService.getInstance().readXML(context, "weather_scene_slight_snow_day.xml"); 49 | } catch (Exception e) { 50 | e.printStackTrace(); 51 | } 52 | getViewSize(context); 53 | loadRainImage(context); 54 | addRandomRain(); 55 | } 56 | 57 | @Override 58 | public void draw(Canvas canvas, int width, int height) { 59 | try { 60 | if (canvas != null) { 61 | drawRain(canvas); 62 | ActorInfo rain = null; 63 | for (int k = 0; k < NUM_SNOWFLAKES; k++) { 64 | rain = snowflake_xl.get(k); 65 | snowDown(rain); 66 | rain = snowflake_m.get(k); 67 | snowDown(rain); 68 | rain = snowflake_s.get(k); 69 | snowDown(rain); 70 | rain = snowflake_l.get(k); 71 | snowDown(rain); 72 | } 73 | } 74 | Thread.sleep(25); 75 | } catch (InterruptedException e) { 76 | e.printStackTrace(); 77 | } 78 | } 79 | 80 | @SuppressLint("NewApi") 81 | public void drawRain(Canvas canvas) { 82 | ActorInfo rain = null; 83 | for (int k = 0; k < NUM_SNOWFLAKES; k++) { 84 | rain = snowflake_xl.get(k); 85 | canvas.drawBitmap(rain.getBitmap(), rain.getX(), rain.getY(), paint); 86 | rain = snowflake_m.get(k); 87 | canvas.drawBitmap(rain.getBitmap(), rain.getX(), rain.getY(), paint); 88 | rain = snowflake_s.get(k); 89 | canvas.drawBitmap(rain.getBitmap(), rain.getX(), rain.getY(), paint); 90 | rain = snowflake_l.get(k); 91 | canvas.drawBitmap(rain.getBitmap(), rain.getX(), rain.getY(), paint); 92 | } 93 | } 94 | 95 | /** 96 | * 把图片加载到内存汇中 97 | * 98 | * @param context 99 | */ 100 | private void loadRainImage(Context context) { 101 | if (listXMLData != null && listXMLData.size() > 0) { 102 | bitmap_snows = new Bitmap[listXMLData.size()]; 103 | } 104 | for (int i = 0; i < listXMLData.size(); i++) { 105 | bitmap_snows[i] = BitmapFactory.decodeResource(context.getResources(), getResId(listXMLData.get(i).getActorName())); 106 | } 107 | } 108 | 109 | public void addRandomRain() { 110 | 111 | for (int k = 0; k < NUM_SNOWFLAKES; k++) { 112 | snowflake_xl.add(new ActorInfo(bitmap_snows[3], random.nextFloat() 113 | * screenWidth, random.nextFloat() * screenHeiht, 114 | listXMLData.get(3).getSpeed() / 100, 115 | 1 - random.nextFloat() * 2)); 116 | snowflake_m.add(new ActorInfo(bitmap_snows[2], random.nextFloat() 117 | * screenWidth, random.nextFloat() * screenHeiht, 118 | listXMLData.get(2).getSpeed() / 100, 119 | 1 - random.nextFloat() * 2)); 120 | snowflake_s.add(new ActorInfo(bitmap_snows[1], random.nextFloat() 121 | * screenWidth, random.nextFloat() * screenHeiht, 122 | listXMLData.get(1).getSpeed() / 100, 123 | 1 - random.nextFloat() * 2)); 124 | snowflake_l.add(new ActorInfo(bitmap_snows[0], random.nextFloat() 125 | * screenWidth, random.nextFloat() * screenHeiht, 126 | listXMLData.get(0).getSpeed() / 100, 127 | 1 - random.nextFloat() * 2)); 128 | } 129 | } 130 | 131 | /** 132 | * 雨下落 133 | * 134 | * @param snow 135 | */ 136 | private void snowDown(ActorInfo snow) { 137 | // 雨的落出屏幕后又让它从顶上下落 138 | if (snow.getX() > screenWidth || snow.getY() > screenHeiht) { 139 | snow.setY(0); 140 | snow.setX(random.nextFloat() * screenWidth); 141 | } 142 | snow.setX(snow.getX() + snow.getOffset());// 下落飘的偏移量 143 | snow.setY(snow.getY() + snow.getSpeed());// 下落的速度 144 | } 145 | 146 | private int getResId(String resName) { 147 | int drawable = 0; 148 | Resources resources = context.getResources(); 149 | int indentify = resources.getIdentifier(context.getPackageName() 150 | + ":drawable/" + resName, null, null); 151 | /*if (indentify > 0) { 152 | drawable = resources.getDrawable(indentify); 153 | }*/ 154 | return indentify; 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /app/src/main/java/com/kit/weather/animation/utils/SnowShine.java: -------------------------------------------------------------------------------- 1 | package com.kit.weather.animation.utils; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.graphics.RectF; 9 | import android.util.Log; 10 | 11 | import com.kit.weather.animation.R; 12 | 13 | /** 14 | * Desc:描述模块内容 15 | * User: ZhouJing 16 | * Date: 2016/11/3 11:10 17 | */ 18 | public class SnowShine extends Actor { 19 | 20 | float initPositionX; 21 | float initPositionY; 22 | boolean isInit; 23 | Bitmap frame; 24 | RectF box; 25 | RectF targetBox; 26 | Paint paint = new Paint(); 27 | int alpha; 28 | boolean alphaUp = true; 29 | 30 | protected SnowShine(Context context) { 31 | super(context); 32 | box = new RectF(); 33 | targetBox = new RectF(); 34 | paint.setAntiAlias(true); 35 | } 36 | 37 | @Override 38 | public void draw(Canvas canvas, int width, int height) { 39 | //逻辑处理 40 | //初始化 41 | if (!isInit) { 42 | Log.d("weather", "cloud init"); 43 | initPositionX = width * 0.34F; 44 | initPositionY = height * 0.22F; 45 | frame = BitmapFactory.decodeResource(context.getResources(), R.drawable.snow_light); 46 | matrix.reset(); 47 | matrix.setScale(1.3f, 1.3f); 48 | matrix.mapRect(targetBox, box); 49 | matrix.postTranslate(targetBox.width(), 0); 50 | isInit = true; 51 | return; 52 | } 53 | //移动 54 | // matrix.postTranslate(0.5F, 0); 55 | //边界处理 56 | matrix.mapRect(targetBox, box); 57 | if (targetBox.left > width) { 58 | matrix.postTranslate(-targetBox.right, 0); 59 | } 60 | //绘制 61 | canvas.drawBitmap(frame, matrix, paint); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/kit/weather/animation/utils/XMLActorData.java: -------------------------------------------------------------------------------- 1 | package com.kit.weather.animation.utils; 2 | 3 | /** 4 | * Desc:描述模块内容 5 | * User: ZhouJing 6 | * Date: 2016/11/3 10:55 7 | */ 8 | public class XMLActorData { 9 | 10 | // 角度 11 | private float angle; 12 | // 层次 13 | private int layer; 14 | // 比例尺 15 | private float scale; 16 | // 横坐标 17 | private float x; 18 | // 纵坐标 19 | private float y; 20 | // 速度 21 | private float speed; 22 | // 图片名称 23 | private String actorName; 24 | // 图片循环数量 25 | private int count; 26 | 27 | public float getAngle() { 28 | return angle; 29 | } 30 | public void setAngle(float angle) { 31 | this.angle = angle; 32 | } 33 | public int getLayer() { 34 | return layer; 35 | } 36 | public void setLayer(int layer) { 37 | this.layer = layer; 38 | } 39 | public float getScale() { 40 | return scale; 41 | } 42 | public void setScale(float scale) { 43 | this.scale = scale; 44 | } 45 | public float getX() { 46 | return x; 47 | } 48 | public void setX(float x) { 49 | this.x = x; 50 | } 51 | public float getY() { 52 | return y; 53 | } 54 | public void setY(float y) { 55 | this.y = y; 56 | } 57 | public float getSpeed() { 58 | return speed; 59 | } 60 | public void setSpeed(float speed) { 61 | this.speed = speed; 62 | } 63 | public String getActorName() { 64 | return actorName; 65 | } 66 | public void setActorName(String actorName) { 67 | this.actorName = actorName; 68 | } 69 | public int getCount() { 70 | return count; 71 | } 72 | public void setCount(int count) { 73 | this.count = count; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/com/kit/weather/animation/utils/XMLContentHandler.java: -------------------------------------------------------------------------------- 1 | package com.kit.weather.animation.utils; 2 | 3 | import org.xml.sax.Attributes; 4 | import org.xml.sax.SAXException; 5 | import org.xml.sax.helpers.DefaultHandler; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * Desc:描述模块内容 12 | * User: ZhouJing 13 | * Date: 2016/11/3 10:55 14 | */ 15 | public class XMLContentHandler extends DefaultHandler { 16 | 17 | private List listXMLData = null; 18 | private XMLActorData actorData; 19 | 20 | public List getXMLActorData() { 21 | return listXMLData; 22 | } 23 | 24 | @Override 25 | public void startDocument() throws SAXException { 26 | listXMLData = new ArrayList(); 27 | super.startDocument(); 28 | } 29 | 30 | @Override 31 | public void startElement(String uri, String localName, String qName, 32 | Attributes attributes) throws SAXException { 33 | if (localName.equals("actor")) { 34 | actorData = new XMLActorData(); 35 | if (attributes != null && attributes.getLength() > 0) { 36 | actorData.setAngle(Float.parseFloat(attributes.getValue(0))); 37 | actorData.setLayer(Integer.parseInt(attributes.getValue(1))); 38 | actorData.setX(Float.parseFloat(attributes.getValue(2))); 39 | actorData.setY(Float.parseFloat(attributes.getValue(3))); 40 | actorData.setScale(Float.parseFloat(attributes.getValue(4))); 41 | actorData.setSpeed(Float.parseFloat(attributes.getValue(5))); 42 | actorData.setCount(Integer.parseInt(attributes.getValue(7))); 43 | } 44 | } 45 | if (localName.equals("name")) { 46 | actorData.setActorName(attributes.getValue(0)); 47 | } 48 | super.startElement(uri, localName, qName, attributes); 49 | } 50 | 51 | @Override 52 | public void endElement(String uri, String localName, String qName) 53 | throws SAXException { 54 | if (localName.equals("actor")) { 55 | listXMLData.add(actorData); 56 | actorData = null; 57 | } 58 | super.endElement(uri, localName, qName); 59 | } 60 | 61 | @Override 62 | public void characters(char[] ch, int start, int length) 63 | throws SAXException { 64 | super.characters(ch, start, length); 65 | } 66 | 67 | } 68 | 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/kit/weather/animation/view/SceneSurfaceView.java: -------------------------------------------------------------------------------- 1 | package com.kit.weather.animation.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.util.Log; 6 | import android.view.SurfaceHolder; 7 | import android.view.SurfaceView; 8 | 9 | import com.kit.weather.animation.utils.RenderThread; 10 | 11 | /** 12 | * Desc:描述模块内容 13 | * User: ZhouJing 14 | * Date: 2016/11/3 11:13 15 | */ 16 | public class SceneSurfaceView extends SurfaceView implements SurfaceHolder.Callback { 17 | 18 | private RenderThread renderThread; 19 | private SurfaceHolder surfaceHolder; 20 | 21 | public SceneSurfaceView(Context context) { 22 | super(context); 23 | } 24 | 25 | public SceneSurfaceView(Context context, AttributeSet attrs) { 26 | super(context, attrs); 27 | surfaceHolder = getHolder(); 28 | surfaceHolder.addCallback(this); 29 | 30 | setFocusable(true); 31 | setFocusableInTouchMode(true); 32 | this.setKeepScreenOn(true); 33 | } 34 | 35 | public SceneSurfaceView(Context context, AttributeSet attrs, int defStyleAttr) { 36 | super(context, attrs, defStyleAttr); 37 | surfaceHolder = getHolder(); 38 | surfaceHolder.addCallback(this); 39 | 40 | setFocusable(true); 41 | setFocusableInTouchMode(true); 42 | this.setKeepScreenOn(true); 43 | } 44 | 45 | @Override 46 | public void surfaceCreated(SurfaceHolder holder) { 47 | Log.d("weather", "surfaceCreated"); 48 | if (renderThread == null) { 49 | renderThread = new RenderThread(surfaceHolder, getContext()); 50 | renderThread.start(); 51 | } 52 | } 53 | 54 | int width; 55 | int height; 56 | 57 | @Override 58 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 59 | width = getMeasuredWidth(); 60 | height = getMeasuredHeight(); 61 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 62 | Log.d("weather", "onMeasure width=" + width + ",height=" + height); 63 | if (renderThread != null) { 64 | renderThread.setWidth(width); 65 | renderThread.setHeight(height); 66 | } 67 | } 68 | 69 | @Override 70 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 71 | Log.d("weather", "surfaceChanged"); 72 | } 73 | 74 | @Override 75 | public void surfaceDestroyed(SurfaceHolder holder) { 76 | Log.d("weather", "surfaceDestroyed"); 77 | renderThread.getRenderHandler().sendEmptyMessage(1); 78 | } 79 | 80 | @Override 81 | protected void onFinishInflate() { 82 | super.onFinishInflate(); 83 | Log.d("weather", "onFinishInflate"); 84 | } 85 | } 86 | 87 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackyBower/WeatherAnimationDemo/d4bcc68880818c39467ab532e4ca6604cdf299ec/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/snowflake_l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackyBower/WeatherAnimationDemo/d4bcc68880818c39467ab532e4ca6604cdf299ec/app/src/main/res/drawable-hdpi/snowflake_l.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/snowflake_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackyBower/WeatherAnimationDemo/d4bcc68880818c39467ab532e4ca6604cdf299ec/app/src/main/res/drawable-hdpi/snowflake_m.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/snowflake_xl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackyBower/WeatherAnimationDemo/d4bcc68880818c39467ab532e4ca6604cdf299ec/app/src/main/res/drawable-hdpi/snowflake_xl.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/snowflake_xxl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackyBower/WeatherAnimationDemo/d4bcc68880818c39467ab532e4ca6604cdf299ec/app/src/main/res/drawable-hdpi/snowflake_xxl.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackyBower/WeatherAnimationDemo/d4bcc68880818c39467ab532e4ca6604cdf299ec/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackyBower/WeatherAnimationDemo/d4bcc68880818c39467ab532e4ca6604cdf299ec/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/bg_snow_night.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackyBower/WeatherAnimationDemo/d4bcc68880818c39467ab532e4ca6604cdf299ec/app/src/main/res/drawable-xxhdpi/bg_snow_night.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackyBower/WeatherAnimationDemo/d4bcc68880818c39467ab532e4ca6604cdf299ec/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/snow_light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackyBower/WeatherAnimationDemo/d4bcc68880818c39467ab532e4ca6604cdf299ec/app/src/main/res/drawable-xxhdpi/snow_light.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | WeatherAnimationDemo 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/harmonywisdom/weather/animation/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.harmonywisdom.weather.animation; 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 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.2' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackyBower/WeatherAnimationDemo/d4bcc68880818c39467ab532e4ca6604cdf299ec/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 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-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /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 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /snowdemo/snow_demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackyBower/WeatherAnimationDemo/d4bcc68880818c39467ab532e4ca6604cdf299ec/snowdemo/snow_demo.gif --------------------------------------------------------------------------------