Search in sources :

Example 76 with ArgbEvaluator

use of android.animation.ArgbEvaluator in project ViewAnimator by florent37.

the class AnimationBuilder method backgroundColor.

public AnimationBuilder backgroundColor(int... colors) {
    for (View view : views) {
        ObjectAnimator objectAnimator = ObjectAnimator.ofInt(view, "backgroundColor", colors);
        objectAnimator.setEvaluator(new ArgbEvaluator());
        this.animatorList.add(objectAnimator);
    }
    return this;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) ArgbEvaluator(android.animation.ArgbEvaluator) TextView(android.widget.TextView) View(android.view.View)

Example 77 with ArgbEvaluator

use of android.animation.ArgbEvaluator in project LeafPic by HoraApps.

the class SingleMediaActivity method changeBackGroundColor.

private void changeBackGroundColor() {
    int colorTo;
    int colorFrom;
    if (fullScreenMode) {
        colorFrom = getBackgroundColor();
        colorTo = (ContextCompat.getColor(SingleMediaActivity.this, R.color.md_black_1000));
    } else {
        colorFrom = (ContextCompat.getColor(SingleMediaActivity.this, R.color.md_black_1000));
        colorTo = getBackgroundColor();
    }
    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
    colorAnimation.setDuration(240);
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            ActivityBackground.setBackgroundColor((Integer) animator.getAnimatedValue());
        }
    });
    colorAnimation.start();
}
Also used : ArgbEvaluator(android.animation.ArgbEvaluator) ValueAnimator(android.animation.ValueAnimator)

Example 78 with ArgbEvaluator

use of android.animation.ArgbEvaluator in project apps-android-wikipedia by wikimedia.

the class OnThisDayFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_on_this_day, container, false);
    AnimationUtil.setSharedElementTransitions(requireActivity());
    unbinder = ButterKnife.bind(this, view);
    int age = requireActivity().getIntent().getIntExtra(AGE, 0);
    wiki = requireActivity().getIntent().getParcelableExtra(WIKISITE);
    date = DateUtil.getDefaultDateFor(age);
    setUpToolbar();
    eventsRecycler.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
    final int topDecorationDp = 24;
    eventsRecycler.addItemDecoration(new HeaderMarginItemDecoration(topDecorationDp, 0));
    setUpRecycler(eventsRecycler);
    errorView.setBackClickListener(v -> requireActivity().finish());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && requireActivity().getWindow().getSharedElementEnterTransition() != null && savedInstanceState == null) {
        final int animDelay = 500;
        dayText.postDelayed(() -> {
            if (!isAdded() || dayText == null) {
                return;
            }
            updateContents(age);
            ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), dayText.getCurrentTextColor(), ResourceUtil.getThemedColor(requireContext(), R.attr.main_toolbar_title_color));
            colorAnimation.addUpdateListener(animator -> {
                if (dayText != null) {
                    dayText.setTextColor((Integer) animator.getAnimatedValue());
                }
            });
            colorAnimation.start();
        }, animDelay);
    } else {
        dayText.setTextColor(ResourceUtil.getThemedColor(requireContext(), R.attr.main_toolbar_title_color));
        updateContents(age);
    }
    eventsRecycler.setVisibility(View.GONE);
    errorView.setVisibility(View.GONE);
    return view;
}
Also used : HeaderMarginItemDecoration(org.wikipedia.views.HeaderMarginItemDecoration) ArgbEvaluator(android.animation.ArgbEvaluator) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ValueAnimator(android.animation.ValueAnimator) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) WikiErrorView(org.wikipedia.views.WikiErrorView)

Example 79 with ArgbEvaluator

use of android.animation.ArgbEvaluator in project easy by MehdiBenmesa.

the class MaterialViewPagerAnimator method setColor.

/**
 * Change the color of the statusbackground, toolbar, toolbarlayout and pagertitlestrip
 * With a color transition animation
 *
 * @param color    the final color
 * @param duration the transition color animation duration
 */
void setColor(int color, int duration) {
    final ValueAnimator colorAnim = ObjectAnimator.ofInt(mHeader.headerBackground, "backgroundColor", settings.color, color);
    colorAnim.setEvaluator(new ArgbEvaluator());
    colorAnim.setDuration(duration);
    colorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            final int animatedValue = (Integer) animation.getAnimatedValue();
            int colorAlpha = colorWithAlpha(animatedValue, lastPercent);
            mHeader.headerBackground.setBackgroundColor(colorAlpha);
            mHeader.statusBackground.setBackgroundColor(colorAlpha);
            mHeader.toolbar.setBackgroundColor(colorAlpha);
            mHeader.toolbarLayoutBackground.setBackgroundColor(colorAlpha);
            mHeader.mPagerSlidingTabStrip.setBackgroundColor(colorAlpha);
            // set the new color as MaterialViewPager's color
            settings.color = animatedValue;
        }
    });
    colorAnim.start();
}
Also used : ArgbEvaluator(android.animation.ArgbEvaluator) ValueAnimator(android.animation.ValueAnimator)

Example 80 with ArgbEvaluator

use of android.animation.ArgbEvaluator in project atlas by alibaba.

the class TextResize method createAnimator.

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }
    final TextResizeData startData = (TextResizeData) startValues.values.get(DATA);
    final TextResizeData endData = (TextResizeData) endValues.values.get(DATA);
    if (startData.gravity != endData.gravity) {
        // Can't deal with changes in gravity
        return null;
    }
    final TextView textView = (TextView) endValues.view;
    float startFontSize = (Float) startValues.values.get(FONT_SIZE);
    // Capture the start bitmap -- we need to set the values to the start values first
    setTextViewData(textView, startData, startFontSize);
    final float startWidth = textView.getPaint().measureText(textView.getText().toString());
    final Bitmap startBitmap = captureTextBitmap(textView);
    if (startBitmap == null) {
        startFontSize = 0;
    }
    float endFontSize = (Float) endValues.values.get(FONT_SIZE);
    // Set the values to the end values
    setTextViewData(textView, endData, endFontSize);
    final float endWidth = textView.getPaint().measureText(textView.getText().toString());
    // Capture the end bitmap
    final Bitmap endBitmap = captureTextBitmap(textView);
    if (endBitmap == null) {
        endFontSize = 0;
    }
    if (startFontSize == 0 && endFontSize == 0) {
        // Can't animate null bitmaps
        return null;
    }
    // Set the colors of the TextView so that nothing is drawn.
    // Only draw the bitmaps in the overlay.
    final ColorStateList textColors = textView.getTextColors();
    final ColorStateList hintColors = textView.getHintTextColors();
    final int highlightColor = textView.getHighlightColor();
    final ColorStateList linkColors = textView.getLinkTextColors();
    textView.setTextColor(Color.TRANSPARENT);
    textView.setHintTextColor(Color.TRANSPARENT);
    textView.setHighlightColor(Color.TRANSPARENT);
    textView.setLinkTextColor(Color.TRANSPARENT);
    // Create the drawable that will be animated in the TextView's overlay.
    // Ensure that it is showing the start state now.
    final SwitchBitmapDrawable drawable = new SwitchBitmapDrawable(textView, startData.gravity, startBitmap, startFontSize, startWidth, endBitmap, endFontSize, endWidth);
    textView.getOverlay().add(drawable);
    // Properties: left, top, font size, text color
    final PropertyValuesHolder leftProp = PropertyValuesHolder.ofFloat("left", startData.paddingLeft, endData.paddingLeft);
    final PropertyValuesHolder topProp = PropertyValuesHolder.ofFloat("top", startData.paddingTop, endData.paddingTop);
    final PropertyValuesHolder rightProp = PropertyValuesHolder.ofFloat("right", startData.width - startData.paddingRight, endData.width - endData.paddingRight);
    final PropertyValuesHolder bottomProp = PropertyValuesHolder.ofFloat("bottom", startData.height - startData.paddingBottom, endData.height - endData.paddingBottom);
    final PropertyValuesHolder fontSizeProp = PropertyValuesHolder.ofFloat("fontSize", startFontSize, endFontSize);
    final ObjectAnimator animator;
    if (startData.textColor != endData.textColor) {
        final PropertyValuesHolder textColorProp = PropertyValuesHolder.ofObject("textColor", new ArgbEvaluator(), startData.textColor, endData.textColor);
        animator = ObjectAnimator.ofPropertyValuesHolder(drawable, leftProp, topProp, rightProp, bottomProp, fontSizeProp, textColorProp);
    } else {
        animator = ObjectAnimator.ofPropertyValuesHolder(drawable, leftProp, topProp, rightProp, bottomProp, fontSizeProp);
    }
    final float finalFontSize = endFontSize;
    AnimatorListenerAdapter listener = new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            textView.getOverlay().remove(drawable);
            textView.setTextColor(textColors);
            textView.setHintTextColor(hintColors);
            textView.setHighlightColor(highlightColor);
            textView.setLinkTextColor(linkColors);
        }

        @Override
        public void onAnimationPause(Animator animation) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, drawable.getFontSize());
            final int paddingLeft = Math.round(drawable.getLeft());
            final int paddingTop = Math.round(drawable.getTop());
            final float fraction = animator.getAnimatedFraction();
            final int paddingRight = Math.round(interpolate(startData.paddingRight, endData.paddingRight, fraction));
            final int paddingBottom = Math.round(interpolate(startData.paddingBottom, endData.paddingBottom, fraction));
            textView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
            textView.setTextColor(drawable.getTextColor());
        }

        @Override
        public void onAnimationResume(Animator animation) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, finalFontSize);
            textView.setPadding(endData.paddingLeft, endData.paddingTop, endData.paddingRight, endData.paddingBottom);
            textView.setTextColor(endData.textColor);
        }
    };
    animator.addListener(listener);
    animator.addPauseListener(listener);
    return animator;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) ArgbEvaluator(android.animation.ArgbEvaluator) ColorStateList(android.content.res.ColorStateList) Paint(android.graphics.Paint) Bitmap(android.graphics.Bitmap) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder) TextView(android.widget.TextView)

Aggregations

ArgbEvaluator (android.animation.ArgbEvaluator)107 ValueAnimator (android.animation.ValueAnimator)68 ObjectAnimator (android.animation.ObjectAnimator)29 Animator (android.animation.Animator)23 View (android.view.View)15 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)13 TextView (android.widget.TextView)9 ColorDrawable (android.graphics.drawable.ColorDrawable)8 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)7 AnimatorSet (android.animation.AnimatorSet)6 PropertyValuesHolder (android.animation.PropertyValuesHolder)6 Paint (android.graphics.Paint)6 AnimatorListener (android.animation.Animator.AnimatorListener)5 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)5 TargetApi (android.annotation.TargetApi)4 Handler (android.os.Handler)4 ViewGroup (android.view.ViewGroup)4 SuppressLint (android.annotation.SuppressLint)3 ColorFilter (android.graphics.ColorFilter)3 LightingColorFilter (android.graphics.LightingColorFilter)3