use of android.animation.AnimatorListenerAdapter in project GeekNews by codeestX.
the class CircularAnimUtil method hide.
/**
* 由满向中间收缩,直到隐藏。
*/
@SuppressLint("NewApi")
public static void hide(final View myView, float endRadius, long durationMills) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
myView.setVisibility(View.INVISIBLE);
return;
}
int cx = (myView.getLeft() + myView.getRight()) / 2;
int cy = (myView.getTop() + myView.getBottom()) / 2;
int w = myView.getWidth();
int h = myView.getHeight();
// 勾股定理 & 进一法
int initialRadius = (int) Math.sqrt(w * w + h * h) + 1;
Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, endRadius);
anim.setDuration(durationMills);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
myView.setVisibility(View.INVISIBLE);
}
});
anim.start();
}
use of android.animation.AnimatorListenerAdapter in project GeekNews by codeestX.
the class CircularAnimUtil method startActivityForResult.
/**
* 从指定View开始向四周伸张(伸张颜色或图片为colorOrImageRes), 然后进入另一个Activity,
* 返回至 @thisActivity 后显示收缩动画。
*/
@SuppressLint("NewApi")
public static void startActivityForResult(final Activity thisActivity, final Intent intent, final Integer requestCode, final Bundle bundle, final View triggerView, int colorOrImageRes, long durationMills) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
thisActivity.startActivity(intent);
return;
}
int[] location = new int[2];
triggerView.getLocationInWindow(location);
final int cx = location[0] + triggerView.getWidth() / 2;
final int cy = location[1] + triggerView.getHeight() / 2;
final ImageView view = new ImageView(thisActivity);
view.setScaleType(ImageView.ScaleType.CENTER_CROP);
view.setImageResource(colorOrImageRes);
final ViewGroup decorView = (ViewGroup) thisActivity.getWindow().getDecorView();
int w = decorView.getWidth();
int h = decorView.getHeight();
decorView.addView(view, w, h);
// 计算中心点至view边界的最大距离
int maxW = Math.max(cx, w - cx);
int maxH = Math.max(cy, h - cy);
final int finalRadius = (int) Math.sqrt(maxW * maxW + maxH * maxH) + 1;
Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
int maxRadius = (int) Math.sqrt(w * w + h * h) + 1;
// 若使用默认时长,则需要根据水波扩散的距离来计算实际时间
if (durationMills == PERFECT_MILLS) {
// 算出实际边距与最大边距的比率
double rate = 1d * finalRadius / maxRadius;
// 水波扩散的距离与扩散时间成正比
durationMills = (long) (PERFECT_MILLS * rate);
}
final long finalDuration = durationMills;
anim.setDuration(finalDuration);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
if (requestCode == null)
thisActivity.startActivity(intent);
else if (bundle == null)
thisActivity.startActivityForResult(intent, requestCode);
else
thisActivity.startActivityForResult(intent, requestCode, bundle);
// 默认渐隐过渡动画.
thisActivity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
// 默认显示返回至当前Activity的动画.
triggerView.postDelayed(new Runnable() {
@Override
public void run() {
Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, finalRadius, 0);
anim.setDuration(finalDuration);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
try {
decorView.removeView(view);
} catch (Exception e) {
e.printStackTrace();
}
}
});
anim.start();
}
}, 1000);
}
});
anim.start();
}
use of android.animation.AnimatorListenerAdapter in project ENViews by codeestX.
the class ENDownloadView method downloadAnim.
private void downloadAnim() {
ValueAnimator downloadAnim = ValueAnimator.ofFloat(1.f, 100.f);
downloadAnim.setDuration(mDownloadTime);
downloadAnim.setInterpolator(new LinearInterpolator());
downloadAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
mFraction = valueAnimator.getAnimatedFraction();
if (mUnit != DownloadUnit.NONE && mTotalSize > 0)
mCurrentSize = mFraction * mTotalSize;
invalidate();
}
});
downloadAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mCurrentState = STATE_END;
endAnim();
}
});
downloadAnim.start();
}
use of android.animation.AnimatorListenerAdapter in project ENViews by codeestX.
the class ENDownloadView method endAnim.
private void endAnim() {
ValueAnimator endAnim = ValueAnimator.ofFloat(1.f, 100.f);
endAnim.setDuration(700);
endAnim.setInterpolator(new OvershootInterpolator());
endAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
mFraction = valueAnimator.getAnimatedFraction();
invalidate();
}
});
endAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mFraction = 0;
mCurrentState = STATE_RESET;
if (onDownloadStateListener != null) {
onDownloadStateListener.onDownloadFinish();
}
}
});
endAnim.start();
}
use of android.animation.AnimatorListenerAdapter in project ENViews by codeestX.
the class ENSearchView method start.
public void start() {
if (mCurrentState == STATE_SEARCHING) {
return;
}
mCurrentState = STATE_SEARCHING;
ValueAnimator valueAnim = ValueAnimator.ofFloat(1.f, 100.f);
valueAnim.setDuration(mDuration);
valueAnim.setInterpolator(new LinearInterpolator());
valueAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
mFraction = valueAnimator.getAnimatedFraction();
invalidate();
}
});
valueAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mCurrentState = STATE_WAIT;
}
});
valueAnim.start();
}
Aggregations