android supports animation

This commit is contained in:
pengfei.zhou 2019-11-29 15:07:32 +08:00
parent 410ad72d71
commit 4e596642f2
3 changed files with 100 additions and 67 deletions

View File

@ -16,8 +16,11 @@
package pub.doric.shader; package pub.doric.shader;
import android.animation.Animator; import android.animation.Animator;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.content.Context; import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
@ -169,7 +172,17 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
} }
break; break;
case "bgColor": case "bgColor":
view.setBackgroundColor(prop.asNumber().toInt()); if (isAnimating()) {
ObjectAnimator animator = ObjectAnimator.ofInt(
this,
name,
getBgColor(),
prop.asNumber().toInt());
animator.setEvaluator(new ArgbEvaluator());
addAnimator(animator);
} else {
setBgColor(prop.asNumber().toInt());
}
break; break;
case "onClick": case "onClick":
final String functionId = prop.asString().value(); final String functionId = prop.asString().value();
@ -425,4 +438,16 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
return 0; return 0;
} }
@DoricMethod
public int getBgColor() {
if (mView.getBackground() instanceof ColorDrawable) {
return ((ColorDrawable) mView.getBackground()).getColor();
}
return Color.TRANSPARENT;
}
@DoricMethod
public void setBgColor(int color) {
mView.setBackgroundColor(color);
}
} }

View File

@ -1,75 +1,79 @@
import { animate, Group, Panel, gravity, Color, LayoutSpec, vlayout, scroller, layoutConfig, IVLayout, modal, IText, network, View, stack } from "doric"; import { animate, Group, Panel, gravity, Color, LayoutSpec, vlayout, scroller, layoutConfig, IVLayout, modal, IText, network, View, stack, IHLayout, hlayout, IView, text } from "doric";
import { title, label, colors, box } from "./utils"; import { title, colors, box } from "./utils";
function thisLabel(str: string) {
return text({
text: str,
width: 100,
height: 50,
bgColor: colors[4],
textSize: 20,
textColor: Color.WHITE,
layoutConfig: layoutConfig().exactly(),
})
}
@Entry @Entry
class AnimatorDemo extends Panel { class AnimatorDemo extends Panel {
build(rootView: Group): void { build(rootView: Group): void {
const view = box(2) const view = box(2)
let idx = 0
vlayout([ vlayout([
title("Animator Demo"), title("Animator Demo"),
label('Reset').apply({ vlayout(
width: 100, [
height: 50, hlayout([
bgColor: colors[4], thisLabel('Reset').apply({
textSize: 20, onClick: () => {
textColor: Color.WHITE, animate(this)({
layoutConfig: layoutConfig().exactly(), animations: () => {
} as IText).also(v => { view.width = view.height = 20
v.onClick = () => { },
animate(this)({ duration: 3000,
animations: () => { }).then(() => {
view.width = view.height = 20 modal(context).toast('Fininshed')
}, }).catch(e => {
duration: 3000, modal(context).toast(`${e}`)
}).then(() => { })
modal(context).toast('Fininshed') }
}, (e: any) => { }),
modal(context).toast(`${e}`) ]),
}) hlayout([
} thisLabel('Width').apply({
}), onClick: () => {
label('Width').apply({ animate(this)({
width: 100, animations: () => {
height: 50, view.width = 200
bgColor: colors[0], },
textSize: 20, duration: 3000,
textColor: Color.WHITE, })
layoutConfig: layoutConfig().exactly(), }
} as IText).also(v => { }),
v.onClick = () => { thisLabel('Height').apply({
animate(this)({ onClick: () => {
animations: () => { animate(this)({
view.width = 300 animations: () => {
}, view.height = 200
duration: 3000, },
}).then(() => { duration: 3000,
modal(context).toast('Fininshed') })
}, (e: any) => { }
modal(context).toast(`${e}`) }),
}) ]).apply({ space: 10 } as IHLayout),
} hlayout([
}), thisLabel('BgColor').apply({
label('Height').apply({ onClick: () => {
width: 100, animate(this)({
height: 50, animations: () => {
bgColor: colors[0], view.bgColor = colors[(idx++) % colors.length]
textSize: 20, },
textColor: Color.WHITE, duration: 3000,
layoutConfig: layoutConfig().exactly(), });
} as IText).also(v => { }
v.onClick = () => { }),
animate(this)({ ]).apply({ space: 10 } as IHLayout),
animations: () => { ]
view.height = 300 ).apply({ space: 10 } as IVLayout),
},
duration: 3000,
}).then(() => {
modal(context).toast('Fininshed')
}, (e: any) => {
modal(context).toast(`${e}`)
})
}
}),
stack([ stack([
view.also(v => { view.also(v => {
v.left = 20 v.left = 20

View File

@ -17,7 +17,11 @@ function fromDir(startPath, filter) {
fromDir(filename, filter); fromDir(filename, filter);
} }
else if (filename.indexOf(filter) >= 0) { else if (filename.indexOf(filter) >= 0) {
doMerge(startPath, files[i]) try {
doMerge(startPath, files[i])
} catch (e) {
console.log(e)
}
}; };
}; };
}; };