├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_live.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_happy_red_16.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_white_flash_128.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable-anydpi
│ │ │ │ ├── ic_happy_white_32.png
│ │ │ │ ├── anim_square_play.xml
│ │ │ │ ├── arrow_anim.xml
│ │ │ │ ├── ic_icon_square.xml
│ │ │ │ ├── anim_helix_play.xml
│ │ │ │ ├── anim_beauty_circle_play.xml
│ │ │ │ ├── arrow.xml
│ │ │ │ ├── anim_three_point_loading.xml
│ │ │ │ └── ic_svg_beauty_circle.xml
│ │ │ ├── drawable
│ │ │ │ ├── ripple_red.xml
│ │ │ │ ├── anim_arrow_bank_play.xml
│ │ │ │ ├── ic_svg_icon_helix.xml
│ │ │ │ ├── ic_svg_three_point.xml
│ │ │ │ └── ic_svg_arrow_right_bank.xml
│ │ │ ├── animator
│ │ │ │ ├── anim_translate_top_iii.xml
│ │ │ │ ├── anim_translate_right_i.xml
│ │ │ │ ├── anim_path_start.xml
│ │ │ │ ├── anim_fivestar.xml
│ │ │ │ ├── anim_left.xml
│ │ │ │ ├── anim_right.xml
│ │ │ │ ├── anim_color_turn_red_fill.xml
│ │ │ │ ├── anim_translate_top.xml
│ │ │ │ ├── anim_path_end.xml
│ │ │ │ ├── anim_translate_top_i.xml
│ │ │ │ ├── anim_translate_top_ii.xml
│ │ │ │ ├── anim_color_turn_red.xml
│ │ │ │ └── anim_square_to_helix.xml
│ │ │ └── layout
│ │ │ │ ├── activity_test_anim.xml
│ │ │ │ ├── activity_path_measure.xml
│ │ │ │ ├── activity_bezier.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── activity_vector.xml
│ │ │ │ └── activity_lollipop.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── rayhahah
│ │ │ │ └── advancedanim
│ │ │ │ ├── MainFragment.java
│ │ │ │ ├── bezier
│ │ │ │ ├── BezierUtil.java
│ │ │ │ ├── DrawPathView.java
│ │ │ │ ├── BezierActivity.java
│ │ │ │ ├── SecondBezierView.java
│ │ │ │ ├── ThirdBezierView.java
│ │ │ │ ├── BallRollView.java
│ │ │ │ └── WaveView.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── pathmeasure
│ │ │ │ ├── PathMeasureActivity.java
│ │ │ │ └── PathMeasureView.java
│ │ │ │ ├── vector
│ │ │ │ └── VectorActivity.java
│ │ │ │ └── lollipop
│ │ │ │ ├── LollipopActivity.java
│ │ │ │ └── TestAnimActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── rayhahah
│ │ │ └── advancedanim
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── rayhahah
│ │ └── advancedanim
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── kotlinc.xml
├── inspectionProfiles
│ ├── profiles_settings.xml
│ └── Project_Default.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AdvancedAnim
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_live.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/mipmap-mdpi/ic_live.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_happy_red_16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/mipmap-mdpi/ic_happy_red_16.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_white_flash_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/mipmap-mdpi/ic_white_flash_128.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-anydpi/ic_happy_white_32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayhahah/AdvancedAnim/HEAD/app/src/main/res/drawable-anydpi/ic_happy_white_32.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ripple_red.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Mar 30 20:35:12 CST 2017
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-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #6a46ff
7 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AdvancedAnim
2 | Android动画进阶使用Demo
3 |
4 | ## VectorDrawable的使用
5 | 参照我的简述博客[VectorDrawable动画进阶](http://www.jianshu.com/p/e71978a6cffa)
6 |
7 | ## PathMeasure的使用
8 | 参照我的简书博客[PathMeasure动画进阶](http://www.jianshu.com/p/4b440fca400a)
9 |
10 | ## Lollipop中动画的使用
11 | 参照我的简书博客[Lollipop动画进阶](http://www.jianshu.com/p/04db6ddae20f)
12 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/anim_translate_top_iii.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/anim_translate_right_i.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/MainFragment.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v7.app.AppCompatDelegate;
5 |
6 | /**
7 | * Created by a on 2017/3/30.
8 | */
9 |
10 | public class MainFragment extends Fragment {
11 |
12 | static {
13 | AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/anim_path_start.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/anim_fivestar.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-anydpi/anim_square_play.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-anydpi/arrow_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/anim_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/anim_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/anim_color_turn_red_fill.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/anim_translate_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/anim_path_end.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-anydpi/ic_icon_square.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/test/java/com/rayhahah/advancedanim/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim;
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 | }
--------------------------------------------------------------------------------
/app/src/main/res/animator/anim_translate_top_i.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/anim_translate_top_ii.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/anim_color_turn_red.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-anydpi/anim_helix_play.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/animator/anim_square_to_helix.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-anydpi/anim_beauty_circle_play.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
9 |
10 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/anim_arrow_bank_play.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
13 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-anydpi/arrow.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_svg_icon_helix.xml:
--------------------------------------------------------------------------------
1 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
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 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-anydpi/anim_three_point_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
15 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/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=-Xmx1024m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/rayhahah/advancedanim/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim;
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.rayhahah.advancedanim", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/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 E:\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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_svg_three_point.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-anydpi/ic_svg_beauty_circle.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | //apply plugin : 表示Gradle所引入的插件
2 | //这里表示该module是一个Android Application,插件里面有Android相关的一切工具
3 | apply plugin: 'com.android.application'
4 |
5 | //android : 描述了当前Android module构建过程所用到的所有参数
6 | android {
7 | //目标版本号
8 | compileSdkVersion 25
9 | //编译工具版本号
10 |
11 | buildToolsVersion "25.0.2"
12 | //默认配置
13 | defaultConfig {
14 | applicationId "com.rayhahah.advancedanim"
15 | minSdkVersion 19
16 | targetSdkVersion 25
17 | versionCode 1
18 | versionName "1.0"
19 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
20 | vectorDrawables.useSupportLibrary = true
21 | }
22 | //构建配置
23 | buildTypes {
24 | release {
25 | minifyEnabled false
26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
27 | }
28 | }
29 | }
30 | //dependencies : 当前Android Module构建过程中所依赖的所有库
31 | dependencies {
32 | compile fileTree(dir: 'libs', include: ['*.jar'])
33 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
34 | exclude group: 'com.android.support', module: 'support-annotations'
35 | })
36 | compile 'com.android.support:appcompat-v7:25.2.0'
37 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
38 | compile 'com.ashokvarma.android:bottom-navigation-bar:1.3.0'
39 | testCompile 'junit:junit:4.12'
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_svg_arrow_right_bank.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
13 |
14 |
15 |
16 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_test_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
21 |
22 |
30 |
31 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/bezier/BezierUtil.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim.bezier;
2 |
3 | import android.graphics.PointF;
4 |
5 | /**
6 | * Created by a on 2017/4/2.
7 | */
8 |
9 | public class BezierUtil {
10 |
11 |
12 | /**
13 | * 根据起始点,控制点,终止点坐标和曲线长度比例获取曲线上点的坐标
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 | * 根据起始点,控制点,终止点坐标和曲线长度比例获取曲线上点的坐标 *
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 |
48 |
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_path_measure.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
21 |
22 |
30 |
31 |
38 |
39 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import com.rayhahah.advancedanim.bezier.BezierActivity;
10 | import com.rayhahah.advancedanim.lollipop.LollipopActivity;
11 | import com.rayhahah.advancedanim.pathmeasure.PathMeasureActivity;
12 | import com.rayhahah.advancedanim.vector.VectorActivity;
13 |
14 | public class MainActivity extends AppCompatActivity {
15 |
16 |
17 | private Button btnVector;
18 | private Button btnBezier;
19 | private Button btnPathmeasure;
20 | private Button btnLollipop;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 |
27 | initView();
28 | }
29 |
30 |
31 | public void doClick(View view) {
32 | switch (view.getId()) {
33 | case R.id.btn_vector:
34 | startActivity(new Intent(this, VectorActivity.class));
35 | break;
36 | case R.id.btn_bezier:
37 | startActivity(new Intent(this, BezierActivity.class));
38 | break;
39 | case R.id.btn_pathmeasure:
40 | startActivity(new Intent(this, PathMeasureActivity.class));
41 | break;
42 | case R.id.btn_lollipop:
43 | startActivity(new Intent(this, LollipopActivity.class));
44 | break;
45 |
46 | }
47 |
48 | }
49 |
50 | private void initView() {
51 | btnVector = (Button) findViewById(R.id.btn_vector);
52 | btnBezier = (Button) findViewById(R.id.btn_bezier);
53 | btnPathmeasure = (Button) findViewById(R.id.btn_pathmeasure);
54 | btnLollipop = (Button) findViewById(R.id.btn_lollipop);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_bezier.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
19 |
26 |
27 |
33 |
34 |
40 |
41 |
47 |
48 |
49 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/pathmeasure/PathMeasureActivity.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim.pathmeasure;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.widget.CompoundButton;
6 | import android.widget.ToggleButton;
7 |
8 | import com.rayhahah.advancedanim.R;
9 |
10 | public class PathMeasureActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
11 |
12 | private PathMeasureView pathMeasureView;
13 | private ToggleButton tbNormal;
14 | private ToggleButton tbWindow;
15 | private ToggleButton tbArrow;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_path_measure);
21 | initView();
22 | }
23 |
24 | private void initView() {
25 | pathMeasureView = (PathMeasureView) findViewById(R.id.pathMeasureView);
26 | tbNormal = (ToggleButton) findViewById(R.id.tb_normal);
27 | tbWindow = (ToggleButton) findViewById(R.id.tb_window);
28 | tbArrow = (ToggleButton) findViewById(R.id.tb_arrow);
29 | tbNormal.setOnCheckedChangeListener(this);
30 | tbWindow.setOnCheckedChangeListener(this);
31 | tbArrow.setOnCheckedChangeListener(this);
32 | }
33 |
34 |
35 | @Override
36 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
37 | switch (buttonView.getId()) {
38 | case R.id.tb_normal:
39 | if (isChecked) {
40 | pathMeasureView.startAnim();
41 | } else {
42 | pathMeasureView.pauseAnim();
43 | }
44 |
45 | break;
46 | case R.id.tb_window:
47 | if (isChecked) {
48 | pathMeasureView.setWindow(true);
49 | } else {
50 | pathMeasureView.setWindow(false);
51 | }
52 | break;
53 |
54 | case R.id.tb_arrow:
55 |
56 | if (isChecked) {
57 | pathMeasureView.setArrow(true);
58 | } else {
59 | pathMeasureView.setArrow(false);
60 | }
61 |
62 | break;
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/vector/VectorActivity.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim.vector;
2 |
3 | import android.graphics.drawable.Animatable;
4 | import android.graphics.drawable.AnimatedVectorDrawable;
5 | import android.graphics.drawable.Drawable;
6 | import android.os.Bundle;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.app.AppCompatDelegate;
9 | import android.view.View;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 |
13 | import com.rayhahah.advancedanim.R;
14 |
15 | public class VectorActivity extends AppCompatActivity {
16 |
17 | static {
18 | //设置Activity支持5.0以下版本兼容VectorDrawable
19 | AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
20 |
21 | }
22 |
23 | private TextView textView;
24 | private TextView tvPath;
25 | private TextView tvSet;
26 | private TextView tvStar;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_vector);
32 | initView();
33 | }
34 |
35 | public void doClick(View view) {
36 |
37 | /**
38 | * 这个主要针对pathData路径变化
39 | * 只支持5.0以上的版本
40 | */
41 | if (view.getId() == R.id.tv_path) {
42 | AnimatedVectorDrawable vectorDrawable = (AnimatedVectorDrawable) getDrawable(R.drawable.anim_square_play);
43 | ((TextView) view).setCompoundDrawables(null, vectorDrawable, null, null);
44 | vectorDrawable.start();
45 | } else {
46 |
47 | /**
48 | * TextView中获取资源并启动
49 | */
50 | if (view instanceof TextView) {
51 | Drawable[] drawables = ((TextView) view).getCompoundDrawables();
52 | ((Animatable) drawables[1]).start();
53 | }
54 |
55 | /**
56 | * ImageView中获取资源并启动
57 | */
58 | if (view instanceof ImageView) {
59 | ((Animatable) ((ImageView) view).getDrawable()).start();
60 | }
61 | }
62 | }
63 |
64 | private void initView() {
65 | textView = (TextView) findViewById(R.id.textView);
66 | tvPath = (TextView) findViewById(R.id.tv_path);
67 | tvSet = (TextView) findViewById(R.id.tv_set);
68 | tvStar = (TextView) findViewById(R.id.tv_star);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
25 |
26 |
36 |
37 |
47 |
48 |
58 |
59 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/.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 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/lollipop/LollipopActivity.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim.lollipop;
2 |
3 | import android.app.ActivityOptions;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.util.Pair;
8 | import android.view.View;
9 | import android.widget.Button;
10 |
11 | import com.rayhahah.advancedanim.R;
12 |
13 | public class LollipopActivity extends AppCompatActivity {
14 |
15 | private Intent mIntent;
16 | private Button btnNormal;
17 | private Button btnExplode;
18 | private Button btnSlide;
19 | private Button btnFade;
20 | private View ivImageI;
21 | private View ivImageIi;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_lollipop);
27 | initView();
28 | }
29 |
30 | public void btnClick(View view) {
31 | mIntent = new Intent(this, TestAnimActivity.class);
32 | int animType = 0;
33 | switch (view.getId()) {
34 | case R.id.btn_normal:
35 | animType = TestAnimActivity.ANIM_NORMAL;
36 | break;
37 | case R.id.btn_explode:
38 | animType = TestAnimActivity.ANIM_EXPLODE;
39 | break;
40 | case R.id.btn_slide:
41 | animType = TestAnimActivity.ANIM_SLIDE;
42 | break;
43 | case R.id.btn_fade:
44 | animType = TestAnimActivity.ANIM_FADE;
45 | break;
46 | case R.id.btn_changebounds:
47 | animType = 4;
48 | break;
49 | case R.id.btn_changeclipbounds:
50 | animType = 5;
51 | break;
52 | case R.id.btn_changetransform:
53 | animType = 6;
54 | break;
55 | case R.id.btn_changeimagetransform:
56 | animType = 7;
57 | break;
58 |
59 | }
60 | mIntent.putExtra(TestAnimActivity.TAG_ANIM, animType);
61 |
62 | if (animType == TestAnimActivity.ANIM_NORMAL)
63 | startActivity(mIntent);
64 | else
65 | startActivity(mIntent,
66 | ActivityOptions.makeSceneTransitionAnimation(this,
67 | Pair.create(ivImageI, "one"),
68 | Pair.create(ivImageIi, "two"))
69 | .toBundle());
70 |
71 | }
72 |
73 | private void initView() {
74 | btnNormal = (Button) findViewById(R.id.btn_normal);
75 | btnExplode = (Button) findViewById(R.id.btn_explode);
76 | btnSlide = (Button) findViewById(R.id.btn_slide);
77 | btnFade = (Button) findViewById(R.id.btn_fade);
78 | ivImageI = findViewById(R.id.iv_image_i);
79 | ivImageIi = findViewById(R.id.iv_image_ii);
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/bezier/DrawPathView.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim.bezier;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Path;
8 | import android.support.annotation.Nullable;
9 | import android.util.AttributeSet;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 |
13 | /**
14 | * @author Rayhahah
15 | * @blog http://www.jianshu.com/u/ec42ce134e8d
16 | * @Github https://github.com/Rayhahah
17 | * @time 2017/4/3
18 | * @fuction 触摸画笔绘制,使用贝塞尔曲线优化线条
19 | * @use
20 | */
21 | public class DrawPathView extends View {
22 | private Path mPath;
23 | private Paint mPathPaint;
24 | private Paint mPointPaint;
25 | private float mX;
26 | private float mY;
27 | private float rX;
28 | private float rY;
29 |
30 | public DrawPathView(Context context) {
31 | super(context);
32 |
33 | }
34 |
35 | public DrawPathView(Context context, @Nullable AttributeSet attrs) {
36 | super(context, attrs);
37 | }
38 |
39 | public DrawPathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
40 | super(context, attrs, defStyleAttr);
41 |
42 | }
43 |
44 |
45 | @Override
46 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
47 | super.onSizeChanged(w, h, oldw, oldh);
48 | mPath = new Path();
49 | mPathPaint = new Paint();
50 | mPathPaint.setStyle(Paint.Style.STROKE);
51 | mPathPaint.setColor(Color.BLACK);
52 | mPathPaint.setAntiAlias(true);
53 | mPathPaint.setStrokeWidth(5);
54 | mPointPaint = new Paint();
55 | mPointPaint.setStyle(Paint.Style.FILL_AND_STROKE);
56 | mPointPaint.setColor(Color.BLUE);
57 | mPointPaint.setStrokeWidth(10);
58 | }
59 |
60 | @Override
61 | protected void onDraw(Canvas canvas) {
62 | super.onDraw(canvas);
63 | canvas.drawPath(mPath, mPathPaint);
64 | canvas.drawPoint(rX, rY, mPointPaint);
65 |
66 | }
67 |
68 |
69 | /**
70 | * 触摸绘制
71 | *
72 | * @param event
73 | * @return
74 | */
75 | @Override
76 | public boolean onTouchEvent(MotionEvent event) {
77 | switch (event.getAction()) {
78 | case MotionEvent.ACTION_DOWN:
79 | mPath.reset();
80 | mX = event.getX();
81 | mY = event.getY();
82 | mPath.moveTo(mX, mY);
83 | break;
84 |
85 | case MotionEvent.ACTION_MOVE:
86 | float x = event.getX();
87 | float y = event.getY();
88 |
89 |
90 | rX = (x + mX) / 2;
91 | rY = (y + mY) / 2;
92 |
93 | mPath.quadTo(mX, mY, rX, rY);
94 | mX = x;
95 | mY = y;
96 |
97 | break;
98 | }
99 | invalidate();
100 | return true;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_vector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
17 |
18 |
24 |
25 |
31 |
32 |
43 |
44 |
50 |
51 |
61 |
62 |
73 |
74 |
75 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/bezier/BezierActivity.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim.bezier;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 |
7 | import com.ashokvarma.bottomnavigation.BottomNavigationBar;
8 | import com.ashokvarma.bottomnavigation.BottomNavigationItem;
9 | import com.rayhahah.advancedanim.R;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | public class BezierActivity extends AppCompatActivity implements BottomNavigationBar.OnTabSelectedListener {
15 |
16 | private BottomNavigationBar bnb;
17 | private SecondBezierView secondBV;
18 | private ThirdBezierView thirdBV;
19 | private List mViewList = new ArrayList<>();
20 | private DrawPathView drawPath;
21 | private WaveView waveView;
22 | private BallRollView ballRollView;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_bezier);
28 | initView();
29 |
30 | initBnb();
31 | }
32 |
33 | /**
34 | * BottomNavigationBar初始化
35 | */
36 | private void initBnb() {
37 | bnb.setActiveColor("#ffffff")
38 | .setInActiveColor("#88000000")
39 | .setBarBackgroundColor("#ff0000")
40 | .setMode(BottomNavigationBar.MODE_SHIFTING);
41 | bnb.addItem(new BottomNavigationItem(R.mipmap.ic_white_flash_128, "二阶"))
42 | .addItem(new BottomNavigationItem(R.mipmap.ic_white_flash_128, "三阶"))
43 | .addItem(new BottomNavigationItem(R.mipmap.ic_white_flash_128, "写字板"))
44 | .addItem(new BottomNavigationItem(R.mipmap.ic_white_flash_128, "波浪"))
45 | .addItem(new BottomNavigationItem(R.mipmap.ic_white_flash_128, "滚动小球"))
46 | .initialise();
47 | bnb.setTabSelectedListener(this);
48 |
49 | }
50 |
51 | private void initView() {
52 |
53 | bnb = (BottomNavigationBar) findViewById(R.id.bnb);
54 | secondBV = (SecondBezierView) findViewById(R.id.secondBV);
55 | mViewList.add(secondBV);
56 | thirdBV = (ThirdBezierView) findViewById(R.id.thirdBV);
57 | mViewList.add(thirdBV);
58 | drawPath = (DrawPathView) findViewById(R.id.drawPath);
59 | mViewList.add(drawPath);
60 | waveView = (WaveView) findViewById(R.id.waveView);
61 | mViewList.add(waveView);
62 | ballRollView = (BallRollView) findViewById(R.id.ballRollView);
63 | mViewList.add(ballRollView);
64 | }
65 |
66 | @Override
67 | public void onTabSelected(int position) {
68 | switch (position) {
69 | case 0:
70 | setViewVisible(secondBV);
71 | break;
72 | case 1:
73 | setViewVisible(thirdBV);
74 | break;
75 | case 2:
76 | setViewVisible(drawPath);
77 | break;
78 | case 3:
79 | setViewVisible(waveView);
80 | break;
81 | case 4:
82 | setViewVisible(ballRollView);
83 | break;
84 | }
85 |
86 |
87 | }
88 |
89 | private void setViewVisible(View view) {
90 | for (View v : mViewList) {
91 | if (v.getId() == view.getId()) {
92 | v.setVisibility(View.VISIBLE);
93 | } else {
94 | v.setVisibility(View.GONE);
95 | }
96 | }
97 | }
98 |
99 | @Override
100 | public void onTabUnselected(int position) {
101 |
102 | }
103 |
104 | @Override
105 | public void onTabReselected(int position) {
106 |
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_lollipop.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
17 |
24 |
25 |
32 |
33 |
40 |
41 |
48 |
49 |
50 |
57 |
58 |
66 |
67 |
75 |
76 |
83 |
84 |
85 |
93 |
94 |
102 |
103 |
109 |
110 |
116 |
117 |
118 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/pathmeasure/PathMeasureView.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim.pathmeasure;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.Path;
8 | import android.graphics.PathMeasure;
9 | import android.support.annotation.Nullable;
10 | import android.util.AttributeSet;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.view.animation.AccelerateDecelerateInterpolator;
14 |
15 | /**
16 | * @author Rayhahah
17 | * @blog http://www.jianshu.com/u/ec42ce134e8d
18 | * @Github https://github.com/Rayhahah
19 | * @time 2017/4/3
20 | * @fuction 原生实现路径绘制动画
21 | * @use
22 | */
23 | public class PathMeasureView extends View {
24 | private Paint mPaint;
25 | private Path mCirclePath;
26 | private Path mDstPath;
27 | private PathMeasure mPathMeasure;
28 | private float mLength;
29 | private ValueAnimator mValueAnimator;
30 | private float mAnimatedValue;
31 | private boolean mIsWindow;
32 | private boolean mIsArrow;
33 | private float[] mPos = new float[2];
34 | private float[] mTan = new float[2];
35 |
36 | public PathMeasureView(Context context) {
37 | super(context);
38 | }
39 |
40 | public PathMeasureView(Context context, @Nullable AttributeSet attrs) {
41 | super(context, attrs);
42 | }
43 |
44 | public PathMeasureView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
45 | super(context, attrs, defStyleAttr);
46 | }
47 |
48 |
49 | public void setWindow(boolean window) {
50 | mIsWindow = window;
51 | invalidate();
52 | }
53 |
54 | public void setArrow(boolean arrow) {
55 | mIsArrow = arrow;
56 | invalidate();
57 | }
58 |
59 | @Override
60 | protected void onDraw(Canvas canvas) {
61 | super.onDraw(canvas);
62 | //必须要有lineTo(0,0)才可以实现路径的完整绘制
63 | mDstPath.reset();
64 | mDstPath.lineTo(0, 0);
65 | float stopD = mAnimatedValue * mLength;
66 | float startD = 0;
67 | if (mIsWindow) {
68 | //通过设置其实位置的变化来实现Window加载风格
69 | startD = (float) (stopD - ((0.5 - Math.abs(mAnimatedValue - 0.5)) * mLength));
70 | }
71 |
72 | //获取当前进度的路径,同时赋值给传入的mDstPath
73 | mPathMeasure.getSegment(startD, stopD, mDstPath, true);
74 |
75 | canvas.save();
76 | canvas.translate(300, 300);
77 | canvas.drawPath(mDstPath, mPaint);
78 | canvas.restore();
79 |
80 |
81 | if (mIsArrow) {
82 | //mPos是当前路径点的坐标
83 | //mTan通过下面公式可以得到当前点的切线角度
84 | mPathMeasure.getPosTan(mAnimatedValue * mLength, mPos, mTan);
85 | float degree = (float) (Math.atan2(mTan[1], mTan[0]) * 180 / Math.PI);
86 | Log.e("lzh", "onDraw: degree=" + degree);
87 | canvas.save();
88 | canvas.translate(300, 300);
89 | canvas.drawCircle(mPos[0], mPos[1], 10, mPaint);
90 | canvas.rotate(degree);
91 | //绘制切线
92 | canvas.drawLine(0, -200, 200, -200, mPaint);
93 | canvas.restore();
94 |
95 | }
96 | }
97 |
98 | @Override
99 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
100 | super.onSizeChanged(w, h, oldw, oldh);
101 | mPaint = new Paint();
102 | mPaint.setStyle(Paint.Style.STROKE);
103 | mPaint.setStrokeWidth(5);
104 | //完整的圆的路径
105 | mCirclePath = new Path();
106 | //路径绘制每段截取出来的路径
107 | mDstPath = new Path();
108 |
109 | mCirclePath.addCircle(0, 0, 200, Path.Direction.CW);
110 |
111 | //路径测量类
112 | mPathMeasure = new PathMeasure();
113 | //测量路径
114 | mPathMeasure.setPath(mCirclePath, true);
115 |
116 | //获取被测量路径的总长度
117 | mLength = mPathMeasure.getLength();
118 |
119 | mValueAnimator = ValueAnimator.ofFloat(0, 1);
120 | mValueAnimator.setDuration(2000);
121 | mValueAnimator.setRepeatCount(ValueAnimator.INFINITE);
122 | mValueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
123 | mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
124 | @Override
125 | public void onAnimationUpdate(ValueAnimator animation) {
126 | //获取从0-1的变化值
127 | mAnimatedValue = (float) animation.getAnimatedValue();
128 | //不断刷新绘图,实现路径绘制
129 | invalidate();
130 | }
131 | });
132 | }
133 |
134 | public void startAnim() {
135 | if (mValueAnimator != null) {
136 | mValueAnimator.start();
137 | }
138 | }
139 |
140 | public void pauseAnim() {
141 | if (mValueAnimator != null
142 | && mValueAnimator.isStarted()
143 | && mValueAnimator.isRunning()) {
144 | mValueAnimator.pause();
145 | }
146 | }
147 |
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/bezier/SecondBezierView.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim.bezier;
2 |
3 | import android.animation.TypeEvaluator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.graphics.Path;
10 | import android.graphics.PointF;
11 | import android.support.annotation.Nullable;
12 | import android.util.AttributeSet;
13 | import android.view.MotionEvent;
14 | import android.view.View;
15 | import android.view.animation.AccelerateDecelerateInterpolator;
16 |
17 | /**
18 | * Created by a on 2017/4/1.
19 | */
20 |
21 | public class SecondBezierView extends View {
22 | private int mStartX;
23 | private int mStartY;
24 | private int mEndX;
25 | private int mEndY;
26 | private int mFlagX;
27 | private int mFlagY;
28 | private Path mPath;
29 | private Paint pointPaint;
30 | private Paint linePaint;
31 | private Paint pathPaint;
32 | private ValueAnimator mValueAnimator;
33 | private Paint mMovePaint;
34 | private PointF mMovePoint;
35 |
36 |
37 | public SecondBezierView(Context context) {
38 | super(context, null);
39 | }
40 |
41 | public SecondBezierView(Context context, @Nullable AttributeSet attrs) {
42 | super(context, attrs, 0);
43 | }
44 |
45 | public SecondBezierView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
46 | super(context, attrs, defStyleAttr);
47 |
48 |
49 | }
50 |
51 | private void setPaint(Paint paint, int color, int strokeWidth) {
52 | paint.setAntiAlias(true);
53 | paint.setStrokeWidth(strokeWidth);
54 | paint.setColor(color);
55 | paint.setStyle(Paint.Style.STROKE);
56 | }
57 |
58 | @Override
59 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
60 | super.onSizeChanged(w, h, oldw, oldh);
61 | mStartX = w / 8;
62 | mStartY = h / 2;
63 |
64 | mFlagX = w / 2;
65 | mFlagY = h / 2;
66 |
67 | mEndX = w / 8 * 7;
68 | mEndY = h / 2;
69 |
70 | mPath = new Path();
71 |
72 | pathPaint = new Paint();
73 | setPaint(pathPaint, Color.BLACK, 5);
74 | pointPaint = new Paint();
75 | setPaint(pointPaint, Color.BLUE, 10);
76 | linePaint = new Paint();
77 | setPaint(linePaint, Color.GRAY, 3);
78 |
79 | mMovePaint = new Paint();
80 | mMovePaint.setAntiAlias(true);
81 | mMovePaint.setStyle(Paint.Style.FILL);
82 | mMovePaint.setColor(Color.parseColor("#ff5831"));
83 |
84 | startAnim();
85 | }
86 |
87 | private void startAnim() {
88 | mValueAnimator = ValueAnimator.ofObject(
89 | new SecondBezierEvaluator(new PointF(mFlagX, mFlagY)),
90 | new PointF(mStartX, mStartY),
91 | new PointF(mEndX, mEndY));
92 | mValueAnimator.setDuration(2000);
93 | mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
94 |
95 | @Override
96 | public void onAnimationUpdate(ValueAnimator animation) {
97 | mMovePoint = ((PointF) animation.getAnimatedValue());
98 | invalidate();
99 | }
100 | });
101 | mValueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
102 | mValueAnimator.start();
103 |
104 | }
105 |
106 |
107 | @Override
108 | protected void onDraw(Canvas canvas) {
109 | super.onDraw(canvas);
110 | mPath.reset();
111 | mPath.moveTo(mStartX, mStartY);
112 | mPath.quadTo(mFlagX, mFlagY, mEndX, mEndY);
113 |
114 | canvas.drawPoint(mStartX, mStartY, pointPaint);
115 | canvas.drawPoint(mFlagX, mFlagY, pointPaint);
116 | canvas.drawPoint(mEndX, mEndY, pointPaint);
117 |
118 | canvas.drawLine(mStartX, mStartY, mFlagX, mFlagY, linePaint);
119 | canvas.drawLine(mFlagX, mFlagY, mEndX, mEndY, linePaint);
120 |
121 | canvas.drawCircle(mMovePoint.x, mMovePoint.y, 10, mMovePaint);
122 | canvas.drawPath(mPath, pathPaint);
123 |
124 | }
125 |
126 | @Override
127 | public boolean onTouchEvent(MotionEvent event) {
128 | switch (event.getAction()) {
129 | case MotionEvent.ACTION_MOVE:
130 | mFlagX = (int) event.getX();
131 | mFlagY = (int) event.getY();
132 | invalidate();
133 | break;
134 | case MotionEvent.ACTION_UP:
135 | startAnim();
136 | break;
137 | }
138 |
139 | return true;
140 | }
141 |
142 | /**
143 | * 二阶贝塞尔曲线转换
144 | */
145 | class SecondBezierEvaluator implements TypeEvaluator {
146 |
147 | private PointF mFlagPoint;
148 |
149 | public SecondBezierEvaluator(PointF flagPoint) {
150 | mFlagPoint = flagPoint;
151 | }
152 |
153 | /**
154 | * 根据当前控制点,起始点,终止点,和当前长度比例,计算出贝塞尔曲线上点的坐标
155 | *
156 | * @param fraction
157 | * @param startValue
158 | * @param endValue
159 | * @return
160 | */
161 | @Override
162 | public PointF evaluate(float fraction, PointF startValue, PointF endValue) {
163 | PointF pointF = BezierUtil.CalculateBezierPointForQuadratic(fraction, startValue, mFlagPoint, endValue);
164 | return pointF;
165 | }
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/bezier/ThirdBezierView.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim.bezier;
2 |
3 | import android.animation.TypeEvaluator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.graphics.Path;
10 | import android.graphics.PointF;
11 | import android.support.annotation.Nullable;
12 | import android.util.AttributeSet;
13 | import android.view.MotionEvent;
14 | import android.view.View;
15 | import android.view.animation.AccelerateDecelerateInterpolator;
16 |
17 | /**
18 | * Created by a on 2017/4/1.
19 | */
20 |
21 | public class ThirdBezierView extends View {
22 | private int mStartX;
23 | private int mStartY;
24 | private int mFlagOneX;
25 | private int mFlagOneY;
26 | private int mFlagTwoX;
27 | private int mFlagTwoY;
28 | private int mEndX;
29 | private int mEndY;
30 | private Path mPath;
31 | private Paint pathPaint;
32 | private Paint pointPaint;
33 | private Paint linePaint;
34 | private boolean mIsMoreTouch;
35 | private ValueAnimator mValueAnimator;
36 | private float mMoveX;
37 | private float mMoveY;
38 | private Paint mMovePaint;
39 |
40 | public ThirdBezierView(Context context) {
41 | super(context);
42 | }
43 |
44 | public ThirdBezierView(Context context, @Nullable AttributeSet attrs) {
45 | super(context, attrs);
46 | }
47 |
48 | public ThirdBezierView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
49 | super(context, attrs, defStyleAttr);
50 | }
51 |
52 |
53 | @Override
54 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
55 | super.onSizeChanged(w, h, oldw, oldh);
56 | mStartX = w / 8;
57 | mStartY = h / 2;
58 |
59 | mFlagOneX = w / 8 * 3;
60 | mFlagOneY = h / 2;
61 |
62 | mFlagTwoX = w / 8 * 5;
63 | mFlagTwoY = h / 2;
64 |
65 | mEndX = w / 8 * 7;
66 | mEndY = h / 2;
67 |
68 | mPath = new Path();
69 |
70 | pathPaint = new Paint();
71 | setPaint(pathPaint, Color.BLACK, 5);
72 | pointPaint = new Paint();
73 | setPaint(pointPaint, Color.BLUE, 10);
74 | linePaint = new Paint();
75 | setPaint(linePaint, Color.GRAY, 3);
76 |
77 | mMovePaint = new Paint();
78 | mMovePaint.setAntiAlias(true);
79 | mMovePaint.setStyle(Paint.Style.FILL);
80 | mMovePaint.setColor(Color.parseColor("#ff5831"));
81 | }
82 |
83 | private void setPaint(Paint paint, int color, int strokeWidth) {
84 | paint.setAntiAlias(true);
85 | paint.setStrokeWidth(strokeWidth);
86 | paint.setColor(color);
87 | paint.setStyle(Paint.Style.STROKE);
88 | }
89 |
90 |
91 | @Override
92 | protected void onDraw(Canvas canvas) {
93 | super.onDraw(canvas);
94 |
95 | mPath.reset();
96 | mPath.moveTo(mStartX, mStartY);
97 | //画出三阶贝塞尔曲线!
98 | mPath.cubicTo(mFlagOneX, mFlagOneY, mFlagTwoX, mFlagTwoY, mEndX, mEndY);
99 |
100 | canvas.drawPoint(mStartX, mStartY, pointPaint);
101 | canvas.drawPoint(mFlagOneX, mFlagOneY, pointPaint);
102 | canvas.drawPoint(mFlagTwoX, mFlagTwoY, pointPaint);
103 | canvas.drawPoint(mEndX, mEndY, pointPaint);
104 |
105 | canvas.drawLine(mStartX, mStartY, mFlagOneX, mFlagOneY, linePaint);
106 | canvas.drawLine(mFlagOneX, mFlagOneY, mFlagTwoX, mFlagTwoY, linePaint);
107 | canvas.drawLine(mFlagTwoX, mFlagTwoY, mEndX, mEndY, linePaint);
108 |
109 | canvas.drawCircle(mMoveX, mMoveY, 10, mMovePaint);
110 |
111 | canvas.drawPath(mPath, pathPaint);
112 | }
113 |
114 | @Override
115 | public boolean onTouchEvent(MotionEvent event) {
116 | switch (event.getAction() &
117 | //多指解码,只有添加这个条件才可以识别多指触控
118 | MotionEvent.ACTION_MASK) {
119 | case MotionEvent.ACTION_POINTER_DOWN:
120 | mIsMoreTouch = true;
121 | break;
122 | case MotionEvent.ACTION_MOVE:
123 | mFlagOneX = (int) event.getX(0);
124 | mFlagOneY = (int) event.getY(0);
125 | if (mIsMoreTouch) {
126 | mFlagTwoX = (int) event.getX(1);
127 | mFlagTwoY = (int) event.getY(1);
128 | }
129 | invalidate();
130 | break;
131 | case MotionEvent.ACTION_POINTER_UP:
132 | mIsMoreTouch = false;
133 | // startAnim();
134 | break;
135 | case MotionEvent.ACTION_UP:
136 | startAnim();
137 | break;
138 |
139 | }
140 | return true;
141 | }
142 |
143 | private void startAnim() {
144 |
145 | mValueAnimator = ValueAnimator.ofObject(
146 | new ThirdBezierEvalutor(new PointF(mFlagOneX, mFlagOneY), new PointF(mFlagTwoX, mFlagTwoY)),
147 | new PointF(mStartX, mStartY),
148 | new PointF(mEndX, mEndY)
149 | );
150 | mValueAnimator.setDuration(2000);
151 | mValueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
152 | mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
153 | @Override
154 | public void onAnimationUpdate(ValueAnimator animation) {
155 | PointF pointF = (PointF) animation.getAnimatedValue();
156 | mMoveX = pointF.x;
157 | mMoveY = pointF.y;
158 | invalidate();
159 | }
160 | });
161 | mValueAnimator.start();
162 |
163 |
164 | }
165 |
166 | class ThirdBezierEvalutor implements TypeEvaluator {
167 |
168 | private PointF mFlagOnePoint;
169 | private PointF mFlagTwoPoint;
170 |
171 | public ThirdBezierEvalutor(PointF flagOnePoint, PointF flagTwoPoint) {
172 | mFlagOnePoint = flagOnePoint;
173 | mFlagTwoPoint = flagTwoPoint;
174 | }
175 |
176 | @Override
177 | public PointF evaluate(float fraction, PointF startValue, PointF endValue) {
178 | return BezierUtil.CalculateBezierPointForCubic(fraction, startValue, mFlagOnePoint, mFlagTwoPoint, endValue);
179 | }
180 | }
181 |
182 | }
183 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/lollipop/TestAnimActivity.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim.lollipop;
2 |
3 | import android.animation.Animator;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.transition.ChangeBounds;
7 | import android.transition.ChangeClipBounds;
8 | import android.transition.ChangeImageTransform;
9 | import android.transition.ChangeTransform;
10 | import android.transition.Explode;
11 | import android.transition.Fade;
12 | import android.transition.Slide;
13 | import android.view.View;
14 | import android.view.ViewAnimationUtils;
15 | import android.view.Window;
16 | import android.view.animation.AccelerateDecelerateInterpolator;
17 | import android.widget.ImageView;
18 | import android.widget.LinearLayout;
19 |
20 | import com.rayhahah.advancedanim.R;
21 |
22 | public class TestAnimActivity extends AppCompatActivity {
23 |
24 |
25 | public static final String TAG_ANIM = "TAG_ANIM";
26 | public static int ANIM_NORMAL = 0;
27 | public static int ANIM_EXPLODE = 1;
28 | public static int ANIM_SLIDE = 2;
29 | public static int ANIM_FADE = 3;
30 | private ImageView ivImageI;
31 | private ImageView ivImageIi;
32 | private LinearLayout llRoot;
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
38 | getWindow().setSharedElementsUseOverlay(true);
39 | setTransition(getIntent().getIntExtra(TAG_ANIM, 0));
40 | setContentView(R.layout.activity_test_anim);
41 | initView();
42 |
43 | llRoot.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
44 | @Override
45 | public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
46 | v.removeOnLayoutChangeListener(this);
47 | Animator circularReveal = ViewAnimationUtils.createCircularReveal(
48 | llRoot,
49 | llRoot.getWidth() / 2,
50 | llRoot.getHeight() / 2,
51 | 50,
52 | 1000);
53 | circularReveal.setInterpolator(new AccelerateDecelerateInterpolator());
54 | circularReveal.setDuration(1000);
55 | circularReveal.start();
56 | }
57 | });
58 | ivImageI.setOnClickListener(new View.OnClickListener() {
59 | @Override
60 | public void onClick(View v) {
61 | Animator circularReveal = ViewAnimationUtils.createCircularReveal(
62 | ivImageI,
63 | 0,
64 | 0,
65 | 0,
66 | ivImageI.getWidth() + 159);
67 | circularReveal.setInterpolator(new AccelerateDecelerateInterpolator());
68 | circularReveal.setDuration(1000);
69 | circularReveal.start();
70 | }
71 | });
72 | }
73 |
74 | /**
75 | * 设置动画过渡模式
76 | *
77 | * @param animType
78 | */
79 | private void setTransition(int animType) {
80 |
81 | switch (animType) {
82 | case 0:
83 | break;
84 | case 1:
85 | getWindow().setEnterTransition(new Explode());
86 | getWindow().setExitTransition(new Explode());
87 | getWindow().setReenterTransition(new Explode());
88 | getWindow().setReturnTransition(new Explode());
89 | break;
90 | case 2:
91 | getWindow().setEnterTransition(new Slide());
92 | getWindow().setExitTransition(new Slide());
93 | getWindow().setReenterTransition(new Slide());
94 | getWindow().setReturnTransition(new Slide());
95 | break;
96 | case 3:
97 | getWindow().setEnterTransition(new Fade());
98 | getWindow().setExitTransition(new Fade());
99 | getWindow().setReenterTransition(new Fade());
100 | getWindow().setReturnTransition(new Fade());
101 |
102 | break;
103 |
104 | case 4:
105 | getWindow().setEnterTransition(new Fade());
106 | getWindow().setExitTransition(new Fade());
107 | getWindow().setReenterTransition(new Fade());
108 | getWindow().setReturnTransition(new Fade());
109 |
110 | getWindow().setSharedElementExitTransition(new ChangeBounds());
111 | getWindow().setSharedElementEnterTransition(new ChangeBounds());
112 | getWindow().setSharedElementReenterTransition(new ChangeBounds());
113 | getWindow().setSharedElementReturnTransition(new ChangeBounds());
114 |
115 | break;
116 | case 5:
117 | getWindow().setEnterTransition(new Fade());
118 | getWindow().setExitTransition(new Fade());
119 | getWindow().setReenterTransition(new Fade());
120 | getWindow().setReturnTransition(new Fade());
121 |
122 | getWindow().setSharedElementExitTransition(new ChangeClipBounds());
123 | getWindow().setSharedElementEnterTransition(new ChangeClipBounds());
124 | getWindow().setSharedElementReenterTransition(new ChangeClipBounds());
125 | getWindow().setSharedElementReturnTransition(new ChangeClipBounds());
126 |
127 | break;
128 | case 6:
129 | getWindow().setEnterTransition(new Fade());
130 | getWindow().setExitTransition(new Fade());
131 | getWindow().setReenterTransition(new Fade());
132 | getWindow().setReturnTransition(new Fade());
133 |
134 | getWindow().setSharedElementExitTransition(new ChangeTransform());
135 | getWindow().setSharedElementEnterTransition(new ChangeTransform());
136 | getWindow().setSharedElementReenterTransition(new ChangeTransform());
137 | getWindow().setSharedElementReturnTransition(new ChangeTransform());
138 | break;
139 | case 7:
140 | getWindow().setEnterTransition(new Fade());
141 | getWindow().setExitTransition(new Fade());
142 | getWindow().setReenterTransition(new Fade());
143 | getWindow().setReturnTransition(new Fade());
144 |
145 | getWindow().setSharedElementExitTransition(new ChangeImageTransform());
146 | getWindow().setSharedElementEnterTransition(new ChangeImageTransform());
147 | getWindow().setSharedElementReenterTransition(new ChangeImageTransform());
148 | getWindow().setSharedElementReturnTransition(new ChangeImageTransform());
149 | break;
150 | }
151 | }
152 |
153 | private void initView() {
154 | ivImageI = (ImageView) findViewById(R.id.iv_image_i);
155 | ivImageIi = (ImageView) findViewById(R.id.iv_image_ii);
156 | llRoot = (LinearLayout) findViewById(R.id.ll_root);
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/bezier/BallRollView.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim.bezier;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.graphics.Path;
10 | import android.graphics.PathMeasure;
11 | import android.graphics.PointF;
12 | import android.support.annotation.Nullable;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 | import android.view.animation.AccelerateDecelerateInterpolator;
16 |
17 | /**
18 | * @author Rayhahah
19 | * @blog http://www.jianshu.com/u/ec42ce134e8d
20 | * @Github https://github.com/Rayhahah
21 | * @time 2017/4/5
22 | * @fuction 小球滚动Loading动画
23 | * @usage
24 | */
25 | public class BallRollView extends View {
26 |
27 | private int mViewWidth;
28 | private int mViewHeight;
29 | private int mCenterHeight;
30 | private int mBallCount = 7;
31 | private int mBallSize;
32 | private int mBallRadius;
33 | private int mBallOffset = 10;
34 | private ValueAnimator mValueAnimator;
35 | private int mDuration = 500;
36 | private float mAnimatedValue;
37 | private Path mBezierPathI;
38 | private Path mBezierPathII;
39 | private Paint mBallPaint;
40 | private int mOffSet = 150;
41 | private PathMeasure mPathMeasureI;
42 | private PathMeasure mPathMeasureII;
43 | private boolean mIsBezier = true;
44 | private float mBezierILength;
45 | private float mBezierIILength;
46 | private float[] mPos = new float[2];
47 | private float[] mTan = new float[2];
48 | private int mBezierHeight = 300;
49 | private ValueAnimator mValueAnimatorBezier;
50 | private PointF mBezierPoint;
51 | private Paint mBezierPaint;
52 | private int mTarRed = 255;
53 | private int mTarGreen = 0;
54 | private int mTarBlue = 0;
55 | private int[] mNRgb = new int[]{0, 0, 0};
56 | private int[] mARgb = new int[]{255, 0, 0};
57 |
58 | public BallRollView(Context context) {
59 | super(context);
60 | }
61 |
62 | public BallRollView(Context context, @Nullable AttributeSet attrs) {
63 | super(context, attrs);
64 | }
65 |
66 | public BallRollView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
67 | super(context, attrs, defStyleAttr);
68 | }
69 |
70 | @Override
71 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
72 | super.onSizeChanged(w, h, oldw, oldh);
73 |
74 | mViewWidth = w;
75 | mViewHeight = h;
76 | mCenterHeight = mViewHeight / 2;
77 |
78 | mBallSize = (mViewWidth - mOffSet) / mBallCount;
79 | mBallRadius = mBallSize / 2 - mBallOffset;
80 |
81 | initPaint();
82 |
83 | initBezierPath();
84 |
85 | initTarColor();
86 |
87 | initValueAnimator();
88 |
89 | }
90 |
91 | @Override
92 | protected void onDraw(Canvas canvas) {
93 | super.onDraw(canvas);
94 |
95 | if (mIsBezier) {
96 | mPathMeasureI.getPosTan(mAnimatedValue * mBezierILength, mPos, mTan);
97 | } else {
98 | mPathMeasureII.getPosTan(mAnimatedValue * mBezierIILength, mPos, mTan);
99 | }
100 | mBezierPaint.setColor(Color.rgb((int) (mARgb[0] - mTarRed * mAnimatedValue),
101 | (int) (mARgb[1] - mTarGreen * mAnimatedValue),
102 | (int) (mARgb[2] - mTarBlue * mAnimatedValue)));
103 | // mBezierPaint.setColor(Color.rgb(255, 0, 0));
104 | canvas.drawCircle(mPos[0], mPos[1], mBallRadius, mBezierPaint);
105 |
106 | canvas.save();
107 | canvas.translate(0 - mAnimatedValue * mBallSize, mCenterHeight);
108 | for (int i = 1; i < mBallCount; i++) {
109 | if (i == 1) {
110 | mBallPaint.setColor(Color.rgb((int) (mNRgb[0] + mTarRed * mAnimatedValue),
111 | (int) (mNRgb[1] + mTarGreen * mAnimatedValue),
112 | (int) (mNRgb[2] + mTarBlue * mAnimatedValue)));
113 | } else {
114 | mBallPaint.setColor(Color.rgb(mNRgb[0], mNRgb[1], mNRgb[2]));
115 | }
116 | canvas.drawCircle(mBallRadius + mBallOffset + i * mBallSize + mOffSet / 2, 0, mBallRadius, mBallPaint);
117 | }
118 | canvas.restore();
119 |
120 | }
121 |
122 | /**
123 | * 初始化画笔
124 | */
125 | private void initPaint() {
126 | mBallPaint = new Paint();
127 | mBallPaint.setStyle(Paint.Style.FILL);
128 | mBallPaint.setColor(Color.rgb(mNRgb[0], mNRgb[1], mNRgb[2]));
129 | mBallPaint.setAntiAlias(true);
130 |
131 | mBezierPaint = new Paint();
132 | mBezierPaint.setStyle(Paint.Style.FILL);
133 | mBezierPaint.setColor(Color.rgb(mNRgb[0] + mTarRed,
134 | mNRgb[1] + mTarGreen,
135 | mNRgb[2] + mTarBlue));
136 | mBezierPaint.setAntiAlias(true);
137 | }
138 |
139 | /**
140 | * 初始化渐变颜色
141 | */
142 | private void initTarColor() {
143 | mTarRed = mARgb[0] - mNRgb[0];
144 | mTarGreen = mARgb[1] - mNRgb[1];
145 | mTarBlue = mARgb[2] - mNRgb[2];
146 | }
147 |
148 |
149 | /**
150 | * 初始化动画生成器
151 | */
152 | private void initValueAnimator() {
153 | if (mValueAnimator == null) {
154 | mValueAnimator = ValueAnimator.ofFloat(0, 1);
155 | mValueAnimator.setDuration(mDuration);
156 | mValueAnimator.setRepeatCount(ValueAnimator.INFINITE);
157 | mValueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
158 | mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
159 | @Override
160 | public void onAnimationUpdate(ValueAnimator animation) {
161 | mAnimatedValue = (float) animation.getAnimatedValue();
162 | postInvalidate();
163 | }
164 | });
165 | mValueAnimator.addListener(new Animator.AnimatorListener() {
166 | @Override
167 | public void onAnimationStart(Animator animation) {
168 |
169 | }
170 |
171 | @Override
172 | public void onAnimationEnd(Animator animation) {
173 |
174 | }
175 |
176 | @Override
177 | public void onAnimationCancel(Animator animation) {
178 |
179 | }
180 |
181 | @Override
182 | public void onAnimationRepeat(Animator animation) {
183 | mIsBezier = !mIsBezier;
184 | setColor(Color.parseColor("#aabbcc"), Color.parseColor("#ff5831"));
185 | }
186 | });
187 | mValueAnimator.start();
188 |
189 | }
190 | }
191 |
192 | /**
193 | * 初始化贝塞尔曲线路径
194 | */
195 | private void initBezierPath() {
196 | mBezierPathI = new Path();
197 | mBezierPathI.moveTo((mBallSize + mOffSet) / 2, mCenterHeight);
198 | mBezierPathI.quadTo(mViewWidth / 2, mCenterHeight - mBezierHeight,
199 | (mBallCount - 1) * mBallSize + (mBallSize + mOffSet) / 2, mCenterHeight);
200 |
201 | mPathMeasureI = new PathMeasure();
202 | mPathMeasureI.setPath(mBezierPathI, false);
203 | mBezierILength = mPathMeasureI.getLength();
204 |
205 |
206 | mBezierPathII = new Path();
207 | mBezierPathII.moveTo((mBallSize + mOffSet) / 2, mCenterHeight);
208 | mBezierPathII.quadTo(mViewWidth / 2, mCenterHeight + mBezierHeight,
209 | (mBallCount - 1) * mBallSize + (mBallSize + mOffSet) / 2, mCenterHeight);
210 |
211 | mPathMeasureII = new PathMeasure();
212 | mPathMeasureII.setPath(mBezierPathII, false);
213 | mBezierIILength = mPathMeasureII.getLength();
214 | }
215 |
216 | /**
217 | * 设置小球渐变颜色
218 | * 只支持rgb通道,不支持argb
219 | *
220 | * @param normalColor 普通小球颜色
221 | * @param activeColor 移动小球颜色
222 | */
223 | public BallRollView setColor(int normalColor, int activeColor) {
224 | mNRgb = int2RGB(normalColor);
225 | mARgb = int2RGB(activeColor);
226 |
227 | initTarColor();
228 | return this;
229 | }
230 |
231 | /**
232 | * 设置小球个数
233 | *
234 | * @param ballCount
235 | */
236 | public BallRollView setBallCount(int ballCount) {
237 | mBallCount = ballCount;
238 | return this;
239 | }
240 |
241 | /**
242 | * 设置一轮动画的时长
243 | *
244 | * @param duration
245 | */
246 | public BallRollView setDuration(int duration) {
247 | mDuration = duration;
248 | return this;
249 | }
250 |
251 |
252 | /**
253 | * 提取出颜色的rgb三色通道的值
254 | * 范围是0-255
255 | *
256 | * @param color
257 | * @return
258 | */
259 | private int[] int2RGB(int color) {
260 | int[] rgb = new int[3];
261 | rgb[0] = (color & 0xff0000) >> 16;
262 | rgb[1] = (color & 0x00ff00) >> 8;
263 | rgb[2] = (color & 0x0000ff);
264 | return rgb;
265 | }
266 | }
267 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rayhahah/advancedanim/bezier/WaveView.java:
--------------------------------------------------------------------------------
1 | package com.rayhahah.advancedanim.bezier;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Paint;
10 | import android.graphics.Path;
11 | import android.graphics.PorterDuff;
12 | import android.graphics.PorterDuffXfermode;
13 | import android.support.annotation.Nullable;
14 | import android.util.AttributeSet;
15 | import android.view.MotionEvent;
16 | import android.view.View;
17 | import android.view.animation.LinearInterpolator;
18 |
19 |
20 | /**
21 | * @author Rayhahah
22 | * @blog http://www.jianshu.com/u/ec42ce134e8d
23 | * @Github https://github.com/Rayhahah
24 | * @time 2017/4/2
25 | * @fuction 波浪动画
26 | * @use
27 | */
28 | public class WaveView extends View implements View.OnClickListener {
29 | private int mViewWidth;
30 | private int mViewHeight;
31 | private int mCenterHeight;
32 | private int mWaveLength;
33 | private int mWaveCount;
34 | //第一层波浪
35 | private Path mPathOne;
36 | private Path mPathTwo;
37 | private Paint mPaintOne;
38 | private Paint mPaintTwo;
39 | private Path mPathThree;
40 | private Paint mPaintThree;
41 | private int mColorOne = Color.parseColor("#72c8ff");
42 | private int mColorTwo = Color.parseColor("#b9e8ff");
43 | private int mColorThree = Color.parseColor("#997ce8ef");
44 | private int mGradient;
45 | private ValueAnimator mValueAnimator;
46 | private boolean mIsPlaying;
47 | private float mOffset;
48 | private boolean mIsTouchable = true;
49 | private boolean mIsCircle = true;
50 | private Path mPathCircle;
51 | private int mRadius;
52 | private Paint mShapePaint;
53 | private Bitmap mBackGround;
54 | private Canvas mC;
55 |
56 |
57 | public WaveView(Context context) {
58 | super(context);
59 | }
60 |
61 | public WaveView(Context context, @Nullable AttributeSet attrs) {
62 | super(context, attrs);
63 | }
64 |
65 | public WaveView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
66 | super(context, attrs, defStyleAttr);
67 | }
68 |
69 | @Override
70 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
71 | super.onSizeChanged(w, h, oldw, oldh);
72 |
73 | mGradient = 60;
74 |
75 | mWaveLength = 700;
76 |
77 | mViewWidth = w;
78 | mViewHeight = h;
79 |
80 | mCenterHeight = h / 2;
81 |
82 | mRadius = mWaveLength / 2;
83 |
84 |
85 | initPathAndPaint();
86 |
87 | setOnClickListener(this);
88 | mBackGround = Bitmap.createBitmap(mViewWidth, mViewHeight,
89 | Bitmap.Config.ARGB_8888);
90 |
91 | mC = new Canvas();
92 | mC.setBitmap(mBackGround);
93 |
94 | }
95 |
96 |
97 | @Override
98 | protected void onDraw(Canvas canvas) {
99 | // super.onDraw(canvas);
100 |
101 | drawWave(canvas, mPathTwo, mPaintTwo, (int) (mOffset + 120), -20,
102 | mWaveLength, mCenterHeight, mIsCircle);
103 | drawWave(canvas, mPathOne, mPaintOne, (int) (mOffset + 0), 0,
104 | mWaveLength, mCenterHeight, mIsCircle);
105 | drawWave(canvas, mPathThree, mPaintThree, (int) (mOffset - 80), -10,
106 | mWaveLength, mCenterHeight + 30, mIsCircle);
107 |
108 | // mPathCircle.reset();
109 | // mPathCircle.addCircle(mViewWidth / 2, mViewHeight / 2, mRadius, Path.Direction.CCW);
110 | // canvas.drawCircle(mBackGround, 0, 0, null);
111 |
112 | }
113 |
114 | /**
115 | * 绘制波浪
116 | *
117 | * @param canvas
118 | * @param path
119 | * @param paint
120 | * @param offsetX
121 | */
122 | private void drawWave(Canvas canvas, Path path, Paint paint,
123 | int offsetX, int offsetY,
124 | int waveLength, int centerHeight,
125 | boolean isCircle) {
126 | path.reset();
127 | mWaveCount = (int) Math.round(mViewWidth / waveLength + 1.5);
128 | path.moveTo(-waveLength + offsetX, centerHeight);
129 |
130 | int i = 0;
131 |
132 | for (i = 0; i < mWaveCount; i++) {
133 | //绘制全部n型的贝塞尔曲线
134 | path.quadTo(-waveLength * 3 / 4 + i * waveLength + offsetX,
135 | centerHeight - mGradient - offsetY,
136 | -waveLength / 2 + i * waveLength + offsetX,
137 | centerHeight);
138 | //绘制全部U型的贝塞尔曲线
139 | path.quadTo(-waveLength * 1 / 4 + i * waveLength + offsetX,
140 | centerHeight + mGradient + offsetY,
141 | i * waveLength + offsetX,
142 | centerHeight);
143 | }
144 |
145 | /**
146 | * 将绘制的路径闭合
147 | */
148 |
149 | path.lineTo(mViewWidth, mViewHeight);
150 | path.lineTo(0, mViewHeight);
151 | path.lineTo(-mWaveLength, centerHeight);
152 |
153 | path.close();
154 |
155 | if (isCircle) {
156 | Bitmap circleBitmap = getCircleBitmap();
157 | paint.setXfermode(null);
158 | canvas.drawPath(path, paint);
159 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
160 | canvas.drawBitmap(circleBitmap, 0, 0, paint);
161 | // mPathCircle.op(path, Path.Op.INTERSECT);
162 | // canvas.drawPath(mPathCircle, paint);
163 | } else {
164 | canvas.drawPath(path, paint);
165 | }
166 | }
167 |
168 | /**
169 | * 点击播放波浪动画
170 | *
171 | * @param v
172 | */
173 | @Override
174 | public void onClick(View v) {
175 |
176 | }
177 |
178 | public void playAnim() {
179 | if (!mIsPlaying) {
180 | mValueAnimator.start();
181 | mIsPlaying = true;
182 | }
183 | }
184 |
185 | public void pauseAnim() {
186 | if (mIsPlaying) {
187 | if (mValueAnimator.isRunning()) {
188 | mValueAnimator.pause();
189 | mIsPlaying = false;
190 | }
191 | }
192 | }
193 |
194 | private void initValueAnimator() {
195 | if (mValueAnimator == null) {
196 | mValueAnimator = ValueAnimator.ofFloat(0, mWaveLength);
197 | mValueAnimator.setDuration(750);
198 | mValueAnimator.setInterpolator(new LinearInterpolator());
199 | mValueAnimator.setRepeatCount(ValueAnimator.INFINITE);
200 | mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
201 | @Override
202 | public void onAnimationUpdate(ValueAnimator animation) {
203 | mOffset = ((float) animation.getAnimatedValue());
204 | postInvalidate();
205 | }
206 | });
207 | mValueAnimator.addListener(new Animator.AnimatorListener() {
208 | @Override
209 | public void onAnimationStart(Animator animation) {
210 | mOffset = 0;
211 | }
212 |
213 | @Override
214 | public void onAnimationEnd(Animator animation) {
215 |
216 | }
217 |
218 | @Override
219 | public void onAnimationCancel(Animator animation) {
220 |
221 | }
222 |
223 | @Override
224 | public void onAnimationRepeat(Animator animation) {
225 |
226 | }
227 | });
228 |
229 | }
230 | }
231 |
232 | @Override
233 | public boolean onTouchEvent(MotionEvent event) {
234 | if (mIsTouchable) {
235 | switch (event.getAction()) {
236 | case MotionEvent.ACTION_DOWN:
237 | initValueAnimator();
238 | if (mIsPlaying) {
239 | pauseAnim();
240 | } else {
241 | playAnim();
242 | }
243 | break;
244 | case MotionEvent.ACTION_MOVE:
245 | mCenterHeight = (int) event.getY();
246 | invalidate();
247 | break;
248 | }
249 | }
250 | return true;
251 | }
252 |
253 | private void initPathAndPaint() {
254 |
255 | mPathOne = new Path();
256 | mPathCircle = new Path();
257 | mPaintOne = new Paint();
258 | mPaintOne.setColor(mColorOne);
259 | mPaintOne.setAntiAlias(true);
260 | mPaintOne.setStrokeWidth(2);
261 | mPaintOne.setStyle(Paint.Style.FILL);
262 |
263 | mPathTwo = new Path();
264 | mPaintTwo = new Paint();
265 | mPaintTwo.setColor(mColorTwo);
266 | mPaintTwo.setAntiAlias(true);
267 | mPaintTwo.setStrokeWidth(2);
268 | mPaintTwo.setStyle(Paint.Style.FILL);
269 |
270 |
271 | mPathThree = new Path();
272 | mPaintThree = new Paint();
273 | mPaintThree.setColor(mColorThree);
274 | mPaintThree.setAntiAlias(true);
275 | mPaintThree.setStrokeWidth(2);
276 | mPaintThree.setStyle(Paint.Style.FILL);
277 |
278 | }
279 |
280 | /**
281 | * 绘制形状
282 | *
283 | * @return
284 | */
285 | public Bitmap getCircleBitmap() {
286 |
287 | Canvas canvas = new Canvas(mBackGround);
288 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
289 | paint.setColor(Color.argb(255, 255, 255, 255));
290 | canvas.drawCircle(mViewWidth / 2, mViewHeight / 2, mRadius,
291 | paint);
292 | return mBackGround;
293 | }
294 |
295 |
296 | }
297 |
--------------------------------------------------------------------------------