Skip to content

Commit

Permalink
feat: Design boolean content
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxGalaxy committed Nov 13, 2023
1 parent 3cd0678 commit 4594e80
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 42 deletions.
13 changes: 7 additions & 6 deletions app/src/main/java/builtin/blocks/BuiltInBlocks.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package builtin.blocks;

import android.graphics.Color;
import android.util.Log;
import android.widget.Toast;
import com.dragon.ide.objects.Block;
import com.dragon.ide.objects.BlockContent;
import com.dragon.ide.objects.BlocksHolder;
Expand All @@ -26,7 +28,7 @@ public static ArrayList<BlocksHolder> getBuiltInBlocksHolder() {
blockInHolder1.setName("addSource");
blockInHolder1.setRawCode("DevKumar DragonIDE parameter DevKumar");

ArrayList<Object> block1ContentList = new ArrayList<Object>();
ArrayList<BlockContent> block1ContentList = new ArrayList<BlockContent>();

BlockContent block1Content1 = new BlockContent();
block1Content1.setText("add source");
Expand All @@ -44,7 +46,7 @@ public static ArrayList<BlocksHolder> getBuiltInBlocksHolder() {
blockInHolder2.setName("Test");
blockInHolder2.setRawCode("I am block code DevKumar DragonIDE parameter DevKumar");

ArrayList<Object> block2ContentList = new ArrayList<Object>();
ArrayList<BlockContent> block2ContentList = new ArrayList<BlockContent>();

BlockContent block2Content1 = new BlockContent();
block2Content1.setText("Test block code");
Expand All @@ -62,22 +64,21 @@ public static ArrayList<BlocksHolder> getBuiltInBlocksHolder() {
blockInHolder3.setName("if");
StringBuilder blockInHolder3StringBuilder = new StringBuilder();
blockInHolder3StringBuilder.append("if (");
blockInHolder3StringBuilder.append(CodeReplacer.getReplacer("parameter"));
blockInHolder3StringBuilder.append(CodeReplacer.getReplacer("condition"));
blockInHolder3StringBuilder.append(") {\n\t");
blockInHolder3StringBuilder.append(CodeReplacer.getReplacer("complexBlockContent"));
blockInHolder3StringBuilder.append("\n}");
blockInHolder3.setRawCode(blockInHolder3StringBuilder.toString());

ArrayList<Object> block3ContentList = new ArrayList<Object>();
ArrayList<BlockContent> block3ContentList = new ArrayList<BlockContent>();

BlockContent block3Content1 = new BlockContent();
block3Content1.setText("if");
block3ContentList.add(block3Content1);

BooleanContent block3Content2 = new BooleanContent();
block3Content2.setId("parameter");
block3Content2.setId("condition");
block3ContentList.add(block3Content2);

blockInHolder3.setBlockContent(block3ContentList);

blockList.add(blockInHolder1);
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/com/dragon/ide/objects/Block.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dragon.ide.objects;

import com.dragon.ide.objects.blockcontent.BooleanContent;
import com.dragon.ide.objects.blockcontent.SourceContent;
import com.dragon.ide.utils.CodeReplacer;
import java.io.Serializable;
Expand All @@ -9,7 +10,7 @@ public class Block implements Serializable, Cloneable {
private static final long serialVersionUID = 428383837L;
private String color;
private String name;
private ArrayList<Object> blockContent;
private ArrayList<BlockContent> blockContent;
private int BlockType;
private String rawCode;
private String returns;
Expand Down Expand Up @@ -72,11 +73,11 @@ public final class BlockType {
public static final int doubleComplexBlock = 2;
}

public ArrayList<Object> getBlockContent() {
public ArrayList<BlockContent> getBlockContent() {
return blockContent;
}

public void setBlockContent(ArrayList<Object> blockContent) {
public void setBlockContent(ArrayList<BlockContent> blockContent) {
this.blockContent = blockContent;
}

Expand Down Expand Up @@ -105,20 +106,22 @@ public Block clone() throws CloneNotSupportedException {
} else {
mName = new String("");
}
ArrayList<Object> mBlockContent;
ArrayList<BlockContent> mBlockContent;
if (getBlockContent() != null) {
mBlockContent = new ArrayList<Object>();
mBlockContent = new ArrayList<BlockContent>();
for (int i = 0; i < getBlockContent().size(); ++i) {
if (getBlockContent().get(i) instanceof ComplexBlockContent) {
if (getBlockContent().get(i) instanceof SourceContent) {
mBlockContent.add(((SourceContent) getBlockContent().get(i)).clone());
} else if (getBlockContent().get(i) instanceof BooleanContent) {
mBlockContent.add(((BooleanContent) getBlockContent().get(i)).clone());
}
} else if (getBlockContent().get(i) instanceof BlockContent) {
mBlockContent.add(((BlockContent) getBlockContent().get(i)).clone());
}
}
} else {
mBlockContent = new ArrayList<Object>();
mBlockContent = new ArrayList<BlockContent>();
}
int mBlockType;
if (getBlockType() != 0) {
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/com/dragon/ide/objects/ComplexBlock.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dragon.ide.objects;

import android.util.Log;
import com.dragon.ide.objects.blockcontent.BooleanContent;
import com.dragon.ide.objects.blockcontent.SourceContent;
import com.dragon.ide.utils.CodeReplacer;
import java.io.Serializable;
Expand Down Expand Up @@ -71,7 +72,9 @@ public String getCode() {
}
innerBlockCodeSB.append(innerBlockCodeLines[i2]);
}
line = line.replaceAll(CodeReplacer.getReplacer("complexBlockContent"), innerBlockCodeSB.toString());
line =
line.replaceAll(
CodeReplacer.getReplacer("complexBlockContent"), innerBlockCodeSB.toString());
}
if (i != 0) {
mainCode.append("\n");
Expand Down Expand Up @@ -99,20 +102,22 @@ public ComplexBlock clone() throws CloneNotSupportedException {
} else {
mName = new String("");
}
ArrayList<Object> mBlockContent;
ArrayList<BlockContent> mBlockContent;
if (getBlockContent() != null) {
mBlockContent = new ArrayList<Object>();
mBlockContent = new ArrayList<BlockContent>();
for (int i = 0; i < getBlockContent().size(); ++i) {
if (getBlockContent().get(i) instanceof ComplexBlockContent) {
if (getBlockContent().get(i) instanceof SourceContent) {
mBlockContent.add(((SourceContent) getBlockContent().get(i)).clone());
} else if (getBlockContent().get(i) instanceof BooleanContent) {
mBlockContent.add(((BooleanContent) getBlockContent().get(i)).clone());
}
} else if (getBlockContent().get(i) instanceof BlockContent) {
mBlockContent.add(((BlockContent) getBlockContent().get(i)).clone());
}
}
} else {
mBlockContent = new ArrayList<Object>();
mBlockContent = new ArrayList<BlockContent>();
}
int mBlockType;
if (getBlockType() != 0) {
Expand Down
25 changes: 14 additions & 11 deletions app/src/main/java/com/dragon/ide/objects/DoubleComplexBlock.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dragon.ide.objects;

import com.dragon.ide.objects.blockcontent.BooleanContent;
import com.dragon.ide.objects.blockcontent.SourceContent;
import com.dragon.ide.utils.CodeReplacer;
import java.io.Serializable;
Expand All @@ -8,7 +9,7 @@
public class DoubleComplexBlock extends ComplexBlock implements Serializable, Cloneable {
public static final long serialVersionUID = 428383841L;
private ArrayList<Block> doubleComplexBlocks;
private ArrayList<Object> complexBlockContent;
private ArrayList<BlockContent> complexBlockContent;

public ArrayList<Block> getDoubleComplexBlocks() {
if (doubleComplexBlocks != null) {
Expand Down Expand Up @@ -87,11 +88,11 @@ public String getCode() {
return new String(blockRawCode);
}

public ArrayList<Object> getComplexBlockContent() {
public ArrayList<BlockContent> getComplexBlockContent() {
return this.complexBlockContent;
}

public void setComplexBlockContent(ArrayList<Object> conplexBlockContent) {
public void setComplexBlockContent(ArrayList<BlockContent> conplexBlockContent) {
this.complexBlockContent = complexBlockContent;
}

Expand All @@ -110,9 +111,9 @@ public DoubleComplexBlock clone() throws CloneNotSupportedException {
} else {
mName = new String("");
}
ArrayList<Object> mBlockContent;
ArrayList<BlockContent> mBlockContent;
if (getBlockContent() != null) {
mBlockContent = new ArrayList<Object>();
mBlockContent = new ArrayList<BlockContent>();
for (int i = 0; i < getBlockContent().size(); ++i) {
if (getBlockContent().get(i) instanceof ComplexBlockContent) {
if (getBlockContent().get(i) instanceof SourceContent) {
Expand All @@ -123,7 +124,7 @@ public DoubleComplexBlock clone() throws CloneNotSupportedException {
}
}
} else {
mBlockContent = new ArrayList<Object>();
mBlockContent = new ArrayList<BlockContent>();
}
int mBlockType;
if (getBlockType() != 0) {
Expand Down Expand Up @@ -173,20 +174,22 @@ public DoubleComplexBlock clone() throws CloneNotSupportedException {
} else {
mDoubleComplexBlocks = new ArrayList<Block>();
}
ArrayList<Object> mComplexBlockContent;
ArrayList<BlockContent> mComplexBlockContent;
if (getComplexBlockContent() != null) {
mComplexBlockContent = new ArrayList<Object>();
mComplexBlockContent = new ArrayList<BlockContent>();
for (int i = 0; i < getComplexBlockContent().size(); ++i) {
if (getComplexBlockContent().get(i) instanceof ComplexBlockContent) {
if (getComplexBlockContent().get(i) instanceof SourceContent) {
mComplexBlockContent.add(((SourceContent) getComplexBlockContent().get(i)).clone());
if (getBlockContent().get(i) instanceof SourceContent) {
mBlockContent.add(((SourceContent) getBlockContent().get(i)).clone());
} else if (getBlockContent().get(i) instanceof BooleanContent) {
mBlockContent.add(((BooleanContent) getBlockContent().get(i)).clone());
}
} else if (getBlockContent().get(i) instanceof BlockContent) {
mComplexBlockContent.add(((BlockContent) getComplexBlockContent().get(i)).clone());
}
}
} else {
mComplexBlockContent = new ArrayList<Object>();
mComplexBlockContent = new ArrayList<BlockContent>();
}
mDoubleComplexBlock.setColor(mColor);
mDoubleComplexBlock.setName(mName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@

public class BooleanContent extends ComplexBlockContent implements Cloneable {
public BooleanContent() {
setAcceptance("boolean");
setAcceptance("");
setSurrounder("");
setText("");
setType(BlockContent.BlockContentType.Boolean);
setSupportCodeEditor(false);
setOnClick(ComplexBlockContent.onClickTypes.noAction);
setValue("");
setType(BlockContent.BlockContentType.InputSourceCode);
setSupportCodeEditor(true);
setOnClick(ComplexBlockContent.onClickTypes.valueEditor);
}

@Override
public String getValue() {
if (super.getValue() != null) {
StringBuilder value = new StringBuilder();
value.append(new String(getValue()));
return value.toString();
}
return "0";
StringBuilder value = new StringBuilder();
value.append(new String(getSurrounder()));
value.append(new String(super.getValue()));
value.append(new String(getSurrounder()));
return value.toString();
}

@Override
Expand All @@ -35,7 +36,7 @@ public BooleanContent clone() throws CloneNotSupportedException {
if (getId() != null) {
mId = new String(getId());
} else {
mId = new String();
mId = new String("");
}
String mSurrounder;
if (getSurrounder() != null) {
Expand All @@ -47,7 +48,7 @@ public BooleanContent clone() throws CloneNotSupportedException {
if (getType() == 0) {
mType = new Integer(getType());
} else {
mType = 0;
mType = BlockContent.BlockContentType.InputSourceCode;
}
String mAcceptance;
if (getAcceptance() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public SourceContent clone() throws CloneNotSupportedException {
if (getId() != null) {
mId = new String(getId());
} else {
mId = new String();
mId = new String("");
}
String mSurrounder;
if (getSurrounder() != null) {
Expand All @@ -48,7 +48,7 @@ public SourceContent clone() throws CloneNotSupportedException {
if (getType() == 0) {
mType = new Integer(getType());
} else {
mType = 0;
mType = BlockContent.BlockContentType.InputSourceCode;
}
String mAcceptance;
if (getAcceptance() != null) {
Expand Down
17 changes: 16 additions & 1 deletion app/src/main/java/com/dragon/ide/utils/BlockContentLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

import android.app.Activity;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.dragon.ide.R;
import com.dragon.ide.listeners.ValueListener;
import com.dragon.ide.objects.BlockContent;
import com.dragon.ide.objects.ComplexBlockContent;
import com.dragon.ide.objects.blockcontent.BooleanContent;
import com.dragon.ide.objects.blockcontent.SourceContent;
import com.dragon.ide.ui.dialogs.eventeditor.ValueEditorDialog;
import java.util.ArrayList;

public class BlockContentLoader {
public static void loadBlockContent(
ArrayList<Object> blockContent,
ArrayList<BlockContent> blockContent,
ViewGroup view,
String color,
String language,
Expand Down Expand Up @@ -53,6 +58,16 @@ public static void loadBlockContent(
new BlockContentLoader()
.new SourceContentClickListener(tvTextContent, sc, activity, language));
}
} else if (blockContent.get(i) instanceof BooleanContent) {
final LinearLayout ll_boolean = new LinearLayout(view.getContext());
ll_boolean.setBackgroundResource(R.drawable.boolean_bg);
Drawable backgroundDrawableBoolean = ll_boolean.getBackground();
backgroundDrawableBoolean.setTint(Color.parseColor("#ffffff"));
backgroundDrawableBoolean.setTintMode(PorterDuff.Mode.SRC_IN);
ll_boolean.setBackground(backgroundDrawableBoolean);
ll_boolean.setAlpha(0.4f);

view.addView(ll_boolean, view.getChildCount());
}
} else if (blockContent.get(i) instanceof BlockContent) {
TextView tvTextContent = new TextView(view.getContext());
Expand Down
Binary file added app/src/main/res/drawable/boolean_bg.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/boolean_bg_patch.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4594e80

Please sign in to comment.