public void show(KrollDict options) { AlertDialog dialog = (AlertDialog) dialogWrapper.getDialog(); if (dialog == null) { if (dialogWrapper.getActivity() == null) { TiBaseActivity dialogActivity = (TiBaseActivity) getCurrentActivity(); dialogWrapper.setActivity(new WeakReference<TiBaseActivity>(dialogActivity)); } // processProperties(proxy.getProperties()); getBuilder() .setOnCancelListener( new OnCancelListener() { @Override public void onCancel(DialogInterface dlg) { int cancelIndex = (proxy.hasProperty(TiC.PROPERTY_CANCEL)) ? TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_CANCEL)) : -1; Log.d( TAG, "onCancelListener called. Sending index: " + cancelIndex + ", hideOnClick: " + hideOnClick, Log.DEBUG_MODE); handleEvent(cancelIndex, false); if (hideOnClick == true) hide(null); } }); dialog = getBuilder().create(); dialog.setOnShowListener( new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { TiApplication.getInstance().cancelPauseEvent(); } }); dialog.setCancelable(hideOnClick); dialog.setCanceledOnTouchOutside(tapToDismiss); dialog.setOnKeyListener( new Dialog.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { if (proxy.hasListeners(TiC.EVENT_ANDROID_BACK)) { proxy.fireEvent(TiC.EVENT_ANDROID_BACK); } else if (hideOnClick) { handleEvent(cancelIndex, false); hide(null); } } return true; } }); // Initially apply accessibility properties here, the first time // the dialog actually becomes available. After this, propertyChanged // can also be used. ListView listView = dialog.getListView(); if (listView != null) { listView.setContentDescription(composeContentDescription()); int importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO; if (proxy != null) { Object propertyValue = proxy.getProperty(TiC.PROPERTY_ACCESSIBILITY_HIDDEN); if (propertyValue != null && TiConvert.toBoolean(propertyValue)) { importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO; } } ViewCompat.setImportantForAccessibility(listView, importance); } dialogWrapper.setDialog(dialog); builder = null; } try { Activity dialogActivity = dialogWrapper.getActivity(); if (dialogActivity != null && !dialogActivity.isFinishing()) { if (dialogActivity instanceof TiBaseActivity) { // add dialog to its activity so we can clean it up later to prevent memory leak. ((TiBaseActivity) dialogActivity).addDialog(dialogWrapper); dialog.show(); setButtonsListeners(dialog); fireEvent(TiC.EVENT_OPEN, null, false); } } else { dialog = null; Log.w( TAG, "Dialog activity is destroyed, unable to show dialog with message: " + TiConvert.toString(proxy.getProperty(TiC.PROPERTY_MESSAGE))); } } catch (Throwable t) { Log.w(TAG, "Context must have gone away: " + t.getMessage(), t); } }