use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by ParanoidAndroid.
the class PagedView method onFlingToDelete.
public void onFlingToDelete(PointF vel) {
final long startTime = AnimationUtils.currentAnimationTimeMillis();
// NOTE: Because it takes time for the first frame of animation to actually be
// called and we expect the animation to be a continuation of the fling, we have
// to account for the time that has elapsed since the fling finished. And since
// we don't have a startDelay, we will always get call to update when we call
// start() (which we want to ignore).
final TimeInterpolator tInterpolator = new TimeInterpolator() {
private int mCount = -1;
private long mStartTime;
private float mOffset;
/* Anonymous inner class ctor */
{
mStartTime = startTime;
}
@Override
public float getInterpolation(float t) {
if (mCount < 0) {
mCount++;
} else if (mCount == 0) {
mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / FLING_TO_DELETE_FADE_OUT_DURATION);
mCount++;
}
return Math.min(1f, mOffset + t);
}
};
final Rect from = new Rect();
final View dragView = mDragView;
from.left = (int) dragView.getTranslationX();
from.top = (int) dragView.getTranslationY();
AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime, FLING_TO_DELETE_FRICTION);
final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView);
// Create and start the animation
ValueAnimator mDropAnim = new ValueAnimator();
mDropAnim.setInterpolator(tInterpolator);
mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION);
mDropAnim.setFloatValues(0f, 1f);
mDropAnim.addUpdateListener(updateCb);
mDropAnim.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator animation) {
onAnimationEndRunnable.run();
}
});
mDropAnim.start();
mDeferringForDelete = true;
}
use of android.animation.ValueAnimator.AnimatorUpdateListener in project MPAndroidChart by PhilJay.
the class Chart method init.
/**
* initialize all paints and stuff
*/
protected void init() {
setWillNotDraw(false);
if (android.os.Build.VERSION.SDK_INT < 11)
mAnimator = new ChartAnimator();
else
mAnimator = new ChartAnimator(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
// ViewCompat.postInvalidateOnAnimation(Chart.this);
postInvalidate();
}
});
// initialize the utils
Utils.init(getContext());
mMaxHighlightDistance = Utils.convertDpToPixel(500f);
mDescription = new Description();
mLegend = new Legend();
mLegendRenderer = new LegendRenderer(mViewPortHandler, mLegend);
mXAxis = new XAxis();
mDescPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mInfoPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
// orange
mInfoPaint.setColor(Color.rgb(247, 189, 51));
mInfoPaint.setTextAlign(Align.CENTER);
mInfoPaint.setTextSize(Utils.convertDpToPixel(12f));
if (mLogEnabled)
Log.i("", "Chart.init()");
}
use of android.animation.ValueAnimator.AnimatorUpdateListener in project Fairphone by Kwamecorp.
the class DeleteDropTarget method createFlingToTrashAnimatorListener.
/**
* Creates an animation from the current drag view to the delete trash icon.
*/
private AnimatorUpdateListener createFlingToTrashAnimatorListener(final DragLayer dragLayer, DragObject d, PointF vel, ViewConfiguration config) {
final Rect to = getIconRect(d.dragView.getMeasuredWidth(), d.dragView.getMeasuredHeight(), mCurrentDrawable.getIntrinsicWidth(), mCurrentDrawable.getIntrinsicHeight());
final Rect from = new Rect();
dragLayer.getViewRectRelativeToSelf(d.dragView, from);
// Calculate how far along the velocity vector we should put the intermediate point on
// the bezier curve
float velocity = Math.abs(vel.length());
float vp = Math.min(1f, velocity / (config.getScaledMaximumFlingVelocity() / 2f));
int offsetY = (int) (-from.top * vp);
int offsetX = (int) (offsetY / (vel.y / vel.x));
// intermediate t/l
final float y2 = from.top + offsetY;
final float x2 = from.left + offsetX;
// drag view t/l
final float x1 = from.left;
final float y1 = from.top;
// delete target t/l
final float x3 = to.left;
final float y3 = to.top;
final TimeInterpolator scaleAlphaInterpolator = new TimeInterpolator() {
@Override
public float getInterpolation(float t) {
return t * t * t * t * t * t * t * t;
}
};
return new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
final DragView dragView = (DragView) dragLayer.getAnimatedView();
float t = ((Float) animation.getAnimatedValue()).floatValue();
float tp = scaleAlphaInterpolator.getInterpolation(t);
float initialScale = dragView.getInitialScale();
float finalAlpha = 0.5f;
float scale = dragView.getScaleX();
float x1o = ((1f - scale) * dragView.getMeasuredWidth()) / 2f;
float y1o = ((1f - scale) * dragView.getMeasuredHeight()) / 2f;
float x = (1f - t) * (1f - t) * (x1 - x1o) + 2 * (1f - t) * t * (x2 - x1o) + (t * t) * x3;
float y = (1f - t) * (1f - t) * (y1 - y1o) + 2 * (1f - t) * t * (y2 - x1o) + (t * t) * y3;
dragView.setTranslationX(x);
dragView.setTranslationY(y);
dragView.setScaleX(initialScale * (1f - tp));
dragView.setScaleY(initialScale * (1f - tp));
dragView.setAlpha(finalAlpha + (1f - finalAlpha) * (1f - tp));
}
};
}
use of android.animation.ValueAnimator.AnimatorUpdateListener in project Fairphone by Kwamecorp.
the class CellLayout method animateChildToPosition.
public boolean animateChildToPosition(final View child, int cellX, int cellY, int duration, int delay, boolean permanent, boolean adjustOccupied) {
ShortcutAndWidgetContainer clc = getShortcutsAndWidgets();
boolean[][] occupied = mOccupied;
if (!permanent) {
occupied = mTmpOccupied;
}
if (clc.indexOfChild(child) != -1) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final ItemInfo info = (ItemInfo) child.getTag();
// We cancel any existing animations
if (mReorderAnimators.containsKey(lp)) {
mReorderAnimators.get(lp).cancel();
mReorderAnimators.remove(lp);
}
final int oldX = lp.x;
final int oldY = lp.y;
if (adjustOccupied) {
occupied[lp.cellX][lp.cellY] = false;
occupied[cellX][cellY] = true;
}
lp.isLockedToGrid = true;
if (permanent) {
lp.cellX = info.cellX = cellX;
lp.cellY = info.cellY = cellY;
} else {
lp.tmpCellX = cellX;
lp.tmpCellY = cellY;
}
clc.setupLp(lp);
lp.isLockedToGrid = false;
final int newX = lp.x;
final int newY = lp.y;
lp.x = oldX;
lp.y = oldY;
// Exit early if we're not actually moving the view
if (oldX == newX && oldY == newY) {
lp.isLockedToGrid = true;
return true;
}
ValueAnimator va = LauncherAnimUtils.ofFloat(0f, 1f);
va.setDuration(duration);
mReorderAnimators.put(lp, va);
va.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float r = ((Float) animation.getAnimatedValue()).floatValue();
lp.x = (int) ((1 - r) * oldX + r * newX);
lp.y = (int) ((1 - r) * oldY + r * newY);
child.requestLayout();
}
});
va.addListener(new AnimatorListenerAdapter() {
boolean cancelled = false;
public void onAnimationEnd(Animator animation) {
// place just yet.
if (!cancelled) {
lp.isLockedToGrid = true;
child.requestLayout();
}
if (mReorderAnimators.containsKey(lp)) {
mReorderAnimators.remove(lp);
}
}
public void onAnimationCancel(Animator animation) {
cancelled = true;
}
});
va.setStartDelay(delay);
va.start();
return true;
}
return false;
}
use of android.animation.ValueAnimator.AnimatorUpdateListener in project Fairphone by Kwamecorp.
the class DragLayer method fadeOutDragView.
private void fadeOutDragView() {
mFadeOutAnim = new ValueAnimator();
mFadeOutAnim.setDuration(150);
mFadeOutAnim.setFloatValues(0f, 1f);
mFadeOutAnim.removeAllUpdateListeners();
mFadeOutAnim.addUpdateListener(new AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
final float percent = (Float) animation.getAnimatedValue();
float alpha = 1 - percent;
mDropView.setAlpha(alpha);
}
});
mFadeOutAnim.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator animation) {
if (mDropView != null) {
mDragController.onDeferredEndDrag(mDropView);
}
mDropView = null;
invalidate();
}
});
mFadeOutAnim.start();
}
Aggregations