├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── tgithubc
│ │ └── view
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── tgithubc
│ │ │ └── view
│ │ │ ├── MainActivity.java
│ │ │ └── musicnote
│ │ │ ├── BezierEvaluator.java
│ │ │ ├── CircleMusicView.java
│ │ │ ├── MusicalNoteLayout.java
│ │ │ └── util
│ │ │ ├── DPPXUtil.java
│ │ │ └── WeakWrapperHandler.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ ├── douyin.png
│ │ ├── ic_launcher.png
│ │ ├── note1.png
│ │ └── note2.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── attr.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── ids.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── tgithubc
│ └── view
│ └── ExampleUnitTest.java
├── build.gradle
├── gif
└── 1.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | DouYinMusicView
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
22 |
23 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DouYinMusicView
2 |
3 | 模仿抖音右下角的控件
4 |
5 | 效果图:
6 | 
7 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.tgithubc.view"
9 | minSdkVersion 15
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:26.+'
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 /Users/litiancheng/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/tgithubc/view/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.tgithubc.view;
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 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tgithubc/view/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.tgithubc.view;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | public class MainActivity extends AppCompatActivity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.activity_main);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tgithubc/view/musicnote/BezierEvaluator.java:
--------------------------------------------------------------------------------
1 | package com.tgithubc.view.musicnote;
2 |
3 | import android.animation.TypeEvaluator;
4 | import android.graphics.PointF;
5 |
6 | public class BezierEvaluator implements TypeEvaluator {
7 |
8 | private PointF pointF1;
9 | private PointF pointF2;
10 |
11 | public BezierEvaluator(PointF pointF1, PointF pointF2) {
12 | this.pointF1 = pointF1;
13 | this.pointF2 = pointF2;
14 | }
15 |
16 | @Override
17 | public PointF evaluate(float time, PointF startValue, PointF endValue) {
18 |
19 | float timeLeft = 1.0f - time;
20 | PointF point = new PointF();
21 |
22 | point.x = timeLeft * timeLeft * timeLeft * (startValue.x)
23 | + 3 * timeLeft * timeLeft * time * (pointF1.x)
24 | + 3 * timeLeft * time * time * (pointF2.x)
25 | + time * time * time * (endValue.x);
26 |
27 | point.y = timeLeft * timeLeft * timeLeft * (startValue.y)
28 | + 3 * timeLeft * timeLeft * time * (pointF1.y)
29 | + 3 * timeLeft * time * time * (pointF2.y)
30 | + time * time * time * (endValue.y);
31 | return point;
32 | }
33 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/tgithubc/view/musicnote/CircleMusicView.java:
--------------------------------------------------------------------------------
1 | package com.tgithubc.view.musicnote;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.graphics.PorterDuff;
10 | import android.graphics.PorterDuffXfermode;
11 | import android.graphics.RectF;
12 | import android.graphics.drawable.Drawable;
13 | import android.graphics.drawable.NinePatchDrawable;
14 | import android.util.AttributeSet;
15 | import android.widget.ImageView;
16 |
17 | import com.tgithubc.view.R;
18 | import com.tgithubc.view.musicnote.util.DPPXUtil;
19 |
20 |
21 | /**
22 | * Created by tc :)
23 | */
24 | public class CircleMusicView extends ImageView {
25 |
26 | private static final int DEFAULT_BORDER_WIDTH = 2;//dp
27 | private static final int DEFAULT_DEFAULT_SIZE = 45;//dp
28 |
29 | private int mDefaultSize;
30 | private int mProgressWidth;
31 | // 进度槽颜色
32 | private int mProgressSlotColor;
33 | // 缓冲进度颜色
34 | private int mProgressBufferColor;
35 | // 进度颜色
36 | private int mProgressColor;
37 | private int mSize;
38 |
39 | private float mBufferProgress;
40 | private float mProgress;
41 | private float mDegree;
42 |
43 | // 遮罩相关
44 | private Bitmap mShadeBitmap;
45 | private Paint mPaint;
46 |
47 | // 进度相关
48 | private Paint mProgressPaint;
49 | private RectF mProgressRect;
50 |
51 | public CircleMusicView(Context context) {
52 | this(context, null);
53 | }
54 |
55 | public CircleMusicView(Context context, AttributeSet attrs) {
56 | this(context, attrs, 0);
57 | }
58 |
59 | public CircleMusicView(Context context, AttributeSet attrs, int defStyleAttr) {
60 | super(context, attrs, defStyleAttr);
61 | init(context, attrs);
62 | }
63 |
64 | private void init(Context context, AttributeSet attrs) {
65 | mDefaultSize = DPPXUtil.dip2px(getContext(), DEFAULT_DEFAULT_SIZE);
66 | int defaultBorderWidth = DPPXUtil.dip2px(getContext(), DEFAULT_BORDER_WIDTH);
67 | final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CircleMusicView, 0, 0);
68 | try {
69 | mProgressWidth = ta.getDimensionPixelOffset(R.styleable.CircleMusicView_circle_music_view_progress_width,
70 | defaultBorderWidth);
71 | mProgressBufferColor = ta.getColor(R.styleable.CircleMusicView_circle_music_view_progress_slot_color,
72 | Color.LTGRAY);
73 | mProgressSlotColor = ta.getColor(R.styleable.CircleMusicView_circle_music_view_progress_buffer_color,
74 | Color.GRAY);
75 | mProgressColor = ta.getColor(R.styleable.CircleMusicView_circle_music_view_progress_color,
76 | Color.YELLOW);
77 | } finally {
78 | ta.recycle();
79 | }
80 |
81 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
82 | mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
83 | mPaint.setFilterBitmap(true);
84 |
85 | mProgressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
86 | mProgressPaint.setStrokeWidth(mProgressWidth);
87 | mProgressPaint.setStyle(Paint.Style.STROKE);
88 | }
89 |
90 | @Override
91 | protected void onDraw(Canvas canvas) {
92 | final Drawable drawable = getDrawable();
93 | if (drawable == null || drawable instanceof NinePatchDrawable) {
94 | return;
95 | }
96 | int layer = canvas.saveLayer(0F, 0F, mSize, mSize, null, Canvas.ALL_SAVE_FLAG);
97 | canvas.rotate(mDegree, mSize / 2, mSize / 2);
98 | drawable.setBounds(0, 0, mSize, mSize);
99 | // 原图
100 | drawable.draw(canvas);
101 | if (mShadeBitmap == null || mShadeBitmap.isRecycled()) {
102 | mShadeBitmap = createShadeBitmap();
103 | }
104 | // 遮罩
105 | canvas.drawBitmap(mShadeBitmap, 0F, 0F, mPaint);
106 | canvas.restoreToCount(layer);
107 | // 进度槽
108 | mProgressPaint.setColor(mProgressSlotColor);
109 | canvas.drawArc(mProgressRect, 0F, 360F, false, mProgressPaint);
110 | // 缓冲进度
111 | mProgressPaint.setColor(mProgressBufferColor);
112 | canvas.drawArc(mProgressRect, -90F, mBufferProgress, false, mProgressPaint);
113 | // 进度
114 | mProgressPaint.setColor(mProgressColor);
115 | canvas.drawArc(mProgressRect, -90F, mProgress, false, mProgressPaint);
116 | }
117 |
118 | @Override
119 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
120 | int measureWidth = measureDimension(mDefaultSize, widthMeasureSpec);
121 | int measureHeight = measureDimension(mDefaultSize, heightMeasureSpec);
122 | setMeasuredDimension(measureWidth, measureHeight);
123 | }
124 |
125 | @Override
126 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
127 | super.onSizeChanged(w, h, oldw, oldh);
128 | mSize = Math.min(w, h);
129 | // 进度条范围
130 | int halfBoardWidth = mProgressWidth / 2;
131 | mProgressRect = new RectF(halfBoardWidth,
132 | halfBoardWidth,
133 | mSize - halfBoardWidth,
134 | mSize - halfBoardWidth);
135 | }
136 |
137 | public void setProgress(float progress) {
138 | this.mProgress = progress;
139 | invalidate();
140 | }
141 |
142 | public void setBufferProgress(float progress) {
143 | this.mBufferProgress = progress;
144 | invalidate();
145 | }
146 |
147 | @Override
148 | public void setImageResource(int resId) {
149 | super.setImageResource(resId);
150 | mDegree = 0;
151 | }
152 |
153 | @Override
154 | public void setImageBitmap(Bitmap bm) {
155 | super.setImageBitmap(bm);
156 | mDegree = 0;
157 | }
158 |
159 | private int measureDimension(int defaultSize, int measureSpec) {
160 | int result;
161 | int specMode = MeasureSpec.getMode(measureSpec);
162 | int specSize = MeasureSpec.getSize(measureSpec);
163 | if (specMode == MeasureSpec.EXACTLY) {
164 | result = specSize;
165 | } else if (specMode == MeasureSpec.AT_MOST) {
166 | result = Math.min(defaultSize, specSize);
167 | } else {
168 | result = defaultSize;
169 | }
170 | return result;
171 | }
172 |
173 | private void setDegree(float degree) {
174 | this.mDegree = degree;
175 | invalidate();
176 | }
177 |
178 | public void startRotate() {
179 | mDegree++;
180 | if (mDegree > 360) {
181 | mDegree = 0;
182 | }
183 | setDegree(mDegree);
184 | }
185 |
186 | /**
187 | * 弄个圆形遮罩图片,XferMode只能要图片,画别的不行
188 | */
189 | private Bitmap createShadeBitmap() {
190 | Bitmap bitmap = Bitmap.createBitmap(mSize, mSize, Bitmap.Config.ARGB_8888);
191 | Canvas canvas = new Canvas(bitmap);
192 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
193 | paint.setFilterBitmap(true);
194 | RectF f = new RectF(mProgressWidth,
195 | mProgressWidth,
196 | mSize - mProgressWidth,
197 | mSize - mProgressWidth);
198 | canvas.drawOval(f, paint);
199 | return bitmap;
200 | }
201 | }
202 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tgithubc/view/musicnote/MusicalNoteLayout.java:
--------------------------------------------------------------------------------
1 | package com.tgithubc.view.musicnote;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.AnimatorSet;
6 | import android.animation.ObjectAnimator;
7 | import android.animation.ValueAnimator;
8 | import android.content.Context;
9 | import android.content.res.TypedArray;
10 | import android.graphics.Bitmap;
11 | import android.graphics.PointF;
12 | import android.graphics.drawable.Drawable;
13 | import android.os.Message;
14 | import android.util.AttributeSet;
15 | import android.view.View;
16 | import android.view.animation.AccelerateInterpolator;
17 | import android.widget.ImageView;
18 | import android.widget.RelativeLayout;
19 |
20 | import com.tgithubc.view.R;
21 | import com.tgithubc.view.musicnote.util.DPPXUtil;
22 | import com.tgithubc.view.musicnote.util.WeakWrapperHandler;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 | import java.util.Random;
27 |
28 |
29 | /**
30 | * Created by tc :)
31 | */
32 | public class MusicalNoteLayout extends RelativeLayout implements WeakWrapperHandler.MessageHandler {
33 |
34 | private static final int DEFAULT_MUSIC_VIEW_SIZE = 45;//dp
35 |
36 | private static final int MSG_WHAT_ROTATION = 0;
37 | private static final int MSG_WHAT_ADD_NOTE = 1;
38 | private static final int DEFAULT_ROTATION_SPEED = 50;
39 | private static final int DEFAULT_ADD_NOTE_SPEED = 1500;
40 |
41 | // layout的宽高
42 | private int mWidth, mHeight;
43 | // 音符Drawable集合
44 | private List mDrawables;
45 | // 音符的宽高
46 | private int mDrawableWidth, mDrawableHeight;
47 | // 音符LayoutParams
48 | private LayoutParams mNoteParams;
49 | // 转圈的音乐view
50 | private CircleMusicView mMusicView;
51 |
52 | private int mIndex;
53 | private Random mRandom = new Random();
54 |
55 | private WeakWrapperHandler mAnimateHandler;
56 |
57 | public MusicalNoteLayout(Context context) {
58 | this(context, null);
59 | }
60 |
61 | public MusicalNoteLayout(Context context, AttributeSet attrs) {
62 | this(context, attrs, 0);
63 | }
64 |
65 | public MusicalNoteLayout(Context context, AttributeSet attrs, int defStyleAttr) {
66 | super(context, attrs, defStyleAttr);
67 | init(context, attrs);
68 | }
69 |
70 | @Override
71 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
72 | super.onSizeChanged(w, h, oldw, oldh);
73 | mWidth = w;
74 | mHeight = h;
75 | // test code
76 | start(true);
77 | }
78 |
79 | private void init(Context context, AttributeSet attrs) {
80 | mAnimateHandler = new WeakWrapperHandler(this);
81 | int defaultSize = DPPXUtil.dip2px(getContext(), DEFAULT_MUSIC_VIEW_SIZE);
82 | int musicViewSize;
83 | Drawable musicViewRes;
84 | final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MusicalNoteLayout, 0, 0);
85 | try {
86 | musicViewSize = ta.getDimensionPixelOffset(R.styleable.MusicalNoteLayout_circle_music_view_size,
87 | defaultSize);
88 | musicViewRes = ta.getDrawable(R.styleable.MusicalNoteLayout_circle_music_view_res);
89 | } finally {
90 | ta.recycle();
91 | }
92 | mMusicView = new CircleMusicView(getContext());
93 | if (musicViewRes != null) {
94 | mMusicView.setImageDrawable(musicViewRes);
95 | }
96 | mMusicView.setId(R.id.music_view_id);
97 | LayoutParams params = new LayoutParams(musicViewSize, musicViewSize);
98 | params.addRule(ALIGN_PARENT_BOTTOM);
99 | params.addRule(ALIGN_PARENT_RIGHT);
100 | params.rightMargin = DPPXUtil.dip2px(getContext(), 10);
101 | params.bottomMargin = DPPXUtil.dip2px(getContext(), 25);
102 | addView(mMusicView, params);
103 |
104 | Drawable note1 = getResources().getDrawable(R.mipmap.note1);
105 | Drawable note2 = getResources().getDrawable(R.mipmap.note2);
106 | mDrawables = new ArrayList<>();
107 | for (int i = 0; i < 3; i++) {
108 | mDrawables.add(i == 0 ? note1 : note2);
109 | }
110 |
111 | mDrawableHeight = note1.getIntrinsicHeight() / 2;
112 | mDrawableWidth = note1.getIntrinsicWidth() / 2;
113 |
114 | mNoteParams = new LayoutParams(mDrawableWidth, mDrawableHeight);
115 | mNoteParams.addRule(ALIGN_PARENT_BOTTOM);
116 | mNoteParams.addRule(ALIGN_PARENT_RIGHT);
117 | mNoteParams.rightMargin = params.rightMargin + musicViewSize / 2 - mDrawableWidth / 2;
118 | mNoteParams.bottomMargin = params.bottomMargin - mDrawableHeight;
119 | }
120 |
121 | public void start(boolean start) {
122 | mAnimateHandler.removeMessages(MSG_WHAT_ROTATION);
123 | mAnimateHandler.removeMessages(MSG_WHAT_ADD_NOTE);
124 | if (start) {
125 | mAnimateHandler.sendEmptyMessage(MSG_WHAT_ROTATION);
126 | mAnimateHandler.sendEmptyMessage(MSG_WHAT_ADD_NOTE);
127 | }
128 | }
129 |
130 | public void setImageResource(int resId) {
131 | mMusicView.setImageResource(resId);
132 | }
133 |
134 | public void setImageBitmap(Bitmap bm) {
135 | mMusicView.setImageBitmap(bm);
136 | }
137 |
138 | @Override
139 | public void handleMessage(Message msg) {
140 | if (msg.what == MSG_WHAT_ROTATION) {
141 | mMusicView.startRotate();
142 | mAnimateHandler.sendEmptyMessageDelayed(MSG_WHAT_ROTATION,
143 | DEFAULT_ROTATION_SPEED);
144 | } else if (msg.what == MSG_WHAT_ADD_NOTE) {
145 | ++mIndex;
146 | if (mIndex >= mDrawables.size()) {
147 | mIndex = 0;
148 | }
149 | addMusicNote(mIndex);
150 | mAnimateHandler.sendEmptyMessageDelayed(MSG_WHAT_ADD_NOTE,
151 | DEFAULT_ADD_NOTE_SPEED);
152 | }
153 | }
154 |
155 | private void addMusicNote(int index) {
156 | ImageView noteView = new ImageView(getContext());
157 | noteView.setImageDrawable(mDrawables.get(index));
158 | addView(noteView, mNoteParams);
159 | Animator set = getFinalAnimator(noteView);
160 | set.addListener(new AnimEndListener(noteView));
161 | set.start();
162 | }
163 |
164 | private Animator getFinalAnimator(View target) {
165 | AnimatorSet set = getEnterAnimator(target);
166 | ValueAnimator bezierValueAnimator = getBezierValueAnimator(target);
167 | AnimatorSet finalSet = new AnimatorSet();
168 | finalSet.playTogether(set, bezierValueAnimator);
169 | finalSet.setInterpolator(new AccelerateInterpolator());
170 | finalSet.setTarget(target);
171 | return finalSet;
172 | }
173 |
174 | // 出场动画
175 | private AnimatorSet getEnterAnimator(final View target) {
176 | ObjectAnimator alpha = ObjectAnimator.ofFloat(target, View.ALPHA, 0.1f, 1f);
177 | ObjectAnimator scaleX = ObjectAnimator.ofFloat(target, View.SCALE_X, 0.0f, 1f);
178 | ObjectAnimator scaleY = ObjectAnimator.ofFloat(target, View.SCALE_Y, 0.0f, 1f);
179 | AnimatorSet enter = new AnimatorSet();
180 | enter.setDuration(1000);
181 | enter.setInterpolator(new AccelerateInterpolator());
182 | enter.playTogether(alpha, scaleX, scaleY);
183 |
184 | AnimatorSet before = new AnimatorSet();
185 | // 同时在正负25f的角度上做随机旋转
186 | ObjectAnimator rotate = ObjectAnimator.ofFloat(target, View.ROTATION, 0.0f, mRandom.nextInt(50) - 25.5f);
187 | rotate.setDuration(2000);
188 | before.playSequentially(enter, rotate);
189 | return before;
190 | }
191 |
192 | // 贝塞尔曲线轨迹动画
193 | private ValueAnimator getBezierValueAnimator(View target) {
194 | // 中点
195 | BezierEvaluator evaluator = new BezierEvaluator(new PointF(0f, mHeight - mHeight / 4),
196 | new PointF(0f, mHeight - mHeight / 2));
197 | // 终点在0
198 | // 起点定在音符的左上角坐标
199 | ValueAnimator animator = ValueAnimator.ofObject(evaluator,
200 | new PointF(mMusicView.getX() + mMusicView.getWidth() / 2 - mDrawableHeight / 2,
201 | mMusicView.getBottom()),
202 | new PointF(mMusicView.getLeft() / 2, mMusicView.getTop() - mMusicView.getHeight() / 2));
203 | animator.addUpdateListener(new BezierListener(target));
204 | animator.setDuration(4000);
205 | return animator;
206 | }
207 |
208 | private class BezierListener implements ValueAnimator.AnimatorUpdateListener {
209 |
210 | private View target;
211 |
212 | public BezierListener(View target) {
213 | this.target = target;
214 | }
215 |
216 | @Override
217 | public void onAnimationUpdate(ValueAnimator va) {
218 | PointF pointF = (PointF) va.getAnimatedValue();
219 | target.setX(pointF.x);
220 | target.setY(pointF.y);
221 | target.setAlpha(1 - va.getAnimatedFraction());
222 | }
223 | }
224 |
225 | private class AnimEndListener extends AnimatorListenerAdapter {
226 |
227 | private View target;
228 |
229 | public AnimEndListener(View target) {
230 | this.target = target;
231 | }
232 |
233 | @Override
234 | public void onAnimationEnd(Animator animation) {
235 | super.onAnimationEnd(animation);
236 | removeView((target));
237 | }
238 | }
239 | }
240 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tgithubc/view/musicnote/util/DPPXUtil.java:
--------------------------------------------------------------------------------
1 | package com.tgithubc.view.musicnote.util;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by tc :)
7 | */
8 | public class DPPXUtil {
9 |
10 | public static int px2dip(Context context, float pxValue) {
11 | final float scale = context.getResources().getDisplayMetrics().density;
12 | return (int) (pxValue / scale + 0.5f);
13 | }
14 |
15 | public static int dip2px(Context context,float dipValue) {
16 | final float scale = context.getResources().getDisplayMetrics().density;
17 | return (int) (dipValue * scale + 0.5f);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tgithubc/view/musicnote/util/WeakWrapperHandler.java:
--------------------------------------------------------------------------------
1 | package com.tgithubc.view.musicnote.util;
2 |
3 | import android.os.Handler;
4 | import android.os.Message;
5 |
6 | import java.lang.ref.WeakReference;
7 |
8 | /**
9 | * Created by tc :)
10 | */
11 | public class WeakWrapperHandler extends Handler {
12 |
13 | public interface MessageHandler {
14 | void handleMessage(Message msg);
15 | }
16 |
17 | private WeakReference mMessageHandler;
18 |
19 | public WeakWrapperHandler(MessageHandler msgHandler) {
20 | mMessageHandler = new WeakReference<>(msgHandler);
21 | }
22 |
23 | @Override
24 | public void handleMessage(Message msg) {
25 | MessageHandler realHandler = mMessageHandler.get();
26 | if (realHandler != null) {
27 | realHandler.handleMessage(msg);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tgithubc/DouYinMusicView/b002b1796cf482eedd9619a51e09c5305361f509/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tgithubc/DouYinMusicView/b002b1796cf482eedd9619a51e09c5305361f509/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tgithubc/DouYinMusicView/b002b1796cf482eedd9619a51e09c5305361f509/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/douyin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tgithubc/DouYinMusicView/b002b1796cf482eedd9619a51e09c5305361f509/app/src/main/res/mipmap-xxhdpi/douyin.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tgithubc/DouYinMusicView/b002b1796cf482eedd9619a51e09c5305361f509/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/note1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tgithubc/DouYinMusicView/b002b1796cf482eedd9619a51e09c5305361f509/app/src/main/res/mipmap-xxhdpi/note1.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/note2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tgithubc/DouYinMusicView/b002b1796cf482eedd9619a51e09c5305361f509/app/src/main/res/mipmap-xxhdpi/note2.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tgithubc/DouYinMusicView/b002b1796cf482eedd9619a51e09c5305361f509/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MusicNoteLayout
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/tgithubc/view/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.tgithubc.view;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.0.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gif/1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tgithubc/DouYinMusicView/b002b1796cf482eedd9619a51e09c5305361f509/gif/1.gif
--------------------------------------------------------------------------------
/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tgithubc/DouYinMusicView/b002b1796cf482eedd9619a51e09c5305361f509/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------