Java Code Examples for android.animation.ValueAnimator#ofFloat()

The following examples show how to use android.animation.ValueAnimator#ofFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Scale.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues,
        TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }

    final float startScale = (Float) startValues.values.get(PROPNAME_SCALE);
    final float endScale = (Float) endValues.values.get(PROPNAME_SCALE);

    final View view = startValues.view;
    view.setScaleX(startScale);
    view.setScaleY(startScale);

    ValueAnimator animator = ValueAnimator.ofFloat(startScale, endScale);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            final float scale = (Float) animation.getAnimatedValue();
            view.setScaleX(scale);
            view.setScaleY(scale);
        }
    });
    return animator;
}
 
Example 2
Source File: PaymentRequestUI.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom,
        int oldLeft, int oldTop, int oldRight, int oldBottom) {
    if (mSheetAnimator != null) mSheetAnimator.cancel();

    mRequestView.removeOnLayoutChangeListener(this);
    mContainerHeightDifference = (bottom - top) - (oldBottom - oldTop);

    ValueAnimator containerAnimator = ValueAnimator.ofFloat(1f, 0f);
    containerAnimator.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float alpha = (Float) animation.getAnimatedValue();
            update(alpha);
        }
    });

    mSheetAnimator = containerAnimator;
    mSheetAnimator.setDuration(DIALOG_ENTER_ANIMATION_MS);
    mSheetAnimator.setInterpolator(new LinearOutSlowInInterpolator());
    mSheetAnimator.addListener(this);
    mSheetAnimator.start();
}
 
Example 3
Source File: ShapeRipple.java    From ShapeRipple with Apache License 2.0 6 votes vote down vote up
/**
 * Start the {@link #rippleValueAnimator} with specified duration for each ripple.
 *
 * @param millis the duration in milliseconds
 */
void start(int millis) {

    // Do a ripple value renderer
    rippleValueAnimator = ValueAnimator.ofFloat(0f, 1f);
    rippleValueAnimator.setDuration(millis);
    rippleValueAnimator.setRepeatMode(ValueAnimator.RESTART);
    rippleValueAnimator.setRepeatCount(ValueAnimator.INFINITE);
    rippleValueAnimator.setInterpolator(rippleInterpolator);
    rippleValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            render((Float) animation.getAnimatedValue());
        }
    });

    rippleValueAnimator.start();
}
 
Example 4
Source File: ScreenUtils.java    From BookReader with Apache License 2.0 6 votes vote down vote up
/**
 * 调整窗口的透明度  1.0f,0.5f 变暗
 *
 * @param from    from>=0&&from<=1.0f
 * @param to      to>=0&&to<=1.0f
 * @param context 当前的activity
 */
public static void dimBackground(final float from, final float to, Activity context) {
    final Window window = context.getWindow();
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(from, to);
    valueAnimator.setDuration(500);
    valueAnimator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    WindowManager.LayoutParams params = window.getAttributes();
                    params.alpha = (Float) animation.getAnimatedValue();
                    window.setAttributes(params);
                }
            });
    valueAnimator.start();
}
 
Example 5
Source File: IconRotateController.java    From DragFooterView with Apache License 2.0 6 votes vote down vote up
private void startIconRotateAnimator(@DragContainer.DragState int dragState) {
    if (iconRotateAnimator != null && iconRotateAnimator.isRunning()) {
        iconRotateAnimator.cancel();
    }
    if (dragState == DragContainer.DRAG_OUT) {
        dragOutRotateAnimatorExecuted = true;
        dragInRotateAnimatorExecuted = false;
        iconRotateAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
    } else {
        dragInRotateAnimatorExecuted = true;
        dragOutRotateAnimatorExecuted = false;
        iconRotateAnimator = ValueAnimator.ofFloat(1.0f, 0.0f);
    }
    iconRotateAnimator.setDuration(rotateDuration);
    iconRotateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            rotateDegree = (float) animation.getAnimatedValue() * 180;
        }
    });
    iconRotateAnimator.start();
}
 
Example 6
Source File: ElevationTransition.java    From Cinema-App-Concept with MIT License 6 votes vote down vote up
@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }

    Float startVal = (Float) startValues.values.get(PROPNAME_ELEVATION);
    Float endVal = (Float) endValues.values.get(PROPNAME_ELEVATION);
    if (startVal == null || endVal == null || startVal.floatValue() == endVal.floatValue()) {
        return null;
    }

    final View view = endValues.view;
    ValueAnimator a = ValueAnimator.ofFloat(startVal, endVal);
    a.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            view.setElevation((float)animation.getAnimatedValue());
        }
    });

    return a;
}
 
Example 7
Source File: TwoFishView.java    From luckly_recyclerview with MIT License 6 votes vote down vote up
/**
 * 开始动画
 */
private void startAnimation() {
    for (int i = 0; i < numberOfCircle; i++) {
        final int index = i;
        fadeAnimator = ValueAnimator.ofFloat(0, 360);
        fadeAnimator.setRepeatCount(ValueAnimator.INFINITE);
        fadeAnimator.setDuration(1700);
        fadeAnimator.setStartDelay((index >= 5 ? index - 5 : index) * 100);
        fadeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                rotates[index] = (float) animation.getAnimatedValue();
                invalidate();
            }
        });

        fadeAnimator.start();
    }
}
 
Example 8
Source File: KLetter.java    From ReadMark with Apache License 2.0 6 votes vote down vote up
@Override
public void startAnim() {
    mAnimator = ValueAnimator.ofFloat(0, 1);
    mAnimator.setDuration(mDuration);
    mAnimator.setRepeatCount(0);
    mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float factor = (float) animation.getAnimatedValue();
            mSweepArg = (int) (180 * factor);
            mSecPoint.y = (int) (mFirPoint.y + 3 * MAX_RADIUS_CIRCLE * factor);
            if(factor > 0.6 && factor < 0.9){
                mFourPoint.x = (int) (mThiPoint.x + (factor - 0.6) / 4 * 10 * MAX_RADIUS_CIRCLE);
                mFifPoint.x = mFourPoint.x;
            }else if(factor > 0.9){
                mFifPoint.y = mSecPoint.y;
            }
        }
    });
    mAnimator.start();
}
 
Example 9
Source File: MainUIActivity.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private void m()
{
    if (ad.booleanValue())
    {
        return;
    } else
    {
        ValueAnimator valueanimator = ValueAnimator.ofFloat(new float[] {
            0.0F, 1.0F
        });
        valueanimator.setDuration(100L);
        valueanimator.addListener(new aG(this));
        valueanimator.addUpdateListener(new aH(this));
        valueanimator.start();
        return;
    }
}
 
Example 10
Source File: MaterialSquareLoading.java    From materialsquareloading with Apache License 2.0 5 votes vote down vote up
public static ValueAnimator createCosinusValueAnimator(final float start, final float end, final CosinusAnimatorUpdateListener listener) {
  ValueAnimator valueAnimator = ValueAnimator.ofFloat((float) (-Math.PI), (float) (Math.PI));
  valueAnimator.setInterpolator(new LinearInterpolator());
  if (listener != null) {
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
      @Override public void onAnimationUpdate(ValueAnimator animation) {
        double offset = (Math.cos((float) animation.getAnimatedValue()) + 1) / 2;
        float value = (float) (start + (end - start) * offset);
        listener.onCosinusAnimatorUpdate(value);
      }
    });
  }
  return valueAnimator;
}
 
Example 11
Source File: QRefreshLayout.java    From QRefreshLayout with MIT License 5 votes vote down vote up
private void animateToSecondFloor() {
    if (isAnimating) return;
    isAnimating = true;
    if (animatorToSecondFloor == null) {
        animatorToSecondFloor = ValueAnimator.ofFloat(overScroll, viewContentHeight);
        animatorToSecondFloor.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float height = (float) animation.getAnimatedValue();
                overScroll = height;
                viewRefreshContainer.setTranslationY(overScroll / 2);
                viewLoadContainer.setTranslationY(overScroll / 2);
                viewRefresh.setHeight(Math.abs(overScroll), loadMidHeight, viewContentHeight);
                viewTarget.setTranslationY(overScroll);
                if (height == viewContentHeight) {
                    isAnimating = false;
                    isInSecondFloor = true;
                    viewRefresh.setToSecondFloor();
                }
            }
        });
        animatorToSecondFloor.setDuration(animateDuration);
    } else {
        animatorToSecondFloor.setFloatValues(overScroll, viewContentHeight);
    }
    animatorToSecondFloor.start();
}
 
Example 12
Source File: BottomSheetBehavior.java    From bottomsheetrecycler with Apache License 2.0 5 votes vote down vote up
private void createShapeValueAnimator() {
    interpolatorAnimator = ValueAnimator.ofFloat(0f, 1f);
    interpolatorAnimator.setDuration(CORNER_ANIMATION_DURATION);
    interpolatorAnimator.addUpdateListener(
            new AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float value = (float) animation.getAnimatedValue();
                    if (materialShapeDrawable != null) {
                        materialShapeDrawable.setInterpolation(value);
                    }
                }
            });
}
 
Example 13
Source File: PieChatView.java    From ClockView with Apache License 2.0 5 votes vote down vote up
private void initAnimator() {
    ValueAnimator anim = ValueAnimator.ofFloat(0, 360);
    anim.setDuration(10000);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            animatedValue = (float) valueAnimator.getAnimatedValue();
            invalidate();
        }
    });
    anim.start();
}
 
Example 14
Source File: ProxySettingsActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void setShareDoneEnabled(boolean enabled, boolean animated) {
    if (shareDoneEnabled != enabled) {
        if (shareDoneAnimator != null) {
            shareDoneAnimator.cancel();
        } else if (animated) {
            shareDoneAnimator = ValueAnimator.ofFloat(0f, 1f);
            shareDoneAnimator.setDuration(200);
            shareDoneAnimator.addUpdateListener(a -> {
                shareDoneProgress = AndroidUtilities.lerp(shareDoneProgressAnimValues, a.getAnimatedFraction());
                shareCell.setTextColor(ColorUtils.blendARGB(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2), Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4), shareDoneProgress));
                doneItem.setAlpha(shareDoneProgress / 2f + 0.5f);
            });
        }
        if (animated) {
            shareDoneProgressAnimValues[0] = shareDoneProgress;
            shareDoneProgressAnimValues[1] = enabled ? 1f : 0f;
            shareDoneAnimator.start();
        } else {
            shareDoneProgress = enabled ? 1f : 0f;
            shareCell.setTextColor(enabled ? Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4) : Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
            doneItem.setAlpha(enabled ? 1f : .5f);
        }
        shareCell.setEnabled(enabled);
        doneItem.setEnabled(enabled);
        shareDoneEnabled = enabled;
    }
}
 
Example 15
Source File: MainActivity.java    From Tutors with Apache License 2.0 5 votes vote down vote up
private void initViews() {
    this.buttonOk = (Button) findViewById(R.id.button_ok);
    this.buttonShow = (Button) findViewById(R.id.button_show);
    this.textDescription = (TextView) findViewById(R.id.text_description);
    this.buttonHello = (Button) findViewById(R.id.button_hello);
    this.toolbar = (Toolbar) findViewById(R.id.toolbar);

    setSupportActionBar(toolbar);

    tutors = new TutorsBuilder()
            .textColorRes(android.R.color.white)
            .shadowColorRes(R.color.shadow)
            .textSizeRes(R.dimen.textNormal)
            .completeIconRes(R.drawable.ic_cross_24_white)
            .spacingRes(R.dimen.spacingNormal)
            .lineWidthRes(R.dimen.lineWidth)
            .cancelable(false)
            .build();

    buttonShow.setOnClickListener(this);

    tutors.setListener(this);

    ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            MainActivity.this.buttonHello.setAlpha((Float) animation.getAnimatedValue());
        }
    });

    animator.setDuration(500);
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.setRepeatCount(-1);
    animator.start();
}
 
Example 16
Source File: PullForegroundDrawable.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void updateTextProgress(float pullProgress) {
    boolean endText = pullProgress > SNAP_HEIGHT;
    if (animateToEndText != endText) {
        animateToEndText = endText;
        if (textInProgress == 0f) {
            if (textSwipingAnimator != null) {
                textSwipingAnimator.cancel();
            }
            textSwappingProgress = endText ? 0f : 1f;
        } else {
            if (textSwipingAnimator != null) {
                textSwipingAnimator.cancel();
            }
            textSwipingAnimator = ValueAnimator.ofFloat(textSwappingProgress, endText ? 0f : 1f);
            textSwipingAnimator.addUpdateListener(textSwappingUpdateListener);
            textSwipingAnimator.setInterpolator(new LinearInterpolator());
            textSwipingAnimator.setDuration(170);
            textSwipingAnimator.start();
        }
    }

    if (endText != arrowAnimateTo) {
        arrowAnimateTo = endText;
        if (arrowRotateAnimator != null) {
            arrowRotateAnimator.cancel();
        }
        arrowRotateAnimator = ValueAnimator.ofFloat(arrowRotateProgress, arrowAnimateTo ? 0f : 1f);
        arrowRotateAnimator.addUpdateListener(animation -> {
            arrowRotateProgress = (float) animation.getAnimatedValue();
            if (cell != null) {
                cell.invalidate();
            }
        });
        arrowRotateAnimator.setInterpolator(CubicBezierInterpolator.EASE_BOTH);
        arrowRotateAnimator.setDuration(250);
        arrowRotateAnimator.start();
    }
}
 
Example 17
Source File: InsightsAnimatorSetFactory.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static @Nullable Animator createPercentSecureAnimator(@Nullable UpdateListener updateListener) {
  if (updateListener == null) return null;

  final ValueAnimator percentSecureAnimator = ValueAnimator.ofFloat(1f, PERCENT_SECURE_MAX_SCALE, 1f);

  percentSecureAnimator.setStartDelay(ANIMATION_START_DELAY);
  percentSecureAnimator.setDuration(PERCENT_SECURE_ANIMATION_DURATION);
  percentSecureAnimator.addUpdateListener(animation -> updateListener.onUpdate((float) animation.getAnimatedValue()));

  return percentSecureAnimator;
}
 
Example 18
Source File: Hold.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public Animator onAppear(
    @NonNull ViewGroup sceneRoot,
    @NonNull View view,
    @Nullable TransitionValues startValues,
    @Nullable TransitionValues endValues) {
  return ValueAnimator.ofFloat(0);
}
 
Example 19
Source File: FocusLayoutManager.java    From FocusLayoutManager with Apache License 2.0 4 votes vote down vote up
private void startValueAnimator(int position) {
        cancelAnimator();

        final float distance = getScrollToPositionOffset(position);
//        log("onceLength = " + onceCompleteScrollLength);
//        log("curoffset = " + mHorizontalOffset + ";distance = " + distance + ";endOffset = " +
// (mHorizontalOffset + distance));
//        log("currentpos = " + ((int) (Math.abs(mHorizontalOffset) / (int)
// onceCompleteScrollLength)) + ";end pos = " + ((mHorizontalOffset + distance) %
// onceCompleteScrollLength));
//        log("current fra = " + ((Math.abs(mHorizontalOffset) % onceCompleteScrollLength) /
// (onceCompleteScrollLength * 1.0f)) + ";end fra = " + (Math.abs(mHorizontalOffset + distance) %
// onceCompleteScrollLength) / (onceCompleteScrollLength * 1.0f));

        long minDuration = autoSelectMinDuration;
        long maxDuration = autoSelectMaxDuration;
        long duration;
        float distanceFraction = (Math.abs(distance) / (onceCompleteScrollLength));
        if (distance <= onceCompleteScrollLength) {
            duration = (long) (minDuration + (maxDuration - minDuration) * distanceFraction);
        } else {
            duration = (long) (maxDuration * distanceFraction);
        }

        selectAnimator = ValueAnimator.ofFloat(0.0f, distance);
        selectAnimator.setDuration(duration);
        selectAnimator.setInterpolator(new LinearInterpolator());
        final float startedOffset =
                (focusOrientation == FOCUS_LEFT || focusOrientation == FOCUS_RIGHT) ?
                        mHorizontalOffset : mVerticalOffset;

        selectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                if (focusOrientation == FOCUS_LEFT || focusOrientation == FOCUS_RIGHT) {
                    if (mHorizontalOffset < 0) {
                        mHorizontalOffset =
                                (long) Math.floor(startedOffset + (float) animation.getAnimatedValue());
                    } else {
                        mHorizontalOffset =
                                (long) Math.ceil(startedOffset + (float) animation.getAnimatedValue());
                    }
                    requestLayout();
                } else if (focusOrientation == FOCUS_TOP || focusOrientation == FOCUS_BOTTOM) {
                    if (mVerticalOffset < 0) {
                        mVerticalOffset =
                                (long) Math.floor(startedOffset + (float) animation.getAnimatedValue());
                    } else {
                        mVerticalOffset =
                                (long) Math.ceil(startedOffset + (float) animation.getAnimatedValue());
                    }
                    requestLayout();
                }

            }
        });
        selectAnimator.start();

    }
 
Example 20
Source File: ChartDataAnimatorV14.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
public ChartDataAnimatorV14(Chart chart) {
    this.chart = chart;
    animator = ValueAnimator.ofFloat(0.0f, 1.0f);
    animator.addListener(this);
    animator.addUpdateListener(this);
}