911d2cec400698795669641e705b187083d80ffa
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / CrashReportingActivity.java
1 package net.ktnx.mobileledger.ui.activity;
2
3 import android.os.Bundle;
4 import androidx.annotation.Nullable;
5 import androidx.appcompat.app.AppCompatActivity;
6 import android.util.Log;
7
8 import net.ktnx.mobileledger.ui.CrashReportDialogFragment;
9 import net.ktnx.mobileledger.utils.Colors;
10
11 import java.io.PrintWriter;
12 import java.io.StringWriter;
13
14 public abstract class CrashReportingActivity extends AppCompatActivity {
15     protected void setupProfileColors() {
16         Colors.setupTheme(this);
17     }
18     @Override
19     protected void onStart() {
20         super.onStart();
21         Colors.refreshColors(getTheme());
22     }
23     @Override
24     protected void onCreate(@Nullable Bundle savedInstanceState) {
25         super.onCreate(savedInstanceState);
26         Colors.setupTheme(this);
27
28         Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
29             @Override
30             public void uncaughtException(Thread t, Throwable e) {
31                 StringWriter sw = new StringWriter();
32                 PrintWriter pw = new PrintWriter(sw);
33                 e.printStackTrace(pw);
34
35                 Log.e(null, sw.toString());
36
37                 CrashReportDialogFragment df = new CrashReportDialogFragment();
38                 df.setCrashReportText(sw.toString());
39                 df.show(getSupportFragmentManager(), "crash_report");
40             }
41         });
42         Log.d("crash", "Uncaught exception handler set");
43     }
44 }