From 53290aea92ac6496e16490330ddd0d569c95fb99 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Sun, 26 Nov 2023 00:33:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BD=BF=E6=88=BF=E9=97=B4?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=8C=81=E6=9C=89=E7=94=BB=E6=9D=BF=E3=80=82?= 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 127433 -> 127733 bytes .gradle/8.0/fileHashes/fileHashes.lock | Bin 17 -> 17 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .../java/com/muqingedit/activity/Edit.java | 12 ++---- app/src/main/java/com/muqingedit/fanjian.java | 36 ++++++++++++++---- app/src/main/java/com/muqingedit/xian.java | 18 ++++++--- 7 files changed, 44 insertions(+), 22 deletions(-) diff --git a/.gradle/8.0/executionHistory/executionHistory.lock b/.gradle/8.0/executionHistory/executionHistory.lock index ea478f9482c583148ecd908fb41c2bd8491168e8..2e7a9ef7916ce5d823e7d9a3df45995692bce600 100644 GIT binary patch literal 17 VcmZR6yJ^m`1vkAnF@OQb0RTqp215V< literal 17 VcmZR6yJ^m`1vkAnF@OQbQ~*Z61{eSU diff --git a/.gradle/8.0/fileHashes/fileHashes.bin b/.gradle/8.0/fileHashes/fileHashes.bin index 0be581454dfc3481f4070fbcba0e6bd7c85e9ea2..89108dd51469c3b05caa90a5572f68b0574a051d 100644 GIT binary patch delta 1672 zcmZXUc~BEq9LM(&NDzTULr91i7b{S8kRV49M2dhk6kCXnieSM)#RE~1GEyk1bSR)4 zV#F6g!CG2WP=OQ^7_l-`C^}poP_GdKk;`x?F#-xz(3{w{v#RJu zl5~(N@k%PAbZ}5qub!Zj=(IG)UQT1wyq(HgQmt+#*$AnZqo)yQkdC{QlmQ26{_}<< z^w_m+(cO_@B+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j7>V_{8o_#s z$788yfa{m5ZR1mQlS}ixtSu|k`UL?PHipc9K7P-OS5s6W^=r3$TAIjlp_6)R3HU{+TS5SC67Ui3b2@(r*&Gq`;(vMvkq`uY>xwGWJ@pM2QrSB##^6oP5s zi_{~R>`fja-+isv@%f>jM_AB(>U;-*>SrL{k*E99g&M+NCA3l9@*JwiMoH80#G;<) zUD;xdPWQ0wSQO3F%k_+W{_xu2LuFogHbt{|HWqR%rq0%kCP^SfUGGG>CirK5`hs6u z-Kg~d{t5WT=xk_W7QB;{Z~gsjAvRgUiybQH)BK*z7Hio_ytjT5!}W2g#sS&${3g3$ zL9w@(WiW@5up(1!f^w1R~kc-v5z(LN@s{rnYgPw(K*uQ#?a*XkMRBqZsGrc70;8?DL$c wmVV#EGBRlfkcUy>BE*qZm6vZAEmIM;sLsV*t8twyDvd^EIs9WDT7(t&7tvap^#A|> diff --git a/.gradle/8.0/fileHashes/fileHashes.lock b/.gradle/8.0/fileHashes/fileHashes.lock index a0a8052dd19fa107b178ce32ff9edc82de45cc0d..1f9c0095f351f678ede4b4dc5b78fab0c77049b4 100644 GIT binary patch literal 17 VcmZSX2>ZE?wbpt&0~m-F001*I1cCqn literal 17 VcmZSX2>ZE?wbpt&0~m-h0{}9|1Qh@P diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index df5003e473629cb0c0401a8452ce6b47e5d322e7..a5fb0f6f68bde4c2956f8189384f0e5f7c489835 100644 GIT binary patch literal 17 VcmZQR{+!=6w@BEC0SqKQ0RSvC1T+8u literal 17 VcmZQR{+!=6w@BEC0SqLL0{|=u1PK5D diff --git a/app/src/main/java/com/muqingedit/activity/Edit.java b/app/src/main/java/com/muqingedit/activity/Edit.java index e622064..b3369be 100644 --- a/app/src/main/java/com/muqingedit/activity/Edit.java +++ b/app/src/main/java/com/muqingedit/activity/Edit.java @@ -14,7 +14,8 @@ import com.muqingedit.xian; public class Edit extends ActivityFragment { @SuppressLint("StaticFieldLeak") - public static FrameLayout frameLayout; + public FrameLayout frameLayout; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -22,19 +23,12 @@ public class Edit extends ActivityFragment { frameLayout = findViewById(R.id.view); //绘制一个房间 findViewById(R.id.button).setOnClickListener(view -> { - fanjian button = new fanjian(Edit.this) + fanjian button = new fanjian(Edit.this).setPaletteView(frameLayout) .setLayoutParams(260, 250) .setXY(200, 100); frameLayout.addView(button); }); } - public static void addView(View view) { - frameLayout.addView(view); - } - - public static Context getContext() { - return frameLayout.getContext(); - } } diff --git a/app/src/main/java/com/muqingedit/fanjian.java b/app/src/main/java/com/muqingedit/fanjian.java index a429b2a..637484a 100644 --- a/app/src/main/java/com/muqingedit/fanjian.java +++ b/app/src/main/java/com/muqingedit/fanjian.java @@ -18,6 +18,18 @@ import com.muqingedit.activity.Edit; public class fanjian extends FrameLayout { + private FrameLayout paletteView; + + /** + * 为其设置画板视图 + * + * @param paletteView + */ + public fanjian setPaletteView(FrameLayout paletteView) { + this.paletteView = paletteView; + return this; + } + public static int id = 0; private int X, Y; @@ -30,14 +42,16 @@ public class fanjian extends FrameLayout { private class dian extends View { xian xian; + public dian(Context context) { super(context); ViewGroup.LayoutParams aa = fanjian.this.getLayoutParams(); - LayoutParams layoutParams = new LayoutParams(aa.width /3, + LayoutParams layoutParams = new LayoutParams(aa.width / 3, aa.height / 3, Gravity.CENTER); this.setLayoutParams(layoutParams); // setBackgroundColor(Color.WHITE); } + @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); @@ -45,12 +59,14 @@ public class fanjian extends FrameLayout { paint.setColor(Color.WHITE); paint.setStyle(Paint.Style.FILL); paint.setAntiAlias(true); - int centerX = getWidth()/2; - int centerY = getHeight()/2; + int centerX = getWidth() / 2; + int centerY = getHeight() / 2; int radius = Math.min(centerX, centerY); canvas.drawCircle(centerX, centerY, radius, paint); } - float ax, ay,csx, csy; + + float ax, ay, csx, csy; + @Override public boolean onTouchEvent(MotionEvent event) { ax = event.getX(); @@ -60,9 +76,9 @@ public class fanjian extends FrameLayout { //在视图上面添加一条线 int[] location = new int[2]; 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(csx, csy); + 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; case MotionEvent.ACTION_MOVE: //绘制线 @@ -72,7 +88,7 @@ public class fanjian extends FrameLayout { case MotionEvent.ACTION_UP: //删除线 xian.clearCurrentLine(); - Edit.frameLayout.removeView(xian); + paletteView.removeView(xian); xian = null; return true; } @@ -83,6 +99,7 @@ public class fanjian extends FrameLayout { private GestureDetector gestureDetector; private boolean Long = false; + private void init() { // 设置背景颜色为红色 setBackgroundColor(Color.RED); @@ -95,6 +112,7 @@ public class fanjian extends FrameLayout { Long = !Long; // 处理长按事件 } + @Override public boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) { if (Long) { @@ -113,6 +131,7 @@ public class fanjian extends FrameLayout { gestureDetector.onTouchEvent(event); return true; } + @SuppressLint("DrawAllocation") @Override protected void onDraw(Canvas canvas) { @@ -153,6 +172,7 @@ public class fanjian extends FrameLayout { super.setX(x); X = (int) x; } + @Override public void setY(float y) { super.setY(y); diff --git a/app/src/main/java/com/muqingedit/xian.java b/app/src/main/java/com/muqingedit/xian.java index 198aff2..2b69c11 100644 --- a/app/src/main/java/com/muqingedit/xian.java +++ b/app/src/main/java/com/muqingedit/xian.java @@ -7,6 +7,7 @@ import android.graphics.Color; import android.graphics.Paint; import android.view.MotionEvent; import android.view.View; +import android.widget.FrameLayout; import com.muqingedit.activity.Edit; @@ -32,18 +33,25 @@ public class xian extends View { linePaint.setStrokeWidth(5f); } - public xian createNewLine(float x, float y) { - startX = x;startY = y;currentX = x;currentY = y; - Edit.addView(this); + public xian createNewLine(FrameLayout frameLayout, float x, float y) { + startX = x; + startY = y; + currentX = x; + currentY = y; + frameLayout.addView(this); invalidate();//创建一个新的线 return this; } + public void updateCurrentLine(float x, float y) { - currentX = x;currentY = y; + currentX = x; + currentY = y; invalidate();//绘制中 } + public void clearCurrentLine() { - currentX = startX;currentY = startY; + currentX = startX; + currentY = startY; invalidate();//关闭绘制 }