Skip to content

Commit

Permalink
feat: fixed boolean block drop feature
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxGalaxy committed Nov 14, 2023
1 parent cd95c0e commit be786f4
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 87 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/builtin/blocks/BuiltInBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public static ArrayList<BlocksHolder> getBuiltInBlocksHolder() {
blockInHolder4.setBlockType(Block.BlockType.returnWithTypeBoolean);
blockInHolder4.setName("true");
blockInHolder4.setRawCode("true");
blockInHolder4.setReturns("boolean");

ArrayList<BlockContent> block4ContentList = new ArrayList<BlockContent>();

Expand Down
229 changes: 157 additions & 72 deletions app/src/main/java/com/dragon/ide/ui/activities/EventEditorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ public void handleShadowRemove(ViewGroup v) {
}
}
}
} else if (v.getTag() instanceof String[]) {
for (String str : (String[]) v.getTag()) {
if (str.equals("boolean")) {
if (v.getChildCount() > 1) {
v.getChildAt(1).setVisibility(View.VISIBLE);
}
}
}
}
}
if (blockShadow.getParent() != null) {
Expand Down Expand Up @@ -359,80 +367,122 @@ public boolean onDrag(View v, DragEvent dragEvent) {
case DragEvent.ACTION_DRAG_EXITED:
return true;
case DragEvent.ACTION_DROP:
if (v instanceof LinearLayout) {
if ((dragView instanceof BlockDefaultView)) {
if (((BlockDefaultView) dragView).getBlock().getBlockType()
== Block.BlockType.defaultBlock) {
BlockDefaultView blockView = new BlockDefaultView(this);
blockView.setLanguage(language);
blockView.setEnableEdit(true);
try {
Block block = ((BlockDefaultView) dragView).getBlock().clone();
blockView.setBlock(block);
} catch (CloneNotSupportedException e) {
blockView.setBlock(new Block());
}
((LinearLayout) v).addView(blockView, index);
if (blockView.getLayoutParams() != null) {
((LinearLayout.LayoutParams) blockView.getLayoutParams()).setMargins(0, -26, 0, 0);
((LinearLayout.LayoutParams) blockView.getLayoutParams()).width =
LinearLayout.LayoutParams.WRAP_CONTENT;
}
if (((int) v.getId()) != R.id.relativeBlockListEditorArea) {
if (index == 0) {
if (((LinearLayout.LayoutParams) blockView.getLayoutParams()) != null) {
if (v.getTag() != null) {
if (v.getTag() instanceof String) {
if (((String) v.getTag()).equals("blockDroppingArea")) {
if ((dragView instanceof BlockDefaultView)) {
if (((BlockDefaultView) dragView).getBlock().getBlockType()
== Block.BlockType.defaultBlock) {
BlockDefaultView blockView = new BlockDefaultView(this);
blockView.setLanguage(language);
blockView.setEnableEdit(true);
try {
Block block = ((BlockDefaultView) dragView).getBlock().clone();
blockView.setBlock(block);
} catch (CloneNotSupportedException e) {
blockView.setBlock(new Block());
}
((LinearLayout) v).addView(blockView, index);
if (blockView.getLayoutParams() != null) {
((LinearLayout.LayoutParams) blockView.getLayoutParams())
.setMargins(0, 0, 0, 0);
if (((LinearLayout) v).getChildCount() > 1) {
if (((LinearLayout) v).getChildAt(1).getLayoutParams() != null) {
((LinearLayout.LayoutParams)
((LinearLayout) v).getChildAt(1).getLayoutParams())
.setMargins(0, -26, 0, 0);
.setMargins(0, -26, 0, 0);
((LinearLayout.LayoutParams) blockView.getLayoutParams()).width =
LinearLayout.LayoutParams.WRAP_CONTENT;
}
if (v.getId() != R.id.relativeBlockListEditorArea) {
if (index == 0) {
if (((LinearLayout.LayoutParams) blockView.getLayoutParams()) != null) {
((LinearLayout.LayoutParams) blockView.getLayoutParams())
.setMargins(0, 0, 0, 0);
if (((LinearLayout) v).getChildCount() > 1) {
if (((LinearLayout) v).getChildAt(1).getLayoutParams() != null) {
((LinearLayout.LayoutParams)
((LinearLayout) v).getChildAt(1).getLayoutParams())
.setMargins(0, -26, 0, 0);
}
}
}
}
}
}
}
}
}

if ((dragView instanceof ComplexBlockView)) {
if (((ComplexBlockView) dragView).getComplexBlock().getBlockType()
== Block.BlockType.complexBlock) {
ComplexBlockView blockView = new ComplexBlockView(this);
blockView.setLanguage(language);
blockView.setEnableEdit(true);
try {
ComplexBlock complexBlock = ((ComplexBlockView) dragView).getComplexBlock().clone();
blockView.setComplexBlock(complexBlock);
} catch (CloneNotSupportedException e) {
blockView.setComplexBlock(new ComplexBlock());
}
((LinearLayout) v).addView(blockView, index);
if (blockView.getLayoutParams() != null) {
((LinearLayout.LayoutParams) blockView.getLayoutParams()).setMargins(0, -26, 0, 0);
((LinearLayout.LayoutParams) blockView.getLayoutParams()).width =
LinearLayout.LayoutParams.WRAP_CONTENT;
}

if (v.getId() != R.id.relativeBlockListEditorArea) {
if (index == 0) {
if (((LinearLayout.LayoutParams) blockView.getLayoutParams()) != null) {
if ((dragView instanceof ComplexBlockView)) {
if (((ComplexBlockView) dragView).getComplexBlock().getBlockType()
== Block.BlockType.complexBlock) {
ComplexBlockView blockView = new ComplexBlockView(this);
blockView.setLanguage(language);
blockView.setEnableEdit(true);
try {
ComplexBlock complexBlock =
((ComplexBlockView) dragView).getComplexBlock().clone();
blockView.setComplexBlock(complexBlock);
} catch (CloneNotSupportedException e) {
blockView.setComplexBlock(new ComplexBlock());
}
((LinearLayout) v).addView(blockView, index);
if (blockView.getLayoutParams() != null) {
((LinearLayout.LayoutParams) blockView.getLayoutParams())
.setMargins(0, 0, 0, 0);
if (((LinearLayout) v).getChildCount() > 1) {
if (((LinearLayout) v).getChildAt(1).getLayoutParams() != null) {
((LinearLayout.LayoutParams)
((LinearLayout) v).getChildAt(1).getLayoutParams())
.setMargins(0, -26, 0, 0);
.setMargins(0, -26, 0, 0);
((LinearLayout.LayoutParams) blockView.getLayoutParams()).width =
LinearLayout.LayoutParams.WRAP_CONTENT;
}

if (v.getId() != R.id.relativeBlockListEditorArea) {
if (index == 0) {
if (((LinearLayout.LayoutParams) blockView.getLayoutParams()) != null) {
((LinearLayout.LayoutParams) blockView.getLayoutParams())
.setMargins(0, 0, 0, 0);
if (((LinearLayout) v).getChildCount() > 1) {
if (((LinearLayout) v).getChildAt(1).getLayoutParams() != null) {
((LinearLayout.LayoutParams)
((LinearLayout) v).getChildAt(1).getLayoutParams())
.setMargins(0, -26, 0, 0);
}
}
}
}
}
}
}
}
} else if (v.getTag() instanceof String[]) {
for (String str : (String[]) v.getTag()) {
if (str.equals("boolean")) {
BlockDefaultView blockView = new BlockDefaultView(this);
blockView.setLanguage(language);
blockView.setEnableEdit(true);
try {
Block block = ((BlockDefaultView) dragView).getBlock().clone();
blockView.setBlock(block);
} catch (CloneNotSupportedException e) {
blockView.setBlock(new Block());
}
if (((ViewGroup) v).getChildCount() != 0) {
View view = ((ViewGroup) v).getChildAt(0);
if (((ViewGroup) view).getParent() != null) {
((ViewGroup) ((ViewGroup) view).getParent()).removeView(view);
}
binding.relativeBlockListEditorArea.addView(view);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(-2, -2);
lp.setMargins(
(int) dropX + binding.relativeBlockListEditorArea.getScrollX(),
(int) dropY + binding.relativeBlockListEditorArea.getScrollY(),
0,
0);
view.setLayoutParams(lp);
}

((ViewGroup) v).addView(blockView);
if (blockView.getLayoutParams() != null) {
((LinearLayout.LayoutParams) blockView.getLayoutParams()).width =
LinearLayout.LayoutParams.WRAP_CONTENT;
}
}
}
}
}

if (v instanceof FrameLayout) {
if ((dragView instanceof BlockDefaultView)) {
BlockDefaultView blockView = new BlockDefaultView(this);
Expand Down Expand Up @@ -519,25 +569,60 @@ public boolean onDrag(View v, DragEvent dragEvent) {
}

private void handleShadowOnLocation(final View v, final int index) {
if (!(v instanceof FrameLayout)) {
((ViewGroup) v).addView(blockShadow, index);
if (((LinearLayout.LayoutParams) blockShadow.getLayoutParams()) != null) {
((LinearLayout.LayoutParams) blockShadow.getLayoutParams()).setMargins(0, -26, 0, 0);
((LinearLayout.LayoutParams) blockShadow.getLayoutParams()).width =
LinearLayout.LayoutParams.WRAP_CONTENT;
}
if (v.getId() != R.id.blockListEditorArea) {
if (index == 0) {
if (((LinearLayout.LayoutParams) blockShadow.getLayoutParams()) != null) {
((LinearLayout.LayoutParams) blockShadow.getLayoutParams()).setMargins(0, 0, 0, 0);
if (((LinearLayout) v).getChildCount() > 1) {
if (((LinearLayout) v).getChildAt(1).getLayoutParams() != null) {
((LinearLayout.LayoutParams) ((LinearLayout) v).getChildAt(1).getLayoutParams())
if (v.getTag() != null) {
if (v.getTag() instanceof String) {
if (((String) v.getTag()).equals("blockDroppingArea")) {
blockShadow.setBackgroundResource(R.drawable.block_default);

Drawable backgroundDrawable = blockShadow.getBackground();
backgroundDrawable.setTint(Color.BLACK);
backgroundDrawable.setTintMode(PorterDuff.Mode.SRC_IN);
blockShadow.setBackground(backgroundDrawable);
if (v.getId() != R.id.blockListEditorArea) {
if (index != 0) {
if (((ViewGroup) blockShadow).getLayoutParams() != null) {
((LinearLayout.LayoutParams) blockShadow.getLayoutParams())
.setMargins(0, -26, 0, 0);
}
} else {
((LinearLayout.LayoutParams) blockShadow.getLayoutParams()).setMargins(0, 0, 0, 0);
if (((LinearLayout.LayoutParams) blockShadow.getLayoutParams()) != null) {
if (((LinearLayout) v).getChildCount() > 0) {
if (((LinearLayout) v).getChildAt(0).getLayoutParams() != null) {
((LinearLayout.LayoutParams) ((LinearLayout) v).getChildAt(0).getLayoutParams())
.setMargins(0, -26, 0, 0);
}
}
}
}

} else {
if (((ViewGroup) blockShadow).getLayoutParams() != null) {
((LinearLayout.LayoutParams) blockShadow.getLayoutParams()).setMargins(0, -26, 0, 0);
}
}
((ViewGroup) v).addView(blockShadow, index);
}
} else if (v.getTag() instanceof String[]) {
for (String str : (String[]) v.getTag()) {
if (str.equals("boolean")) {
blockShadow.setBackgroundResource(R.drawable.block_boolean);

Drawable backgroundDrawable = blockShadow.getBackground();
backgroundDrawable.setTint(Color.BLACK);
backgroundDrawable.setTintMode(PorterDuff.Mode.SRC_IN);
blockShadow.setBackground(backgroundDrawable);
if (((ViewGroup) v).getChildCount() != 0) {
((ViewGroup) v).getChildAt(0).setVisibility(View.GONE);
}
((ViewGroup) v).addView(blockShadow, 0);
}
}
}

if (((LinearLayout.LayoutParams) blockShadow.getLayoutParams()) != null) {
((LinearLayout.LayoutParams) blockShadow.getLayoutParams()).width =
LinearLayout.LayoutParams.WRAP_CONTENT;
}
}
}
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/java/com/dragon/ide/ui/adapters/BlockListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ public void onBindViewHolder(ViewHolder _holder, int _position) {
ClipData data = ClipData.newPlainText("", "");
View.DragShadowBuilder shadow = new View.DragShadowBuilder(complexBlockView);

// ((EventEditorActivity) activity)
// .binding
// .getRoot()
// .findViewById(R.id.blockListEditorArea)
// .setOnDragListener(((EventEditorActivity) activity));

addDragListener(
((EventEditorActivity) activity).binding.relativeBlockListEditorArea,
(EventEditorActivity) activity,
Expand All @@ -83,12 +77,6 @@ public void onBindViewHolder(ViewHolder _holder, int _position) {
ClipData data = ClipData.newPlainText("", "");
View.DragShadowBuilder shadow = new View.DragShadowBuilder(blockView);

// ((EventEditorActivity) activity)
// .binding
// .getRoot()
// .findViewById(R.id.blockListEditorArea)
// .setOnDragListener(((EventEditorActivity) activity));

addDragListener(
((EventEditorActivity) activity).binding.relativeBlockListEditorArea,
(EventEditorActivity) activity,
Expand Down
29 changes: 26 additions & 3 deletions app/src/main/java/com/dragon/ide/utils/BlockContentLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,38 @@ public static void loadBlockContent(
.new SourceContentClickListener(tvTextContent, sc, activity, language, ll_source));
}
} else if (blockContent.get(i) instanceof BooleanContent) {
final LinearLayout ll_boolean = new LinearLayout(view.getContext());
final LinearLayout ll_boolean =
new LinearLayout(view.getContext()) {
@Override
public void addView(View v) {
super.addView(v);
setAlpha(1f);
}

@Override
public void addView(View v, int index) {
super.addView(v, index);
setAlpha(1f);
}

@Override
public void removeView(View v) {
super.removeView(v);
if (getChildCount() == 0) {
setAlpha(0.3f);
} else {
setAlpha(1f);
}
}
};
ll_boolean.setTag(((ComplexBlockContent) blockContent.get(i)).getAcceptance());
ll_boolean.setBackgroundResource(R.drawable.block_boolean_bg);
Drawable backgroundDrawableBoolean = ll_boolean.getBackground();
backgroundDrawableBoolean.setTint(
ColorUtils.getColor(activity, com.google.android.material.R.attr.colorSurface));
ColorUtils.getColor(activity, com.google.android.material.R.attr.colorOnSurface));
backgroundDrawableBoolean.setTintMode(PorterDuff.Mode.SRC_IN);
ll_boolean.setBackground(backgroundDrawableBoolean);
ll_boolean.setAlpha(0.5f);
ll_boolean.setAlpha(0.3f);
view.addView(ll_boolean, view.getChildCount());
}
} else if (blockContent.get(i) instanceof BlockContent) {
Expand Down

0 comments on commit be786f4

Please sign in to comment.