Search in sources :

Example 81 with ArgbEvaluator

use of android.animation.ArgbEvaluator in project native-navigation by airbnb.

the class DefaultNavigationImplementation method reconcileStatusBarStyleOnLollipop.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void reconcileStatusBarStyleOnLollipop(final Activity activity, ReadableMap prev, ReadableMap next, boolean firstCall) {
    if (firstCall || numberHasChanged("statusBarColor", prev, next)) {
        boolean animated = false;
        if (next.hasKey("statusBarAnimation")) {
            animated = !("none".equals(next.getString("statusBarAnimation")));
        }
        Integer color = defaults.statusBarColor;
        if (next.hasKey("statusBarColor")) {
            color = next.getInt("statusBarColor");
        }
        if (animated) {
            int curColor = activity.getWindow().getStatusBarColor();
            ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), curColor, color);
            colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(ValueAnimator animator) {
                    activity.getWindow().setStatusBarColor((Integer) animator.getAnimatedValue());
                }
            });
            colorAnimation.setDuration(300).setStartDelay(0);
            colorAnimation.start();
        } else {
            activity.getWindow().setStatusBarColor(color);
        }
    }
    if (firstCall || boolHasChanged("statusBarTranslucent", prev, next)) {
        boolean translucent = defaults.statusBarTranslucent;
        if (next.hasKey("statusBarTranslucent")) {
            translucent = next.getBoolean("statusBarTranslucent");
        }
        View decorView = activity.getWindow().getDecorView();
        // and consume all the top insets so no padding will be added under the status bar.
        if (translucent) {
            decorView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

                @Override
                public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                    WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
                    return defaultInsets.replaceSystemWindowInsets(defaultInsets.getSystemWindowInsetLeft(), 0, defaultInsets.getSystemWindowInsetRight(), defaultInsets.getSystemWindowInsetBottom());
                }
            });
        } else {
            decorView.setOnApplyWindowInsetsListener(null);
        }
        ViewCompat.requestApplyInsets(decorView);
    }
}
Also used : ArgbEvaluator(android.animation.ArgbEvaluator) ValueAnimator(android.animation.ValueAnimator) BottomNavigationItemView(android.support.design.internal.BottomNavigationItemView) BottomNavigationView(android.support.design.widget.BottomNavigationView) BottomNavigationMenuView(android.support.design.internal.BottomNavigationMenuView) TargetApi(android.annotation.TargetApi)

Example 82 with ArgbEvaluator

use of android.animation.ArgbEvaluator in project Qblog_Android by qiaoyhh.

the class BottomNavigationUtils method changeTextColor.

static void changeTextColor(final TextView textView, int fromColor, int toColor) {
    ValueAnimator changeTextColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor);
    changeTextColorAnimation.setDuration(150);
    changeTextColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            textView.setTextColor((Integer) animator.getAnimatedValue());
        }
    });
    changeTextColorAnimation.start();
}
Also used : ArgbEvaluator(android.animation.ArgbEvaluator) ValueAnimator(android.animation.ValueAnimator)

Example 83 with ArgbEvaluator

use of android.animation.ArgbEvaluator in project collect by opendatakit.

the class ODKView method highlightWidget.

/**
 * Highlights the question at the given {@link FormIndex} in red for 2.5 seconds, scrolls the
 * view to display that question at the top and gives it focus.
 */
public void highlightWidget(FormIndex formIndex) {
    QuestionWidget qw = getQuestionWidget(formIndex);
    if (qw != null) {
        // postDelayed is needed because otherwise scrolling may not work as expected in case when
        // answers are validated during form finalization.
        new Handler().postDelayed(() -> {
            qw.setFocus(getContext());
            scrollTo(qw);
            ValueAnimator va = new ValueAnimator();
            va.setIntValues(new ThemeUtils(getContext()).getColorError(), getDrawingCacheBackgroundColor());
            va.setEvaluator(new ArgbEvaluator());
            va.addUpdateListener(valueAnimator -> qw.setBackgroundColor((int) valueAnimator.getAnimatedValue()));
            va.setDuration(2500);
            va.start();
        }, 100);
    }
}
Also used : ArgbEvaluator(android.animation.ArgbEvaluator) Handler(android.os.Handler) ThemeUtils(org.odk.collect.android.utilities.ThemeUtils) QuestionWidget(org.odk.collect.android.widgets.QuestionWidget) ValueAnimator(android.animation.ValueAnimator)

Example 84 with ArgbEvaluator

use of android.animation.ArgbEvaluator in project incubator-weex by apache.

the class AnimationAction method createAnimator.

@Nullable
private ObjectAnimator createAnimator(final View target, final int viewPortWidth) {
    if (target == null) {
        return null;
    }
    WXAnimationBean.Style style = mAnimationBean.styles;
    if (style != null) {
        ObjectAnimator animator;
        List<PropertyValuesHolder> holders = style.getHolders();
        if (!TextUtils.isEmpty(style.backgroundColor)) {
            BorderDrawable borderDrawable;
            if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) {
                holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(), borderDrawable.getColor(), WXResourceUtils.getColor(style.backgroundColor)));
            } else if (target.getBackground() instanceof ColorDrawable) {
                holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(), ((ColorDrawable) target.getBackground()).getColor(), WXResourceUtils.getColor(style.backgroundColor)));
            }
        }
        if (target.getLayoutParams() != null && (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) {
            ViewGroup.LayoutParams layoutParams = target.getLayoutParams();
            if (!TextUtils.isEmpty(style.width)) {
                holders.add(PropertyValuesHolder.ofInt(new WidthProperty(), layoutParams.width, (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth)));
            }
            if (!TextUtils.isEmpty(style.height)) {
                holders.add(PropertyValuesHolder.ofInt(new HeightProperty(), layoutParams.height, (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth)));
            }
        }
        if (style.getPivot() != null) {
            Pair<Float, Float> pair = style.getPivot();
            target.setPivotX(pair.first);
            target.setPivotY(pair.second);
        }
        animator = ObjectAnimator.ofPropertyValuesHolder(target, holders.toArray(new PropertyValuesHolder[holders.size()]));
        animator.setStartDelay(mAnimationBean.delay);
        return animator;
    } else {
        return null;
    }
}
Also used : WXAnimationBean(com.taobao.weex.ui.animation.WXAnimationBean) ObjectAnimator(android.animation.ObjectAnimator) ViewGroup(android.view.ViewGroup) ArgbEvaluator(android.animation.ArgbEvaluator) BackgroundColorProperty(com.taobao.weex.ui.animation.BackgroundColorProperty) WidthProperty(com.taobao.weex.ui.animation.WidthProperty) HeightProperty(com.taobao.weex.ui.animation.HeightProperty) BorderDrawable(com.taobao.weex.ui.view.border.BorderDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) PropertyValuesHolder(android.animation.PropertyValuesHolder) Nullable(android.support.annotation.Nullable)

Example 85 with ArgbEvaluator

use of android.animation.ArgbEvaluator in project incubator-weex by apache.

the class WXTransition method doPendingTransformAnimation.

/**
 *  transform, opacity, backgroundcolor which not effect layout use android system animation in main thread.
 */
private void doPendingTransformAnimation(int token) {
    if (transformAnimator != null) {
        transformAnimator.cancel();
        transformAnimator = null;
    }
    if (transformPendingUpdates.size() == 0) {
        return;
    }
    final View taregtView = getTargetView();
    if (taregtView == null) {
        return;
    }
    List<PropertyValuesHolder> holders = new ArrayList<>(8);
    String transform = WXUtils.getString(transformPendingUpdates.remove(Constants.Name.TRANSFORM), null);
    if (!TextUtils.isEmpty(transform)) {
        Map<Property<View, Float>, Float> properties = TransformParser.parseTransForm(transform, (int) domObject.getLayoutWidth(), (int) domObject.getLayoutHeight(), domObject.getViewPortWidth());
        PropertyValuesHolder[] transformHolders = TransformParser.toHolders(properties);
        for (PropertyValuesHolder holder : transformHolders) {
            holders.add(holder);
        }
        synchronized (targetStyles) {
            targetStyles.put(Constants.Name.TRANSFORM, transform);
        }
    }
    for (String property : properties) {
        if (!TRANSFORM_PROPERTIES.contains(property)) {
            continue;
        }
        if (!transformPendingUpdates.containsKey(property)) {
            continue;
        }
        Object value = transformPendingUpdates.remove(property);
        synchronized (targetStyles) {
            targetStyles.put(property, value);
        }
        switch(property) {
            case Constants.Name.OPACITY:
                {
                    holders.add(PropertyValuesHolder.ofFloat(View.ALPHA, taregtView.getAlpha(), WXUtils.getFloat(value, 1.0f)));
                    // hardware or none has bug on some platform
                    taregtView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
                }
                break;
            case Constants.Name.BACKGROUND_COLOR:
                {
                    int fromColor = WXResourceUtils.getColor(WXUtils.getString(domObject.getStyles().getBackgroundColor(), null), 0);
                    int toColor = WXResourceUtils.getColor(WXUtils.getString(value, null), 0);
                    if (WXViewUtils.getBorderDrawable(taregtView) != null) {
                        fromColor = WXViewUtils.getBorderDrawable(taregtView).getColor();
                    } else if (taregtView.getBackground() instanceof ColorDrawable) {
                        fromColor = ((ColorDrawable) taregtView.getBackground()).getColor();
                    }
                    holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(), fromColor, toColor));
                }
                break;
            default:
                break;
        }
    }
    if (token == lockToken.get()) {
        transformPendingUpdates.clear();
    }
    transformAnimator = ObjectAnimator.ofPropertyValuesHolder(taregtView, holders.toArray(new PropertyValuesHolder[holders.size()]));
    transformAnimator.setDuration((long) duration);
    if ((long) delay > 0) {
        transformAnimator.setStartDelay((long) delay);
    }
    if (interpolator != null) {
        transformAnimator.setInterpolator(interpolator);
    }
    transformAnimator.addListener(new AnimatorListenerAdapter() {

        boolean hasCancel = false;

        @Override
        public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
            hasCancel = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (hasCancel) {
                return;
            }
            super.onAnimationEnd(animation);
            WXTransition.this.onTransitionAnimationEnd();
            if (WXEnvironment.isApkDebugable()) {
                WXLogUtils.d("WXTransition transform onTransitionAnimationEnd " + domObject.getRef());
            }
        }
    });
    transformAnimator.start();
}
Also used : ArgbEvaluator(android.animation.ArgbEvaluator) ArrayList(java.util.ArrayList) View(android.view.View) BackgroundColorProperty(com.taobao.weex.ui.animation.BackgroundColorProperty) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) ColorDrawable(android.graphics.drawable.ColorDrawable) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder) WXDomObject(com.taobao.weex.dom.WXDomObject) Property(android.util.Property) BackgroundColorProperty(com.taobao.weex.ui.animation.BackgroundColorProperty)

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