| | |
| | | package com.hdl.photovoltaic.other; |
| | | |
| | | import android.app.Dialog; |
| | | import android.content.Context; |
| | | import android.os.Handler; |
| | | import android.os.Looper; |
| | | import android.util.Log; |
| | | import android.widget.Toast; |
| | | |
| | | import androidx.appcompat.app.AlertDialog; |
| | | |
| | | import com.hdl.photovoltaic.enums.ShowErrorMode; |
| | | import com.hdl.photovoltaic.widget.ConfirmationDialog; |
| | | import com.hdl.photovoltaic.widget.ConfirmationCancelDialog; |
| | | import com.hdl.photovoltaic.widget.ConfirmationExceptionDialog; |
| | | |
| | | /** |
| | | * 线程逻辑 |
| | |
| | | /** |
| | | * 切换回主线程执行 |
| | | * |
| | | * @param run 回调 |
| | | * @param runnable 回调 |
| | | * @param context 上下文(不需要弹框填null) |
| | | * @param showErrorMode 是否显示错误(不需要显示错误填null) |
| | | */ |
| | | public static void runMainThread(Runnable run, Context context, ShowErrorMode showErrorMode) { |
| | | public static void runMainThread(Runnable runnable, Context context, ShowErrorMode showErrorMode) { |
| | | try { |
| | | if (Looper.myLooper() == Looper.getMainLooper()) { |
| | | run.run(); |
| | | runnable.run(); |
| | | } else { |
| | | handler.post(run); |
| | | handler.post(runnable); |
| | | } |
| | | } catch (Exception e) { |
| | | |
| | | exception(e, showErrorMode, context); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 子线程执行 |
| | | * |
| | | * @param run 回调 |
| | | * @param runnable 回调 |
| | | * @param context 上下文(不需要弹框填null) |
| | | * @param showErrorMode 是否显示错误(不需要填null) |
| | | */ |
| | | public static void runThread(Runnable run, Context context, ShowErrorMode showErrorMode) { |
| | | public static void runThread(Runnable runnable, Context context, ShowErrorMode showErrorMode) { |
| | | |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | run.run(); |
| | | runnable.run(); |
| | | } catch (Exception e) { |
| | | exception(e, showErrorMode, context); |
| | | } |
| | |
| | | @Override |
| | | public void run() { |
| | | |
| | | ConfirmationDialog confirmationDialog = new ConfirmationDialog(context); |
| | | confirmationDialog.setTitle("提示"); |
| | | confirmationDialog.setContent("很抱歉,程序出现错误了,点击\"确认\"获取更多详细错误信息."); |
| | | confirmationDialog.setConfirmation("确认"); |
| | | confirmationDialog.setCancel("取消"); |
| | | confirmationDialog.show(); |
| | | confirmationDialog.setNoOnclickListener(new ConfirmationDialog.onNoOnclickListener() { |
| | | ConfirmationCancelDialog confirmationCancelDialog = new ConfirmationCancelDialog(context); |
| | | confirmationCancelDialog.setTitle("提示"); |
| | | confirmationCancelDialog.setContent("很抱歉,程序出现错误了,点击\"确认\"获取更多详细错误信息."); |
| | | confirmationCancelDialog.setConfirmation("确认"); |
| | | confirmationCancelDialog.setCancel("取消"); |
| | | confirmationCancelDialog.show(); |
| | | confirmationCancelDialog.setNoOnclickListener(new ConfirmationCancelDialog.onNoOnclickListener() { |
| | | @Override |
| | | public void Cancel() { |
| | | confirmationDialog.dismiss(); |
| | | confirmationCancelDialog.dismiss(); |
| | | } |
| | | }); |
| | | confirmationDialog.setYesOnclickListener(new ConfirmationDialog.onYesOnclickListener() { |
| | | confirmationCancelDialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() { |
| | | @Override |
| | | public void Confirm() { |
| | | confirmationDialog.dismiss(); |
| | | String s = getStackTrace(ex); |
| | | |
| | | confirmationCancelDialog.dismiss(); |
| | | ConfirmationExceptionDialog confirmationExceptionDialog = new ConfirmationExceptionDialog(context); |
| | | // String s = getStackTrace(ex); |
| | | String s = Log.getStackTraceString(ex); |
| | | confirmationExceptionDialog.setContent(s); |
| | | confirmationExceptionDialog.show(); |
| | | } |
| | | }); |
| | | |