diff --git a/src/main/java/org/acra/dialog/BaseCrashReportDialog.java b/src/main/java/org/acra/dialog/BaseCrashReportDialog.java
index 1705c78d3c..58a535570a 100644
--- a/src/main/java/org/acra/dialog/BaseCrashReportDialog.java
+++ b/src/main/java/org/acra/dialog/BaseCrashReportDialog.java
@@ -29,17 +29,19 @@
* The methods sendCrash(comment, usrEmail) and cancelReports() can be used to send or cancel
* sending of reports respectively.
*
- * This Activity will be instantiated with 3 arguments:
+ * This Activity will be instantiated with 3 (or 4) arguments:
*
* - {@link ACRAConstants#EXTRA_REPORT_FILE_NAME}
* - {@link ACRAConstants#EXTRA_REPORT_EXCEPTION}
* - {@link ACRAConstants#EXTRA_REPORT_CONFIG}
+ * - {@link ACRAConstants#EXTRA_FORCE_CANCEL} (optional)
*
*/
public abstract class BaseCrashReportDialog extends Activity {
private File reportFile;
private ACRAConfiguration config;
+ private Throwable exception;
@CallSuper
@Override
@@ -49,6 +51,9 @@ protected void onCreate(Bundle 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");
+ }
final boolean forceCancel = getIntent().getBooleanExtra(ACRAConstants.EXTRA_FORCE_CANCEL, false);
if (forceCancel) {
@@ -61,8 +66,9 @@ protected void onCreate(Bundle savedInstanceState) {
reportFile = (File) getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_FILE);
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Opening CrashReportDialog for " + reportFile);
if (reportFile == null) {
- finish();
+ throw new IllegalStateException("CrashReportDialog has to be called with extra ACRAConstants#EXTRA_REPORT_FILE");
}
+ exception = (Throwable) getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_EXCEPTION);
}
@@ -101,4 +107,12 @@ protected void sendCrash(@Nullable String comment, @Nullable String userEmail) {
ToastSender.sendToast(getApplicationContext(), toastId, Toast.LENGTH_LONG);
}
}
+
+ protected final ACRAConfiguration getConfig(){
+ return config;
+ }
+
+ protected final Throwable getException(){
+ return exception;
+ }
}
diff --git a/src/main/java/org/acra/dialog/CrashReportDialog.java b/src/main/java/org/acra/dialog/CrashReportDialog.java
index 985f444fdf..9df080cfb9 100644
--- a/src/main/java/org/acra/dialog/CrashReportDialog.java
+++ b/src/main/java/org/acra/dialog/CrashReportDialog.java
@@ -14,9 +14,9 @@
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
+
import org.acra.ACRA;
import org.acra.ACRAConstants;
-import org.acra.config.ACRAConfiguration;
import org.acra.prefs.SharedPreferencesFactory;
@@ -27,13 +27,13 @@
**/
public class CrashReportDialog extends BaseCrashReportDialog implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
+ private static final int PADDING = 10;
private static final String STATE_EMAIL = "email";
private static final String STATE_COMMENT = "comment";
private LinearLayout scrollable;
private EditText userCommentView;
private EditText userEmailView;
- private ACRAConfiguration config;
private SharedPreferencesFactory sharedPreferencesFactory;
private AlertDialog mDialog;
@@ -45,8 +45,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
scrollable = new LinearLayout(this);
scrollable.setOrientation(LinearLayout.VERTICAL);
- config = (ACRAConfiguration) getIntent().getSerializableExtra(ACRAConstants.EXTRA_REPORT_CONFIG);
- sharedPreferencesFactory = new SharedPreferencesFactory(getApplicationContext(), config);
+ sharedPreferencesFactory = new SharedPreferencesFactory(getApplicationContext(), getConfig());
buildAndShowDialog(savedInstanceState);
}
@@ -57,17 +56,17 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
*/
protected void buildAndShowDialog(@Nullable Bundle savedInstanceState){
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
- final int titleResourceId = config.resDialogTitle();
- if (titleResourceId != 0) {
+ final int titleResourceId = getConfig().resDialogTitle();
+ if (titleResourceId != ACRAConstants.DEFAULT_RES_VALUE) {
dialogBuilder.setTitle(titleResourceId);
}
- final int iconResourceId = config.resDialogIcon();
- if (iconResourceId != 0) {
+ final int iconResourceId = getConfig().resDialogIcon();
+ if (iconResourceId != ACRAConstants.DEFAULT_RES_VALUE) {
dialogBuilder.setIcon(iconResourceId);
}
dialogBuilder.setView(buildCustomView(savedInstanceState));
- dialogBuilder.setPositiveButton(getText(config.resDialogPositiveButtonText()), CrashReportDialog.this);
- dialogBuilder.setNegativeButton(getText(config.resDialogNegativeButtonText()), CrashReportDialog.this);
+ dialogBuilder.setPositiveButton(getText(getConfig().resDialogPositiveButtonText()), CrashReportDialog.this);
+ dialogBuilder.setNegativeButton(getText(getConfig().resDialogNegativeButtonText()), CrashReportDialog.this);
mDialog = dialogBuilder.create();
mDialog.setCanceledOnTouchOutside(false);
@@ -77,41 +76,40 @@ protected void buildAndShowDialog(@Nullable Bundle savedInstanceState){
@NonNull
protected View buildCustomView(@Nullable Bundle savedInstanceState) {
- final LinearLayout root = new LinearLayout(this);
- root.setOrientation(LinearLayout.VERTICAL);
- root.setPadding(10, 10, 10, 10);
+ final ScrollView root = new ScrollView(this);
+ root.setPadding(PADDING, PADDING, PADDING, PADDING);
root.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
root.setFocusable(true);
root.setFocusableInTouchMode(true);
-
- final ScrollView scroll = new ScrollView(this);
- root.addView(scroll, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
- scroll.addView(scrollable);
+ root.addView(scrollable);
addViewToDialog(getMainView());
// Add an optional prompt for user comments
- final int commentPromptId = config.resDialogCommentPrompt();
- if (commentPromptId != 0) {
+ View comment = getCommentLabel();
+ if(comment != null){
+ comment.setPadding(comment.getPaddingLeft(), PADDING, comment.getPaddingRight(), comment.getPaddingBottom());
+ addViewToDialog(comment);
String savedComment = null;
if (savedInstanceState != null) {
savedComment = savedInstanceState.getString(STATE_COMMENT);
}
- userCommentView = getCommentPrompt(getText(commentPromptId), savedComment);
+ userCommentView = getCommentPrompt(savedComment);
addViewToDialog(userCommentView);
}
// Add an optional user email field
- final int emailPromptId = config.resDialogEmailPrompt();
- if (emailPromptId != 0) {
+ View email = getEmailLabel();
+ if(email != null){
+ email.setPadding(email.getPaddingLeft(), PADDING, email.getPaddingRight(), email.getPaddingBottom());
+ addViewToDialog(email);
String savedEmail = null;
if (savedInstanceState != null) {
savedEmail = savedInstanceState.getString(STATE_EMAIL);
}
- userEmailView = getEmailPrompt(getText(emailPromptId), savedEmail);
+ userEmailView = getEmailPrompt(savedEmail);
addViewToDialog(userEmailView);
}
-
return root;
}
@@ -125,35 +123,43 @@ protected final void addViewToDialog(View v) {
}
/**
- * Creates a main view containing text of resDialogText
+ * Creates a main view containing text of resDialogText, or nothing if not found
*
* @return the main view
*/
@NonNull
protected View getMainView() {
final TextView text = new TextView(this);
- final int dialogTextId = config.resDialogText();
- if (dialogTextId != 0) {
+ final int dialogTextId = getConfig().resDialogText();
+ if (dialogTextId != ACRAConstants.DEFAULT_RES_VALUE) {
text.setText(getText(dialogTextId));
}
return text;
}
+ /**
+ * creates a comment label view with resDialogCommentPrompt as text
+ * @return the label or null if there is no resource
+ */
+ @Nullable
+ protected View getCommentLabel() {
+ final int commentPromptId = getConfig().resDialogCommentPrompt();
+ if (commentPromptId != ACRAConstants.DEFAULT_RES_VALUE) {
+ final TextView labelView = new TextView(this);
+ labelView.setText(getText(commentPromptId));
+ return labelView;
+ }
+ return null;
+ }
+
/**
* creates a comment prompt
*
- * @param label the label of the prompt
* @param savedComment the content of the prompt (usually from a saved state)
* @return the comment prompt
*/
@NonNull
- protected EditText getCommentPrompt(CharSequence label, @Nullable CharSequence savedComment) {
- final TextView labelView = new TextView(this);
- labelView.setText(label);
-
- labelView.setPadding(labelView.getPaddingLeft(), 10, labelView.getPaddingRight(), labelView.getPaddingBottom());
- scrollable.addView(labelView, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
-
+ protected EditText getCommentPrompt(@Nullable CharSequence savedComment) {
EditText userCommentView = new EditText(this);
userCommentView.setLines(2);
if (savedComment != null) {
@@ -162,21 +168,29 @@ protected EditText getCommentPrompt(CharSequence label, @Nullable CharSequence s
return userCommentView;
}
+ /**
+ * creates a email label view with resDialogEmailPrompt as text
+ * @return the label or null if there is no resource
+ */
+ @Nullable
+ protected View getEmailLabel(){
+ final int emailPromptId = getConfig().resDialogEmailPrompt();
+ if (emailPromptId != ACRAConstants.DEFAULT_RES_VALUE) {
+ final TextView labelView = new TextView(this);
+ labelView.setText(getText(emailPromptId));
+ return labelView;
+ }
+ return null;
+ }
+
/**
* creates an email prompt
*
- * @param label the label of the prompt
- * @param savedEmail the content of the prompt (usually from a saved state)
+ * @param savedEmail the content of the prompt (usually from a saved state or settings)
* @return the email prompt
*/
@NonNull
- protected EditText getEmailPrompt(CharSequence label, @Nullable CharSequence savedEmail) {
- final TextView labelView = new TextView(this);
- labelView.setText(label);
-
- labelView.setPadding(labelView.getPaddingLeft(), 10, labelView.getPaddingRight(), labelView.getPaddingBottom());
- scrollable.addView(labelView);
-
+ protected EditText getEmailPrompt(@Nullable CharSequence savedEmail) {
EditText userEmailView = new EditText(this);
userEmailView.setSingleLine();
userEmailView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);