Example #1
0
  public void snapChild(final SwipeableItemView view) {
    final View animView = view.getSwipeableView().getView();
    final boolean canAnimViewBeDismissed = mCallback.canChildBeDismissed(view);
    final ObjectAnimator anim = createTranslationAnimation(animView, 0);
    final int duration = SNAP_ANIM_LEN;
    anim.setDuration(duration);
    anim.addUpdateListener(
        new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            if (FADE_OUT_DURING_SWIPE && canAnimViewBeDismissed) {
              animView.setAlpha(getAlphaForOffset(animView));
            }
            invalidateGlobalRegion(animView);
          }
        });
    anim.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {
            animView.setAlpha(1.0f);
            mCallback.onDragCancelled(mCurrView);
          }

          @Override
          public void onAnimationCancel(Animator animation) {}

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
    anim.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();
  }
  /** Animates the stack scroll */
  void animateScroll(float curScroll, float newScroll, final Runnable postRunnable) {
    // Finish any current scrolling animations
    Log.d(TAG, "animateScroll: ");
    if (mScrollAnimator != null && mScrollAnimator.isRunning()) {
      setStackScroll(mFinalAnimatedScroll);
      mScroller.startScroll(0, progressToScrollRange(mFinalAnimatedScroll), 0, 0, 0);
    }
    stopScroller();
    stopBoundScrollAnimation();

    mFinalAnimatedScroll = newScroll;
    mScrollAnimator = ObjectAnimator.ofFloat(this, "stackScroll", curScroll, newScroll);
    mScrollAnimator.setDuration(mConfig.taskStackScrollDuration);
    mScrollAnimator.setInterpolator(mConfig.linearOutSlowInInterpolator);
    mScrollAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            setStackScroll((Float) animation.getAnimatedValue());
          }
        });
    mScrollAnimator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            if (postRunnable != null) {
              postRunnable.run();
            }
            mScrollAnimator.removeAllListeners();
          }
        });
    mScrollAnimator.start();
  }
Example #4
0
  /**
   * @param view The view to be dismissed
   * @param velocity The desired pixels/second speed at which the view should move
   */
  private void dismissChild(final SwipeableItemView view, float velocity) {
    final View animView = mCurrView.getSwipeableView().getView();
    final boolean canAnimViewBeDismissed = mCallback.canChildBeDismissed(view);
    float newPos = determinePos(animView, velocity);
    int duration = determineDuration(animView, newPos, velocity);

    Utils.enableHardwareLayer(animView);
    ObjectAnimator anim = createDismissAnimation(animView, newPos, duration);
    anim.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            mCallback.onChildDismissed(mCurrView);
            animView.setLayerType(View.LAYER_TYPE_NONE, null);
          }
        });
    anim.addUpdateListener(
        new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            if (FADE_OUT_DURING_SWIPE && canAnimViewBeDismissed) {
              animView.setAlpha(getAlphaForOffset(animView));
            }
            invalidateGlobalRegion(animView);
          }
        });
    anim.start();
  }
  public ObjectAnimator getDisappearAnimator() {
    if (!mIsInitialized || !mDrawValuesReady) {
      Log.e(TAG, "RadialSelectorView was not ready for animation.");
      return null;
    }

    Keyframe kf0, kf1, kf2;
    float midwayPoint = 0.2f;
    int duration = 500;

    kf0 = Keyframe.ofFloat(0f, 1);
    kf1 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf2 = Keyframe.ofFloat(1f, mTransitionEndRadiusMultiplier);
    PropertyValuesHolder radiusDisappear =
        PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2);

    kf0 = Keyframe.ofFloat(0f, 1f);
    kf1 = Keyframe.ofFloat(1f, 0f);
    PropertyValuesHolder fadeOut = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1);

    ObjectAnimator disappearAnimator =
        ObjectAnimator.ofPropertyValuesHolder(this, radiusDisappear, fadeOut).setDuration(duration);
    disappearAnimator.addUpdateListener(mInvalidateUpdateListener);

    return disappearAnimator;
  }
  /** Animation for the textview if the action bar is visible. */
  public void startShowAnimation() {
    if (mCurrentAnimation != null) mCurrentAnimation.cancel();

    mCurrentAnimation =
        ObjectAnimator.ofInt(
                mActionBarDelegate,
                TOP_MARGIN_ANIM_PROPERTY,
                (int) (Math.max(0, queryCurrentActionBarHeight() - mTabStripHeight)))
            .setDuration(SLIDE_DURATION_MS);

    mCurrentAnimation.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            mCurrentAnimation = null;
          }
        });

    mCurrentAnimation.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            ActionBar actionBar = mActionBarDelegate.getSupportActionBar();
            if (actionBar != null) {
              animation.setIntValues(
                  (int) (Math.max(0, queryCurrentActionBarHeight() - mTabStripHeight)));
            }
          }
        });

    mActionBarDelegate.setActionBarBackgroundVisibility(true);
    mCurrentAnimation.start();
    mShowingActionMode = true;
  }
Example #7
0
  /** Render the animations for appearing and disappearing. */
  private void renderAnimations() {
    Keyframe kf0, kf1, kf2, kf3;
    float midwayPoint = 0.2f;
    int duration = 500;

    // Set up animator for disappearing.
    kf0 = Keyframe.ofFloat(0f, 1);
    kf1 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf2 = Keyframe.ofFloat(1f, mTransitionEndRadiusMultiplier);
    PropertyValuesHolder radiusDisappear =
        PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2);

    kf0 = Keyframe.ofFloat(0f, 1f);
    kf1 = Keyframe.ofFloat(1f, 0f);
    PropertyValuesHolder fadeOut = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1);

    mDisappearAnimator =
        ObjectAnimator.ofPropertyValuesHolder(this, radiusDisappear, fadeOut).setDuration(duration);
    mDisappearAnimator.addUpdateListener(mInvalidateUpdateListener);

    // Set up animator for reappearing.
    float delayMultiplier = 0.25f;
    float transitionDurationMultiplier = 1f;
    float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier;
    int totalDuration = (int) (duration * totalDurationMultiplier);
    float delayPoint = (delayMultiplier * duration) / totalDuration;
    midwayPoint = 1 - (midwayPoint * (1 - delayPoint));

    kf0 = Keyframe.ofFloat(0f, mTransitionEndRadiusMultiplier);
    kf1 = Keyframe.ofFloat(delayPoint, mTransitionEndRadiusMultiplier);
    kf2 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf3 = Keyframe.ofFloat(1f, 1);
    PropertyValuesHolder radiusReappear =
        PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2, kf3);

    kf0 = Keyframe.ofFloat(0f, 0f);
    kf1 = Keyframe.ofFloat(delayPoint, 0f);
    kf2 = Keyframe.ofFloat(1f, 1f);
    PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1, kf2);

    mReappearAnimator =
        ObjectAnimator.ofPropertyValuesHolder(this, radiusReappear, fadeIn)
            .setDuration(totalDuration);
    mReappearAnimator.addUpdateListener(mInvalidateUpdateListener);
  }
  /**
   * Animate the progress arc to the specified value.
   *
   * @param duration Duration of the animation.
   * @param finalValue End value of the animation.
   */
  public void animateProgress(long duration, int finalValue) {

    // start the animation if no animation is currently in progress.
    if (!animationInProgress) {
      animationInProgress = true;
      progressAnimator.setIntValues(progress, finalValue);
      progressAnimator.setDuration(duration);
      progressAnimator.setInterpolator(new AccelerateInterpolator());
      progressAnimator.addUpdateListener(updateListener);
      progressAnimator.addListener(animatorListenerAdapter);
      progressAnimator.start();
    }
  }
  public void animateProgressTo(
      final int start, final int end, final ProgressAnimationListener listener) {
    if (start != 0) setProgress(start);

    final ObjectAnimator progressBarAnimator =
        ObjectAnimator.ofFloat(this, "animateProgress", end * 60000, start);
    progressBarAnimator.setDuration(end * 60000);
    //		progressBarAnimator.setInterpolator(new AnticipateOvershootInterpolator(2f, 1.5f));
    progressBarAnimator.setInterpolator(new LinearInterpolator());

    progressBarAnimator.addListener(
        new AnimatorListener() {
          @Override
          public void onAnimationCancel(final Animator animation) {
            if (listener != null) listener.onAnimationFinish();
          }

          @Override
          public void onAnimationEnd(final Animator animation) {
            if (listener != null) listener.onAnimationFinish();
          }

          @Override
          public void onAnimationRepeat(final Animator animation) {}

          @Override
          public void onAnimationStart(final Animator animation) {
            CircularProgressBar.this.setProgress(start);
            if (listener != null) listener.onAnimationStart();
          }
        });

    progressBarAnimator.addUpdateListener(
        new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(final ValueAnimator animation) {
            if (!inProgress) progressBarAnimator.cancel();
            int progress = ((Float) animation.getAnimatedValue()).intValue();
            if (progress != CircularProgressBar.this.getProgress() && inProgress) {
              Log.d(TAG, progress + "");
              CircularProgressBar.this.setProgress(progress);
              if (listener != null) listener.onAnimationProgress(progress);
            }
          }
        });
    if (!inProgress) {
      progressBarAnimator.cancel();
    } else {
      progressBarAnimator.start();
    }
  }
Example #10
0
  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();
  }
  @Override
  public void onClick(View v) {
    ObjectAnimator animator =
        ObjectAnimator.ofFloat(imageView, "aaa", 0.1f, 1.0f, 1.0f, 0.1f, 1.0f);
    animator.setDuration(4000);
    animator.start();
    animator.addUpdateListener(
        new AnimatorUpdateListener() {

          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            imageView.setScaleX(value);
            imageView.setScaleY(value);
            imageView.setAlpha(value);
          }
        });
  }
 private void parentViewSliding(
     int fromx, int tox, View view, long duration, AnimatorListenerAdapter listener) {
   PropertyValuesHolder pvTY = PropertyValuesHolder.ofFloat("x", fromx, tox);
   ObjectAnimator objectAnimator =
       ObjectAnimator.ofPropertyValuesHolder(view, pvTY).setDuration(duration);
   objectAnimator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator valueAnimator) {
           //                parentViewScrollX = ((Float)
           // valueAnimator.getAnimatedValue()).intValue();
           changeListView();
         }
       });
   objectAnimator.addListener(listener);
   objectAnimator.setInterpolator(new DecelerateInterpolator());
   objectAnimator.start();
 }
  /** 执行反向动画将其隐藏 */
  private void doReverseAnimation() {
    if (Build.VERSION.SDK_INT < 11) {
      sv_bottom_content.setVisibility(View.GONE);
      ll_full_screen.setVisibility(View.GONE);
    } else {
      // 如果弹出动画还在执行,则直接将弹出动画的值置为最终值,代表该动画结束,接着直接进行收进动画
      popAnimation.end();
      // 避免用户连续快速点击造成短时间内执行两次收进动画,此处进行判断
      if (reverseAnimation != null && reverseAnimation.isRunning()) {
        return;
      }
      if (reverseAnimation == null) {
        reverseAnimation =
            ObjectAnimator.ofInt(sv_bottom_content, "bottomMargin", 0, -scrollViewMeasureHeight);
        reverseAnimation.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                int value = (Integer) animation.getAnimatedValue();
                RelativeLayout.LayoutParams params =
                    (RelativeLayout.LayoutParams) sv_bottom_content.getLayoutParams();
                params.bottomMargin = value;
                sv_bottom_content.setLayoutParams(params);
                ((View) (sv_bottom_content.getParent())).invalidate();
                if (value <= -scrollViewMeasureHeight) {
                  sv_bottom_content.setVisibility(View.GONE);
                }

                ll_full_screen.setAlpha(
                    (float)
                        (((scrollViewMeasureHeight + value) * 1.0)
                            / (scrollViewMeasureHeight * 1.0)));
                if (ll_full_screen.getAlpha() <= 0) {
                  ll_full_screen.setVisibility(View.GONE);
                }
              }
            });
        reverseAnimation.setDuration(500);
      }
      reverseAnimation.start();
    }
  }
  /**
   * Applys a spin animation to the Chart.
   *
   * @param durationmillis
   * @param fromangle
   * @param toangle
   */
  @SuppressLint("NewApi")
  public void spin(int durationmillis, float fromangle, float toangle) {

    if (android.os.Build.VERSION.SDK_INT < 11) return;

    mRotationAngle = fromangle;

    mSpinAnimator = ObjectAnimator.ofFloat(this, "rotationAngle", fromangle, toangle);
    mSpinAnimator.setDuration(durationmillis);

    mSpinAnimator.addUpdateListener(
        new AnimatorUpdateListener() {

          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            postInvalidate();
          }
        });
    mSpinAnimator.start();
  }
  @SuppressLint("NewApi")
  public void spin(int durationmillis, float fromangle, float toangle, Easing.EasingOption easing) {

    if (android.os.Build.VERSION.SDK_INT < 11) return;

    setRotationAngle(fromangle);

    ObjectAnimator spinAnimator = ObjectAnimator.ofFloat(this, "rotationAngle", fromangle, toangle);
    spinAnimator.setDuration(durationmillis);
    spinAnimator.setInterpolator(Easing.getEasingFunctionFromOption(easing));

    spinAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {

          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            postInvalidate();
          }
        });
    spinAnimator.start();
  }
  /** 开启关闭动画 */
  private void closeAnim() {
    ObjectAnimator tranAnimY = ObjectAnimator.ofFloat(mMenuViewSmall, "translationY", -20, 0);

    ObjectAnimator tranAnimPointX =
        ObjectAnimator.ofFloat(mMenuViewSmall, "translationX", viewMoveX, 0);
    ObjectAnimator tranAnimPointY =
        ObjectAnimator.ofFloat(mMenuViewSmall, "translationY", viewMoveY, -20);

    ObjectAnimator scaleAnimX =
        ObjectAnimator.ofFloat(mMenuViewSmall, "scaleX", toValueX + 1.0f, 1.0f);
    ObjectAnimator scaleAnimY =
        ObjectAnimator.ofFloat(mMenuViewSmall, "scaleY", toValueY + 1.0f, 1.0f);

    AnimatorSet set = new AnimatorSet();
    set.setDuration(500);
    set.play(tranAnimPointX)
        .with(tranAnimPointY)
        .with(scaleAnimX)
        .with(scaleAnimY)
        .before(tranAnimY);

    scaleAnimX.addUpdateListener(
        new AnimatorUpdateListener() {

          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            float alphaValue = (float) (0.5 / ((((value - 1) / toValueX) * 0.5) + 0.5));
            float scaleX = (float) (0.8 / ((((value - 1) / toValueX) * 0.2) + 0.8));
            float scaleY = (float) (0.8 / ((((value - 1) / toValueX) * 0.2) + 0.8));
            //				mMenuViewSmall.setScaleX(value);
            mContentView.setAlpha(alphaValue < 0.5f ? 0.5f : alphaValue);
            mContentView.setScaleX(scaleX > 1 ? 1 : scaleX);
            mContentView.setScaleY(scaleY > 1 ? 1 : scaleY);
          }
        });

    set.addListener(this);
    set.start();
  }
  /** 用来显示该popwindow,保证在调用该方法之前已经调用{@link #addItemToBottomPopWindow(int, int, String)}方法 */
  protected void showBottomPopWindow() {
    if (Build.VERSION.SDK_INT >= 11) {
      // 如果上次的动画还在执行,直接停止
      if (reverseAnimation != null) {
        reverseAnimation.end();
      }
      sv_bottom_content.setVisibility(View.VISIBLE);
      ll_full_screen.setVisibility(View.VISIBLE);
      // 需要滚动到顶部
      sv_bottom_content.scrollTo(0, 0);
      if (popAnimation == null) {
        popAnimation =
            ObjectAnimator.ofInt(sv_bottom_content, "bottomMargin", -scrollViewMeasureHeight, 0);
        popAnimation.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                int value = (Integer) animation.getAnimatedValue();
                RelativeLayout.LayoutParams params =
                    (RelativeLayout.LayoutParams) sv_bottom_content.getLayoutParams();
                params.bottomMargin = value;
                sv_bottom_content.setLayoutParams(params);
                ((View) (sv_bottom_content.getParent())).invalidate();

                ll_full_screen.setAlpha(
                    (float)
                        (((scrollViewMeasureHeight + value) * 1.0)
                            / (scrollViewMeasureHeight * 1.0)));
              }
            });
        popAnimation.setDuration(500);
      }
      popAnimation.start();
    } else {
      ll_full_screen.setVisibility(View.VISIBLE);
      sv_bottom_content.setVisibility(View.VISIBLE);
      // 需要滚动到顶部
      sv_bottom_content.scrollTo(0, 0);
    }
  }
Example #18
0
 @SuppressLint("NewApi")
 public void snapChild(final View view, float velocity) {
   final View animView = mCallback.getChildContentView(view);
   final boolean canAnimViewBeDismissed = mCallback.canChildBeDismissed(animView);
   ObjectAnimator anim = createTranslationAnimation(animView, 0);
   int duration = SNAP_ANIM_LEN;
   anim.setDuration(duration);
   anim.addUpdateListener(
       new AnimatorUpdateListener() {
         public void onAnimationUpdate(ValueAnimator animation) {
           updateSwipeProgressFromOffset(animView, canAnimViewBeDismissed);
         }
       });
   anim.addListener(
       new AnimatorListenerAdapter() {
         public void onAnimationEnd(Animator animator) {
           updateSwipeProgressFromOffset(animView, canAnimViewBeDismissed);
           mCallback.onChildSnappedBack(animView);
         }
       });
   anim.start();
 }
  public ObjectAnimator getReappearAnimator() {
    if (!mIsInitialized || !mDrawValuesReady) {
      Log.e(TAG, "RadialSelectorView was not ready for animation.");
      return null;
    }

    Keyframe kf0, kf1, kf2, kf3;
    float midwayPoint = 0.2f;
    int duration = 500;

    // The time points are half of what they would normally be, because this animation is
    // staggered against the disappear so they happen seamlessly. The reappear starts
    // halfway into the disappear.
    float delayMultiplier = 0.25f;
    float transitionDurationMultiplier = 1f;
    float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier;
    int totalDuration = (int) (duration * totalDurationMultiplier);
    float delayPoint = (delayMultiplier * duration) / totalDuration;
    midwayPoint = 1 - (midwayPoint * (1 - delayPoint));

    kf0 = Keyframe.ofFloat(0f, mTransitionEndRadiusMultiplier);
    kf1 = Keyframe.ofFloat(delayPoint, mTransitionEndRadiusMultiplier);
    kf2 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf3 = Keyframe.ofFloat(1f, 1);
    PropertyValuesHolder radiusReappear =
        PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2, kf3);

    kf0 = Keyframe.ofFloat(0f, 0f);
    kf1 = Keyframe.ofFloat(delayPoint, 0f);
    kf2 = Keyframe.ofFloat(1f, 1f);
    PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1, kf2);

    ObjectAnimator reappearAnimator =
        ObjectAnimator.ofPropertyValuesHolder(this, radiusReappear, fadeIn)
            .setDuration(totalDuration);
    reappearAnimator.addUpdateListener(mInvalidateUpdateListener);
    return reappearAnimator;
  }
  void updateViewPropertiesToTaskTransform(
      TaskViewTransform toTransform,
      int duration,
      ValueAnimator.AnimatorUpdateListener updateCallback) {
    // Apply the transform
    toTransform.applyToTaskView(
        this,
        duration,
        mConfig.fastOutSlowInInterpolator,
        false,
        !mConfig.fakeShadows,
        updateCallback);

    // Update the task progress
    Utilities.cancelAnimationWithoutCallbacks(mTaskProgressAnimator);
    if (duration <= 0) {
      setTaskProgress(toTransform.p);
    } else {
      mTaskProgressAnimator = ObjectAnimator.ofFloat(this, "taskProgress", toTransform.p);
      mTaskProgressAnimator.setDuration(duration);
      mTaskProgressAnimator.addUpdateListener(mUpdateDimListener);
      mTaskProgressAnimator.start();
    }
  }
Example #21
0
  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();
  }
  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();
    }
  }
Example #23
0
  /**
   * @param view The view to be dismissed
   * @param velocity The desired pixels/second speed at which the view should move
   * @param endAction The action to perform at the end
   * @param delay The delay after which we should start
   * @param useAccelerateInterpolator Should an accelerating Interpolator be used
   * @param fixedDuration If not 0, this exact duration will be taken
   */
  @SuppressLint("NewApi")
  public void dismissChild(
      final View view,
      float velocity,
      final Runnable endAction,
      long delay,
      boolean useAccelerateInterpolator,
      long fixedDuration) {
    final View animView = mCallback.getChildContentView(view);
    final boolean canAnimViewBeDismissed = mCallback.canChildBeDismissed(view);
    float newPos;

    if (velocity < 0
        || (velocity == 0 && getTranslation(animView) < 0)
        // if we use the Menu to dismiss an item in landscape, animate up
        || (velocity == 0 && getTranslation(animView) == 0 && mSwipeDirection == Y)) {
      newPos = -getSize(animView);
    } else {
      newPos = getSize(animView);
    }
    long duration;
    if (fixedDuration == 0) {
      duration = MAX_ESCAPE_ANIMATION_DURATION;
      if (velocity != 0) {
        duration =
            Math.min(
                duration,
                (int) (Math.abs(newPos - getTranslation(animView)) * 1000f / Math.abs(velocity)));
      } else {
        duration = DEFAULT_ESCAPE_ANIMATION_DURATION;
      }
    } else {
      duration = fixedDuration;
    }

    animView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    ObjectAnimator anim = createTranslationAnimation(animView, newPos);
    if (useAccelerateInterpolator) {
      anim.setInterpolator(mFastOutLinearInInterpolator);
    } else {
      anim.setInterpolator(sLinearInterpolator);
    }
    anim.setDuration(duration);
    if (delay > 0) {
      anim.setStartDelay(delay);
    }
    anim.addListener(
        new AnimatorListenerAdapter() {
          public void onAnimationEnd(Animator animation) {
            mCallback.onChildDismissed(view);
            if (endAction != null) {
              endAction.run();
            }
            animView.setLayerType(View.LAYER_TYPE_NONE, null);
          }
        });
    anim.addUpdateListener(
        new AnimatorUpdateListener() {
          public void onAnimationUpdate(ValueAnimator animation) {
            updateSwipeProgressFromOffset(animView, canAnimViewBeDismissed);
          }
        });
    anim.start();
  }
 public boolean b(MotionEvent paramMotionEvent)
 {
   if (!p) {
     return false;
   }
   n.addMovement(paramMotionEvent);
   float f1;
   float f3;
   float f2;
   switch (paramMotionEvent.getAction())
   {
   default: 
   case 2: 
   case 4: 
     do
     {
       return true;
     } while (r == null);
     f1 = paramMotionEvent.getX() - o;
     if (Math.abs(f1) < j) {
       return true;
     }
     if (!b.a(r))
     {
       f3 = b(s);
       f2 = 0.05F * f3;
       if (Math.abs(f1) >= f3) {
         if (f1 > 0.0F) {
           f1 = f2;
         }
       }
     }
     break;
   }
   for (;;)
   {
     label135:
     b.b(r, (int)Math.signum(f1));
     paramMotionEvent = s;
     if (m == 0) {
       paramMotionEvent.setTranslationX(f1);
     }
     for (;;)
     {
       a(r.a());
       break;
       f1 = -f2;
       break label135;
       f1 = f2 * (float)Math.sin(f1 / f3 * 1.5707963267948966D);
       break label135;
       paramMotionEvent.setTranslationY(f1);
     }
     if (r == null) {
       break;
     }
     f1 = h;
     f2 = u;
     n.computeCurrentVelocity(1000, f1 * f2);
     f3 = e;
     float f4 = u;
     paramMotionEvent = n;
     label277:
     label294:
     label333:
     int i2;
     label367:
     int i3;
     if (m == 0)
     {
       f1 = paramMotionEvent.getXVelocity();
       paramMotionEvent = n;
       if (m != 0) {
         break label651;
       }
       f2 = paramMotionEvent.getYVelocity();
       float f5 = Math.abs(s.getTranslationX());
       float f6 = b(s);
       if (f5 <= 0.4D * f6) {
         break label659;
       }
       i1 = 1;
       if ((Math.abs(f1) <= f3 * f4) || (Math.abs(f1) <= Math.abs(f2))) {
         break label677;
       }
       if (f1 <= 0.0F) {
         break label665;
       }
       i2 = 1;
       if (s.getTranslationX() <= 0.0F) {
         break label671;
       }
       i3 = 1;
       label382:
       if ((i2 != i3) || (f5 <= f6 * 0.05D)) {
         break label677;
       }
       i2 = 1;
       label406:
       if ((!b.a(r)) || ((i2 == 0) && (i1 == 0))) {
         break label683;
       }
       i1 = 1;
       label435:
       if (i1 == 0) {
         break label712;
       }
       paramMotionEvent = r;
       if (i2 == 0) {
         break label689;
       }
       label450:
       localView = r.a();
       if ((f1 >= 0.0F) && ((f1 != 0.0F) || (localView.getTranslationX() >= 0.0F)) && ((f1 != 0.0F) || (localView.getTranslationX() != 0.0F) || (m != 1))) {
         break label694;
       }
       f2 = -b(localView);
       label515:
       i1 = g;
       if (f1 == 0.0F) {
         break label704;
       }
     }
     label651:
     label659:
     label665:
     label671:
     label677:
     label683:
     label689:
     label694:
     label704:
     for (int i1 = Math.min(i1, (int)(Math.abs(f2 - localView.getTranslationX()) * 1000.0F / Math.abs(f1)));; i1 = f)
     {
       if ((localView != null) && (localView.isHardwareAccelerated()))
       {
         localView.setLayerType(2, null);
         localView.buildLayer();
       }
       localObjectAnimator = a(localView, f2);
       localObjectAnimator.setInterpolator(d);
       localObjectAnimator.setDuration(i1);
       localObjectAnimator.addListener(new crl(this, localView, paramMotionEvent));
       localObjectAnimator.addUpdateListener(new crm(this, localView));
       localObjectAnimator.start();
       break;
       f1 = paramMotionEvent.getYVelocity();
       break label277;
       f2 = paramMotionEvent.getXVelocity();
       break label294;
       i1 = 0;
       break label333;
       i2 = 0;
       break label367;
       i3 = 0;
       break label382;
       i2 = 0;
       break label406;
       i1 = 0;
       break label435;
       f1 = 0.0F;
       break label450;
       f2 = b(localView);
       break label515;
     }
     label712:
     paramMotionEvent = r;
     View localView = paramMotionEvent.a();
     ObjectAnimator localObjectAnimator = a(localView, 0.0F);
     localObjectAnimator.setDuration(i);
     localObjectAnimator.addUpdateListener(new crn(this, localView));
     localObjectAnimator.addListener(new cro(this, paramMotionEvent, localObjectAnimator, localView));
     localObjectAnimator.start();
     break;
   }
 }