Skip to content

Commit

Permalink
fix in editor, drag drop improvement,shadow movement changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxGalaxy committed Nov 11, 2023
1 parent 7be50cb commit 07db6bb
Show file tree
Hide file tree
Showing 15 changed files with 688 additions and 242 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/dragon/ide/objects/ComplexBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public String getCode() {

// Formatter

String[] lines = getRawCode().split("\n");
String[] lines = blockRawCode.split("\n");
StringBuilder mainCode = new StringBuilder();

for (int i = 0; i < lines.length; ++i) {
Expand Down
188 changes: 167 additions & 21 deletions app/src/main/java/com/dragon/ide/ui/activities/EventEditorActivity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.dragon.ide.ui.activities;

import android.content.ClipData;
import android.os.Build;
import android.widget.RelativeLayout;
import static com.dragon.ide.utils.Environments.PROJECTS;

import android.graphics.Color;
Expand All @@ -12,8 +9,10 @@
import android.view.DragEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import androidx.annotation.MainThread;
import androidx.recyclerview.widget.LinearLayoutManager;
Expand All @@ -30,6 +29,7 @@
import com.dragon.ide.ui.view.BlockDefaultView;
import com.dragon.ide.ui.view.ComplexBlockView;
import com.dragon.ide.utils.BlocksHandler;
import com.dragon.ide.utils.Utils;
import com.dragon.ide.utils.eventeditor.BlocksListLoader;
import editor.tsd.tools.Language;
import java.io.File;
Expand All @@ -56,8 +56,6 @@ public class EventEditorActivity extends BaseActivity implements View.OnDragList
private String language;
private LinearLayout blockShadow;

// private View DraggingView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -107,6 +105,8 @@ public void onClick(View arg0) {
*/

blockShadow = new LinearLayout(this);
blockShadow.setTag("shadow");
// blockShadow.setOnTouchListener(this);
blockShadow.setBackgroundResource(R.drawable.block_default);

Drawable backgroundDrawable = blockShadow.getBackground();
Expand Down Expand Up @@ -293,6 +293,22 @@ public boolean onDrag(View v, DragEvent dragEvent) {
float dropY = dragEvent.getY();

if (blockShadow.getParent() != null) {
if (((ViewGroup) blockShadow.getParent()).getChildCount() > 1) {
if (((ViewGroup) blockShadow.getParent()).getChildAt(0).getTag() != null) {
if (((ViewGroup) blockShadow.getParent()).getChildAt(0).getTag() instanceof String) {
if (((ViewGroup) blockShadow.getParent()).getChildAt(0).getTag().equals("shadow")) {
if (((ViewGroup) blockShadow.getParent()).getId()
!= R.id.relativeBlockListEditorArea) {
if (((ViewGroup) blockShadow.getParent()).getChildAt(1).getLayoutParams() != null) {
((LinearLayout.LayoutParams)
((ViewGroup) blockShadow.getParent()).getChildAt(1).getLayoutParams())
.setMargins(0, 0, 0, 0);
}
}
}
}
}
}
((ViewGroup) blockShadow.getParent()).removeView(blockShadow);
}

Expand All @@ -319,6 +335,19 @@ public boolean onDrag(View v, DragEvent dragEvent) {
((LinearLayout.LayoutParams) blockShadow.getLayoutParams()).width =
LinearLayout.LayoutParams.WRAP_CONTENT;
}
if (v.getId() != R.id.relativeBlockListEditorArea) {
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())
.setMargins(0, -26, 0, 0);
}
}
}
}
}
}
return true;
case DragEvent.ACTION_DRAG_EXITED:
Expand All @@ -343,6 +372,21 @@ public boolean onDrag(View v, DragEvent dragEvent) {
((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) {
((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);
}
}
}
}
}
}
}

Expand All @@ -360,14 +404,30 @@ public boolean onDrag(View v, DragEvent dragEvent) {
}
((LinearLayout) v).addView(blockView, index);
if (blockView.getLayoutParams() != null) {
((LinearLayout.LayoutParams) blockView.getLayoutParams()).setMargins(4, -26, 0, 0);
((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) {
((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 (v instanceof RelativeLayout) {
if (v instanceof FrameLayout) {
if ((dragView instanceof BlockDefaultView)) {
if (((BlockDefaultView) dragView).getBlock().getBlockType()
== Block.BlockType.defaultBlock) {
Expand All @@ -380,12 +440,27 @@ public boolean onDrag(View v, DragEvent dragEvent) {
} catch (CloneNotSupportedException e) {
blockView.setBlock(new Block());
}
((RelativeLayout) v).addView(blockView, index);
((FrameLayout) v).addView(blockView);
if (blockView.getLayoutParams() != null) {
((RelativeLayout.LayoutParams) blockView.getLayoutParams())
.setMargins((int) dropX, (int) dropY, 0, 0);
((RelativeLayout.LayoutParams) blockView.getLayoutParams()).width =
RelativeLayout.LayoutParams.WRAP_CONTENT;
blockView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
blockView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
blockView.requestLayout();
((FrameLayout.LayoutParams) blockView.getLayoutParams())
.setMargins(
(int) dropX
+ binding.relativeBlockListEditorArea.getScrollX()
- ((8
* (blockView.getWidth()
+ blockView.getPaddingLeft()
+ blockView.getPaddingRight()))),
(int) dropY
+ binding.relativeBlockListEditorArea.getScrollY()
- ((2
* (blockView.getHeight()
+ blockView.getPaddingTop()
+ blockView.getPaddingRight()))),
0,
0);
}
}
}
Expand All @@ -402,12 +477,27 @@ public boolean onDrag(View v, DragEvent dragEvent) {
} catch (CloneNotSupportedException e) {
blockView.setComplexBlock(new ComplexBlock());
}
((RelativeLayout) v).addView(blockView, index);
((FrameLayout) v).addView(blockView);
if (blockView.getLayoutParams() != null) {
((RelativeLayout.LayoutParams) blockView.getLayoutParams())
.setMargins((int) dropX, (int) dropY, 0, 0);
((RelativeLayout.LayoutParams) blockView.getLayoutParams()).width =
RelativeLayout.LayoutParams.WRAP_CONTENT;
blockView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
blockView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
blockView.requestLayout();
((FrameLayout.LayoutParams) blockView.getLayoutParams())
.setMargins(
(int) dropX
+ binding.relativeBlockListEditorArea.getScrollX()
- ((8
* (blockView.getWidth()
+ blockView.getPaddingLeft()
+ blockView.getPaddingRight()))),
(int) dropY
+ binding.relativeBlockListEditorArea.getScrollY()
- ((2
* (blockView.getHeight()
+ blockView.getPaddingTop()
+ blockView.getPaddingRight()))),
0,
0);
}
}
}
Expand All @@ -426,7 +516,8 @@ public boolean onDrag(View v, DragEvent dragEvent) {
}

public void loadBlocks(Event e) {
BlocksLoader.loadBlockViews(binding.blockListEditorArea, e.getBlocks(), language, this);
BlocksLoader.loadBlockViews(
binding.getRoot().findViewById(R.id.blockListEditorArea), e.getBlocks(), language, this);
}

public void saveFileList() {
Expand All @@ -450,15 +541,15 @@ public void saveFileList() {
@MainThread
public void onBackPressed() {
if (isLoaded) {
updateBlocks(binding.blockListEditorArea);
updateBlocks(binding.getRoot().findViewById(R.id.blockListEditorArea));
saveFileList();
}
}

@Override
protected void onPause() {
if (isLoaded) {
updateBlocks(binding.blockListEditorArea);
updateBlocks(binding.getRoot().findViewById(R.id.blockListEditorArea));
saveFileList();
}
super.onPause();
Expand All @@ -475,7 +566,7 @@ public boolean onCreateOptionsMenu(Menu arg0) {
@Override
public boolean onOptionsItemSelected(MenuItem arg0) {
if (arg0.getItemId() == R.id.show_source_code) {
updateBlocks(binding.blockListEditorArea);
updateBlocks(binding.getRoot().findViewById(R.id.blockListEditorArea));
if (isLoaded) {
String language = "";
switch (WebFile.getSupportedFileSuffix(file.getFileType())) {
Expand All @@ -502,4 +593,59 @@ public void updateBlocks(ViewGroup view) {
event.setBlocks(BlocksHandler.loadBlocksIntoObject(view));
}
}

private View DraggingView;
/*
@Override
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (view instanceof BlockDefaultView) {
if (blockShadow.getParent() != null) {
((ViewGroup) blockShadow.getParent()).removeView(blockShadow);
}
binding.getRoot().addView(blockShadow);
if (blockShadow.getLayoutParams() != null) {
int x = 0;
int y = 0;
int[] coordinates = {x, y};
view.getLocationInWindow(coordinates);
((FrameLayout.LayoutParams) blockShadow.getLayoutParams())
.setMargins(
(int) event.getX() + coordinates[0] - 200,
(int) event.getY() + coordinates[1] - 200,
0,
0);
blockShadow.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
blockShadow.getLayoutParams().height = -2;
}
}
}
if (event.getAction() == MotionEvent.ACTION_MOVE) {
if (blockShadow.getParent() != null) {
if (blockShadow.getLayoutParams() != null) {
int x = 0;
int y = 0;
int[] coordinates = {x, y};
view.getLocationOnScreen(coordinates);
((FrameLayout.LayoutParams) blockShadow.getLayoutParams())
.setMargins(
(int) event.getX() + coordinates[0] - 200,
(int) event.getY() + coordinates[1] - 200,
0,
0);
blockShadow.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
blockShadow.getLayoutParams().height = -2;
blockShadow.requestLayout();
}
}
}
if (event.getAction() == MotionEvent.ACTION_UP) {
if (blockShadow.getParent() != null) {
((ViewGroup) blockShadow.getParent()).removeView(blockShadow);
}
}
return false; // Return true to consume the event within the view
}*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class MainActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
com.tsd.SketchLogger.startLogging();

// Inflate and get instance of binding.
binding = ActivityMainBinding.inflate(getLayoutInflater());
Expand Down
Loading

0 comments on commit 07db6bb

Please sign in to comment.