diff --git a/app/src/main/java/builtin/blocks/BuiltInBlocks.java b/app/src/main/java/builtin/blocks/BuiltInBlocks.java index 98c3f0f..cf8d732 100644 --- a/app/src/main/java/builtin/blocks/BuiltInBlocks.java +++ b/app/src/main/java/builtin/blocks/BuiltInBlocks.java @@ -86,6 +86,7 @@ public static ArrayList getBuiltInBlocksHolder() { blockInHolder4.setBlockType(Block.BlockType.returnWithTypeBoolean); blockInHolder4.setName("true"); blockInHolder4.setRawCode("true"); + blockInHolder4.setReturns("boolean"); ArrayList block4ContentList = new ArrayList(); diff --git a/app/src/main/java/com/dragon/ide/ui/activities/EventEditorActivity.java b/app/src/main/java/com/dragon/ide/ui/activities/EventEditorActivity.java index 9296f4b..80ffb80 100644 --- a/app/src/main/java/com/dragon/ide/ui/activities/EventEditorActivity.java +++ b/app/src/main/java/com/dragon/ide/ui/activities/EventEditorActivity.java @@ -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) { @@ -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); @@ -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; } } } diff --git a/app/src/main/java/com/dragon/ide/ui/adapters/BlockListAdapter.java b/app/src/main/java/com/dragon/ide/ui/adapters/BlockListAdapter.java index f7a446e..fd30044 100644 --- a/app/src/main/java/com/dragon/ide/ui/adapters/BlockListAdapter.java +++ b/app/src/main/java/com/dragon/ide/ui/adapters/BlockListAdapter.java @@ -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, @@ -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, diff --git a/app/src/main/java/com/dragon/ide/utils/BlockContentLoader.java b/app/src/main/java/com/dragon/ide/utils/BlockContentLoader.java index b44088a..6ee4c90 100644 --- a/app/src/main/java/com/dragon/ide/utils/BlockContentLoader.java +++ b/app/src/main/java/com/dragon/ide/utils/BlockContentLoader.java @@ -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) {