Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

BaseCrashReportDialog #413

Merged
merged 3 commits into from
Mar 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ android {
}

dependencies {
compile 'com.android.support:support-v4:23.2.0'
compile 'com.android.support:support-annotations:23.2.0'
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:support-annotations:23.2.1'
}
69 changes: 37 additions & 32 deletions src/main/java/org/acra/dialog/BaseCrashReportDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.Nullable;
import android.widget.Toast;

import org.acra.ACRA;
import org.acra.ACRAConstants;
import org.acra.collector.CrashReportData;
Expand All @@ -16,25 +16,25 @@

import java.io.File;
import java.io.IOException;
import java.io.Serializable;

import static org.acra.ACRA.LOG_TAG;
import static org.acra.ReportField.USER_COMMENT;
import static org.acra.ReportField.USER_EMAIL;

/**
* Activity which implements the base functionality for a CrashReportDialog
* Activities which extend from this class can override onCreate() to create a custom view,
* but they must call super.onCreate() at the beginning of the method.
* Activities which extend from this class can override init to create a custom view.
*
* The methods sendCrash(comment, usrEmail) and cancelReports() can be used to send or cancel
* The methods sendCrash(comment, userEmail) and cancelReports() can be used to send or cancel
* sending of reports respectively.
*
* This Activity will be instantiated with 3 (or 4) arguments:
* <ol>
* <li>{@link ACRAConstants#EXTRA_REPORT_FILE_NAME}</li>
* <li>{@link ACRAConstants#EXTRA_REPORT_EXCEPTION}</li>
* <li>{@link ACRAConstants#EXTRA_REPORT_CONFIG}</li>
* <li>{@link ACRAConstants#EXTRA_FORCE_CANCEL} (optional)</li>
* <li>{@link ACRAConstants#EXTRA_REPORT_FILE_NAME}</li>
* <li>{@link ACRAConstants#EXTRA_REPORT_EXCEPTION}</li>
* <li>{@link ACRAConstants#EXTRA_REPORT_CONFIG}</li>
* <li>{@link ACRAConstants#EXTRA_FORCE_CANCEL} (optional)</li>
* </ol>
*/
public abstract class BaseCrashReportDialog extends Activity {
Expand All @@ -43,51 +43,56 @@ public abstract class BaseCrashReportDialog extends Activity {
private ACRAConfiguration config;
private Throwable exception;

@CallSuper
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
protected final void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "CrashReportDialog extras=" + getIntent().getExtras());

config = (ACRAConfiguration) getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_CONFIG);
if(config == null) {
throw new IllegalStateException("CrashReportDialog has to be called with extra ACRAConstants#EXTRA_REPORT_CONFIG");
if (ACRA.DEV_LOGGING) {
ACRA.log.d(LOG_TAG, "CrashReportDialog extras=" + getIntent().getExtras());
}

Serializable sConfig = getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_CONFIG);
Serializable sReportFile = getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_FILE);
Serializable sException = getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_EXCEPTION);
final boolean forceCancel = getIntent().getBooleanExtra(ACRAConstants.EXTRA_FORCE_CANCEL, false);
if (forceCancel) {
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Forced reports deletion.");
cancelReports();

if (!forceCancel && sConfig instanceof ACRAConfiguration && sReportFile instanceof File
&& (sException == null || sException instanceof Throwable)) {
config = (ACRAConfiguration) sConfig;
reportFile = (File) sReportFile;
exception = (Throwable) sException;
init(savedInstanceState);
} else {
if (forceCancel) {
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Forced reports deletion.");
cancelReports();
} else {
ACRA.log.w(LOG_TAG, "Illegal or incomplete call of BaseCrashReportDialog.");
}
finish();
return;
}
}

reportFile = (File) getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_FILE);
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Opening CrashReportDialog for " + reportFile);
if (reportFile == null) {
throw new IllegalStateException("CrashReportDialog has to be called with extra ACRAConstants#EXTRA_REPORT_FILE");
}
exception = (Throwable) getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_EXCEPTION);
protected void init(@Nullable Bundle savedInstanceState) {
}


/**
* Cancel any pending crash reports.
*/
@CallSuper
protected void cancelReports() {
protected final void cancelReports() {
new BulkReportDeleter(getApplicationContext()).deleteReports(false, 0);
}


/**
* Send crash report given user's comment and email address. If none should be empty strings
* @param comment Comment (may be null) provided by the user.
* @param userEmail Email address (may be null) provided by the client.
*
* @param comment Comment (may be null) provided by the user.
* @param userEmail Email address (may be null) provided by the client.
*/
@CallSuper
protected void sendCrash(@Nullable String comment, @Nullable String userEmail) {
protected final void sendCrash(@Nullable String comment, @Nullable String userEmail) {
final CrashReportPersister persister = new CrashReportPersister();
try {
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Add user comment to " + reportFile);
Expand All @@ -110,11 +115,11 @@ protected void sendCrash(@Nullable String comment, @Nullable String userEmail) {
}
}

protected final ACRAConfiguration getConfig(){
protected final ACRAConfiguration getConfig() {
return config;
}

protected final Throwable getException(){
protected final Throwable getException() {
return exception;
}
}
10 changes: 4 additions & 6 deletions src/main/java/org/acra/dialog/CrashReportDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public class CrashReportDialog extends BaseCrashReportDialog implements DialogIn

@CallSuper
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

protected void init(@Nullable Bundle savedInstanceState) {
scrollable = new LinearLayout(this);
scrollable.setOrientation(LinearLayout.VERTICAL);
sharedPreferencesFactory = new SharedPreferencesFactory(getApplicationContext(), getConfig());
Expand All @@ -64,9 +62,9 @@ protected void buildAndShowDialog(@Nullable Bundle savedInstanceState){
if (iconResourceId != ACRAConstants.DEFAULT_RES_VALUE) {
dialogBuilder.setIcon(iconResourceId);
}
dialogBuilder.setView(buildCustomView(savedInstanceState));
dialogBuilder.setPositiveButton(getText(getConfig().resDialogPositiveButtonText()), CrashReportDialog.this);
dialogBuilder.setNegativeButton(getText(getConfig().resDialogNegativeButtonText()), CrashReportDialog.this);
dialogBuilder.setView(buildCustomView(savedInstanceState))
.setPositiveButton(getText(getConfig().resDialogPositiveButtonText()), this)
.setNegativeButton(getText(getConfig().resDialogNegativeButtonText()), this);

mDialog = dialogBuilder.create();
mDialog.setCanceledOnTouchOutside(false);
Expand Down