Use new nextcloud-commons library for uncaught exception handling

https://github.com/stefan-niedermann/nextcloud-commons

Signed-off-by: stefan-niedermann <info@niedermann.it>
This commit is contained in:
stefan-niedermann 2020-02-12 20:17:13 +01:00
parent e87ddac3a0
commit 4b1c60e874
9 changed files with 6 additions and 144 deletions

View file

@ -96,10 +96,6 @@
</intent-filter>
</activity>
<activity
android:name=".android.activity.ExceptionActivity"
android:process=":error_activity" />
<receiver
android:name=".android.appwidget.CreateNoteWidget"
android:label="@string/widget_create_note">

View file

@ -32,7 +32,7 @@ public class AboutActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this, ExceptionActivity.class));
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this));
setContentView(R.layout.activity_about);
ButterKnife.bind(this);

View file

@ -55,7 +55,7 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this, ExceptionActivity.class));
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this));
setContentView(R.layout.activity_edit);

View file

@ -1,58 +0,0 @@
package it.niedermann.owncloud.notes.android.activity;
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import it.niedermann.nextcloud.exception.ExceptionUtil;
import it.niedermann.owncloud.notes.R;
import static it.niedermann.nextcloud.exception.ExceptionHandler.KEY_THROWABLE;
public class ExceptionActivity extends AppCompatActivity {
Throwable throwable;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.message)
TextView message;
@BindView(R.id.stacktrace)
TextView stacktrace;
@SuppressLint("SetTextI18n") // only used for logging
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_exception);
ButterKnife.bind(this);
super.onCreate(savedInstanceState);
setSupportActionBar(toolbar);
throwable = ((Throwable) getIntent().getSerializableExtra(KEY_THROWABLE));
toolbar.setTitle(getString(R.string.simple_error));
this.message.setText(throwable.getMessage());
this.stacktrace.setText(ExceptionUtil.getDebugInfos(this, throwable));
}
@OnClick(R.id.copy)
void copyStacktraceToClipboard() {
final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText(getString(R.string.simple_exception), "```\n" + this.stacktrace.getText() + "\n```");
clipboardManager.setPrimaryClip(clipData);
Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
}
@OnClick(R.id.close)
void close() {
finish();
}
}

View file

@ -155,7 +155,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this, ExceptionActivity.class));
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this));
setContentView(R.layout.drawer_layout);
ButterKnife.bind(this);

View file

@ -24,7 +24,7 @@ public class PreferencesActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this, ExceptionActivity.class));
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this));
setContentView(R.layout.activity_preferences);
ButterKnife.bind(this);
setSupportActionBar(toolbar);

View file

@ -26,7 +26,7 @@ public class SelectSingleNoteActivity extends NotesListViewActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this, ExceptionActivity.class));
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this));
setResult(Activity.RESULT_CANCELED);
ButterKnife.bind(this);

View file

@ -16,7 +16,7 @@ public class SplashscreenActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this, ExceptionActivity.class));
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this));
Intent intent = new Intent(this, NotesListViewActivity.class);
startActivity(intent);

View file

@ -1,76 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/toolbarStyle"
app:contentInsetStartWithNavigation="0dp"
app:elevation="4dp"
app:titleMarginStart="0dp"
tools:title="@string/simple_exception" />
<TextView
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_margin"
android:hint="An error appeared."
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/stacktrace"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:background="@color/bg_highlighted"
android:padding="8dp"
android:scrollbars="horizontal|vertical"
android:textIsSelectable="true"
android:typeface="monospace"
tools:text="@string/android_get_accounts_permission_not_granted_exception_message" />
<LinearLayout
style="?android:buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:gravity="end"
android:orientation="horizontal"
android:weightSum="1.0">
<Button
android:id="@+id/close"
style="?android:buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight=".5"
android:text="@string/simple_close" />
<Button
android:id="@+id/copy"
style="?android:buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:layout_weight=".5"
android:background="@color/primary"
android:foreground="?attr/selectableItemBackground"
android:text="@string/simple_copy"
android:textColor="@color/fg_contrast"
tools:ignore="UnusedAttribute" />
</LinearLayout>
</LinearLayout>