List of usage examples for android.app AlertDialog dismiss
@Override public void dismiss()
From source file:Main.java
public static AlertDialog showAlertMessage(String title, String message, Context context) { final AlertDialog alertDialog = new AlertDialog.Builder(context).create(); alertDialog.setTitle(title);//from w w w . ja v a2 s . c o m alertDialog.setMessage(message); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { alertDialog.dismiss(); } }); alertDialog.show(); return alertDialog; }
From source file:com.spoiledmilk.cykelsuperstier.navigation.SMRouteNavigationActivity.java
public static void showRouteNoBreakDialog(final Context context, AlertDialog dialog) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(CykelsuperstierApplication.getString("no_route")); builder.setMessage(CykelsuperstierApplication.getString("cannot_broken")); builder.setPositiveButton("OK", new OnClickListener() { @Override/*from w w w .ja va 2 s . c o m*/ public void onClick(DialogInterface dialog, int arg1) { dialog.dismiss(); } }); dialog = builder.create(); dialog.setCancelable(false); dialog.show(); }
From source file:com.cw.litenote.folder.FolderUi.java
public static void addNewFolder(final AppCompatActivity act, final int newTableId, final SimpleDragSortCursorAdapter folderAdapter) { // get folder name final String hintFolderName = act.getResources().getString(R.string.default_folder_name) .concat(String.valueOf(newTableId)); // get layout inflater View rootView = act.getLayoutInflater().inflate(R.layout.add_new_folder, null); final TouchableEditText editFolderName = (TouchableEditText) rootView.findViewById(R.id.new_folder_name); // set cursor try {// w ww . jav a2 s . c o m Field f = TextView.class.getDeclaredField("mCursorDrawableRes"); f.setAccessible(true); f.set(editFolderName, R.drawable.cursor); } catch (Exception ignored) { } // set hint editFolderName.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { ((EditText) v).setHint(hintFolderName); } } }); editFolderName.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { ((EditText) v).setText(hintFolderName); ((EditText) v).setSelection(hintFolderName.length()); v.performClick(); return false; } }); // radio buttons final RadioGroup mRadioGroup = (RadioGroup) rootView.findViewById(R.id.radioGroup_new_folder_at); // get new folder location option mPref_add_new_folder_location = act.getSharedPreferences("add_new_folder_option", 0); if (mPref_add_new_folder_location.getString("KEY_ADD_NEW_FOLDER_TO", "bottom").equalsIgnoreCase("top")) { mRadioGroup.check(mRadioGroup.getChildAt(0).getId()); mAddFolderAt = 0; } else if (mPref_add_new_folder_location.getString("KEY_ADD_NEW_FOLDER_TO", "bottom") .equalsIgnoreCase("bottom")) { mRadioGroup.check(mRadioGroup.getChildAt(1).getId()); mAddFolderAt = 1; } // update new folder location option mRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup RG, int id) { mAddFolderAt = mRadioGroup.indexOfChild(mRadioGroup.findViewById(id)); if (mAddFolderAt == 0) { mPref_add_new_folder_location.edit().putString("KEY_ADD_NEW_FOLDER_TO", "top").apply(); } else if (mAddFolderAt == 1) { mPref_add_new_folder_location.edit().putString("KEY_ADD_NEW_FOLDER_TO", "bottom").apply(); } } }); // set view to dialog Builder builder1 = new Builder(act); builder1.setView(rootView); final AlertDialog dialog1 = builder1.create(); dialog1.show(); // cancel button Button btnCancel = (Button) rootView.findViewById(R.id.new_folder_cancel); btnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog1.dismiss(); } }); // add button Button btnAdd = (Button) rootView.findViewById(R.id.new_folder_add); btnAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DB_drawer db_drawer = new DB_drawer(act); String folderTitle; if (!Util.isEmptyString(editFolderName.getText().toString())) folderTitle = editFolderName.getText().toString(); else folderTitle = act.getResources().getString(R.string.default_folder_name) .concat(String.valueOf(newTableId)); MainAct.mFolderTitles.add(folderTitle); // insert new drawer Id and Title db_drawer.insertFolder(newTableId, folderTitle, true); // insert folder table db_drawer.insertFolderTable(newTableId, true); // insert initial page table after Add new folder if (Define.INITIAL_PAGES_COUNT > 0) { for (int i = 1; i <= Define.INITIAL_PAGES_COUNT; i++) { DB_folder dB_folder = new DB_folder(act, newTableId); int style = Util.getNewPageStyle(act); dB_folder.insertPage(DB_folder.getFocusFolder_tableName(), Define.getTabTitle(act, 1), i, style, true); dB_folder.insertPageTable(dB_folder, newTableId, i, true); } } // add new folder to the top if (mAddFolderAt == 0) { int startCursor = db_drawer.getFoldersCount(true) - 1; int endCursor = 0; //reorder data base storage for ADD_NEW_TO_TOP option int loop = Math.abs(startCursor - endCursor); for (int i = 0; i < loop; i++) { swapFolderRows(startCursor, endCursor); if ((startCursor - endCursor) > 0) endCursor++; else endCursor--; } // update focus folder position if (db_drawer.getFoldersCount(true) == 1) setFocus_folderPos(0); else setFocus_folderPos(getFocus_folderPos() + 1); // update focus folder table Id for Add to top Pref.setPref_focusView_folder_tableId(act, db_drawer.getFolderTableId(getFocus_folderPos(), true)); // update playing highlight if needed if (BackgroundAudioService.mMediaPlayer != null) MainAct.mPlaying_folderPos++; } // recover focus folder table Id DB_folder.setFocusFolder_tableId(Pref.getPref_focusView_folder_tableId(act)); folderAdapter.notifyDataSetChanged(); //end dialog1.dismiss(); updateFocus_folderPosition(); MainAct.mAct.invalidateOptionsMenu(); } }); }
From source file:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java
/** * Display a dialog warning the user that goodreads authentication is required; gives them * the options: 'request now', 'more info' or 'cancel'. *///from w w w . ja v a 2 s.c om public static int goodreadsAuthAlert(final FragmentActivity context) { // Get the title final AlertDialog alertDialog = new AlertDialog.Builder(context).setTitle(R.string.authorize_access) .setMessage(R.string.goodreads_action_cannot_blah_blah).create(); alertDialog.setIcon(android.R.drawable.ic_menu_info_details); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { alertDialog.dismiss(); GoodreadsRegister.requestAuthorizationInBackground(context); } }); alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, context.getResources().getString(R.string.tell_me_more), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { alertDialog.dismiss(); Intent i = new Intent(context, GoodreadsRegister.class); context.startActivity(i); } }); alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { alertDialog.dismiss(); } }); alertDialog.show(); return 0; }
From source file:nya.miku.wishmaster.http.cloudflare.CloudflareUIHandler.java
/** * ?-? Cloudflare.//from w ww . j a va 2 s . c o m * * @param e ? {@link CloudflareException} * @param chan * @param activity ?, ? ( ? ? ), * ? ? WebView ? Anti DDOS ? javascript. * ??? ? UI ({@link Activity#runOnUiThread(Runnable)}) * @param cfTask ?? * @param callback ? {@link Callback} */ static void handleCloudflare(final CloudflareException e, final HttpChanModule chan, final Activity activity, final CancellableTask cfTask, final InteractiveException.Callback callback) { if (cfTask.isCancelled()) return; if (!e.isRecaptcha()) { // ? anti DDOS if (!CloudflareChecker.getInstance().isAvaibleAntiDDOS()) { //? ? ?? , ? ? ? // ?, ? ChanModule, // ? ? () cloudflare ? ? // ? ? ? ? ? CloudflareChecker while (!CloudflareChecker.getInstance().isAvaibleAntiDDOS()) Thread.yield(); if (!cfTask.isCancelled()) activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onSuccess(); } }); return; } Cookie cfCookie = CloudflareChecker.getInstance().checkAntiDDOS(e, chan.getHttpClient(), cfTask, activity); if (cfCookie != null) { chan.saveCookie(cfCookie); if (!cfTask.isCancelled()) { activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onSuccess(); } }); } } else if (!cfTask.isCancelled()) { activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onError(activity.getString(R.string.error_cloudflare_antiddos)); } }); } } else { // ? final Recaptcha recaptcha; try { recaptcha = CloudflareChecker.getInstance().getRecaptcha(e, chan.getHttpClient(), cfTask); } catch (RecaptchaException recaptchaException) { if (!cfTask.isCancelled()) activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onError(activity.getString(R.string.error_cloudflare_get_captcha)); } }); return; } if (!cfTask.isCancelled()) activity.runOnUiThread(new Runnable() { @SuppressLint("InflateParams") @Override public void run() { Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? new ContextThemeWrapper(activity, R.style.Neutron_Medium) : activity; View view = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_cloudflare_captcha, null); ImageView captchaView = (ImageView) view.findViewById(R.id.dialog_captcha_view); final EditText captchaField = (EditText) view.findViewById(R.id.dialog_captcha_field); captchaView.setImageBitmap(recaptcha.bitmap); DialogInterface.OnClickListener process = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (cfTask.isCancelled()) return; PriorityThreadFactory.LOW_PRIORITY_FACTORY.newThread(new Runnable() { @Override public void run() { String answer = captchaField.getText().toString(); Cookie cfCookie = CloudflareChecker.getInstance().checkRecaptcha(e, (ExtendedHttpClient) chan.getHttpClient(), cfTask, recaptcha.challenge, answer); if (cfCookie != null) { chan.saveCookie(cfCookie); if (!cfTask.isCancelled()) { activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onSuccess(); } }); } } else { // (?, , ) handleCloudflare(e, chan, activity, cfTask, callback); } } }).start(); } }; DialogInterface.OnCancelListener onCancel = new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { callback.onError(activity.getString(R.string.error_cloudflare_cancelled)); } }; if (cfTask.isCancelled()) return; final AlertDialog recaptchaDialog = new AlertDialog.Builder(dialogContext).setView(view) .setPositiveButton(R.string.dialog_cloudflare_captcha_check, process) .setOnCancelListener(onCancel).create(); recaptchaDialog.getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); recaptchaDialog.setCanceledOnTouchOutside(false); recaptchaDialog.show(); captchaView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { recaptchaDialog.dismiss(); if (cfTask.isCancelled()) return; PriorityThreadFactory.LOW_PRIORITY_FACTORY.newThread(new Runnable() { @Override public void run() { handleCloudflare(e, chan, activity, cfTask, callback); } }).start(); } }); } }); } }
From source file:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java
public static void needLibraryThingAlert(final Context context, final boolean ltRequired, final String prefSuffix) { boolean showAlert; int msgId;// w w w . jav a2 s .c om final String prefName = LibraryThingManager.LT_HIDE_ALERT_PREF_NAME + "_" + prefSuffix; if (!ltRequired) { msgId = R.string.uses_library_thing_info; SharedPreferences prefs = context.getSharedPreferences("bookCatalogue", android.content.Context.MODE_PRIVATE); showAlert = !prefs.getBoolean(prefName, false); } else { msgId = R.string.require_library_thing_info; showAlert = true; } if (!showAlert) return; final AlertDialog dlg = new AlertDialog.Builder(context).setMessage(msgId).create(); dlg.setTitle(R.string.reg_library_thing_title); dlg.setIcon(android.R.drawable.ic_menu_info_details); dlg.setButton(DialogInterface.BUTTON_POSITIVE, context.getResources().getString(R.string.more_info), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent i = new Intent(context, AdministrationLibraryThing.class); context.startActivity(i); dlg.dismiss(); } }); if (!ltRequired) { dlg.setButton(DialogInterface.BUTTON_NEUTRAL, context.getResources().getString(R.string.disable_dialogue), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { SharedPreferences prefs = context.getSharedPreferences("bookCatalogue", android.content.Context.MODE_PRIVATE); SharedPreferences.Editor ed = prefs.edit(); ed.putBoolean(prefName, true); ed.commit(); dlg.dismiss(); } }); } dlg.setButton(DialogInterface.BUTTON_NEGATIVE, context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dlg.dismiss(); } }); dlg.show(); }
From source file:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java
public static void deleteSeriesAlert(Context context, final CatalogueDBAdapter dbHelper, final Series series, final Runnable onDeleted) { // When we get here, we know the names are genuinely different and the old series is used in more than one place. String message = "Delete series"; try {//ww w .jav a2 s . c om message = String.format(context.getResources().getString(R.string.really_delete_series), series.name); } catch (NullPointerException e) { Logger.logError(e); } final AlertDialog alertDialog = new AlertDialog.Builder(context).setMessage(message).create(); alertDialog.setTitle(R.string.delete_series); alertDialog.setIcon(android.R.drawable.ic_menu_info_details); //alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { alertDialog.setButton2(context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dbHelper.deleteSeries(series); alertDialog.dismiss(); onDeleted.run(); } }); //alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { alertDialog.setButton(context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { alertDialog.dismiss(); } }); alertDialog.show(); }
From source file:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java
public static int deleteBookAlert(Context context, final CatalogueDBAdapter dbHelper, final long id, final Runnable onDeleted) { ArrayList<Author> authorList = dbHelper.getBookAuthorList(id); String title;// w ww.jav a 2s . c o m Cursor cur = dbHelper.fetchBookById(id); try { if (cur == null || !cur.moveToFirst()) return R.string.unable_to_find_book; title = cur.getString(cur.getColumnIndex(CatalogueDBAdapter.KEY_TITLE)); if (title == null || title.length() == 0) title = "<Unknown>"; } finally { if (cur != null) cur.close(); } // Format the list of authors nicely String authors; if (authorList.size() == 0) authors = "<Unknown>"; else { authors = authorList.get(0).getDisplayName(); for (int i = 1; i < authorList.size() - 1; i++) { authors += ", " + authorList.get(i).getDisplayName(); } if (authorList.size() > 1) authors += " " + context.getResources().getString(R.string.list_and) + " " + authorList.get(authorList.size() - 1).getDisplayName(); } // Get the title String format = context.getResources().getString(R.string.really_delete_book); String message = String.format(format, title, authors); final AlertDialog alertDialog = new AlertDialog.Builder(context).setMessage(message).create(); alertDialog.setTitle(R.string.menu_delete); alertDialog.setIcon(android.R.drawable.ic_menu_info_details); //alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { alertDialog.setButton2(context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dbHelper.deleteBook(id); alertDialog.dismiss(); onDeleted.run(); } }); //alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { alertDialog.setButton(context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { alertDialog.dismiss(); } }); alertDialog.show(); return 0; }
From source file:com.otaupdater.utils.UserUtils.java
public static void showLoginDialog(final Context ctx, String defUsername, final DialogCallback dlgCallback, final LoginCallback loginCallback) { @SuppressLint("InflateParams") View view = LayoutInflater.from(ctx).inflate(R.layout.login_dialog, null); if (view == null) return;/* www . j a va2s . c o m*/ final EditText inputUsername = (EditText) view.findViewById(R.id.auth_username); final EditText inputPassword = (EditText) view.findViewById(R.id.auth_password); if (defUsername != null) inputUsername.setText(defUsername); AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setTitle(R.string.alert_login_title); builder.setView(view); builder.setPositiveButton(R.string.login, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { /* set below */ } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (loginCallback != null) loginCallback.onCancel(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { if (dlgCallback != null) dlgCallback.onDialogShown(dlg); Button button = dlg.getButton(DialogInterface.BUTTON_POSITIVE); if (button == null) return; button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String username = inputUsername.getText().toString(); final String password = inputPassword.getText().toString(); if (username.length() == 0 || password.length() == 0) { Toast.makeText(ctx, R.string.toast_blank_userpass_error, Toast.LENGTH_LONG).show(); return; } dlg.dismiss(); APIUtils.userLogin(ctx, username, password, new APIUtils.ProgressDialogAPICallback(ctx, ctx.getString(R.string.alert_logging_in), dlgCallback) { @Override public void onSuccess(String message, JSONObject respObj) { try { String realUsername = respObj.getString("username"); String hmacKey = respObj.getString("key"); Config.getInstance(ctx).storeLogin(realUsername, hmacKey); if (loginCallback != null) loginCallback.onLoggedIn(realUsername); } catch (JSONException e) { e.printStackTrace(); } } @Override public void onError(String message, JSONObject respObj) { //TODO show some error } }); } }); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (dlgCallback != null) dlgCallback.onDialogClosed(dlg); } }); dlg.show(); }
From source file:com.github.andrewlord1990.materialandroidsample.color.ColorChooserDialog.java
@NonNull @Override// www .j a va 2 s . co m public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog dialog = new AlertDialog.Builder(getContext()).setTitle(title) .setPositiveButton(R.string.sample_color_chooser_cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create(); dialog.setView(setupCustomView(dialog)); return dialog; }