42
42
import org .json .JSONObject ;
43
43
44
44
/** Dialog for displaying JS errors in an eye-catching form (red box). */
45
- /* package */ class RedBoxDialog extends Dialog implements AdapterView .OnItemClickListener {
45
+ /* package */ class RedBoxDialog implements AdapterView .OnItemClickListener {
46
46
47
47
private final DevSupportManager mDevSupportManager ;
48
48
private final DoubleTapReloadRecognizer mDoubleTapReloadRecognizer ;
49
49
private final @ Nullable RedBoxHandler mRedBoxHandler ;
50
+ private final View mContentView ;
51
+ private final Context mContext ;
50
52
53
+ private @ Nullable Dialog mDialog ;
51
54
private ListView mStackView ;
52
55
private Button mReloadJsButton ;
53
56
private Button mDismissButton ;
@@ -238,28 +241,25 @@ private static JSONObject stackFrameToJson(StackFrame frame) {
238
241
239
242
protected RedBoxDialog (
240
243
Context context , DevSupportManager devSupportManager , @ Nullable RedBoxHandler redBoxHandler ) {
241
- super (context , R .style .Theme_Catalyst_RedBox );
242
-
243
- requestWindowFeature (Window .FEATURE_NO_TITLE );
244
-
245
- setContentView (R .layout .redbox_view );
244
+ mContext = context ;
245
+ mContentView = (View ) LayoutInflater .from (context ).inflate (R .layout .redbox_view , null );
246
246
247
247
mDevSupportManager = devSupportManager ;
248
248
mDoubleTapReloadRecognizer = new DoubleTapReloadRecognizer ();
249
249
mRedBoxHandler = redBoxHandler ;
250
250
251
- mStackView = (ListView ) findViewById (R .id .rn_redbox_stack );
251
+ mStackView = (ListView ) mContentView . findViewById (R .id .rn_redbox_stack );
252
252
mStackView .setOnItemClickListener (this );
253
253
254
- mReloadJsButton = (Button ) findViewById (R .id .rn_redbox_reload_button );
254
+ mReloadJsButton = (Button ) mContentView . findViewById (R .id .rn_redbox_reload_button );
255
255
mReloadJsButton .setOnClickListener (
256
256
new View .OnClickListener () {
257
257
@ Override
258
258
public void onClick (View v ) {
259
259
mDevSupportManager .handleReloadJS ();
260
260
}
261
261
});
262
- mDismissButton = (Button ) findViewById (R .id .rn_redbox_dismiss_button );
262
+ mDismissButton = (Button ) mContentView . findViewById (R .id .rn_redbox_dismiss_button );
263
263
mDismissButton .setOnClickListener (
264
264
new View .OnClickListener () {
265
265
@ Override
@@ -269,12 +269,12 @@ public void onClick(View v) {
269
269
});
270
270
271
271
if (mRedBoxHandler != null && mRedBoxHandler .isReportEnabled ()) {
272
- mLoadingIndicator = (ProgressBar ) findViewById (R .id .rn_redbox_loading_indicator );
273
- mLineSeparator = (View ) findViewById (R .id .rn_redbox_line_separator );
274
- mReportTextView = (TextView ) findViewById (R .id .rn_redbox_report_label );
272
+ mLoadingIndicator = (ProgressBar ) mContentView . findViewById (R .id .rn_redbox_loading_indicator );
273
+ mLineSeparator = (View ) mContentView . findViewById (R .id .rn_redbox_line_separator );
274
+ mReportTextView = (TextView ) mContentView . findViewById (R .id .rn_redbox_report_label );
275
275
mReportTextView .setMovementMethod (LinkMovementMethod .getInstance ());
276
276
mReportTextView .setHighlightColor (Color .TRANSPARENT );
277
- mReportButton = (Button ) findViewById (R .id .rn_redbox_report_button );
277
+ mReportButton = (Button ) mContentView . findViewById (R .id .rn_redbox_report_button );
278
278
mReportButton .setOnClickListener (mReportButtonOnClickListener );
279
279
}
280
280
}
@@ -303,15 +303,39 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
303
303
AsyncTask .THREAD_POOL_EXECUTOR , (StackFrame ) mStackView .getAdapter ().getItem (position ));
304
304
}
305
305
306
- @ Override
307
306
public boolean onKeyUp (int keyCode , KeyEvent event ) {
308
307
if (keyCode == KeyEvent .KEYCODE_MENU ) {
309
308
mDevSupportManager .showDevOptionsDialog ();
310
309
return true ;
311
310
}
312
- if (mDoubleTapReloadRecognizer .didDoubleTapR (keyCode , getCurrentFocus ())) {
311
+ if (mDoubleTapReloadRecognizer .didDoubleTapR (keyCode , mDialog . getCurrentFocus ())) {
313
312
mDevSupportManager .handleReloadJS ();
314
313
}
315
- return super .onKeyUp (keyCode , event );
314
+ return mDialog .onKeyUp (keyCode , event );
315
+ }
316
+
317
+ public Context getContext () {
318
+ return mContext ;
319
+ }
320
+
321
+ public View getContentView () {
322
+ return mContentView ;
323
+ }
324
+
325
+ public boolean isShowing () {
326
+ return mDialog .isShowing ();
327
+ }
328
+
329
+ public void show () {
330
+ if (mDialog == null ) {
331
+ mDialog = new Dialog (mContext , R .style .Theme_Catalyst_RedBox );
332
+ mDialog .requestWindowFeature (Window .FEATURE_NO_TITLE );
333
+ }
334
+ mDialog .setContentView (mContentView );
335
+ mDialog .show ();
336
+ }
337
+
338
+ public void dismiss () {
339
+ mDialog .dismiss ();
316
340
}
317
341
}
0 commit comments