public void startRippleAnimation(
      final int centerX, final int centerY, int min, int max, boolean expand) {

    isAnimation = true;

    ValueAnimator valueAnimator;

    if (expand) valueAnimator = ValueAnimator.ofInt(min, max);
    else valueAnimator = ValueAnimator.ofInt(max, 0);

    valueAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            path.reset();
            path.addCircle(centerX, centerY, (int) animation.getAnimatedValue(), Path.Direction.CW);
            path.close();
            invalidate();
          }
        });

    valueAnimator.setInterpolator(interpolator);
    valueAnimator.setDuration(duration).start();
    postDelayed(
        new Runnable() {
          @Override
          public void run() {
            isAnimation = false;
          }
        },
        duration);
  }
  private void initBackgroundDimAnimation() {
    final int maxAlpha = Color.alpha(mBackgroundColor);
    final int red = Color.red(mBackgroundColor);
    final int green = Color.green(mBackgroundColor);
    final int blue = Color.blue(mBackgroundColor);

    mShowBackgroundAnimator = ValueAnimator.ofInt(0, maxAlpha);
    mShowBackgroundAnimator.setDuration(ANIMATION_DURATION);
    mShowBackgroundAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            Integer alpha = (Integer) animation.getAnimatedValue();
            setBackgroundColor(Color.argb(alpha, red, green, blue));
          }
        });

    mHideBackgroundAnimator = ValueAnimator.ofInt(maxAlpha, 0);
    mHideBackgroundAnimator.setDuration(ANIMATION_DURATION);
    mHideBackgroundAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            Integer alpha = (Integer) animation.getAnimatedValue();
            setBackgroundColor(Color.argb(alpha, red, green, blue));
          }
        });
  }
Beispiel #3
0
  private void animateOut() {
    ValueAnimator animWidth = ValueAnimator.ofInt(zoomableImageView.getMeasuredWidth(), rect.right);
    animWidth.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams();
            layoutParams.width = val;
            zoomableImageView.setLayoutParams(layoutParams);
          }
        });
    animWidth.setDuration(500);
    animWidth.start();

    ValueAnimator animHeight =
        ValueAnimator.ofInt(zoomableImageView.getMeasuredHeight(), rect.bottom);
    animHeight.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams();
            layoutParams.height = val;
            zoomableImageView.setLayoutParams(layoutParams);
          }
        });
    animHeight.setDuration(500);
    animHeight.start();
    if (statusBarHeightCorrection > 0) {
      zoomableImageView.animate().y(-statusBarHeightCorrection).setDuration(300).start();
    }
    zoomableImageView.animate().alpha(0.0f).setDuration(500).start();
  }
  private void performDismiss() {
    // Animate the dismissed view to zero-height and then fire the dismiss callback.
    // This triggers layout on each animation frame; in the future we may want to do something
    // smarter and more performant.

    final ViewGroup.LayoutParams lp = mView.getLayoutParams();
    final int originalHeight = mView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            mCallbacks.onDismiss(mView, mToken);
            // Reset view presentation
            mView.setAlpha(1f);
            mView.setTranslationX(0);
            lp.height = originalHeight;
            mView.setLayoutParams(lp);
          }
        });

    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            mView.setLayoutParams(lp);
          }
        });

    animator.start();
  }
  private void performDismiss(
      final View dismissView, final int dismissPosition, final int direction) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(createAnimatorListener(originalHeight));

    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
          }
        });

    mPendingDismisses.add(new PendingDismissData(dismissPosition, direction, dismissView));
    animator.start();
  }
  private void scrollToTarget(int target, final Runnable after) {
    int scrollX = getScrollX();
    if (scrollX == target) {
      if (after != null) after.run();
    } else {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        ValueAnimator realSmoothScrollAnimation =
            ValueAnimator.ofInt(scrollX, target).setDuration(500);
        realSmoothScrollAnimation.setInterpolator(new DecelerateInterpolator());
        realSmoothScrollAnimation.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                scrollTo((Integer) animation.getAnimatedValue(), 0);
              }
            });

        realSmoothScrollAnimation.addListener(
            new AnimatorListenerAdapter() {
              @Override
              public void onAnimationEnd(Animator animation) {
                if (after != null) after.run();
              }
            });
        realSmoothScrollAnimation.start();
      } else {
        smoothScrollTo(target, 0);
        if (after != null) after.run();
      }
    }
  }
  @Override
  public List<Animator> createAnimation() {
    List<Animator> animators = new ArrayList<>();

    int[] durations = {960, 930, 1190, 1130, 1340, 940, 1200, 820, 1190};
    int[] delays = {360, 400, 680, 410, 710, -150, -120, 10, 320};

    for (int i = 0; i < 9; i++) {
      final int index = i;
      ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 168, 255);
      alphaAnim.setDuration(durations[i]);
      alphaAnim.setRepeatCount(-1);
      alphaAnim.setStartDelay(delays[i]);
      alphaAnim.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              alphas[index] = (int) animation.getAnimatedValue();
              postInvalidate();
            }
          });
      alphaAnim.start();
      animators.add(alphaAnim);
    }
    return animators;
  }
Beispiel #8
0
 public void start(int a) {
   v = ValueAnimator.ofInt(0, 1000);
   v.setDuration(a);
   v.addUpdateListener(this);
   playing = true;
   v.start();
 }
Beispiel #9
0
 public void stop() {
   playing = false;
   v.cancel();
   ValueAnimator v2 = ValueAnimator.ofInt(0, 100);
   v2.setDuration(200);
   v2.addUpdateListener(this);
   v2.start();
 }
  private void expend() {
    int height = 0;
    int targeHeight = getMeasureHeight();
    if (!isOpen) {
      isOpen = true;
      valueAnimator = ValueAnimator.ofInt(height, targeHeight);
    } else {
      isOpen = false;
      // 缩回
      valueAnimator = ValueAnimator.ofInt(targeHeight, height);
    }
    // 监听弹出操作
    valueAnimator.addUpdateListener(
        new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator arg0) {
            // 可以获取当前的控件所在的高度值
            layoutParams.height = (Integer) arg0.getAnimatedValue();
            ll_footer.setLayoutParams(layoutParams);
          }
        });
    // 监听动画完成后的操作
    valueAnimator.addListener(
        new AnimatorListener() {
          @Override
          public void onAnimationStart(Animator arg0) {}

          @Override
          public void onAnimationRepeat(Animator arg0) {}

          @Override
          public void onAnimationEnd(Animator arg0) {
            if (isOpen) {
              arrow.setBackgroundResource(R.drawable.arrow_up);
            } else {
              arrow.setBackgroundResource(R.drawable.arrow_down);
            }
          }

          @Override
          public void onAnimationCancel(Animator arg0) {}
        });

    valueAnimator.start();
    valueAnimator.setDuration(100);
  }
Beispiel #11
0
 public void setProportionWithAnimation(int proportion) {
   ValueAnimator valueAnimator = ValueAnimator.ofInt(0, proportion);
   valueAnimator.setDuration(animationLoadingDuration);
   valueAnimator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           setProportion((Integer) animation.getAnimatedValue());
         }
       });
   valueAnimator.start();
 }
 /** 设置下拉刷新控件的paddingTop到0,带动画 */
 private void changeRefreshHeaderViewToZero() {
   ValueAnimator animator = ValueAnimator.ofInt(mWholeHeaderView.getPaddingTop(), 0);
   animator.setDuration(mRefreshViewHolder.getTopAnimDuration());
   animator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           int paddingTop = (int) animation.getAnimatedValue();
           mWholeHeaderView.setPadding(0, paddingTop, 0, 0);
         }
       });
   animator.start();
 }
 public void animateToFullSize() {
   final ValueAnimator animator = ValueAnimator.ofInt(getLevel(), DRAWABLE_MAX_LEVEL);
   animator.setDuration(CIRCLE_ANIM_DURATION_MS);
   animator.setInterpolator(Gusterpolator.INSTANCE);
   animator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           setLevel((Integer) animation.getAnimatedValue());
         }
       });
   animator.start();
 }
  private void initIfNecessary(TextPaint tp) {
    if (jumpAnimator != null) {
      return;
    }

    shift = (int) tp.ascent() / 2;
    jumpAnimator = ValueAnimator.ofInt(0, shift, 0);
    jumpAnimator.setDuration(loopDuration).setStartDelay(delay);
    jumpAnimator.setInterpolator(new JumpInterpolator(animatedRange));
    jumpAnimator.setRepeatCount(ValueAnimator.INFINITE);
    jumpAnimator.setRepeatMode(ValueAnimator.RESTART);
    jumpAnimator.addUpdateListener(this);
    jumpAnimator.start();
  }
  private void initIfNecessary(float ascent) {
    if (jumpAnimator != null) {
      return;
    }

    this.shift = 0;
    int maxShift = (int) ascent / 2;
    jumpAnimator = ValueAnimator.ofInt(0, maxShift);
    jumpAnimator.setDuration(loopDuration).setStartDelay(delay);
    jumpAnimator.setInterpolator(new JumpInterpolator(animatedRange));
    jumpAnimator.setRepeatCount(ValueAnimator.INFINITE);
    jumpAnimator.setRepeatMode(ValueAnimator.RESTART);
    jumpAnimator.addUpdateListener(this);
    jumpAnimator.start();
  }
 private void animateLastRequests(int from, int to) {
   suggestionsVisible = to > 0 ? true : false;
   final RelativeLayout last = (RelativeLayout) findViewById(R.id.last);
   final ViewGroup.LayoutParams lp = last.getLayoutParams();
   ValueAnimator animator = ValueAnimator.ofInt(from, to);
   animator.setDuration(200);
   animator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           lp.height = (int) animation.getAnimatedValue();
           last.setLayoutParams(lp);
         }
       });
   if (adapter.getItemCount() > 0) animator.start();
 }
  /** Value Animators * */
  private ValueAnimator translateSections(int start, int end) {

    ValueAnimator animator = ValueAnimator.ofInt(start, end);

    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            // Update Height
            int value = (Integer) valueAnimator.getAnimatedValue();
            main_sections.setY(value);
          }
        });
    animator.setInterpolator(new DecelerateInterpolator());
    return animator.setDuration(animation_duration);
  }
  /** Hide the SuperCardToast and animate the Layout. Post Honeycomb only. * */
  @SuppressLint("NewApi")
  private void dismissWithLayoutAnimation() {

    if (mToastView != null) {

      mToastView.setVisibility(View.INVISIBLE);

      final ViewGroup.LayoutParams layoutParams = mToastView.getLayoutParams();
      final int originalHeight = mToastView.getHeight();

      ValueAnimator animator =
          ValueAnimator.ofInt(originalHeight, 1)
              .setDuration(
                  mContext.getResources().getInteger(android.R.integer.config_shortAnimTime));

      animator.addListener(
          new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {

              Handler mHandler = new Handler();
              mHandler.post(mHideImmediateRunnable);
            }
          });

      animator.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {

              if (mToastView != null) {

                layoutParams.height = (Integer) valueAnimator.getAnimatedValue();
                mToastView.setLayoutParams(layoutParams);
              }
            }
          });

      animator.start();

    } else {

      dismissImmediately();
    }
  }
  private ValueAnimator slideAnimator(int start, int end, final View v) {

    ValueAnimator animator = ValueAnimator.ofInt(start, end);

    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            // Update Height
            int value = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
            layoutParams.height = value;
            v.setLayoutParams(layoutParams);
          }
        });
    return animator;
  }
 private void _mth02CB(TextView textview, EditText edittext)
 {
     if (textview.getVisibility() != 0)
     {
         return;
     } else
     {
         ValueAnimator valueanimator = ValueAnimator.ofInt(new int[] {
             brt, 0
         });
         valueanimator.addUpdateListener(new ali(this, textview));
         valueanimator.addListener(new ala(this, textview, edittext));
         valueanimator.setDuration(180L);
         valueanimator.start();
         return;
     }
 }
  private void startRippleAnim() {
    mStatus = RIPPLE;
    rippleAnimator = ValueAnimator.ofFloat(mRippleWidth, mMaxRippleWidth);
    rippleAlphaAnimator = ValueAnimator.ofInt(255, 0);
    rippleAnimator.setDuration(mRippleDuration);
    rippleAlphaAnimator.setDuration(mRippleDuration);
    rippleAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mRippleWidth = (Float) animation.getAnimatedValue();
          }
        });
    rippleAlphaAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mRippleAlpha = (int) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    rippleAnimator.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {
            mRippleWidth = mInitRippleWidth;
            mRippleAlpha = 255;
            startLineAnim();
          }

          @Override
          public void onAnimationCancel(Animator animation) {
            mRippleWidth = mInitRippleWidth;
            mRippleAlpha = 255;
          }

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
    AnimatorSet animSet = new AnimatorSet();
    animSet.playTogether(rippleAnimator, rippleAlphaAnimator);
    animSet.start();
  }
  /** 对TextView进行伸缩处理 */
  private void flexibleHeight() {
    isExpand = !isExpand;
    int textHeight = 0;
    float startDegree = 0.0f;
    float endDegree = 180.0f;
    if (isExpand) {
      // 如果是展开模式,那么取消最大行为maxLine的限制
      textHeight = contentLine * mTextView.getLineHeight();
      mTextView.setMaxLines(contentLine);
    } else {
      textHeight = mTextView.getLineHeight() * maxLine;
      endDegree = 0.0f;
      startDegree = 180.0f;
    }
    final LayoutParams mParam = (LayoutParams) mTextView.getLayoutParams();
    // TextView的平移动画
    ValueAnimator animator_textView = ValueAnimator.ofInt(mTextView.getHeight(), textHeight);
    animator_textView.addUpdateListener(
        new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mParam.height = (Integer) animation.getAnimatedValue();
            mTextView.setLayoutParams(mParam);
          }
        });
    // imageView的旋转动画
    ObjectAnimator animator_img =
        ObjectAnimator.ofFloat(mImageView, "rotation", startDegree, endDegree);

    AnimatorSet mAnimatorSets = new AnimatorSet();
    mAnimatorSets.setDuration(500);
    mAnimatorSets.play(animator_img).with(animator_textView);
    mAnimatorSets.start();
    mAnimatorSets.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            // 动画结束之后,如果是非展开模式,则设置最大行数为maxLine
            if (!isExpand) {
              mTextView.setMaxLines(maxLine);
            }
          }
        });
  }
 private void _mth02CA(TextView textview, EditText edittext)
 {
     if (textview.getVisibility() == 0)
     {
         return;
     } else
     {
         textview.setVisibility(0);
         ValueAnimator valueanimator = ValueAnimator.ofInt(new int[] {
             0, brt
         });
         valueanimator.addUpdateListener(new alg(this, textview));
         valueanimator.addListener(new alh(this, edittext));
         valueanimator.setDuration(180L);
         valueanimator.start();
         return;
     }
 }
  private void animateScanMediaMessage() {
    TranslateAnimation anim = new TranslateAnimation(0, 0, -200, 0);
    anim.setDuration(900);
    messageContainer.startAnimation(anim);

    ValueAnimator animator = ValueAnimator.ofInt(initialCourseListPadding, 90);
    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          // @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            courseList.setPadding(0, (Integer) valueAnimator.getAnimatedValue(), 0, 0);
            courseList.setSelectionAfterHeaderView();
          }
        });
    animator.setStartDelay(200);
    animator.setDuration(700);
    animator.start();
  }
 public void animateToSmallRadius() {
   int smallLevel =
       map(
           mSmallRadiusTarget,
           0,
           diagonalLength(mCanvasWidth, mCanvasHeight) / 2,
           0,
           DRAWABLE_MAX_LEVEL);
   final ValueAnimator animator = ValueAnimator.ofInt(getLevel(), smallLevel);
   animator.setDuration(CIRCLE_ANIM_DURATION_MS);
   animator.setInterpolator(Gusterpolator.INSTANCE);
   animator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           setLevel((Integer) animation.getAnimatedValue());
         }
       });
   animator.start();
 }
  private void processPendingDismisses(final PendingDismissData pendingDismissData) {
    mPendingDismiss = null;
    final ViewGroup.LayoutParams lp = pendingDismissData.rowContainer.container.getLayoutParams();
    final int originalHeight = pendingDismissData.rowContainer.container.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            if (mCallbacks.canDismiss(pendingDismissData.position))
              mCallbacks.onDismiss(mRecyclerView, pendingDismissData.position);
            pendingDismissData.rowContainer.dataContainer.post(
                new Runnable() {
                  @Override
                  public void run() {
                    pendingDismissData.rowContainer.dataContainer.setTranslationX(0);
                    pendingDismissData.rowContainer.dataContainer.setAlpha(1);
                    pendingDismissData.rowContainer.undoContainer.setVisibility(View.GONE);
                    pendingDismissData.rowContainer.undoContainer.setTranslationX(0);
                    pendingDismissData.rowContainer.undoContainer.setAlpha(1);

                    lp.height = originalHeight;
                    pendingDismissData.rowContainer.container.setLayoutParams(lp);
                  }
                });
          }
        });

    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            pendingDismissData.rowContainer.container.setLayoutParams(lp);
          }
        });

    animator.start();
  }
  /**
   * 指定座標に移動します。<br>
   * 画面端の座標を超える場合は、自動的に画面端に移動します。
   *
   * @param currentX 現在のX座標(アニメーションの始点用に使用)
   * @param currentY 現在のY座標(アニメーションの始点用に使用)
   * @param goalPositionX 移動先のX座標
   * @param goalPositionY 移動先のY座標
   * @param withAnimation アニメーションを行う場合はtrue.行わない場合はfalse
   */
  private void moveTo(
      int currentX, int currentY, int goalPositionX, int goalPositionY, boolean withAnimation) {
    // 画面端からはみ出さないように調整
    goalPositionX =
        Math.min(Math.max(mPositionLimitRect.left, goalPositionX), mPositionLimitRect.right);
    goalPositionY =
        Math.min(Math.max(mPositionLimitRect.top, goalPositionY), mPositionLimitRect.bottom);
    // アニメーションを行う場合
    if (withAnimation) {
      // TODO:Y座標もアニメーションさせる
      mParams.y = goalPositionY;

      mMoveEdgeAnimator = ValueAnimator.ofInt(currentX, goalPositionX);
      mMoveEdgeAnimator.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              mParams.x = (Integer) animation.getAnimatedValue();
              mWindowManager.updateViewLayout(FloatingView.this, mParams);
            }
          });
      // X軸のアニメーション設定
      mMoveEdgeAnimator.setDuration(MOVE_TO_EDGE_DURATION);
      mMoveEdgeAnimator.setInterpolator(mMoveEdgeInterpolator);
      mMoveEdgeAnimator.start();
    } else {
      // 位置が変化した時のみ更新
      if (mParams.x != goalPositionX || mParams.y != goalPositionY) {
        mParams.x = goalPositionX;
        mParams.y = goalPositionY;
        mWindowManager.updateViewLayout(FloatingView.this, mParams);
      }
    }
    // タッチ座標を初期化
    mLocalTouchX = 0;
    mLocalTouchY = 0;
    mScreenTouchDownX = 0;
    mScreenTouchDownY = 0;
    mIsMoveAccept = false;
  }
  private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
              // No active animations, process all pending dismisses.
              // Sort by descending position
              Collections.sort(mPendingDismisses);

              int[] dismissPositions = new int[mPendingDismisses.size()];
              for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                dismissPositions[i] = mPendingDismisses.get(i).position;
              }
              mCallbacks.onDismiss(mListView, dismissPositions);

              // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
              // animation with a stale position
              mDownPosition = ListView.INVALID_POSITION;

              ViewGroup.LayoutParams lp;
              for (PendingDismissData pendingDismiss : mPendingDismisses) {
                // Reset view presentation
                pendingDismiss.view.setAlpha(1f);
                pendingDismiss.view.setTranslationX(0);
                lp = pendingDismiss.view.getLayoutParams();
                lp.height = 0;
                pendingDismiss.view.setLayoutParams(lp);
              }

              // Send a cancel event
              long time = SystemClock.uptimeMillis();
              MotionEvent cancelEvent =
                  MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
              mListView.dispatchTouchEvent(cancelEvent);

              mPendingDismisses.clear();
            }
          }
        });

    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
          }
        });

    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
  }
  @Override
  public Animator createAnimator(
      ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null
        || endValues == null
        || !(startValues.view instanceof TextView)
        || !(endValues.view instanceof TextView)) {
      return null;
    }
    final TextView view = (TextView) endValues.view;
    Map<String, Object> startVals = startValues.values;
    Map<String, Object> endVals = endValues.values;
    final CharSequence startText =
        startVals.get(PROPNAME_TEXT) != null ? (CharSequence) startVals.get(PROPNAME_TEXT) : "";
    final CharSequence endText =
        endVals.get(PROPNAME_TEXT) != null ? (CharSequence) endVals.get(PROPNAME_TEXT) : "";
    final int startSelectionStart, startSelectionEnd, endSelectionStart, endSelectionEnd;
    if (view instanceof EditText) {
      startSelectionStart =
          startVals.get(PROPNAME_TEXT_SELECTION_START) != null
              ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_START)
              : -1;
      startSelectionEnd =
          startVals.get(PROPNAME_TEXT_SELECTION_END) != null
              ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_END)
              : startSelectionStart;
      endSelectionStart =
          endVals.get(PROPNAME_TEXT_SELECTION_START) != null
              ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_START)
              : -1;
      endSelectionEnd =
          endVals.get(PROPNAME_TEXT_SELECTION_END) != null
              ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_END)
              : endSelectionStart;
    } else {
      startSelectionStart = startSelectionEnd = endSelectionStart = endSelectionEnd = -1;
    }
    if (!startText.equals(endText)) {
      final int startColor;
      final int endColor;
      if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
        view.setText(startText);
        if (view instanceof EditText) {
          setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
        }
      }
      Animator anim;
      if (mChangeBehavior == CHANGE_BEHAVIOR_KEEP) {
        startColor = endColor = 0;
        anim = ValueAnimator.ofFloat(0, 1);
        anim.addListener(
            new AnimatorListenerAdapter() {
              @Override
              public void onAnimationEnd(Animator animation) {
                if (startText.equals(view.getText())) {
                  // Only set if it hasn't been changed since anim started
                  view.setText(endText);
                  if (view instanceof EditText) {
                    setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                  }
                }
              }
            });
      } else {
        startColor = (Integer) startVals.get(PROPNAME_TEXT_COLOR);
        endColor = (Integer) endVals.get(PROPNAME_TEXT_COLOR);
        // Fade out start text
        ValueAnimator outAnim = null, inAnim = null;
        if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_OUT) {
          outAnim = ValueAnimator.ofInt(255, 0);
          outAnim.addUpdateListener(
              new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                  int currAlpha = (Integer) animation.getAnimatedValue();
                  view.setTextColor(
                      currAlpha << 24
                          | startColor & 0xff0000
                          | startColor & 0xff00
                          | startColor & 0xff);
                }
              });
          outAnim.addListener(
              new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                  if (startText.equals(view.getText())) {
                    // Only set if it hasn't been changed since anim started
                    view.setText(endText);
                    if (view instanceof EditText) {
                      setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                    }
                  }
                  // restore opaque alpha and correct end color
                  view.setTextColor(endColor);
                }
              });
        }
        if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_IN) {
          inAnim = ValueAnimator.ofInt(0, 255);
          inAnim.addUpdateListener(
              new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                  int currAlpha = (Integer) animation.getAnimatedValue();
                  view.setTextColor(
                      currAlpha << 24
                          | Color.red(endColor) << 16
                          | Color.green(endColor) << 8
                          | Color.red(endColor));
                }
              });
          inAnim.addListener(
              new AnimatorListenerAdapter() {
                @Override
                public void onAnimationCancel(Animator animation) {
                  // restore opaque alpha and correct end color
                  view.setTextColor(endColor);
                }
              });
        }
        if (outAnim != null && inAnim != null) {
          anim = new AnimatorSet();
          ((AnimatorSet) anim).playSequentially(outAnim, inAnim);
        } else if (outAnim != null) {
          anim = outAnim;
        } else {
          // Must be an in-only animation
          anim = inAnim;
        }
      }
      TransitionListener transitionListener =
          new TransitionListenerAdapter() {
            int mPausedColor = 0;

            @Override
            public void onTransitionPause(Transition transition) {
              if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
                view.setText(endText);
                if (view instanceof EditText) {
                  setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                }
              }
              if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
                mPausedColor = view.getCurrentTextColor();
                view.setTextColor(endColor);
              }
            }

            @Override
            public void onTransitionResume(Transition transition) {
              if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
                view.setText(startText);
                if (view instanceof EditText) {
                  setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
                }
              }
              if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
                view.setTextColor(mPausedColor);
              }
            }
          };
      addListener(transitionListener);
      if (DBG) {
        Log.d(LOG_TAG, "createAnimator returning " + anim);
      }
      return anim;
    }
    return null;
  }
Beispiel #30
0
  private void animateIn(final Dialog dialog) {
    RelativeLayout.LayoutParams params =
        (RelativeLayout.LayoutParams) zoomableImageView.getLayoutParams();
    params.width = rect.right;
    params.height = rect.bottom;
    zoomableImageView.setLayoutParams(params);

    zoomableImageView.setX(rect.left);
    zoomableImageView.setY(rect.top - statusBarHeightCorrection);
    zoomableImageView.setAlpha(0.0f);
    zoomableImageView.setImageBitmap(bitmap);

    WindowManager win = getActivity().getWindowManager();
    Display d = win.getDefaultDisplay();
    int displayWidth = d.getWidth(); // Width of the actual device
    int displayHeight = d.getHeight() + statusBarHeightCorrection;

    ValueAnimator animWidth = ValueAnimator.ofInt(rect.right, displayWidth);
    animWidth.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams();
            layoutParams.width = val;
            zoomableImageView.setLayoutParams(layoutParams);
          }
        });
    animWidth.setDuration(500);
    animWidth.setInterpolator(new LinearOutSlowInInterpolator());
    animWidth.start();

    ValueAnimator animHeight = ValueAnimator.ofInt(rect.bottom, displayHeight);
    animHeight.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams();
            layoutParams.height = val;
            zoomableImageView.setLayoutParams(layoutParams);
          }
        });
    animHeight.setDuration(500);
    animHeight.setInterpolator(new LinearOutSlowInInterpolator());

    animHeight.start();

    if (statusBarHeightCorrection > 0) {
      zoomableImageView.animate().y(0.0f).setDuration(300).start();
    }

    ValueAnimator animDim = ValueAnimator.ofFloat(0.0f, 0.5f);
    animDim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
            layoutParams.copyFrom(dialog.getWindow().getAttributes());
            layoutParams.dimAmount = (Float) valueAnimator.getAnimatedValue();
            dialog.getWindow().setAttributes(layoutParams);
          }
        });
    animDim.setDuration(300);
    animDim.setStartDelay(300);
    animDim.start();
    zoomableImageView.animate().alpha(1.0f).setDuration(300).start();
  }