Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5154916

Browse filesBrowse files
committed
add hear.png
add view animator update Animation_time
1 parent 0b06ad6 commit 5154916
Copy full SHA for 5154916

File tree

Expand file treeCollapse file tree

5 files changed

+70
-17
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+70
-17
lines changed
Open diff view settings
Collapse file

‎library/src/main/java/xyz/hanks/library/SmallBang.java‎

Copy file name to clipboardExpand all lines: library/src/main/java/xyz/hanks/library/SmallBang.java
+59-15Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

33
import android.animation.ValueAnimator;
44
import android.annotation.TargetApi;
5+
import android.app.Activity;
56
import android.content.Context;
67
import android.graphics.Canvas;
78
import android.graphics.Color;
89
import android.graphics.Paint;
9-
import android.graphics.PorterDuff;
10-
import android.graphics.PorterDuffXfermode;
10+
import android.graphics.Rect;
1111
import android.os.Build;
1212
import android.util.AttributeSet;
1313
import android.util.Log;
1414
import android.view.View;
15+
import android.view.ViewGroup;
16+
import android.view.Window;
17+
import android.view.animation.OvershootInterpolator;
1518

1619
import java.util.ArrayList;
1720
import java.util.List;
@@ -23,7 +26,8 @@
2326
*/
2427
public class SmallBang extends View {
2528

26-
int[] colors = {0xFFDF4288, 0xFFCD8BF8,0XFF2B9DF2,0XFFA4EEB4,0XFFE097CA,0XFFCAACC6,0XFFC5A5FC,0XFFF5BC16,0XFFF2DFC8,0XFFE1BE8E,0XFFC8C79D};
29+
int[] colors = {0xFFDF4288, 0xFFCD8BF8, 0XFF2B9DF2, 0XFFA4EEB4, 0XFFE097CA, 0XFFCAACC6, 0XFFC5A5FC, 0XFFF5BC16, 0XFFF2DFC8, 0XFFE1BE8E, 0XFFC8C79D};
30+
List<Dot> dotList = new ArrayList<>();
2731
private long ANIMATE_DURATION = 1000;
2832
private float MAX_RADIUS = 150;
2933
private float MAX_CIRCLE_RADIUS = 100;
@@ -36,8 +40,7 @@ public class SmallBang extends View {
3640
private int DOT_NUMBER = 16;
3741
private float DOT_BIG_RADIUS = 8;
3842
private float DOT_SMALL_RADIUS = 5;
39-
40-
43+
private int[] mExpandInset = new int[2];
4144
// 将下面的view变小
4245
// 画圆半径从小到大,同时颜色渐变 (P1)
4346
// 当半径到达 MAX_RADIUS, 开始画空心圆,空闲圆半径变大,画笔宽度从MAX_RADIUS变小
@@ -73,6 +76,38 @@ private void init(AttributeSet attrs, int defStyleAttr) {
7376

7477
}
7578

79+
public void bang(final View view) {
80+
Rect r = new Rect();
81+
view.getGlobalVisibleRect(r);
82+
int[] location = new int[2];
83+
getLocationOnScreen(location);
84+
r.offset(-location[0], -location[1]);
85+
r.inset(-mExpandInset[0], -mExpandInset[1]);
86+
int startDelay = 100;
87+
view.setScaleX(0.1f);
88+
view.setScaleY(0.1f);
89+
ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f).setDuration((long) (ANIMATE_DURATION*0.5f));
90+
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
91+
92+
// Random random = new Random();
93+
94+
@Override
95+
public void onAnimationUpdate(ValueAnimator animation) {
96+
// view.setTranslationX((random.nextFloat() - 0.5f) * view.getWidth() * 0.05f);
97+
// view.setTranslationY((random.nextFloat() - 0.5f) * view.getHeight() * 0.05f);
98+
float animatedFraction = animation.getAnimatedFraction();
99+
view.setScaleX(0.1f + animatedFraction*0.9f);
100+
view.setScaleY(0.1f + animatedFraction*0.9f);
101+
}
102+
});
103+
animator.setInterpolator(new OvershootInterpolator(2));
104+
animator.setStartDelay((long) (ANIMATE_DURATION * P3));
105+
animator.start();
106+
// view.animate().setDuration(150).setStartDelay(startDelay).scaleX(0f).scaleY(0f).alpha(0f).start();
107+
//explode(Utils.createBitmapFromView(view), r, startDelay, ExplosionAnimator.DEFAULT_DURATION);
108+
bang();
109+
}
110+
76111
public void bang() {
77112
ValueAnimator valueAnimator = new ValueAnimator().ofFloat(0, 1).setDuration(ANIMATE_DURATION);
78113
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@@ -86,11 +121,10 @@ public void onAnimationUpdate(ValueAnimator animation) {
86121
initDots();
87122
}
88123

89-
List<Dot> dotList = new ArrayList<>();
90-
private void initDots(){
124+
private void initDots() {
91125

92126
Random random = new Random(System.currentTimeMillis());
93-
for (int i = 0; i < DOT_NUMBER*2; i++) {
127+
for (int i = 0; i < DOT_NUMBER * 2; i++) {
94128
Dot dot = new Dot();
95129
dot.startColor = colors[random.nextInt(99999) % colors.length];
96130
dot.endColor = colors[random.nextInt(99999) % colors.length];
@@ -104,17 +138,17 @@ protected void onDraw(Canvas canvas) {
104138

105139
Log.d("SmallBang", "draw" + progress);
106140

107-
if(progress>=0 && progress<=P1) {
141+
if (progress >= 0 && progress <= P1) {
108142
float progress1 = 1f / P1 * progress;
109143
if (progress1 > 1) progress1 = 1;
110144
int startColor = colors[0];
111145
int endColor = colors[1];
112146
circlePaint.setStyle(Paint.Style.FILL);
113147
circlePaint.setColor(evaluateColor(startColor, endColor, progress1));
114148
canvas.drawCircle(getWidth() / 2, getHeight() / 2, MAX_CIRCLE_RADIUS * progress1, circlePaint);
115-
}else if(progress>P1){
149+
} else if (progress > P1) {
116150

117-
if(progress>P1 && progress<=P3) {
151+
if (progress > P1 && progress <= P3) {
118152
float progress2 = (progress - P1) / (P3 - P1);
119153
if (progress2 < 0) progress2 = 0;
120154
if (progress2 > 1) progress2 = 1;
@@ -150,14 +184,19 @@ protected void onDraw(Canvas canvas) {
150184
}
151185
}
152186
}
153-
}
154187

155188

156-
class Dot {
157-
int startColor;
158-
int endColor;
159189
}
160190

191+
public static SmallBang attach2Window(Activity activity) {
192+
ViewGroup rootView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);
193+
SmallBang smallBang = new SmallBang(activity);
194+
rootView.addView(smallBang, new ViewGroup.LayoutParams(
195+
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
196+
return smallBang;
197+
}
198+
199+
161200
private int evaluateColor(int startValue, int endValue, float fraction) {
162201
if (fraction <= 0) {
163202
return startValue;
@@ -179,4 +218,9 @@ private int evaluateColor(int startValue, int endValue, float fraction) {
179218

180219
return ((startA + (int) (fraction * (endA - startA))) << 24) | ((startR + (int) (fraction * (endR - startR))) << 16) | ((startG + (int) (fraction * (endG - startG))) << 8) | ((startB + (int) (fraction * (endB - startB))));
181220
}
221+
222+
class Dot {
223+
int startColor;
224+
int endColor;
225+
}
182226
}
Collapse file

‎simple/src/main/java/xyz/hanks/smallbang/MainActivity.java‎

Copy file name to clipboardExpand all lines: simple/src/main/java/xyz/hanks/smallbang/MainActivity.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ protected void onCreate(Bundle savedInstanceState) {
1515
super.onCreate(savedInstanceState);
1616
setContentView(R.layout.activity_main);
1717
smallBang = (SmallBang)findViewById(R.id.smallbang);
18+
1819
}
1920

2021
public void show(View view){
21-
smallBang.bang();
22+
smallBang.bang(findViewById(R.id.image));
2223
}
2324
}
Collapse file
8.06 KB
  • Display the source diff
  • Display the rich diff
Loading
Collapse file
7.99 KB
  • Display the source diff
  • Display the rich diff
Loading
Collapse file

‎simple/src/main/res/layout/activity_main.xml‎

Copy file name to clipboardExpand all lines: simple/src/main/res/layout/activity_main.xml
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@
99
android:paddingTop="@dimen/activity_vertical_margin"
1010
tools:context="xyz.hanks.smallbang.MainActivity">
1111

12+
<ImageView
13+
android:id="@+id/image"
14+
android:src="@mipmap/ic_launcher"
15+
android:layout_width="wrap_content"
16+
android:layout_centerInParent="true"
17+
android:layout_height="wrap_content"
18+
android:text="Hello World!" />
1219
<xyz.hanks.library.SmallBang
13-
android:background="@mipmap/ic_launcher"
1420
android:id="@+id/smallbang"
1521
android:clickable="true"
1622
android:onClick="show"
1723
android:layout_width="match_parent"
1824
android:layout_height="match_parent"
1925
android:text="Hello World!" />
26+
27+
2028
</RelativeLayout>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.