From 49db2ff387b7cc6385d51cefb80a8604600408f0 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期四, 21 三月 2024 16:55:06 +0800 Subject: [PATCH] 2024年03月21日16:54:46 --- app/src/main/java/com/hdl/photovoltaic/other/HdlThreadLogic.java | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 54 insertions(+), 3 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..01b396c 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlThreadLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlThreadLogic.java @@ -43,6 +43,23 @@ } } + /** + * 鍒囨崲鍥炰富绾跨▼鎵ц + * + * @param runnable 鍥炶皟 + */ + public static void runMainThread(Runnable runnable) { + try { + if (Looper.myLooper() == Looper.getMainLooper()) { + runnable.run(); + } else { + handler.post(runnable); + } + } catch (Exception ignored) { + + } + } + /** * 瀛愮嚎绋嬫墽琛� @@ -60,6 +77,25 @@ runnable.run(); } catch (Exception e) { exception(e, showErrorMode, context); + } + } + }).start(); + + } + + /** + * 瀛愮嚎绋嬫墽琛� + * + * @param runnable 鍥炶皟 + */ + public static void runSubThread(Runnable runnable) { + + new Thread(new Runnable() { + @Override + public void run() { + try { + runnable.run(); + } catch (Exception ignored) { } } }).start(); @@ -105,17 +141,32 @@ /** - * 閿欒鎻愮ず妗嗭紙钃濇箹涓婃牱寮忥級 + * 鍏ㄥ眬寮瑰嚭妗�,閿欒鎻愮ず妗嗭紙钃濇箹涓婃牱寮忥級 * * @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); + FlashingBoxDialog flashingBoxDialog = new FlashingBoxDialog(context, millisecond); if (isBoolean) { Drawable drawable = AppCompatResources.getDrawable(context, R.drawable.tip_succeed); flashingBoxDialog.setImage(drawable); @@ -123,7 +174,7 @@ Drawable drawable = AppCompatResources.getDrawable(context, R.drawable.tip_fail); flashingBoxDialog.setImage(drawable); } - flashingBoxDialog.setContent(msg + "\r\n(" + code + ")"); + flashingBoxDialog.setContent(msg + "(" + code + ")"); flashingBoxDialog.show(); } }, null, null); -- Gitblit v1.8.0