use of com.taobao.weex.ui.animation.BackgroundColorProperty 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 com.taobao.weex.ui.animation.BackgroundColorProperty 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