Ejemplo n.º 1
0
  private AnimatorSet startAniMoveRightToCenter(View rightDot) {
    int dotDiameter = (int) getResources().getDimension(R.dimen.loading_dot_size);
    int dotPadding = (int) getResources().getDimension(R.dimen.loading_dot_padding);
    AnimatorSet moveRightToCentral = new AnimatorSet();
    ObjectAnimator rightDotToCentral =
        ObjectAnimator.ofFloat(rightDot, "translationX", 0, -dotPadding - dotDiameter);

    rightDotColorChange =
        ValueAnimator.ofObject(
            new ArgbEvaluator(),
            getResources().getColor(R.color.dot_normal),
            getResources().getColor(R.color.dot_active));
    final GradientDrawable rightDotBg = (GradientDrawable) rightDot.getBackground();
    rightDotColorChange.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(final ValueAnimator animator) {
            rightDotBg.setColor((Integer) animator.getAnimatedValue());
          }
        });
    rightDotColorChange.setDuration(aniDuration);
    rightDotColorChange.addListener(this);
    moveRightToCentral.play(rightDotColorChange).with(rightDotToCentral);
    return moveRightToCentral;
  }
Ejemplo n.º 2
0
  private void smoothTo(int fromY, int toY) {
    ValueAnimator valueAnimator =
        ValueAnimator.ofObject(
            new TypeEvaluator<Integer>() {
              @Override
              public Integer evaluate(float fraction, Integer startValue, Integer endValue) {
                return startValue + (int) (fraction * (endValue - startValue));
              }
            },
            fromY,
            toY);

    valueAnimator.setInterpolator(null);
    valueAnimator.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
    valueAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            offsetTop = (int) animation.getAnimatedValue();
            requestLayout();
          }
        });

    valueAnimator.start();
  }
Ejemplo n.º 3
0
  @TargetApi(11)
  public ValueAnimator setSpeed(double progress, long duration, long startDelay) {
    if (progress <= 0)
      throw new IllegalArgumentException("Non-positive value specified as a speed.");

    if (progress > maxSpeed) progress = maxSpeed;

    ValueAnimator va =
        ValueAnimator.ofObject(
            new TypeEvaluator<Double>() {
              @Override
              public Double evaluate(float fraction, Double startValue, Double endValue) {
                return startValue + fraction * (endValue - startValue);
              }
            },
            Double.valueOf(getSpeed()),
            Double.valueOf(progress));

    va.setDuration(duration);
    va.setStartDelay(startDelay);
    va.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            Double value = (Double) animation.getAnimatedValue();
            if (value != null) setSpeed(value);
          }
        });
    va.start();
    return va;
  }
Ejemplo n.º 4
0
 private void startAnimation(int temp_moveX, int temp_moveY) {
   Point startPoint = new Point(temp_moveX, temp_moveY);
   Point endPoint = new Point((int) centerX, (int) centerY);
   ValueAnimator anim = ValueAnimator.ofObject(new PointEvaluator(), startPoint, endPoint);
   anim.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           Point point = (Point) animation.getAnimatedValue();
           moveX = point.getX();
           moveY = point.getY();
           Log.i("CJT", moveX + "   ====   " + moveY);
           invalidate();
         }
       });
   anim.addListener(
       new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
           isAnim = false;
           VIEW_STATUS = VIEW_ACTION_STATUS;
           invalidate();
         }
       });
   anim.setInterpolator(new SpringInterpolator());
   anim.setDuration(1000);
   anim.start();
 }
 private void dimBackgroundAsAnimation(final View view) {
   Integer colorFrom = getResources().getColor(android.R.color.transparent);
   Integer colorTo = getResources().getColor(R.color.black_semi_transparent);
   ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
   colorAnimation.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animator) {
           view.setBackgroundColor((Integer) animator.getAnimatedValue());
         }
       });
   colorAnimation.start();
 }
  @SuppressLint("NewApi")
  private void setNavigationBarTint(final int tintColor, boolean force) {
    if (mNavigationBarView == null) return;

    if (mSettingsHelper.shouldLinkStatusBarAndNavBar() && !force) {
      log("Ignoring manual navigation bar color change cause we're linked");
      return;
    }

    log("Setting navigation bar color to " + tintColor);

    if (mSettingsHelper.animateStatusBarTintChange()) {
      if (tintColor != KITKAT_TRANSPARENT_COLOR) {
        ValueAnimator colorAnimation =
            ValueAnimator.ofObject(new ArgbEvaluator(), mLastSetNavBarTint, tintColor);
        colorAnimation.addUpdateListener(
            new AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animator) {
                mNavigationBarView.setBackgroundColor((Integer) animator.getAnimatedValue());
              }
            });
        colorAnimation.start();
      } else {
        mNavigationBarView.setBackgroundColor(KITKAT_TRANSPARENT_COLOR);
        Utils.setViewBackground(
            mNavigationBarView,
            new BarBackgroundDrawable(
                mStatusBarView.getContext(), mResources, R.drawable.nav_background));
      }
    } else {
      if (tintColor == KITKAT_TRANSPARENT_COLOR) {
        mNavigationBarView.setBackgroundColor(KITKAT_TRANSPARENT_COLOR);
        Utils.setViewBackground(
            mNavigationBarView,
            new BarBackgroundDrawable(
                mNavigationBarView.getContext(), mResources, R.drawable.nav_background));
      } else {
        mNavigationBarView.setBackgroundColor(tintColor);
      }
    }

    if (mNavigationBarView != null && tintColor != KITKAT_TRANSPARENT_COLOR) {
      Intent intent = new Intent("gravitybox.intent.action.ACTION_NAVBAR_CHANGED");
      intent.putExtra("navbarBgColor", tintColor);
      intent.putExtra("navbarColorEnable", true);
      mNavigationBarView.getContext().sendBroadcast(intent);
    }

    mLastSetNavBarTint = tintColor;
  }
Ejemplo n.º 7
0
  private void animer(int width) {

    valeurHaut.setText("");
    valeurBas.setText("");

    ViewGroup.LayoutParams params = progressBarHaut.getLayoutParams();
    params.width = 0;
    progressBarHaut.setLayoutParams(params);

    ViewGroup.LayoutParams params2 = progressBarBas.getLayoutParams();
    params2.width = 0;
    progressBarBas.setLayoutParams(params2);

    float largeurMax = barreHaut.getWidth();
    float pourcentHaut = vHaut / max;
    float pourcentBas = vBas / max;

    int largeurHaut = (int) (largeurMax * pourcentHaut);
    int largeurtBas = (int) (largeurMax * pourcentBas);

    final AnimatorSet anim = new AnimatorSet();
    anim.setInterpolator(new AccelerateInterpolator());
    anim.setDuration((long) temps);
    anim.playTogether(
        ValueAnimator.ofObject(
            new WidthEvaluator(progressBarHaut, valeurHaut, vHaut), 0, largeurHaut),
        ValueAnimator.ofObject(
            new WidthEvaluator(progressBarBas, valeurBas, vBas), 0, largeurtBas));

    this.postDelayed(
        new Runnable() {
          @Override
          public void run() {
            anim.start();
          }
        },
        attente);
  }
  private static void animateFlashText(
      final TextView[] textViews, int color1, int color2, boolean staySecondColor) {

    ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), color1, color2);
    anim.addUpdateListener(
        new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animator) {
            for (TextView textView : textViews) {
              textView.setTextColor((Integer) animator.getAnimatedValue());
            }
          }
        });
    anim.setRepeatMode(ValueAnimator.REVERSE);
    anim.setRepeatCount(staySecondColor ? 4 : 5);
    anim.setDuration(180);
    anim.setInterpolator(new AccelerateInterpolator());
    anim.start();
  }
  @SuppressLint("NewApi")
  public void setStatusBarTint(final int tintColor) {
    if (mStatusBarView == null) return;

    log("Setting statusbar color to " + tintColor);

    if (mSettingsHelper.animateStatusBarTintChange()) {
      int animateFrom =
          mLastSetColor == KITKAT_TRANSPARENT_COLOR ? Color.TRANSPARENT : mLastSetColor;
      int animateTo = tintColor == KITKAT_TRANSPARENT_COLOR ? Color.TRANSPARENT : tintColor;
      ValueAnimator colorAnimation =
          ValueAnimator.ofObject(new ArgbEvaluator(), animateFrom, animateTo);
      colorAnimation.addUpdateListener(
          new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
              mGradientDrawable.setColor((Integer) animator.getAnimatedValue());
            }
          });
      Utils.setViewBackground(mStatusBarView, mGradientDrawable);
      mGradientDrawable.setMode(mSettingsHelper.getOverlayMode());
      colorAnimation.start();
    } else {
      mStatusBarView.setAlpha(1f);
      if (tintColor == KITKAT_TRANSPARENT_COLOR) {
        Utils.setViewBackground(mStatusBarView, mGradientDrawable);
        mGradientDrawable.setColor(Color.TRANSPARENT);
        mGradientDrawable.setMode(mSettingsHelper.getOverlayMode());
      } else {
        Utils.setViewBackground(mStatusBarView, mGradientDrawable);
        mGradientDrawable.setColor(tintColor);
        mGradientDrawable.setMode(mSettingsHelper.getOverlayMode());
      }
    }

    mLastSetColor = tintColor;

    if (mSettingsHelper.shouldLinkStatusBarAndNavBar() && !mKeyboardUp) {
      mNavigationBarTint = tintColor;
      setNavigationBarTint(tintColor, true);
    }
  }
Ejemplo n.º 10
0
  private void moveIndicatorByAnimation(int currPos, int lastPos) {
    int x1 = mIndicatorMarginTab + lastPos * mTabWidth;
    Point startPoint = new Point(x1, mIndicatorTopY);

    int lineMarginX_end = x1 + (currPos - lastPos) * mTabWidth;
    Point endPoint = new Point(lineMarginX_end, mIndicatorTopY);

    ValueAnimator animator = ValueAnimator.ofObject(new PointEvaluator(), startPoint, endPoint);
    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            Point point = (Point) valueAnimator.getAnimatedValue();
            mLineMarginX = (int) point.x;
            postInvalidate();
          }
        });
    animator.setDuration(200);
    animator.start();
  }
Ejemplo n.º 11
0
 private void startAnimator() {
   Point startPoint = new Point(getWidth() / 2, RADIUS);
   Point endPoint = new Point(getWidth() / 2, getHeight() - RADIUS);
   ValueAnimator anim = ValueAnimator.ofObject(new PointEvaluator(), startPoint, endPoint);
   anim.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           currentPoint = (Point) animation.getAnimatedValue();
           invalidate();
         }
       });
   ObjectAnimator anim2 =
       ObjectAnimator.ofObject(this, "color", new ColorEvaluator(), "#0000FF", "#FF0000");
   AnimatorSet animset = new AnimatorSet();
   animset.play(anim).with(anim2);
   animset.setInterpolator(new BounceInterpolator());
   animset.setDuration(5000);
   animset.start();
 }
Ejemplo n.º 12
0
  @Override
  protected void done(@Nullable Object result) {
    if (noBitmap) {
      // Animate to default color
      colorAnimation =
          ValueAnimator.ofObject(
              new ArgbEvaluator(), colorFrom, ContextCompat.getColor(context, R.color.color400));
      colorAnimation.setDuration(2000);

      colorAnimation.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
              detailHolder.setBackgroundColor((Integer) animator.getAnimatedValue());
            }
          });
      colorAnimation.start();
    }
  }
Ejemplo n.º 13
0
  public IconicLabelView setTexts(String text1, String text2) {
    if (text1 == null || text2 == null) {
      return this;
    }
    mText1 = text1;
    Rect text1Bounds = new Rect();
    mTextPaint.getTextBounds(mText1, 0, mText1.length(), text1Bounds);

    mText2 = text2;
    Rect text2Bounds = new Rect();
    mTextPaint.getTextBounds(mText2, 0, mText2.length(), text2Bounds);

    mText = text1;
    mTextBounds = new Rect(text1Bounds);

    mAnimText1ToText2 = true;
    mAnim = ValueAnimator.ofObject(new RectEvaluator(mTextBounds), text1Bounds, text2Bounds);
    mAnim.addUpdateListener(this);
    mAnim.addListener(this);
    return this;
  }
Ejemplo n.º 14
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();
  }
Ejemplo n.º 15
0
  private AnimatorSet startAniMoveCenterToRight(View centralDot) {
    int dotDiameter = (int) getResources().getDimension(R.dimen.loading_dot_size);
    int dotPadding = (int) getResources().getDimension(R.dimen.loading_dot_padding);
    AnimatorSet moveCentralToRight = new AnimatorSet();
    ObjectAnimator xOriginToXMinLeft =
        ObjectAnimator.ofFloat(centralDot, "translationX", dotPadding + dotDiameter, dotPadding)
            .setDuration(aniDuration);
    ObjectAnimator leftDotYOriginToYDown =
        ObjectAnimator.ofFloat(centralDot, "translationY", 0, dotPadding + dotDiameter)
            .setDuration(aniDuration);
    moveCentralToRight.play(xOriginToXMinLeft).with(leftDotYOriginToYDown);
    ObjectAnimator xMinLeftToXRight =
        ObjectAnimator.ofFloat(
                centralDot, "translationX", dotPadding, 3 * dotPadding + 2 * dotDiameter)
            .setDuration(aniDuration);
    ObjectAnimator leftDotYDownToYUp =
        ObjectAnimator.ofFloat(
                centralDot, "translationY", dotPadding + dotDiameter, -3 * dotDiameter)
            .setDuration(aniDuration);
    ObjectAnimator leftDotZoomInX =
        ObjectAnimator.ofFloat(centralDot, "scaleX", 1, zoomScale).setDuration(aniDuration / 2);
    ObjectAnimator leftDotZoomInY =
        ObjectAnimator.ofFloat(centralDot, "scaleY", 1, zoomScale).setDuration(aniDuration / 2);

    ObjectAnimator leftDotZoomOutX =
        ObjectAnimator.ofFloat(centralDot, "scaleX", zoomScale, 1).setDuration(aniDuration / 2);
    ObjectAnimator leftDotZoomOutY =
        ObjectAnimator.ofFloat(centralDot, "scaleY", zoomScale, 1).setDuration(aniDuration / 2);

    moveCentralToRight.play(xMinLeftToXRight).with(leftDotYDownToYUp).after(leftDotYOriginToYDown);
    moveCentralToRight.play(leftDotZoomInX).with(leftDotZoomInY).after(leftDotYOriginToYDown);
    moveCentralToRight.play(leftDotZoomOutX).with(leftDotZoomOutY).after(leftDotZoomInX);

    ObjectAnimator xRightToXOrigin =
        ObjectAnimator.ofFloat(
                centralDot,
                "translationX",
                3 * dotPadding + 2 * dotDiameter,
                2 * dotPadding + 2 * dotDiameter)
            .setDuration(aniDuration);
    ObjectAnimator leftDotYUpToYOrigin =
        ObjectAnimator.ofFloat(centralDot, "translationY", -3 * dotDiameter, 0)
            .setDuration(aniDuration);

    leftDotColorChangeToNormal =
        ValueAnimator.ofObject(
            new ArgbEvaluator(),
            getResources().getColor(R.color.dot_active),
            getResources().getColor(R.color.dot_normal));
    final GradientDrawable backgroundDrawable = (GradientDrawable) leftDot.getBackground();
    leftDotColorChangeToNormal.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {

          @Override
          public void onAnimationUpdate(final ValueAnimator animator) {
            backgroundDrawable.setColor((Integer) animator.getAnimatedValue());
            backgroundDrawable.setStroke(
                (int) getResources().getDimension(R.dimen.loading_dot_stroke_width),
                getResources().getColor(R.color.dot_active));
          }
        });
    leftDotColorChangeToNormal.setDuration(aniDuration);
    moveCentralToRight
        .play(xRightToXOrigin)
        .with(leftDotYUpToYOrigin)
        .with(leftDotColorChangeToNormal)
        .after(leftDotZoomOutX);
    leftDotColorChangeToNormal.addListener(this);
    return moveCentralToRight;
  }
  @Override
  public void onClick(View v) {
    Button button = (Button) v;
    int i = (int) button.getTag();
    switch (i) {
      case 0:
        new AchievementUnlocked(this)
            .setTitle("Lilac and Gooseberries")
            .setSubtitleColor(0x80ffffff)
            .setSubTitle("Find the sorceress")
            .setBackgroundColor(Color.parseColor("#C2185B"))
            .setTitleColor(0xffffffff)
            .setIcon(getDrawableFromRes(R.drawable.wand))
            .isLarge(false)
            .build()
            .show();
        break;
      case 1:
        new AchievementUnlocked(this)
            .setTitle("Transhumanist")
            .setSubTitle("Augmented")
            .setTypeface(Typeface.createFromAsset(getApplicationContext().getAssets(), "font.TTF"))
            .setIcon(getDrawableFromRes(R.drawable.mario))
            .setBackgroundDrawable(getDrawableFromRes(R.drawable.custom_bg))
            .isLarge(true)
            .build()
            .show();
        break;
      case 2:
        new AchievementUnlocked(this)
            .setTitle("Pacifist")
            .setSubTitle("They don't deserve death")
            .setIcon(getDrawableFromRes(R.drawable.monster))
            .isRounded(false)
            .isLarge(false)
            .alignTop(false)
            .build()
            .show();
        break;
      case 3:
        new AchievementUnlocked(this)
            .setTitle("I bet mine is bigger")
            .setSubTitle("Upgrade your guns")
            .isLarge(true)
            .alignTop(false)
            .setIcon(getDrawableFromRes(R.drawable.mario))
            .build()
            .show();
        break;
      case 4:
        new AchievementUnlocked(this)
            .setTitle("The Illusive Man")
            .setSubTitle("Shepard, Freedom's Progress won't investigate itself.")
            .setSubtitleColor(0x80000000)
            .setIcon(getDrawableFromRes(R.drawable.chat))
            .isRounded(false)
            .setDuration(2500)
            .isLarge(true)
            .build()
            .show();
        break;
      case 5:
        new AchievementUnlocked(this)
            .setTitle("Eliza Cassan posted on your timeline")
            .setSubtitleColor(0xffffffff)
            .setBackgroundColor(Color.parseColor("#3b5998"))
            .setSubTitle("Where can we meet?")
            .setIcon(getDrawableFromRes(R.drawable.fb))
            .setDuration(2500)
            .setTitleColor(0x80ffffff)
            .isLarge(false)
            .build()
            .show();
        break;
      case 6:
        final AchievementUnlocked achievementUnlocked =
            new AchievementUnlocked(this)
                .setTitle("Faridah Malik is calling...")
                .setTitleColor(0xff000000)
                .setSubTitle("Tap to reject")
                .setSubtitleColor(0x80000000)
                .setIcon(getDrawableFromRes(R.drawable.calling))
                .isPersistent(true)
                .build();

        View iconIV = achievementUnlocked.getIconView();
        ObjectAnimator outX = ObjectAnimator.ofFloat(iconIV, "scaleX", 1f, 0.7f);
        ObjectAnimator outY = ObjectAnimator.ofFloat(iconIV, "scaleY", 1f, 0.7f);
        ObjectAnimator inX = ObjectAnimator.ofFloat(iconIV, "scaleX", 0.7f, 1f);
        ObjectAnimator inY = ObjectAnimator.ofFloat(iconIV, "scaleY", 0.7f, 1f);
        final AnimatorSet Outset = new AnimatorSet();
        final AnimatorSet Ani = new AnimatorSet();
        final AnimatorSet Inset = new AnimatorSet();
        outX.setDuration(1000);
        outY.setDuration(1000);
        inX.setDuration(1000);
        inY.setDuration(1000);
        Ani.addListener(
            new AnimatorListenerAdapter() {
              @Override
              public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                Ani.start();
              }
            });
        Outset.playTogether(outX, outY);
        Inset.playTogether(inX, inY);
        (achievementUnlocked.getAchievementView())
            .setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    achievementUnlocked.dismiss();
                  }
                });
        Ani.play(Outset).before(Inset);
        achievementUnlocked.setAchievementListener(
            new AchievementUnlocked.achievementListener() {
              @Override
              public void onAchievementBeingCreated(
                  AchievementUnlocked achievement, boolean created) {}

              @Override
              public void onAchievementExpanding(
                  AchievementUnlocked achievement, boolean expanded) {
                if (expanded) Ani.start();
              }

              @Override
              public void onAchievementShrinking(
                  AchievementUnlocked achievement, boolean shrunken) {
                if (!shrunken) {
                  if (Ani.isRunning()) Ani.cancel();
                }
              }

              @Override
              public void onAchievementBeingDestroyed(
                  AchievementUnlocked achievement, boolean destroyed) {}
            });
        achievementUnlocked.show();
        break;
      case 7:
        new AchievementUnlocked(this)
            .setTitle("Ghosttown")
            .setIconBG(Color.parseColor("#E67E22"))
            .setBackgroundColor(Color.parseColor("#D35400"))
            .setTitleColor(0xffffffff)
            .setSubTitle("Madonna")
            .setSubtitleColor(0x80ffffff)
            .setIcon(getDrawableFromRes(R.drawable.music))
            .setDuration(1500)
            .isLarge(false)
            .build()
            .show();

        break;

      case 8:
        AchievementUnlocked toast =
            new AchievementUnlocked(this)
                .setTitle("Picture was sent")
                .setBackgroundColor(Color.parseColor("#333333"))
                .setTitleColor(0xffffffff)
                .setIcon(getDrawableFromRes(R.drawable.tick))
                .setDuration(1000)
                .alignTop(false)
                .isLarge(false)
                .build();
        toast.show();
        break;

      case 9:
        int bg = 0xffffffff;
        boolean rounded = false;
        if (Build.VERSION.SDK_INT >= 21) {
          rounded = true;
        }

        final AchievementUnlocked toastCool =
            new AchievementUnlocked(this)
                .isRounded(rounded)
                .setBackgroundColor(bg)
                .isPersistent(true)
                .setTitle("Message is about to be sent")
                .setSubTitle("Tap to cancel, or wait 3 sec until it's sent ")
                .setIcon(getDrawableFromRes(R.drawable.delete))
                .isPersistent(true)
                .build();

        final View popUp = toastCool.getAchievementView();

        final View icon = toastCool.getIconView();
        int delta = toastCool.height;
        final ObjectAnimator transout = ObjectAnimator.ofFloat(icon, "translationY", 0, delta);
        final ObjectAnimator transin = ObjectAnimator.ofFloat(icon, "translationY", -delta, 0);
        transin.setDuration(250);
        transout.setDuration(250);
        final ValueAnimator blue = ValueAnimator.ofObject(new ArgbEvaluator(), bg, 0xff2196F3);
        blue.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {

              @Override
              public void onAnimationUpdate(ValueAnimator animator) {
                if (Build.VERSION.SDK_INT >= 21) {
                  popUp.getBackground().setTint((Integer) animator.getAnimatedValue());
                } else {
                  popUp.setBackgroundColor((Integer) animator.getAnimatedValue());
                }
              }
            });

        final ValueAnimator red = ValueAnimator.ofObject(new ArgbEvaluator(), bg, 0xffF44336);
        red.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {

              @Override
              public void onAnimationUpdate(ValueAnimator animator) {
                if (Build.VERSION.SDK_INT >= 21) {
                  popUp.getBackground().setTint((Integer) animator.getAnimatedValue());
                } else {
                  popUp.setBackgroundColor((Integer) animator.getAnimatedValue());
                }
              }
            });
        popUp.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (toastCool.expanded && !blue.isRunning()) {
                  toastCool.dismiss();
                  red.start();
                  transout.addListener(
                      new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                          super.onAnimationEnd(animation);
                          if (Build.VERSION.SDK_INT >= 16) {
                            icon.setBackground(getDrawableFromRes(R.drawable.no));
                          } else {
                            icon.setBackgroundDrawable(getDrawableFromRes(R.drawable.no));
                          }
                          transin.start();
                        }
                      });
                  transout.start();
                }
              }
            });

        toastCool.setAchievementListener(
            new AchievementUnlocked.achievementListener() {
              @Override
              public void onAchievementBeingCreated(
                  AchievementUnlocked achievement, boolean created) {}

              @Override
              public void onAchievementExpanding(
                  AchievementUnlocked achievement, boolean expanded) {
                if (expanded)
                  (new android.os.Handler())
                      .postDelayed(
                          new Runnable() {
                            public void run() {
                              if (toastCool.expanded && !red.isRunning()) {
                                popUp.setOnClickListener(null);
                                toastCool.dismiss();
                                blue.start();

                                transout.addListener(
                                    new AnimatorListenerAdapter() {
                                      @Override
                                      public void onAnimationEnd(Animator animation) {
                                        super.onAnimationEnd(animation);
                                        if (Build.VERSION.SDK_INT >= 16) {
                                          icon.setBackground(getDrawableFromRes(R.drawable.send));
                                        } else {
                                          icon.setBackgroundDrawable(
                                              getDrawableFromRes(R.drawable.send));
                                        }

                                        transin.start();
                                      }
                                    });
                                transout.start();
                              }
                            }
                          },
                          3000);
              }

              @Override
              public void onAchievementShrinking(
                  AchievementUnlocked achievement, boolean shrunken) {
                achievement.getTitleTextView().setVisibility(View.INVISIBLE);

                achievement.getSubtitleTextView().setVisibility(View.INVISIBLE);
              }

              @Override
              public void onAchievementBeingDestroyed(
                  AchievementUnlocked achievement, boolean destroyed) {}
            });

        toastCool.show();

        break;

      case 10:
        AchievementUnlocked gpg =
            new AchievementUnlocked(this)
                .setTitle("Welcome")
                .setTitleColor(0x70444444)
                .setSubTitle("Jane Valderamma")
                .setSubtitleColor(0xff444444)
                .setIcon(getDrawableFromRes(R.drawable.gpg))
                .setDuration(1500)
                .isLarge(false)
                .build();
        final View iconView = gpg.getIconView();
        final Drawable iconViewDefaultBackground = gpg.getIconView().getBackground();
        final ObjectAnimator out = ObjectAnimator.ofFloat(iconView, "alpha", 1f, 0f);
        final ObjectAnimator in = ObjectAnimator.ofFloat(iconView, "alpha", 0f, 1f);

        gpg.setAchievementListener(
            new AchievementUnlocked.achievementListener() {
              @Override
              public void onAchievementBeingCreated(
                  AchievementUnlocked achievement, boolean created) {}

              @Override
              public void onAchievementExpanding(
                  AchievementUnlocked achievement, boolean expanded) {
                if (expanded) {

                  out.addListener(
                      new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                          super.onAnimationEnd(animation);
                          if (Build.VERSION.SDK_INT >= 16) {
                            iconView.setBackground(getDrawableFromRes(R.drawable.jane));
                          } else {
                            iconView.setBackgroundDrawable(getDrawableFromRes(R.drawable.jane));
                          }
                          in.start();
                        }
                      });
                  out.start();
                }
              }

              @Override
              public void onAchievementShrinking(
                  AchievementUnlocked achievement, boolean shrunken) {

                if (!shrunken) {

                  out.addListener(
                      new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                          super.onAnimationEnd(animation);
                          if (Build.VERSION.SDK_INT >= 16) {
                            iconView.setBackground(iconViewDefaultBackground);
                          } else iconView.setBackgroundDrawable(iconViewDefaultBackground);

                          in.start();
                        }
                      });
                  out.start();
                }
              }

              @Override
              public void onAchievementBeingDestroyed(
                  AchievementUnlocked achievement, boolean destroyed) {}
            });
        gpg.show();

        break;
    }
  }
  public void startTickAnim() {
    mStatus = TICK;
    Path rightEndPath = new Path();
    rightEndPath.moveTo(cxLeft, cyLeft - mLineRadius);
    rightEndPath.cubicTo(
        cxRight + 2 * mLineRadius,
        cyRight - 2 * mLineRadius,
        cxRight + 2 * mLineRadius,
        cyRight + 2 * mLineRadius,
        (float) (cxLeft + mRecWidth * 0.48 - 1.5 * mTickLen),
        (float) (cyLeft - mRadius * 0.25));
    final PathMeasure mPathMeasureRightEnd = new PathMeasure(rightEndPath, false);
    Path rightStartPath = new Path();
    rightStartPath.moveTo(cxLeft, cyLeft - mLineRadius);
    rightStartPath.cubicTo(
        cxRight + 2 * mLineRadius,
        cyRight - 2 * mLineRadius,
        cxRight + 2 * mLineRadius,
        cyRight + 2 * mLineRadius,
        (float) (cxLeft + mRecWidth * 0.48),
        (float) (cyLeft + mTickLen * Math.cos(45)));
    final PathMeasure mPathMeasureRightStart = new PathMeasure(rightStartPath, false);
    Path leftEndPath = new Path();
    leftEndPath.moveTo(cxRight, cyRight + mLineRadius);
    leftEndPath.cubicTo(
        cxLeft - 2 * mLineRadius,
        cyRight - 2 * mLineRadius,
        cxLeft - 2 * mLineRadius,
        cyLeft + 2 * mLineRadius,
        (float) (cxLeft + mRecWidth * 0.48 + 2 * mTickLen),
        cyLeft - mTickLen);

    Path leftStartPath = new Path();
    leftStartPath.moveTo(cxRight, cyRight + mLineRadius);
    leftStartPath.cubicTo(
        cxLeft - 3 * mLineRadius,
        cyRight - 3 * mLineRadius,
        cxLeft - 3 * mLineRadius,
        cyLeft + 3 * mLineRadius,
        (float) (cxLeft + mRecWidth * 0.48),
        (float) (cyLeft + mTickLen * Math.cos(45)));

    final PathMeasure mPathMeasureLeftEnd = new PathMeasure(leftEndPath, false);
    final PathMeasure mPathMeasureLeftStart = new PathMeasure(leftStartPath, false);
    btnBgColorAnim = ValueAnimator.ofObject(new ArgbEvaluator(), mInitBtnColor, mLineColor);
    tickColorAnim = ValueAnimator.ofObject(new ArgbEvaluator(), mLineColor, mTickColor);
    tickRightEndAnim = ValueAnimator.ofFloat(0, mPathMeasureRightEnd.getLength());
    tickRightStartAnim = ValueAnimator.ofFloat(0, mPathMeasureRightStart.getLength());
    tickLeftEndAnim = ValueAnimator.ofFloat(0, mPathMeasureLeftEnd.getLength());
    tickLeftStartAnim = ValueAnimator.ofFloat(0, mPathMeasureLeftStart.getLength());
    tickRightStartAnim.setInterpolator(new LinearInterpolator());
    int mTickDuration = 3;
    tickColorAnim.setDuration(mRippleDuration * mTickDuration);
    btnBgColorAnim.setDuration(mRippleDuration * mTickDuration);
    tickRightStartAnim.setDuration(mRippleDuration * mTickDuration);
    tickRightEndAnim.setDuration(mRippleDuration * mTickDuration);
    tickLeftEndAnim.setDuration(mRippleDuration * mTickDuration);
    tickLeftStartAnim.setDuration(mRippleDuration * mTickDuration);
    tickLeftStartAnim.setInterpolator(new LinearInterpolator());
    tickColorAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mTickPaint.setColor((Integer) animation.getAnimatedValue());
          }
        });
    btnBgColorAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mButtonPaint.setColor((Integer) animation.getAnimatedValue());
          }
        });
    tickLeftEndAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          float value;

          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            value = (Float) animation.getAnimatedValue();
            mPathMeasureLeftEnd.getPosTan(value, mTickLeftEndPosition, null);
          }
        });
    tickLeftStartAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          float value;

          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            value = (Float) animation.getAnimatedValue();
            mPathMeasureLeftStart.getPosTan(value, mTickLeftStartPosition, null);
          }
        });
    tickRightEndAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          float value;

          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            value = (Float) animation.getAnimatedValue();
            mPathMeasureRightEnd.getPosTan(value - mTickLen, mTickRightEndPosition, null);
            Log.d(TAG, "onAnimationUpdate: mTickRightEndPosition" + mTickRightEndPosition[0]);
            postInvalidate();
          }
        });
    tickRightStartAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          float value;

          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            value = (Float) animation.getAnimatedValue();
            mPathMeasureRightStart.getPosTan(value, mTickRightStartPosition, null);
          }
        });
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
        tickLeftEndAnim,
        tickRightEndAnim,
        tickLeftStartAnim,
        tickRightStartAnim,
        btnBgColorAnim,
        tickColorAnim);
    animatorSet.start();
  }
Ejemplo n.º 18
0
  private AnimatorSet startAniMoveCenterToLeft(View centralDot) {
    int dotDiameter = (int) getResources().getDimension(R.dimen.loading_dot_size);
    int dotPadding = (int) getResources().getDimension(R.dimen.loading_dot_padding);
    AnimatorSet centerToLeftAni = new AnimatorSet();

    // move the central dot to lower right
    ObjectAnimator yOriginToYDown =
        ObjectAnimator.ofFloat(centralDot, "translationY", 0, dotPadding + dotDiameter)
            .setDuration(aniDuration);
    ObjectAnimator xOriginToXMinRight =
        ObjectAnimator.ofFloat(centralDot, "translationX", 0, dotPadding).setDuration(aniDuration);
    centerToLeftAni.playTogether(yOriginToYDown, xOriginToXMinRight);

    // move the central dot to up left
    ObjectAnimator yDownToYUp =
        ObjectAnimator.ofFloat(
                centralDot, "translationY", dotPadding + dotDiameter, -3 * dotDiameter)
            .setDuration(aniDuration);
    ObjectAnimator xMinRightToXLeft =
        ObjectAnimator.ofFloat(
                centralDot, "translationX", dotPadding, -2 * dotPadding - dotDiameter)
            .setDuration(aniDuration);

    centerToLeftAni.play(yDownToYUp).with(xMinRightToXLeft).after(yOriginToYDown);

    ObjectAnimator zoomInX =
        ObjectAnimator.ofFloat(centralDot, "scaleX", 1, zoomScale).setDuration(aniDuration / 2);
    ObjectAnimator zoomInY =
        ObjectAnimator.ofFloat(centralDot, "scaleY", 1, zoomScale).setDuration(aniDuration / 2);

    ObjectAnimator zoomOutX =
        ObjectAnimator.ofFloat(centralDot, "scaleX", zoomScale, 1).setDuration(aniDuration / 2);
    ObjectAnimator zoomOutY =
        ObjectAnimator.ofFloat(centralDot, "scaleY", zoomScale, 1).setDuration(aniDuration / 2);
    centerToLeftAni.play(zoomInX).with(zoomInY).after(yOriginToYDown);
    centerToLeftAni.play(zoomOutX).with(zoomOutY).after(zoomInX);

    ObjectAnimator yUpToYOrigin =
        ObjectAnimator.ofFloat(centralDot, "translationY", -3 * dotDiameter, 0)
            .setDuration(aniDuration);
    ObjectAnimator xLeftToLeftDotSpot =
        ObjectAnimator.ofFloat(
                centralDot,
                "translationX",
                -2 * Utilities.dpToPixels(getContext(), 10) - dotDiameter,
                -dotPadding - dotDiameter)
            .setDuration(aniDuration);
    centerToLeftAni.play(yUpToYOrigin).with(xLeftToLeftDotSpot);
    centerToLeftAni.play(yUpToYOrigin).after(xMinRightToXLeft);

    centralDotColorChangeToNormal =
        ValueAnimator.ofObject(
            new ArgbEvaluator(),
            getResources().getColor(R.color.dot_active),
            getResources().getColor(R.color.dot_normal));
    final GradientDrawable centralDotBg = (GradientDrawable) centralDot.getBackground();
    centralDotColorChangeToNormal.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {

          @Override
          public void onAnimationUpdate(final ValueAnimator animator) {
            centralDotBg.setColor((Integer) animator.getAnimatedValue());
            centralDotBg.setStroke(
                (int) getResources().getDimension(R.dimen.loading_dot_stroke_width),
                getResources().getColor(R.color.dot_active));
          }
        });
    centralDotColorChangeToNormal.addListener(this);
    centerToLeftAni.play(centralDotColorChangeToNormal).after(zoomOutX);
    return centerToLeftAni;
  }
  protected void onResult(final String result) {
    // Calculate the values needed to perform the scale and translation animations,
    // accounting for how the scale will affect the final position of the text.
    final float resultScale =
        mFormulaEditText.getVariableTextSize(result) / mResultEditText.getTextSize();
    final float resultTranslationX =
        (1.0f - resultScale)
            * (mResultEditText.getWidth() / 2.0f - mResultEditText.getPaddingRight());

    // Calculate the height of the formula (without padding)
    final float formulaRealHeight =
        mFormulaEditText.getHeight()
            - mFormulaEditText.getPaddingTop()
            - mFormulaEditText.getPaddingBottom();

    // Calculate the height of the resized result (without padding)
    final float resultRealHeight =
        resultScale
            * (mResultEditText.getHeight()
                - mResultEditText.getPaddingTop()
                - mResultEditText.getPaddingBottom());

    // Now adjust the result upwards!
    final float resultTranslationY =
        // Move the result up (so both formula + result heights match)
        -mFormulaEditText.getHeight()
            // Now switch the result's padding top with the formula's padding top
            - resultScale * mResultEditText.getPaddingTop()
            + mFormulaEditText.getPaddingTop()
            // But the result centers its text! And it's taller now! So adjust for that centered
            // text
            + (formulaRealHeight - resultRealHeight) / 2;

    // Move the formula all the way to the top of the screen
    final float formulaTranslationY = -mFormulaEditText.getBottom();

    // Use a value animator to fade to the final text color over the course of the animation.
    final int resultTextColor = mResultEditText.getCurrentTextColor();
    final int formulaTextColor = mFormulaEditText.getCurrentTextColor();
    final ValueAnimator textColorAnimator =
        ValueAnimator.ofObject(new ArgbEvaluator(), resultTextColor, formulaTextColor);
    textColorAnimator.addUpdateListener(
        new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mResultEditText.setTextColor((Integer) valueAnimator.getAnimatedValue());
          }
        });
    mResultEditText.setText(result);
    mResultEditText.setPivotX(mResultEditText.getWidth() / 2);
    mResultEditText.setPivotY(0f);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
        textColorAnimator,
        ObjectAnimator.ofFloat(mResultEditText, View.SCALE_X, resultScale),
        ObjectAnimator.ofFloat(mResultEditText, View.SCALE_Y, resultScale),
        ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_X, resultTranslationX),
        ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_Y, resultTranslationY),
        ObjectAnimator.ofFloat(mFormulaEditText, View.TRANSLATION_Y, formulaTranslationY));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(
        new AnimationFinishedListener() {
          @Override
          public void onAnimationFinished() {
            // Reset all of the values modified during the animation.
            mResultEditText.setPivotY(mResultEditText.getHeight() / 2);
            mResultEditText.setTextColor(resultTextColor);
            mResultEditText.setScaleX(1.0f);
            mResultEditText.setScaleY(1.0f);
            mResultEditText.setTranslationX(0.0f);
            mResultEditText.setTranslationY(0.0f);
            mFormulaEditText.setTranslationY(0.0f);

            // Finally update the formula to use the current result.
            mFormulaEditText.setText(result);
            setState(CalculatorState.RESULT);
          }
        });

    play(animatorSet);
  }
Ejemplo n.º 20
0
  /** Method that request the deletion of the current selected frame */
  @SuppressWarnings("boxing")
  public void deleteCurrentFrame() {
    if (mTarget == null) return;
    if (mResizeFrame == null) return;

    final Disposition targetDisposition = resizerToDisposition();

    // Get valid dispositions to move
    final List<Disposition> adjacents = findAdjacentsDispositions(targetDisposition);
    if (adjacents == null) {
      // Nothing to do
      Toast.makeText(
              getContext(), R.string.pref_disposition_unable_delete_advise, Toast.LENGTH_SHORT)
          .show();
      return;
    }

    // Hide resizer
    mResizeFrame.setVisibility(View.GONE);

    // Animate adjacents views
    List<Animator> animators = new ArrayList<Animator>();
    animators.add(ObjectAnimator.ofFloat(mTarget, "scaleX", 1.0f, 0.0f));
    animators.add(ObjectAnimator.ofFloat(mTarget, "scaleY", 1.0f, 0.0f));

    Disposition first = null;
    for (Disposition adjacent : adjacents) {
      // Extract the view and remove from dispositions
      View v = findViewFromRect(getLocationFromDisposition(adjacent));
      mDispositions.remove(adjacent);

      // Clone first disposition
      if (first == null) {
        first = new Disposition();
        first.x = adjacent.x;
        first.y = adjacent.y;
        first.w = adjacent.w;
        first.h = adjacent.h;
      }

      // Add animators and fix the adjacent
      if (v != null) {
        if (first.x < targetDisposition.x) {
          // From Left to Right
          int width = mTarget.getWidth() + mInternalPadding;
          animators.add(
              ValueAnimator.ofObject(
                  new Evaluators.WidthEvaluator(v), v.getWidth(), v.getWidth() + width));

          // Update the adjacent
          adjacent.w += targetDisposition.w;
          mDispositions.add(adjacent);

        } else if (first.x > targetDisposition.x) {
          // From Right to Left
          int width = mTarget.getWidth() + mInternalPadding;
          animators.add(
              ValueAnimator.ofObject(
                  new Evaluators.WidthEvaluator(v), v.getWidth(), v.getWidth() + width));
          animators.add(ObjectAnimator.ofFloat(v, "x", v.getX(), mTarget.getX()));

          // Update the adjacent
          adjacent.x = targetDisposition.x;
          adjacent.w += targetDisposition.w;
          mDispositions.add(adjacent);

        } else if (first.y < targetDisposition.y) {
          // From Top to Bottom
          int height = mTarget.getHeight() + mInternalPadding;
          animators.add(
              ValueAnimator.ofObject(
                  new Evaluators.HeightEvaluator(v), v.getHeight(), v.getHeight() + height));

          // Update the adjacent
          adjacent.h += targetDisposition.h;
          mDispositions.add(adjacent);

        } else if (first.y > targetDisposition.y) {
          // From Bottom to Top
          int height = mTarget.getHeight() + mInternalPadding;
          animators.add(
              ValueAnimator.ofObject(
                  new Evaluators.HeightEvaluator(v), v.getHeight(), v.getHeight() + height));
          animators.add(ObjectAnimator.ofFloat(v, "y", v.getY(), mTarget.getY()));

          // Update the adjacent
          adjacent.y = targetDisposition.y;
          adjacent.h += targetDisposition.h;
          mDispositions.add(adjacent);
        }
      }
    }
    if (animators.size() > 0) {
      AnimatorSet animSet = new AnimatorSet();
      animSet.playTogether(animators);
      animSet.setDuration(getResources().getInteger(R.integer.disposition_hide_anim));
      animSet.setInterpolator(new AccelerateInterpolator());
      animSet.addListener(
          new AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
              // Ignore
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
              // Ignore
            }

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

            @Override
            public void onAnimationCancel(Animator animation) {
              finishDeleteAnimation(targetDisposition);
            }
          });
      animSet.start();
    }
  }