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);
}
}
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();
}
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);
}
}
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;
}
}
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();
}
Aggregations