From 80f2ca2df62ff1cd03046864af504245be078eb2 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期四, 05 六月 2025 10:37:28 +0800
Subject: [PATCH] 2025年06月05日10:37:26

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlThreadLogic.java |   82 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 73 insertions(+), 9 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlThreadLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlThreadLogic.java
index 7b983fc..1d87970 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlThreadLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlThreadLogic.java
@@ -15,6 +15,7 @@
 import com.hdl.photovoltaic.widget.ConfirmationCancelDialog;
 import com.hdl.photovoltaic.widget.ConfirmationExceptionDialog;
 import com.hdl.photovoltaic.widget.FlashingBoxDialog;
+import com.hdl.photovoltaic.widget.FlashingIconBoxDialog;
 
 /**
  * 绾跨▼閫昏緫
@@ -43,6 +44,23 @@
         }
     }
 
+    /**
+     * 鍒囨崲鍥炰富绾跨▼鎵ц
+     *
+     * @param runnable 鍥炶皟
+     */
+    public static void runMainThread(Runnable runnable) {
+        try {
+            if (Looper.myLooper() == Looper.getMainLooper()) {
+                runnable.run();
+            } else {
+                handler.post(runnable);
+            }
+        } catch (Exception ignored) {
+
+        }
+    }
+
 
     /**
      * 瀛愮嚎绋嬫墽琛�
@@ -66,6 +84,25 @@
 
     }
 
+    /**
+     * 瀛愮嚎绋嬫墽琛�
+     *
+     * @param runnable 鍥炶皟
+     */
+    public static void runSubThread(Runnable runnable) {
+
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    runnable.run();
+                } catch (Exception ignored) {
+                }
+            }
+        }).start();
+
+    }
+
 
     /**
      * 鍏ㄥ眬寮瑰嚭妗�,绯荤粺榛樿Toast
@@ -74,7 +111,10 @@
         handler.post(new Runnable() {
             @Override
             public void run() {
-                Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
+                FlashingBoxDialog flashingBoxDialog = new FlashingBoxDialog(context, 1500);
+                flashingBoxDialog.setContent(text);
+                flashingBoxDialog.show();
+//                Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
             }
         });
     }
@@ -86,6 +126,9 @@
         handler.post(new Runnable() {
             @Override
             public void run() {
+//                FlashingBoxDialog flashingIconBoxDialog = new FlashingBoxDialog(context, 1500);
+//                flashingIconBoxDialog.setContent(hdlException.getMsg() + "(" + hdlException.getCode() + ")");
+//                flashingIconBoxDialog.show();
                 Toast.makeText(context, hdlException.getMsg() + "(" + hdlException.getCode() + ")", Toast.LENGTH_SHORT).show();
             }
         });
@@ -98,6 +141,7 @@
         handler.post(new Runnable() {
             @Override
             public void run() {
+
                 Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
             }
         });
@@ -105,26 +149,46 @@
 
 
     /**
-     * 閿欒鎻愮ず妗嗭紙钃濇箹涓婃牱寮忥級
+     * 鍏ㄥ眬寮瑰嚭妗�,閿欒鎻愮ず妗嗭紙钃濇箹涓婃牱寮忥級
      *
-     * @param isBoolean 鍥炬爣(true浣跨敤鎴愬姛鍥炬爣,false浣跨敤鎴愬姛鍥炬爣)
+     * @param isBoolean 鍥炬爣(true浣跨敤鎴愬姛鍥炬爣,false浣跨敤澶辫触鍥炬爣)
      * @param msg       淇℃伅
      * @param code      鐘舵��
      */
     public static void tipFlashingBox(Context context, boolean isBoolean, String msg, int code) {
+        tipFlashingBox(context, isBoolean, msg, code, 1500);
+    }
+
+    /**
+     * 鍏ㄥ眬寮瑰嚭妗�,閿欒鎻愮ず妗嗭紙钃濇箹涓婃牱寮忥級
+     *
+     * @param isBoolean   鍥炬爣(true浣跨敤鎴愬姛鍥炬爣,false浣跨敤澶辫触鍥炬爣)
+     * @param msg         淇℃伅
+     * @param code        鐘舵��
+     * @param millisecond 璁剧疆寤舵椂鏃堕棿鍏抽棴寮圭獥(鍗曚綅ms)
+     */
+    public static void tipFlashingBox(Context context, boolean isBoolean, String msg, int code, int millisecond) {
+        if (context == null) {
+            return;
+        }
         HdlThreadLogic.runMainThread(new Runnable() {
             @Override
             public void run() {
-                FlashingBoxDialog flashingBoxDialog = new FlashingBoxDialog(context);
+                FlashingIconBoxDialog flashingIconBoxDialog = new FlashingIconBoxDialog(context, millisecond);
                 if (isBoolean) {
                     Drawable drawable = AppCompatResources.getDrawable(context, R.drawable.tip_succeed);
-                    flashingBoxDialog.setImage(drawable);
+                    flashingIconBoxDialog.setImage(drawable);
                 } else {
                     Drawable drawable = AppCompatResources.getDrawable(context, R.drawable.tip_fail);
-                    flashingBoxDialog.setImage(drawable);
+                    flashingIconBoxDialog.setImage(drawable);
                 }
-                flashingBoxDialog.setContent(msg + "\r\n(" + code + ")");
-                flashingBoxDialog.show();
+                if (code == 0) {
+                    //鎴愬姛涓嶉渶瑕佸鍔犵姸鎬佺爜
+                    flashingIconBoxDialog.setContent(msg);
+                } else {
+                    flashingIconBoxDialog.setContent(msg + "(" + code + ")");
+                }
+                flashingIconBoxDialog.show();
             }
         }, null, null);
     }
@@ -178,7 +242,7 @@
      * @return 璋冪敤鏍�
      */
     private static String getStackTrace(Exception ex) {
-        StringBuilder sb = new StringBuilder("");
+        StringBuilder sb = new StringBuilder();
         StackTraceElement[] trace = ex.getStackTrace();
         for (StackTraceElement stackTraceElement : trace) {
             sb.append(stackTraceElement).append("\n");

--
Gitblit v1.8.0