@Override
  public List<Animator> createAnimation() {
    List<Animator> animators = new ArrayList<Animator>();
    ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.6f, 1);
    scaleAnim.setDuration(1000);
    scaleAnim.setRepeatCount(-1);
    scaleAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            scaleFloat = (Float) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    scaleAnim.start();

    ValueAnimator rotateAnim = ValueAnimator.ofFloat(0, 180, 360);
    rotateAnim.setDuration(1000);
    rotateAnim.setRepeatCount(-1);
    rotateAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            degrees = (Float) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    rotateAnim.start();
    animators.add(scaleAnim);
    animators.add(rotateAnim);
    return animators;
  }
  private void setup(int duration) {
    // region saturation
    animationSaturation = ValueAnimator.ofFloat(0.2f, 1f);
    animationSaturation.setDuration(duration);
    animationSaturation.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            saturation = animation.getAnimatedFraction();
          }
        });
    // endregion

    // region contrast
    animationContrast = ValueAnimator.ofFloat(0, 1f);
    animationContrast.setDuration(duration * 3 / 4);
    animationContrast.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            ColorMatrix colorMatrix = setContrast(animation.getAnimatedFraction());
            colorMatrix.setSaturation(saturation);
            ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
            drawable.setColorFilter(colorFilter);
          }
        });
    // endregion

    // region alpha
    animationAlpha = ObjectAnimator.ofFloat(imageView, "alpha", 0f, 1f);
    animationAlpha.setDuration(duration / 2);
    // endregion
  }
  @Override
  public void createAnimation() {
    float startX = getWidth() / 6;
    float startY = getWidth() / 6;
    for (int i = 0; i < 2; i++) {
      final int index = i;
      ValueAnimator translateXAnim =
          ValueAnimator.ofFloat(startX, getWidth() - startX, startX, getWidth() - startX, startX);
      if (i == 1) {
        translateXAnim =
            ValueAnimator.ofFloat(
                getWidth() - startX, startX, getWidth() - startX, startX, getWidth() - startX);
      }
      ValueAnimator translateYAnim =
          ValueAnimator.ofFloat(startY, startY, getHeight() - startY, getHeight() - startY, startY);
      if (i == 1) {
        translateYAnim =
            ValueAnimator.ofFloat(
                getHeight() - startY, getHeight() - startY, startY, startY, getHeight() - startY);
      }

      translateXAnim.setDuration(2000);
      translateXAnim.setInterpolator(new LinearInterpolator());
      translateXAnim.setRepeatCount(-1);
      translateXAnim.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              translateX[index] = (float) animation.getAnimatedValue();
              postInvalidate();
            }
          });
      translateXAnim.start();

      translateYAnim.setDuration(2000);
      translateYAnim.setInterpolator(new LinearInterpolator());
      translateYAnim.setRepeatCount(-1);
      translateYAnim.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              translateY[index] = (float) animation.getAnimatedValue();
              postInvalidate();
            }
          });
      translateYAnim.start();
    }
  }
  @Override
  public List<Animator> createAnimation() {
    List<Animator> animators = new ArrayList<Animator>();

    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] = (Integer) animation.getAnimatedValue();
              postInvalidate();
            }
          });
      alphaAnim.start();
      animators.add(alphaAnim);
    }
    return animators;
  }
Esempio n. 5
0
  public void duang() {
    mStatus = Status.STATUS_DOWN;
    ValueAnimator valueAnimator = ValueAnimator.ofInt(mMaxArcHeight, 0);
    valueAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mArcHeight = (int) animation.getAnimatedValue();
            invalidate();
          }
        });
    valueAnimator.addListener(
        new SimpleAnimationListener() {

          @Override
          public void onAnimationEnd(Animator animation) {
            if (mAnimationListener != null) {
              mAnimationListener.onEnd();
            }
          }
        });
    valueAnimator.setDuration(500);
    valueAnimator.setInterpolator(new OvershootInterpolator(5f));
    valueAnimator.start();
  }
Esempio n. 6
0
  public void show() {
    mStatus = Status.STATUS_SMOOTH_UP;

    if (mAnimationListener != null) {
      mAnimationListener.onStart();
      this.postDelayed(
          new Runnable() {
            @Override
            public void run() {

              mAnimationListener.onContentShow();
            }
          },
          600);
    }

    ValueAnimator valueAnimator = ValueAnimator.ofInt(0, mMaxArcHeight);
    valueAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            int value = (int) animation.getAnimatedValue();
            mArcHeight = value;

            if (value == mMaxArcHeight) {
              duang();
            }
            invalidate();
          }
        });
    valueAnimator.setDuration(800);
    valueAnimator.setInterpolator(new AccelerateInterpolator());
    valueAnimator.start();
  }
  /**
   * @param anim The animator, must not be null
   * @param arrayAnimator Incoming typed array for Animator's attributes.
   * @param arrayObjectAnimator Incoming typed array for Object Animator's attributes.
   */
  private static void parseAnimatorFromTypeArray(
      ValueAnimator anim, TypedArray arrayAnimator, TypedArray arrayObjectAnimator) {
    long duration = arrayAnimator.getInt(R.styleable.Animator_android_duration, 300);

    long startDelay = arrayAnimator.getInt(R.styleable.Animator_android_startOffset, 0);

    int valueType = arrayAnimator.getInt(R.styleable.Animator_vc_valueType, 0);

    TypeEvaluator evaluator = null;

    // Must be a path animator by the time I reach here
    if (valueType == VALUE_TYPE_PATH) {
      evaluator = setupAnimatorForPath(anim, arrayAnimator);
    } else {
      throw new IllegalArgumentException("target is not a pathType target");
    }

    anim.setDuration(duration);
    anim.setStartDelay(startDelay);

    if (arrayAnimator.hasValue(R.styleable.Animator_android_repeatCount)) {
      anim.setRepeatCount(arrayAnimator.getInt(R.styleable.Animator_android_repeatCount, 0));
    }
    if (arrayAnimator.hasValue(R.styleable.Animator_android_repeatMode)) {
      anim.setRepeatMode(
          arrayAnimator.getInt(R.styleable.Animator_android_repeatMode, ValueAnimator.RESTART));
    }
    if (evaluator != null) {
      anim.setEvaluator(evaluator);
    }

    if (arrayObjectAnimator != null) {
      setupObjectAnimator(anim, arrayObjectAnimator);
    }
  }
  public void animateSubjectOut(final SubjectCard materia) {
    final List<View> toBeAnimated = new ArrayList<View>();
    boolean after = false;
    for (SubjectCard mtr : mSubjectCards) {
      if (after) toBeAnimated.add(mtr);
      if (mtr == materia) after = true;
    }
    toBeAnimated.add(mAddButton);
    final int numberToBeAnimated = toBeAnimated.size();

    int maxScroll = mScrollView.getChildAt(0).getHeight() - mScrollView.getHeight(),
        materiaHeight = materia.getHeight();
    final int initScroll = mScrollView.getScrollY(),
        scrollBy =
            ((maxScroll < initScroll + materiaHeight)
                    ? Math.max(maxScroll - materiaHeight, 0)
                    : initScroll)
                - initScroll;
    ValueAnimator listAnimator = ValueAnimator.ofFloat(0, -materiaHeight);
    listAnimator.setInterpolator(new DecelerateInterpolator(3.2f));
    listAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            for (int i = 0; i < numberToBeAnimated; i++)
              ViewHelper.setTranslationY(toBeAnimated.get(i), value);
            ViewHelper.setScrollY(
                mScrollView, (int) (initScroll + scrollBy * animation.getAnimatedFraction()));
          }
        });
    listAnimator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            mSubjectCards.remove(materia);
            mSubjectsLayout.removeView(materia);
            mSqlHelper.remove(materia.getData().getSqlID());
            updateTotal();
            mScrollView.setVerticalScrollBarEnabled(true);
            mScrollView.setOnTouchListener(null);
            for (View mtr : toBeAnimated) ViewHelper.setTranslationY(mtr, 0);
          }
        });
    listAnimator.setDuration(700);
    mScrollView.setVerticalScrollBarEnabled(false);
    mScrollView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        }); // disable user scrolling during the animation

    if (ViewHelper.getTranslationX(materia) == 0) materia.swipeRight(0, 0);
    listAnimator.setStartDelay(500);
    listAnimator.start();
  }
  private void handleActionUp() {
    if (isOutOfRange) {
      // When user drag it back, we should call onReset().
      if (GeometryUtil.getDistanceBetween2Points(mDragCenter, mInitCenter) < resetDistance) {
        if (mListener != null) mListener.onReset(isOutOfRange);
        return;
      }

      // Otherwise
      disappeared();
    } else {

      // 手指抬起时,弹回动画
      mAnim = ValueAnimator.ofFloat(1.0f);
      mAnim.setInterpolator(new OvershootInterpolator(4.0f));

      final PointF startPoint = new PointF(mDragCenter.x, mDragCenter.y);
      final PointF endPoint = new PointF(mStickCenter.x, mStickCenter.y);
      mAnim.addUpdateListener(
          new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              float fraction = animation.getAnimatedFraction();
              PointF pointByPercent =
                  GeometryUtil.getPointByPercent(startPoint, endPoint, fraction);
              updateDragCenter((float) pointByPercent.x, (float) pointByPercent.y);
            }
          });
      mAnim.addListener(
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
              if (mListener != null) mListener.onReset(isOutOfRange);
            }
          });
      if (GeometryUtil.getDistanceBetween2Points(startPoint, endPoint) < 10) {
        mAnim.setDuration(10);
      } else {
        mAnim.setDuration(500);
      }
      mAnim.start();
    }
  }
    @Override
    public void executeAnim(final View target, final int animType) {
      if (ExpandableStickyListHeadersListView.ANIMATION_EXPAND == animType
          && target.getVisibility() == View.VISIBLE) {
        return;
      }
      if (ExpandableStickyListHeadersListView.ANIMATION_COLLAPSE == animType
          && target.getVisibility() != View.VISIBLE) {
        return;
      }
      if (mOriginalViewHeightPool.get(target) == null) {
        mOriginalViewHeightPool.put(target, target.getHeight());
      }
      final int viewHeight = mOriginalViewHeightPool.get(target);
      float animStartY =
          animType == ExpandableStickyListHeadersListView.ANIMATION_EXPAND ? 0f : viewHeight;
      float animEndY =
          animType == ExpandableStickyListHeadersListView.ANIMATION_EXPAND ? viewHeight : 0f;
      final ViewGroup.LayoutParams lp = target.getLayoutParams();
      ValueAnimator animator = ValueAnimator.ofFloat(animStartY, animEndY);
      animator.setDuration(200);
      target.setVisibility(View.VISIBLE);
      animator.addListener(
          new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {}

            @Override
            public void onAnimationEnd(Animator animator) {
              if (animType == ExpandableStickyListHeadersListView.ANIMATION_EXPAND) {
                target.setVisibility(View.VISIBLE);
              } else {
                target.setVisibility(View.GONE);
              }
              target.getLayoutParams().height = viewHeight;
            }

            @Override
            public void onAnimationCancel(Animator animator) {}

            @Override
            public void onAnimationRepeat(Animator animator) {}
          });
      animator.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
              lp.height = ((Float) valueAnimator.getAnimatedValue()).intValue();
              target.setLayoutParams(lp);
              target.requestLayout();
            }
          });
      animator.start();
    }
  @Override
  public void createAnimation() {
    ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.3f, 1);
    scaleAnim.setDuration(1000);
    scaleAnim.setRepeatCount(-1);
    scaleAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            scaleFloat1 = (float) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    scaleAnim.start();

    ValueAnimator scaleAnim2 = ValueAnimator.ofFloat(1, 0.6f, 1);
    scaleAnim2.setDuration(1000);
    scaleAnim2.setRepeatCount(-1);
    scaleAnim2.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            scaleFloat2 = (float) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    scaleAnim2.start();

    ValueAnimator rotateAnim = ValueAnimator.ofFloat(0, 180, 360);
    rotateAnim.setDuration(1000);
    rotateAnim.setRepeatCount(-1);
    rotateAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            degrees = (float) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    rotateAnim.start();
  }
 public void animateColorPercent(float percent, int duration) {
   ValueAnimator valueAnimator = ValueAnimator.ofFloat(lastPercent, percent);
   valueAnimator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           setColorPercent((float) animation.getAnimatedValue());
         }
       });
   valueAnimator.setDuration(duration);
   valueAnimator.start();
 }
Esempio n. 13
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    boolean hit = event.getY() > content.getTop() && getParent() != null;
    if (tapOutsideToDismiss && !hit) {
      hide();
      return false;
    }

    if (hit && swipeToDismiss) {
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        swipe = 0;
        handler.removeCallbacks(hideRunnable);
        if (animator != null) {
          animator.cancel();
          animator = null;
          swipe = ViewHelper.getTranslationX(content);
        }
        super.onTouchEvent(event);
        return true;
      } else if ((event.getAction() == MotionEvent.ACTION_UP
              || event.getAction() == MotionEvent.ACTION_CANCEL)
          && animator == null) {
        animator = ObjectAnimator.ofFloat(swipe, 0);
        animator.setDuration(200);
        animator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                float s = (Float) animation.getAnimatedValue();
                ViewHelper.setTranslationX(content, s);
                ViewHelper.setAlpha(content, Math.max(0, 1 - 2 * Math.abs(s) / content.getWidth()));
                postInvalidate();
              }
            });
        animator.start();
        animator.addListener(
            new AnimatorListenerAdapter() {
              @Override
              public void onAnimationEnd(Animator animation) {
                animator.cancel();
                animator = null;
                if (duration != INFINITE) handler.postDelayed(hideRunnable, duration);
              }
            });
        super.onTouchEvent(event);
        return true;
      }
    }

    return super.onTouchEvent(event);
  }
Esempio n. 14
0
 /** 开始绘制动画 */
 private void startAnim(int value) {
   ValueAnimator valueAnimator = ObjectAnimator.ofInt(value);
   valueAnimator.setDuration(1000);
   valueAnimator.setInterpolator(new LinearInterpolator());
   valueAnimator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator valueAnimator) {
           mDegress = Integer.valueOf(valueAnimator.getAnimatedValue().toString());
           invalidate();
         }
       });
   valueAnimator.start();
 }
  /**
   * Animate change of color
   *
   * @param event Event to process
   */
  public void startAnimateColorChange(@NonNull final DecoEvent event) {
    cancelAnimation();
    event.notifyStartListener();
    mVisible = true;

    mDrawMode = event.getEventType();
    mPercentComplete = 0f;

    final boolean changeColors = event.isColorSet();
    if (changeColors) {
      mColorAnimate = new ColorAnimate(mSeriesItem.getColor(), event.getColor());
      mSeriesItem.setColor(event.getColor());
    } else {
      Log.w(TAG, "Must set new color to start CHANGE_COLOR event");
      return;
    }

    final float maxValue = 1.0f;
    mValueAnimator = ValueAnimator.ofFloat(0, maxValue);

    mValueAnimator.setDuration(event.getEffectDuration());
    if (event.getInterpolator() != null) {
      mValueAnimator.setInterpolator(event.getInterpolator());
    } else {
      mValueAnimator.setInterpolator(new LinearInterpolator());
    }

    mValueAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mPercentComplete = Float.valueOf(valueAnimator.getAnimatedValue().toString());

            for (SeriesItem.SeriesItemListener seriesItemListener : mSeriesItem.getListeners()) {
              seriesItemListener.onSeriesItemDisplayProgress(mPercentComplete);
            }
          }
        });

    mValueAnimator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            event.notifyEndListener();
          }
        });

    mValueAnimator.start();
  }
  @Override
  public void createAnimation() {
    long[] delays = new long[] {0, 200, 400};
    for (int i = 0; i < 3; i++) {
      final int index = i;
      ValueAnimator scaleAnim = ValueAnimator.ofFloat(0, 1);
      scaleAnim.setInterpolator(new LinearInterpolator());
      scaleAnim.setDuration(1000);
      scaleAnim.setRepeatCount(-1);
      scaleAnim.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              scaleFloats[index] = (float) animation.getAnimatedValue();
              postInvalidate();
            }
          });
      scaleAnim.setStartDelay(delays[i]);
      scaleAnim.start();

      ValueAnimator alphaAnim = ValueAnimator.ofInt(0, 255);
      scaleAnim.setInterpolator(new LinearInterpolator());
      alphaAnim.setDuration(1000);
      alphaAnim.setRepeatCount(-1);
      alphaAnim.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              alphaInts[index] = (int) animation.getAnimatedValue();
              postInvalidate();
            }
          });
      scaleAnim.setStartDelay(delays[i]);
      alphaAnim.start();
    }
  }
  @Override
  public void createAnimation() {
    int[] durations = {720, 1020, 1280, 1420, 1450, 1180, 870, 1450, 1060};
    int[] delays = {-60, 250, -170, 480, 310, 30, 460, 780, 450};

    for (int i = 0; i < 9; i++) {
      final int index = i;
      ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.5f, 1);
      scaleAnim.setDuration(durations[i]);
      scaleAnim.setRepeatCount(-1);
      scaleAnim.setStartDelay(delays[i]);
      scaleAnim.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              scaleFloats[index] = (float) animation.getAnimatedValue();
              postInvalidate();
            }
          });
      scaleAnim.start();

      ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 210, 122, 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();
    }
  }
  /**
   * Execute an Animation effect by starting the Value Animator
   *
   * @param event Event to process effect
   * @throws IllegalStateException No effect set in event
   */
  public void startAnimateEffect(@NonNull final DecoEvent event) throws IllegalStateException {
    if (event.getEffectType() == null) {
      throw new IllegalStateException("Unable to execute null effect type");
    }

    // All effects run from 0.0 .. 1.0f in duration
    final float maxValue = 1.0f;

    cancelAnimation();
    event.notifyStartListener();

    mVisible = true;
    mDrawMode = event.getEventType();
    mEffect = new DecoDrawEffect(event.getEffectType(), mPaint, event.getDisplayText());
    mEffect.setRotationCount(event.getEffectRotations());

    mPercentComplete = 0f;

    mValueAnimator = ValueAnimator.ofFloat(0, maxValue);
    mValueAnimator.setDuration(event.getEffectDuration());
    Interpolator interpolator =
        (event.getInterpolator() != null) ? event.getInterpolator() : new LinearInterpolator();
    mValueAnimator.setInterpolator(interpolator);

    mValueAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mPercentComplete = Float.valueOf(valueAnimator.getAnimatedValue().toString());
            for (SeriesItem.SeriesItemListener seriesItemListener : mSeriesItem.getListeners()) {
              seriesItemListener.onSeriesItemDisplayProgress(mPercentComplete);
            }
          }
        });

    mValueAnimator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            event.notifyEndListener();
            mDrawMode = DecoEvent.EventType.EVENT_MOVE;
            mVisible = mEffect.postExecuteVisibility();
            mEffect = null;
          }
        });

    mValueAnimator.start();
  }
Esempio n. 19
0
 private void startSendingAnimation(final RevealView.RevealAnimationListener listener) {
   final int width = mFab.getLeft();
   final int height = mFab.getTop();
   ValueAnimator valueAnimator = new ValueAnimator();
   valueAnimator.setDuration(Const.DURATION / 2);
   valueAnimator.setObjectValues(new PointF(0, 0));
   valueAnimator.setInterpolator(new DecelerateInterpolator());
   valueAnimator.setEvaluator(
       new TypeEvaluator<PointF>() {
         @Override
         public PointF evaluate(float fraction, PointF startValue, PointF endValue) {
           PointF point = new PointF();
           point.x = (width) * (1 - fraction / 2);
           point.y = (height) - 0.85f * (height) * (fraction / 2) * (fraction / 2);
           return point;
         }
       });
   valueAnimator.start();
   valueAnimator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           PointF point = (PointF) animation.getAnimatedValue();
           mFab.setX(point.x);
           mFab.setY(point.y);
         }
       });
   valueAnimator.addListener(
       new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
           super.onAnimationEnd(animation);
           mRevealView.reveal(
               (int) mFab.getX() + mFab.getWidth() / 2,
               (int) mFab.getY() + mFab.getHeight() / 2,
               getThemeColor(),
               Const.RADIUS,
               Const.DURATION,
               listener);
         }
       });
 }
Esempio n. 20
0
  public void show(final View view) {
    pushedView = view;
    if (this.getParent() != null) return;
    synchronized (Snackbar.class) {
      if (!next.contains(this)) next.add(this);
      if (next.indexOf(this) == 0) {
        View decor = ((Activity) getContext()).getWindow().getDecorView();
        ((ViewGroup) decor.findViewById(android.R.id.content))
            .addView(
                this, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        ViewHelper.setAlpha(content, 0);
        AnimUtils.flyIn(content, null);
        if (view != null) {
          ValueAnimator animator = ValueAnimator.ofFloat(0, -1);
          animator.setDuration(200);
          animator.setInterpolator(new DecelerateInterpolator());
          animator.addUpdateListener(
              new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                  MarginLayoutParams lp = (MarginLayoutParams) content.getLayoutParams();
                  Log.e(
                      "snackbar " + Snackbar.this.hashCode(),
                      ""
                          + ((content.getHeight() + lp.bottomMargin)
                              * (Float) valueAnimator.getAnimatedValue()));
                  ViewHelper.setTranslationY(
                      view,
                      (content.getHeight() + lp.bottomMargin)
                          * (Float) valueAnimator.getAnimatedValue());
                  if (pushedView.getParent() != null)
                    ((View) pushedView.getParent()).postInvalidate();
                }
              });
          animator.start();
        }
        if (duration != INFINITE) handler.postDelayed(hideRunnable, duration);
      }
    }
  }
  /**
   * Kick off an animation to hide or show the arc. This results in an animation where both the
   * width of the line used for the arc and the transparency of the arc is altered over the duration
   * provided
   *
   * @param event Event to process
   * @param showArc True to show the arc, false to hide
   */
  public void startAnimateHideShow(@NonNull final DecoEvent event, final boolean showArc) {
    cancelAnimation();
    event.notifyStartListener();

    mDrawMode = event.getEventType();
    mPercentComplete = showArc ? 1.0f : 0f;
    mVisible = true;

    final float maxValue = 1.0f;
    mValueAnimator = ValueAnimator.ofFloat(0, maxValue);

    mValueAnimator.setDuration(event.getEffectDuration());
    mValueAnimator.setInterpolator(new LinearInterpolator());

    mValueAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {

            float current = Float.valueOf(valueAnimator.getAnimatedValue().toString());
            mPercentComplete = showArc ? (maxValue - current) : current;

            for (SeriesItem.SeriesItemListener seriesItemListener : mSeriesItem.getListeners()) {
              seriesItemListener.onSeriesItemDisplayProgress(mPercentComplete);
            }
          }
        });

    mValueAnimator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            if (event.getEventType() != DecoEvent.EventType.EVENT_EFFECT) {
              event.notifyEndListener();
            }
          }
        });

    mValueAnimator.start();
  }
  @Override
  public void createAnimation() {
    int[] delays = new int[] {120, 240, 360};
    for (int i = 0; i < 3; i++) {
      final int index = i;

      ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.3f, 1);
      scaleAnim.setDuration(750);
      scaleAnim.setRepeatCount(-1); // 循环
      scaleAnim.setStartDelay(delays[i]);
      scaleAnim.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              // 每次值value值变化的时候 重设对应 位置圆的scale值
              scaleFloats[index] = (float) animation.getAnimatedValue();
              postInvalidate(); // 通知重绘
            }
          });
      scaleAnim.start();
    }
  }
Esempio n. 23
0
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_UP) {
      // 需要将ImageView的高度缓慢恢复到最初高度
      ValueAnimator animator = ValueAnimator.ofInt(imageView.getHeight(), orignalHeight);
      animator.addUpdateListener(
          new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
              // 获取动画的值,设置给imageview
              int animatedValue = (Integer) animator.getAnimatedValue();

              imageView.getLayoutParams().height = animatedValue;
              imageView.requestLayout(); // 使ImageView的布局参数生效
            }
          });
      animator.setInterpolator(new OvershootInterpolator(5)); // 弹性的插值器
      animator.setDuration(350);
      animator.start();
    }
    return super.onTouchEvent(ev);
  }
Esempio n. 24
0
 public void hide() {
   synchronized (Snackbar.class) {
     if (getParent() == null) return;
     handler.removeCallbacks(hideRunnable);
     if (onDismissedListener != null) onDismissedListener.onDismissed();
     AnimUtils.flyOut(
         content,
         new AnimatorListenerAdapter() {
           @Override
           public void onAnimationEnd(Animator animator) {
             hideInternal();
           }
         });
     if (pushedView != null) {
       ValueAnimator animator = ValueAnimator.ofFloat(-1, 0);
       animator.setDuration(200);
       animator.setInterpolator(new DecelerateInterpolator());
       animator.addUpdateListener(
           new ValueAnimator.AnimatorUpdateListener() {
             @Override
             public void onAnimationUpdate(ValueAnimator valueAnimator) {
               MarginLayoutParams lp = (MarginLayoutParams) content.getLayoutParams();
               Log.e(
                   "snackbar " + Snackbar.this.hashCode(),
                   ""
                       + ((content.getHeight() + lp.bottomMargin)
                           * (Float) valueAnimator.getAnimatedValue()));
               ViewHelper.setTranslationY(
                   pushedView,
                   (content.getHeight() + lp.bottomMargin)
                       * (Float) valueAnimator.getAnimatedValue());
               if (pushedView.getParent() != null)
                 ((View) pushedView.getParent()).postInvalidate();
             }
           });
       animator.start();
     }
   }
 }
 /** 回滚状态动画 */
 private void startRollBackAnimation(long duration) {
   ValueAnimator rollBackAnim = ValueAnimator.ofFloat(curRadius, originRadius);
   rollBackAnim.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           float value = (float) animation.getAnimatedValue();
           curRadius = (int) value;
           postInvalidate();
         }
       });
   rollBackAnim.setInterpolator(new BounceInterpolator()); // 反弹效果
   rollBackAnim.addListener(
       new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
           super.onAnimationEnd(animation);
           DraggableFlagView.this.clearAnimation();
         }
       });
   rollBackAnim.setDuration(duration);
   rollBackAnim.start();
 }
Esempio n. 26
0
 @Override
 public List<Animator> createAnimation() {
   List<Animator> animators = new ArrayList<>();
   long[] delays = new long[] {100, 200, 300, 400, 500};
   for (int i = 0; i < 5; i++) {
     final int index = i;
     ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.4f, 1);
     scaleAnim.setDuration(1000);
     scaleAnim.setRepeatCount(-1);
     scaleAnim.setStartDelay(delays[i]);
     scaleAnim.addUpdateListener(
         new ValueAnimator.AnimatorUpdateListener() {
           @Override
           public void onAnimationUpdate(ValueAnimator animation) {
             scaleYFloats[index] = (float) animation.getAnimatedValue();
             postInvalidate();
           }
         });
     scaleAnim.start();
     animators.add(scaleAnim);
   }
   return animators;
 }
  /**
   * Change the color of the statusbackground, toolbar, toolbarlayout and pagertitlestrip With a
   * color transition animation
   *
   * @param color the final color
   * @param duration the transition color animation duration
   */
  public void setColor(int color, int duration) {
    ValueAnimator colorAnim =
        ObjectAnimator.ofInt(mHeader.headerBackground, "backgroundColor", settings.color, color);
    colorAnim.setEvaluator(new ArgbEvaluator());
    colorAnim.setDuration(duration);
    colorAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            final int animatedValue = (Integer) animation.getAnimatedValue();
            int colorAlpha = colorWithAlpha(animatedValue, lastPercent);
            mHeader.headerBackground.setBackgroundColor(colorAlpha);
            mHeader.statusBackground.setBackgroundColor(colorAlpha);
            mHeader.toolbar.setBackgroundColor(colorAlpha);
            mHeader.toolbarLayoutBackground.setBackgroundColor(colorAlpha);
            mHeader.mPagerSlidingTabStrip.setBackgroundColor(colorAlpha);

            // set the new color as MaterialViewPager's color
            settings.color = animatedValue;
          }
        });
    colorAnim.start();
  }
Esempio n. 28
0
  @Override
  public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    boolean hit = e2.getY() > content.getTop() && getParent() != null;

    if (hit && swipeToDismiss && animator == null) {
      swipe = e2.getX() - e1.getX();
      ViewHelper.setTranslationX(content, swipe);
      ViewHelper.setAlpha(content, Math.max(0, 1 - 2 * Math.abs(swipe) / content.getWidth()));
      postInvalidate();
      if (Math.abs(swipe) > content.getWidth() / 4) {
        handler.removeCallbacks(hideRunnable);
        animator = ObjectAnimator.ofFloat(swipe, content.getWidth() / 2.0f * Math.signum(swipe));
        animator.setDuration(200);
        animator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float s = (Float) valueAnimator.getAnimatedValue();
                ViewHelper.setTranslationX(content, s);
                float alpha =
                    Math.max(
                        0,
                        1
                            - 2
                                * Math.abs((Float) valueAnimator.getAnimatedValue())
                                / content.getWidth());
                ViewHelper.setAlpha(content, alpha);
                postInvalidate();
              }
            });
        animator.start();
        animator.addListener(
            new AnimatorListenerAdapter() {
              @Override
              public void onAnimationEnd(Animator animation) {
                hideInternal();
                animator = null;
              }
            });
        if (pushedView != null) {
          ValueAnimator animator = ValueAnimator.ofFloat(-1, 0);
          animator.setDuration(200);
          animator.setInterpolator(new DecelerateInterpolator());
          animator.addUpdateListener(
              new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                  MarginLayoutParams lp = (MarginLayoutParams) content.getLayoutParams();
                  Log.e(
                      "snackbar " + Snackbar.this.hashCode(),
                      ""
                          + ((content.getHeight() + lp.bottomMargin)
                              * (Float) valueAnimator.getAnimatedValue()));
                  ViewHelper.setTranslationY(
                      pushedView,
                      (content.getHeight() + lp.bottomMargin)
                          * (Float) valueAnimator.getAnimatedValue());
                  if (pushedView.getParent() != null)
                    ((View) pushedView.getParent()).postInvalidate();
                }
              });
          animator.start();
        }
      }
      return true;
    }
    return false;
  }
Esempio n. 29
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    float v = (value - min) / (max - min);
    float v2 = (value2 - min) / (max - min);

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
      int thumbX =
          (int)
              (v * (getWidth() - getPaddingLeft() - getPaddingRight() - thumbRadius * 2)
                  + getPaddingLeft()
                  + thumbRadius);
      int thumbX2 =
          (int)
              (v2 * (getWidth() - getPaddingLeft() - getPaddingRight() - thumbRadius2 * 2)
                  + getPaddingLeft()
                  + thumbRadius2);
      if (Math.abs(event.getX() - thumbX) < Math.abs(event.getX() - thumbX2)) {
        draggedThumb = 1;
        if (radiusAnimator != null) radiusAnimator.end();
        radiusAnimator = ValueAnimator.ofFloat(thumbRadius, THUMB_RADIUS_DRAGGED);
        radiusAnimator.setDuration(200);
        radiusAnimator.setInterpolator(interpolator);
        radiusAnimator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                thumbRadius = (float) animation.getAnimatedValue();
                postInvalidate();
              }
            });
        radiusAnimator.start();
      } else {
        draggedThumb = 2;
        if (radiusAnimator != null) radiusAnimator.end();
        radiusAnimator = ValueAnimator.ofFloat(thumbRadius2, THUMB_RADIUS_DRAGGED);
        radiusAnimator.setDuration(200);
        radiusAnimator.setInterpolator(interpolator);
        radiusAnimator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                thumbRadius2 = (float) animation.getAnimatedValue();
                postInvalidate();
              }
            });
        radiusAnimator.start();
      }
      ViewParent parent = getParent();
      if (parent != null) parent.requestDisallowInterceptTouchEvent(true);
    } else if (event.getAction() == MotionEvent.ACTION_CANCEL
        || event.getAction() == MotionEvent.ACTION_UP) {
      if (draggedThumb == 1) {
        if (style == Style.Discrete) {
          float val = (float) Math.floor((value - min + step / 2) / step) * step + min;
          if (valueAnimator != null) valueAnimator.cancel();
          valueAnimator = ValueAnimator.ofFloat(value, val);
          valueAnimator.setDuration(200);
          valueAnimator.setInterpolator(interpolator);
          valueAnimator.addUpdateListener(
              new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                  value = (float) animation.getAnimatedValue();
                  int thumbX =
                      (int)
                          ((value - min)
                                  / (max - min)
                                  * (getWidth() - getPaddingLeft() - getPaddingRight())
                              + getPaddingLeft());
                  int thumbY = getHeight() / 2;
                  int radius = rippleDrawable.getRadius();
                  rippleDrawable.setBounds(
                      thumbX - radius, thumbY - radius, thumbX + radius, thumbY + radius);
                  postInvalidate();
                }
              });
          valueAnimator.start();
        }
        if (radiusAnimator != null) radiusAnimator.end();
        radiusAnimator = ValueAnimator.ofFloat(thumbRadius, THUMB_RADIUS);
        radiusAnimator.setDuration(200);
        radiusAnimator.setInterpolator(interpolator);
        radiusAnimator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                thumbRadius = (float) animation.getAnimatedValue();
                postInvalidate();
              }
            });
        radiusAnimator.start();
      } else {
        if (style == Style.Discrete) {
          float val2 = (float) Math.floor((value2 - min + step / 2) / step) * step + min;
          if (valueAnimator != null) valueAnimator.cancel();
          valueAnimator = ValueAnimator.ofFloat(value2, val2);
          valueAnimator.setDuration(200);
          valueAnimator.setInterpolator(interpolator);
          valueAnimator.addUpdateListener(
              new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                  value2 = (float) animation.getAnimatedValue();
                  int thumbX =
                      (int)
                          ((value2 - min)
                                  / (max - min)
                                  * (getWidth() - getPaddingLeft() - getPaddingRight())
                              + getPaddingLeft());
                  int thumbY = getHeight() / 2;
                  int radius = rippleDrawable.getRadius();
                  rippleDrawable.setBounds(
                      thumbX - radius, thumbY - radius, thumbX + radius, thumbY + radius);
                  postInvalidate();
                }
              });
          valueAnimator.start();
        }
        if (radiusAnimator != null) radiusAnimator.end();
        radiusAnimator = ValueAnimator.ofFloat(thumbRadius2, THUMB_RADIUS);
        radiusAnimator.setDuration(200);
        radiusAnimator.setInterpolator(interpolator);
        radiusAnimator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                thumbRadius2 = (float) animation.getAnimatedValue();
                postInvalidate();
              }
            });
        radiusAnimator.start();
      }
      draggedThumb = -1;
      ViewParent parent = getParent();
      if (parent != null) parent.requestDisallowInterceptTouchEvent(false);
    }

    if (draggedThumb == 1) {
      v = (event.getX() - getPaddingLeft()) / (getWidth() - getPaddingLeft() - getPaddingRight());
      v = Math.max(0, Math.min(v, 1));
    } else if (draggedThumb == 2) {
      v2 = (event.getX() - getPaddingLeft()) / (getWidth() - getPaddingLeft() - getPaddingRight());
      v2 = Math.max(0, Math.min(v2, 1));
    }

    if (v > v2) {
      draggedThumb = 3 - draggedThumb;
      float t = v;
      v = v2;
      v2 = t;
    }
    float newValue = v * (max - min) + min;
    float newValue2 = v2 * (max - min) + min;

    if (rippleDrawable != null) {
      rippleDrawable.setHotspot(event.getX(), event.getY());
      int thumbY = getHeight() / 2;
      int radius = rippleDrawable.getRadius();
      if (draggedThumb == 1) {
        int thumbX =
            (int) (v * (getWidth() - getPaddingLeft() - getPaddingRight()) + getPaddingLeft());
        rippleDrawable.setBounds(
            thumbX - radius, thumbY - radius, thumbX + radius, thumbY + radius);
      } else if (draggedThumb == 2) {
        int thumbX2 =
            (int) (v2 * (getWidth() - getPaddingLeft() - getPaddingRight()) + getPaddingLeft());
        rippleDrawable.setBounds(
            thumbX2 - radius, thumbY - radius, thumbX2 + radius, thumbY + radius);
      }
    }

    postInvalidate();
    if (newValue != value && onValueChangedListener != null) {
      if (style == Style.Discrete) {
        int sv = stepValue(newValue);
        int sv2 = stepValue(newValue2);
        if (stepValue(value) != sv || stepValue(value2) != sv2)
          onValueChangedListener.onValueChanged(this, sv, sv2);
      } else {
        onValueChangedListener.onValueChanged(this, newValue, newValue2);
      }
      value = newValue;
    }
    super.onTouchEvent(event);
    return true;
  }
  @Override
  public List<Animator> createAnimation() {
    List<Animator> animators = new ArrayList<>();
    float startT = getWidth() / 11;
    ValueAnimator translationAnim = ValueAnimator.ofFloat(getWidth() - startT, getWidth() / 2);
    translationAnim.setDuration(650);
    translationAnim.setInterpolator(new LinearInterpolator());
    translationAnim.setRepeatCount(-1);
    translationAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            translateX = (float) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    translationAnim.start();

    ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 122);
    alphaAnim.setDuration(650);
    alphaAnim.setRepeatCount(-1);
    alphaAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            alpha = (int) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    alphaAnim.start();

    ValueAnimator rotateAnim1 = ValueAnimator.ofFloat(0, 45, 0);
    rotateAnim1.setDuration(650);
    rotateAnim1.setRepeatCount(-1);
    rotateAnim1.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            degrees1 = (float) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    rotateAnim1.start();

    ValueAnimator rotateAnim2 = ValueAnimator.ofFloat(0, -45, 0);
    rotateAnim2.setDuration(650);
    rotateAnim2.setRepeatCount(-1);
    rotateAnim2.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            degrees2 = (float) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    rotateAnim2.start();

    animators.add(translationAnim);
    animators.add(alphaAnim);
    animators.add(rotateAnim1);
    animators.add(rotateAnim2);
    return animators;
  }