deal border
This commit is contained in:
parent
796de55cc4
commit
c4672fc0af
@ -5,7 +5,6 @@ import android.graphics.Canvas;
|
|||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Path;
|
import android.graphics.Path;
|
||||||
import android.graphics.Region;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
@ -20,13 +19,11 @@ import android.widget.FrameLayout;
|
|||||||
* @CreateDate: 2019-07-31
|
* @CreateDate: 2019-07-31
|
||||||
*/
|
*/
|
||||||
public class DoricLayer extends FrameLayout {
|
public class DoricLayer extends FrameLayout {
|
||||||
private int mBorderWidth;
|
|
||||||
private int mBorderColor = Color.BLACK;
|
|
||||||
private int mCornerRadius;
|
private int mCornerRadius;
|
||||||
|
|
||||||
private Path mCornerPath = new Path();
|
private Path mCornerPath = new Path();
|
||||||
private Paint shadowPaint = new Paint();
|
private Paint shadowPaint = new Paint();
|
||||||
|
private Paint mBorderPaint;
|
||||||
|
|
||||||
public DoricLayer(@NonNull Context context) {
|
public DoricLayer(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -48,9 +45,11 @@ public class DoricLayer extends FrameLayout {
|
|||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
// draw shadow
|
}
|
||||||
canvas.save();
|
|
||||||
canvas.restore();
|
@Override
|
||||||
|
public void draw(Canvas canvas) {
|
||||||
|
super.draw(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -58,12 +57,26 @@ public class DoricLayer extends FrameLayout {
|
|||||||
return super.drawChild(canvas, child, drawingTime);
|
return super.drawChild(canvas, child, drawingTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBorderWidth(int borderWidth) {
|
@Override
|
||||||
this.mBorderWidth = borderWidth;
|
protected void dispatchDraw(Canvas canvas) {
|
||||||
|
super.dispatchDraw(canvas);
|
||||||
|
// draw border
|
||||||
|
if (mBorderPaint != null) {
|
||||||
|
canvas.drawRect(0, 0, getWidth(), getHeight(), mBorderPaint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBorderColor(int borderColor) {
|
public void setBorder(int borderWidth, int borderColor) {
|
||||||
this.mBorderColor = borderColor;
|
if (borderWidth == 0) {
|
||||||
|
mBorderPaint = null;
|
||||||
|
}
|
||||||
|
if (mBorderPaint == null) {
|
||||||
|
mBorderPaint = new Paint();
|
||||||
|
mBorderPaint.setAntiAlias(true);
|
||||||
|
mBorderPaint.setStyle(Paint.Style.STROKE);
|
||||||
|
}
|
||||||
|
mBorderPaint.setStrokeWidth(borderWidth);
|
||||||
|
mBorderPaint.setColor(borderColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCornerRadius(int corner) {
|
public void setCornerRadius(int corner) {
|
||||||
|
@ -49,19 +49,22 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
|||||||
if (mView == null) {
|
if (mView == null) {
|
||||||
mView = build(jsObject);
|
mView = build(jsObject);
|
||||||
}
|
}
|
||||||
for (String prop : jsObject.propertySet()) {
|
|
||||||
blend(mView, layoutParams, prop, jsObject.getProperty(prop));
|
|
||||||
}
|
|
||||||
if (getView() == null) {
|
if (getView() == null) {
|
||||||
doricLayer = new DoricLayer(getContext());
|
doricLayer = new DoricLayer(getContext());
|
||||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(layoutParams.width, layoutParams.height);
|
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(layoutParams.width, layoutParams.height);
|
||||||
doricLayer.addView(mView, params);
|
doricLayer.addView(mView, params);
|
||||||
} else {
|
}
|
||||||
ViewGroup.LayoutParams params = mView.getLayoutParams();
|
for (String prop : jsObject.propertySet()) {
|
||||||
|
blend(mView, layoutParams, prop, jsObject.getProperty(prop));
|
||||||
|
}
|
||||||
|
ViewGroup.LayoutParams params = mView.getLayoutParams();
|
||||||
|
if (params != null) {
|
||||||
params.width = layoutParams.width;
|
params.width = layoutParams.width;
|
||||||
params.height = layoutParams.height;
|
params.height = layoutParams.height;
|
||||||
mView.setLayoutParams(params);
|
} else {
|
||||||
|
params = layoutParams;
|
||||||
}
|
}
|
||||||
|
mView.setLayoutParams(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void blend(T view, ViewGroup.LayoutParams layoutParams, String name, JSValue prop) {
|
protected void blend(T view, ViewGroup.LayoutParams layoutParams, String name, JSValue prop) {
|
||||||
@ -109,6 +112,12 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
|||||||
mParent.blendChild(this, prop.asObject());
|
mParent.blendChild(this, prop.asObject());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "border":
|
||||||
|
if (prop.isObject() && doricLayer != null) {
|
||||||
|
doricLayer.setBorder(DoricUtils.dp2px(prop.asObject().getProperty("width").asNumber().toFloat()),
|
||||||
|
prop.asObject().getProperty("color").asNumber().toInt());
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,10 @@ class CounterView extends ViewHolder {
|
|||||||
}
|
}
|
||||||
this.counter = new Text
|
this.counter = new Text
|
||||||
this.counter.text = "点击计数"
|
this.counter.text = "点击计数"
|
||||||
|
this.counter.border = {
|
||||||
|
width: 1,
|
||||||
|
color: Color.parse('#000000'),
|
||||||
|
}
|
||||||
this.counter.textSize = 20
|
this.counter.textSize = 20
|
||||||
|
|
||||||
vlayout.space = 20
|
vlayout.space = 20
|
||||||
@ -28,7 +32,7 @@ class CounterView extends ViewHolder {
|
|||||||
}
|
}
|
||||||
vlayout.addChild(this.number)
|
vlayout.addChild(this.number)
|
||||||
vlayout.addChild(this.counter)
|
vlayout.addChild(this.counter)
|
||||||
root.bgColor = Color.parse('#00ff00')
|
// root.bgColor = Color.parse('#00ff00')
|
||||||
vlayout.bgColor = Color.parse('#ff00ff')
|
vlayout.bgColor = Color.parse('#ff00ff')
|
||||||
root.addChild(vlayout)
|
root.addChild(vlayout)
|
||||||
}
|
}
|
||||||
@ -51,6 +55,7 @@ class CounterVM extends ViewModel<CountModel, CounterView> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Entry
|
||||||
class MyPage extends VMPanel<CountModel, CounterView>{
|
class MyPage extends VMPanel<CountModel, CounterView>{
|
||||||
|
|
||||||
getVMClass() {
|
getVMClass() {
|
||||||
@ -374,7 +379,7 @@ class SnakeVM extends ViewModel<SnakeModel, SnakeView>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Entry
|
|
||||||
class SnakePanel extends VMPanel<SnakeModel, SnakeView>{
|
class SnakePanel extends VMPanel<SnakeModel, SnakeView>{
|
||||||
|
|
||||||
getVMClass() {
|
getVMClass() {
|
||||||
|
Reference in New Issue
Block a user