MCPcopy Create free account
hub / github.com/cinit/TMoe / FaultyDialog

Class FaultyDialog

app/src/main/java/cc/ioctl/tmoe/ui/util/FaultyDialog.java:17–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15import cc.ioctl.tmoe.util.SyncUtils;
16
17public class FaultyDialog {
18
19 private FaultyDialog() {
20 throw new AssertionError("No " + getClass().getName() + " instances for you!");
21 }
22
23 public static void show(@NonNull Context ctx, @NonNull Throwable e) {
24 show(ctx, null, e, true);
25 }
26
27 public static void show(@NonNull Context ctx, @Nullable String title, @NonNull Throwable e) {
28 show(ctx, title, e, true);
29 }
30
31 public static void show(@NonNull Context ctx, @Nullable String title, @NonNull Throwable e, boolean cancelable) {
32 Log.e(e);
33 String t = TextUtils.isEmpty(title) ? Reflex.getShortClassName(e) : title;
34 assert t != null;
35 SyncUtils.runOnUiThread(() -> showImpl(ctx, t, e, cancelable));
36 }
37
38 public static void show(@NonNull Context ctx, @NonNull String title, @NonNull String msg) {
39 show(ctx, title, msg, false);
40 }
41
42 public static void show(@NonNull Context ctx, @NonNull String title, @NonNull String msg, boolean cancelable) {
43 SyncUtils.runOnUiThread(() -> showImpl(ctx, title, msg, cancelable));
44 }
45
46 private static void showImpl(@NonNull Context ctx, @NonNull String title, @NonNull Throwable e, boolean cancelable) {
47 Context c = CommonContextWrapper.createAppCompatContext(ctx);
48 String msg = Log.getStackTraceString(e);
49 new AlertDialog.Builder(c)
50 .setTitle(title)
51 .setMessage(msg)
52 .setCancelable(cancelable)
53 .setPositiveButton(android.R.string.ok, null)
54 .setNeutralButton(android.R.string.copy, (dialog, which) -> {
55 ClipboardManager clipboard = (ClipboardManager) c.getSystemService(Context.CLIPBOARD_SERVICE);
56 ClipData clip = ClipData.newPlainText("error", msg);
57 clipboard.setPrimaryClip(clip);
58 })
59 .show();
60 }
61
62 private static void showImpl(@NonNull Context ctx, @NonNull String title, @NonNull CharSequence msg, boolean cancelable) {
63 Context c = CommonContextWrapper.createAppCompatContext(ctx);
64 new AlertDialog.Builder(c)
65 .setTitle(title)
66 .setMessage(msg)
67 .setCancelable(cancelable)
68 .setPositiveButton(android.R.string.ok, null)
69 .show();
70 }
71}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected