Skip to content

Commit d779eab

Browse files
committed
add try catch
1 parent fc1b1a3 commit d779eab

File tree

10 files changed

+240
-482
lines changed

10 files changed

+240
-482
lines changed

circularanim/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ android {
1111
minSdkVersion 14
1212
targetSdkVersion 24
1313
versionCode 5
14-
versionName "0.3.1"
14+
versionName "0.3.2"
1515
}
1616
buildTypes {
1717
release {

circularanim/src/main/java/top/wefor/circularanim/CircularAnim.java

Lines changed: 94 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* <p/>
1818
* GitHub: https://github.com/XunMengWinter
1919
* <p/>
20-
* latest edited date: 2016-08-05 17:07
20+
* latest edited date: 2016-08-05 20:00
2121
*
2222
* @author ice
2323
*/
@@ -81,13 +81,7 @@ public VisibleBuilder onAnimationEndListener(OnAnimationEndListener onAnimationE
8181
public void go() {
8282
// 版本判断
8383
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
84-
if (isShow)
85-
mAnimView.setVisibility(View.VISIBLE);
86-
else
87-
mAnimView.setVisibility(View.INVISIBLE);
88-
89-
if (mOnAnimationEndListener != null)
90-
mOnAnimationEndListener.onAnimationEnd();
84+
doOnEnd();
9185
return;
9286
}
9387

@@ -137,26 +131,37 @@ public void go() {
137131
else if (!isShow && mStartRadius == null)
138132
mStartRadius = maxRadius + 0F;
139133

140-
Animator anim = ViewAnimationUtils.createCircularReveal(
141-
mAnimView, rippleCX, rippleCY, mStartRadius, mEndRadius);
142-
mAnimView.setVisibility(View.VISIBLE);
143-
anim.setDuration(mDurationMills);
144-
145-
anim.addListener(new AnimatorListenerAdapter() {
146-
@Override
147-
public void onAnimationEnd(Animator animation) {
148-
super.onAnimationEnd(animation);
149-
if (isShow)
150-
mAnimView.setVisibility(View.VISIBLE);
151-
else
152-
mAnimView.setVisibility(View.INVISIBLE);
153-
154-
if (mOnAnimationEndListener != null)
155-
mOnAnimationEndListener.onAnimationEnd();
156-
}
157-
});
134+
try {
135+
Animator anim = ViewAnimationUtils.createCircularReveal(
136+
mAnimView, rippleCX, rippleCY, mStartRadius, mEndRadius);
137+
138+
139+
mAnimView.setVisibility(View.VISIBLE);
140+
anim.setDuration(mDurationMills);
141+
142+
anim.addListener(new AnimatorListenerAdapter() {
143+
@Override
144+
public void onAnimationEnd(Animator animation) {
145+
super.onAnimationEnd(animation);
146+
doOnEnd();
147+
}
148+
});
158149

159-
anim.start();
150+
anim.start();
151+
} catch (Exception e) {
152+
e.printStackTrace();
153+
doOnEnd();
154+
}
155+
}
156+
157+
private void doOnEnd() {
158+
if (isShow)
159+
mAnimView.setVisibility(View.VISIBLE);
160+
else
161+
mAnimView.setVisibility(View.INVISIBLE);
162+
163+
if (mOnAnimationEndListener != null)
164+
mOnAnimationEndListener.onAnimationEnd();
160165
}
161166

162167
}
@@ -203,7 +208,7 @@ public void go(OnAnimationEndListener onAnimationEndListener) {
203208

204209
// 版本判断,小于5.0则无动画.
205210
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
206-
mOnAnimationEndListener.onAnimationEnd();
211+
doOnEnd();
207212
return;
208213
}
209214

@@ -224,54 +229,72 @@ public void go(OnAnimationEndListener onAnimationEndListener) {
224229
int maxH = Math.max(cy, h - cy);
225230
final int finalRadius = (int) Math.sqrt(maxW * maxW + maxH * maxH) + 1;
226231

227-
Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, mStartRadius, finalRadius);
228-
int maxRadius = (int) Math.sqrt(w * w + h * h) + 1;
229-
// 若未设置时长,则以PERFECT_MILLS为基准根据水波扩散的距离来计算实际时间
230-
if (mDurationMills == null) {
231-
// 算出实际边距与最大边距的比率
232-
double rate = 1d * finalRadius / maxRadius;
233-
// 为了让用户便于感触到水波,速度应随最大边距的变小而越慢,扩散时间应随最大边距的变小而变小,因此比率应在 @rate 与 1 之间。
234-
mDurationMills = (long) (PERFECT_MILLS * Math.sqrt(rate));
235-
}
236-
final long finalDuration = mDurationMills;
237-
// 由于thisActivity.startActivity()会有所停顿,所以进入的水波动画应比退出的水波动画时间短才能保持视觉上的一致。
238-
anim.setDuration((long) (finalDuration * 0.9));
239-
anim.addListener(new AnimatorListenerAdapter() {
240-
@Override
241-
public void onAnimationEnd(Animator animation) {
242-
super.onAnimationEnd(animation);
243-
244-
mOnAnimationEndListener.onAnimationEnd();
245-
246-
mActivity.overridePendingTransition(mEnterAnim, mExitAnim);
247-
248-
// 默认显示返回至当前Activity的动画.
249-
mTriggerView.postDelayed(new Runnable() {
250-
@Override
251-
public void run() {
252-
if (mActivity.isFinishing()) return;
253-
254-
Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy,
255-
finalRadius, mStartRadius);
256-
anim.setDuration(finalDuration);
257-
anim.addListener(new AnimatorListenerAdapter() {
258-
@Override
259-
public void onAnimationEnd(Animator animation) {
260-
super.onAnimationEnd(animation);
232+
try {
233+
Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, mStartRadius, finalRadius);
234+
235+
int maxRadius = (int) Math.sqrt(w * w + h * h) + 1;
236+
// 若未设置时长,则以PERFECT_MILLS为基准根据水波扩散的距离来计算实际时间
237+
if (mDurationMills == null) {
238+
// 算出实际边距与最大边距的比率
239+
double rate = 1d * finalRadius / maxRadius;
240+
// 为了让用户便于感触到水波,速度应随最大边距的变小而越慢,扩散时间应随最大边距的变小而变小,因此比率应在 @rate 与 1 之间。
241+
mDurationMills = (long) (PERFECT_MILLS * Math.sqrt(rate));
242+
}
243+
final long finalDuration = mDurationMills;
244+
// 由于thisActivity.startActivity()会有所停顿,所以进入的水波动画应比退出的水波动画时间短才能保持视觉上的一致。
245+
anim.setDuration((long) (finalDuration * 0.9));
246+
anim.addListener(new AnimatorListenerAdapter() {
247+
@Override
248+
public void onAnimationEnd(Animator animation) {
249+
super.onAnimationEnd(animation);
250+
251+
doOnEnd();
252+
253+
mActivity.overridePendingTransition(mEnterAnim, mExitAnim);
254+
255+
// 默认显示返回至当前Activity的动画.
256+
mTriggerView.postDelayed(new Runnable() {
257+
@Override
258+
public void run() {
259+
if (mActivity.isFinishing()) return;
260+
try {
261+
Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy,
262+
finalRadius, mStartRadius);
263+
anim.setDuration(finalDuration);
264+
anim.addListener(new AnimatorListenerAdapter() {
265+
@Override
266+
public void onAnimationEnd(Animator animation) {
267+
super.onAnimationEnd(animation);
268+
try {
269+
decorView.removeView(view);
270+
} catch (Exception e) {
271+
e.printStackTrace();
272+
}
273+
}
274+
});
275+
anim.start();
276+
} catch (Exception e) {
277+
e.printStackTrace();
261278
try {
262279
decorView.removeView(view);
263-
} catch (Exception e) {
264-
e.printStackTrace();
280+
} catch (Exception e1) {
281+
e1.printStackTrace();
265282
}
266283
}
267-
});
268-
anim.start();
269-
}
270-
}, 1000);
284+
}
285+
}, 1000);
286+
287+
}
288+
});
289+
anim.start();
290+
} catch (Exception e) {
291+
e.printStackTrace();
292+
doOnEnd();
293+
}
294+
}
271295

272-
}
273-
});
274-
anim.start();
296+
private void doOnEnd() {
297+
mOnAnimationEndListener.onAnimationEnd();
275298
}
276299
}
277300

0 commit comments

Comments
 (0)