/**
   * Creates an animator that can be used for x and/or y translations. When interrupted, it sets a
   * tag to keep track of the position so that it may be continued from position.
   *
   * @param view The view being moved. This may be in the overlay for onDisappear.
   * @param values The values containing the view in the view hierarchy.
   * @param viewPosX The x screen coordinate of view
   * @param startX The start translation x of view
   * @param endX The end translation x of view
   * @param interpolator The interpolator to use with this animator.
   * @return An animator that moves from (startX, startY) to (endX, endY) unless there was a
   *     previous interruption, in which case it moves from the current position to (endX, endY).
   */
  static Animator createAnimation(
      View view,
      TransitionValues values,
      int viewPosX,
      float startX,
      float endX,
      TimeInterpolator interpolator,
      Transition transition) {
    float terminalX = view.getTranslationX();
    Integer startPosition = (Integer) values.view.getTag(R.id.transitionPosition);
    if (startPosition != null) {
      startX = startPosition - viewPosX + terminalX;
    }
    // Initial position is at translation startX, startY, so position is offset by that
    // amount
    int startPosX = viewPosX + Math.round(startX - terminalX);

    view.setTranslationX(startX);
    if (startX == endX) {
      return null;
    }
    Path path = new Path();
    path.moveTo(startX, 0);
    path.lineTo(endX, 0);
    ObjectAnimator anim =
        ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, path);

    TransitionPositionListener listener =
        new TransitionPositionListener(view, values.view, startPosX, terminalX);
    transition.addListener(listener);
    anim.addListener(listener);
    anim.addPauseListener(listener);
    anim.setInterpolator(interpolator);
    return anim;
  }
  /**
   * ��ת����
   *
   * @param one
   * @param two
   */
  private void flipit(View one, View two) {
    final View visible;
    final View invisible;
    if (one.getVisibility() == View.GONE) {
      visible = two;
      invisible = one;

    } else {
      invisible = two;
      visible = one;
    }
    ObjectAnimator visToInvis = ObjectAnimator.ofFloat(visible, "rotationY", 0f, 90f);
    visToInvis.setDuration(500);
    visToInvis.setInterpolator(accelerator);
    final ObjectAnimator invisToVis = ObjectAnimator.ofFloat(invisible, "rotationY", -90f, 0f);
    invisToVis.setDuration(500);
    invisToVis.setInterpolator(decelerator);
    visToInvis.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator anim) {
            visible.setVisibility(View.GONE);
            invisToVis.start();
            invisible.setVisibility(View.VISIBLE);
          }
        });
    visToInvis.start();
  }
  private void setupAnimations() {
    mObjectAnimatorAngle = ObjectAnimator.ofFloat(this, mAngleProperty, 360f);
    mObjectAnimatorAngle.setInterpolator(ANGLE_INTERPOLATOR);
    mObjectAnimatorAngle.setDuration(ANGLE_ANIMATOR_DURATION);
    mObjectAnimatorAngle.setRepeatMode(ValueAnimator.RESTART);
    mObjectAnimatorAngle.setRepeatCount(ValueAnimator.INFINITE);

    mObjectAnimatorSweep = ObjectAnimator.ofFloat(this, mSweepProperty, 360f - MIN_SWEEP_ANGLE * 2);
    mObjectAnimatorSweep.setInterpolator(SWEEP_INTERPOLATOR);
    mObjectAnimatorSweep.setDuration(SWEEP_ANIMATOR_DURATION);
    mObjectAnimatorSweep.setRepeatMode(ValueAnimator.RESTART);
    mObjectAnimatorSweep.setRepeatCount(ValueAnimator.INFINITE);
    mObjectAnimatorSweep.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {}

          @Override
          public void onAnimationCancel(Animator animation) {}

          @Override
          public void onAnimationRepeat(Animator animation) {
            toggleAppearingMode();
          }
        });
  }
Example #4
0
 /** Return to initial state */
 public void finish(int finishMode) {
   if (!mAttached) {
     return;
   }
   mTextHint.setVisibility(View.GONE);
   if (finishMode == FINISH_SLIDE_OUT) {
     PropertyValuesHolder slideX =
         PropertyValuesHolder.ofFloat(
             "translationX", new float[] {0.0f, mScreenshotView.getWidth()});
     mSlideoutAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, slideX);
     mSlideoutAnimator.setInterpolator(new AccelerateInterpolator());
     mSlideoutAnimator.setDuration(SLIDE_OUT_DURATION_MS);
     mSlideoutAnimator.addListener(this);
     mSlideoutAnimator.start();
   } else {
     float currentScale = mScreenshotView.getScaleX();
     float currentAlpha = mScreenshotView.getAlpha();
     PropertyValuesHolder scaleUpX =
         PropertyValuesHolder.ofFloat("scaleX", new float[] {currentScale, 1.0f});
     PropertyValuesHolder scaleUpY =
         PropertyValuesHolder.ofFloat("scaleY", new float[] {currentScale, 1.0f});
     PropertyValuesHolder scaleUpAlpha =
         PropertyValuesHolder.ofFloat("alpha", new float[] {currentAlpha, 1.0f});
     mScaleUpAnimator =
         ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, scaleUpX, scaleUpY, scaleUpAlpha);
     mScaleUpAnimator.setInterpolator(new DecelerateInterpolator());
     mScaleUpAnimator.setDuration(SCALE_UP_DURATION_MS);
     mScaleUpAnimator.addListener(this);
     mScaleUpAnimator.start();
   }
 }
Example #5
0
    public LayoutParams(ViewGroup.LayoutParams source) {
      super(source);

      mExpandDir.setInterpolator(sExpandInterpolator);
      mExpandAlpha.setInterpolator(sAlphaExpandInterpolator);
      mCollapseDir.setInterpolator(sCollapseInterpolator);
      mCollapseAlpha.setInterpolator(sCollapseInterpolator);

      mCollapseAlpha.setProperty(View.ALPHA);
      mCollapseAlpha.setFloatValues(1f, 0f);

      mExpandAlpha.setProperty(View.ALPHA);
      mExpandAlpha.setFloatValues(0f, 1f);

      switch (mExpandDirection) {
        case EXPAND_UP:
        case EXPAND_DOWN:
          mCollapseDir.setProperty(View.TRANSLATION_Y);
          mExpandDir.setProperty(View.TRANSLATION_Y);
          break;
        case EXPAND_LEFT:
        case EXPAND_RIGHT:
          mCollapseDir.setProperty(View.TRANSLATION_X);
          mExpandDir.setProperty(View.TRANSLATION_X);
          break;
      }

      mExpandAnimation.play(mExpandAlpha);
      mExpandAnimation.play(mExpandDir);

      mCollapseAnimation.play(mCollapseAlpha);
      mCollapseAnimation.play(mCollapseDir);
    }
Example #6
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (!isEnabled()) return false;

    switch (event.getAction()) {
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        if (!knobState) {
          innerContentAnimator =
              ObjectAnimator.ofFloat(AnSwitch.this, innerContentProperty, innerContentRate, 1.0F);
          innerContentAnimator.setDuration(300L);
          innerContentAnimator.setInterpolator(new DecelerateInterpolator());

          innerContentAnimator.start();
        }

        knobExpandAnimator =
            ObjectAnimator.ofFloat(AnSwitch.this, knobExpandProperty, knobExpandRate, 0.0F);
        knobExpandAnimator.setDuration(300L);
        knobExpandAnimator.setInterpolator(new DecelerateInterpolator());

        knobExpandAnimator.start();

        mIsChecked = knobState;

        if (AnSwitch.this.onSwitchStateChangeListener != null && mIsChecked != preIsOn) {
          AnSwitch.this.onSwitchStateChangeListener.onSwitchStateChange(mIsChecked);
        }

        break;
    }

    return gestureDetector.onTouchEvent(event);
  }
Example #7
0
  private void stopAnimator() {
    ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(this, "scaleX", 1, 0);
    ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(this, "scaleY", 1, 0);
    scaleXAnimator.setDuration(300);
    scaleXAnimator.setInterpolator(new LinearInterpolator());
    scaleYAnimator.setDuration(300);
    scaleYAnimator.setInterpolator(new LinearInterpolator());
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(scaleXAnimator, scaleYAnimator);
    animatorSet.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {
            isStart = false;
          }

          @Override
          public void onAnimationCancel(Animator animation) {}

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
    animatorSet.start();
  }
Example #8
0
 private void startTrans() {
   ObjectAnimator animator = ObjectAnimator.ofFloat(this, "translationX", 0, width / 3);
   animator.setDuration(200);
   animator.setInterpolator(new DecelerateInterpolator());
   ObjectAnimator animator2 = ObjectAnimator.ofFloat(this, "translationX", width / 3, -width / 4);
   animator2.setDuration(200);
   animator2.setInterpolator(new DecelerateInterpolator());
   ObjectAnimator animator3 = ObjectAnimator.ofFloat(this, "translationX", -width / 4, width / 5);
   animator3.setDuration(200);
   animator3.setInterpolator(new DecelerateInterpolator());
   ObjectAnimator animator4 = ObjectAnimator.ofFloat(this, "translationX", width / 5, -width / 6);
   animator4.setDuration(200);
   animator4.setInterpolator(new DecelerateInterpolator());
   ObjectAnimator animator5 = ObjectAnimator.ofFloat(this, "translationX", -width / 6, 0);
   animator5.setDuration(200);
   animator5.setInterpolator(new DecelerateInterpolator());
   AnimatorSet set = new AnimatorSet();
   List<Animator> items = new ArrayList<Animator>();
   items.add(animator);
   items.add(animator2);
   items.add(animator3);
   items.add(animator4);
   items.add(animator5);
   set.playSequentially(items);
   set.start();
 }
  private void flip(final View v1, final View v2, final boolean scale, boolean reverse) {
    final int duration = 300;
    final int degree = reverse ? 90 : -90;
    final int degree2 = -degree;

    final ObjectAnimator a, b;
    if (!scale) {
      a = ObjectAnimator.ofFloat(v1, "rotationY", 0, degree);
      b = ObjectAnimator.ofFloat(v2, "rotationY", degree2, 0);
    } else {
      final float scaleX = 0.5f;
      final float scaleY = 0.5f;
      a =
          ObjectAnimator.ofPropertyValuesHolder(
              v1,
              PropertyValuesHolder.ofFloat("rotationY", 0, degree),
              PropertyValuesHolder.ofFloat("scaleX", 1, scaleX),
              PropertyValuesHolder.ofFloat("scaleY", 1, scaleY));
      b =
          ObjectAnimator.ofPropertyValuesHolder(
              v2,
              PropertyValuesHolder.ofFloat("rotationY", degree2, 0),
              PropertyValuesHolder.ofFloat("scaleX", scaleX, 1),
              PropertyValuesHolder.ofFloat("scaleY", scaleY, 1));
    }

    a.setInterpolator(new LinearInterpolator());
    b.setInterpolator(new LinearInterpolator());
    a.setDuration(duration);
    b.setDuration(duration);

    a.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {
            v1.setVisibility(View.GONE);
            v2.setVisibility(View.VISIBLE);
            if (scale) { // 恢复scale
              v1.setScaleX(1);
              v1.setScaleY(1);
            }
          }

          @Override
          public void onAnimationCancel(Animator animation) {}

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
    v1.setVisibility(View.VISIBLE);
    v2.setVisibility(View.GONE);

    AnimatorSet set = new AnimatorSet();
    set.play(a).before(b);
    set.start();
  }
Example #10
0
  public ShSwitchView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ShSwitchView);

    tintColor = ta.getColor(R.styleable.ShSwitchView_tintColor, 0xFF9CE949);
    tempTintColor = tintColor;

    int defaultOuterStrokeWidth =
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 1.5F, context.getResources().getDisplayMetrics());
    int defaultShadowSpace =
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 5, context.getResources().getDisplayMetrics());

    outerStrokeWidth =
        ta.getDimensionPixelOffset(
            R.styleable.ShSwitchView_outerStrokeWidth, defaultOuterStrokeWidth);
    shadowSpace =
        ta.getDimensionPixelOffset(R.styleable.ShSwitchView_shadowSpace, defaultShadowSpace);

    ta.recycle();

    knobBound = new RectF();
    innerContentBound = new RectF();
    ovalForPath = new RectF();

    tempForRoundRect = new RectF();

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    roundRectPath = new Path();

    gestureDetector = new GestureDetector(context, gestureListener);
    gestureDetector.setIsLongpressEnabled(false);

    if (Build.VERSION.SDK_INT >= 11) {
      setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    innerContentAnimator =
        ObjectAnimator.ofFloat(ShSwitchView.this, innerContentProperty, innerContentRate, 1.0F);
    innerContentAnimator.setDuration(commonDuration);
    innerContentAnimator.setInterpolator(new DecelerateInterpolator());

    knobExpandAnimator =
        ObjectAnimator.ofFloat(ShSwitchView.this, knobExpandProperty, knobExpandRate, 1.0F);
    knobExpandAnimator.setDuration(commonDuration);
    knobExpandAnimator.setInterpolator(new DecelerateInterpolator());

    knobMoveAnimator =
        ObjectAnimator.ofFloat(ShSwitchView.this, knobMoveProperty, knobMoveRate, 1.0F);
    knobMoveAnimator.setDuration(commonDuration);
    knobMoveAnimator.setInterpolator(new DecelerateInterpolator());

    shadowDrawable = context.getResources().getDrawable(R.drawable.shadow);
  }
Example #11
0
 private void startAnimator() {
   ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(this, "scaleX", 0.0f, 1);
   ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(this, "scaleY", 0.0f, 1);
   scaleXAnimator.setDuration(300);
   scaleXAnimator.setInterpolator(new LinearInterpolator());
   scaleYAnimator.setDuration(300);
   scaleYAnimator.setInterpolator(new LinearInterpolator());
   AnimatorSet animatorSet = new AnimatorSet();
   animatorSet.playTogether(scaleXAnimator, scaleYAnimator);
   animatorSet.start();
 }
  /** 上抛 */
  public void upThrow() {

    ObjectAnimator objectAnimator =
        ObjectAnimator.ofFloat(shapeLoadingView, "translationY", mDistance, 0);
    ObjectAnimator scaleIndication = ObjectAnimator.ofFloat(indicationIm, "scaleX", 0.2f, 1);

    ObjectAnimator objectAnimator1 = null;
    switch (shapeLoadingView.getShape()) {
      case SHAPE_RECT:
        objectAnimator1 = ObjectAnimator.ofFloat(shapeLoadingView, "rotation", 0, -120);

        break;
      case SHAPE_CIRCLE:
        objectAnimator1 = ObjectAnimator.ofFloat(shapeLoadingView, "rotation", 0, 180);

        break;
      case SHAPE_TRIANGLE:
        objectAnimator1 = ObjectAnimator.ofFloat(shapeLoadingView, "rotation", 0, 180);

        break;
    }

    objectAnimator.setDuration(ANIMATION_DURATION);
    objectAnimator1.setDuration(ANIMATION_DURATION);
    objectAnimator.setInterpolator(new DecelerateInterpolator());
    objectAnimator1.setInterpolator(new DecelerateInterpolator());
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(ANIMATION_DURATION);
    animatorSet.playTogether(objectAnimator, objectAnimator1, scaleIndication);

    animatorSet.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {
            freeFall();
          }

          @Override
          public void onAnimationCancel(Animator animation) {}

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
    animatorSet.start();
  }
Example #13
0
 private void animateArrow(boolean shouldRotateUp) {
   int start = shouldRotateUp ? 0 : MAX_LEVEL;
   int end = shouldRotateUp ? MAX_LEVEL : 0;
   ObjectAnimator animator = ObjectAnimator.ofInt(drawable, "level", start, end);
   animator.setInterpolator(new LinearOutSlowInInterpolator());
   animator.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();
  }
  // Make the UFO spin around and fly away
  private void easterEggInteraction() {
    mCallback.playSoundOnce(R.raw.easter_egg);

    // Fade into the distance
    ObjectAnimator anim = ObjectAnimator.ofFloat(mImageUfo, "size", 1.0f, 0f);
    anim.setInterpolator(new AccelerateInterpolator());
    anim.setDuration(ImageWithAlphaAndSize.ANIM_DURATION);
    anim.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {
            mImageUfo.setAlpha(ImageWithAlphaAndSize.INVISIBLE);
          }

          @Override
          public void onAnimationCancel(Animator animation) {}

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
    anim.start();
  }
 public static Animator createIndeterminateRotation(Object paramObject) {
   paramObject = ObjectAnimator.ofFloat(paramObject, "rotation", new float[] {0.0F, 720.0F});
   ((ObjectAnimator) paramObject).setDuration(6665L);
   ((ObjectAnimator) paramObject).setInterpolator(Interpolators.LINEAR.INSTANCE);
   ((ObjectAnimator) paramObject).setRepeatCount(-1);
   return (Animator) paramObject;
 }
  /** Add animations to fade a view from the specified start alpha value to end value. */
  public static void addFadeAnimators(
      List<Animator> animators,
      final View view,
      float startAlpha,
      final float endAlpha,
      int animationDelay) {
    if (startAlpha == endAlpha) {
      return;
    }

    view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    view.setAlpha(startAlpha);

    final ObjectAnimator fadeAnimator =
        ObjectAnimator.ofFloat(view, View.ALPHA, view.getAlpha(), endAlpha);
    fadeAnimator.setInterpolator(sDecelerateQuintInterpolator);
    fadeAnimator.setDuration(sAnimationDuration);
    fadeAnimator.setStartDelay(animationDelay);
    fadeAnimator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            view.setAlpha(endAlpha);
            view.setLayerType(View.LAYER_TYPE_NONE, null);
          }
        });
    animators.add(fadeAnimator);
  }
  /** 下落 */
  public void freeFall() {

    ObjectAnimator objectAnimator =
        ObjectAnimator.ofFloat(shapeLoadingView, "translationY", 0, mDistance);
    ObjectAnimator scaleIndication = ObjectAnimator.ofFloat(indicationIm, "scaleX", 1, 0.2f);

    objectAnimator.setDuration(ANIMATION_DURATION);
    objectAnimator.setInterpolator(new AccelerateInterpolator());
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(ANIMATION_DURATION);
    animatorSet.playTogether(objectAnimator, scaleIndication);
    animatorSet.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {

            shapeLoadingView.changeShape();
            upThrow();
          }

          @Override
          public void onAnimationCancel(Animator animation) {}

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
    animatorSet.start();
  }
  /**
   * =============================================================================================
   * The Animate
   * =============================================================================================
   */
  private void animateShowTitle(boolean show) {
    TitleProperty property;
    if (show) property = new TitleProperty(mAttributes);
    else {
      property = new TitleProperty();
      property.mAlpha = 0;
      property.mTextSize = (int) getTextSize();
      property.mPaddingLeft = getPaddingLeft();
      property.mPaddingTop = getPaddingTop();
    }

    if (isAttachWindow) {
      if (mAnimator == null) {
        mAnimator =
            ObjectAnimator.ofObject(
                this, TITLE_PROPERTY, new TitleEvaluator(mCurTitleProperty), property);
        mAnimator.setDuration(ANIMATION_DURATION);
        mAnimator.setInterpolator(ANIMATION_INTERPOLATOR);
      } else {
        mAnimator.cancel();
        mAnimator.setObjectValues(property);
      }
      mAnimator.start();
    } else {
      setTitleProperty(property);
    }
  }
  public void rotateLogo() {
    btnScan.setText(ctx.getString(R.string.stop_scan));
    if (logoAnimator != null) logoAnimator.cancel();
    logoAnimator = ObjectAnimator.ofFloat(imgLogo, "rotation", 0, 360);
    logoAnimator.setDuration(200);
    logoAnimator.setInterpolator(new AccelerateInterpolator());
    logoAnimator.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {
            if (!pleaseStop) {
              rotateLogo();
            } else {
              pleaseStop = false;
              resetLogo();
              Log.w(LOG, "#### not repeating the logo anim anymore");
            }
          }

          @Override
          public void onAnimationCancel(Animator animation) {}

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
    // logoAnimator.start();
    // flashAccuracy();
  }
 private ObjectAnimator createAnimation(View view, AnimationParams params) {
   ObjectAnimator animator = null;
   if (params.attr != null) {
     if (params.paramsFloat != null) {
       animator = ObjectAnimator.ofFloat(view, params.attr, params.paramsFloat);
     } else if (params.paramsInt != null) {
       animator = ObjectAnimator.ofInt(view, params.attr, params.paramsInt);
     }
   } else {
     if (params.paramsFloat != null && params.propertyFloat != null) {
       animator = ObjectAnimator.ofFloat(view, params.propertyFloat, params.paramsFloat);
     } else if (params.paramsInt != null && params.propertyInt != null) {
       animator = ObjectAnimator.ofInt(view, params.propertyInt, params.paramsInt);
     }
   }
   if (animator == null) {
     throw new RuntimeException("Can't support this animation params");
   }
   if (params.evaluator != null) {
     animator.setEvaluator(params.evaluator);
   }
   if (params.interpolator != null) {
     animator.setInterpolator(params.interpolator);
   }
   return animator;
 }
  // 初始化歌曲列表
  private void initLocalMusicList() {
    // fileInfos = MediaUtil.getFileInfos(getApplicationContext()); //获取歌曲对象集合
    setListAdpter(MediaUtil.getMusicMaps(fileInfos)); // 显示歌曲列表
    music_siger_tv.setText(fileInfos.get(listPosition).getArtist());
    music_name_tv.setText(fileInfos.get(listPosition).getTitle());
    music_play_bt.setPressed(play_bt_press);
    music_play_bt.setChecked(play_bt_check);

    anim = ObjectAnimator.ofFloat(music_album_iv, "rotation", 0, 360);
    lin = new LinearInterpolator();
    anim.setDuration(6000);
    anim.setRepeatCount(-1);
    anim.setRepeatMode(ObjectAnimator.RESTART);
    anim.setInterpolator(lin); // 匀速

    PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("alpha", 1f, 0f, 1f);
    PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("scaleX", 1f, 0, 1f);
    PropertyValuesHolder pvhZ = PropertyValuesHolder.ofFloat("scaleY", 1f, 0, 1f);
    animSongName = ObjectAnimator.ofPropertyValuesHolder(music_name_tv, pvhX, pvhY, pvhZ); // 渐现
    animSongName.setDuration(1000);
    animSongName.setRepeatCount(0);
    animSongName.setRepeatMode(ObjectAnimator.RESTART);

    animSongSinger = ObjectAnimator.ofPropertyValuesHolder(music_siger_tv, pvhX, pvhY, pvhZ); // 渐现
    animSongSinger.setDuration(1000);
    animSongSinger.setRepeatCount(0);
    animSongSinger.setRepeatMode(ObjectAnimator.RESTART);
  }
Example #23
0
  private ObjectAnimator buildOpeningAnimation() {
    ObjectAnimator rotationAnimator =
        initAnimator(
            ObjectAnimator.ofFloat(
                mGuillotineView, ROTATION, GUILLOTINE_CLOSED_ANGLE, GUILLOTINE_OPENED_ANGLE));
    rotationAnimator.setInterpolator(mInterpolator);
    rotationAnimator.setDuration(mDuration);
    rotationAnimator.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {
            mGuillotineView.setVisibility(View.VISIBLE);
            isOpening = true;
          }

          @Override
          public void onAnimationEnd(Animator animation) {
            isOpening = false;
            if (mListener != null) {
              mListener.onGuillotineOpened();
            }
          }

          @Override
          public void onAnimationCancel(Animator animation) {}

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
    return rotationAnimator;
  }
 // 开始动画
 private void startAnim() {
   // 遍历第一个不是主菜单的ImageView列表
   for (int i = 1; i < res.length; i++) {
     // 获取展开角度
     float angle = (90 * 1.0f / (res.length - 2)) * (i - 1);
     // 获取X位移
     PropertyValuesHolder holder1 =
         PropertyValuesHolder.ofFloat(
             "translationX", 0, (float) (Math.sin((angle * 1.57 / 90)) * 200));
     // 获取Y位移
     PropertyValuesHolder holder2 =
         PropertyValuesHolder.ofFloat(
             "translationY", 0, (float) (Math.cos((angle * 1.57 / 90)) * 200));
     // 设置ImageView的属性动画
     ObjectAnimator animator =
         ObjectAnimator.ofPropertyValuesHolder(imageViewList.get(i), holder1, holder2);
     // ObjectAnimator animator =
     // ObjectAnimator.ofFloat(imageViewList.get(i), "translationY", 0, i *
     // 60);
     // 动画时间
     animator.setDuration(1000);
     // 动画延迟时间
     animator.setFrameDelay(500 * i);
     // 设置加速器
     animator.setInterpolator(new BounceInterpolator());
     // 启动动画
     animator.start();
     isNotExpand = false;
   }
 }
Example #25
0
  private void updateHeartButton(final CellFeedViewHolder holder, boolean animated) {
    if (animated) {
      if (!likeAnimations.containsKey(holder)) {
        AnimatorSet animatorSet = new AnimatorSet();
        likeAnimations.put(holder, animatorSet);

        ObjectAnimator rotationAnim = ObjectAnimator.ofFloat(holder.btnLike, "rotation", 0f, 360f);
        rotationAnim.setDuration(300);
        rotationAnim.setInterpolator(ACCELERATE_INTERPOLATOR);

        ObjectAnimator bounceAnimX = ObjectAnimator.ofFloat(holder.btnLike, "scaleX", 0.2f, 1f);
        bounceAnimX.setDuration(300);
        bounceAnimX.setInterpolator(OVERSHOOT_INTERPOLATOR);

        ObjectAnimator bounceAnimY = ObjectAnimator.ofFloat(holder.btnLike, "scaleY", 0.2f, 1f);
        bounceAnimY.setDuration(300);
        bounceAnimY.setInterpolator(OVERSHOOT_INTERPOLATOR);
        bounceAnimY.addListener(
            new AnimatorListenerAdapter() {
              @Override
              public void onAnimationStart(Animator animation) {
                holder.btnLike.setImageResource(R.drawable.ic_heart_red);
              }
            });

        animatorSet.play(rotationAnim);
        animatorSet.play(bounceAnimX).with(bounceAnimY).after(rotationAnim);

        animatorSet.addListener(
            new AnimatorListenerAdapter() {
              @Override
              public void onAnimationEnd(Animator animation) {
                resetLikeAnimationState(holder);
              }
            });

        animatorSet.start();
      }
    } else {
      if (likedPositions.contains(holder.getPosition())) {
        holder.btnLike.setImageResource(R.drawable.ic_heart_red);
      } else {
        holder.btnLike.setImageResource(R.drawable.ic_heart_outline_grey);
      }
    }
  }
 /** 启动悬停 */
 private void startHover() {
   if (eventCancelled) return;
   if (hoverAnimator != null) hoverAnimator.cancel();
   final float radius =
       (float) (Math.sqrt(Math.pow(getWidth(), 2) + Math.pow(getHeight(), 2)) * 1.2f);
   hoverAnimator = ObjectAnimator.ofFloat(this, radiusProperty, 35, radius).setDuration(2500);
   //        ObjectAnimator.ofF
   hoverAnimator.setInterpolator(new LinearInterpolator());
   hoverAnimator.start();
 }
 public void fade(int durationMs, int delayMs, int alpha) {
   if (mAnimator != null && mAnimator.isStarted()) {
     mAnimator.cancel();
   }
   mAnimator = ObjectAnimator.ofInt(this, "alpha", alpha);
   mAnimator.setInterpolator(new LinearInterpolator());
   mAnimator.setDuration(durationMs);
   mAnimator.setStartDelay(delayMs);
   mAnimationPending = true;
 }
 public static Animator createIndeterminateHorizontalRect2(Object paramObject) {
   ObjectAnimator localObjectAnimator =
       ObjectAnimatorCompat.ofFloat(
           paramObject, "translateX", null, PATH_INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X);
   localObjectAnimator.setDuration(2000L);
   localObjectAnimator.setInterpolator(
       Interpolators.INDETERMINATE_HORIZONTAL_RECT2_TRANSLATE_X.INSTANCE);
   localObjectAnimator.setRepeatCount(-1);
   paramObject =
       ObjectAnimatorCompat.ofFloat(
           paramObject, null, "scaleX", PATH_INDETERMINATE_HORIZONTAL_RECT2_SCALE_X);
   ((ObjectAnimator) paramObject).setDuration(2000L);
   ((ObjectAnimator) paramObject)
       .setInterpolator(Interpolators.INDETERMINATE_HORIZONTAL_RECT2_SCALE_X.INSTANCE);
   ((ObjectAnimator) paramObject).setRepeatCount(-1);
   AnimatorSet localAnimatorSet = new AnimatorSet();
   localAnimatorSet.playTogether(new Animator[] {localObjectAnimator, paramObject});
   return localAnimatorSet;
 }
  private void updateProgress2(long elapsed) {
    float seconds = elapsed / 1000.0f;
    float progress = seconds / 10f;

    mText.setText(String.format("%.1f", seconds));
    ObjectAnimator animation = ObjectAnimator.ofFloat(mProgress, "progress", progress);
    animation.setDuration(500); // 0.5 second
    animation.setInterpolator(new LinearInterpolator());
    animation.start();
  }
Example #30
0
 public void animateToVisibility(int visibility) {
   if (mVisibilityAnim != null) {
     mVisibilityAnim.cancel();
   }
   if (visibility == VISIBLE) {
     if (getVisibility() != VISIBLE) {
       setAlpha(0);
       if (mSplitView != null && mMenuView != null) {
         mMenuView.setAlpha(0);
       }
     }
     ObjectAnimator anim = ObjectAnimator.ofFloat(this, "alpha", 1);
     anim.setDuration(FADE_DURATION);
     anim.setInterpolator(sAlphaInterpolator);
     if (mSplitView != null && mMenuView != null) {
       AnimatorSet set = new AnimatorSet();
       ObjectAnimator splitAnim = ObjectAnimator.ofFloat(mMenuView, "alpha", 1);
       splitAnim.setDuration(FADE_DURATION);
       set.addListener(mVisAnimListener.withFinalVisibility(visibility));
       set.play(anim).with(splitAnim);
       set.start();
     } else {
       anim.addListener(mVisAnimListener.withFinalVisibility(visibility));
       anim.start();
     }
   } else {
     ObjectAnimator anim = ObjectAnimator.ofFloat(this, "alpha", 0);
     anim.setDuration(FADE_DURATION);
     anim.setInterpolator(sAlphaInterpolator);
     if (mSplitView != null && mMenuView != null) {
       AnimatorSet set = new AnimatorSet();
       ObjectAnimator splitAnim = ObjectAnimator.ofFloat(mMenuView, "alpha", 0);
       splitAnim.setDuration(FADE_DURATION);
       set.addListener(mVisAnimListener.withFinalVisibility(visibility));
       set.play(anim).with(splitAnim);
       set.start();
     } else {
       anim.addListener(mVisAnimListener.withFinalVisibility(visibility));
       anim.start();
     }
   }
 }