From be914dc9075a26d30b223370a44c87b867c22317 Mon Sep 17 00:00:00 2001 From: MUQING <1966944300@qq.com> Date: Mon, 27 Nov 2023 13:03:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=99=E4=BA=86=E4=B8=80=E4=B8=AA=E7=AE=80?= =?UTF-8?q?=E5=8D=95=E7=9A=84=E8=BF=9E=E6=8E=A5=E9=9D=99=E6=80=81=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../executionHistory/executionHistory.lock | Bin 17 -> 17 bytes .gradle/8.0/fileHashes/fileHashes.bin | Bin 127733 -> 131833 bytes .gradle/8.0/fileHashes/fileHashes.lock | Bin 17 -> 17 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .../com/muqingedit/ConnectionManager.java | 48 +++++++ .../java/com/muqingedit/activity/Edit.java | 43 +++++-- app/src/main/java/com/muqingedit/fanjian.java | 121 ++++++++++++------ app/src/main/java/com/muqingedit/xian.java | 9 +- app/src/main/res/layout/new_fangjian.xml | 43 +++++++ local.properties | 2 +- 10 files changed, 208 insertions(+), 58 deletions(-) create mode 100644 app/src/main/java/com/muqingedit/ConnectionManager.java create mode 100644 app/src/main/res/layout/new_fangjian.xml diff --git a/.gradle/8.0/executionHistory/executionHistory.lock b/.gradle/8.0/executionHistory/executionHistory.lock index 2e7a9ef7916ce5d823e7d9a3df45995692bce600..a5cc10d329a4973bbe2c2054fe35d38e0eb3de84 100644 GIT binary patch literal 17 VcmZR6yJ^m`1vkAnF@OQjLI6h81}Fdk literal 17 VcmZR6yJ^m`1vkAnF@OQb0RTqp215V< diff --git a/.gradle/8.0/fileHashes/fileHashes.bin b/.gradle/8.0/fileHashes/fileHashes.bin index 89108dd51469c3b05caa90a5572f68b0574a051d..4cc16ed6fac3fe26ff22255500f83a8a89feab15 100644 GIT binary patch delta 8244 zcma)B2|QI@*T4JXhH&Vby28B~t|9YKii{sFUa z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3;f zKqNJK8MOcRl^SW*M{Ikd-2=(*?ijq*?12KUDl09Av{`f&oPBlc-r&)S?-EoNe?ny# zpPXrhKXguQd@X=+tHqima2tG*qn)Ldd#g@RWlhw7@iS$abI!NcSBe8n8`M z6qefrDE$E#3@_~wkkz@M00293(_v7-Mv-}75m}c9Y5@8CIGDsHoeS|CHjJ%8rbVC- zn!6gIcST?~Jnb5b1g8N$3%PY7=QAJ_P91-pJa`s#a^QN8P}1xIumEJ>MNkTerIY;u z`S&Fd%_d%Y`2%#c1QVor8>6tR;3M0#Sz$R$Kw?4Lh2o&-)7fU4`dOLY^_m*>1>H=% zw!6^r(pj*H>U_4G+U-;5#+UP|ZISJj%#=L;Fpt6uyr&F0Wj>7-I<99e9UQ`r9&M?y7lnENc8z!uI? zUM||*x3I1|gP<#?MnL8c20kcZpo2L*A6vbRB=N#K%YJuDFHTlDKsBwvRBHY8@uhzA zH(oi0tvyq8P4rcZdl)($tATVkw~j`UEs`G3ll=?oobS@7b}Zn8%Ay9%c#HQ~xa{29 zz&{iRLtH-U$y04Ms(24ED2?}Mw>c1?Q=NcMYPA6)Fx@jLHE*b>Wb5eO`iJrF198Eo zs$wQ%ps@&_7JuBH5v(SW$L;$c^3{^RIM+AQJrN7J56fnW#7}m8`}(HpX}s~UV9$%a zp5GT$nP`#l{U~98?zV%`c>l7*bp4gSk&Q~sv%hH+U{;a2e`4KVjPNX7MmYQEKpkz5 zX3QL{TRdvpc$2RhYld88lpkacazJcN9WH(rPd+m@dh4XYQJQ;ymYZE?wbpt&0~pA70su1`1Y!UH literal 17 VcmZSX2>ZE?wbpt&0~m-F001*I1cCqn diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index a5fb0f6f68bde4c2956f8189384f0e5f7c489835..3d428fbbffb85db39a9b45e9055ef1558b8210a5 100644 GIT binary patch literal 17 UcmZQR{+!=6w@BEC0Sx5%0V`hvSO5S3 literal 17 VcmZQR{+!=6w@BEC0SqKQ0RSvC1T+8u diff --git a/app/src/main/java/com/muqingedit/ConnectionManager.java b/app/src/main/java/com/muqingedit/ConnectionManager.java new file mode 100644 index 0000000..3de91b5 --- /dev/null +++ b/app/src/main/java/com/muqingedit/ConnectionManager.java @@ -0,0 +1,48 @@ +package com.muqingedit; + +import java.util.HashSet; +import java.util.Set; + +/** + * ConnectionManager 类用于管理视图之间的连接关系。 + */ +public class ConnectionManager { + private static Set connections = new HashSet<>(); + /** + * ConnectionManager 构造函数,初始化连接集合。 + */ + /** + * 添加视图之间的连接。 + * + * @param view1Id 第一个视图的ID + * @param view2Id 第二个视图的ID + */ + public static void addConnection(String view1Id, String view2Id) { + String connection = getConnectionKey(view1Id, view2Id); + connections.add(connection); + } + + /** + * 检查两个视图是否已连接。 + * + * @param view1Id 第一个视图的ID + * @param view2Id 第二个视图的ID + * @return 如果两个视图已连接,则返回 true;否则返回 false。 + */ + public static boolean isConnected(String view1Id, String view2Id) { + String connection = getConnectionKey(view1Id, view2Id); + return connections.contains(connection); + } + + /** + * 获取视图连接的唯一标识。 + * + * @param view1Id 第一个视图的ID + * @param view2Id 第二个视图的ID + * @return 视图连接的唯一标识 + */ + private static String getConnectionKey(String view1Id, String view2Id) { + // 这里使用视图 ID 作为连接信息的关键 + return view1Id + "-" + view2Id; + } +} diff --git a/app/src/main/java/com/muqingedit/activity/Edit.java b/app/src/main/java/com/muqingedit/activity/Edit.java index b3369be..09a5fa3 100644 --- a/app/src/main/java/com/muqingedit/activity/Edit.java +++ b/app/src/main/java/com/muqingedit/activity/Edit.java @@ -1,34 +1,49 @@ package com.muqingedit.activity; import android.annotation.SuppressLint; -import android.content.Context; import android.os.Bundle; -import android.view.View; +import android.view.ViewTreeObserver; import android.widget.FrameLayout; import androidx.annotation.Nullable; +import com.muqingedit.ConnectionManager; import com.muqingedit.R; import com.muqingedit.fanjian; -import com.muqingedit.xian; +import com.muqingedit.gj; + +import java.util.ArrayList; +import java.util.List; public class Edit extends ActivityFragment { - @SuppressLint("StaticFieldLeak") - public FrameLayout frameLayout; - + public FrameLayout frameLayout;//后续需要添加fragment的移动和缩放 + public static List list_fanjian = new ArrayList<>(); + @SuppressLint("ClickableViewAccessibility") @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.edit); frameLayout = findViewById(R.id.view); //绘制一个房间 - findViewById(R.id.button).setOnClickListener(view -> { - fanjian button = new fanjian(Edit.this).setPaletteView(frameLayout) - .setLayoutParams(260, 250) - .setXY(200, 100); - frameLayout.addView(button); + findViewById(R.id.button).setOnClickListener(view -> new fanjian(frameLayout)); + frameLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + // 在布局完成之后获取 FrameLayout 的高度 + int height = frameLayout.getHeight(); + int width = frameLayout.getWidth(); + + fanjian main = new fanjian(frameLayout, "main");//设置主房间 + int viewWidth = main.getMeasuredWidth(); + int viewHeight = main.getMeasuredHeight(); + float x = (width - viewWidth) / 2.0f; + float y = (height - viewHeight) / 2.0f; + gj.sc(height + ":" + y); + main.setXY((int) x, (int) y); + frameLayout.addView(main); + // 如果只需要获取一次高度,可以在获取之后移除监听器 + frameLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } }); } - - -} +} \ No newline at end of file diff --git a/app/src/main/java/com/muqingedit/fanjian.java b/app/src/main/java/com/muqingedit/fanjian.java index 637484a..a30f967 100644 --- a/app/src/main/java/com/muqingedit/fanjian.java +++ b/app/src/main/java/com/muqingedit/fanjian.java @@ -5,38 +5,61 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.text.TextUtils; import android.view.GestureDetector; import android.view.Gravity; +import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; import android.widget.FrameLayout; import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.muqingedit.activity.Edit; public class fanjian extends FrameLayout { + private String id; + private int X, Y; + public FrameLayout frameLayout; - private FrameLayout paletteView; - - /** - * 为其设置画板视图 - * - * @param paletteView - */ - public fanjian setPaletteView(FrameLayout paletteView) { - this.paletteView = paletteView; - return this; + public fanjian(FrameLayout context, String id) { + super(context.getContext()); + this.frameLayout = context; + init(); + setId(id.hashCode()); + setLayoutParams(300, 300); } - public static int id = 0; - - private int X, Y; - - public fanjian(Context context) { - super(context); - setId(id++); + public fanjian(FrameLayout context) { + super(context.getContext()); + this.frameLayout = context; + MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(this.getContext()); + dialogBuilder.setTitle("创建房间"); + View inflate = LayoutInflater.from(getContext()).inflate(R.layout.new_fangjian, null); + EditText edit_id = inflate.findViewById(R.id.edit_id); + Button end = inflate.findViewById(R.id.button_end); + Button start = inflate.findViewById(R.id.button_start); + dialogBuilder.setView(inflate); + AlertDialog show = dialogBuilder.show(); + end.setOnClickListener(view -> show.dismiss()); + start.setOnClickListener(view -> { + String id = edit_id.getText().toString(); + if (TextUtils.isEmpty(id)) { + return; + } + fanjian.this.id = id; + setId(id.hashCode()); + Edit.list_fanjian.add(fanjian.this); + setLayoutParams(300, 300); + setXY(0, 0); + frameLayout.addView(fanjian.this); + show.dismiss(); + }); init(); } @@ -78,21 +101,41 @@ public class fanjian extends FrameLayout { fanjian.this.getLocationOnScreen(location); csx = (int) fanjian.this.getX() + fanjian.this.getWidth() / 2; csy = (int) fanjian.this.getY() + fanjian.this.getHeight() / 2; - xian = new xian(getContext()).createNewLine(paletteView, csx, csy); - return true; + xian = new xian(fanjian.this.frameLayout).createNewLine(csx, csy); + break; case MotionEvent.ACTION_MOVE: //绘制线 xian.updateCurrentLine(csx + ax, csy + ay); // xian.updateCurrentLine(event.getRawX()-ax, event.getRawY()-ay); - return true; + break; case MotionEvent.ACTION_UP: - //删除线 + //删除线 判断是否连接房间 如果连接则不删除不连接则删除 + int size = Edit.list_fanjian.size(); + //只要大于1个房间才会进行判断操作 + if (size > 1) { + for (int i = 0; i < size; i++) { + fanjian aa = Edit.list_fanjian.get(i); + if (aa == fanjian.this) { + continue; + } + boolean ab = ConnectionManager.isConnected(fanjian.this.Id(), aa.Id()); + if (ab) { + break; + } + boolean a = csx + ax > aa.getX() && csx + ax < aa.getX() + 300; + boolean b = csy + ay > aa.getY() && csy + ay < aa.getY() + 300; + if (a && b) { + ConnectionManager.addConnection(fanjian.this.Id(), aa.Id()); + return true; + } + } + } xian.clearCurrentLine(); - paletteView.removeView(xian); + frameLayout.removeView(xian); xian = null; - return true; + break; } - return super.onTouchEvent(event); + return true; } } @@ -115,12 +158,9 @@ public class fanjian extends FrameLayout { @Override public boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) { - if (Long) { - } else { - Y = (int) (e2.getY() - e1.getY()); - X = (int) (e2.getX() - e1.getX()); - animate().xBy(X).yBy(Y).setDuration(0).start(); - } + Y = (int) (e2.getY() - e1.getY()); + X = (int) (e2.getX() - e1.getX()); + animate().xBy(X).yBy(Y).setDuration(0).start(); return true; } }); @@ -144,17 +184,20 @@ public class fanjian extends FrameLayout { return this; } -/* - @Override - public float getX() { - return this.X; - } + /* + @Override + public float getX() { + return this.X; + } - @Override - public float getY() { - return this.Y; + @Override + public float getY() { + return this.Y; + } + */ + public String Id() { + return id; } -*/ public String getXY() { return X + ":" + Y; diff --git a/app/src/main/java/com/muqingedit/xian.java b/app/src/main/java/com/muqingedit/xian.java index 2b69c11..d989a7a 100644 --- a/app/src/main/java/com/muqingedit/xian.java +++ b/app/src/main/java/com/muqingedit/xian.java @@ -17,9 +17,10 @@ public class xian extends View { private Paint linePaint; private float currentX, currentY; private float startX, startY; - - public xian(Context context) { - super(context); + FrameLayout frameLayout; + public xian(FrameLayout context) { + super(context.getContext()); + this.frameLayout = context; init(); } @@ -33,7 +34,7 @@ public class xian extends View { linePaint.setStrokeWidth(5f); } - public xian createNewLine(FrameLayout frameLayout, float x, float y) { + public xian createNewLine(float x, float y) { startX = x; startY = y; currentX = x; diff --git a/app/src/main/res/layout/new_fangjian.xml b/app/src/main/res/layout/new_fangjian.xml new file mode 100644 index 0000000..da79be6 --- /dev/null +++ b/app/src/main/res/layout/new_fangjian.xml @@ -0,0 +1,43 @@ + + + + + + + + + + +