├── src
├── main
│ ├── res
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ ├── styles.xml
│ │ │ └── attrs.xml
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ └── layout
│ │ │ ├── activity_bezier_view.xml
│ │ │ ├── layout_pager.xml
│ │ │ ├── activity_pager.xml
│ │ │ ├── activity_bezier_evaluator.xml
│ │ │ └── activity_fullscreen.xml
│ ├── java
│ │ └── cn
│ │ │ └── gavinliu
│ │ │ └── beautifulofbezier
│ │ │ ├── BezierViewActivity.java
│ │ │ ├── FullscreenActivity.java
│ │ │ ├── BezierEvaluator.java
│ │ │ ├── BezierView.java
│ │ │ ├── BezierEvaluatorActivity.java
│ │ │ ├── DropPagerIndicatorActivity.java
│ │ │ └── DropPagerIndicator.java
│ └── AndroidManifest.xml
└── androidTest
│ └── java
│ └── cn
│ └── gavinliu
│ └── beautifulofbezier
│ └── ApplicationTest.java
├── Readme.md
├── .gitignore
└── proguard-rules.pro
/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #66000000
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gavinliu/BeautifulOfBezier/HEAD/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gavinliu/BeautifulOfBezier/HEAD/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gavinliu/BeautifulOfBezier/HEAD/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gavinliu/BeautifulOfBezier/HEAD/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | # BeautifulOfBezier
2 |
3 | [Android - Animation 贝塞尔曲线之美](http://gavinliu.cn/2015/03/30/Android-Animation-%E8%B4%9D%E5%A1%9E%E5%B0%94%E6%9B%B2%E7%BA%BF%E4%B9%8B%E7%BE%8E/) 博客Demo
4 |
--------------------------------------------------------------------------------
/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BeautifulOfBezier
3 |
4 | Dummy Button
5 | DUMMY\nCONTENT
6 |
7 |
--------------------------------------------------------------------------------
/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #Android generated
2 | bin
3 | gen
4 | gen*
5 |
6 | #Eclipse
7 | .project
8 | .classpath
9 | .settings
10 |
11 | #IntelliJ IDEA
12 | .idea
13 | *.iml
14 | *.ipr
15 | *.iws
16 | out
17 |
18 | #Maven
19 | target
20 | release.properties
21 | pom.xml.*
22 |
23 | #Ant
24 | build.xml
25 | local.properties
26 | proguard.cfg
27 |
28 | #Gradle
29 | .gradle
30 | build
31 |
32 | #OSX
33 | .DS_Store
34 |
35 | #Personal Files
36 | signing.
37 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_bezier_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/src/androidTest/java/cn/gavinliu/beautifulofbezier/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.beautifulofbezier;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/src/main/res/layout/layout_pager.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/src/main/java/cn/gavinliu/beautifulofbezier/BezierViewActivity.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.beautifulofbezier;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.ActionBarActivity;
5 |
6 | /**
7 | * Created by gavin on 15-4-2.
8 | */
9 | public class BezierViewActivity extends ActionBarActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_bezier_view);
15 |
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_pager.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/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 /home/gavin/Develop/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 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_bezier_evaluator.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
18 |
19 |
--------------------------------------------------------------------------------
/src/main/java/cn/gavinliu/beautifulofbezier/FullscreenActivity.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.beautifulofbezier;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.ActionBarActivity;
6 | import android.view.View;
7 |
8 | public class FullscreenActivity extends ActionBarActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_fullscreen);
14 |
15 | }
16 |
17 | public void onBezierView(View view) {
18 | Intent intent = new Intent(this, BezierViewActivity.class);
19 | startActivity(intent);
20 | }
21 |
22 | public void onDropPagerIndicator(View view) {
23 | Intent intent = new Intent(this, DropPagerIndicatorActivity.class);
24 | startActivity(intent);
25 | }
26 |
27 | public void onBezierEvaluator(View view) {
28 | Intent intent = new Intent(this, BezierEvaluatorActivity.class);
29 | startActivity(intent);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/res/layout/activity_fullscreen.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
14 |
15 |
21 |
22 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/main/java/cn/gavinliu/beautifulofbezier/BezierEvaluator.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.beautifulofbezier;
2 |
3 | import android.animation.TypeEvaluator;
4 | import android.graphics.PointF;
5 |
6 | /**
7 | * Created by gavin on 15-4-2.
8 | */
9 | public class BezierEvaluator implements TypeEvaluator {
10 |
11 | private PointF points[];
12 |
13 | public BezierEvaluator(PointF... points) {
14 | if (points.length != 4) {
15 | throw new IllegalArgumentException("只演示三次方贝赛尔曲线");
16 | }
17 | this.points = points;
18 | }
19 |
20 | @Override
21 | public PointF evaluate(float fraction, PointF startValue, PointF endValue) {
22 | // B(t) = P0 * (1-t)^3 + 3 * P1 * t * (1-t)^2 + 3 * P2 * t^2 * (1-t) + P3 * t^3
23 |
24 | float t = fraction;
25 | float one_t = 1.0f - t;
26 |
27 | PointF P0 = points[0];
28 | PointF P1 = points[1];
29 | PointF P2 = points[2];
30 | PointF P3 = points[3];
31 |
32 | float x = (float) (P0.x * Math.pow(one_t, 3) + 3 * P1.x * t * Math.pow(one_t, 2) + 3 * P2.x * Math.pow(t, 2) * one_t + P3.x * Math.pow(t, 3));
33 | float y = (float) (P0.y * Math.pow(one_t, 3) + 3 * P1.y * t * Math.pow(one_t, 2) + 3 * P2.y * Math.pow(t, 2) * one_t + P3.y * Math.pow(t, 3));
34 |
35 | PointF pointF = new PointF(x, y);
36 |
37 | return pointF;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
25 |
26 |
30 |
31 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/main/java/cn/gavinliu/beautifulofbezier/BezierView.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.beautifulofbezier;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.DrawFilter;
6 | import android.graphics.Paint;
7 | import android.graphics.PaintFlagsDrawFilter;
8 | import android.graphics.Path;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 |
12 | /**
13 | * Created by gavin on 15-4-1.
14 | */
15 | public class BezierView extends View {
16 |
17 | private final Path mPath = new Path();
18 | private Paint mPaint;
19 |
20 | public BezierView(Context context) {
21 | this(context, null);
22 | }
23 |
24 | public BezierView(Context context, AttributeSet attrs) {
25 | this(context, attrs, 0);
26 | }
27 |
28 | public BezierView(Context context, AttributeSet attrs, int defStyleAttr) {
29 | super(context, attrs, defStyleAttr);
30 | mPaint = new Paint();
31 | mPaint.setAntiAlias(true);
32 | mPaint.setStyle(Paint.Style.STROKE);
33 | mPaint.setStrokeWidth(5);
34 | mPaint.setColor(0xFF009688);
35 | }
36 |
37 | @Override
38 | protected void onDraw(Canvas canvas) {
39 | super.onDraw(canvas);
40 |
41 | mPath.moveTo(100, 100);
42 | mPath.cubicTo(800, 100, 100, 800, 800, 800);
43 |
44 | canvas.drawPath(mPath, mPaint);
45 | }
46 |
47 | @Override
48 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
49 | super.onSizeChanged(w, h, oldw, oldh);
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/cn/gavinliu/beautifulofbezier/BezierEvaluatorActivity.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.beautifulofbezier;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.PointF;
5 | import android.os.Bundle;
6 | import android.support.v7.app.ActionBarActivity;
7 | import android.view.animation.AccelerateInterpolator;
8 | import android.widget.TextView;
9 |
10 | /**
11 | * Created by gavin on 15-4-2.
12 | */
13 | public class BezierEvaluatorActivity extends ActionBarActivity {
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_bezier_evaluator);
19 |
20 | final TextView textView = (TextView) findViewById(R.id.textView);
21 |
22 | PointF p0 = new PointF(100, 100);
23 | PointF p1 = new PointF(800, 100);
24 | PointF p2 = new PointF(100, 800);
25 | PointF p3 = new PointF(800, 800);
26 |
27 | BezierEvaluator evaluator = new BezierEvaluator(p0, p1, p2, p3);
28 |
29 | ValueAnimator animator = ValueAnimator.ofObject(evaluator, p0, p3)
30 | .setDuration(4500);
31 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
32 |
33 | @Override
34 | public void onAnimationUpdate(ValueAnimator animation) {
35 | PointF pointF = (PointF) animation.getAnimatedValue();
36 | textView.setX(pointF.x);
37 | textView.setY(pointF.y);
38 | }
39 |
40 | });
41 |
42 | animator.start();
43 |
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/cn/gavinliu/beautifulofbezier/DropPagerIndicatorActivity.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.beautifulofbezier;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.view.PagerAdapter;
5 | import android.support.v4.view.ViewPager;
6 | import android.support.v7.app.ActionBarActivity;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | /**
14 | * Created by gavin on 15-4-2.
15 | */
16 | public class DropPagerIndicatorActivity extends ActionBarActivity {
17 |
18 | private DropPagerIndicator indicator;
19 | private ViewPager viewPager;
20 |
21 | private List views;
22 |
23 | @Override
24 | public void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_pager);
27 |
28 | viewPager = (ViewPager) findViewById(R.id.pager);
29 | indicator = (DropPagerIndicator) findViewById(R.id.indicator);
30 |
31 |
32 | views = new ArrayList<>();
33 | views.add(getLayoutInflater().inflate(R.layout.layout_pager, null));
34 | views.add(getLayoutInflater().inflate(R.layout.layout_pager, null));
35 | views.add(getLayoutInflater().inflate(R.layout.layout_pager, null));
36 | views.add(getLayoutInflater().inflate(R.layout.layout_pager, null));
37 |
38 | ArrayList colors = new ArrayList<>();
39 | colors.add(0xFFFF0000);
40 | colors.add(0xFF00FF00);
41 | colors.add(0xFF0000FF);
42 | colors.add(0xFFFF00FF);
43 | indicator.setColors(colors);
44 | indicator.setPagerCount(views.size());
45 | indicator.setMode(DropPagerIndicator.MODE_BEND);
46 |
47 |
48 |
49 | viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
50 |
51 | @Override
52 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
53 | indicator.setPositionAndOffset(position, positionOffset);
54 | }
55 |
56 | @Override
57 | public void onPageSelected(int position) {
58 |
59 | }
60 |
61 | @Override
62 | public void onPageScrollStateChanged(int state) {
63 |
64 | }
65 | });
66 |
67 | viewPager.setAdapter(new PagerAdapter() {
68 |
69 | @Override
70 | public int getCount() {
71 | return views.size();
72 | }
73 |
74 | @Override
75 | public boolean isViewFromObject(View view, Object object) {
76 | return view == object;
77 | }
78 |
79 | @Override
80 | public void destroyItem(ViewGroup container, int position, Object object) {
81 | container.removeView(views.get(position));
82 | }
83 |
84 |
85 | @Override
86 | public Object instantiateItem(ViewGroup container, int position) {
87 | container.addView(views.get(position), 0);
88 | return views.get(position);
89 | }
90 | });
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/cn/gavinliu/beautifulofbezier/DropPagerIndicator.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.beautifulofbezier;
2 |
3 | import android.animation.ArgbEvaluator;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.graphics.Canvas;
8 | import android.graphics.Paint;
9 | import android.graphics.Path;
10 | import android.graphics.PointF;
11 | import android.util.AttributeSet;
12 | import android.view.View;
13 | import android.view.animation.AccelerateDecelerateInterpolator;
14 | import android.view.animation.AccelerateInterpolator;
15 | import android.view.animation.DecelerateInterpolator;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | public class DropPagerIndicator extends View {
21 |
22 | private List mColors;
23 |
24 | private ArrayList mAnimators;
25 |
26 | private int mWidth;
27 | private int mHeight;
28 |
29 | private float leftCircleRadius;
30 | private float leftCircleX;
31 |
32 | private float rightCircleRadius;
33 | private float rightCircleX;
34 |
35 | private List mPoints;
36 |
37 | private int mPagerCount;
38 |
39 | private float mMaxCircleRadius;
40 | private float mMinCircleRadius;
41 |
42 | private Paint mPaint;
43 | private Path mPath = new Path();
44 |
45 | private int mMode = MODE_NORMAL;
46 |
47 | public static final int MODE_NORMAL = 1;
48 | public static final int MODE_BEND = 2;
49 |
50 | public DropPagerIndicator(Context context) {
51 | this(context, null);
52 | }
53 |
54 | public DropPagerIndicator(Context context, AttributeSet attrs) {
55 | this(context, attrs, 0);
56 | }
57 |
58 | public DropPagerIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
59 | super(context, attrs, defStyleAttr);
60 | init();
61 | }
62 |
63 | private void init() {
64 | mAnimators = new ArrayList<>();
65 | mPoints = new ArrayList<>();
66 |
67 | mPaint = new Paint();
68 | mPaint.setAntiAlias(true);
69 | mPaint.setStyle(Paint.Style.FILL);
70 | }
71 |
72 | @Override
73 | protected void onDraw(Canvas canvas) {
74 | super.onDraw(canvas);
75 |
76 | canvas.drawCircle(leftCircleX, mHeight / 2, leftCircleRadius, mPaint);
77 | canvas.drawCircle(rightCircleX, mHeight / 2, rightCircleRadius, mPaint);
78 |
79 | switch (mMode) {
80 | case MODE_NORMAL:
81 | drawModeNormal(canvas);
82 | break;
83 |
84 | case MODE_BEND:
85 | drawModeBend(canvas);
86 | break;
87 | }
88 |
89 | }
90 |
91 | private void drawModeNormal(Canvas canvas) {
92 | mPath.reset();
93 |
94 | mPath.moveTo(rightCircleX, mHeight / 2);
95 |
96 | mPath.lineTo(rightCircleX, mHeight / 2 - rightCircleRadius);
97 |
98 | mPath.quadTo(rightCircleX,
99 | mHeight / 2 - rightCircleRadius,
100 |
101 | leftCircleX,
102 | mHeight / 2 - leftCircleRadius);
103 |
104 | mPath.lineTo(leftCircleX, mHeight / 2 + leftCircleRadius);
105 |
106 | mPath.quadTo(leftCircleX,
107 | mHeight / 2 + leftCircleRadius,
108 |
109 | rightCircleX,
110 | mHeight / 2 + rightCircleRadius);
111 |
112 | mPath.close();
113 |
114 | canvas.drawPath(mPath, mPaint);
115 | }
116 |
117 | private void drawModeBend(Canvas canvas) {
118 | float middleOffset = (leftCircleX - rightCircleX) / (mPoints.get(1).x - mPoints.get(0).x) * (mHeight / 10);
119 |
120 | mPath.reset();
121 |
122 | mPath.moveTo(rightCircleX, mHeight / 2);
123 |
124 | mPath.lineTo(rightCircleX, mHeight / 2 - rightCircleRadius);
125 |
126 | mPath.cubicTo(rightCircleX,
127 | mHeight / 2 - rightCircleRadius,
128 |
129 | rightCircleX + (leftCircleX - rightCircleX) / 2.0F,
130 | mHeight / 2 + middleOffset,
131 |
132 | leftCircleX,
133 | mHeight / 2 - leftCircleRadius);
134 |
135 | mPath.lineTo(leftCircleX, mHeight / 2 + leftCircleRadius);
136 |
137 | mPath.cubicTo(leftCircleX,
138 | mHeight / 2 + leftCircleRadius,
139 |
140 | rightCircleX + (leftCircleX - rightCircleX) / 2.0F,
141 | mHeight / 2 - middleOffset,
142 |
143 | rightCircleX,
144 | mHeight / 2 + rightCircleRadius);
145 |
146 | mPath.close();
147 | canvas.drawPath(mPath, mPaint);
148 | }
149 |
150 | @Override
151 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
152 | super.onSizeChanged(w, h, oldw, oldh);
153 | mWidth = w;
154 | mHeight = h;
155 |
156 | mMaxCircleRadius = 0.45f * mHeight;
157 | mMinCircleRadius = 0.15f * mHeight;
158 |
159 | resetPoint();
160 | }
161 |
162 | private void createAnimator(int paramInt) {
163 | if (mPoints.isEmpty()) {
164 | return;
165 | }
166 | mAnimators.clear();
167 |
168 | int i = Math.min(mPagerCount - 1, paramInt + 1);
169 |
170 | float leftX = mPoints.get(paramInt).x;
171 | float rightX = mPoints.get(i).x;
172 |
173 | ObjectAnimator leftPointAnimator = ObjectAnimator.ofFloat(this, "rightCircleX", leftX, rightX);
174 | leftPointAnimator.setDuration(5000L);
175 | leftPointAnimator.setInterpolator(new DecelerateInterpolator());
176 | mAnimators.add(leftPointAnimator);
177 |
178 | ObjectAnimator rightPointAnimator = ObjectAnimator.ofFloat(this, "leftCircleX", leftX, rightX);
179 | rightPointAnimator.setDuration(5000L);
180 | rightPointAnimator.setInterpolator(new AccelerateInterpolator(1.5F));
181 | mAnimators.add(rightPointAnimator);
182 |
183 | ObjectAnimator leftCircleRadiusAnimator = ObjectAnimator.ofFloat(this, "rightCircleRadius", mMinCircleRadius, mMaxCircleRadius);
184 | leftCircleRadiusAnimator.setDuration(5000L);
185 | leftCircleRadiusAnimator.setInterpolator(new AccelerateInterpolator(1.5F));
186 | mAnimators.add(leftCircleRadiusAnimator);
187 |
188 | ObjectAnimator rightCircleRadiusAnimator = ObjectAnimator.ofFloat(this, "leftCircleRadius", mMaxCircleRadius, mMinCircleRadius);
189 | rightCircleRadiusAnimator.setDuration(5000L);
190 | rightCircleRadiusAnimator.setInterpolator(new DecelerateInterpolator(0.8F));
191 | mAnimators.add(rightCircleRadiusAnimator);
192 |
193 | int color1 = mColors.get(paramInt);
194 | int color2 = mColors.get(i);
195 | ValueAnimator paintColorAnimator = ObjectAnimator.ofInt(color1, color2);
196 | paintColorAnimator.setDuration(5000L);
197 | paintColorAnimator.setEvaluator(new ArgbEvaluator());
198 | paintColorAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
199 | paintColorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
200 |
201 | public void onAnimationUpdate(ValueAnimator animator) {
202 | mPaint.setColor((Integer) animator.getAnimatedValue());
203 | }
204 | });
205 |
206 | mAnimators.add(paintColorAnimator);
207 | }
208 |
209 | private void seekAnimator(float offset) {
210 | for (ValueAnimator animator : mAnimators) {
211 | animator.setCurrentPlayTime((long) (5000.0F * offset));
212 | }
213 |
214 | postInvalidate();
215 | }
216 |
217 | public void setPositionAndOffset(int position, float offSet) {
218 | createAnimator(position);
219 | seekAnimator(offSet);
220 | }
221 |
222 | private void resetPoint() {
223 | mPoints.clear();
224 | for (int i = 0; i < mPagerCount; i++) {
225 | int x = mWidth / (mPagerCount + 1) * (i + 1);
226 | mPoints.add(new PointF(x, 0));
227 | }
228 |
229 | if (!mPoints.isEmpty()) {
230 | leftCircleX = mPoints.get(0).x;
231 | leftCircleRadius = mMaxCircleRadius;
232 |
233 | rightCircleX = mPoints.get(0).x;
234 | rightCircleRadius = mMinCircleRadius;
235 | postInvalidate();
236 | }
237 | }
238 |
239 | public void setPagerCount(int pagerCount) {
240 | mPagerCount = pagerCount;
241 | }
242 |
243 | public void setColors(List colors) {
244 | mColors = colors;
245 |
246 | if (!colors.isEmpty()) {
247 | mPaint.setColor(colors.get(0));
248 | }
249 | }
250 |
251 | public void setMode(int mode) {
252 | this.mMode = mode;
253 | }
254 |
255 |
256 | public float getLeftCircleX() {
257 | return leftCircleX;
258 | }
259 |
260 | public void setLeftCircleX(float leftCircleX) {
261 | this.leftCircleX = leftCircleX;
262 | }
263 |
264 | public float getLeftCircleRadius() {
265 | return leftCircleRadius;
266 | }
267 |
268 | public void setLeftCircleRadius(float leftCircleRadius) {
269 | this.leftCircleRadius = leftCircleRadius;
270 | }
271 |
272 | public float getRightCircleRadius() {
273 | return rightCircleRadius;
274 | }
275 |
276 | public void setRightCircleRadius(float rightCircleRadius) {
277 | this.rightCircleRadius = rightCircleRadius;
278 | }
279 |
280 | public float getRightCircleX() {
281 | return rightCircleX;
282 | }
283 |
284 | public void setRightCircleX(float rightCircleX) {
285 | this.rightCircleX = rightCircleX;
286 | }
287 | }
288 |
--------------------------------------------------------------------------------