use of android.animation.ValueAnimator.AnimatorUpdateListener in project XobotOS by xamarin.
the class Tweener method to.
public static Tweener to(Object object, long duration, Object... vars) {
long delay = 0;
AnimatorUpdateListener updateListener = null;
AnimatorListener listener = null;
TimeInterpolator interpolator = null;
// Iterate through arguments and discover properties to animate
ArrayList<PropertyValuesHolder> props = new ArrayList<PropertyValuesHolder>(vars.length / 2);
for (int i = 0; i < vars.length; i += 2) {
if (!(vars[i] instanceof String)) {
throw new IllegalArgumentException("Key must be a string: " + vars[i]);
}
String key = (String) vars[i];
Object value = vars[i + 1];
if ("simultaneousTween".equals(key)) {
// TODO
} else if ("ease".equals(key)) {
// TODO: multiple interpolators?
interpolator = (TimeInterpolator) value;
} else if ("onUpdate".equals(key) || "onUpdateListener".equals(key)) {
updateListener = (AnimatorUpdateListener) value;
} else if ("onComplete".equals(key) || "onCompleteListener".equals(key)) {
listener = (AnimatorListener) value;
} else if ("delay".equals(key)) {
delay = ((Number) value).longValue();
} else if ("syncWith".equals(key)) {
// TODO
} else if (value instanceof float[]) {
props.add(PropertyValuesHolder.ofFloat(key, ((float[]) value)[0], ((float[]) value)[1]));
} else if (value instanceof Number) {
float floatValue = ((Number) value).floatValue();
props.add(PropertyValuesHolder.ofFloat(key, floatValue));
} else {
throw new IllegalArgumentException("Bad argument for key \"" + key + "\" with value " + value.getClass());
}
}
// Re-use existing tween, if present
Tweener tween = sTweens.get(object);
ObjectAnimator anim = null;
if (tween == null) {
anim = ObjectAnimator.ofPropertyValuesHolder(object, props.toArray(new PropertyValuesHolder[props.size()]));
tween = new Tweener(anim);
sTweens.put(object, tween);
if (DEBUG)
Log.v(TAG, "Added new Tweener " + tween);
} else {
anim = sTweens.get(object).animator;
// Cancel all animators for given object
replace(props, object);
}
if (interpolator != null) {
anim.setInterpolator(interpolator);
}
// Update animation with properties discovered in loop above
anim.setStartDelay(delay);
anim.setDuration(duration);
if (updateListener != null) {
// There should be only one
anim.removeAllUpdateListeners();
anim.addUpdateListener(updateListener);
}
if (listener != null) {
// There should be only one.
anim.removeAllListeners();
anim.addListener(listener);
}
anim.addListener(mCleanupListener);
anim.start();
return tween;
}
use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by AOSPA.
the class GlobalScreenshot method createScreenshotDropInAnimation.
private ValueAnimator createScreenshotDropInAnimation() {
final float flashPeakDurationPct = ((float) (SCREENSHOT_FLASH_TO_PEAK_DURATION) / SCREENSHOT_DROP_IN_DURATION);
final float flashDurationPct = 2f * flashPeakDurationPct;
final Interpolator flashAlphaInterpolator = new Interpolator() {
@Override
public float getInterpolation(float x) {
// Flash the flash view in and out quickly
if (x <= flashDurationPct) {
return (float) Math.sin(Math.PI * (x / flashDurationPct));
}
return 0;
}
};
final Interpolator scaleInterpolator = new Interpolator() {
@Override
public float getInterpolation(float x) {
// We start scaling when the flash is at it's peak
if (x < flashPeakDurationPct) {
return 0;
}
return (x - flashDurationPct) / (1f - flashDurationPct);
}
};
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
anim.setDuration(SCREENSHOT_DROP_IN_DURATION);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
mBackgroundView.setAlpha(0f);
mBackgroundView.setVisibility(View.VISIBLE);
mScreenshotView.setAlpha(0f);
mScreenshotView.setTranslationX(0f);
mScreenshotView.setTranslationY(0f);
mScreenshotView.setScaleX(SCREENSHOT_SCALE + mBgPaddingScale);
mScreenshotView.setScaleY(SCREENSHOT_SCALE + mBgPaddingScale);
mScreenshotView.setVisibility(View.VISIBLE);
mScreenshotFlash.setAlpha(0f);
mScreenshotFlash.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(android.animation.Animator animation) {
mScreenshotFlash.setVisibility(View.GONE);
}
});
anim.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float t = (Float) animation.getAnimatedValue();
float scaleT = (SCREENSHOT_SCALE + mBgPaddingScale) - scaleInterpolator.getInterpolation(t) * (SCREENSHOT_SCALE - SCREENSHOT_DROP_IN_MIN_SCALE);
mBackgroundView.setAlpha(scaleInterpolator.getInterpolation(t) * BACKGROUND_ALPHA);
mScreenshotView.setAlpha(t);
mScreenshotView.setScaleX(scaleT);
mScreenshotView.setScaleY(scaleT);
mScreenshotFlash.setAlpha(flashAlphaInterpolator.getInterpolation(t));
}
});
return anim;
}
use of android.animation.ValueAnimator.AnimatorUpdateListener in project UltimateAndroid by cymcsg.
the class FlipView method peak.
private void peak(boolean next, boolean once) {
final float baseFlipDistance = mCurrentPageIndex * FLIP_DISTANCE_PER_PAGE;
if (next) {
mPeakAnim = ValueAnimator.ofFloat(baseFlipDistance, baseFlipDistance + FLIP_DISTANCE_PER_PAGE / 4);
} else {
mPeakAnim = ValueAnimator.ofFloat(baseFlipDistance, baseFlipDistance - FLIP_DISTANCE_PER_PAGE / 4);
}
mPeakAnim.setInterpolator(mPeakInterpolator);
mPeakAnim.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
setFlipDistance((Float) animation.getAnimatedValue());
}
});
mPeakAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
endPeak();
}
});
mPeakAnim.setDuration(PEAK_ANIM_DURATION);
mPeakAnim.setRepeatMode(ValueAnimator.REVERSE);
mPeakAnim.setRepeatCount(once ? 1 : ValueAnimator.INFINITE);
mPeakAnim.start();
}
use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by ResurrectionRemix.
the class GlobalScreenshot method createScreenshotDropInAnimation.
private ValueAnimator createScreenshotDropInAnimation() {
final float flashPeakDurationPct = ((float) (SCREENSHOT_FLASH_TO_PEAK_DURATION) / SCREENSHOT_DROP_IN_DURATION);
final float flashDurationPct = 2f * flashPeakDurationPct;
final Interpolator flashAlphaInterpolator = new Interpolator() {
@Override
public float getInterpolation(float x) {
// Flash the flash view in and out quickly
if (x <= flashDurationPct) {
return (float) Math.sin(Math.PI * (x / flashDurationPct));
}
return 0;
}
};
final Interpolator scaleInterpolator = new Interpolator() {
@Override
public float getInterpolation(float x) {
// We start scaling when the flash is at it's peak
if (x < flashPeakDurationPct) {
return 0;
}
return (x - flashDurationPct) / (1f - flashDurationPct);
}
};
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
anim.setDuration(SCREENSHOT_DROP_IN_DURATION);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
mBackgroundView.setAlpha(0f);
mBackgroundView.setVisibility(View.VISIBLE);
mScreenshotView.setAlpha(0f);
mScreenshotView.setTranslationX(0f);
mScreenshotView.setTranslationY(0f);
mScreenshotView.setScaleX(SCREENSHOT_SCALE + mBgPaddingScale);
mScreenshotView.setScaleY(SCREENSHOT_SCALE + mBgPaddingScale);
mScreenshotView.setRotation(5.0f);
mScreenshotView.setVisibility(View.VISIBLE);
mScreenshotFlash.setAlpha(0f);
mScreenshotFlash.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(android.animation.Animator animation) {
mScreenshotFlash.setVisibility(View.GONE);
}
});
anim.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float t = (Float) animation.getAnimatedValue();
float scaleT = (SCREENSHOT_SCALE + mBgPaddingScale) - scaleInterpolator.getInterpolation(t) * (SCREENSHOT_SCALE - SCREENSHOT_DROP_IN_MIN_SCALE);
mBackgroundView.setAlpha(scaleInterpolator.getInterpolation(t) * BACKGROUND_ALPHA);
mScreenshotView.setAlpha(t);
mScreenshotView.setScaleX(scaleT);
mScreenshotView.setScaleY(scaleT);
mScreenshotFlash.setAlpha(flashAlphaInterpolator.getInterpolation(t));
}
});
return anim;
}
use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by ResurrectionRemix.
the class VolumeDialogMotion method startDismiss.
public void startDismiss(final Runnable onComplete) {
if (D.BUG)
Log.d(TAG, "startDismiss");
if (mDismissing)
return;
setDismissing(true);
if (mShowing) {
mDialogView.animate().cancel();
if (mContentsPositionAnimator != null) {
mContentsPositionAnimator.cancel();
}
mContents.animate().cancel();
if (mChevronPositionAnimator != null) {
mChevronPositionAnimator.cancel();
}
mChevron.animate().cancel();
setShowing(false);
}
mDialogView.animate().translationY(-mDialogView.getHeight()).setDuration(scaledDuration(250)).setInterpolator(new LogAccelerateInterpolator()).setUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mContents.setTranslationY(-mDialogView.getTranslationY());
final int posY = chevronPosY();
mChevron.setTranslationY(posY + -mDialogView.getTranslationY());
}
}).setListener(new AnimatorListenerAdapter() {
private boolean mCancelled;
@Override
public void onAnimationEnd(Animator animation) {
if (mCancelled)
return;
if (D.BUG)
Log.d(TAG, "dismiss.onAnimationEnd");
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
if (D.BUG)
Log.d(TAG, "mDialog.dismiss()");
mDialog.dismiss();
onComplete.run();
setDismissing(false);
}
}, PRE_DISMISS_DELAY);
}
@Override
public void onAnimationCancel(Animator animation) {
if (D.BUG)
Log.d(TAG, "dismiss.onAnimationCancel");
mCancelled = true;
}
}).start();
}
Aggregations