wjc
2023-06-25 c96a5eb14685ca81771d3fa4e28ccc77db54a989
app/src/main/java/com/hdl/photovoltaic/other/HdlThreadLogic.java
@@ -9,6 +9,7 @@
import androidx.appcompat.app.AlertDialog;
import com.hdl.photovoltaic.enums.ShowErrorMode;
import com.hdl.photovoltaic.widget.ConfirmationDialog;
/**
 * 线程逻辑
@@ -86,12 +87,12 @@
    /**
     * @param e             异常信息类
     * @param ex            异常信息类
     * @param context       上下文(不需要弹框填null)
     * @param showErrorMode 是否显示错误(不需要填null)
     */
    private static void exception(Exception e, ShowErrorMode showErrorMode, Context context) {
        if (showErrorMode == null || context == null || e == null) {
    private static void exception(Exception ex, ShowErrorMode showErrorMode, Context context) {
        if (showErrorMode == null || context == null || ex == null) {
            return;
        }
        if (showErrorMode == ShowErrorMode.NO) {
@@ -101,18 +102,42 @@
        handler.post(new Runnable() {
            @Override
            public void run() {
                Dialog alertDialog = new AlertDialog.Builder(context).
                        setTitle("抱歉程序出现错误了,点击\"确认\"获取更多详细信息.").
                        setMessage(e.getMessage()).
                        create();
                alertDialog.show();
                //提示
//                AlertDialog alertDialog = new AlertDialog(context, androidx.fragment.R.style.TextAppearance_Compat_Notification);
//                alertDialog.setTitle("抱歉程序出现错误了");
//                alertDialog.show();
//                Toast.makeText(context, "抱歉程序出现错误了", Toast.LENGTH_SHORT).show();
                ConfirmationDialog confirmationDialog = new ConfirmationDialog(context);
                confirmationDialog.setTitle("提示");
                confirmationDialog.setContent("很抱歉,程序出现错误了,点击\"确认\"获取更多详细错误信息.");
                confirmationDialog.setConfirmation("确认");
                confirmationDialog.setCancel("取消");
                confirmationDialog.show();
                confirmationDialog.setNoOnclickListener(new ConfirmationDialog.onNoOnclickListener() {
                    @Override
                    public void Cancel() {
                        confirmationDialog.dismiss();
                    }
                });
                confirmationDialog.setYesOnclickListener(new ConfirmationDialog.onYesOnclickListener() {
                    @Override
                    public void Confirm() {
                        confirmationDialog.dismiss();
                        String s = getStackTrace(ex);
                    }
                });
            }
        });
    }
    /**
     * @return 调用栈
     */
    private static String getStackTrace(Exception ex) {
        StringBuilder sb = new StringBuilder("");
        StackTraceElement[] trace = ex.getStackTrace();
        for (StackTraceElement stackTraceElement : trace) {
            sb.append(stackTraceElement).append("\n");
        }
        return sb.toString();
    }
}