Esempio n. 1
0
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  private void animateTextColor(int targetColor) {
    if (mCurrentColorAnim != null) {
      mCurrentColorAnim.cancel();
    }

    mCurrentColorAnim = new AnimatorSet();
    mCurrentColorAnim.setDuration(DragView.COLOR_CHANGE_DURATION);

    if (mSrcFilter == null) {
      mSrcFilter = new ColorMatrix();
      mDstFilter = new ColorMatrix();
      mCurrentFilter = new ColorMatrix();
    }

    DragView.setColorScale(getTextColor(), mSrcFilter);
    DragView.setColorScale(targetColor, mDstFilter);
    ValueAnimator anim1 =
        ValueAnimator.ofObject(
            new FloatArrayEvaluator(mCurrentFilter.getArray()),
            mSrcFilter.getArray(),
            mDstFilter.getArray());
    anim1.addUpdateListener(
        new AnimatorUpdateListener() {

          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mDrawable.setColorFilter(new ColorMatrixColorFilter(mCurrentFilter));
            invalidate();
          }
        });

    mCurrentColorAnim.play(anim1);
    mCurrentColorAnim.play(ObjectAnimator.ofArgb(this, "textColor", targetColor));
    mCurrentColorAnim.start();
  }
Esempio n. 2
0
  // Show(or hide) one view with some effects
  private void showView(int viewId, int delay, int b) {
    View myView = findViewById(viewId);
    final int behavior = b;

    if (android.os.Build.VERSION.SDK_INT >= 21) {

      float x = myView.getX();
      float y = myView.getY();

      Path path1 = new Path();
      Path path2 = new Path();

      // Show with bounce effect
      if (behavior == 0) {
        path1.moveTo(x, y + 100);
        path1.rLineTo(0, -100);
        path2.moveTo(0, 0);
        path2.lineTo(1, 1);
      }
      // Show with bounce effect(and drop from top)
      else if (behavior == 1) {
        path1.moveTo(x, y - 300);
        path1.rLineTo(0, 300);
        path2.moveTo(1, 1);
        path2.lineTo(1, 1);
      }
      // Show with inflate effect
      else if (behavior == 2) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(10, 10);
      }
      // Hide with deflate effect(from large shape)
      else if (behavior == 3) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(10, 10);
        path2.lineTo(1, 1);
      }
      // Fade in and float
      else if (behavior == 4) {
        path1.moveTo(x, y + 50);
        path1.rLineTo(0, -50);
        path2.moveTo(1, 1);
        path2.lineTo(1, 1);
      }
      // Fade out
      else if (behavior == 5) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(1, 1);
      }
      // Hide with deflate effect
      else if (behavior == 6) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(0, 0);
      }
      // Show with inflate effect
      else if (behavior == 7) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(20, 20);
      }
      // Hide with deflate effect(from large shape)
      else if (behavior == 8) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(20, 20);
        path2.lineTo(1, 1);
      }
      // This effect only used for the flipTimes label
      else if (behavior == 9) {
        path1.moveTo(x, y);
        path1.rLineTo(0, 0);
        path2.moveTo(1, 1);
        path2.lineTo(1, 1);
        path2.lineTo(2, 2);
      }

      ObjectAnimator mAnimator1, mAnimator2, mAnimator3;
      mAnimator1 = ObjectAnimator.ofFloat(myView, View.X, View.Y, path1);
      mAnimator2 = ObjectAnimator.ofFloat(myView, View.SCALE_X, View.SCALE_Y, path2);
      mAnimator1.setDuration(300);
      mAnimator2.setDuration(300);
      mAnimator1.setStartDelay(delay);
      mAnimator2.setStartDelay(delay);

      if (behavior == 0 || behavior == 1) {
        mAnimator1.setInterpolator(new BounceInterpolator());
        mAnimator2.setInterpolator(new BounceInterpolator());
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", myView.getAlpha(), 1);
        mAnimator3.setDuration(10);
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      } else if (behavior == 2 || behavior == 7) {
        myView.bringToFront();
        FrameLayout menuLayout = (FrameLayout) findViewById(R.id.menu);
        menuLayout.requestLayout();
        menuLayout.invalidate();

        mAnimator3 =
            ObjectAnimator.ofArgb(
                myView, "textColor", ((Button) myView).getCurrentTextColor(), Color.TRANSPARENT);
        mAnimator3.setDuration(100);
        mAnimator1.setInterpolator(new AccelerateInterpolator());
        mAnimator2.setInterpolator(new AccelerateInterpolator());
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
        mSound.play(mSoundID[SOUND_OPEN], 1, 1, 1, 0, 1);
      } else if (behavior == 3 || behavior == 8) {
        mAnimator3 =
            ObjectAnimator.ofArgb(
                myView, "textColor", ((Button) myView).getCurrentTextColor(), Color.WHITE);
        mAnimator3.setDuration(100);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator3.setStartDelay(delay + 200);
        mAnimator3.start();
        mSound.play(mSoundID[SOUND_CLOSE], 1, 1, 1, 0, 1);
      } else if (behavior == 4) {
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", myView.getAlpha(), 1);
        mAnimator3.setDuration(300);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      } else if (behavior == 5) {
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", myView.getAlpha(), 0);
        mAnimator3.setDuration(300);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      } else if (behavior == 6) {
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", myView.getAlpha(), 0);
        mAnimator3.setDuration(300);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      } else if (behavior == 9) {
        mAnimator3 = ObjectAnimator.ofFloat(myView, "alpha", 1, 0);
        mAnimator2.setDuration(1000);
        mAnimator3.setDuration(1000);
        mAnimator1.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setInterpolator(new DecelerateInterpolator());
        mAnimator2.setRepeatCount(Animation.INFINITE);
        mAnimator3.setRepeatCount(Animation.INFINITE);
        mAnimator3.setStartDelay(delay);
        mAnimator3.start();
      }
      if (behavior == 0 || behavior == 1 || behavior == 4) {
        mAnimator1.start();
      }
      mAnimator2.start();

      mAnimator1.addListener(
          new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
              if (behavior == 0) {
                mSound.play(mSoundID[SOUND_BLOP], 1, 1, 1, 0, 1);
              }
            }

            @Override
            public void onAnimationEnd(Animator animation) {}

            @Override
            public void onAnimationCancel(Animator animation) {}

            @Override
            public void onAnimationRepeat(Animator animation) {}
          });
    }
    // If the device OS is below Lollipop, the animation feature will be lost
    else {
      if (behavior == 5 || behavior == 6) {
        myView.setAlpha(0);
      } else {
        myView.setAlpha(1);
      }

      if (behavior == 2) {
        myView.setScaleX(10);
        myView.setScaleY(10);
        ((Button) myView).setTextColor(Color.TRANSPARENT);
      } else if (behavior == 3) {
        myView.setScaleX(1);
        myView.setScaleY(1);
        ((Button) myView).setTextColor(Color.WHITE);
      }

      if (behavior == 0) {
        mSound.play(mSoundID[SOUND_BLOP], 1, 1, 1, 0, 1);
      } else if (behavior == 2 || behavior == 7) {
        mSound.play(mSoundID[SOUND_OPEN], 1, 1, 1, 0, 1);
      } else if (behavior == 3 || behavior == 8) {
        mSound.play(mSoundID[SOUND_CLOSE], 1, 1, 1, 0, 1);
      } else if (behavior == 6) {
        mSound.play(mSoundID[SOUND_CLICK], 1, 1, 1, 0, 1);
      }
    }
  }