Skip to content

Commit

Permalink
wip: add ActionBlockLayer functioning
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxGalaxy committed Jan 1, 2025
1 parent 00eb127 commit a5588df
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void addLayers() {

BlockElementLayerBean elementLayer = layers.get(i);
LayerBeanView layerView = LayerBuilder.buildBlockLayerView(
context, eventBlockBean, elementLayer, configuration);
context, eventBlockBean, elementLayer, getLogicEditor(), configuration);
layerView.setLayerPosition(i);
layerView.setFirstLayer(i == 0);
layerView.setLastLayer(i == (layers.size() - 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void addLayers() {
LinearLayout.LayoutParams.WRAP_CONTENT);

LayerBeanView layerView = LayerBuilder.buildBlockLayerView(
context, regularBlockBean, layers.get(i), getLogicEditorConfiguration());
context, regularBlockBean, layers.get(i), getLogicEditor(), getLogicEditorConfiguration());
layerView.setLayerPosition(i);
layerView.setFirstLayer(i == 0);
layerView.setLastLayer(i == (layers.size() - 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@

package com.icst.logic.lib.builder;

import com.icst.android.appstudio.beans.ActionBlockLayerBean;
import com.icst.android.appstudio.beans.BlockBean;
import com.icst.android.appstudio.beans.BlockElementLayerBean;
import com.icst.android.appstudio.beans.ExpressionBlockBean;
import com.icst.android.appstudio.beans.LabelBlockElementBean;
import com.icst.android.appstudio.beans.LayerBean;
import com.icst.logic.editor.view.LogicEditorView;
import com.icst.logic.lib.config.LogicEditorConfiguration;
import com.icst.logic.lib.view.ActionBlockLayerView;
import com.icst.logic.lib.view.BlockElementLayerBeanView;
import com.icst.logic.lib.view.LayerBeanView;
import com.icst.logic.utils.ColorUtils;
Expand All @@ -53,23 +56,28 @@ public static LayerBeanView buildBlockLayerView(
Context context,
BlockBean blockBean,
LayerBean layerBean,
LogicEditorView logicEdtitor,
LogicEditorConfiguration configuration) {
if (layerBean instanceof BlockElementLayerBean mBlockElementLayerBean) {
return buildBlockElementLayerView(
context, blockBean, mBlockElementLayerBean, configuration);
} else if (layerBean instanceof ActionBlockLayerBean actionBlockLayerBean) {
return buildActionBlockLayerView(
context, blockBean, actionBlockLayerBean, logicEdtitor, configuration);
} else
/*return buildActionBlockLayerView(
context, blockBean, mBlockElementLayerBean, configuration);*/
return null;
}

/*private static LayerBeanView<LinearLayout> buildActionBlockLayerView(
Context context,
private static LayerBeanView buildActionBlockLayerView(
Context context,
BlockBean blockBean,
BlockElementLayerBean mBlockElementLayerBean,
LogicEditorConfiguration configuration){
}*/
ActionBlockLayerBean actionBlockLayerBean,
LogicEditorView logicEdtitor,
LogicEditorConfiguration configuration) {
ActionBlockLayerView actionBlockLayerView = new ActionBlockLayerView(context, configuration, logicEdtitor);
actionBlockLayerView.addActionBlocksBeans(actionBlockLayerBean.getActionBlockBean(), 0);
return actionBlockLayerView;
}

// Build the block element layer
private static LayerBeanView buildBlockElementLayerView(
Expand Down Expand Up @@ -112,8 +120,9 @@ private static View buildLabelView(
LinearLayout.LayoutParams.WRAP_CONTENT // Height
);
labelTextView.setTextColor(
ColorUtils.getTextColorForColor(Color.parseColor(
ColorUtils.harmonizeHexColor(context, blockBean.getColor()))));
ColorUtils.getTextColorForColor(
Color.parseColor(
ColorUtils.harmonizeHexColor(context, blockBean.getColor()))));
labelTextView.setLayoutParams(layerLayoutParams);
labelTextView.setPadding(8, 8, 8, 8);
return labelTextView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,25 @@ public void dereferenceActionBlocks(int index) {
// Always throw this error to make sure no unexpected view is added.
@Override
public void addView(View view) {
throw new UnexpectedViewAddedException(this, view);
if (view instanceof LinearLayout) {
super.addView(view);
} else if (view instanceof ActionBlockBeanView) {
super.addView(view);
} else {
throw new UnexpectedViewAddedException(this, view);
}
}

// Always throw this error to make sure no unexpected view is added.
@Override
public void addView(View view, int index) {
throw new UnexpectedViewAddedException(this, view);
if (view instanceof LinearLayout) {
super.addView(view, index);
} else if (view instanceof ActionBlockBeanView) {
super.addView(view, index);
} else {
throw new UnexpectedViewAddedException(this, view);
}
}

public void highlightNearestTarget(ArrayList<ActionBlockBean> blocks, float x, float y) {
Expand Down Expand Up @@ -124,8 +136,6 @@ public void highlightNearestTarget(ActionBlockBean block, float x, float y) {

public void dropToNearestTarget(ArrayList<ActionBlockBean> blocks, float x, float y) {
if (canDrop(blocks, x, y)) {
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.setMargins(0, BlockMarginConstants.CHAINED_ACTION_BLOCK_TOP_MARGIN, 0, 0);
int index = getIndex(x, y);
addBlockBeans(blocks, index);
}
Expand Down Expand Up @@ -198,6 +208,9 @@ public void addActionBlocksBeans(ArrayList<ActionBlockBean> actionBlocks, int in
if (blockBeans == null) {
blockBeans = new ArrayList<ActionBlockBean>();
}
if (actionBlocks == null) {
return;
}
if (index <= blockBeans.size()) {
if (blockBeans.size() == index) {
if (isTerminated())
Expand All @@ -216,7 +229,7 @@ public void addActionBlocksBeans(ArrayList<ActionBlockBean> actionBlocks, int in
throw new IndexOutOfBoundsException(index);
}

private void addBlockBeans(ArrayList<ActionBlockBean> actionBlocks, int index) {
protected void addBlockBeans(ArrayList<ActionBlockBean> actionBlocks, int index) {
this.blockBeans.addAll(index, actionBlocks);

for (int i = 0; i < actionBlocks.size(); ++i) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package com.icst.logic.lib.view;

import java.util.ArrayList;

import com.icst.android.appstudio.beans.ActionBlockBean;
import com.icst.android.appstudio.beans.BlockBean;
import com.icst.logic.block.view.ActionBlockBeanView;
import com.icst.logic.core.BlockMarginConstants;
import com.icst.logic.editor.view.LogicEditorView;
import com.icst.logic.lib.config.LogicEditorConfiguration;
import com.icst.logic.utils.BlockImageUtils;
import com.icst.logic.utils.ColorUtils;
import com.icst.logic.utils.ImageViewUtils;
import com.icst.logic.utils.ActionBlockUtils;
import com.icst.logic.utils.CanvaMathUtils;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;

public class ActionBlockLayerView extends ActionBlockDropZoneView
implements LayerBeanView<ActionBlockLayerView> {
Expand All @@ -18,25 +24,114 @@ public class ActionBlockLayerView extends ActionBlockDropZoneView
private String color;
private BlockBean block;

public ActionBlockLayerView(Context context,
private LinearLayout blockLayout;

public ActionBlockLayerView(
Context context,
LogicEditorConfiguration logicEditorConfiguration,
LogicEditorView logicEditor) {
super(context, logicEditorConfiguration, logicEditor);

blockLayout = new LinearLayout(context);
blockLayout.setOrientation(VERTICAL);
addView(blockLayout);

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
blockLayout.setLayoutParams(lp);
}

@Override
public void setColor(String color) {
this.color = color;
BlockImageUtils.Image image = null;
// BlockImageUtils.Image image = null;
//
// image = BlockImageUtils.Image.BLOCK_ELEMENT_LAYER_BACKDROP;
//
// setBackgroundDrawable(
// ImageViewUtils.getImageView(
// getContext(),
// ColorUtils.harmonizeHexColor(getContext(), getColor()),
// BlockImageUtils.getImage(image)));
// invalidate();
}

// Configured for ActionBlockLayerView
@Override
public int getIndex(float x, float y) {
int[] relativeCoordinates = CanvaMathUtils.getRelativeCoordinates(this, getLogicEditor());

int index = 0;
for (int i = 0; i < blockLayout.getChildCount(); i++) {
View child = blockLayout.getChildAt(i);
if (y - ((int) relativeCoordinates[1]) > child.getY() + (child.getHeight() / 2)) {
index = i + 1;
} else {
break;
}
}

return index;
}

// Configured for ActionBlockLayerView
@Override
protected void addBlockBeans(ArrayList<ActionBlockBean> actionBlocks, int index) {
this.getBlockBeans().addAll(index, actionBlocks);

image = BlockImageUtils.Image.BLOCK_ELEMENT_LAYER_BACKDROP;
for (int i = 0; i < actionBlocks.size(); ++i) {
ActionBlockBean actionBlock = actionBlocks.get(i);
ActionBlockBeanView actionBlockBeanView = ActionBlockUtils.getBlockView(
getContext(), actionBlock, getConfiguration(), getLogicEditor());

setBackgroundDrawable(
ImageViewUtils.getImageView(
getContext(),
ColorUtils.harmonizeHexColor(getContext(), getColor()),
BlockImageUtils.getImage(image)));
invalidate();
if (actionBlockBeanView == null)
continue;

actionBlockBeanView.setInsideCanva(true);
blockLayout.addView(actionBlockBeanView, i + index);

if (i == 0 && index == 0)
continue;

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);

lp.setMargins(0, BlockMarginConstants.CHAINED_ACTION_BLOCK_TOP_MARGIN, 0, 0);
actionBlockBeanView.setLayoutParams(lp);
}
}

// Configured for ActionBlockLayerView
@Override
public void highlightNearestTarget(ArrayList<ActionBlockBean> blocks, float x, float y) {
if (canDrop(blocks, x, y)) {
getLogicEditor().removeDummyHighlighter();
LayoutParams highlighterLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
highlighterLp.setMargins(0, BlockMarginConstants.CHAINED_ACTION_BLOCK_TOP_MARGIN, 0, 0);
NearestTargetHighlighterView highlighter = new NearestTargetHighlighterView(getContext(), blocks.get(0));
getLogicEditor().setDummyHighlighter(highlighter);
int index = getIndex(x, y);
blockLayout.addView(highlighter, index);

highlighter.setLayoutParams(highlighterLp);
}
}

// Configured for ActionBlockLayerView
@Override
public void highlightNearestTarget(ActionBlockBean block, float x, float y) {
if (canDrop(block, x, y)) {
getLogicEditor().removeDummyHighlighter();
LayoutParams highlighterLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
highlighterLp.setMargins(0, BlockMarginConstants.CHAINED_ACTION_BLOCK_TOP_MARGIN, 0, 0);
NearestTargetHighlighterView highlighter = new NearestTargetHighlighterView(getContext(), block);
getLogicEditor().setDummyHighlighter(highlighter);
int index = getIndex(x, y);
blockLayout.addView(highlighter, index);
highlighter.setLayoutParams(highlighterLp);
}
}

@Override
Expand Down

0 comments on commit a5588df

Please sign in to comment.