Example usage for android.animation ObjectAnimator ofFloat

List of usage examples for android.animation ObjectAnimator ofFloat

Introduction

In this page you can find the example usage for android.animation ObjectAnimator ofFloat.

Prototype

public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> property, float... values) 

Source Link

Document

Constructs and returns an ObjectAnimator that animates between float values.

Usage

From source file:io.jawg.osmcontributor.ui.adapters.OfflineRegionsAdapter.java

@Override
public void onBindViewHolder(final OfflineRegionHolder holder, final int position) {
    OfflineRegionItem region = offlineRegions.get(position);

    String regionName = OfflineRegionManager.decodeRegionName(region.getOfflineRegion().getMetadata());
    holder.offlineRegionTextView.setText(regionName);

    if (region.isSelected()) {
        Animator animX = ObjectAnimator.ofFloat(holder.cardView, View.SCALE_X, 1.15f);
        Animator animY = ObjectAnimator.ofFloat(holder.cardView, View.SCALE_Y, 1.15f);
        AnimatorSet animSet = new AnimatorSet();
        animSet.playTogether(animX, animY);
        animSet.start();/*from   w ww. j  a  va2s.  com*/
    } else {
        Animator animX = ObjectAnimator.ofFloat(holder.cardView, View.SCALE_X, 1.0f);
        Animator animY = ObjectAnimator.ofFloat(holder.cardView, View.SCALE_Y, 1.0f);
        AnimatorSet animSet = new AnimatorSet();
        animSet.playTogether(animX, animY);
        animSet.start();
    }

    if (region.getStatus().isComplete()) {
        holder.cardView.setBackgroundColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
        holder.offlineRegionTextView.setTextColor(Color.WHITE);
    } else {
        holder.cardView.setBackgroundColor(ContextCompat.getColor(context, R.color.active_text));
        holder.offlineRegionTextView.setTextColor(ContextCompat.getColor(context, R.color.disable_text));
    }
}

From source file:com.google.android.apps.muzei.util.AnimatedMuzeiLogoFragment.java

@Override
public void onViewCreated(final View view, @Nullable final Bundle savedInstanceState) {
    mSubtitleView = view.findViewById(R.id.logo_subtitle);

    mLogoView = (AnimatedMuzeiLogoView) view.findViewById(R.id.animated_logo);
    mLogoView.setOnStateChangeListener(new AnimatedMuzeiLogoView.OnStateChangeListener() {
        @Override//from  w w  w.ja  v  a2 s  . co m
        public void onStateChange(int state) {
            if (state == AnimatedMuzeiLogoView.STATE_FILL_STARTED) {
                mSubtitleView.setAlpha(0);
                mSubtitleView.setVisibility(View.VISIBLE);
                mSubtitleView.setTranslationY(-mSubtitleView.getHeight());

                // Bug in older versions where set.setInterpolator didn't work
                AnimatorSet set = new AnimatorSet();
                Interpolator interpolator = new OvershootInterpolator();
                ObjectAnimator a1 = ObjectAnimator.ofFloat(mLogoView, View.TRANSLATION_Y, 0);
                ObjectAnimator a2 = ObjectAnimator.ofFloat(mSubtitleView, View.TRANSLATION_Y, 0);
                ObjectAnimator a3 = ObjectAnimator.ofFloat(mSubtitleView, View.ALPHA, 1);
                a1.setInterpolator(interpolator);
                a2.setInterpolator(interpolator);
                set.setDuration(500).playTogether(a1, a2, a3);
                set.start();

                if (mOnFillStartedCallback != null) {
                    mOnFillStartedCallback.run();
                }
            }
        }
    });
    if (savedInstanceState == null) {
        reset();
    }
}

From source file:com.chromium.fontinstaller.util.ViewUtils.java

public static void reveal(Activity activity, View view, View sourceView, int colorRes) {
    if (activity == null || view == null || sourceView == null)
        return;//from  w ww . ja  va  2s . com
    if (isLollipop()) {
        final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) activity.getWindow().getDecorView()
                .getOverlay();

        final Rect displayRect = new Rect();
        view.getGlobalVisibleRect(displayRect);

        // Make reveal cover the display and status bar.
        final View revealView = new View(activity);
        revealView.setTop(displayRect.top);
        revealView.setBottom(displayRect.bottom);
        revealView.setLeft(displayRect.left);
        revealView.setRight(displayRect.right);
        revealView.setBackgroundColor(ContextCompat.getColor(activity, colorRes));
        groupOverlay.add(revealView);

        final int[] clearLocation = new int[2];
        sourceView.getLocationInWindow(clearLocation);
        clearLocation[0] += sourceView.getWidth() / 2;
        clearLocation[1] += sourceView.getHeight() / 2;

        final int revealCenterX = clearLocation[0] - revealView.getLeft();
        final int revealCenterY = clearLocation[1] - revealView.getTop();

        final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
        final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
        final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
        final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

        try {
            final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
                    revealCenterY, 0.0f, revealRadius);
            revealAnimator
                    .setDuration(activity.getResources().getInteger(android.R.integer.config_mediumAnimTime));

            final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
            alphaAnimator
                    .setDuration(activity.getResources().getInteger(android.R.integer.config_shortAnimTime));
            alphaAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.abc_fade_in));
                    view.setVisibility(View.VISIBLE);
                }
            });

            final AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.play(revealAnimator).before(alphaAnimator);
            animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
            animatorSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animator) {
                    groupOverlay.remove(revealView);
                }
            });

            animatorSet.start();
        } catch (IllegalStateException e) {
            Timber.i("View is detached - not animating");
        }
    } else {
        view.setVisibility(View.VISIBLE);
    }
}

From source file:com.android.clear.reminder.ItemAnimator.java

@Override
public boolean animateAdd(final ViewHolder holder) {
    endAnimation(holder);/*from w ww.j  a v  a2  s.com*/

    final float prevAlpha = holder.itemView.getAlpha();
    holder.itemView.setAlpha(0f);

    final Animator addAnimator = ObjectAnimator.ofFloat(holder.itemView, View.ALPHA, 1f)
            .setDuration(getAddDuration());
    addAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animator) {
            dispatchAddStarting(holder);
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            animator.removeAllListeners();
            mAnimators.remove(holder);
            holder.itemView.setAlpha(prevAlpha);
            dispatchAddFinished(holder);
        }
    });
    mAddAnimatorsList.add(addAnimator);
    mAnimators.put(holder, addAnimator);
    return true;
}

From source file:com.sysdata.widget.accordion.ExpandedViewHolder.java

@Override
public Animator onAnimateChange(List<Object> payloads, int fromLeft, int fromTop, int fromRight, int fromBottom,
        long duration) {
    if (payloads == null || payloads.isEmpty()) {
        return null;
    }//from   www. j a v  a 2  s  .c  o  m

    final AnimatorSet animatorSet = new AnimatorSet();
    if (arrow != null) {
        animatorSet.playTogether(
                AnimatorUtils.getBoundsAnimator(itemView, fromLeft, fromTop, fromRight, fromBottom,
                        itemView.getLeft(), itemView.getTop(), itemView.getRight(), itemView.getBottom()),
                ObjectAnimator.ofFloat(arrow, TRANSLATION_Y, 0f));
    } else {
        animatorSet.playTogether(AnimatorUtils.getBoundsAnimator(itemView, fromLeft, fromTop, fromRight,
                fromBottom, itemView.getLeft(), itemView.getTop(), itemView.getRight(), itemView.getBottom()));
    }
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            setTranslationY(0f);
            itemView.requestLayout();
        }
    });
    animatorSet.setDuration(duration);
    animatorSet.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    return animatorSet;
}

From source file:android.support.designox.widget.FloatingActionButtonLollipop.java

@Override
void onTranslationZChanged(float translationZ) {
    StateListAnimator stateListAnimator = new StateListAnimator();
    // Animate translationZ to our value when pressed or focused
    stateListAnimator.addState(PRESSED_ENABLED_STATE_SET,
            setupAnimator(ObjectAnimator.ofFloat(mView, "translationZ", translationZ)));
    stateListAnimator.addState(FOCUSED_ENABLED_STATE_SET,
            setupAnimator(ObjectAnimator.ofFloat(mView, "translationZ", translationZ)));
    // Animate translationZ to 0 otherwise
    stateListAnimator.addState(EMPTY_STATE_SET,
            setupAnimator(ObjectAnimator.ofFloat(mView, "translationZ", 0f)));
    mView.setStateListAnimator(stateListAnimator);

    if (mShadowViewDelegate.isCompatPaddingEnabled()) {
        updatePadding();/*from ww  w .j  av a  2  s  . com*/
    }
}

From source file:cn.edu.zucc.list.FabAnimation.MorphDialogToFab.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues,
        TransitionValues endValues) {//w  w w  .  j ava 2s . c o m
    Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues);
    if (startValues == null || endValues == null || changeBounds == null) {
        return null;
    }

    Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR);
    Integer startCornerRadius = (Integer) startValues.values.get(PROPERTY_CORNER_RADIUS);
    Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR);
    Integer endCornerRadius = (Integer) endValues.values.get(PROPERTY_CORNER_RADIUS);

    if (startColor == null || startCornerRadius == null || endColor == null || endCornerRadius == null) {
        return null;
    }

    MorphDrawable background = new MorphDrawable(startColor, startCornerRadius);
    endValues.view.setBackground(background);

    Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor);
    Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius);

    // hide child views (offset down & fade out)
    if (endValues.view instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) endValues.view;
        for (int i = 0; i < vg.getChildCount(); i++) {
            View v = vg.getChildAt(i);
            v.animate().alpha(0f).translationY(v.getHeight() / 3).setStartDelay(0L).setDuration(50L)
                    .setInterpolator(AnimationUtils.loadInterpolator(vg.getContext(),
                            android.R.interpolator.fast_out_linear_in))
                    .start();
        }
    }

    AnimatorSet transition = new AnimatorSet();
    transition.playTogether(changeBounds, corners, color);
    transition.setInterpolator(
            AnimationUtils.loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in));
    transition.setDuration(300);
    return transition;
}

From source file:com.google.android.apps.muzei.TutorialFragment.java

@Override
public void onViewCreated(final View view, @Nullable final Bundle savedInstanceState) {
    view.findViewById(R.id.tutorial_icon_affordance).setOnClickListener(new View.OnClickListener() {
        @Override//from  www  .j a v  a  2  s  .  co  m
        public void onClick(View view) {
            FirebaseAnalytics.getInstance(getContext()).logEvent(FirebaseAnalytics.Event.TUTORIAL_COMPLETE,
                    null);
            final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
            sp.edit().putBoolean(PREF_SEEN_TUTORIAL, true).apply();
        }
    });

    if (savedInstanceState == null) {
        float animateDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100,
                getResources().getDisplayMetrics());
        View mainTextView = view.findViewById(R.id.tutorial_main_text);
        mainTextView.setAlpha(0);
        mainTextView.setTranslationY(-animateDistance / 5);
        View subTextView = view.findViewById(R.id.tutorial_sub_text);
        subTextView.setAlpha(0);
        subTextView.setTranslationY(-animateDistance / 5);
        final View affordanceView = view.findViewById(R.id.tutorial_icon_affordance);
        affordanceView.setAlpha(0);
        affordanceView.setTranslationY(animateDistance);
        View iconTextView = view.findViewById(R.id.tutorial_icon_text);
        iconTextView.setAlpha(0);
        iconTextView.setTranslationY(animateDistance);
        mAnimator = new AnimatorSet();
        mAnimator.setStartDelay(500);
        mAnimator.setDuration(250);
        mAnimator.playTogether(ObjectAnimator.ofFloat(mainTextView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(subTextView, View.ALPHA, 1f));
        mAnimator.start();
        mAnimator = new AnimatorSet();
        mAnimator.setStartDelay(2000);
        // Bug in older versions where set.setInterpolator didn't work
        Interpolator interpolator = new OvershootInterpolator();
        ObjectAnimator a1 = ObjectAnimator.ofFloat(affordanceView, View.TRANSLATION_Y, 0);
        ObjectAnimator a2 = ObjectAnimator.ofFloat(iconTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a3 = ObjectAnimator.ofFloat(mainTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a4 = ObjectAnimator.ofFloat(subTextView, View.TRANSLATION_Y, 0);
        a1.setInterpolator(interpolator);
        a2.setInterpolator(interpolator);
        a3.setInterpolator(interpolator);
        a4.setInterpolator(interpolator);
        mAnimator.setDuration(500).playTogether(ObjectAnimator.ofFloat(affordanceView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(iconTextView, View.ALPHA, 1f), a1, a2, a3, a4);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (isAdded()) {
                        ImageView emanateView = (ImageView) view.findViewById(R.id.tutorial_icon_emanate);
                        AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getResources()
                                .getDrawable(R.drawable.avd_tutorial_icon_emanate, getContext().getTheme());
                        emanateView.setImageDrawable(avd);
                        avd.start();
                    }
                }
            });
        }
        mAnimator.start();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ImageView emanateView = (ImageView) view.findViewById(R.id.tutorial_icon_emanate);
        AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getResources()
                .getDrawable(R.drawable.avd_tutorial_icon_emanate, getContext().getTheme());
        emanateView.setImageDrawable(avd);
        avd.start();
    }
}

From source file:cn.edu.zucc.list.FabAnimation.MorphFabToDialog.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues,
        final TransitionValues endValues) {
    Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues);
    if (startValues == null || endValues == null || changeBounds == null) {
        return null;
    }/*from w  ww .  j  a v a 2 s  .c o  m*/

    Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR);
    Integer startCornerRadius = (Integer) startValues.values.get(PROPERTY_CORNER_RADIUS);
    Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR);
    Integer endCornerRadius = (Integer) endValues.values.get(PROPERTY_CORNER_RADIUS);

    if (startColor == null || startCornerRadius == null || endColor == null || endCornerRadius == null) {
        return null;
    }

    MorphDrawable background = new MorphDrawable(startColor, startCornerRadius);
    endValues.view.setBackground(background);

    Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor);
    Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius);

    // ease in the dialog's child views (slide up & fade in)
    if (endValues.view instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) endValues.view;
        float offset = vg.getHeight() / 3;
        for (int i = 0; i < vg.getChildCount(); i++) {
            View v = vg.getChildAt(i);
            v.setTranslationY(offset);
            v.setAlpha(0f);
            v.animate().alpha(1f).translationY(0f).setDuration(150).setStartDelay(150).setInterpolator(
                    AnimationUtils.loadInterpolator(vg.getContext(), android.R.interpolator.fast_out_slow_in))
                    .start();
            offset *= 1.8f;
        }
    }

    AnimatorSet transition = new AnimatorSet();
    transition.playTogether(changeBounds, corners, color);
    transition.setDuration(300);
    transition.setInterpolator(
            AnimationUtils.loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in));
    return transition;
}

From source file:com.commonsware.cwac.crossport.design.widget.FloatingActionButtonLollipop.java

@Override
void onElevationsChanged(final float elevation, final float pressedTranslationZ) {
    if (Build.VERSION.SDK_INT == 21) {
        // Animations produce NPE in version 21. Bluntly set the values instead (matching the
        // logic in the animations below).
        if (mView.isEnabled()) {
            mView.setElevation(elevation);
            if (mView.isFocused() || mView.isPressed()) {
                mView.setTranslationZ(pressedTranslationZ);
            } else {
                mView.setTranslationZ(0);
            }//  ww  w  . j a  v a 2 s.  c  o  m
        } else {
            mView.setElevation(0);
            mView.setTranslationZ(0);
        }
    } else {
        final StateListAnimator stateListAnimator = new StateListAnimator();

        // Animate elevation and translationZ to our values when pressed
        AnimatorSet set = new AnimatorSet();
        set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator
                .ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION));
        set.setInterpolator(ANIM_INTERPOLATOR);
        stateListAnimator.addState(PRESSED_ENABLED_STATE_SET, set);

        // Same deal for when we're focused
        set = new AnimatorSet();
        set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator
                .ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION));
        set.setInterpolator(ANIM_INTERPOLATOR);
        stateListAnimator.addState(FOCUSED_ENABLED_STATE_SET, set);

        // Animate translationZ to 0 if not pressed
        set = new AnimatorSet();
        List<Animator> animators = new ArrayList<>();
        animators.add(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0));
        if (Build.VERSION.SDK_INT >= 22 && Build.VERSION.SDK_INT <= 24) {
            // This is a no-op animation which exists here only for introducing the duration
            // because setting the delay (on the next animation) via "setDelay" or "after"
            // can trigger a NPE between android versions 22 and 24 (due to a framework
            // bug). The issue has been fixed in version 25.
            animators.add(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, mView.getTranslationZ())
                    .setDuration(PRESSED_ANIM_DELAY));
        }
        animators.add(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(PRESSED_ANIM_DURATION));
        set.playSequentially(animators.toArray(new ObjectAnimator[0]));
        set.setInterpolator(ANIM_INTERPOLATOR);
        stateListAnimator.addState(ENABLED_STATE_SET, set);

        // Animate everything to 0 when disabled
        set = new AnimatorSet();
        set.play(ObjectAnimator.ofFloat(mView, "elevation", 0f).setDuration(0))
                .with(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(0));
        set.setInterpolator(ANIM_INTERPOLATOR);
        stateListAnimator.addState(EMPTY_STATE_SET, set);

        mView.setStateListAnimator(stateListAnimator);
    }

    if (mShadowViewDelegate.isCompatPaddingEnabled()) {
        updatePadding();
    }
}