diff --git a/.gradle/8.0/executionHistory/executionHistory.lock b/.gradle/8.0/executionHistory/executionHistory.lock index a5cc10d..3fc2f3e 100644 Binary files a/.gradle/8.0/executionHistory/executionHistory.lock and b/.gradle/8.0/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.0/fileHashes/fileHashes.bin b/.gradle/8.0/fileHashes/fileHashes.bin index 4cc16ed..5e86e7e 100644 Binary files a/.gradle/8.0/fileHashes/fileHashes.bin and b/.gradle/8.0/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.0/fileHashes/fileHashes.lock b/.gradle/8.0/fileHashes/fileHashes.lock index 45dcd58..967eb5d 100644 Binary files a/.gradle/8.0/fileHashes/fileHashes.lock and b/.gradle/8.0/fileHashes/fileHashes.lock differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 3d428fb..24d7933 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/app/src/main/java/com/muqingedit/activity/ActivityFragment.java b/app/src/main/java/com/muqingedit/activity/ActivityFragment.java index 84b9022..176e210 100644 --- a/app/src/main/java/com/muqingedit/activity/ActivityFragment.java +++ b/app/src/main/java/com/muqingedit/activity/ActivityFragment.java @@ -4,6 +4,9 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import com.muqingedit.R; + +import java.util.Objects; + public class ActivityFragment extends AppCompatActivity { @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { @@ -14,7 +17,7 @@ public class ActivityFragment extends AppCompatActivity { } public void setToolbar() { setSupportActionBar(findViewById(R.id.toolbar)); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); + Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); } @Override diff --git a/app/src/main/java/com/muqingedit/activity/Edit.java b/app/src/main/java/com/muqingedit/activity/Edit.java index 09a5fa3..055b4b9 100644 --- a/app/src/main/java/com/muqingedit/activity/Edit.java +++ b/app/src/main/java/com/muqingedit/activity/Edit.java @@ -2,48 +2,71 @@ package com.muqingedit.activity; import android.annotation.SuppressLint; import android.os.Bundle; -import android.view.ViewTreeObserver; +import android.view.Menu; +import android.view.MenuItem; import android.widget.FrameLayout; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; -import com.muqingedit.ConnectionManager; +import com.google.android.material.bottomappbar.BottomAppBar; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.muqingedit.R; import com.muqingedit.fanjian; -import com.muqingedit.gj; import java.util.ArrayList; import java.util.List; public class Edit extends ActivityFragment { public FrameLayout frameLayout;//后续需要添加fragment的移动和缩放 - public static List list_fanjian = new ArrayList<>(); + //收集所有的房间 + public static List list_fanjian; + public static BottomAppBar bottomAppBar; + + @SuppressLint("StaticFieldLeak") + public static fanjian fanjian;//选中的房间 + @SuppressLint("ClickableViewAccessibility") @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.edit); + list_fanjian = new ArrayList<>(); frameLayout = findViewById(R.id.view); //绘制一个房间 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); - } - }); + Connection(); + fanjian main = new fanjian(frameLayout, "main");//设置主房间 } + + private void Connection() { + bottomAppBar = findViewById(R.id.bottomAppBar); + bottomAppBar.setOnMenuItemClickListener(item -> { + int id = item.getItemId(); + if (id == R.id.Connection) { + if (fanjian != null) { + new com.muqingedit.list_AlertDialog(this); + } + } + return false; + }); + bottomAppBar.performHide(false); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.edit_toolbar,menu); + return super.onCreateOptionsMenu(menu); + } + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + int itemId = item.getItemId(); + if (itemId == R.id.Save) { + //保存 + } + return super.onOptionsItemSelected(item); + } + + } \ 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 a30f967..23f8534 100644 --- a/app/src/main/java/com/muqingedit/fanjian.java +++ b/app/src/main/java/com/muqingedit/fanjian.java @@ -1,13 +1,10 @@ package com.muqingedit; import android.annotation.SuppressLint; -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; @@ -15,6 +12,8 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.FrameLayout; +import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; @@ -30,9 +29,7 @@ public class fanjian extends FrameLayout { public fanjian(FrameLayout context, String id) { super(context.getContext()); this.frameLayout = context; - init(); - setId(id.hashCode()); - setLayoutParams(300, 300); + init(id); } public fanjian(FrameLayout context) { @@ -49,20 +46,131 @@ public class fanjian extends FrameLayout { end.setOnClickListener(view -> show.dismiss()); start.setOnClickListener(view -> { String id = edit_id.getText().toString(); + for (int i = 0; i < Edit.list_fanjian.size(); i++) { + if (Edit.list_fanjian.get(i).Id().equals(id)) { + Toast.makeText(this.getContext(), "已经存在该房间", Toast.LENGTH_SHORT).show(); + return; + } + } 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); + init(id); show.dismiss(); }); - init(); } + + private GestureDetector gestureDetector; + private boolean Long = false; + + public TextView textView; + private void init(String id) { + // 设置背景颜色为红色 + setBackgroundColor(Color.RED); + // 设置视图的尺寸为100x100像素 + setLayoutParams(300, 300); + Id(id); + frameLayout.addView(this); + Edit.list_fanjian.add(this); + // 进行初始化操作,例如设置背景颜色、文字等 + gestureDetector = new GestureDetector(getContext(), + new GestureDetector.SimpleOnGestureListener() { + @Override + public boolean onDoubleTap(@NonNull MotionEvent e) { + if (Edit.fanjian != null) { + Edit.fanjian.setBackgroundColor(Color.RED); + } + if (Edit.fanjian == fanjian.this) { + Edit.fanjian = null; + Edit.bottomAppBar.performHide(); + return super.onDoubleTap(e); + } + Edit.bottomAppBar.performShow(); + Edit.fanjian = fanjian.this; + fanjian.this.setBackgroundColor(Color.MAGENTA); + return super.onDoubleTap(e); + } + + @Override + public void onLongPress(@NonNull MotionEvent e) { + Long = !Long; + // 处理长按事件 + } + + @Override + public boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) { + Y = (int) (e2.getY() - e1.getY()); + X = (int) (e2.getX() - e1.getX()); + animate().xBy(X).yBy(Y).setDuration(0).start(); + return true; + } + }); + + textView = new TextView(this.getContext()); + textView.setText(id); + addView(textView); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + gestureDetector.onTouchEvent(event); + return true; + } + + @SuppressLint("DrawAllocation") + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + } + + public fanjian setLayoutParams(int a, int b) { + setLayoutParams(new ViewGroup.LayoutParams(a, b)); + return this; + } + + /* + @Override + public float getX() { + return this.X; + } + + @Override + public float getY() { + return this.Y; + } + */ + public String Id() { + return id; + } + + public String getXY() { + return X + ":" + Y; + } + + public fanjian setXY(int a, int b) { + setX(a); + setY(b); + return this; + } + + @Override + public void setX(float x) { + super.setX(x); + X = (int) x; + } + + @Override + public void setY(float y) { + super.setY(y); + Y = (int) y; + } + + public void Id(String id) { + this.id = id; + setId(id.hashCode()); + } + /*暂时弃用的一个自定义控件 private class dian extends View { xian xian; @@ -139,87 +247,5 @@ public class fanjian extends FrameLayout { } } - - private GestureDetector gestureDetector; - private boolean Long = false; - - private void init() { - // 设置背景颜色为红色 - setBackgroundColor(Color.RED); - // 设置视图的尺寸为100x100像素 - setLayoutParams(new ViewGroup.LayoutParams(0, 0)); - // 进行初始化操作,例如设置背景颜色、文字等 - gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() { - @Override - public void onLongPress(@NonNull MotionEvent e) { - Long = !Long; - // 处理长按事件 - } - - @Override - public boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) { - Y = (int) (e2.getY() - e1.getY()); - X = (int) (e2.getX() - e1.getX()); - animate().xBy(X).yBy(Y).setDuration(0).start(); - return true; - } - }); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - gestureDetector.onTouchEvent(event); - return true; - } - - @SuppressLint("DrawAllocation") - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - // 在此处进行自定义的绘制操作,例如绘制图形、文本等 - } - - public fanjian setLayoutParams(int a, int b) { - setLayoutParams(new ViewGroup.LayoutParams(a, b)); - return this; - } - - /* - @Override - public float getX() { - return this.X; - } - - @Override - public float getY() { - return this.Y; - } - */ - public String Id() { - return id; - } - - public String getXY() { - return X + ":" + Y; - } - - public fanjian setXY(int a, int b) { - setX(a); - setY(b); - addView(new dian(getContext())); - return this; - } - - @Override - public void setX(float x) { - super.setX(x); - X = (int) x; - } - - @Override - public void setY(float y) { - super.setY(y); - Y = (int) y; - } - +*/ } diff --git a/app/src/main/java/com/muqingedit/list_AlertDialog.java b/app/src/main/java/com/muqingedit/list_AlertDialog.java new file mode 100644 index 0000000..07fd34c --- /dev/null +++ b/app/src/main/java/com/muqingedit/list_AlertDialog.java @@ -0,0 +1,88 @@ +package com.muqingedit; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.muqingedit.activity.Edit; + +import java.util.ArrayList; +import java.util.List; + +public class list_AlertDialog extends MaterialAlertDialogBuilder { + RecyclerView list; + AlertDialog alertDialog; + public list_AlertDialog(@NonNull Context context) { + super(context); + list = new RecyclerView(context); + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context); + list.setLayoutManager(linearLayoutManager); + list.setAdapter(new adapter(Edit.list_fanjian)); + setView(list); + show(); + } + + @Override + public AlertDialog show() { + this.alertDialog = super.show(); + return alertDialog; + } + public void dismiss() { + alertDialog.dismiss(); + } + + class adapter extends RecyclerView.Adapter { + + private final List list=new ArrayList<>(); + + public adapter(List list) { + this.list.addAll(list); + this.list.remove(Edit.fanjian); + } + @NonNull + @Override + public Vh onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View inflate = View.inflate(list_AlertDialog.this.getContext(), + R.layout.list_fangjian, null); + ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + inflate.setLayoutParams(lp); + return new Vh(inflate); + } + + @Override + public void onBindViewHolder(@NonNull Vh holder, int position) { + fanjian fanjian = list.get(position); + holder.textView.setText(fanjian.Id()); + holder.itemView.setOnClickListener(view -> { + fanjian.textView.setText(fanjian.Id() + "已经连接了" + Edit.fanjian.Id()); + Edit.fanjian.textView.setText(Edit.fanjian.Id()+"已经连接了"+ + fanjian.Id()); +/* xian xian = new xian(fanjian.frameLayout); + xian.createNewLine(Edit.fanjian.getX(), Edit.fanjian.getY()); + xian.updateCurrentLine(fanjian.getX(), fanjian.getY());*/ + list_AlertDialog.this.dismiss(); + }); + } + + @Override + public int getItemCount() { + return list.size(); + } + } + + class Vh extends RecyclerView.ViewHolder { + public TextView textView; + public Vh(@NonNull View itemView) { + super(itemView); + textView = itemView.findViewById(R.id.text); + } + } +} diff --git a/app/src/main/res/layout/edit.xml b/app/src/main/res/layout/edit.xml index ee0b893..8f98444 100644 --- a/app/src/main/res/layout/edit.xml +++ b/app/src/main/res/layout/edit.xml @@ -1,6 +1,7 @@ @@ -25,13 +26,18 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" - app:menu="@menu/bottom_app_bar" /> + app:menu="@menu/bottom_app_bar" + app:navigationContentDescription="@string/app_name" + app:fabAlignmentMode="center" + tools:ignore="VisualLintBottomAppBar" /> + app:srcCompat="@drawable/baseline_add_24" + tools:ignore="ImageContrastCheck" + android:contentDescription="@string/app_name" /> \ No newline at end of file diff --git a/app/src/main/res/layout/list_fangjian.xml b/app/src/main/res/layout/list_fangjian.xml new file mode 100644 index 0000000..bb6bae9 --- /dev/null +++ b/app/src/main/res/layout/list_fangjian.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/bottom_app_bar.xml b/app/src/main/res/menu/bottom_app_bar.xml index 458c7e8..be95496 100644 --- a/app/src/main/res/menu/bottom_app_bar.xml +++ b/app/src/main/res/menu/bottom_app_bar.xml @@ -1,24 +1,10 @@ - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/app/src/main/res/menu/edit_toolbar.xml b/app/src/main/res/menu/edit_toolbar.xml new file mode 100644 index 0000000..27fe96e --- /dev/null +++ b/app/src/main/res/menu/edit_toolbar.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file