add resources to support image tile mode.

This commit is contained in:
吴尚昆 2022-03-17 17:27:02 +08:00 committed by osborn
parent 77617df848
commit 3f017a9beb
6 changed files with 63 additions and 11 deletions

View File

@ -93,6 +93,7 @@ public class ImageNode extends ViewNode<ImageView> {
private int placeHolderColor = Color.TRANSPARENT; private int placeHolderColor = Color.TRANSPARENT;
private int errorColor = Color.TRANSPARENT; private int errorColor = Color.TRANSPARENT;
private JSObject stretchInset = null; private JSObject stretchInset = null;
private JSObject tileInset = null;
private float imageScale = DoricUtils.getScreenScale(); private float imageScale = DoricUtils.getScreenScale();
private Animatable2Compat.AnimationCallback animationCallback = null; private Animatable2Compat.AnimationCallback animationCallback = null;
@ -161,6 +162,10 @@ public class ImageNode extends ViewNode<ImageView> {
if (stretchInsetValue.isObject()) { if (stretchInsetValue.isObject()) {
this.stretchInset = stretchInsetValue.asObject(); this.stretchInset = stretchInsetValue.asObject();
} }
JSValue tileInsetValue = jsObject.getProperty("tileInset");
if (tileInsetValue.isObject()) {
this.tileInset = tileInsetValue.asObject();
}
JSValue imageScaleValue = jsObject.getProperty("imageScale"); JSValue imageScaleValue = jsObject.getProperty("imageScale");
if (imageScaleValue.isNumber()) { if (imageScaleValue.isNumber()) {
this.imageScale = imageScaleValue.asNumber().toFloat(); this.imageScale = imageScaleValue.asNumber().toFloat();
@ -371,6 +376,27 @@ public class ImageNode extends ViewNode<ImageView> {
(int) (bitmap.getHeight() - bottom) (int) (bitmap.getHeight() - bottom)
); );
NinePatchDrawable ninePatchDrawable = new NinePatchDrawable(
getContext().getResources(),
bitmap,
DoricUtils.getNinePatchChunk(rect),
rect,
null
);
super.setResource(ninePatchDrawable);
} else if (tileInset != null) {
float left = tileInset.getProperty("left").asNumber().toFloat() * scale;
float top = tileInset.getProperty("top").asNumber().toFloat() * scale;
float right = tileInset.getProperty("right").asNumber().toFloat() * scale;
float bottom = tileInset.getProperty("bottom").asNumber().toFloat() * scale;
Rect rect = new Rect(
(int) left,
(int) top,
(int) (bitmap.getWidth() - right),
(int) (bitmap.getHeight() - bottom)
);
NinePatchDrawable ninePatchDrawable = new NinePatchDrawable( NinePatchDrawable ninePatchDrawable = new NinePatchDrawable(
getContext().getResources(), getContext().getResources(),
bitmap, bitmap,

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 627 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 627 B

View File

@ -158,7 +158,7 @@ class ImageDemo extends Panel {
scaleType: ScaleType.ScaleAspectFill, scaleType: ScaleType.ScaleAspectFill,
layoutConfig: layoutConfig().just(), layoutConfig: layoutConfig().just(),
}), }),
label('StretchInset'), label('StretchInset1'),
image({ image({
imageBase64: img_base64[1], imageBase64: img_base64[1],
height: 60, height: 60,
@ -179,25 +179,51 @@ class ImageDemo extends Panel {
bottom: 0 bottom: 0
} }
}), }),
label('tileInset'),
label('StretchInset 2'),
image({ image({
imageBase64: img_base64[1], image: new AssetsResource("coupon_bg2.png"),
height: 66, height: 48,
width: 147, width: 78,
scaleType: ScaleType.ScaleAspectFill, scaleType: ScaleType.ScaleAspectFill,
layoutConfig: layoutConfig().just(), layoutConfig: layoutConfig().just(),
}), }),
image({ image({
imageBase64: img_base64[1], image: new AssetsResource("coupon_bg2.png"),
height: 66 * 2, height: 48,
width: 147 * 2, width: 78*3,
backgroundColor: Color.CYAN, scaleType: ScaleType.ScaleToFill,
imageScale:1,
layoutConfig: layoutConfig().just(),
stretchInset: {
left: 0,
top: 0,
right: 76,
bottom: 0
}
}),
label('tileInset'),
image({
image: new AssetsResource("dididi.png"),
height: 78,
width: 84,
backgroundColor: Color.BLACK,
scaleType: ScaleType.ScaleAspectFill,
layoutConfig: layoutConfig().just(),
}),
image({
image: new AssetsResource("dididi.png"),
height: 78 * 1,
width: 84 * 3,
imageScale:1,
backgroundColor: Color.BLACK,
scaleType: ScaleType.ScaleToFill, scaleType: ScaleType.ScaleToFill,
layoutConfig: layoutConfig().just(), layoutConfig: layoutConfig().just(),
tileInset: { tileInset: {
left: 0, left: 0,
top: 0, top: 0,
right: 83, right: 0,
bottom: 0 bottom: 0
} }
}), }),
@ -242,4 +268,4 @@ class ImageDemo extends Panel {
onDestroy() { onDestroy() {
modal(context).toast('onDestroy') modal(context).toast('onDestroy')
} }
} }