├── .gitignore
├── README.md
├── build.gradle
├── demo.gif
├── proguard-rules.txt
├── src
└── main
│ ├── AndroidManifest.xml
│ ├── java
│ ├── com
│ │ └── dpt
│ │ │ └── widget
│ │ │ ├── AnimPoint.java
│ │ │ ├── CurvedLineAnimDrawable2.java
│ │ │ ├── LineAnimHelper.java
│ │ │ └── NormalLineAnimDrawable.java
│ └── test
│ │ └── DemoActivity.java
│ └── res
│ ├── drawable-hdpi
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ └── ic_launcher.png
│ ├── layout
│ └── activity_main.xml
│ ├── menu
│ └── main.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── widget.iml
/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | LineAnimation
2 | -----
3 |
4 | use of point and line draw animation
5 |
6 | support for Android sdk 3.0+
7 |
8 |
9 | ###demo
10 | 
11 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:0.9.+'
7 | }
8 | }
9 | apply plugin: 'android'
10 |
11 | repositories {
12 | mavenCentral()
13 | }
14 |
15 | android {
16 | compileSdkVersion 19
17 | buildToolsVersion "20.0.0"
18 |
19 | defaultConfig {
20 | minSdkVersion 19
21 | targetSdkVersion 19
22 | versionCode 1
23 | versionName "1.0"
24 | }
25 | buildTypes {
26 | release {
27 | runProguard false
28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
29 | }
30 | }
31 | }
32 |
33 | dependencies {
34 | compile fileTree(dir: 'libs', include: ['*.jar'])
35 | compile 'com.android.support:appcompat-v7:19.+'
36 | }
37 |
--------------------------------------------------------------------------------
/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/LineAnimation/21c78bb7ded993973687e5b17f39b0aa7c9a3c90/demo.gif
--------------------------------------------------------------------------------
/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/dupengtao/letv/tools/adt-bundle-linux-x86_64-20140702/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
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 | #}
--------------------------------------------------------------------------------
/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/main/java/com/dpt/widget/AnimPoint.java:
--------------------------------------------------------------------------------
1 | package com.dpt.widget;
2 |
3 | /**
4 | * Created by dupengtao on 14-9-11.
5 | */
6 | public class AnimPoint {
7 | private float curX;
8 | private float curY;
9 | private float moveX;
10 | private float moveY;
11 |
12 | public AnimPoint(float curX, float curY, float moveX, float moveY) {
13 | this.curX = curX;
14 | this.curY = curY;
15 | this.moveX = moveX;
16 | this.moveY = moveY;
17 | }
18 |
19 | public AnimPoint() {
20 | }
21 |
22 | public float getCurX() {
23 | return curX;
24 | }
25 |
26 | public void setCurX(float curX) {
27 | this.curX = curX;
28 | }
29 |
30 | public float getCurY() {
31 | return curY;
32 | }
33 |
34 | public void setCurY(float curY) {
35 | this.curY = curY;
36 | }
37 |
38 | public float getMoveX() {
39 | return moveX;
40 | }
41 |
42 | public void setMoveX(float moveX) {
43 | this.moveX = moveX;
44 | }
45 |
46 | public float getMoveY() {
47 | return moveY;
48 | }
49 |
50 | public void setMoveY(float moveY) {
51 | this.moveY = moveY;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/dpt/widget/CurvedLineAnimDrawable2.java:
--------------------------------------------------------------------------------
1 | package com.dpt.widget;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.animation.PropertyValuesHolder;
5 | import android.animation.ValueAnimator;
6 | import android.graphics.*;
7 | import android.graphics.drawable.Drawable;
8 |
9 | /**
10 | * Created by dupengtao on 14-9-11.
11 | */
12 | public class CurvedLineAnimDrawable2 extends Drawable implements ValueAnimator.AnimatorUpdateListener {
13 |
14 | private static final String DEGREE_FACTOR="degreeFactor";
15 | private int durationMS=500;
16 | private final Paint mPaint2;
17 | private final RectF mRectF;
18 | private ObjectAnimator mLineAnim;
19 | private float degreeFactor;
20 |
21 |
22 | public CurvedLineAnimDrawable2(RectF rectF, Paint paint) {
23 | mPaint2 = paint == null ? getDefaultPaint() : paint;
24 | mRectF=rectF;
25 | }
26 |
27 | private Paint getDefaultPaint() {
28 | Paint p = new Paint();
29 | p.setAntiAlias(true);
30 | p.setDither(true);
31 | p.setStyle(Paint.Style.STROKE);
32 | p.setStrokeJoin(Paint.Join.ROUND);
33 | p.setStrokeCap(Paint.Cap.ROUND);
34 | p.setStrokeWidth(5);
35 | p.setColor(Color.RED);
36 | return p;
37 | }
38 |
39 | private ObjectAnimator getCurvedLineAnim() {
40 | PropertyValuesHolder degreesPVH = PropertyValuesHolder.ofFloat(DEGREE_FACTOR,
41 | 0f, 1f);
42 | ObjectAnimator lineAnim = ObjectAnimator.ofPropertyValuesHolder(
43 | this, degreesPVH).setDuration(durationMS);
44 | lineAnim.addUpdateListener(this);
45 | lineAnim.setAutoCancel(true);
46 | return lineAnim;
47 | }
48 |
49 | public void playAnim() {
50 | if (mLineAnim == null) {
51 | mLineAnim = getCurvedLineAnim();
52 | }
53 | if (mLineAnim.isRunning()) {
54 | mLineAnim.cancel();
55 | }
56 | mLineAnim.start();
57 | }
58 |
59 |
60 | @Override
61 | public void onAnimationUpdate(ValueAnimator animation) {
62 | invalidateSelf();
63 | }
64 |
65 | @Override
66 | public void draw(Canvas canvas) {
67 | canvas.drawArc(mRectF, 180, 180* degreeFactor, false, mPaint2);
68 | }
69 |
70 | @Override
71 | public void setAlpha(int alpha) {
72 | }
73 |
74 | @Override
75 | public void setColorFilter(ColorFilter cf) {
76 |
77 | }
78 |
79 | @Override
80 | public int getOpacity() {
81 | return 0;
82 | }
83 |
84 | public float getDegreeFactor() {
85 | return degreeFactor;
86 | }
87 |
88 | public void setDegreeFactor(float degreeFactor) {
89 | this.degreeFactor = degreeFactor;
90 | }
91 |
92 | public int getDurationMS() {
93 | return durationMS;
94 | }
95 |
96 | public void setDurationMS(int durationMS) {
97 | this.durationMS = durationMS;
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/java/com/dpt/widget/LineAnimHelper.java:
--------------------------------------------------------------------------------
1 | package com.dpt.widget;
2 |
3 | import android.graphics.Paint;
4 | import android.graphics.RectF;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | /**
10 | * Created by dupengtao on 14-9-18.
11 | */
12 | public class LineAnimHelper {
13 |
14 |
15 | public static NormalLineAnimDrawable drawRec(float x, float y, float width, float height, Paint paint) {
16 | NormalLineAnimDrawable animDrawable = new NormalLineAnimDrawable(paint);
17 | List animPoints = new ArrayList(4);
18 | float w = x + width;
19 | float h = y+height;
20 | animPoints.add(new AnimPoint(x, y, w, y));
21 | animPoints.add(new AnimPoint(w, y, w, h));
22 | animPoints.add(new AnimPoint(w, h, x, h));
23 | animPoints.add(new AnimPoint(x, h, x, y));
24 | animDrawable.setPoints(animPoints);
25 | return animDrawable;
26 | }
27 |
28 | public static NormalLineAnimDrawable drawLine(float curX, float curY, float moveX, float moveY, Paint paint) {
29 | NormalLineAnimDrawable animDrawable = new NormalLineAnimDrawable(paint);
30 | List animPoints = new ArrayList();
31 | animPoints.add(new AnimPoint(curX, curY, moveX, moveY));
32 | animDrawable.setPoints(animPoints);
33 | return animDrawable;
34 | }
35 |
36 | public static NormalLineAnimDrawable drawShape(List animPoints, Paint paint) {
37 | NormalLineAnimDrawable animDrawable = new NormalLineAnimDrawable(paint);
38 | animDrawable.setPoints(animPoints);
39 | return animDrawable;
40 | }
41 |
42 | public static CurvedLineAnimDrawable2 drawCurvedLine(RectF rectF, Paint paint) {
43 | CurvedLineAnimDrawable2 drawable2 = new CurvedLineAnimDrawable2(rectF,paint);
44 | return drawable2;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/dpt/widget/NormalLineAnimDrawable.java:
--------------------------------------------------------------------------------
1 | package com.dpt.widget;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.PropertyValuesHolder;
6 | import android.animation.ValueAnimator;
7 | import android.graphics.*;
8 | import android.graphics.drawable.Drawable;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | /**
14 | * Created by dupengtao on 14-9-11.
15 | */
16 | public class NormalLineAnimDrawable extends Drawable implements ValueAnimator.AnimatorUpdateListener {
17 |
18 | private static final String FACTOR_X="factorX";
19 | private static final String FACTOR_Y="factorY";
20 | private final Path mPath2;
21 | private final Paint mPaint2;
22 | private float factorY, factorX;
23 | private AnimPoint curAnimPoint = null;
24 | private int moveTimes;
25 | private List mAnimPoints = new ArrayList();
26 | private ObjectAnimator mLineAnim;
27 | private DisplayMode curDisplayMode = DisplayMode.Appear;
28 | private int durationMS=500;
29 |
30 |
31 | public NormalLineAnimDrawable() {
32 | this(null);
33 | }
34 |
35 | public NormalLineAnimDrawable(Paint paint) {
36 | mPath2 = new Path();
37 | mPaint2 = paint == null ? getDefaultPaint() : paint;
38 | }
39 |
40 | private Paint getDefaultPaint() {
41 | Paint p = new Paint();
42 | p.setAntiAlias(true);
43 | p.setDither(true);
44 | p.setStyle(Paint.Style.STROKE);
45 | p.setStrokeJoin(Paint.Join.ROUND);
46 | p.setStrokeCap(Paint.Cap.ROUND);
47 | p.setStrokeWidth(5);
48 | p.setColor(Color.RED);
49 | return p;
50 | }
51 |
52 | private ObjectAnimator getLineAnim() {
53 | PropertyValuesHolder pvMoveY = PropertyValuesHolder.ofFloat(FACTOR_Y,
54 | 0f, 1f);
55 | PropertyValuesHolder pvMoveX = PropertyValuesHolder.ofFloat(FACTOR_X,
56 | 0f, 1f);
57 | ObjectAnimator lineAnim = ObjectAnimator.ofPropertyValuesHolder(
58 | this, pvMoveY, pvMoveX).setDuration(durationMS);
59 | lineAnim.setRepeatMode(ValueAnimator.RESTART);
60 | lineAnim.setRepeatCount(mAnimPoints.size() - 1);
61 | lineAnim.addUpdateListener(this);
62 | lineAnim.setAutoCancel(true);
63 | lineAnim.addListener(new Animator.AnimatorListener() {
64 | @Override
65 | public void onAnimationStart(Animator animation) {
66 | moveTimes = 0;
67 | curAnimPoint = mAnimPoints.get(moveTimes);
68 | }
69 |
70 | @Override
71 | public void onAnimationEnd(Animator animation) {
72 | }
73 |
74 | @Override
75 | public void onAnimationCancel(Animator animation) {
76 | }
77 |
78 | @Override
79 | public void onAnimationRepeat(Animator animation) {
80 | moveTimes++;
81 | curAnimPoint = mAnimPoints.get(moveTimes);
82 | }
83 | });
84 | return lineAnim;
85 | }
86 |
87 | public void playAnim(List animPoints) {
88 | if(animPoints !=null){
89 | mAnimPoints = animPoints;
90 | }
91 | if (mLineAnim == null) {
92 | mLineAnim = getLineAnim();
93 | }
94 | if (mLineAnim.isRunning()) {
95 | mLineAnim.cancel();
96 | }
97 | mLineAnim.start();
98 | }
99 | public void playAnim() {
100 | playAnim(null);
101 | }
102 |
103 |
104 | public float getFactorY() {
105 | return factorY;
106 | }
107 |
108 | public void setFactorY(float factorY) {
109 | this.factorY = factorY;
110 | }
111 |
112 | public float getFactorX() {
113 | return factorX;
114 | }
115 |
116 | public void setFactorX(float factorX) {
117 | this.factorX = factorX;
118 | }
119 |
120 | @Override
121 | public void onAnimationUpdate(ValueAnimator animation) {
122 | invalidateSelf();
123 | }
124 |
125 | private void drawLine(List animPoints, int num) {
126 | drawLine(animPoints, num, animPoints.size());
127 | }
128 |
129 | private void drawLine(List animPoints, int num, int size) {
130 | for (int i = num, j = size; i < j; i++) {
131 | AnimPoint p = animPoints.get(i);
132 | mPath2.moveTo(p.getCurX(), p.getCurY());
133 | mPath2.lineTo(p.getMoveX(), p.getMoveY());
134 | }
135 | }
136 |
137 | public DisplayMode getCurDisplayMode() {
138 | return curDisplayMode;
139 | }
140 |
141 | public void setCurDisplayMode(DisplayMode curDisplayMode) {
142 | this.curDisplayMode = curDisplayMode;
143 | }
144 |
145 | @Override
146 | public void draw(Canvas canvas) {
147 | if (curAnimPoint != null) {
148 | mPath2.rewind();
149 | float curX = curAnimPoint.getCurX();
150 | float curY = curAnimPoint.getCurY();
151 | float moveX = curAnimPoint.getMoveX();
152 | float moveY = curAnimPoint.getMoveY();
153 | if (curDisplayMode == DisplayMode.Disappear) {
154 | mPath2.moveTo(curX == moveX ? moveX : curX + ((moveX - curX) * factorX), curY == moveY ? moveY : curY + ((moveY - curY) * factorY));
155 | mPath2.lineTo(moveX, moveY);
156 | drawLine(mAnimPoints, moveTimes + 1);
157 | } else if (curDisplayMode == DisplayMode.Appear) {
158 | drawLine(mAnimPoints, 0, moveTimes);
159 | mPath2.moveTo(curX, curY);
160 | mPath2.lineTo(curX == moveX ? moveX : curX + ((moveX - curX) * factorX), curY == moveY ? moveY : curY + ((moveY - curY) * factorY));
161 | }
162 | canvas.drawPath(mPath2, mPaint2);
163 | } else {
164 | canvas.drawPath(mPath2, mPaint2);
165 | }
166 | }
167 |
168 | @Override
169 | public void setAlpha(int alpha) {
170 |
171 | }
172 |
173 | @Override
174 | public void setColorFilter(ColorFilter cf) {
175 |
176 | }
177 |
178 | @Override
179 | public int getOpacity() {
180 | return 0;
181 | }
182 |
183 | public List getPoints() {
184 | return mAnimPoints;
185 | }
186 |
187 | public void setPoints(List animPoints) {
188 | mAnimPoints = animPoints;
189 | }
190 |
191 | public int getDurationMS() {
192 | return durationMS;
193 | }
194 |
195 | public void setDurationMS(int durationMS) {
196 | this.durationMS = durationMS;
197 | }
198 |
199 | /**
200 | * How to display the LineAnim
201 | */
202 | public enum DisplayMode {
203 |
204 | Disappear,
205 |
206 | Appear,
207 | }
208 |
209 | }
210 |
--------------------------------------------------------------------------------
/src/main/java/test/DemoActivity.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import android.app.Activity;
4 | import android.graphics.RectF;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import com.dpt.widget.*;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 |
13 | public class DemoActivity extends Activity {
14 | private NormalLineAnimDrawable animDrawable1;
15 | private NormalLineAnimDrawable animDrawable2;
16 | private NormalLineAnimDrawable animDrawable3;
17 | private CurvedLineAnimDrawable2 curvedLineAnimDrawable2;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_main);
23 | List animPoints = new ArrayList();
24 | animPoints.add(new AnimPoint(50, 50, 300, 50));
25 | animPoints.add(new AnimPoint(300, 50, 300, 300));
26 | animPoints.add(new AnimPoint(300, 300, 50, 300));
27 | animPoints.add(new AnimPoint(50, 300, 50, 50));
28 | animPoints.add(new AnimPoint(50, 50, 300, 300));
29 | animDrawable1= LineAnimHelper.drawShape(animPoints, null);
30 | findViewById(R.id.v1).setBackground(animDrawable1);
31 | animDrawable2=LineAnimHelper.drawShape(animPoints,null);
32 | animDrawable2.setCurDisplayMode(NormalLineAnimDrawable.DisplayMode.Disappear);
33 | findViewById(R.id.v2).setBackground(animDrawable2);
34 | animDrawable3 = LineAnimHelper.drawRec(50, 50, 100, 150, null);
35 | findViewById(R.id.v3).setBackground(animDrawable3);
36 | curvedLineAnimDrawable2=LineAnimHelper.drawCurvedLine(new RectF(100,100,300,300),null);
37 | findViewById(R.id.v5).setBackground(curvedLineAnimDrawable2);
38 | }
39 |
40 | public void beginAnim(View view) {
41 | animDrawable1.playAnim();
42 | animDrawable2.playAnim();
43 | animDrawable3.playAnim();
44 | curvedLineAnimDrawable2.playAnim();
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/LineAnimation/21c78bb7ded993973687e5b17f39b0aa7c9a3c90/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/LineAnimation/21c78bb7ded993973687e5b17f39b0aa7c9a3c90/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/LineAnimation/21c78bb7ded993973687e5b17f39b0aa7c9a3c90/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dupengtao/LineAnimation/21c78bb7ded993973687e5b17f39b0aa7c9a3c90/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
15 |
16 |
20 |
21 |
25 |
29 |
33 |
34 |
35 |
41 |
42 |
--------------------------------------------------------------------------------
/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | LineAnimation
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/widget.iml:
--------------------------------------------------------------------------------
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 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------