public void onTimeUpdate(TimeAnimator timeAnimator, long totalTime, long deltaTime) { if (!this.mStarted.booleanValue()) { this.mStarted = Boolean.valueOf(true); if (this.mAnimationListener != null) { this.mAnimationListener.onAnimationStart(null); } } if (timeAnimator.isRunning()) { if (isReallyClose().booleanValue()) { stepFast(); } else { step(); } if (isFinished().booleanValue() && this.mAnimationListener != null) { this.mAnimationListener.onAnimationEnd(null); } } }
void init() { this.handler = new Handler(Looper.getMainLooper()); this.mAnimationCallback = new TimeListener() { public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) { PanelView.this.animationTick(deltaTime); } }; this.mStopAnimator = new Runnable() { public void run() { if (PanelView.this.mTimeAnimator != null && PanelView.this.mTimeAnimator.isStarted()) { PanelView.this.LOG("Stop Animator : stopping", new Object[0]); PanelView.this.mTimeAnimator.end(); PanelView.this.mRubberbanding = false; PanelView.this.mClosing = false; } } }; this.mTimeAnimator = new TimeAnimator(); this.mTimeAnimator.setTimeListener(this.mAnimationCallback); }
@Override public void onTimeUpdate(TimeAnimator animation, long totalTimeMs, long deltaTimeMs) { // Cap progress bar animation frame time so that it doesn't jump too much even when // the animation is janky. float progress = mAnimationLogic.updateProgress(mTargetProgress, Math.min(deltaTimeMs, PROGRESS_FRAME_TIME_CAP_MS) * 0.001f, getWidth()); progress = Math.max(progress, 0); ToolbarProgressBar.super.setProgress(progress); if (mAnimatingView != null) { int width = Math.abs( getDrawable().getBounds().right - getDrawable().getBounds().left); mAnimatingView.update(progress * width); } if (getProgress() == mTargetProgress) { if (!mIsStarted) postOnAnimationDelayed(mHideRunnable, mHidingDelayMs); mProgressAnimator.end(); return; } }
@Override public void onTimeUpdate(TimeAnimator animation, long totalTimeMs, long deltaTimeMs) { // Cap progress bar animation frame time so that it doesn't jump too much even when // the animation is janky. ToolbarProgressBar.super.setProgress(mAnimationLogic.updateProgress( mTargetProgress, Math.max(deltaTimeMs, PROGRESS_FRAME_TIME_CAP_MS) * 0.001f, getWidth())); if (getProgress() == mTargetProgress) { if (mTargetProgress == 1.0f && !mIsStarted) { postOnAnimationDelayed(mHideRunnable, mHidingDelayMs); } mProgressAnimator.end(); return; } }
private Runnable createJBRunnable() { // On JB, we rely on TimeAnimator to send events tied with vsync. return new Runnable() { @Override public void run() { mTimeAnimator = new TimeAnimator(); mTimeAnimator.setTimeListener(new TimeListener() { @Override public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) { if (!sendEvent(mDownTime + totalTime)) { mTimeAnimator.end(); } } }); mTimeAnimator.start(); } }; }
private Runnable createJBRunnable() { // On JB, we rely on TimeAnimator to send events tied with vsync. return new Runnable() { @Override public void run() { mTimeAnimator = new TimeAnimator(); mTimeAnimator.setTimeListener(new TimeListener() { @Override public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) { if (!sendEvent(mStartTime + totalTime)) { mTimeAnimator.end(); } } }); mTimeAnimator.start(); } }; }
@Override public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) { if (mFrameTimesCount == mFrameTimesMs.length) { mAnimator.end(); cleanUp(); Log.w(TAG, "Animation frame time recording reached the maximum number. It's either" + "the animation took too long or recording end is not called."); return; } // deltaTime is 0 for the first frame. if (deltaTime > 0) { mFrameTimesMs[mFrameTimesCount++] = deltaTime; } }
public void onTimeUpdate(TimeAnimator timeAnimator, long totalTime, long deltaTime) { if (!timeAnimator.isRunning()) { return; } if (((float) totalTime) > this.mDuration) { timeAnimator.cancel(); if (this.mAnimationListener != null) { this.mAnimationListener.onAnimationEnd(null); return; } return; } step((float) totalTime); }
AppMenuDragHelper(Activity activity, AppMenu appMenu, int itemRowHeight) { mActivity = activity; mAppMenu = appMenu; mItemRowHeight = itemRowHeight; Resources res = mActivity.getResources(); mAutoScrollFullVelocity = res.getDimensionPixelSize(R.dimen.auto_scroll_full_velocity); // If user is dragging and the popup ListView is too big to display at once, // mDragScrolling animator scrolls mPopup.getListView() automatically depending on // the user's touch position. mDragScrolling.setTimeListener(new TimeAnimator.TimeListener() { @Override public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) { ListPopupWindow popup = mAppMenu.getPopup(); if (popup == null || popup.getListView() == null) return; // We keep both mDragScrollOffset and mDragScrollOffsetRounded because // the actual scrolling is by the rounded value but at the same time we also // want to keep the precise scroll value in float. mDragScrollOffset += (deltaTime * 0.001f) * mDragScrollingVelocity; int diff = Math.round(mDragScrollOffset - mDragScrollOffsetRounded); mDragScrollOffsetRounded += diff; popup.getListView().smoothScrollBy(diff, 0); // Force touch move event to highlight items correctly for the scrolled position. if (!Float.isNaN(mLastTouchX) && !Float.isNaN(mLastTouchY)) { menuItemAction(Math.round(mLastTouchX), Math.round(mLastTouchY), ITEM_ACTION_HIGHLIGHT); } } }); // We use medium timeout, the average of tap and long press timeouts. This is consistent // with ListPopupWindow#ForwardingListener implementation. mTapTimeout = (ViewConfiguration.getTapTimeout() + ViewConfiguration.getLongPressTimeout()) / 2; mScaledTouchSlop = ViewConfiguration.get(activity).getScaledTouchSlop(); }
/** * Every TimeAnimator frame, nudge each bouncing view along. */ public void onTimeUpdate(TimeAnimator animation, long elapsed, long dt_ms) { final float dt = dt_ms / 1000f; // seconds for (int i = 0; i < getChildCount(); i++) { final View view = getChildAt(i); final PointF v = (PointF) view.getTag(); // step view for velocity * time view.setX(view.getX() + v.x * dt); view.setY(view.getY() + v.y * dt); // handle reflections final float l = view.getX(); final float t = view.getY(); final float r = l + view.getWidth(); final float b = t + view.getHeight(); boolean flipX = false, flipY = false; if (r > mWidth) { view.setX(view.getX() - 2 * (r - mWidth)); flipX = true; } else if (l < 0) { view.setX(-l); flipX = true; } if (b > mHeight) { view.setY(view.getY() - 2 * (b - mHeight)); flipY = true; } else if (t < 0) { view.setY(-t); flipY = true; } if (flipX) v.x *= -1; if (flipY) v.y *= -1; } }
public void onTimeUpdate(TimeAnimator animation, long elapsed, long dt_ms) { final float dt = dt_ms / 1000f; // seconds for (int i=0; i<getChildCount(); i++) { final View view = getChildAt(i); final PointF v = (PointF) view.getTag(); // step view for velocity * time view.setX(view.getX() + v.x * dt); view.setY(view.getY() + v.y * dt); // handle reflections final float l = view.getX(); final float t = view.getY(); final float r = l + view.getWidth(); final float b = t + view.getHeight(); boolean flipX = false, flipY = false; if (r > mWidth) { view.setX(view.getX() - 2 * (r - mWidth)); flipX = true; } else if (l < 0) { view.setX(-l); flipX = true; } if (b > mHeight) { view.setY(view.getY() - 2 * (b - mHeight)); flipY = true; } else if (t < 0) { view.setY(-t); flipY = true; } if (flipX) v.x *= -1; if (flipY) v.y *= -1; } }
private void init(Context context) { animator = new TimeAnimator(); animator.setTimeListener(this); paint = new Paint(); paint.setColor(Color.WHITE); density = getResources().getDisplayMetrics().density; path = new Path(); pathMeasure = new PathMeasure(); position = new PointF(); velocity = new PointF(); }
@Override public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) { float fraction; if (totalTime >= mDuration) { fraction = 1; mAnimator.end(); } else { fraction = (float) (totalTime / (double) mDuration); } if (mInterpolator != null) { fraction = mInterpolator.getInterpolation(fraction); } setFocusLevel(mFocusLevelStart + fraction * mFocusLevelDelta); }
public SystemClockManager(SystemClockListener listener, long resolution) { mListener = listener; mResolution = resolution; mAnimator = new TimeAnimator(); mAnimator.setTimeListener(this); }
@Override public void onTimeUpdate(TimeAnimator timeAnimator, long l, long l2) { long now = l / mResolution; if (now != mLast) { mLast = now; mListener.onTimeChanged(System.currentTimeMillis()); } }
public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) { double currentFps; if (deltaTime != 0) currentFps = 1000.0 / (double) deltaTime; else currentFps = 0.9 * fps; if (fps < 0.0) fps = currentFps; else fps = 0.9 * fps + 0.1 * currentFps; textView.setText(String.format("fps: %.2f", fps)); }
@Override @SuppressLint("NewApi") protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.property_animations09); if (android.os.Build.VERSION.SDK_INT >= 19) { ImageView someImage = (ImageView) findViewById(R.id.some_image); ObjectAnimator rotateAnim = ObjectAnimator.ofFloat(someImage, "rotation", 0, 360); rotateAnim.setDuration(1000); rotateAnim.setRepeatCount(5); rotateAnim.setRepeatMode(ObjectAnimator.RESTART); fpsText = (TextView) findViewById(R.id.fps_text); FpsTimeListener listener = new FpsTimeListener(fpsText); final TimeAnimator timeAnim = new TimeAnimator(); timeAnim.setTimeListener(listener); anim = new AnimatorSet(); anim.play(rotateAnim).with(timeAnim); rotateAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { timeAnim.end(); } }); } }
private void animationTick(long dtms) { boolean z = true; if (!this.mTimeAnimator.isStarted()) { this.mTimeAnimator = new TimeAnimator(); this.mTimeAnimator.setTimeListener(this.mAnimationCallback); if (this.mPeekAnimator != null) { this.mPeekAnimator.cancel(); } this.mTimeAnimator.start(); boolean z2 = this.mRubberbandingEnabled && this.mExpandedHeight > getFullHeight() && this.mVel >= (-this.mFlingGestureMinDistPx); this.mRubberbanding = z2; if (this.mRubberbanding) { this.mClosing = true; } else if (this.mVel == 0.0f) { if (this.mFinalTouchY / getFullHeight() >= 0.5f) { z = false; } this.mClosing = z; } else { if (this.mExpandedHeight <= 0.0f || this.mVel >= 0.0f) { z = false; } this.mClosing = z; } } else if (dtms > 0) { float dt = ((float) dtms) * 0.001f; float fh = getFullHeight(); this.mAccel = this.mClosing ? -this.mCollapseAccelPx : this.mExpandAccelPx; this.mVel += this.mAccel * dt; if (false) { if (this.mClosing && this.mVel > (-this.mBrakingSpeedPx)) { this.mVel = -this.mBrakingSpeedPx; } else if (!this.mClosing && this.mVel < this.mBrakingSpeedPx) { this.mVel = this.mBrakingSpeedPx; } } else if (this.mClosing && this.mVel > (-this.mFlingCollapseMinVelocityPx)) { this.mVel = -this.mFlingCollapseMinVelocityPx; } else if (!this.mClosing && this.mVel > this.mFlingGestureMaxOutputVelocityPx) { this.mVel = this.mFlingGestureMaxOutputVelocityPx; } float h = this.mExpandedHeight + (this.mVel * dt); if (this.mRubberbanding && h < fh) { h = fh; } setExpandedHeightInternal(h); this.mBar.panelExpansionChanged(this, this.mExpandedFraction); if (this.mVel == 0.0f || ((this.mClosing && getTargetExpandedHeight() == 0) || ((this.mRubberbanding || !this.mClosing) && this.mExpandedHeight == fh))) { this.handler.post(this.mStopAnimator); if (this.mClosing && getTargetExpandedHeight() == 0) { this.handler.post(this.closePanelsRunnable); } } } else { Log.v(TAG, "animationTick called with dtms=" + dtms + "; nothing to do (h=" + this.mExpandedHeight + " v=" + this.mVel + ")"); } }
public Bouncer(Context context, AttributeSet attrs, int flags) { super(context, attrs, flags); mAnimator = new TimeAnimator(); mAnimator.setTimeListener(this); }
@Override public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) { if (mSelectAnimator.isRunning()) { updateSelect(totalTime, deltaTime); } }
@Override public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) { final float dt = deltaTime / 1000f; // seconds position.x += velocity.x * dt; position.y += velocity.y * dt; bound(); path.lineTo(position.x, position.y); invalidate(); }
@Override public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) { invalidate(); }