wjc
2024-12-03 4c111f5659d7e8872ad91316127326de9a9f6162
app/src/main/java/com/hdl/photovoltaic/other/HdlThreadLogic.java
@@ -14,7 +14,7 @@
import com.hdl.photovoltaic.enums.ShowErrorMode;
import com.hdl.photovoltaic.widget.ConfirmationCancelDialog;
import com.hdl.photovoltaic.widget.ConfirmationExceptionDialog;
import com.hdl.photovoltaic.widget.FlashingBoxDialog;
import com.hdl.photovoltaic.widget.FlashingIconBoxDialog;
/**
 * 线程逻辑
@@ -46,7 +46,7 @@
    /**
     * 切换回主线程执行
     *
     * @param runnable      回调
     * @param runnable 回调
     */
    public static void runMainThread(Runnable runnable) {
        try {
@@ -59,7 +59,6 @@
        }
    }
    /**
@@ -78,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();
@@ -123,26 +141,46 @@
    /**
     * 错误提示框(蓝湖上样式)
     * 全局弹出框,错误提示框(蓝湖上样式)
     *
     * @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);
    }
@@ -196,7 +234,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");