public void setPressed(boolean pressed) { if (mGlowBG != null) { if (pressed != isPressed()) { if (mPressedAnim != null && mPressedAnim.isRunning()) { mPressedAnim.cancel(); } final AnimatorSet as = mPressedAnim = new AnimatorSet(); if (pressed) { if (mGlowScale < GLOW_MAX_SCALE_FACTOR) mGlowScale = GLOW_MAX_SCALE_FACTOR; if (mGlowAlpha < mQuiescentAlpha) mGlowAlpha = mQuiescentAlpha; setDrawingAlpha(1f); as.playTogether( ObjectAnimator.ofFloat(this, "glowAlpha", 1f), ObjectAnimator.ofFloat(this, "glowScale", GLOW_MAX_SCALE_FACTOR)); as.setDuration(50); } else { mAnimateToQuiescent.cancel(); mAnimateToQuiescent = animateToQuiescent(); as.playTogether( ObjectAnimator.ofFloat(this, "glowAlpha", 0f), ObjectAnimator.ofFloat(this, "glowScale", 1f), mAnimateToQuiescent); as.setDuration(500); } as.start(); } } super.setPressed(pressed); }
public void setPressed(boolean pressed) { if (mGlowBG != null) { if (pressed != isPressed()) { if (mPressedAnim != null && mPressedAnim.isRunning()) { mPressedAnim.cancel(); } final AnimatorSet as = mPressedAnim = new AnimatorSet(); if (pressed) { if (mGlowScale < GLOW_MAX_SCALE_FACTOR) mGlowScale = GLOW_MAX_SCALE_FACTOR; if (mGlowAlpha < BUTTON_QUIESCENT_ALPHA) mGlowAlpha = BUTTON_QUIESCENT_ALPHA; setDrawingAlpha(1f); as.playTogether( ObjectAnimator.ofFloat(this, "glowAlpha", 1f), ObjectAnimator.ofFloat(this, "glowScale", GLOW_MAX_SCALE_FACTOR)); as.setDuration(50); } else { as.playTogether( ObjectAnimator.ofFloat(this, "glowAlpha", 0f), ObjectAnimator.ofFloat(this, "glowScale", 1f), ObjectAnimator.ofFloat(this, "drawingAlpha", BUTTON_QUIESCENT_ALPHA)); as.setDuration(500); } as.start(); } } super.setPressed(pressed); }
private void createDefaultIconAnimation() { ObjectAnimator collapseAnimator = ObjectAnimator.ofFloat( mImageToggle, "rotation", mLabelsPosition == LABELS_POSITION_LEFT ? OPENED_PLUS_ROTATION_LEFT : OPENED_PLUS_ROTATION_RIGHT, CLOSED_PLUS_ROTATION); ObjectAnimator expandAnimator = ObjectAnimator.ofFloat( mImageToggle, "rotation", CLOSED_PLUS_ROTATION, mLabelsPosition == LABELS_POSITION_LEFT ? OPENED_PLUS_ROTATION_LEFT : OPENED_PLUS_ROTATION_RIGHT); mOpenAnimatorSet.play(expandAnimator); mCloseAnimatorSet.play(collapseAnimator); mOpenAnimatorSet.setInterpolator(mOpenInterpolator); mCloseAnimatorSet.setInterpolator(mCloseInterpolator); mOpenAnimatorSet.setDuration(ANIMATION_DURATION); mCloseAnimatorSet.setDuration(ANIMATION_DURATION); }
private AnimatorSet createAnimationSet() { List<Animator> animators = new ArrayList<>(); view.setLayerType(View.LAYER_TYPE_HARDWARE, null); if (!objectAnimations.isEmpty()) for (AnimationParams customAnimation : objectAnimations) { animators.add(createAnimation(view, customAnimation)); } if (this.animators != null) for (Animator animator : this.animators) { animators.add(animator); } AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(animators); if (interpolator != null) { animatorSet.setInterpolator(interpolator); } animatorSet.setDuration(duration); animatorSet.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationCancel(Animator animation) { super.onAnimationCancel(animation); view.setLayerType(View.LAYER_TYPE_NONE, null); } @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); view.setLayerType(View.LAYER_TYPE_NONE, null); } }); return animatorSet; }
private void animateFadeOutFadeIn(final View src, final View dst) { if (dst.getVisibility() != View.VISIBLE || dst.getAlpha() != 1f) { AnimatorSet set = new AnimatorSet(); set.playSequentially( ObjectAnimator.ofFloat(src, "alpha", 0f), ObjectAnimator.ofFloat(dst, "alpha", 1f)); set.setInterpolator(new LinearInterpolator()); set.addListener( new AnimatorListener() { @Override public void onAnimationStart(Animator animation) { src.setAlpha(1f); dst.setAlpha(0f); src.setVisibility(View.VISIBLE); dst.setVisibility(View.VISIBLE); } @Override public void onAnimationRepeat(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { src.setVisibility(View.GONE); } @Override public void onAnimationCancel(Animator animation) {} }); set.setDuration(250); set.start(); } else { src.setAlpha(1f); src.setVisibility(View.GONE); } }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") private void init() { mXAnimator = ObjectAnimator.ofFloat(this, "x", 0); mYAnimator = ObjectAnimator.ofFloat(this, "y", 0); mWAnimator = ObjectAnimator.ofInt(this, "wid", 0); mHAnimator = ObjectAnimator.ofInt(this, "hei", 0); mAnimatorSet = new AnimatorSet(); mAnimatorSet.setDuration(AnimationDuration); mAnimatorSet.playTogether(mWAnimator, mHAnimator, mXAnimator, mYAnimator); mAnimatorSet.addListener( new AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { if (getVisibility() != View.VISIBLE) { setVisibility(View.VISIBLE); } } @Override public void onAnimationCancel(Animator animation) {} }); }
@Override public void onTextSizeChanged(final TextView textView, float oldSize) { if (mCurrentState != CalculatorState.INPUT) { // TODO dont animate when showing graph // Only animate text changes that occur from user input. return; } // Calculate the values needed to perform the scale and translation animations, // maintaining the same apparent baseline for the displayed text. final float textScale = oldSize / textView.getTextSize(); final float translationX; if (android.os.Build.VERSION.SDK_INT >= 17) { translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingEnd()); } else { translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingRight()); } final float translationY = (1.0f - textScale) * (textView.getHeight() / 2.0f - textView.getPaddingBottom()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether( ObjectAnimator.ofFloat(textView, View.SCALE_X, textScale, 1.0f), ObjectAnimator.ofFloat(textView, View.SCALE_Y, textScale, 1.0f), ObjectAnimator.ofFloat(textView, View.TRANSLATION_X, translationX, 0.0f), ObjectAnimator.ofFloat(textView, View.TRANSLATION_Y, translationY, 0.0f)); animatorSet.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); animatorSet.setInterpolator(new AccelerateDecelerateInterpolator()); animatorSet.start(); }
/** 开启打开动画 */ private void startAnim() { ObjectAnimator tranAnimY = ObjectAnimator.ofFloat(mMenuViewSmall, "translationY", 0, -20); ObjectAnimator tranAnimPointX = ObjectAnimator.ofFloat(mMenuViewSmall, "translationX", 0, viewMoveX); ObjectAnimator tranAnimPointY = ObjectAnimator.ofFloat(mMenuViewSmall, "translationY", -20, viewMoveY); ObjectAnimator scaleAnimX = ObjectAnimator.ofFloat(mMenuViewSmall, "scaleX", 1.0f, (toValueX + 1.0f)); ObjectAnimator scaleAnimY = ObjectAnimator.ofFloat(mMenuViewSmall, "scaleY", 1.0f, (toValueY + 1.0f)); AnimatorSet set = new AnimatorSet(); set.setDuration(500); set.play(tranAnimY) .before(tranAnimPointX) .before(tranAnimPointY) .before(scaleAnimX) .before(scaleAnimY); scaleAnimX.addUpdateListener( new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float value = (float) animation.getAnimatedValue(); // mMenuViewSmall.setScaleX(value); mContentView.setAlpha((float) (1 - ((value - 1) / toValueX) * 0.5)); mContentView.setScaleX((float) (1 - ((value - 1) / toValueX) * 0.2)); mContentView.setScaleY((float) (1 - ((value - 1) / toValueX) * 0.2)); } }); set.addListener(this); set.start(); }
/** 下落 */ public void freeFall() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(shapeLoadingView, "translationY", 0, mDistance); ObjectAnimator scaleIndication = ObjectAnimator.ofFloat(indicationIm, "scaleX", 1, 0.2f); objectAnimator.setDuration(ANIMATION_DURATION); objectAnimator.setInterpolator(new AccelerateInterpolator()); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(ANIMATION_DURATION); animatorSet.playTogether(objectAnimator, scaleIndication); animatorSet.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { shapeLoadingView.changeShape(); upThrow(); } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); animatorSet.start(); }
private void applyMode(int mode, boolean animate) { if (mLeftSide == null) return; // pre-init float newAlpha = getNonBatteryClockAlphaFor(mode); float newAlphaBC = getBatteryClockAlpha(mode); if (mCurrentAnimation != null) { mCurrentAnimation.cancel(); } if (animate) { AnimatorSet anims = new AnimatorSet(); anims.playTogether( animateTransitionTo(mLeftSide, newAlpha), animateTransitionTo(mStatusIcons, newAlpha), animateTransitionTo(mSignalCluster, newAlpha), animateTransitionTo(mNetworkTraffic, newAlpha), animateTransitionTo(mBattery, newAlphaBC), animateTransitionTo(mClock, newAlphaBC)); if (isLightsOut(mode)) { anims.setDuration(LIGHTS_OUT_DURATION); } anims.start(); mCurrentAnimation = anims; } else { mLeftSide.setAlpha(newAlpha); mStatusIcons.setAlpha(newAlpha); mSignalCluster.setAlpha(newAlpha); mNetworkTraffic.setAlpha(newAlpha); mBattery.setAlpha(newAlphaBC); mClock.setAlpha(newAlphaBC); } }
private void startAnimation(View img, final Intent intent) { // ObjectAnimator oaTranslationX = ObjectAnimator.ofFloat(img, // "translationX", 0, mScreenWidth / 2); // ObjectAnimator oaTranslationY = ObjectAnimator.ofFloat(img, // "translationY", 0, mScreenHeight / 2); ObjectAnimator oaScaleX = ObjectAnimator.ofFloat(img, "scaleX", 0.5f, 1.2f, 1f); ObjectAnimator oaScaleY = ObjectAnimator.ofFloat(img, "scaleY", 0.5f, 1.2f, 1f); // oaTranslationX.setDuration(1000); // oaTranslationY.setDuration(1000); // oaScaleX.setDuration(1000); // oaScaleY.setDuration(1000); AnimatorSet set = new AnimatorSet(); set.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { isLocked = true; super.onAnimationStart(animation); } @Override public void onAnimationEnd(Animator animation) { Log.e("", "动画完成"); isLocked = false; startActivity(intent); } }); set.play(oaScaleX).with(oaScaleY); set.setDuration(500); if (!isLocked) { set.start(); } }
private void performSwitch() { ObjectAnimator animator1 = ObjectAnimator.ofFloat( mFirstView, "translationY", mFirstView.getTranslationY() - mBannerHeight); ObjectAnimator animator2 = ObjectAnimator.ofFloat( mSecondView, "translationY", mSecondView.getTranslationY() - mBannerHeight); AnimatorSet set = new AnimatorSet(); set.playTogether(animator1, animator2); set.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mFirstView.setTranslationY(0); mSecondView.setTranslationY(0); View removedView = getChildAt(0); mPosition++; mAdapter.setItem(removedView, mAdapter.getItem(mPosition % mAdapter.getCount())); removeView(removedView); addView(removedView, 1); } }); set.setDuration(mAnimDuration); set.start(); }
/** Starts the animation. */ public void start() { resetAllPaths(); animatorSet.cancel(); animatorSet.setDuration(duration); animatorSet.setInterpolator(interpolator); animatorSet.setStartDelay(delay); animatorSet.start(); }
private void combine() { ObjectAnimator moveIn = ObjectAnimator.ofFloat(tv, "translationX", -500f, 0f); ObjectAnimator rotate = ObjectAnimator.ofFloat(tv, "rotation", 0f, 360f); ObjectAnimator fadeInOut = ObjectAnimator.ofFloat(tv, "alpha", 1f, 0f, 1f); AnimatorSet animSet = new AnimatorSet(); animSet.play(rotate).with(fadeInOut).after(moveIn); animSet.setDuration(5000); animSet.start(); }
@Override public void animate() { final ViewGroup parentView = (ViewGroup) view.getParent(); final FrameLayout slideOutFrame = new FrameLayout(view.getContext()); final int positionView = parentView.indexOfChild(view); slideOutFrame.setLayoutParams(view.getLayoutParams()); slideOutFrame.setClipChildren(true); parentView.removeView(view); slideOutFrame.addView(view); parentView.addView(slideOutFrame, positionView); switch (direction) { case DIRECTION_LEFT: slideAnim = ObjectAnimator.ofFloat( view, View.TRANSLATION_X, view.getTranslationX() - view.getWidth()); break; case DIRECTION_RIGHT: slideAnim = ObjectAnimator.ofFloat( view, View.TRANSLATION_X, view.getTranslationX() + view.getWidth()); break; case DIRECTION_UP: slideAnim = ObjectAnimator.ofFloat( view, View.TRANSLATION_Y, view.getTranslationY() - view.getHeight()); break; case DIRECTION_DOWN: slideAnim = ObjectAnimator.ofFloat( view, View.TRANSLATION_Y, view.getTranslationY() + view.getHeight()); break; default: break; } AnimatorSet slideSet = new AnimatorSet(); slideSet.play(slideAnim); slideSet.setInterpolator(interpolator); slideSet.setDuration(duration); slideSet.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setVisibility(View.INVISIBLE); slideAnim.reverse(); slideOutFrame.removeAllViews(); parentView.removeView(slideOutFrame); parentView.addView(view, positionView); if (getListener() != null) { getListener().onAnimationEnd(SlideOutUnderneathAnimation.this); } } }); slideSet.start(); }
/** 初始化属性 */ private void init() { // x y方向上的缩放 ObjectAnimator xScaleAnimator = ObjectAnimator.ofFloat(this, "scaleX", START_SCALE, END_SCALE); ObjectAnimator yScaleAnimator = ObjectAnimator.ofFloat(this, "scaleY", START_SCALE, END_SCALE); // 组合动画 animSet = new AnimatorSet(); animSet.play(xScaleAnimator).with(yScaleAnimator); animSet.setDuration(SCALE_DURATION); }
@Override public void startAnimation( final ViewHolder holder, long duration, final BaseItemAnimator animator) { System.out.println("startAnimation"); float x = (holder.itemView.getWidth() - holder.itemView.getPaddingLeft() - holder.itemView.getPaddingRight()) / 2 + holder.itemView.getPaddingLeft(); float y = holder.itemView.getHeight() - holder.itemView.getPaddingBottom(); AnimatorSet set = new AnimatorSet(); set.playTogether( ObjectAnimator.ofFloat(holder.itemView, "pivotX", x, x, x, x, x), ObjectAnimator.ofFloat(holder.itemView, "pivotY", y, y, y, y, y), ObjectAnimator.ofFloat(holder.itemView, "rotationX", 90, 55, -30, 15, -15, 0)); set.addListener( new AnimatorListener() { @Override public void onAnimationStart(Animator animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animator animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animator animation) { animator.dispatchAddFinished(holder); animator.mAddAnimations.remove(holder); animator.dispatchFinishedWhenDone(); } @Override public void onAnimationCancel(Animator animation) { // TODO Auto-generated method stub } }); set.setStartDelay(mDelay * mDelayCount); set.setDuration(animator.getAddDuration()); set.start(); animator.mAddAnimations.add(holder); }
private AnimatorSet buildAnimationSet(int duration, ObjectAnimator... objectAnimators) { AnimatorSet a = new AnimatorSet(); a.playTogether(objectAnimators); a.setInterpolator( AnimationUtils.loadInterpolator( EventActivity.this, android.R.interpolator.accelerate_decelerate)); a.setDuration(duration); return a; }
private void startChildAnimation(View child) { if (animationEnabled) { AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether( ObjectAnimator.ofFloat(child, "alpha", 0.0f, 1.0f), ObjectAnimator.ofFloat( child, "translationY", AndroidUtilities.dp(showedFromBotton ? 6 : -6), 0)); animatorSet.setDuration(180); animatorSet.setInterpolator(decelerateInterpolator); animatorSet.start(); } }
private void addAnimation(View view) { float[] vaules = new float[] { 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 1.1f, 1.2f, 1.3f, 1.25f, 1.2f, 1.15f, 1.1f, 1.0f }; AnimatorSet set = new AnimatorSet(); set.playTogether( ObjectAnimator.ofFloat(view, "scaleX", vaules), ObjectAnimator.ofFloat(view, "scaleY", vaules)); set.setDuration(150); set.start(); }
@SuppressLint("NewApi") public void onRevealAnimationProgress(boolean open, float radius, int x, int y) { if (!open) { return; } int count = Build.VERSION.SDK_INT <= 19 ? 11 : 8; for (int a = 0; a < count; a++) { if (views[a].getTag(R.string.AppName) == null) { if (distCache[a] == 0) { int buttonX = views[a].getLeft() + views[a].getMeasuredWidth() / 2; int buttonY = views[a].getTop() + views[a].getMeasuredHeight() / 2; distCache[a] = (float) Math.sqrt((x - buttonX) * (x - buttonX) + (y - buttonY) * (y - buttonY)); float vecX = (x - buttonX) / distCache[a]; float vecY = (y - buttonY) / distCache[a]; views[a].setPivotX(views[a].getMeasuredWidth() / 2 + vecX * AndroidUtilities.dp(20)); views[a].setPivotY(views[a].getMeasuredHeight() / 2 + vecY * AndroidUtilities.dp(20)); } if (distCache[a] > radius + AndroidUtilities.dp(27)) { continue; } views[a].setTag(R.string.AppName, 1); final ArrayList<Animator> animators = new ArrayList<>(); final ArrayList<Animator> animators2 = new ArrayList<>(); if (a < 8) { animators.add(ObjectAnimator.ofFloat(views[a], "scaleX", 0.7f, 1.05f)); animators.add(ObjectAnimator.ofFloat(views[a], "scaleY", 0.7f, 1.05f)); animators2.add(ObjectAnimator.ofFloat(views[a], "scaleX", 1.0f)); animators2.add(ObjectAnimator.ofFloat(views[a], "scaleY", 1.0f)); } if (Build.VERSION.SDK_INT <= 19) { animators.add(ObjectAnimator.ofFloat(views[a], "alpha", 1.0f)); } AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(animators); animatorSet.setDuration(150); animatorSet.setInterpolator(decelerateInterpolator); animatorSet.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(animators2); animatorSet.setDuration(100); animatorSet.setInterpolator(decelerateInterpolator); animatorSet.start(); } }); animatorSet.start(); } } }
public void startAnimation() { if (animationEnabled) { if (windowAnimatorSet != null) { return; } ActionBarPopupWindowLayout content = (ActionBarPopupWindowLayout) getContentView(); content.setTranslationY(0); content.setAlpha(1.0f); content.setPivotX(content.getMeasuredWidth()); content.setPivotY(0); int count = content.getItemsCount(); content.positions.clear(); int visibleCount = 0; for (int a = 0; a < count; a++) { View child = content.getItemAt(a); if (child.getVisibility() != View.VISIBLE) { continue; } content.positions.put(child, visibleCount); child.setAlpha(0.0f); visibleCount++; } if (content.showedFromBotton) { content.lastStartedChild = count - 1; } else { content.lastStartedChild = 0; } windowAnimatorSet = new AnimatorSet(); windowAnimatorSet.playTogether( ObjectAnimator.ofFloat(content, "backScaleY", 0.0f, 1.0f), ObjectAnimator.ofInt(content, "backAlpha", 0, 255)); windowAnimatorSet.setDuration(150 + 16 * visibleCount); windowAnimatorSet.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { windowAnimatorSet = null; } @Override public void onAnimationCancel(Animator animation) { onAnimationEnd(animation); } @Override public void onAnimationRepeat(Animator animation) {} }); windowAnimatorSet.start(); } }
public void showNext() { if (height <= 0) { height = topToast1.getHeight(); } ObjectAnimator anim1 = ObjectAnimator.ofFloat(topToastArray[(showPosition + 1) % length], "y", -height, 0f); ObjectAnimator anim2 = ObjectAnimator.ofFloat(topToastArray[showPosition], "y", 0f, height); AnimatorSet animSet = new AnimatorSet(); animSet.play(anim1).with(anim2); animSet.setDuration(500); animSet.start(); showPosition = (showPosition + 1) % length; }
// multiple object animator objects to be run in parallel public void runObjectAnimators(View view) { ObjectAnimator oaX = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, TX_END); ObjectAnimator oaY = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, TY_END); // oaX.start(); // just put the start on the end of the above definitions and delete the object // assignment // oaY.start(); // object assignment used with below example of animation set for parallel // or to run them in parallel AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(oaX).with(oaY); animatorSet.setDuration(1000); // animatorSet.setInterpolator(new OvershootInterpolator()); // working animatorSet.start(); }
@Override public AnimatorSet createAnimatorSet() { ViewHelper.setClipChildren(targetView, false); AnimatorSet rotationSet = new AnimatorSet(); rotationSet.play( ObjectAnimator.ofFloat(targetView, View.ROTATION, targetView.getRotation() + degrees)); rotationSet.setInterpolator(interpolator); rotationSet.setDuration(duration); if (listener != null) { rotationSet.addListener(listener); } return rotationSet; }
public void dismiss(boolean animated) { setFocusable(false); if (animationEnabled && animated) { if (windowAnimatorSet != null) { windowAnimatorSet.cancel(); } ActionBarPopupWindowLayout content = (ActionBarPopupWindowLayout) getContentView(); windowAnimatorSet = new AnimatorSet(); windowAnimatorSet.playTogether( ObjectAnimator.ofFloat( content, "translationY", AndroidUtilities.dp(content.showedFromBotton ? 5 : -5)), ObjectAnimator.ofFloat(content, "alpha", 0.0f)); windowAnimatorSet.setDuration(150); windowAnimatorSet.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { windowAnimatorSet = null; setFocusable(false); try { ActionBarPopupWindow.super.dismiss(); } catch (Exception e) { // don't promt } unregisterListener(); } @Override public void onAnimationCancel(Animator animation) { onAnimationEnd(animation); } @Override public void onAnimationRepeat(Animator animation) {} }); windowAnimatorSet.start(); } else { try { super.dismiss(); } catch (Exception e) { // don't promt } unregisterListener(); } }
/** 上抛 */ public void upThrow() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(shapeLoadingView, "translationY", mDistance, 0); ObjectAnimator scaleIndication = ObjectAnimator.ofFloat(indicationIm, "scaleX", 0.2f, 1); ObjectAnimator objectAnimator1 = null; switch (shapeLoadingView.getShape()) { case SHAPE_RECT: objectAnimator1 = ObjectAnimator.ofFloat(shapeLoadingView, "rotation", 0, -120); break; case SHAPE_CIRCLE: objectAnimator1 = ObjectAnimator.ofFloat(shapeLoadingView, "rotation", 0, 180); break; case SHAPE_TRIANGLE: objectAnimator1 = ObjectAnimator.ofFloat(shapeLoadingView, "rotation", 0, 180); break; } objectAnimator.setDuration(ANIMATION_DURATION); objectAnimator1.setDuration(ANIMATION_DURATION); objectAnimator.setInterpolator(new DecelerateInterpolator()); objectAnimator1.setInterpolator(new DecelerateInterpolator()); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(ANIMATION_DURATION); animatorSet.playTogether(objectAnimator, objectAnimator1, scaleIndication); animatorSet.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { freeFall(); } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); animatorSet.start(); }
void animatePagesToCarousel() { if (mChildrenTransformsAnimator != null) { mChildrenTransformsAnimator.cancel(); mChildrenTransformsAnimator = null; } int count = getChildCount(); PropertyValuesHolder alpha; PropertyValuesHolder outlineAlpha; PropertyValuesHolder rotationY; PropertyValuesHolder pivotX; PropertyValuesHolder pivotY; ArrayList<Animator> anims = new ArrayList<Animator>(); for (int i = 0; i < count; i++) { KeyguardWidgetFrame child = getWidgetPageAt(i); float finalAlpha = getAlphaForPage(mScreenCenter, i, true); float finalOutlineAlpha = getOutlineAlphaForPage(mScreenCenter, i, true); getTransformForPage(mScreenCenter, i, mTmpTransform); boolean inVisibleRange = (i >= mCurrentPage - 1 && i <= mCurrentPage + 1); ObjectAnimator a; alpha = PropertyValuesHolder.ofFloat("contentAlpha", finalAlpha); outlineAlpha = PropertyValuesHolder.ofFloat("backgroundAlpha", finalOutlineAlpha); pivotX = PropertyValuesHolder.ofFloat("pivotX", mTmpTransform[0]); pivotY = PropertyValuesHolder.ofFloat("pivotY", mTmpTransform[1]); rotationY = PropertyValuesHolder.ofFloat("rotationY", mTmpTransform[2]); if (inVisibleRange) { // for the central pages we animate into a rotated state a = ObjectAnimator.ofPropertyValuesHolder( child, alpha, outlineAlpha, pivotX, pivotY, rotationY); } else { a = ObjectAnimator.ofPropertyValuesHolder(child, alpha, outlineAlpha); a.setInterpolator(mFastFadeInterpolator); } anims.add(a); } int duration = REORDERING_ZOOM_IN_OUT_DURATION; mChildrenTransformsAnimator = new AnimatorSet(); mChildrenTransformsAnimator.playTogether(anims); mChildrenTransformsAnimator.setDuration(duration); mChildrenTransformsAnimator.start(); }
private void scaleToLarge(View item) { if (!item.isFocused()) { return; } animatorSet = new AnimatorSet(); largeX = ObjectAnimator.ofFloat(item, "ScaleX", 1f, scale); ObjectAnimator largeY = ObjectAnimator.ofFloat(item, "ScaleY", 1f, scale); ObjectAnimator cursorX = ObjectAnimator.ofFloat(cursor, "ScaleX", 1f, scale); ObjectAnimator cursorY = ObjectAnimator.ofFloat(cursor, "ScaleY", 1f, scale); animatorSet.setDuration(durationLarge); animatorSet.play(largeX).with(largeY).with(cursorX).with(cursorY); animatorSet.start(); }
/** * item的交换动画效果 * * @param oldPosition * @param newPosition */ private void animateReorder(final int oldPosition, final int newPosition) { boolean isForward = newPosition > oldPosition; List<Animator> resultList = new LinkedList<Animator>(); if (isForward) { for (int pos = oldPosition; pos < newPosition; pos++) { View view = getChildAt(pos - getFirstVisiblePosition()); System.out.println(pos); if ((pos + 1) % getNumColumns() == 0) { resultList.add( createTranslationAnimations( view, -view.getWidth() * (getNumColumns() - 1), 0, view.getHeight(), 0)); } else { resultList.add(createTranslationAnimations(view, view.getWidth(), 0, 0, 0)); } } } else { for (int pos = oldPosition; pos > newPosition; pos--) { View view = getChildAt(pos - getFirstVisiblePosition()); if ((pos + getNumColumns()) % getNumColumns() == 0) { resultList.add( createTranslationAnimations( view, view.getWidth() * (getNumColumns() - 1), 0, -view.getHeight(), 0)); } else { resultList.add(createTranslationAnimations(view, -view.getWidth(), 0, 0, 0)); } } } AnimatorSet resultSet = new AnimatorSet(); resultSet.playTogether(resultList); resultSet.setDuration(300); resultSet.setInterpolator(new AccelerateDecelerateInterpolator()); resultSet.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { mAnimationEnd = false; } @Override public void onAnimationEnd(Animator animation) { mAnimationEnd = true; } }); resultSet.start(); }