add layer for android
This commit is contained in:
parent
2e7814b499
commit
796de55cc4
@ -0,0 +1,76 @@
|
|||||||
|
package com.github.penfeizhou.doric.shader;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Path;
|
||||||
|
import android.graphics.Region;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.annotation.RequiresApi;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: com.github.penfeizhou.doric.shader
|
||||||
|
* @Author: pengfei.zhou
|
||||||
|
* @CreateDate: 2019-07-31
|
||||||
|
*/
|
||||||
|
public class DoricLayer extends FrameLayout {
|
||||||
|
private int mBorderWidth;
|
||||||
|
private int mBorderColor = Color.BLACK;
|
||||||
|
private int mCornerRadius;
|
||||||
|
|
||||||
|
private Path mCornerPath = new Path();
|
||||||
|
private Paint shadowPaint = new Paint();
|
||||||
|
|
||||||
|
|
||||||
|
public DoricLayer(@NonNull Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DoricLayer(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DoricLayer(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
public DoricLayer(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
// draw shadow
|
||||||
|
canvas.save();
|
||||||
|
canvas.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
|
||||||
|
return super.drawChild(canvas, child, drawingTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBorderWidth(int borderWidth) {
|
||||||
|
this.mBorderWidth = borderWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBorderColor(int borderColor) {
|
||||||
|
this.mBorderColor = borderColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCornerRadius(int corner) {
|
||||||
|
if (mCornerRadius != corner) {
|
||||||
|
this.mCornerRadius = corner;
|
||||||
|
mCornerPath.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -50,7 +50,7 @@ public abstract class GroupNode<F extends ViewGroup> extends ViewNode<F> {
|
|||||||
} else if (i != child.index) {
|
} else if (i != child.index) {
|
||||||
mIndexInfo.remove(i);
|
mIndexInfo.remove(i);
|
||||||
child.index = i;
|
child.index = i;
|
||||||
mView.removeView(child.mView);
|
mView.removeView(child.getView());
|
||||||
}
|
}
|
||||||
ViewGroup.LayoutParams params = child.getLayoutParams();
|
ViewGroup.LayoutParams params = child.getLayoutParams();
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
@ -58,7 +58,7 @@ public abstract class GroupNode<F extends ViewGroup> extends ViewNode<F> {
|
|||||||
}
|
}
|
||||||
child.blend(childObj.getProperty("props").asObject(), params);
|
child.blend(childObj.getProperty("props").asObject(), params);
|
||||||
if (mIndexInfo.get(i) == null) {
|
if (mIndexInfo.get(i) == null) {
|
||||||
mView.addView(child.mView, i);
|
mView.addView(child.getView(), i, child.getLayoutParams());
|
||||||
mIndexInfo.put(i, child);
|
mIndexInfo.put(i, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.github.penfeizhou.doric.shader;
|
package com.github.penfeizhou.doric.shader;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
import com.github.penfeizhou.doric.DoricContext;
|
import com.github.penfeizhou.doric.DoricContext;
|
||||||
@ -17,11 +19,21 @@ public class RootNode extends StackNode {
|
|||||||
super(doricContext);
|
super(doricContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView() {
|
||||||
|
return mView;
|
||||||
|
}
|
||||||
|
|
||||||
public void setRootView(FrameLayout rootView) {
|
public void setRootView(FrameLayout rootView) {
|
||||||
this.mView = rootView;
|
this.mView = rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ViewGroup.LayoutParams getLayoutParams() {
|
||||||
|
return mView.getLayoutParams();
|
||||||
|
}
|
||||||
|
|
||||||
public void render(JSObject props) {
|
public void render(JSObject props) {
|
||||||
blend(props, mView.getLayoutParams());
|
blend(props, getLayoutParams());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.github.penfeizhou.doric.shader;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
import com.github.penfeizhou.doric.DoricContext;
|
import com.github.penfeizhou.doric.DoricContext;
|
||||||
import com.github.penfeizhou.doric.DoricRegistry;
|
import com.github.penfeizhou.doric.DoricRegistry;
|
||||||
@ -31,8 +32,10 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
|||||||
super(doricContext);
|
super(doricContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getView() {
|
private DoricLayer doricLayer;
|
||||||
return mView;
|
|
||||||
|
public View getView() {
|
||||||
|
return doricLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Context getContext() {
|
public Context getContext() {
|
||||||
@ -49,7 +52,16 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
|||||||
for (String prop : jsObject.propertySet()) {
|
for (String prop : jsObject.propertySet()) {
|
||||||
blend(mView, layoutParams, prop, jsObject.getProperty(prop));
|
blend(mView, layoutParams, prop, jsObject.getProperty(prop));
|
||||||
}
|
}
|
||||||
mView.setLayoutParams(layoutParams);
|
if (getView() == null) {
|
||||||
|
doricLayer = new DoricLayer(getContext());
|
||||||
|
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(layoutParams.width, layoutParams.height);
|
||||||
|
doricLayer.addView(mView, params);
|
||||||
|
} else {
|
||||||
|
ViewGroup.LayoutParams params = mView.getLayoutParams();
|
||||||
|
params.width = layoutParams.width;
|
||||||
|
params.height = layoutParams.height;
|
||||||
|
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) {
|
||||||
|
@ -174,7 +174,7 @@ class SnakeModel {
|
|||||||
if (this.head.x < 0 || this.head.x >= this.width
|
if (this.head.x < 0 || this.head.x >= this.width
|
||||||
|| this.head.y < 0 || this.head.y >= this.height) {
|
|| this.head.y < 0 || this.head.y >= this.height) {
|
||||||
//If out of bound
|
//If out of bound
|
||||||
loge('out of bound', this.head)
|
loge('out of bound')
|
||||||
this.state = State.fail
|
this.state = State.fail
|
||||||
} else if (this.head.x == this.food.x && this.head.y == this.food.y) {
|
} else if (this.head.x == this.food.x && this.head.y == this.food.y) {
|
||||||
//If eat food
|
//If eat food
|
||||||
|
Reference in New Issue
Block a user