├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── findbugs-idea.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── example
│ │ └── sangenan
│ │ └── weather
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── sangenan
│ │ │ └── weather
│ │ │ ├── GyroscopeObserver.java
│ │ │ ├── MainActivity.java
│ │ │ ├── Util
│ │ │ ├── BezierEvaluator.java
│ │ │ ├── BezierUtil.java
│ │ │ ├── BitmapUtil.java
│ │ │ ├── CalculateUtil.java
│ │ │ └── ScaleChangeUtils.java
│ │ │ └── WeatherAnimView.java
│ └── res
│ │ ├── drawable
│ │ ├── bg_sunny_left_night.png
│ │ ├── bg_sunny_night.png
│ │ ├── bg_sunny_right_night.png
│ │ ├── bg_sunny_tree_ball_left_night.png
│ │ ├── bg_sunny_tree_ball_middle_night.png
│ │ ├── bg_sunny_tree_ball_right_night.png
│ │ ├── bg_sunny_tree_branch_night.png
│ │ ├── bg_sunny_tree_leaf_night.png
│ │ ├── bg_sunny_tree_trunk_night.png
│ │ ├── blue01.png
│ │ ├── blue02.png
│ │ ├── blue03.png
│ │ ├── blue04.png
│ │ ├── blue05.png
│ │ ├── blue06.png
│ │ ├── blue07.png
│ │ ├── blue08.png
│ │ ├── blue09.png
│ │ ├── blue10.png
│ │ ├── blue11.png
│ │ ├── blue12.png
│ │ ├── blue13.png
│ │ ├── blue14.png
│ │ ├── blue15.png
│ │ └── blue16.png
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── example
│ └── sangenan
│ └── weather
│ └── ExampleUnitTest.java
├── build.gradle
├── clip
├── Tree.java
├── backgroudView.java
└── flyingBirds.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.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/findbugs-idea.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Weather
2 | Android自定义View-小米MIUI8天气动画(晴天)
3 |
4 | **正常模式:**
5 |
6 | 
7 |
8 | **View跟随手机摇晃后移动:**
9 |
10 | 
11 |
12 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "25.0.1"
6 | defaultConfig {
7 | applicationId "com.example.sangenan.weather"
8 | minSdkVersion 19
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:24.2.1'
28 | testCompile 'junit:junit:4.12'
29 | }
30 |
--------------------------------------------------------------------------------
/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 /Users/kuwakuzukusunoki/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/sangenan/weather/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.sangenan.weather;
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.example.sangenan.weather", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/sangenan/weather/GyroscopeObserver.java:
--------------------------------------------------------------------------------
1 | package com.example.sangenan.weather;
2 |
3 | import android.content.Context;
4 | import android.hardware.Sensor;
5 | import android.hardware.SensorEvent;
6 | import android.hardware.SensorEventListener;
7 | import android.hardware.SensorManager;
8 |
9 | /**
10 | * Created by kuwakuzukusunoki on 2017/2/5.
11 | */
12 |
13 | public class GyroscopeObserver implements SensorEventListener {
14 | private SensorManager mSensorManager;
15 |
16 | // For translate nanosecond to second.
17 | private static final float NS2S = 1.0f / 1000000000.0f;
18 |
19 | // The time in nanosecond when last sensor event happened.
20 | private long mLastTimestamp;
21 |
22 | // The radian the device already rotate along y-axis.
23 | private double mRotateRadianY;
24 |
25 | // The radian the device already rotate along x-axis.
26 | private double mRotateRadianX;
27 | // The maximum radian that the device should rotate along x-axis and y-axis to show image's bounds
28 | // The value must between (0, π/2].
29 | private double mMaxRotateRadian = Math.PI/9;
30 |
31 | // The PanoramaImageViews to be notified when the device rotate.
32 | private WeatherAnimView mView;
33 |
34 | public void register(Context context) {
35 | if (mSensorManager == null) {
36 | mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
37 | }
38 | Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
39 | mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_FASTEST);
40 |
41 | mLastTimestamp = 0;
42 | mRotateRadianY = mRotateRadianX = 0;
43 | }
44 |
45 | public void unregister() {
46 | if (mSensorManager != null) {
47 | mSensorManager.unregisterListener(this);
48 | mSensorManager = null;
49 | }
50 | }
51 | void addWeatherAnimView(WeatherAnimView view) {
52 | if (view != null) {
53 | mView = view;
54 | }
55 | }
56 | @Override
57 | public void onSensorChanged(SensorEvent event) {
58 | if (mLastTimestamp == 0) {
59 | mLastTimestamp = event.timestamp;
60 | return;
61 | }
62 |
63 | float rotateX = Math.abs(event.values[0]);
64 | float rotateY = Math.abs(event.values[1]);
65 | float rotateZ = Math.abs(event.values[2]);
66 |
67 | if (rotateY > rotateX + rotateZ) {
68 | final float dT = (event.timestamp - mLastTimestamp) * NS2S;
69 | mRotateRadianY += event.values[1] * dT;
70 | if (mRotateRadianY > mMaxRotateRadian) {
71 | mRotateRadianY = mMaxRotateRadian;
72 | } else if (mRotateRadianY < -mMaxRotateRadian) {
73 | mRotateRadianY = -mMaxRotateRadian;
74 | } else {
75 | mView.setSensorChangedFraction((float) (mRotateRadianY / mMaxRotateRadian));
76 | }
77 | }
78 | mLastTimestamp = event.timestamp;
79 | }
80 |
81 | @Override
82 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
83 |
84 | }
85 |
86 | public void setMaxRotateRadian(double maxRotateRadian) {
87 | if (maxRotateRadian <= 0 || maxRotateRadian > Math.PI/2) {
88 | throw new IllegalArgumentException("The maxRotateRadian must be between (0, π/2].");
89 | }
90 | this.mMaxRotateRadian = maxRotateRadian;
91 | }
92 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/sangenan/weather/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.sangenan.weather;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 | public class MainActivity extends AppCompatActivity {
7 | private WeatherAnimView weather;
8 | private GyroscopeObserver gyroscopeObserver;
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 |
15 | weather = (WeatherAnimView) findViewById(R.id.weather);
16 | gyroscopeObserver = new GyroscopeObserver();
17 | weather.setGyroscopeObserver(gyroscopeObserver);
18 | }
19 |
20 | @Override
21 | protected void onResume() {
22 | super.onResume();
23 | gyroscopeObserver.register(this);
24 |
25 | }
26 |
27 | @Override
28 | protected void onPause() {
29 | super.onPause();
30 | gyroscopeObserver.unregister();
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/sangenan/weather/Util/BezierEvaluator.java:
--------------------------------------------------------------------------------
1 | package com.example.sangenan.weather.Util;
2 |
3 | import android.animation.TypeEvaluator;
4 | import android.graphics.PointF;
5 |
6 | public class BezierEvaluator implements TypeEvaluator {
7 |
8 | private PointF mControlPoint1;
9 |
10 | public BezierEvaluator(PointF mControlPoint1) {
11 | this.mControlPoint1 = mControlPoint1;
12 | }
13 |
14 | @Override
15 | public PointF evaluate(float t, PointF startValue, PointF endValue) {
16 | return BezierUtil.CalculateBezierPointForQuadratic(t, startValue, mControlPoint1,endValue);
17 | }
18 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/sangenan/weather/Util/BezierUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.sangenan.weather.Util;
2 |
3 | import android.graphics.PointF;
4 |
5 | /**
6 | * 计算贝塞尔曲线上的点坐标
7 | *
8 | * Created by xuyisheng on 16/7/13.
9 | */
10 | public class BezierUtil {
11 |
12 | /**
13 | * B(t) = (1 - t)^2 * P0 + 2t * (1 - t) * P1 + t^2 * P2, t ∈ [0,1]
14 | *
15 | * @param t 曲线长度比例
16 | * @param p0 起始点
17 | * @param p1 控制点
18 | * @param p2 终止点
19 | * @return t对应的点
20 | */
21 | public static PointF CalculateBezierPointForQuadratic(float t, PointF p0, PointF p1, PointF p2) {
22 | PointF point = new PointF();
23 | float temp = 1 - t;
24 | point.x = temp * temp * p0.x + 2 * t * temp * p1.x + t * t * p2.x;
25 | point.y = temp * temp * p0.y + 2 * t * temp * p1.y + t * t * p2.y;
26 | return point;
27 | }
28 |
29 | /**
30 | * B(t) = P0 * (1-t)^3 + 3 * P1 * t * (1-t)^2 + 3 * P2 * t^2 * (1-t) + P3 * t^3, t ∈ [0,1]
31 | *
32 | * @param t 曲线长度比例
33 | * @param p0 起始点
34 | * @param p1 控制点1
35 | * @param p2 控制点2
36 | * @param p3 终止点
37 | * @return t对应的点
38 | */
39 | public static PointF CalculateBezierPointForCubic(float t, PointF p0, PointF p1, PointF p2, PointF p3) {
40 | PointF point = new PointF();
41 | float temp = 1 - t;
42 | point.x = p0.x * temp * temp * temp + 3 * p1.x * t * temp * temp + 3 * p2.x * t * t * temp + p3.x * t * t * t;
43 | point.y = p0.y * temp * temp * temp + 3 * p1.y * t * temp * temp + 3 * p2.y * t * t * temp + p3.y * t * t * t;
44 | return point;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/sangenan/weather/Util/BitmapUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.sangenan.weather.Util;
2 |
3 | import android.content.res.Resources;
4 | import android.graphics.BitmapFactory;
5 |
6 | import com.example.sangenan.weather.R;
7 |
8 | /**
9 | * Created by kuwakuzukusunoki on 2017/1/29.
10 | */
11 |
12 | public class BitmapUtil {
13 | public static int getBirdsResource(int times){
14 | switch (times % 16){
15 | case 1:
16 | return R.drawable.blue01;
17 | case 2:
18 | return R.drawable.blue02;
19 | case 3:
20 | return R.drawable.blue03;
21 | case 4:
22 | return R.drawable.blue04;
23 | case 5:
24 | return R.drawable.blue05;
25 | case 6:
26 | return R.drawable.blue06;
27 | case 7:
28 | return R.drawable.blue07;
29 | case 8:
30 | return R.drawable.blue08;
31 | case 9:
32 | return R.drawable.blue09;
33 | case 10:
34 | return R.drawable.blue10;
35 | case 11:
36 | return R.drawable.blue11;
37 | case 12:
38 | return R.drawable.blue12;
39 | case 13:
40 | return R.drawable.blue13;
41 | case 14:
42 | return R.drawable.blue14;
43 | case 15:
44 | return R.drawable.blue15;
45 | case 16:
46 | return R.drawable.blue16;
47 | default:
48 | return R.drawable.blue01;
49 | }
50 | }
51 | public static float getBitmapScale(Resources res,int id){
52 | BitmapFactory.Options options = new BitmapFactory.Options();
53 | options.inJustDecodeBounds = true;
54 | BitmapFactory.decodeResource(res, id, options);
55 | if (options.outHeight != 0)
56 | return options.outWidth / options.outHeight;
57 | return 0;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/sangenan/weather/Util/CalculateUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.sangenan.weather.Util;
2 |
3 | /**
4 | * Created by kuwakuzukusunoki on 2017/2/2.
5 | */
6 |
7 | public class CalculateUtil {
8 | public static float getPythagorean(double first,double second){
9 | return (float) Math.sqrt(first*first+second*second);
10 | }
11 |
12 | public static float getSquare(float x){
13 | return x*x;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/sangenan/weather/Util/ScaleChangeUtils.java:
--------------------------------------------------------------------------------
1 | package com.example.sangenan.weather.Util;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by 79127 on 2016/9/15.
7 | */
8 | public class ScaleChangeUtils {
9 | /**
10 | * dp转px
11 | *
12 | * @param context 上下文
13 | * @param dpValue dp值
14 | * @return px值
15 | */
16 | public static int dp2px(Context context, float dpValue) {
17 | final float scale = context.getResources().getDisplayMetrics().density;
18 | return (int) (dpValue * scale + 0.5f);
19 | }
20 |
21 | /**
22 | * px转dp
23 | *
24 | * @param context 上下文
25 | * @param pxValue px值
26 | * @return dp值
27 | */
28 | public static int px2dp(Context context, float pxValue) {
29 | final float scale = context.getResources().getDisplayMetrics().density;
30 | return (int) (pxValue / scale + 0.5f);
31 | }
32 |
33 | /**
34 | * sp转px
35 | *
36 | * @param context 上下文
37 | * @param spValue sp值
38 | * @return px值
39 | */
40 | public static int sp2px(Context context, float spValue) {
41 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
42 | return (int) (spValue * fontScale + 0.5f);
43 | }
44 |
45 | /**
46 | * px转sp
47 | *
48 | * @param context 上下文
49 | * @param pxValue px值
50 | * @return sp值
51 | */
52 | public static int px2sp(Context context, float pxValue) {
53 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
54 | return (int) (pxValue / fontScale + 0.5f);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/sangenan/weather/WeatherAnimView.java:
--------------------------------------------------------------------------------
1 | package com.example.sangenan.weather;
2 |
3 |
4 | import android.animation.Animator;
5 | import android.animation.AnimatorListenerAdapter;
6 | import android.animation.ValueAnimator;
7 | import android.content.Context;
8 | import android.graphics.Bitmap;
9 | import android.graphics.BitmapFactory;
10 | import android.graphics.Canvas;
11 | import android.graphics.Matrix;
12 | import android.graphics.Paint;
13 | import android.graphics.PointF;
14 | import android.graphics.RectF;
15 | import android.graphics.drawable.BitmapDrawable;
16 | import android.graphics.drawable.Drawable;
17 | import android.util.AttributeSet;
18 | import android.view.View;
19 | import android.view.animation.LinearInterpolator;
20 |
21 | import com.example.sangenan.weather.Util.BezierEvaluator;
22 | import com.example.sangenan.weather.Util.BitmapUtil;
23 | import com.example.sangenan.weather.Util.CalculateUtil;
24 | import com.example.sangenan.weather.Util.ScaleChangeUtils;
25 |
26 | import java.util.ArrayList;
27 | import java.util.List;
28 |
29 | /**
30 | * Created by kuwakuzukusunoki on 2017/2/5.
31 | */
32 |
33 | public class WeatherAnimView extends View {
34 | private int Width;
35 | private int Height;
36 | private float scaleSideHill;
37 | private Bitmap sidehillLeft;
38 | private Bitmap sidehillRight;
39 | private RectF mRectFLeft;
40 | private RectF mRectFRight;
41 | private static final int maxOffsetX = 50;
42 | private Bitmap backgroud;
43 | private float currentOffsetX;
44 | private float mProgress;
45 |
46 | private int birdTimes;
47 | private Paint birdPaint;
48 |
49 | private Bitmap bird;
50 | private int offsetBirds;
51 | private int birdStartPointX;
52 | private int birdStartPointY;
53 | private int birdEndPointX;
54 | private int birdEndPointY;
55 |
56 | private int birdMovePointX;
57 | private int birdMovePointY;
58 |
59 | private int birdControlPointX;
60 | private int birdControlPointY;
61 | private static final int birdsSize = 45;
62 | private boolean isDrawBirds = false;
63 | private List birdsList = new ArrayList<>(16);
64 |
65 | private Bitmap treeBranch, treeBallLeft, treeBallRight, treeTrunk, treeBallMiddle, treeLeaf;
66 | private Matrix treeBranch_Matrix, treeBallLeft_Matrix, treeBallRight_Matrix, treeTrunk_Matrix, treeBallMiddle_Matrix, treeLeaf_Matrix;
67 | private static final float SCALESIZE = 0.2f;
68 | private static final float SCALESIZEBALL = 0.3f;
69 | private static final float SCALESIZELEAF = 0.4f;
70 |
71 | private int rotateCenterX;
72 | private int rotateCenterY;
73 | private int treeX;
74 | private int treeY;
75 | private float rotateValueTree = 0;
76 | private float rotateValueLeaf = 0;
77 | private boolean isDrawTree = false;
78 | private float treeControlPointX;
79 | private float treeControlPointY;
80 | private float treeStartPointX;
81 | private float treeStartPointY;
82 | private float treeEndPointX;
83 | private float treeEndPointY;
84 | private float moveLeafX;
85 | private float moveLeafY;
86 | private ValueAnimator valueAnimatorTree;
87 | private ValueAnimator valueAnimatorAlpha;
88 | private double randomRotate;
89 | private int timesTree = 0;
90 | private Paint treeLeafPaint;
91 |
92 | public WeatherAnimView(Context context) {
93 | super(context);
94 | init(context);
95 | }
96 |
97 | public WeatherAnimView(Context context, AttributeSet attrs) {
98 | super(context, attrs);
99 | init(context);
100 | }
101 |
102 | private void init(Context context) {
103 | currentOffsetX = 0;
104 | mProgress = 0;
105 |
106 | bird = BitmapFactory.decodeResource(getResources(), R.drawable.blue01);
107 | birdPaint = new Paint();
108 | birdPaint.setStyle(Paint.Style.STROKE);
109 | birdTimes = 0;
110 | offsetBirds = ScaleChangeUtils.dp2px(context, 15);
111 | ThreadBirds threadBirds = new ThreadBirds();
112 | threadBirds.start();
113 |
114 | treeBranch = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_tree_branch_night);
115 | treeBallLeft = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_tree_ball_left_night);
116 | treeBallRight = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_tree_ball_right_night);
117 | treeBallMiddle = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_tree_ball_middle_night);
118 | treeTrunk = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_tree_trunk_night);
119 | treeLeaf = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_tree_leaf_night);
120 | treeLeafPaint = new Paint();
121 |
122 | valueAnimatorAlpha = new ValueAnimator();
123 | }
124 |
125 |
126 | @Override
127 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
128 | super.onSizeChanged(w, h, oldw, oldh);
129 | Width = w;
130 | Height = h;
131 | BitmapFactory.Options optionsSideHill = new BitmapFactory.Options();
132 | optionsSideHill.inJustDecodeBounds = true;
133 | BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_left_night, optionsSideHill);
134 | if (optionsSideHill.outHeight != 0)
135 | scaleSideHill = optionsSideHill.outWidth / optionsSideHill.outHeight;
136 | mRectFLeft = new RectF(-maxOffsetX, Height / 5 * 3, -maxOffsetX + Height / 5 * 2 * scaleSideHill, Height);
137 | if (Width < Height / 3 * scaleSideHill) {
138 | mRectFRight = new RectF(-maxOffsetX, Height / 5 * 3, maxOffsetX + Height / 5 * 2 * scaleSideHill, Height);
139 | } else {
140 | mRectFRight = new RectF(-maxOffsetX, Height / 5 * 3, maxOffsetX + Width, Height);
141 | }
142 | BitmapFactory.Options options = new BitmapFactory.Options();
143 | options.inJustDecodeBounds = true;
144 | BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_right_night, options);
145 | options.inSampleSize = 32;
146 | options.inJustDecodeBounds = false;
147 | backgroud = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_night, options);
148 | Drawable drawable = new BitmapDrawable(backgroud);
149 | setBackground(drawable);
150 |
151 | optionsSideHill = new BitmapFactory.Options();
152 | optionsSideHill.inJustDecodeBounds = true;
153 | BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_left_night, optionsSideHill);
154 | optionsSideHill.inSampleSize = calculateInSampleSize(optionsSideHill, (int) (Height / 5 * 2 * scaleSideHill), Height / 5 * 2);
155 | optionsSideHill.inJustDecodeBounds = false;
156 | sidehillLeft = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_left_night, optionsSideHill);
157 |
158 | optionsSideHill = new BitmapFactory.Options();
159 | optionsSideHill.inJustDecodeBounds = true;
160 | BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_right_night, optionsSideHill);
161 | optionsSideHill.inSampleSize = calculateInSampleSize(optionsSideHill, 2 * maxOffsetX + Width, Height / 5 * 2);
162 | optionsSideHill.inJustDecodeBounds = false;
163 | sidehillRight = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_right_night, optionsSideHill);
164 |
165 | birdStartPointX = Width;
166 | birdStartPointY = Height / 4;
167 | birdEndPointX = -3 * offsetBirds - birdsSize;
168 | birdEndPointY = 0;
169 | birdControlPointX = Width / 2;
170 | birdControlPointY = Height / 4 + 80;
171 |
172 | treeX = w / 4 * 3;
173 | treeY = (int) (h / 5 * 3 - treeTrunk.getHeight() / 4 * SCALESIZE);
174 |
175 | rotateCenterX = treeX;
176 | rotateCenterY = (int) (treeY + treeTrunk.getHeight() * SCALESIZE / 8 + treeBranch.getHeight() * SCALESIZE);
177 |
178 | treeStartPointX = treeX - treeBallMiddle.getWidth() / 2 * SCALESIZEBALL;
179 | treeStartPointY = treeY - treeBallMiddle.getWidth() * SCALESIZEBALL / 2;
180 | treeEndPointX = w / 2;
181 | treeEndPointY = treeY + treeTrunk.getHeight() * SCALESIZE / 2;
182 | treeControlPointX = w / 2;
183 | treeControlPointY = treeY - treeBallMiddle.getWidth() * SCALESIZEBALL / 2;
184 |
185 | startAnimBirds();
186 | startAnimTree();
187 | }
188 |
189 | @Override
190 | protected void onDraw(Canvas canvas) {
191 | super.onDraw(canvas);
192 | currentOffsetX = maxOffsetX * mProgress;
193 | canvas.translate(currentOffsetX, 0);
194 | drawBirds(canvas);
195 | drawsideHill(canvas);
196 | drawLeaf(canvas);
197 | drawTree(canvas, currentOffsetX);
198 | }
199 |
200 | private void drawBirds(Canvas canvas) {
201 | if (isDrawBirds) {
202 | canvas.drawBitmap(bird, null, new RectF(birdMovePointX, birdMovePointY, birdMovePointX + birdsSize, birdMovePointY + birdsSize), null);
203 | canvas.drawBitmap(bird, null, new RectF(birdMovePointX + offsetBirds, birdMovePointY - offsetBirds / 2, birdMovePointX + birdsSize + offsetBirds, birdMovePointY + birdsSize - offsetBirds / 2), null);
204 | canvas.drawBitmap(bird, null, new RectF(birdMovePointX + 2 * offsetBirds, birdMovePointY - offsetBirds / 2, birdMovePointX + birdsSize + 2 * offsetBirds, birdMovePointY + birdsSize - offsetBirds / 2), null);
205 | canvas.drawBitmap(bird, null, new RectF((float) (birdMovePointX + 1.5 * offsetBirds), (float) (birdMovePointY + offsetBirds / 2), (float) (birdMovePointX + birdsSize + 1.5 * offsetBirds), (float) (birdMovePointY + birdsSize + offsetBirds / 2)), null);
206 | canvas.drawBitmap(bird, null, new RectF(birdMovePointX + 3 * offsetBirds, (float) (birdMovePointY - 1.5 * offsetBirds), birdMovePointX + birdsSize + 3 * offsetBirds, (float) (birdMovePointY + birdsSize - 1.5 * offsetBirds)), null);
207 | }
208 | }
209 |
210 | private void drawsideHill(Canvas canvas) {
211 | canvas.drawBitmap(sidehillLeft, null, mRectFLeft, null);
212 | canvas.drawBitmap(sidehillRight, null, mRectFRight, null);
213 | }
214 |
215 | private void drawLeaf(Canvas canvas) {
216 | if (isDrawTree) {
217 | int degreeX = (int) (treeBallMiddle.getWidth() * SCALESIZEBALL / 5);
218 | int degreeY = 20;
219 | treeLeaf_Matrix = new Matrix();
220 | treeLeaf_Matrix.setScale(SCALESIZELEAF, SCALESIZELEAF);
221 | treeLeaf_Matrix.postTranslate(moveLeafX, moveLeafY);
222 | treeLeaf_Matrix.postRotate((float) (randomRotate + rotateValueLeaf)
223 | , moveLeafX + treeLeaf.getWidth() * SCALESIZELEAF / 2, moveLeafY + treeLeaf.getHeight() * SCALESIZELEAF / 2);
224 | canvas.drawBitmap(treeLeaf, treeLeaf_Matrix, treeLeafPaint);
225 |
226 | treeLeaf_Matrix = new Matrix();
227 | treeLeaf_Matrix.setScale(SCALESIZELEAF, SCALESIZELEAF);
228 | treeLeaf_Matrix.postTranslate(moveLeafX + degreeX, moveLeafY + degreeY);
229 | treeLeaf_Matrix.postRotate((float) (randomRotate + rotateValueLeaf - 30)
230 | , moveLeafX + treeLeaf.getWidth() * SCALESIZELEAF / 2 + degreeX, moveLeafY + treeLeaf.getHeight() * SCALESIZELEAF / 2 + degreeY);
231 | canvas.drawBitmap(treeLeaf, treeLeaf_Matrix, treeLeafPaint);
232 |
233 | treeLeaf_Matrix = new Matrix();
234 | treeLeaf_Matrix.setScale(SCALESIZELEAF, SCALESIZELEAF);
235 | treeLeaf_Matrix.postTranslate(moveLeafX + 2 * degreeX, moveLeafY - degreeY);
236 | treeLeaf_Matrix.postRotate((float) (randomRotate + rotateValueLeaf - 60)
237 | , moveLeafX + treeLeaf.getWidth() * SCALESIZELEAF / 2 + 2 * degreeX, moveLeafY + treeLeaf.getHeight() * SCALESIZELEAF / 2 - degreeY);
238 | canvas.drawBitmap(treeLeaf, treeLeaf_Matrix, treeLeafPaint);
239 |
240 | treeLeaf_Matrix = new Matrix();
241 | treeLeaf_Matrix.setScale(SCALESIZELEAF, SCALESIZELEAF);
242 | treeLeaf_Matrix.postTranslate(moveLeafX + 3 * degreeX, moveLeafY + degreeY);
243 | treeLeaf_Matrix.postRotate((float) (randomRotate + rotateValueLeaf - 90)
244 | , moveLeafX + treeLeaf.getWidth() * SCALESIZELEAF / 2 + 3 * degreeX, moveLeafY + treeLeaf.getHeight() * SCALESIZELEAF / 2 + degreeY);
245 | canvas.drawBitmap(treeLeaf, treeLeaf_Matrix, treeLeafPaint);
246 | }
247 | }
248 |
249 | private void drawTree(Canvas canvas, float currentOffsetX) {
250 | treeTrunk_Matrix = new Matrix();
251 | treeTrunk_Matrix.setScale(SCALESIZE, SCALESIZE);
252 | treeTrunk_Matrix.postTranslate(treeX, treeY);
253 |
254 | treeBranch_Matrix = new Matrix();
255 | treeBranch_Matrix.setScale(SCALESIZE, SCALESIZE);
256 | treeBranch_Matrix.postTranslate(treeX - treeBranch.getWidth() * SCALESIZE / 2, treeY + treeTrunk.getHeight() * SCALESIZE / 8);
257 |
258 | treeBallMiddle_Matrix = new Matrix();
259 | treeBallMiddle_Matrix.setScale(SCALESIZEBALL, SCALESIZEBALL);
260 | treeBallMiddle_Matrix.postTranslate(treeX - treeBallMiddle.getWidth() / 2 * SCALESIZEBALL
261 | , treeY - treeBallMiddle.getWidth() * SCALESIZEBALL + 10);
262 |
263 | float offsetXY = getoffsetXY(treeBallLeft.getWidth() * SCALESIZEBALL / 2);
264 | treeBallLeft_Matrix = new Matrix();
265 | treeBallLeft_Matrix.setScale(SCALESIZEBALL, SCALESIZEBALL);
266 | treeBallLeft_Matrix.postTranslate(treeX - treeBranch.getWidth() * SCALESIZE / 2 - treeBallLeft.getWidth() * SCALESIZEBALL + offsetXY
267 | , treeY + treeTrunk.getHeight() * SCALESIZE / 8 - treeBallLeft.getHeight() * SCALESIZEBALL + offsetXY);
268 |
269 | offsetXY = getoffsetXY(treeBallRight.getWidth() * SCALESIZEBALL / 2) +
270 | CalculateUtil.getPythagorean(treeBranch.getWidth() * SCALESIZE / 2, treeBranch.getHeight() * SCALESIZE) / 4;
271 | treeBallRight_Matrix = new Matrix();
272 | treeBallRight_Matrix.setScale(SCALESIZEBALL, SCALESIZEBALL);
273 | treeBallRight_Matrix.postTranslate(treeX + treeBranch.getWidth() * SCALESIZE / 2 - offsetXY
274 | , treeY + treeTrunk.getHeight() * SCALESIZE / 8 - treeBallRight.getHeight() * SCALESIZEBALL + offsetXY);
275 |
276 | treeBallLeft_Matrix.postRotate(rotateValueTree, rotateCenterX, rotateCenterY);
277 | treeBallRight_Matrix.postRotate(rotateValueTree, rotateCenterX, rotateCenterY);
278 | treeBallMiddle_Matrix.postRotate(rotateValueTree, rotateCenterX, rotateCenterY);
279 | treeBranch_Matrix.postRotate(rotateValueTree, rotateCenterX, rotateCenterY);
280 | canvas.drawBitmap(treeTrunk, treeTrunk_Matrix, null);
281 | canvas.drawBitmap(treeBranch, treeBranch_Matrix, null);
282 | canvas.drawBitmap(treeBallLeft, treeBallLeft_Matrix, null);
283 | canvas.drawBitmap(treeBallMiddle, treeBallMiddle_Matrix, null);
284 | canvas.drawBitmap(treeBallRight, treeBallRight_Matrix, null);
285 | }
286 |
287 | private float getoffsetXY(float radius) {
288 | double clinodiagonal = radius * Math.sqrt(2);
289 | double offsetxy = (clinodiagonal - radius) * Math.sin(45 * Math.PI / 180);
290 | return (float) offsetxy;
291 | }
292 |
293 | private void startAnimTree() {
294 | valueAnimatorTree = new ValueAnimator().ofFloat(0, 15);
295 | valueAnimatorTree.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
296 | @Override
297 | public void onAnimationUpdate(ValueAnimator animation) {
298 | rotateValueTree = 360 - (float) animation.getAnimatedValue();
299 | invalidate();
300 | }
301 | });
302 | valueAnimatorTree.addPauseListener(new Animator.AnimatorPauseListener() {
303 | @Override
304 | public void onAnimationPause(Animator animation) {
305 | rotateValueTree = 0;
306 | isDrawTree = true;
307 | startAnimLeaf();
308 | }
309 |
310 | @Override
311 | public void onAnimationResume(Animator animation) {
312 |
313 | }
314 | });
315 | valueAnimatorTree.addListener(new AnimatorListenerAdapter() {
316 | @Override
317 | public void onAnimationRepeat(Animator animation) {
318 | ++timesTree;
319 | if (timesTree % 2 == 1)
320 | valueAnimatorTree.pause();
321 | }
322 | });
323 | valueAnimatorTree.setDuration(2000);
324 | valueAnimatorTree.setRepeatMode(ValueAnimator.REVERSE);
325 | valueAnimatorTree.setRepeatCount(ValueAnimator.INFINITE);
326 | valueAnimatorTree.setInterpolator(new LinearInterpolator());
327 | valueAnimatorTree.start();
328 |
329 |
330 | }
331 |
332 | private void startAnimLeaf() {
333 | randomRotate = Math.random() * 90;
334 | BezierEvaluator bezierEvaluator = new BezierEvaluator(new PointF(treeControlPointX, treeControlPointY));
335 | final ValueAnimator anim = ValueAnimator.ofObject(bezierEvaluator,
336 | new PointF(treeStartPointX, treeStartPointY),
337 | new PointF(treeEndPointX, treeEndPointY));
338 | anim.setDuration(4000);
339 | anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
340 | @Override
341 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
342 | PointF point = (PointF) valueAnimator.getAnimatedValue();
343 | moveLeafX = point.x;
344 | moveLeafY = point.y;
345 | float fraction = valueAnimator.getAnimatedFraction();
346 | rotateValueLeaf = 90 * fraction;
347 | if (fraction >= 0.75 && valueAnimatorAlpha.isRunning() == false) {
348 | startAlpha();
349 | }
350 | invalidate();
351 | }
352 | });
353 | anim.setInterpolator(new LinearInterpolator());
354 | anim.addListener(new AnimatorListenerAdapter() {
355 | @Override
356 | public void onAnimationEnd(Animator animation) {
357 | isDrawTree = false;
358 | valueAnimatorTree.resume();
359 | invalidate();
360 | }
361 | });
362 | anim.start();
363 | }
364 |
365 | private void startAlpha() {
366 | valueAnimatorAlpha = ValueAnimator.ofFloat(0, 1);
367 | valueAnimatorAlpha.setDuration(1000);
368 | valueAnimatorAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
369 | @Override
370 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
371 | float fraction = (float) valueAnimator.getAnimatedValue();
372 | treeLeafPaint.setAlpha((int) (255 - 255 * fraction));
373 | }
374 | });
375 | valueAnimatorAlpha.addListener(new AnimatorListenerAdapter() {
376 | @Override
377 | public void onAnimationEnd(Animator animation) {
378 | treeLeafPaint.reset();
379 | }
380 | });
381 | valueAnimatorAlpha.setInterpolator(new LinearInterpolator());
382 | valueAnimatorAlpha.start();
383 | }
384 |
385 | private int calculateInSampleSize(BitmapFactory.Options options, int reqWidth,
386 | int reqHeight) {
387 | final int height = options.outHeight;
388 | final int width = options.outWidth;
389 | int inSampleSize = 1;
390 |
391 | if (height > reqHeight || width > reqWidth) {
392 |
393 | // Calculate ratios of height and width to requested height and width
394 | final int heightRatio = Math.round((float) height / (float) reqHeight);
395 | final int widthRatio = Math.round((float) width / (float) reqWidth);
396 |
397 | // Choose the smallest ratio as inSampleSize value, this will guarantee
398 | // a final image with both dimensions larger than or equal to the
399 | // requested height and width.
400 | inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
401 | }
402 |
403 | return inSampleSize;
404 | }
405 |
406 | private void startAnimBirds() {
407 | isDrawBirds = true;
408 | BezierEvaluator bezierEvaluator = new BezierEvaluator(new PointF(birdControlPointX, birdControlPointY));
409 | final ValueAnimator anim = ValueAnimator.ofObject(bezierEvaluator,
410 | new PointF(birdStartPointX, birdStartPointY),
411 | new PointF(birdEndPointX, birdEndPointY));
412 | anim.setDuration(8000);
413 | anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
414 | @Override
415 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
416 | PointF point = (PointF) valueAnimator.getAnimatedValue();
417 | birdMovePointX = (int) point.x;
418 | birdMovePointY = (int) point.y;
419 | ++birdTimes;
420 | if (birdTimes % 8 == 0) {
421 | updatebirds(birdTimes);
422 | }
423 | invalidate();
424 | }
425 | });
426 | anim.setInterpolator(new LinearInterpolator());
427 | anim.addListener(new AnimatorListenerAdapter() {
428 | @Override
429 | public void onAnimationRepeat(Animator animation) {
430 | super.onAnimationRepeat(animation);
431 | birdTimes = 0;
432 | }
433 | });
434 | anim.setRepeatMode(ValueAnimator.RESTART);
435 | anim.setRepeatCount(ValueAnimator.INFINITE);
436 | anim.start();
437 | }
438 |
439 | private void updatebirds(int birdTimes) {
440 | bird = birdsList.get(birdTimes % 16);
441 | }
442 |
443 | class ThreadBirds extends Thread {
444 |
445 | @Override
446 | public void run() {
447 | for (int i = 0; i < 15; ++i) {
448 | birdsList.add(i, BitmapFactory.decodeResource(getResources(), BitmapUtil.getBirdsResource(i + 1)));
449 | }
450 | }
451 | }
452 |
453 | public void setSensorChangedFraction(float v) {
454 | mProgress = v;
455 | invalidate();
456 | }
457 |
458 | public void setGyroscopeObserver(GyroscopeObserver observer) {
459 | if (observer != null) {
460 | observer.addWeatherAnimView(this);
461 | }
462 | }
463 |
464 | public void stopAnim() {
465 |
466 | }
467 | }
468 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_sunny_left_night.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/bg_sunny_left_night.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_sunny_night.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/bg_sunny_night.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_sunny_right_night.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/bg_sunny_right_night.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_sunny_tree_ball_left_night.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/bg_sunny_tree_ball_left_night.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_sunny_tree_ball_middle_night.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/bg_sunny_tree_ball_middle_night.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_sunny_tree_ball_right_night.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/bg_sunny_tree_ball_right_night.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_sunny_tree_branch_night.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/bg_sunny_tree_branch_night.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_sunny_tree_leaf_night.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/bg_sunny_tree_leaf_night.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_sunny_tree_trunk_night.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/bg_sunny_tree_trunk_night.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue01.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue02.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue03.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue04.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue05.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue06.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue07.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue07.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue08.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue09.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue09.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue10.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue11.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue12.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue13.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue14.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue15.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/drawable/blue16.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/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 | Weather
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/sangenan/weather/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.sangenan.weather;
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.3'
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 |
--------------------------------------------------------------------------------
/clip/Tree.java:
--------------------------------------------------------------------------------
1 | package com.example.sangenan.weather;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.graphics.Bitmap;
8 | import android.graphics.BitmapFactory;
9 | import android.graphics.Canvas;
10 | import android.graphics.Matrix;
11 | import android.graphics.Paint;
12 | import android.graphics.PointF;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 | import android.view.animation.LinearInterpolator;
16 |
17 | import com.example.sangenan.weather.Util.BezierEvaluator;
18 | import com.example.sangenan.weather.Util.CalculateUtil;
19 |
20 | /**
21 | * Created by kuwakuzukusunoki on 2017/2/2.
22 | */
23 |
24 | public class Tree extends View {
25 | private Bitmap treeBranch, treeBallLeft, treeBallRight, treeTrunk, treeBallMiddle, treeLeaf;
26 | private Matrix treeBranch_Matrix, treeBallLeft_Matrix, treeBallRight_Matrix, treeTrunk_Matrix, treeBallMiddle_Matrix, treeLeaf_Matrix;
27 | private static final float SCALESIZE = 0.2f;
28 | private static final float SCALESIZEBALL = 0.3f;
29 | private static final float SCALESIZELEAF = 0.4f;
30 |
31 | private int rotateCenterX;
32 | private int rotateCenterY;
33 | private int treeX;
34 | private int treeY;
35 | private float rotateValueTree = 0;
36 | private float rotateValueLeaf = 0;
37 | private boolean isDrawTree = false;
38 | private float treeControlPointX;
39 | private float treeControlPointY;
40 | private float treeStartPointX;
41 | private float treeStartPointY;
42 | private float treeEndPointX;
43 | private float treeEndPointY;
44 | private float moveLeafX;
45 | private float moveLeafY;
46 | private ValueAnimator valueAnimatorTree;
47 | private ValueAnimator valueAnimatorAlpha;
48 | private double randomRotate;
49 | private int timesTree = 0;
50 | private Paint treeLeafPaint;
51 |
52 |
53 | public Tree(Context context) {
54 | super(context);
55 | init();
56 | }
57 |
58 | public Tree(Context context, AttributeSet attrs) {
59 | super(context, attrs);
60 | init();
61 | }
62 |
63 | private void init() {
64 |
65 | treeBranch = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_tree_branch_night);
66 | treeBallLeft = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_tree_ball_left_night);
67 | treeBallRight = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_tree_ball_right_night);
68 | treeBallMiddle = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_tree_ball_middle_night);
69 | treeTrunk = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_tree_trunk_night);
70 | treeLeaf = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_tree_leaf_night);
71 | treeLeafPaint = new Paint();
72 |
73 | valueAnimatorAlpha = new ValueAnimator();
74 |
75 | }
76 |
77 | @Override
78 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
79 | super.onSizeChanged(w, h, oldw, oldh);
80 |
81 | treeX = w / 4 * 3;
82 | treeY = (int) (h / 5 * 3 - treeTrunk.getHeight() / 4 * SCALESIZE);
83 |
84 | rotateCenterX = treeX;
85 | rotateCenterY = (int) (treeY + treeTrunk.getHeight() * SCALESIZE / 8 + treeBranch.getHeight() * SCALESIZE);
86 |
87 | treeStartPointX = treeX - treeBallMiddle.getWidth() / 2 * SCALESIZEBALL;
88 | treeStartPointY = treeY - treeBallMiddle.getWidth() * SCALESIZEBALL / 2;
89 | treeEndPointX = w / 2;
90 | treeEndPointY = treeY + treeTrunk.getHeight() * SCALESIZE / 2;
91 | treeControlPointX = w / 2;
92 | treeControlPointY = treeY - treeBallMiddle.getWidth() * SCALESIZEBALL / 2;
93 | startAnimTree();
94 |
95 | }
96 |
97 | @Override
98 | protected void onDraw(Canvas canvas) {
99 | super.onDraw(canvas);
100 | drawLeaf(canvas);
101 | drawTree(canvas);
102 |
103 | }
104 |
105 | private void drawLeaf(Canvas canvas) {
106 | if (isDrawTree) {
107 | int degreeX = (int) (treeBallMiddle.getWidth() * SCALESIZEBALL / 5);
108 | int degreeY = 20;
109 | treeLeaf_Matrix = new Matrix();
110 | treeLeaf_Matrix.setScale(SCALESIZELEAF, SCALESIZELEAF);
111 | treeLeaf_Matrix.postTranslate(moveLeafX, moveLeafY);
112 | treeLeaf_Matrix.postRotate((float) (randomRotate + rotateValueLeaf)
113 | , moveLeafX + treeLeaf.getWidth() * SCALESIZELEAF / 2, moveLeafY + treeLeaf.getHeight() * SCALESIZELEAF / 2);
114 | canvas.drawBitmap(treeLeaf, treeLeaf_Matrix, treeLeafPaint);
115 |
116 | treeLeaf_Matrix = new Matrix();
117 | treeLeaf_Matrix.setScale(SCALESIZELEAF, SCALESIZELEAF);
118 | treeLeaf_Matrix.postTranslate(moveLeafX + degreeX, moveLeafY + degreeY);
119 | treeLeaf_Matrix.postRotate((float) (randomRotate + rotateValueLeaf - 30)
120 | , moveLeafX + treeLeaf.getWidth() * SCALESIZELEAF / 2 + degreeX, moveLeafY + treeLeaf.getHeight() * SCALESIZELEAF / 2 + degreeY);
121 | canvas.drawBitmap(treeLeaf, treeLeaf_Matrix, treeLeafPaint);
122 |
123 | treeLeaf_Matrix = new Matrix();
124 | treeLeaf_Matrix.setScale(SCALESIZELEAF, SCALESIZELEAF);
125 | treeLeaf_Matrix.postTranslate(moveLeafX + 2 * degreeX, moveLeafY - degreeY);
126 | treeLeaf_Matrix.postRotate((float) (randomRotate + rotateValueLeaf - 60)
127 | , moveLeafX + treeLeaf.getWidth() * SCALESIZELEAF / 2 + 2 * degreeX, moveLeafY + treeLeaf.getHeight() * SCALESIZELEAF / 2 - degreeY);
128 | canvas.drawBitmap(treeLeaf, treeLeaf_Matrix, treeLeafPaint);
129 |
130 | treeLeaf_Matrix = new Matrix();
131 | treeLeaf_Matrix.setScale(SCALESIZELEAF, SCALESIZELEAF);
132 | treeLeaf_Matrix.postTranslate(moveLeafX + 3 * degreeX, moveLeafY + degreeY);
133 | treeLeaf_Matrix.postRotate((float) (randomRotate + rotateValueLeaf - 90)
134 | , moveLeafX + treeLeaf.getWidth() * SCALESIZELEAF / 2 + 3 * degreeX, moveLeafY + treeLeaf.getHeight() * SCALESIZELEAF / 2 + degreeY);
135 | canvas.drawBitmap(treeLeaf, treeLeaf_Matrix, treeLeafPaint);
136 | }
137 | }
138 |
139 | private void drawTree(Canvas canvas) {
140 | treeTrunk_Matrix = new Matrix();
141 | treeTrunk_Matrix.setScale(SCALESIZE, SCALESIZE);
142 | treeTrunk_Matrix.postTranslate(treeX, treeY);
143 |
144 | treeBranch_Matrix = new Matrix();
145 | treeBranch_Matrix.setScale(SCALESIZE, SCALESIZE);
146 | treeBranch_Matrix.postTranslate(treeX - treeBranch.getWidth() * SCALESIZE / 2, treeY + treeTrunk.getHeight() * SCALESIZE / 8);
147 |
148 | treeBallMiddle_Matrix = new Matrix();
149 | treeBallMiddle_Matrix.setScale(SCALESIZEBALL, SCALESIZEBALL);
150 | treeBallMiddle_Matrix.postTranslate(treeX - treeBallMiddle.getWidth() / 2 * SCALESIZEBALL
151 | , treeY - treeBallMiddle.getWidth() * SCALESIZEBALL + 10);
152 |
153 | float offsetXY = getoffsetXY(treeBallLeft.getWidth() * SCALESIZEBALL / 2);
154 | treeBallLeft_Matrix = new Matrix();
155 | treeBallLeft_Matrix.setScale(SCALESIZEBALL, SCALESIZEBALL);
156 | treeBallLeft_Matrix.postTranslate(treeX - treeBranch.getWidth() * SCALESIZE / 2 - treeBallLeft.getWidth() * SCALESIZEBALL + offsetXY
157 | , treeY + treeTrunk.getHeight() * SCALESIZE / 8 - treeBallLeft.getHeight() * SCALESIZEBALL + offsetXY);
158 |
159 | offsetXY = getoffsetXY(treeBallRight.getWidth() * SCALESIZEBALL / 2) +
160 | CalculateUtil.getPythagorean(treeBranch.getWidth() * SCALESIZE / 2, treeBranch.getHeight() * SCALESIZE) / 4;
161 | treeBallRight_Matrix = new Matrix();
162 | treeBallRight_Matrix.setScale(SCALESIZEBALL, SCALESIZEBALL);
163 | treeBallRight_Matrix.postTranslate(treeX + treeBranch.getWidth() * SCALESIZE / 2 - offsetXY
164 | , treeY + treeTrunk.getHeight() * SCALESIZE / 8 - treeBallRight.getHeight() * SCALESIZEBALL + offsetXY);
165 |
166 |
167 | treeBallLeft_Matrix.postRotate(rotateValueTree, rotateCenterX, rotateCenterY);
168 | treeBallRight_Matrix.postRotate(rotateValueTree, rotateCenterX, rotateCenterY);
169 | treeBallMiddle_Matrix.postRotate(rotateValueTree, rotateCenterX, rotateCenterY);
170 | treeBranch_Matrix.postRotate(rotateValueTree, rotateCenterX, rotateCenterY);
171 | canvas.drawBitmap(treeTrunk, treeTrunk_Matrix, null);
172 | canvas.drawBitmap(treeBranch, treeBranch_Matrix, null);
173 | canvas.drawBitmap(treeBallLeft, treeBallLeft_Matrix, null);
174 | canvas.drawBitmap(treeBallMiddle, treeBallMiddle_Matrix, null);
175 | canvas.drawBitmap(treeBallRight, treeBallRight_Matrix, null);
176 | }
177 |
178 | private float getoffsetXY(float radius) {
179 | double clinodiagonal = radius * Math.sqrt(2);
180 | double offsetxy = (clinodiagonal - radius) * Math.sin(45 * Math.PI / 180);
181 | return (float) offsetxy;
182 | }
183 |
184 | public void startAnimTree() {
185 | valueAnimatorTree = new ValueAnimator().ofFloat(0, 15);
186 | valueAnimatorTree.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
187 | @Override
188 | public void onAnimationUpdate(ValueAnimator animation) {
189 | rotateValueTree = 360 - (float) animation.getAnimatedValue();
190 | invalidate();
191 | }
192 | });
193 | valueAnimatorTree.addPauseListener(new Animator.AnimatorPauseListener() {
194 | @Override
195 | public void onAnimationPause(Animator animation) {
196 | rotateValueTree = 0;
197 | isDrawTree = true;
198 | startAnimLeaf();
199 | }
200 |
201 | @Override
202 | public void onAnimationResume(Animator animation) {
203 |
204 | }
205 | });
206 | valueAnimatorTree.addListener(new AnimatorListenerAdapter() {
207 | @Override
208 | public void onAnimationRepeat(Animator animation) {
209 | ++timesTree;
210 | if (timesTree % 2 == 1)
211 | valueAnimatorTree.pause();
212 | }
213 | });
214 | valueAnimatorTree.setDuration(2000);
215 | valueAnimatorTree.setRepeatMode(ValueAnimator.REVERSE);
216 | valueAnimatorTree.setRepeatCount(ValueAnimator.INFINITE);
217 | valueAnimatorTree.setInterpolator(new LinearInterpolator());
218 | valueAnimatorTree.start();
219 |
220 |
221 | }
222 |
223 | public void startAnimLeaf() {
224 | randomRotate = Math.random() * 90;
225 | BezierEvaluator bezierEvaluator = new BezierEvaluator(new PointF(treeControlPointX, treeControlPointY));
226 | final ValueAnimator anim = ValueAnimator.ofObject(bezierEvaluator,
227 | new PointF(treeStartPointX, treeStartPointY),
228 | new PointF(treeEndPointX, treeEndPointY));
229 | anim.setDuration(4000);
230 | anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
231 | @Override
232 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
233 | PointF point = (PointF) valueAnimator.getAnimatedValue();
234 | moveLeafX = point.x;
235 | moveLeafY = point.y;
236 | float fraction =valueAnimator.getAnimatedFraction();
237 | rotateValueLeaf = 90 * fraction;
238 | if (fraction>=0.75 && valueAnimatorAlpha.isRunning()== false){
239 | startAlpha();
240 | }
241 | invalidate();
242 | }
243 | });
244 | anim.setInterpolator(new LinearInterpolator());
245 | anim.addListener(new AnimatorListenerAdapter() {
246 | @Override
247 | public void onAnimationEnd(Animator animation) {
248 | isDrawTree = false;
249 | valueAnimatorTree.resume();
250 | invalidate();
251 | }
252 | });
253 | anim.start();
254 | }
255 | private void startAlpha(){
256 | valueAnimatorAlpha = ValueAnimator.ofFloat(0,1);
257 | valueAnimatorAlpha.setDuration(1000);
258 | valueAnimatorAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
259 | @Override
260 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
261 | float fraction = (float) valueAnimator.getAnimatedValue();
262 | treeLeafPaint.setAlpha((int) (255 - 255 * fraction));
263 | }
264 | });
265 | valueAnimatorAlpha.addListener(new AnimatorListenerAdapter() {
266 | @Override
267 | public void onAnimationEnd(Animator animation) {
268 | treeLeafPaint = new Paint();
269 | }
270 | });
271 | valueAnimatorAlpha.setInterpolator(new LinearInterpolator());
272 | valueAnimatorAlpha.start();
273 | }
274 | }
275 |
--------------------------------------------------------------------------------
/clip/backgroudView.java:
--------------------------------------------------------------------------------
1 | package com.example.sangenan.weather;
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.RectF;
8 | import android.graphics.drawable.BitmapDrawable;
9 | import android.graphics.drawable.Drawable;
10 | import android.util.AttributeSet;
11 | import android.util.Log;
12 | import android.widget.ImageView;
13 |
14 | /**
15 | * Created by kuwakuzukusunoki on 2017/1/31.
16 | */
17 |
18 | public class backgroudView extends ImageView {
19 | private int Width;
20 | private int Height;
21 | private float scaleBackgroud;
22 | private float scaleSideHill;
23 | private Bitmap sidehillLeft;
24 | private Bitmap sidehillRight;
25 | private RectF mRectFLeft;
26 | private RectF mRectFRight;
27 | private static final int maxOffsetX = 50;
28 | private Bitmap backgroud;
29 | private float currentOffsetX;
30 | private float mProgress;
31 |
32 | public backgroudView(Context context) {
33 | super(context);
34 | init();
35 | }
36 |
37 | public backgroudView(Context context, AttributeSet attrs) {
38 | super(context, attrs);
39 | init();
40 |
41 | }
42 |
43 | private void init() {
44 | currentOffsetX = 0;
45 | mProgress = 0;
46 | }
47 |
48 | @Override
49 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
50 | super.onSizeChanged(w, h, oldw, oldh);
51 | Width = w;
52 | Height = h;
53 | scaleBackgroud = w / h;
54 | BitmapFactory.Options optionsSideHill = new BitmapFactory.Options();
55 | optionsSideHill.inJustDecodeBounds = true;
56 | BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_left_night, optionsSideHill);
57 | if (optionsSideHill.outHeight != 0)
58 | scaleSideHill = optionsSideHill.outWidth / optionsSideHill.outHeight;
59 | mRectFLeft = new RectF(-maxOffsetX, Height / 5 * 3, -maxOffsetX + Height / 5 * 2 * scaleSideHill, Height);
60 | if (Width < Height / 3 * scaleSideHill) {
61 | mRectFRight = new RectF(-maxOffsetX, Height / 5 * 3, maxOffsetX + Height / 5 * 2 * scaleSideHill, Height);
62 | } else {
63 | mRectFRight = new RectF(-maxOffsetX, Height / 5 * 3, maxOffsetX + Width, Height);
64 | }
65 | BitmapFactory.Options options = new BitmapFactory.Options();
66 | options.inJustDecodeBounds = true;
67 | BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_right_night, options);
68 | options.inSampleSize = 32;
69 | options.inJustDecodeBounds = false;
70 | backgroud = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_night, options);
71 | Drawable drawable = new BitmapDrawable(backgroud);
72 | setBackground(drawable);
73 |
74 | optionsSideHill = new BitmapFactory.Options();
75 | optionsSideHill.inJustDecodeBounds = true;
76 | BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_left_night, optionsSideHill);
77 | optionsSideHill.inSampleSize = calculateInSampleSize(optionsSideHill, (int) (Height / 5 * 2 * scaleSideHill), Height / 5 * 2);
78 | optionsSideHill.inJustDecodeBounds = false;
79 | sidehillLeft = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_left_night, optionsSideHill);
80 |
81 | optionsSideHill = new BitmapFactory.Options();
82 | optionsSideHill.inJustDecodeBounds = true;
83 | BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_right_night, optionsSideHill);
84 | optionsSideHill.inSampleSize = calculateInSampleSize(optionsSideHill, 2 * maxOffsetX + Width, Height / 5 * 2);
85 | optionsSideHill.inJustDecodeBounds = false;
86 | sidehillRight = BitmapFactory.decodeResource(getResources(), R.drawable.bg_sunny_right_night, optionsSideHill);
87 | }
88 |
89 | @Override
90 | protected void onDraw(Canvas canvas) {
91 | super.onDraw(canvas);
92 | currentOffsetX = maxOffsetX * mProgress;
93 | canvas.translate(currentOffsetX,0);
94 | canvas.drawBitmap(sidehillLeft, null, mRectFLeft, null);
95 | canvas.drawBitmap(sidehillRight, null, mRectFRight, null);
96 |
97 | }
98 |
99 | public int calculateInSampleSize(BitmapFactory.Options options, int reqWidth,
100 | int reqHeight) {
101 | final int height = options.outHeight;
102 | final int width = options.outWidth;
103 | int inSampleSize = 1;
104 |
105 | if (height > reqHeight || width > reqWidth) {
106 |
107 | // Calculate ratios of height and width to requested height and width
108 | final int heightRatio = Math.round((float) height / (float) reqHeight);
109 | final int widthRatio = Math.round((float) width / (float) reqWidth);
110 |
111 | // Choose the smallest ratio as inSampleSize value, this will guarantee
112 | // a final image with both dimensions larger than or equal to the
113 | // requested height and width.
114 | inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
115 | }
116 |
117 | return inSampleSize;
118 | }
119 |
120 | public void setSensorChangedFraction(float v) {
121 | Log.d("tag", "fraction" + v);
122 | mProgress =v;
123 | invalidate();
124 | }
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/clip/flyingBirds.java:
--------------------------------------------------------------------------------
1 | package com.example.sangenan.weather;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.graphics.Bitmap;
8 | import android.graphics.BitmapFactory;
9 | import android.graphics.Canvas;
10 | import android.graphics.Paint;
11 | import android.graphics.PointF;
12 | import android.graphics.RectF;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 | import android.view.animation.LinearInterpolator;
16 |
17 | import com.example.sangenan.weather.Util.BezierEvaluator;
18 | import com.example.sangenan.weather.Util.BitmapUtil;
19 | import com.example.sangenan.weather.Util.ScaleChangeUtils;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 |
25 | /**
26 | * Created by kuwakuzukusunoki on 2017/1/29.
27 | */
28 |
29 | public class flyingBirds extends View {
30 | private int birdTimes;
31 | private Paint birdPaint;
32 |
33 | private Bitmap bird ;
34 | private int Height;
35 | private int Width;
36 | private int offsetBirds;
37 | private int birdStartPointX;
38 | private int birdStartPointY;
39 | private int birdEndPointX;
40 | private int birdEndPointY;
41 |
42 | private int birdMovePointX;
43 | private int birdMovePointY;
44 |
45 | private int birdControlPointX;
46 | private int birdControlPointY;
47 | private static final int birdsSize = 45;
48 | private boolean isDrawBirds = false;
49 | private List birdsList = new ArrayList<>(16);
50 |
51 | public flyingBirds(Context context) {
52 | super(context);
53 | init(context);
54 |
55 | }
56 |
57 | public flyingBirds(Context context, AttributeSet attrs) {
58 | super(context, attrs);
59 | init(context);
60 |
61 | }
62 | private void init(Context context){
63 | bird = BitmapFactory.decodeResource(getResources(),R.drawable.blue01);
64 | birdPaint = new Paint();
65 | birdPaint.setStyle(Paint.Style.STROKE);
66 | birdTimes = 0;
67 | offsetBirds = ScaleChangeUtils.dp2px(context,15);
68 | ThreadBirds threadBirds = new ThreadBirds();
69 | threadBirds.start();
70 | }
71 | @Override
72 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
73 | super.onSizeChanged(w, h, oldw, oldh);
74 | Width = w;
75 | Height = h;
76 | birdStartPointX = Width;
77 | birdStartPointY = Height / 4;
78 | birdEndPointX = -3*offsetBirds-birdsSize;
79 | birdEndPointY = 0;
80 | birdControlPointX = Width / 2;
81 | birdControlPointY = Height / 4 + 80;
82 |
83 | }
84 |
85 | @Override
86 | protected void onDraw(Canvas canvas) {
87 | super.onDraw(canvas);
88 | if (isDrawBirds) {
89 | canvas.drawBitmap(bird, null, new RectF(birdMovePointX, birdMovePointY, birdMovePointX + birdsSize, birdMovePointY + birdsSize), null);
90 | canvas.drawBitmap(bird, null, new RectF(birdMovePointX + offsetBirds, birdMovePointY - offsetBirds / 2, birdMovePointX + birdsSize + offsetBirds, birdMovePointY + birdsSize - offsetBirds / 2), null);
91 | canvas.drawBitmap(bird, null, new RectF(birdMovePointX + 2 * offsetBirds, birdMovePointY - offsetBirds / 2, birdMovePointX + birdsSize + 2 * offsetBirds, birdMovePointY + birdsSize - offsetBirds / 2), null);
92 | canvas.drawBitmap(bird, null, new RectF((float) (birdMovePointX + 1.5 * offsetBirds), (float) (birdMovePointY + offsetBirds / 2), (float) (birdMovePointX + birdsSize + 1.5 * offsetBirds), (float) (birdMovePointY + birdsSize + offsetBirds / 2)), null);
93 | canvas.drawBitmap(bird, null, new RectF(birdMovePointX + 3 * offsetBirds, (float) (birdMovePointY - 1.5 * offsetBirds), birdMovePointX + birdsSize + 3 * offsetBirds, (float) (birdMovePointY + birdsSize - 1.5 * offsetBirds)), null);
94 | }
95 | }
96 | public void startAnimBirds() {
97 | isDrawBirds = true;
98 | BezierEvaluator bezierEvaluator = new BezierEvaluator(new PointF(birdControlPointX, birdControlPointY));
99 | final ValueAnimator anim = ValueAnimator.ofObject(bezierEvaluator,
100 | new PointF(birdStartPointX, birdStartPointY),
101 | new PointF(birdEndPointX, birdEndPointY));
102 | anim.setDuration(8000);
103 | anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
104 | @Override
105 | public void onAnimationUpdate(ValueAnimator valueAnimator) {
106 | PointF point = (PointF) valueAnimator.getAnimatedValue();
107 | birdMovePointX = (int) point.x;
108 | birdMovePointY = (int) point.y;
109 | ++birdTimes;
110 | if (birdTimes % 8 == 0){
111 | updatebirds(birdTimes);
112 | }
113 | invalidate();
114 | }
115 | });
116 | anim.setInterpolator(new LinearInterpolator());
117 | anim.addListener(new AnimatorListenerAdapter() {
118 | @Override
119 | public void onAnimationRepeat(Animator animation) {
120 | super.onAnimationRepeat(animation);
121 | birdTimes = 0 ;
122 | }
123 | });
124 | anim.setRepeatMode(ValueAnimator.RESTART);
125 | anim.setRepeatCount(ValueAnimator.INFINITE);
126 | anim.start();
127 | }
128 | private void updatebirds(int birdTimes){
129 | bird = birdsList.get(birdTimes % 16);
130 | }
131 | class ThreadBirds extends Thread{
132 |
133 | @Override
134 | public void run() {
135 | for (int i=0;i<15;++i){
136 | birdsList.add(i,BitmapFactory.decodeResource(getResources(), BitmapUtil.getBirdsResource(i+1)));
137 | }
138 | }
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/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/sangenan/Weather/d080822514863250820173a8e5ac0d88cff810a9/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 |
--------------------------------------------------------------------------------