add resources to support image tile mode.
This commit is contained in:
parent
77617df848
commit
3f017a9beb
@ -93,6 +93,7 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
private int placeHolderColor = Color.TRANSPARENT;
|
||||
private int errorColor = Color.TRANSPARENT;
|
||||
private JSObject stretchInset = null;
|
||||
private JSObject tileInset = null;
|
||||
private float imageScale = DoricUtils.getScreenScale();
|
||||
private Animatable2Compat.AnimationCallback animationCallback = null;
|
||||
|
||||
@ -161,6 +162,10 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
if (stretchInsetValue.isObject()) {
|
||||
this.stretchInset = stretchInsetValue.asObject();
|
||||
}
|
||||
JSValue tileInsetValue = jsObject.getProperty("tileInset");
|
||||
if (tileInsetValue.isObject()) {
|
||||
this.tileInset = tileInsetValue.asObject();
|
||||
}
|
||||
JSValue imageScaleValue = jsObject.getProperty("imageScale");
|
||||
if (imageScaleValue.isNumber()) {
|
||||
this.imageScale = imageScaleValue.asNumber().toFloat();
|
||||
@ -371,6 +376,27 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
(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(
|
||||
getContext().getResources(),
|
||||
bitmap,
|
||||
|
BIN
doric-demo/assets/coupon_bg2.png
Normal file
BIN
doric-demo/assets/coupon_bg2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 408 B |
BIN
doric-demo/assets/dididi.png
Normal file
BIN
doric-demo/assets/dididi.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 627 B |
BIN
doric-demo/bundle/assets/coupon_bg2.png
Normal file
BIN
doric-demo/bundle/assets/coupon_bg2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 408 B |
BIN
doric-demo/bundle/assets/dididi.png
Normal file
BIN
doric-demo/bundle/assets/dididi.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 627 B |
@ -158,7 +158,7 @@ class ImageDemo extends Panel {
|
||||
scaleType: ScaleType.ScaleAspectFill,
|
||||
layoutConfig: layoutConfig().just(),
|
||||
}),
|
||||
label('StretchInset'),
|
||||
label('StretchInset1'),
|
||||
image({
|
||||
imageBase64: img_base64[1],
|
||||
height: 60,
|
||||
@ -179,25 +179,51 @@ class ImageDemo extends Panel {
|
||||
bottom: 0
|
||||
}
|
||||
}),
|
||||
label('tileInset'),
|
||||
|
||||
label('StretchInset 2'),
|
||||
image({
|
||||
imageBase64: img_base64[1],
|
||||
height: 66,
|
||||
width: 147,
|
||||
image: new AssetsResource("coupon_bg2.png"),
|
||||
height: 48,
|
||||
width: 78,
|
||||
scaleType: ScaleType.ScaleAspectFill,
|
||||
layoutConfig: layoutConfig().just(),
|
||||
}),
|
||||
image({
|
||||
imageBase64: img_base64[1],
|
||||
height: 66 * 2,
|
||||
width: 147 * 2,
|
||||
backgroundColor: Color.CYAN,
|
||||
image: new AssetsResource("coupon_bg2.png"),
|
||||
height: 48,
|
||||
width: 78*3,
|
||||
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,
|
||||
layoutConfig: layoutConfig().just(),
|
||||
tileInset: {
|
||||
left: 0,
|
||||
top: 0,
|
||||
right: 83,
|
||||
right: 0,
|
||||
bottom: 0
|
||||
}
|
||||
}),
|
||||
@ -242,4 +268,4 @@ class ImageDemo extends Panel {
|
||||
onDestroy() {
|
||||
modal(context).toast('onDestroy')
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user