-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added add source block (built-in)
- Loading branch information
1 parent
112ba1a
commit a9d2d73
Showing
13 changed files
with
313 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package builtin.blocks; | ||
|
||
import android.graphics.Color; | ||
import com.dragon.ide.objects.Block; | ||
import com.dragon.ide.objects.BlockContent; | ||
import com.dragon.ide.objects.BlocksHolder; | ||
import com.dragon.ide.objects.ComplexBlockContent; | ||
import com.dragon.ide.objects.blockcontent.SourceContent; | ||
import java.util.ArrayList; | ||
|
||
public class BuiltInBlocks { | ||
public static ArrayList<BlocksHolder> getBuiltInBlocksHolder() { | ||
ArrayList<BlocksHolder> blocksHolder = new ArrayList<BlocksHolder>(); | ||
BlocksHolder holder1 = new BlocksHolder(); | ||
holder1.setColor("#009900"); | ||
holder1.setName("Operators"); | ||
|
||
ArrayList<Block> blockList = new ArrayList<Block>(); | ||
|
||
Block blockInHolder1 = new Block(); | ||
blockInHolder1.setColor("#009900"); | ||
blockInHolder1.setBlockType(Block.BlockType.defaultBlock); | ||
blockInHolder1.setName("addSource"); | ||
blockInHolder1.setRawCode("%%%% DragonIDE param1 %%%%"); | ||
|
||
ArrayList<Object> block1ContentList = new ArrayList<Object>(); | ||
|
||
BlockContent block1Content1 = new BlockContent(); | ||
block1Content1.setText("add source"); | ||
block1ContentList.add(block1Content1); | ||
|
||
SourceContent block1Content2 = new SourceContent(); | ||
block1Content2.setId("param1"); | ||
block1ContentList.add(block1Content2); | ||
|
||
blockInHolder1.setBlockContent(block1ContentList); | ||
|
||
blockList.add(blockInHolder1); | ||
|
||
holder1.setBlocks(blockList); | ||
|
||
blocksHolder.add(holder1); | ||
|
||
return blocksHolder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ public class Block implements Serializable { | |
private ArrayList<Object> blockContent; | ||
private int BlockType; | ||
private String rawCode; | ||
private String replacer; | ||
private String returns; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
CyberGlitch01
Author
Collaborator
|
||
|
||
public String getColor() { | ||
if (this.color != null) { | ||
|
@@ -49,8 +49,7 @@ public String getCode() { | |
if (getBlockContent().get(i) instanceof ComplexBlockContent) { | ||
blockRawCode = | ||
blockRawCode.replaceAll( | ||
CodeReplacer.getReplacer( | ||
((ComplexBlockContent) getBlockContent().get(i)).getId()), | ||
CodeReplacer.getReplacer(((ComplexBlockContent) getBlockContent().get(i)).getId()), | ||
((ComplexBlockContent) getBlockContent().get(i)).getValue()); | ||
} | ||
} | ||
|
@@ -67,17 +66,9 @@ public void setRawCode(String rawCode) { | |
} | ||
|
||
public final class BlockType { | ||
public final int defaultBlock = 0; | ||
public final int complexBlock = 1; | ||
public final int doubleComplexBlock = 2; | ||
} | ||
|
||
public String getReplacer() { | ||
return this.replacer; | ||
} | ||
|
||
public void setReplacer(String replacer) { | ||
this.replacer = replacer; | ||
public static final int defaultBlock = 0; | ||
public static final int complexBlock = 1; | ||
public static final int doubleComplexBlock = 2; | ||
} | ||
|
||
public ArrayList<Object> getBlockContent() { | ||
|
@@ -87,4 +78,15 @@ public ArrayList<Object> getBlockContent() { | |
public void setBlockContent(ArrayList<Object> blockContent) { | ||
this.blockContent = blockContent; | ||
} | ||
|
||
public String getReturns() { | ||
if (returns != null) { | ||
return this.returns; | ||
} | ||
return ""; | ||
} | ||
|
||
public void setReturns(String returns) { | ||
this.returns = returns; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/complexblockcontent/BooleanContent.java → .../objects/blockcontent/BooleanContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ts/complexblockcontent/NumberContent.java → ...e/objects/blockcontent/NumberContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ts/complexblockcontent/SourceContent.java → ...e/objects/blockcontent/SourceContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ts/complexblockcontent/StringContent.java → ...e/objects/blockcontent/StringContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/src/main/java/com/dragon/ide/ui/adapters/BlocksHolderEventEditorListItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.dragon.ide.ui.adapters; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.graphics.Color; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
import com.dragon.ide.R; | ||
import com.dragon.ide.databinding.LayoutBlocksHolderListItemBinding; | ||
import com.dragon.ide.databinding.LayoutEventBlocksHolderListItemBinding; | ||
import com.dragon.ide.objects.BlocksHolder; | ||
import com.dragon.ide.ui.activities.BlockManagerActivity; | ||
import java.util.ArrayList; | ||
|
||
public class BlocksHolderEventEditorListItem extends RecyclerView.Adapter<BlocksHolderEventEditorListItem.ViewHolder> { | ||
|
||
public ArrayList<BlocksHolder> list; | ||
public Activity activity; | ||
|
||
public BlocksHolderEventEditorListItem(ArrayList<BlocksHolder> _arr, Activity activity) { | ||
list = _arr; | ||
this.activity = activity; | ||
} | ||
|
||
@Override | ||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
LayoutEventBlocksHolderListItemBinding item = | ||
LayoutEventBlocksHolderListItemBinding.inflate(activity.getLayoutInflater()); | ||
View _v = item.getRoot(); | ||
RecyclerView.LayoutParams _lp = | ||
new RecyclerView.LayoutParams( | ||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | ||
_v.setLayoutParams(_lp); | ||
return new ViewHolder(_v); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(ViewHolder _holder, int _position) { | ||
LayoutEventBlocksHolderListItemBinding binding = | ||
LayoutEventBlocksHolderListItemBinding.bind(_holder.itemView); | ||
binding.holderName.setText(list.get(_position).getName()); | ||
int blocksCount = list.get(_position).getBlocks().size(); | ||
binding.color.setBackgroundColor(Color.parseColor(list.get(_position).getColor())); | ||
binding | ||
.getRoot() | ||
.setOnClickListener( | ||
(view) -> { | ||
|
||
}); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return list.size(); | ||
} | ||
|
||
public class ViewHolder extends RecyclerView.ViewHolder { | ||
public ViewHolder(View v) { | ||
super(v); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/dragon/ide/ui/view/BlockDefaultView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.dragon.ide.ui.view; | ||
|
||
import android.content.Context; | ||
import android.graphics.Color; | ||
import android.graphics.PorterDuff; | ||
import android.graphics.drawable.Drawable; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
import com.dragon.ide.R; | ||
import com.dragon.ide.objects.Block; | ||
import com.dragon.ide.objects.BlockContent; | ||
import com.dragon.ide.objects.ComplexBlock; | ||
import com.dragon.ide.objects.ComplexBlockContent; | ||
import com.dragon.ide.objects.DoubleComplexBlock; | ||
import com.dragon.ide.objects.blockcontent.SourceContent; | ||
|
||
public class BlockDefaultView extends LinearLayout { | ||
public String returns; | ||
|
||
public BlockDefaultView(Context context) { | ||
super(context); | ||
setOrientation(LinearLayout.HORIZONTAL); | ||
} | ||
|
||
public void setBlock(Block block) { | ||
returns = block.getReturns(); | ||
|
||
if (!(block instanceof DoubleComplexBlock) && !(block instanceof ComplexBlock)) { | ||
if (block instanceof Block) { | ||
if (block.getBlockType() == Block.BlockType.defaultBlock) { | ||
setBackgroundResource(R.drawable.block_default); | ||
|
||
Drawable backgroundDrawable = getBackground(); | ||
backgroundDrawable.setTint(Color.parseColor(block.getColor())); | ||
backgroundDrawable.setTintMode(PorterDuff.Mode.SRC_IN); | ||
setBackground(backgroundDrawable); | ||
} | ||
} | ||
} | ||
for (int i = 0; i < block.getBlockContent().size(); ++i) { | ||
if (block.getBlockContent().get(i) instanceof ComplexBlockContent) { | ||
if (block.getBlockContent().get(i) instanceof SourceContent) { | ||
LinearLayout ll_source = new LinearLayout(getContext()); | ||
ll_source.setPadding(2, 2, 2, 2); | ||
setBackgroundColor(Color.WHITE); | ||
TextView tvTextContent = new TextView(getContext()); | ||
tvTextContent.setText(((SourceContent) block.getBlockContent().get(i)).getValue()); | ||
ll_source.addView(tvTextContent, getChildCount()); | ||
addView(ll_source, getChildCount()); | ||
} | ||
|
||
if (block.getBlockContent().get(i) instanceof SourceContent) { | ||
LinearLayout ll_source = new LinearLayout(getContext()); | ||
ll_source.setPadding(2, 2, 2, 2); | ||
setBackgroundColor(Color.WHITE); | ||
TextView tvTextContent = new TextView(getContext()); | ||
tvTextContent.setText(((SourceContent) block.getBlockContent().get(i)).getValue()); | ||
ll_source.addView(tvTextContent, getChildCount()); | ||
addView(ll_source, getChildCount()); | ||
} | ||
} else if (block.getBlockContent().get(i) instanceof BlockContent) { | ||
TextView tvTextContent = new TextView(getContext()); | ||
tvTextContent.setText(((BlockContent) block.getBlockContent().get(i)).getText()); | ||
addView(tvTextContent, getChildCount()); | ||
} | ||
} | ||
} | ||
|
||
public String getReturns() { | ||
if (returns != null) { | ||
return this.returns; | ||
} | ||
return ""; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/com/dragon/ide/utils/eventeditor/BlocksListLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.dragon.ide.utils.eventeditor; | ||
|
||
import builtin.blocks.BuiltInBlocks; | ||
import static com.dragon.ide.utils.Environments.BLOCKS; | ||
|
||
import android.app.Activity; | ||
import com.dragon.ide.objects.BlocksHolder; | ||
import java.io.FileInputStream; | ||
import java.io.ObjectInputStream; | ||
import java.util.ArrayList; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.Executors; | ||
|
||
public class BlocksListLoader { | ||
|
||
public void loadBlocks(Activity activity, Progress progress) { | ||
Executor executor = Executors.newSingleThreadExecutor(); | ||
executor.execute( | ||
() -> { | ||
ArrayList<BlocksHolder> blocksHolder = new ArrayList<BlocksHolder>(); | ||
|
||
ArrayList<BlocksHolder> builtInBlock = BuiltInBlocks.getBuiltInBlocksHolder(); | ||
|
||
for (int i = 0; i < builtInBlock.size(); ++i) { | ||
blocksHolder.add(builtInBlock.get(i)); | ||
} | ||
|
||
if (BLOCKS.exists()) { | ||
try { | ||
FileInputStream fis = new FileInputStream(BLOCKS); | ||
ObjectInputStream ois = new ObjectInputStream(fis); | ||
Object obj = ois.readObject(); | ||
if (obj instanceof ArrayList) { | ||
for (int i = 0; i < ((ArrayList<BlocksHolder>) obj).size(); ++i) { | ||
blocksHolder.add(((ArrayList<BlocksHolder>) obj).get(i)); | ||
} | ||
} else { | ||
} | ||
fis.close(); | ||
ois.close(); | ||
} catch (Exception e) { | ||
} | ||
} else { | ||
} | ||
activity.runOnUiThread( | ||
() -> { | ||
progress.onCompleteLoading(blocksHolder); | ||
}); | ||
}); | ||
} | ||
|
||
public interface Progress { | ||
void onCompleteLoading(ArrayList<BlocksHolder> holder); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Everything is good but this part may break block code generator system.
Idk what is your logic behind this