List of usage examples for android.app AlertDialog.Builder setOnCancelListener
public void setOnCancelListener(@Nullable OnCancelListener listener)
From source file:org.apache.cordova.core.Notification.java
/** * Builds and shows a native Android confirm dialog with given title, message, buttons. * This dialog only shows up to 3 buttons. Any labels after that will be ignored. * The index of the button pressed will be returned to the JavaScript callback identified by callbackId. * * @param message The message the dialog should display * @param title The title of the dialog * @param buttonLabels A comma separated list of button labels (Up to 3 buttons) * @param callbackContext The callback context. *//*from w w w . j a v a2 s.c om*/ public synchronized void confirm(final String message, final String title, final JSONArray buttonLabels, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; Runnable runnable = new Runnable() { public void run() { AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity()); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(true); // First button if (buttonLabels.length() > 0) { try { dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 1)); } }); } catch (JSONException e) { } } // Second button if (buttonLabels.length() > 1) { try { dlg.setNeutralButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 2)); } }); } catch (JSONException e) { } } // Third button if (buttonLabels.length() > 2) { try { dlg.setPositiveButton(buttonLabels.getString(2), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 3)); } }); } catch (JSONException e) { } } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); } }); dlg.create(); dlg.show(); }; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:jp.watnow.plugins.dialog.Notification.java
/** * // w ww.j a v a 2 s. co m * @param message * @param title * @param buttonLabels * @param defaultTexts * @param callbackContext */ public synchronized void login(final String title, final String message, final JSONArray buttonLabels, final JSONArray defaultTexts, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; Runnable runnable = new Runnable() { public void run() { LinearLayout layout = new LinearLayout(cordova.getActivity()); layout.setOrientation(LinearLayout.VERTICAL); layout.setPadding(10, 0, 10, 0); final EditText usernameInput = new EditText(cordova.getActivity()); usernameInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL); final EditText passwordInput = new EditText(cordova.getActivity()); passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); try { usernameInput.setHint("ID"); usernameInput.setText(defaultTexts.getString(0)); passwordInput.setHint("PASSWORD"); passwordInput.setText(defaultTexts.getString(1)); } catch (JSONException e1) { } layout.addView(usernameInput, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); layout.addView(passwordInput, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(false); dlg.setView(layout); final JSONObject result = new JSONObject(); try { dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 1); result.put("input1", usernameInput.getText()); result.put("input2", passwordInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } try { dlg.setPositiveButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 3); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); try { result.put("buttonIndex", 0); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); changeTextDirection(dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:com.android.messaging.ui.conversation.ConversationFragment.java
void deleteMessage(final String messageId) { if (isReadyForAction()) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) .setTitle(R.string.delete_message_confirmation_dialog_title) .setMessage(R.string.delete_message_confirmation_dialog_text) .setPositiveButton(R.string.delete_message_confirmation_button, new OnClickListener() { @Override//from w w w . j a v a2s. c om public void onClick(final DialogInterface dialog, final int which) { mBinding.getData().deleteMessage(mBinding, messageId); } }).setNegativeButton(android.R.string.cancel, null); if (OsUtil.isAtLeastJB_MR1()) { builder.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(final DialogInterface dialog) { mHost.dismissActionMode(); } }); } else { builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(final DialogInterface dialog) { mHost.dismissActionMode(); } }); } builder.create().show(); } else { warnOfMissingActionConditions(false /*sending*/, null /*commandToRunAfterActionConditionResolved*/); mHost.dismissActionMode(); } }
From source file:org.apache.cordova.dialogs.Notification.java
/** * Builds and shows a native Android confirm dialog with given title, message, buttons. * This dialog only shows up to 3 buttons. Any labels after that will be ignored. * The index of the button pressed will be returned to the JavaScript callback identified by callbackId. * * @param message The message the dialog should display * @param title The title of the dialog * @param buttonLabels A comma separated list of button labels (Up to 3 buttons) * @param callbackContext The callback context. *//*w ww .jav a 2 s.c o m*/ public synchronized void confirm(final String message, final String title, final JSONArray buttonLabels, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; Runnable runnable = new Runnable() { public void run() { AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(true); // First button if (buttonLabels.length() > 0) { try { dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 1)); } }); } catch (JSONException e) { } } // Second button if (buttonLabels.length() > 1) { try { dlg.setNeutralButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 2)); } }); } catch (JSONException e) { } } // Third button if (buttonLabels.length() > 2) { try { dlg.setPositiveButton(buttonLabels.getString(2), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 3)); } }); } catch (JSONException e) { } } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); } }); changeTextDirection(dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:jp.watnow.plugins.dialog.Notification.java
/** * Builds and shows a native Android confirm dialog with given title, message, buttons. * This dialog only shows up to 3 buttons. Any labels after that will be ignored. * The index of the button pressed will be returned to the JavaScript callback identified by callbackId. * * @param message The message the dialog should display * @param title The title of the dialog * @param buttonLabels A comma separated list of button labels (Up to 3 buttons) * @param callbackContext The callback context. *//*from www . jav a 2s . c o m*/ public synchronized void confirm(final String message, final String title, final JSONArray buttonLabels, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; Runnable runnable = new Runnable() { public void run() { AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(false); // First button if (buttonLabels.length() > 0) { try { dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 1)); } }); } catch (JSONException e) { } } // Second button if (buttonLabels.length() > 1) { try { dlg.setNeutralButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 2)); } }); } catch (JSONException e) { } } // Third button if (buttonLabels.length() > 2) { try { dlg.setPositiveButton(buttonLabels.getString(2), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 3)); } }); } catch (JSONException e) { } } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); } }); changeTextDirection(dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:com.csipsimple.ui.favorites.FavAdapter.java
private void showDialogForGroupSelection(final Context context, final Long profileId, final String groupName) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.set_android_group); final Cursor choiceCursor = ContactsWrapper.getInstance().getGroups(context); int selectedIndex = -1; if (choiceCursor != null) { if (choiceCursor.moveToFirst()) { int i = 0; int colIdx = choiceCursor.getColumnIndex(ContactsWrapper.FIELD_GROUP_NAME); do {/*from w w w.j av a 2s. c om*/ String name = choiceCursor.getString(colIdx); if (!TextUtils.isEmpty(name) && name.equalsIgnoreCase(groupName)) { selectedIndex = i; break; } i++; } while (choiceCursor.moveToNext()); } } builder.setSingleChoiceItems(choiceCursor, selectedIndex, ContactsWrapper.FIELD_GROUP_NAME, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (choiceCursor != null) { choiceCursor.moveToPosition(which); String name = choiceCursor .getString(choiceCursor.getColumnIndex(ContactsWrapper.FIELD_GROUP_NAME)); ContentValues cv = new ContentValues(); cv.put(SipProfile.FIELD_ANDROID_GROUP, name); context.getContentResolver().update( ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, profileId), cv, null, null); choiceCursor.close(); } dialog.dismiss(); } }); builder.setCancelable(true); builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (choiceCursor != null) { choiceCursor.close(); } dialog.dismiss(); } }); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (choiceCursor != null) { choiceCursor.close(); } } }); final Dialog dialog = builder.create(); dialog.show(); }
From source file:org.kde.necessitas.ministro.MinistroActivity.java
private boolean checkFreeSpace(final long size) throws InterruptedException { final StatFs stat = new StatFs(m_qtLibsRootPath); if (stat.getBlockSize() * stat.getAvailableBlocks() < size) { runOnUiThread(new Runnable() { public void run() { AlertDialog.Builder builder = new AlertDialog.Builder(MinistroActivity.this); builder.setMessage(getResources().getString(R.string.ministro_disk_space_msg, (size - (stat.getBlockSize() * stat.getAvailableBlocks())) / 1024 + "Kb")); builder.setCancelable(true); builder.setNeutralButton(getResources().getString(R.string.settings_msg), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { try { startActivityForResult( new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS), freeSpaceCode); } catch (Exception e) { e.printStackTrace(); try { startActivityForResult( new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS), freeSpaceCode); } catch (Exception e1) { e1.printStackTrace(); }//ww w . j a v a 2 s . c om } } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); m_diskSpaceSemaphore.release(); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); m_diskSpaceSemaphore.release(); } }); m_distSpaceDialog = builder.create(); m_distSpaceDialog.show(); } }); m_diskSpaceSemaphore.acquire(); } else return true; return stat.getBlockSize() * stat.getAvailableBlocks() > size; }
From source file:com.remobile.dialogs.Notification.java
/** * Builds and shows a native Android confirm dialog with given title, message, buttons. * This dialog only shows up to 3 buttons. Any labels after that will be ignored. * The index of the button pressed will be returned to the JavaScript callback identified by callbackId. * * @param message The message the dialog should display * @param title The title of the dialog * @param buttonLabels A comma separated list of button labels (Up to 3 buttons) * @param callbackContext The callback context. *//* w w w. j av a 2s . c o m*/ public synchronized void confirm(final String message, final String title, final JSONArray buttonLabels, final CallbackContext callbackContext) { Runnable runnable = new Runnable() { public void run() { AlertDialog.Builder dlg = createDialog(); // new AlertDialog.Builder(this.cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(false); // First button if (buttonLabels.length() > 0) { try { dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 1)); } }); } catch (JSONException e) { } } // Second button if (buttonLabels.length() > 1) { try { dlg.setNeutralButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 2)); } }); } catch (JSONException e) { } } // Third button if (buttonLabels.length() > 2) { try { dlg.setPositiveButton(buttonLabels.getString(2), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 3)); } }); } catch (JSONException e) { } } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); } }); changeTextDirection(dlg); } ; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:com.android.mms.ui.MessageUtils.java
private static void confirmReadReportDialog(Context context, OnClickListener positiveListener, OnClickListener negativeListener, OnCancelListener cancelListener) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setCancelable(true);/* ww w . j a v a 2 s. co m*/ builder.setTitle(R.string.confirm); builder.setMessage(R.string.message_send_read_report); builder.setPositiveButton(R.string.yes, positiveListener); builder.setNegativeButton(R.string.no, negativeListener); builder.setOnCancelListener(cancelListener); builder.show(); }
From source file:com.todotxt.todotxttouch.TodoTxtTouch.java
@Override protected Dialog onCreateDialog(final int id) { m_swipeList.discardUndo();// ww w . jav a 2 s .c o m if (id == SYNC_CHOICE_DIALOG) { Log.v(TAG, "Time to show the sync choice dialog"); AlertDialog.Builder upDownChoice = new AlertDialog.Builder(this); upDownChoice.setTitle(R.string.sync_dialog_title); upDownChoice.setMessage(R.string.sync_dialog_msg); upDownChoice.setPositiveButton(R.string.sync_dialog_upload, new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { sendBroadcast(new Intent(Constants.INTENT_START_SYNC_TO_REMOTE) .putExtra(Constants.EXTRA_FORCE_SYNC, true)); // backgroundPushToRemote(); showToast(getString(R.string.sync_upload_message)); } }); upDownChoice.setNegativeButton(R.string.sync_dialog_download, new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { sendBroadcast(new Intent(Constants.INTENT_START_SYNC_FROM_REMOTE) .putExtra(Constants.EXTRA_FORCE_SYNC, true)); // backgroundPullFromRemote(); showToast(getString(R.string.sync_download_message)); } }); upDownChoice.setOnCancelListener(new OnCancelListener() { @SuppressWarnings("deprecation") @Override public void onCancel(DialogInterface dialog) { m_pullToRefreshAttacher.setRefreshComplete(); updateSyncUI(false); removeDialog(id); } }); return upDownChoice.create(); } else if (id == SYNC_CONFLICT_DIALOG) { Log.v(TAG, "Time to show the sync conflict dialog"); AlertDialog.Builder upDownChoice = new AlertDialog.Builder(this); upDownChoice.setTitle(R.string.sync_conflict_dialog_title); upDownChoice.setMessage(R.string.sync_conflict_dialog_msg); upDownChoice.setPositiveButton(R.string.sync_dialog_upload, new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { Log.v(TAG, "User selected PUSH"); sendBroadcast(new Intent(Constants.INTENT_START_SYNC_TO_REMOTE) .putExtra(Constants.EXTRA_OVERWRITE, true).putExtra(Constants.EXTRA_FORCE_SYNC, true)); // backgroundPushToRemote(); showToast(getString(R.string.sync_upload_message)); } }); upDownChoice.setNegativeButton(R.string.sync_dialog_download, new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { Log.v(TAG, "User selected PULL"); sendBroadcast(new Intent(Constants.INTENT_START_SYNC_FROM_REMOTE) .putExtra(Constants.EXTRA_FORCE_SYNC, true)); // backgroundPullFromRemote(); showToast(getString(R.string.sync_download_message)); } }); upDownChoice.setOnCancelListener(new OnCancelListener() { @SuppressWarnings("deprecation") @Override public void onCancel(DialogInterface dialog) { updateSyncUI(false); removeDialog(id); } }); return upDownChoice.create(); } else if (id == ARCHIVE_DIALOG) { AlertDialog.Builder archiveAlert = new AlertDialog.Builder(this); archiveAlert.setTitle(R.string.archive_now_title); archiveAlert.setMessage(R.string.archive_now_explainer); archiveAlert.setPositiveButton(R.string.archive_now_title, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { TodoTxtTouch.this.setResult(RESULT_OK); // produce a archive intent and broadcast it Intent broadcastArchiveIntent = new Intent(); broadcastArchiveIntent.setAction("com.todotxt.todotxttouch.ACTION_ARCHIVE"); sendBroadcast(broadcastArchiveIntent); } }); archiveAlert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @SuppressWarnings("deprecation") public void onClick(DialogInterface arg0, int arg1) { removeDialog(id); } }); archiveAlert.setOnCancelListener(new OnCancelListener() { @SuppressWarnings("deprecation") @Override public void onCancel(DialogInterface dialog) { removeDialog(id); } }); return archiveAlert.create(); } else { return null; } }