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

The following examples show how to use android.animation.ObjectAnimator#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: NewTabPageRecyclerView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * To be triggered when a snippet is bound to a ViewHolder.
 */
public void onSnippetBound(View cardView) {
    // We only run if the feature is enabled and once per NTP.
    if (!SnippetsConfig.isIncreasedCardVisibilityEnabled() || mFirstCardAnimationRun) return;
    mFirstCardAnimationRun = true;

    // We only want an animation to run if we are not scrolled.
    if (computeVerticalScrollOffset() != 0) return;

    // We only show the animation a certain number of times to a user.
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance(getContext());
    int animCount = manager.getNewTabPageFirstCardAnimationRunCount();
    if (animCount > CardsVariationParameters.getFirstCardAnimationMaxRuns()) return;
    manager.setNewTabPageFirstCardAnimationRunCount(animCount + 1);

    // We do not show the animation if the user has previously seen it then scrolled.
    if (manager.getCardsImpressionAfterAnimation()) return;

    // The peeking card bounces up twice from its position.
    ObjectAnimator animator = ObjectAnimator.ofFloat(cardView, View.TRANSLATION_Y,
            0f, -mPeekingCardBounceDistance, 0f, -mPeekingCardBounceDistance, 0f);
    animator.setStartDelay(PEEKING_CARD_ANIMATION_START_DELAY_MS);
    animator.setDuration(PEEKING_CARD_ANIMATION_TIME_MS);
    animator.setInterpolator(PEEKING_CARD_INTERPOLATOR);
    animator.start();
}
 
Example 2
Source File: BottomSheetLayout.java    From ThreePhasesBottomSheet with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Set the presented sheet to be in a peeked state.
 */
public void peekSheet() {
    cancelCurrentAnimation();
    setSheetLayerTypeIfEnabled(LAYER_TYPE_HARDWARE);
    ObjectAnimator anim = ObjectAnimator.ofFloat(this, SHEET_TRANSLATION, getPeekSheetTranslation());
    anim.setDuration(ANIMATION_DURATION);
    anim.setInterpolator(animationInterpolator);
    anim.addListener(new CancelDetectionAnimationListener() {
        @Override
        public void onAnimationEnd(@NonNull Animator animation) {
            if (!canceled) {
                currentAnimator = null;
            }
        }
    });
    anim.start();
    currentAnimator = anim;
    setState(State.PEEKED);
}
 
Example 3
Source File: NormalUltimateViewAdapter.java    From UltimateRecyclerView with Apache License 2.0 6 votes vote down vote up
/**
 * Animations when loading the adapter
 *
 * @param view the view
 * @param type the type of the animation
 * @return the animator in array
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected Animator[] getAdapterAnimations(View view, AdapterAnimationType type) {
    if (type == AdapterAnimationType.ScaleIn) {
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", .5f, 1f);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", .5f, 1f);
        return new ObjectAnimator[]{scaleX, scaleY};
    } else if (type == AdapterAnimationType.AlphaIn) {
        return new Animator[]{ObjectAnimator.ofFloat(view, "alpha", .5f, 1f)};
    } else if (type == AdapterAnimationType.SlideInBottom) {
        return new Animator[]{
                ObjectAnimator.ofFloat(view, "translationY", view.getMeasuredHeight(), 0)
        };
    } else if (type == AdapterAnimationType.SlideInLeft) {
        return new Animator[]{
                ObjectAnimator.ofFloat(view, "translationX", -view.getRootView().getWidth(), 0)
        };
    } else if (type == AdapterAnimationType.SlideInRight) {
        return new Animator[]{
                ObjectAnimator.ofFloat(view, "translationX", view.getRootView().getWidth(), 0)
        };
    }
    return null;
}
 
Example 4
Source File: BottomNavigationBehavior.java    From Toutiao with Apache License 2.0 6 votes vote down vote up
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) {
    if (dy > 0) {// 上滑隐藏
        if (outAnimator == null) {
            outAnimator = ObjectAnimator.ofFloat(child, "translationY", 0, child.getHeight());
            outAnimator.setDuration(200);
        }
        if (!outAnimator.isRunning() && child.getTranslationY() <= 0) {
            outAnimator.start();
        }
    } else if (dy < 0) {// 下滑显示
        if (inAnimator == null) {
            inAnimator = ObjectAnimator.ofFloat(child, "translationY", child.getHeight(), 0);
            inAnimator.setDuration(200);
        }
        if (!inAnimator.isRunning() && child.getTranslationY() >= child.getHeight()) {
            inAnimator.start();
        }
    }
}
 
Example 5
Source File: SplashActivity.java    From ZhuanLan with Apache License 2.0 6 votes vote down vote up
private void animateImage() {
    ObjectAnimator animatorX = ObjectAnimator.ofFloat(mSplashImage, View.SCALE_X, 1f, SCALE_END);
    ObjectAnimator animatorY = ObjectAnimator.ofFloat(mSplashImage, View.SCALE_Y, 1f, SCALE_END);

    AnimatorSet set = new AnimatorSet();
    set.setDuration(ANIMATION_DURATION).play(animatorX).with(animatorY);
    set.start();

    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            MainActivity.start(SplashActivity.this);
            SplashActivity.this.finish();
        }
    });
}
 
Example 6
Source File: PostActivity.java    From materialup with Apache License 2.0 6 votes vote down vote up
private void expandImageAndFinish() {
    if (imageView.getOffset() != 0f) {
        Animator expandImage = ObjectAnimator.ofFloat(imageView, ParallaxScrimageView.OFFSET,
                0f);
        expandImage.setDuration(80);
        expandImage.setInterpolator(AnimationUtils.loadInterpolator(this, android.R
                .interpolator.fast_out_slow_in));
        expandImage.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                supportFinishAfterTransition();
            }
        });
        expandImage.start();
    } else {
        supportFinishAfterTransition();
    }
}
 
Example 7
Source File: ChangeTranslation.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to handle creating and running the Animator.
 */
private Animator createAnimation(View view, float[] startTranslation, float[] endTranslation,
                                 Animator.AnimatorListener listener, TimeInterpolator interpolator) {
    if (startTranslation == null || endTranslation == null ||
            startTranslation.length != endTranslation.length || equals(startTranslation, endTranslation)) {
        // run listener if we're noop'ing the animation, to get the end-state results now
        if (listener != null) {
            listener.onAnimationEnd(null);
        }
        return null;
    }

    final AnimatorSet anim = new AnimatorSet();
    ObjectAnimator animX = null, animY = null;

    if ((mTranslationDirection & X) != 0) {
        animX = ObjectAnimator.ofFloat(view, View.X,
                startTranslation[0], endTranslation[0]);
    }

    if ((mTranslationDirection & Y) != 0) {
        animY = ObjectAnimator.ofFloat(view, View.Y,
                startTranslation[1], endTranslation[1]);
    }

    if (null != animX && null == animY) anim.play(animX);
    if (null == animX && null != animY) anim.play(animY);
    if (null != animX && null != animY) anim.playTogether(animX, animY);
    if (null == animX && null == animY) return null;

    if (listener != null) {
        anim.addListener(listener);
    }

    anim.setInterpolator(interpolator);
    return anim;
}
 
Example 8
Source File: TransHistoryAdapter.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private void startCounterclockwiseRotation(ImageView ivLoader) {
    loaderAnimation = ObjectAnimator.ofFloat(ivLoader, "rotation", 360f, 0.0f);
    loaderAnimation.setDuration(1500);
    loaderAnimation.setRepeatCount(ObjectAnimator.INFINITE);
    loaderAnimation.setInterpolator(new LinearInterpolator());
    loaderAnimation.start();
}
 
Example 9
Source File: KeyButtonRipple.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private void enterSoftware() {
    cancelAnimations();
    mGlowAlpha = mGlowAlphaMax;
    ObjectAnimator scaleAnimator = ObjectAnimator.ofFloat(this, "glowScale",
            0f, GLOW_MAX_SCALE_FACTOR);
    scaleAnimator.setInterpolator(mInterpolator);
    scaleAnimator.setDuration(ANIMATION_DURATION_SCALE);
    scaleAnimator.addListener(mAnimatorListener);
    scaleAnimator.start();
    mRunningAnimations.add(scaleAnimator);
}
 
Example 10
Source File: LineProgressBar.java    From IndicatorBox with MIT License 5 votes vote down vote up
private void flashOut(int duration){
    AnimatorSet set = new AnimatorSet();
    ObjectAnimator colorAnimator = ObjectAnimator.ofObject(this, "backgroundColor",
            new ArgbEvaluator(), mCompletedColor, Color.parseColor("#ffffff"));
    colorAnimator.setDuration(duration);
    colorAnimator.setInterpolator(new AccelerateInterpolator());
    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(this, "scaleY", 1.0f, 0.0f);
    objectAnimator.setDuration(duration);
    objectAnimator.setInterpolator(new AccelerateInterpolator());
    set.play(colorAnimator).with(objectAnimator);
    if (!set.isStarted()){
        set.start();
    }
    isShowing = false;
}
 
Example 11
Source File: AnimationUtil.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
public static void animateAlpha2(final View target, final Animator.AnimatorListener listener) {
    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(target, "alpha", 0f, 1f);
    objectAnimator.setDuration(500);
    objectAnimator.start();
    if (listener != null) {
        objectAnimator.addListener(listener);
    }
}
 
Example 12
Source File: FloatActionButton.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
public void hideFloatingActionButton() {
    if (!mHidden) {
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(this, "scaleX", 1, 0);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(this, "scaleY", 1, 0);
        AnimatorSet animSetXY = new AnimatorSet();
        animSetXY.playTogether(scaleX, scaleY);
        animSetXY.setInterpolator(accelerateInterpolator);
        animSetXY.setDuration(100);
        animSetXY.start();
        mHidden = true;
    }
}
 
Example 13
Source File: TransHistoryAdapter.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private void startClockwiseRotation(ImageView ivLoader) {
    loaderAnimation = ObjectAnimator.ofFloat(ivLoader, "rotation", 0.0f, 360f);
    loaderAnimation.setDuration(1500);
    loaderAnimation.setRepeatCount(ObjectAnimator.INFINITE);
    loaderAnimation.setInterpolator(new LinearInterpolator());
    loaderAnimation.start();
}
 
Example 14
Source File: InitialCenterCircleView.java    From AnimatedCircleLoadingView with Apache License 2.0 5 votes vote down vote up
public void startTranslateBottomAnimation() {
  float translationYFrom = -(260 * parentWidth) / 700;
  float translationYTo = (360 * parentWidth) / 700;
  ObjectAnimator translationY =
      ObjectAnimator.ofFloat(this, "translationY", translationYFrom, translationYTo);
  translationY.setDuration(650);
  translationY.start();
}
 
Example 15
Source File: Slide.java    From android-animations with MIT License 5 votes vote down vote up
public static AnimatorSet OutLeft(View view) {
    AnimatorSet animatorSet = new AnimatorSet();
    float right = view.getRight();

    ObjectAnimator object1 = ObjectAnimator.ofFloat(view,"alpha", 1, 0);
    ObjectAnimator object2 = ObjectAnimator.ofFloat(view,"translationX", 0, - right);

    animatorSet.playTogether(object1, object2);
    return animatorSet;
}
 
Example 16
Source File: PropertyAnimActivity.java    From AndroidStudyDemo with GNU General Public License v2.0 4 votes vote down vote up
public void testScale(View v) {
    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mTestScaleBtn,"scaleX", 0f,1.0f);
    showPropertyAnim01(objectAnimator, v.getId());
}
 
Example 17
Source File: ScaleInAnimationAdapter.java    From recyclerview-animators with Apache License 2.0 4 votes vote down vote up
@Override protected Animator[] getAnimators(View view) {
  ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", mFrom, 1f);
  ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", mFrom, 1f);
  return new ObjectAnimator[] { scaleX, scaleY };
}
 
Example 18
Source File: AnimationSVGImageViewSampleActivity.java    From SVG-Android with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_animation_svg_imageview_sample);
    setTitle(getIntent().getStringExtra("title"));

    final SVGImageView imageView1 = (SVGImageView) findViewById(R.id.animation_svgimageview_image1);
    ObjectAnimator animatorRotation = ObjectAnimator.ofFloat(imageView1, "svgRotation", 0, 360);
    animatorRotation.setDuration(2000);
    animatorRotation.setRepeatCount(ValueAnimator.INFINITE);
    animatorRotation.setInterpolator(new LinearInterpolator());
    animatorRotation.start();

    SVGImageView imageView2 = (SVGImageView) findViewById(R.id.animation_svgimageview_image2);
    ObjectAnimator animatorAlpha = ObjectAnimator.ofFloat(imageView2, "svgAlpha", 0, 1);
    animatorAlpha.setDuration(4000);
    animatorAlpha.setRepeatCount(ValueAnimator.INFINITE);
    animatorAlpha.setRepeatMode(ValueAnimator.REVERSE);
    animatorAlpha.setInterpolator(new LinearInterpolator());
    animatorAlpha.start();

    final SVGImageView imageView3 = (SVGImageView) findViewById(R.id.animation_svgimageview_image3);
    ObjectAnimator animatorWidth = ObjectAnimator.ofInt(imageView3, "svgWidth", 50, 150);
    animatorWidth.setDuration(2000);
    animatorWidth.setInterpolator(new LinearInterpolator());
    animatorWidth.setRepeatCount(ValueAnimator.INFINITE);
    animatorWidth.setRepeatMode(ValueAnimator.REVERSE);
    animatorWidth.start();
    animatorWidth.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            // There is a bug in ImageView(ImageButton), in this case, we must call requestLayout() here.
            imageView3.requestLayout();
        }
    });

    SVGImageView imageView4 = (SVGImageView) findViewById(R.id.animation_svgimageview_image4);
    ObjectAnimator animatorColor = ObjectAnimator.ofInt(imageView4, "svgColor", Color.BLACK, Color.BLUE);
    animatorColor.setDuration(2000);
    animatorColor.setRepeatCount(ValueAnimator.INFINITE);
    animatorColor.setRepeatMode(ValueAnimator.REVERSE);
    animatorColor.setInterpolator(new LinearInterpolator());
    animatorColor.start();

}
 
Example 19
Source File: AnimatorActivity.java    From AndroidDemo with Apache License 2.0 4 votes vote down vote up
public void startObject(View view) {
	ObjectAnimator animator = ObjectAnimator.ofFloat(btn_two, "textSize", 0f, 50f);
	animator.setDuration(2000);
	animator.start();
}
 
Example 20
Source File: SlideInBottomAnimation.java    From AndroidBase with Apache License 2.0 4 votes vote down vote up
@Override
public Animator[] getAnimators(View view) {
    return new Animator[]{
            ObjectAnimator.ofFloat(view, "translationY", view.getMeasuredHeight(), 0)
    };
}