/** * This method takes some view and the values by which its top and bottom bounds should be changed * by. Given these params, an animation which will animate these bound changes is created and * returned. */ private Animator getAnimation(final View view, float translateTop, float translateBottom) { int top = view.getTop(); int bottom = view.getBottom(); int endTop = (int) (top + translateTop); int endBottom = (int) (bottom + translateBottom); PropertyValuesHolder translationTop = PropertyValuesHolder.ofInt("top", top, endTop); PropertyValuesHolder translationBottom = PropertyValuesHolder.ofInt("bottom", bottom, endBottom); return ObjectAnimator.ofPropertyValuesHolder(view, translationTop, translationBottom); }
public void animateClosed() { if (!(getParent() instanceof DragLayer)) return; ObjectAnimator oa; if (mMode == PARTIAL_GROW) { PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f); PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f); oa = ObjectAnimator.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); } else { DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); PropertyValuesHolder width = PropertyValuesHolder.ofInt("width", mIconRect.width()); PropertyValuesHolder height = PropertyValuesHolder.ofInt("height", mIconRect.height()); PropertyValuesHolder x = PropertyValuesHolder.ofInt("x", mIconRect.left); PropertyValuesHolder y = PropertyValuesHolder.ofInt("y", mIconRect.top); oa = ObjectAnimator.ofPropertyValuesHolder(lp, width, height, x, y); oa.addUpdateListener( new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { requestLayout(); } }); PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f); ObjectAnimator alphaOa = ObjectAnimator.ofPropertyValuesHolder(mContent, alpha); alphaOa.setDuration(mExpandDuration); alphaOa.setInterpolator(new DecelerateInterpolator(2.0f)); alphaOa.start(); } oa.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { onCloseComplete(); mState = STATE_SMALL; } @Override public void onAnimationStart(Animator animation) { sendCustomAccessibilityEvent( AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, getContext().getString(R.string.folder_closed)); mState = STATE_ANIMATING; } }); oa.setDuration(mExpandDuration); oa.start(); }
public void testOfPropertyValuesHolder() throws Throwable { Object object = mActivity.view.newBall; String propertyName = "backgroundColor"; int startColor = mActivity.view.RED; int endColor = mActivity.view.BLUE; int values[] = {startColor, endColor}; ArgbEvaluator evaluator = new ArgbEvaluator(); PropertyValuesHolder propertyValuesHolder = PropertyValuesHolder.ofInt(propertyName, values); ObjectAnimator colorAnimator = ObjectAnimator.ofPropertyValuesHolder(object, propertyValuesHolder); colorAnimator.setDuration(1000); colorAnimator.setRepeatCount(1); colorAnimator.setRepeatMode(ValueAnimator.REVERSE); colorAnimator.start(); startAnimation(mObjectAnimator, colorAnimator); Thread.sleep(100); Integer i = (Integer) colorAnimator.getAnimatedValue(); // We are going from less negative value to a more negative value assertTrue(i.intValue() <= startColor); assertTrue(endColor <= i.intValue()); }
public void animateOpen() { positionAndSizeAsIcon(); if (!(getParent() instanceof DragLayer)) return; ObjectAnimator oa; DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); centerAboutIcon(); if (mMode == PARTIAL_GROW) { PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1); PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); oa = ObjectAnimator.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); } else { PropertyValuesHolder width = PropertyValuesHolder.ofInt("width", mNewSize.width()); PropertyValuesHolder height = PropertyValuesHolder.ofInt("height", mNewSize.height()); PropertyValuesHolder x = PropertyValuesHolder.ofInt("x", mNewSize.left); PropertyValuesHolder y = PropertyValuesHolder.ofInt("y", mNewSize.top); oa = ObjectAnimator.ofPropertyValuesHolder(lp, width, height, x, y); oa.addUpdateListener( new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { requestLayout(); } }); PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); ObjectAnimator alphaOa = ObjectAnimator.ofPropertyValuesHolder(mContent, alpha); alphaOa.setDuration(mExpandDuration); alphaOa.setInterpolator(new AccelerateInterpolator(2.0f)); alphaOa.start(); } oa.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { sendCustomAccessibilityEvent( AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, String.format( getContext().getString(R.string.folder_opened), mContent.getCountX(), mContent.getCountY())); mState = STATE_ANIMATING; } @Override public void onAnimationEnd(Animator animation) { mState = STATE_OPEN; Cling cling = mLauncher.showFirstRunFoldersCling(); if (cling != null) { cling.bringToFront(); } setFocusOnFirstChild(); } }); oa.setDuration(mExpandDuration); oa.start(); }
private void createCustomAnimations(LayoutTransition transition) { // Changing while Adding PropertyValuesHolder pvhLeft = PropertyValuesHolder.ofInt("left", 0, 1); PropertyValuesHolder pvhTop = PropertyValuesHolder.ofInt("top", 0, 1); PropertyValuesHolder pvhRight = PropertyValuesHolder.ofInt("right", 0, 1); PropertyValuesHolder pvhBottom = PropertyValuesHolder.ofInt("bottom", 0, 1); PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f, 1f); PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f, 1f); customChangingAppearingAnim = ObjectAnimator.ofPropertyValuesHolder( this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX, pvhScaleY) .setDuration(transition.getDuration(LayoutTransition.CHANGE_APPEARING)); customChangingAppearingAnim.addListener( new AnimatorListenerAdapter() { public void onAnimationEnd(Animator anim) { View view = (View) ((ObjectAnimator) anim).getTarget(); view.setScaleX(1f); view.setScaleY(1f); } }); // Changing while Removing Keyframe kf0 = Keyframe.ofFloat(0f, 0f); Keyframe kf1 = Keyframe.ofFloat(.9999f, 360f); Keyframe kf2 = Keyframe.ofFloat(1f, 0f); PropertyValuesHolder pvhRotation = PropertyValuesHolder.ofKeyframe("rotation", kf0, kf1, kf2); customChangingDisappearingAnim = ObjectAnimator.ofPropertyValuesHolder( this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhRotation) .setDuration(transition.getDuration(LayoutTransition.CHANGE_DISAPPEARING)); customChangingDisappearingAnim.addListener( new AnimatorListenerAdapter() { public void onAnimationEnd(Animator anim) { View view = (View) ((ObjectAnimator) anim).getTarget(); view.setRotation(0f); } }); // Adding customAppearingAnim = ObjectAnimator.ofFloat(null, "rotationY", 90f, 0f) .setDuration(transition.getDuration(LayoutTransition.APPEARING)); customAppearingAnim.addListener( new AnimatorListenerAdapter() { public void onAnimationEnd(Animator anim) { View view = (View) ((ObjectAnimator) anim).getTarget(); view.setRotationY(0f); } }); // Removing customDisappearingAnim = ObjectAnimator.ofFloat(null, "rotationX", 0f, 90f) .setDuration(transition.getDuration(LayoutTransition.DISAPPEARING)); customDisappearingAnim.addListener( new AnimatorListenerAdapter() { public void onAnimationEnd(Animator anim) { View view = (View) ((ObjectAnimator) anim).getTarget(); view.setRotationX(0f); } }); }
public void snapToWidget(boolean animate) { final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); int newWidth = mWidgetView.getWidth() + 2 * mBackgroundPadding - mWidgetPaddingLeft - mWidgetPaddingRight; int newHeight = mWidgetView.getHeight() + 2 * mBackgroundPadding - mWidgetPaddingTop - mWidgetPaddingBottom; mTmpPt[0] = mWidgetView.getLeft(); mTmpPt[1] = mWidgetView.getTop(); mDragLayer.getDescendantCoordRelativeToSelf(mCellLayout.getShortcutsAndWidgets(), mTmpPt); int newX = mTmpPt[0] - mBackgroundPadding + mWidgetPaddingLeft; int newY = mTmpPt[1] - mBackgroundPadding + mWidgetPaddingTop; // We need to make sure the frame's touchable regions lie fully within the bounds of the // DragLayer. We allow the actual handles to be clipped, but we shift the touch regions // down accordingly to provide a proper touch target. if (newY < 0) { // In this case we shift the touch region down to start at the top of the DragLayer mTopTouchRegionAdjustment = -newY; } else { mTopTouchRegionAdjustment = 0; } if (newY + newHeight > mDragLayer.getHeight()) { // In this case we shift the touch region up to end at the bottom of the DragLayer mBottomTouchRegionAdjustment = -(newY + newHeight - mDragLayer.getHeight()); } else { mBottomTouchRegionAdjustment = 0; } if (!animate) { lp.width = newWidth; lp.height = newHeight; lp.x = newX; lp.y = newY; mLeftHandle.setAlpha(1.0f); mRightHandle.setAlpha(1.0f); mTopHandle.setAlpha(1.0f); mBottomHandle.setAlpha(1.0f); requestLayout(); } else { PropertyValuesHolder width = PropertyValuesHolder.ofInt("width", lp.width, newWidth); PropertyValuesHolder height = PropertyValuesHolder.ofInt("height", lp.height, newHeight); PropertyValuesHolder x = PropertyValuesHolder.ofInt("x", lp.x, newX); PropertyValuesHolder y = PropertyValuesHolder.ofInt("y", lp.y, newY); ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(lp, this, width, height, x, y); ObjectAnimator leftOa = LauncherAnimUtils.ofFloat(mLeftHandle, "alpha", 1.0f); ObjectAnimator rightOa = LauncherAnimUtils.ofFloat(mRightHandle, "alpha", 1.0f); ObjectAnimator topOa = LauncherAnimUtils.ofFloat(mTopHandle, "alpha", 1.0f); ObjectAnimator bottomOa = LauncherAnimUtils.ofFloat(mBottomHandle, "alpha", 1.0f); oa.addUpdateListener( new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { requestLayout(); } }); AnimatorSet set = LauncherAnimUtils.createAnimatorSet(); if (mResizeMode == AppWidgetProviderInfo.RESIZE_VERTICAL) { set.playTogether(oa, topOa, bottomOa); } else if (mResizeMode == AppWidgetProviderInfo.RESIZE_HORIZONTAL) { set.playTogether(oa, leftOa, rightOa); } else { set.playTogether(oa, leftOa, rightOa, topOa, bottomOa); } set.setDuration(SNAP_DURATION); set.start(); } }
protected void changeZDepth(ZDepth zDepth) { int newAlphaTopShadow = zDepth.getAlphaTopShadow(); int newAlphaBottomShadow = zDepth.getAlphaBottomShadow(); float newOffsetYTopShadow = zDepth.getOffsetYTopShadowPx(getContext()); float newOffsetYBottomShadow = zDepth.getOffsetYBottomShadowPx(getContext()); float newBlurTopShadow = zDepth.getBlurTopShadowPx(getContext()); float newBlurBottomShadow = zDepth.getBlurBottomShadowPx(getContext()); if (!mZDepthDoAnimation) { mZDepthParam.mAlphaTopShadow = newAlphaTopShadow; mZDepthParam.mAlphaBottomShadow = newAlphaBottomShadow; mZDepthParam.mOffsetYTopShadowPx = newOffsetYTopShadow; mZDepthParam.mOffsetYBottomShadowPx = newOffsetYBottomShadow; mZDepthParam.mBlurTopShadowPx = newBlurTopShadow; mZDepthParam.mBlurBottomShadowPx = newBlurBottomShadow; mShadow.setParameter( mZDepthParam, mZDepthPaddingLeft, mZDepthPaddingTop, getWidth() - mZDepthPaddingRight, getHeight() - mZDepthPaddingBottom); invalidate(); return; } int nowAlphaTopShadow = mZDepthParam.mAlphaTopShadow; int nowAlphaBottomShadow = mZDepthParam.mAlphaBottomShadow; float nowOffsetYTopShadow = mZDepthParam.mOffsetYTopShadowPx; float nowOffsetYBottomShadow = mZDepthParam.mOffsetYBottomShadowPx; float nowBlurTopShadow = mZDepthParam.mBlurTopShadowPx; float nowBlurBottomShadow = mZDepthParam.mBlurBottomShadowPx; PropertyValuesHolder alphaTopShadowHolder = PropertyValuesHolder.ofInt( ANIM_PROPERTY_ALPHA_TOP_SHADOW, nowAlphaTopShadow, newAlphaTopShadow); PropertyValuesHolder alphaBottomShadowHolder = PropertyValuesHolder.ofInt( ANIM_PROPERTY_ALPHA_BOTTOM_SHADOW, nowAlphaBottomShadow, newAlphaBottomShadow); PropertyValuesHolder offsetTopShadowHolder = PropertyValuesHolder.ofFloat( ANIM_PROPERTY_OFFSET_TOP_SHADOW, nowOffsetYTopShadow, newOffsetYTopShadow); PropertyValuesHolder offsetBottomShadowHolder = PropertyValuesHolder.ofFloat( ANIM_PROPERTY_OFFSET_BOTTOM_SHADOW, nowOffsetYBottomShadow, newOffsetYBottomShadow); PropertyValuesHolder blurTopShadowHolder = PropertyValuesHolder.ofFloat( ANIM_PROPERTY_BLUR_TOP_SHADOW, nowBlurTopShadow, newBlurTopShadow); PropertyValuesHolder blurBottomShadowHolder = PropertyValuesHolder.ofFloat( ANIM_PROPERTY_BLUR_BOTTOM_SHADOW, nowBlurBottomShadow, newBlurBottomShadow); ValueAnimator anim = ValueAnimator.ofPropertyValuesHolder( alphaTopShadowHolder, alphaBottomShadowHolder, offsetTopShadowHolder, offsetBottomShadowHolder, blurTopShadowHolder, blurBottomShadowHolder); anim.setDuration(mZDepthAnimDuration); anim.setInterpolator(new LinearInterpolator()); anim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int alphaTopShadow = (Integer) animation.getAnimatedValue(ANIM_PROPERTY_ALPHA_TOP_SHADOW); int alphaBottomShadow = (Integer) animation.getAnimatedValue(ANIM_PROPERTY_ALPHA_BOTTOM_SHADOW); float offsetTopShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_OFFSET_TOP_SHADOW); float offsetBottomShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_OFFSET_BOTTOM_SHADOW); float blurTopShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_BLUR_TOP_SHADOW); float blurBottomShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_BLUR_BOTTOM_SHADOW); mZDepthParam.mAlphaTopShadow = alphaTopShadow; mZDepthParam.mAlphaBottomShadow = alphaBottomShadow; mZDepthParam.mOffsetYTopShadowPx = offsetTopShadow; mZDepthParam.mOffsetYBottomShadowPx = offsetBottomShadow; mZDepthParam.mBlurTopShadowPx = blurTopShadow; mZDepthParam.mBlurBottomShadowPx = blurBottomShadow; mShadow.setParameter( mZDepthParam, mZDepthPaddingLeft, mZDepthPaddingTop, getWidth() - mZDepthPaddingRight, getHeight() - mZDepthPaddingBottom); invalidate(); } }); anim.start(); }