@@ -22,15 +22,27 @@ public class CrashReportDialog extends BaseCrashReportDialog implements DialogIn
22
22
23
23
private static final String STATE_EMAIL = "email" ;
24
24
private static final String STATE_COMMENT = "comment" ;
25
+ private LinearLayout scrollable ;
25
26
private EditText userCommentView ;
26
27
private EditText userEmailView ;
27
28
28
- AlertDialog mDialog ;
29
+ private AlertDialog mDialog ;
29
30
30
31
@ Override
31
32
protected void onCreate (Bundle savedInstanceState ) {
32
33
super .onCreate (savedInstanceState );
33
34
35
+ scrollable = new LinearLayout (this );
36
+ scrollable .setOrientation (LinearLayout .VERTICAL );
37
+
38
+ buildAndShowDialog (savedInstanceState );
39
+ }
40
+
41
+ /**
42
+ * Build the dialog from the values in config
43
+ * @param savedInstanceState old state to restore
44
+ */
45
+ protected void buildAndShowDialog (Bundle savedInstanceState ){
34
46
final AlertDialog .Builder dialogBuilder = new AlertDialog .Builder (this );
35
47
final int titleResourceId = ACRA .getConfig ().resDialogTitle ();
36
48
if (titleResourceId != 0 ) {
@@ -60,66 +72,107 @@ protected View buildCustomView(Bundle savedInstanceState) {
60
72
61
73
final ScrollView scroll = new ScrollView (this );
62
74
root .addView (scroll , new LinearLayout .LayoutParams (LayoutParams .FILL_PARENT , LayoutParams .FILL_PARENT , 1.0f ));
63
- final LinearLayout scrollable = new LinearLayout (this );
64
- scrollable .setOrientation (LinearLayout .VERTICAL );
65
75
scroll .addView (scrollable );
66
76
67
- final TextView text = new TextView (this );
68
- final int dialogTextId = ACRA .getConfig ().resDialogText ();
69
- if (dialogTextId != 0 ) {
70
- text .setText (getText (dialogTextId ));
71
- }
72
- scrollable .addView (text );
77
+ addViewToDialog (getMainView ());
73
78
74
79
// Add an optional prompt for user comments
75
80
final int commentPromptId = ACRA .getConfig ().resDialogCommentPrompt ();
76
81
if (commentPromptId != 0 ) {
77
- final TextView label = new TextView (this );
78
- label .setText (getText (commentPromptId ));
79
-
80
- label .setPadding (label .getPaddingLeft (), 10 , label .getPaddingRight (), label .getPaddingBottom ());
81
- scrollable .addView (label , new LinearLayout .LayoutParams (LayoutParams .FILL_PARENT , LayoutParams .WRAP_CONTENT ));
82
-
83
- userCommentView = new EditText (this );
84
- userCommentView .setLines (2 );
82
+ String savedComment = null ;
85
83
if (savedInstanceState != null ) {
86
- String savedValue = savedInstanceState .getString (STATE_COMMENT );
87
- if (savedValue != null ) {
88
- userCommentView .setText (savedValue );
89
- }
84
+ savedComment = savedInstanceState .getString (STATE_COMMENT );
90
85
}
91
- scrollable .addView (userCommentView );
86
+ userCommentView = getCommentPrompt (getText (commentPromptId ), savedComment );
87
+ addViewToDialog (userCommentView );
92
88
}
93
89
94
90
// Add an optional user email field
95
91
final int emailPromptId = ACRA .getConfig ().resDialogEmailPrompt ();
96
92
if (emailPromptId != 0 ) {
97
- final TextView label = new TextView (this );
98
- label .setText (getText (emailPromptId ));
99
-
100
- label .setPadding (label .getPaddingLeft (), 10 , label .getPaddingRight (), label .getPaddingBottom ());
101
- scrollable .addView (label );
102
-
103
- userEmailView = new EditText (this );
104
- userEmailView .setSingleLine ();
105
- userEmailView .setInputType (InputType .TYPE_CLASS_TEXT | InputType .TYPE_TEXT_VARIATION_EMAIL_ADDRESS );
106
-
107
- String savedValue = null ;
93
+ String savedEmail = null ;
108
94
if (savedInstanceState != null ) {
109
- savedValue = savedInstanceState .getString (STATE_EMAIL );
110
- }
111
- if (savedValue != null ) {
112
- userEmailView .setText (savedValue );
113
- } else {
114
- final SharedPreferences prefs = ACRA .getACRASharedPreferences ();
115
- userEmailView .setText (prefs .getString (ACRA .PREF_USER_EMAIL_ADDRESS , "" ));
95
+ savedEmail = savedInstanceState .getString (STATE_EMAIL );
116
96
}
117
- scrollable .addView (userEmailView );
97
+ userEmailView = getEmailPrompt (getText (emailPromptId ), savedEmail );
98
+ addViewToDialog (userEmailView );
118
99
}
119
100
120
101
return root ;
121
102
}
122
103
104
+ /**
105
+ * adds a view to the end of the dialog
106
+ *
107
+ * @param v the view to add
108
+ */
109
+ protected final void addViewToDialog (View v ) {
110
+ scrollable .addView (v );
111
+ }
112
+
113
+ /**
114
+ * Creates a main view containing text of resDialogText
115
+ *
116
+ * @return the main view
117
+ */
118
+ protected View getMainView () {
119
+ final TextView text = new TextView (this );
120
+ final int dialogTextId = ACRA .getConfig ().resDialogText ();
121
+ if (dialogTextId != 0 ) {
122
+ text .setText (getText (dialogTextId ));
123
+ }
124
+ return text ;
125
+ }
126
+
127
+ /**
128
+ * creates a comment prompt
129
+ *
130
+ * @param label the label of the prompt
131
+ * @param savedComment the content of the prompt (usually from a saved state)
132
+ * @return the comment prompt
133
+ */
134
+ protected EditText getCommentPrompt (CharSequence label , CharSequence savedComment ) {
135
+ final TextView labelView = new TextView (this );
136
+ labelView .setText (label );
137
+
138
+ labelView .setPadding (labelView .getPaddingLeft (), 10 , labelView .getPaddingRight (), labelView .getPaddingBottom ());
139
+ scrollable .addView (labelView , new LinearLayout .LayoutParams (LayoutParams .FILL_PARENT , LayoutParams .WRAP_CONTENT ));
140
+
141
+ EditText userCommentView = new EditText (this );
142
+ userCommentView .setLines (2 );
143
+ if (savedComment != null ) {
144
+ userCommentView .setText (savedComment );
145
+ }
146
+ return userCommentView ;
147
+ }
148
+
149
+ /**
150
+ * creates an email prompt
151
+ *
152
+ * @param label the label of the prompt
153
+ * @param savedEmail the content of the prompt (usually from a saved state)
154
+ * @return the email prompt
155
+ */
156
+ protected EditText getEmailPrompt (CharSequence label , CharSequence savedEmail ) {
157
+ final TextView labelView = new TextView (this );
158
+ labelView .setText (label );
159
+
160
+ labelView .setPadding (labelView .getPaddingLeft (), 10 , labelView .getPaddingRight (), labelView .getPaddingBottom ());
161
+ scrollable .addView (labelView );
162
+
163
+ EditText userEmailView = new EditText (this );
164
+ userEmailView .setSingleLine ();
165
+ userEmailView .setInputType (InputType .TYPE_CLASS_TEXT | InputType .TYPE_TEXT_VARIATION_EMAIL_ADDRESS );
166
+
167
+ if (savedEmail != null ) {
168
+ userEmailView .setText (savedEmail );
169
+ } else {
170
+ final SharedPreferences prefs = ACRA .getACRASharedPreferences ();
171
+ userEmailView .setText (prefs .getString (ACRA .PREF_USER_EMAIL_ADDRESS , "" ));
172
+ }
173
+ return userEmailView ;
174
+ }
175
+
123
176
@ Override
124
177
public void onClick (DialogInterface dialog , int which ) {
125
178
if (which == DialogInterface .BUTTON_POSITIVE ) {
@@ -166,4 +219,11 @@ protected void onSaveInstanceState(Bundle outState) {
166
219
outState .putString (STATE_EMAIL , userEmailView .getText ().toString ());
167
220
}
168
221
}
222
+
223
+ /**
224
+ * @return the AlertDialog displayed by this Activity
225
+ */
226
+ protected AlertDialog getDialog () {
227
+ return mDialog ;
228
+ }
169
229
}
0 commit comments