List of usage examples for android.app AlertDialog setOnShowListener
public void setOnShowListener(@Nullable OnShowListener listener)
From source file:com.shalzz.attendance.fragment.CaptchaDialogFragment.java
@NonNull @Override/*from w ww. j av a 2 s. co m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); builder.setView(inflater.inflate(R.layout.captcha_dialog, null)).setTitle("Input Captcha") .setIcon(R.drawable.ic_menu_edit).setCancelable(true) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { mListener.onDialogPositiveClick(CaptchaDialogFragment.this); } }); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { EditText captxt = (EditText) alertDialog.findViewById(R.id.etCapTxt); Miscellaneous.showKeyboard(getActivity(), captxt); Button positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); positiveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EditText captxt = (EditText) alertDialog.findViewById(R.id.etCapTxt); if (captxt.getText().toString().length() != 6) { captxt.setError("Captcha must be of 6 digits"); Miscellaneous.showKeyboard(getActivity(), captxt); } else mListener.onDialogPositiveClick(CaptchaDialogFragment.this); } }); } }); return alertDialog; }
From source file:br.com.bioscada.apps.biotracks.fragments.ChooseActivityTypeDialogFragment.java
public static Dialog getDialog(final Activity activity, final String category, final ChooseActivityTypeCaller caller) { View view = activity.getLayoutInflater().inflate(R.layout.choose_activity_type, null); GridView gridView = (GridView) view.findViewById(R.id.choose_activity_type_grid_view); final View weightContainer = view.findViewById(R.id.choose_activity_type_weight_container); TextView weightLabel = (TextView) view.findViewById(R.id.choose_activity_type_weight_label); weightLabel.setText(PreferencesUtils.isMetricUnits(activity) ? R.string.description_weight_metric : R.string.description_weight_imperial); final TextView weight = (TextView) view.findViewById(R.id.choose_activity_type_weight); List<Integer> imageIds = new ArrayList<Integer>(); for (String iconValue : TrackIconUtils.getAllIconValues()) { imageIds.add(TrackIconUtils.getIconDrawable(iconValue)); }//w w w. j a v a 2s. c o m Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_track_airplane, options); int padding = 32; int width = options.outWidth + 2 * padding; int height = options.outHeight + 2 * padding; gridView.setColumnWidth(width); final ChooseActivityTypeImageAdapter imageAdapter = new ChooseActivityTypeImageAdapter(activity, imageIds, width, height, padding); gridView.setAdapter(imageAdapter); final String weightValue = StringUtils.formatWeight(PreferencesUtils.getWeightDisplayValue(activity)); final AlertDialog alertDialog = new AlertDialog.Builder(activity) .setNegativeButton(R.string.generic_cancel, null) .setPositiveButton(R.string.generic_ok, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { boolean newWeight = false; if (weightContainer.getVisibility() == View.VISIBLE) { String newValue = weight.getText().toString(); if (!newValue.equals(weightValue)) { newWeight = true; PreferencesUtils.storeWeightValue(activity, newValue); } } int selected = imageAdapter.getSelected(); caller.onChooseActivityTypeDone(TrackIconUtils.getAllIconValues().get(selected), newWeight); } }).setTitle(R.string.track_edit_activity_type_hint).setView(view).create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { int position = getPosition(activity, category); alertDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(position != -1); if (position != -1) { imageAdapter.setSelected(position); imageAdapter.notifyDataSetChanged(); } updateWeightContainer(weightContainer, position); weight.setText(weightValue); DialogUtils.setDialogTitleDivider(activity, alertDialog); } }); gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { alertDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(true); imageAdapter.setSelected(position); imageAdapter.notifyDataSetChanged(); updateWeightContainer(weightContainer, position); } }); return alertDialog; }
From source file:com.nks.nksmod.otaupdater.DownloadsActivity.java
private void showNoFlashDialog(String file) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.alert_install_title); builder.setMessage(getString(R.string.alert_noinstall_message, file)); builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override/*from w ww . ja v a 2 s .c o m*/ public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); }
From source file:com.nks.nksmod.otaupdater.DownloadsActivity.java
protected void showFlashDialog(final BaseInfo info) { if (PropUtils.getNoFlash()) { //can't flash programmatically, must flash manually showNoFlashDialog(info.getDownloadFileName()); }//w w w . j ava 2s . c o m String[] installOpts = getResources().getStringArray(R.array.install_options); final boolean[] selectedOpts = new boolean[installOpts.length]; selectedOpts[selectedOpts.length - 1] = true; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.alert_install_title); builder.setMultiChoiceItems(installOpts, selectedOpts, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { selectedOpts[which] = isChecked; } }); builder.setPositiveButton(R.string.install, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); AlertDialog.Builder builder = new AlertDialog.Builder(DownloadsActivity.this); builder.setTitle(R.string.alert_install_title); builder.setMessage(R.string.alert_install_message); builder.setPositiveButton(R.string.install, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { flashFiles(new String[] { info.getRecoveryFilePath() }, selectedOpts[0], selectedOpts[2], selectedOpts[1]); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); }
From source file:de.schildbach.wallet.ui.ReportIssueDialogFragment.java
@Override public Dialog onCreateDialog(final Bundle savedInstanceState) { final Bundle args = getArguments(); final int titleResId = args.getInt(KEY_TITLE); final int messageResId = args.getInt(KEY_MESSAGE); final String subject = args.getString(KEY_SUBJECT); final String contextualData = args.getString(KEY_CONTEXTUAL_DATA); final ReportIssueDialogBuilder builder = new ReportIssueDialogBuilder(activity, titleResId, messageResId) { @Override/* w w w. j a v a 2 s. c om*/ protected String subject() { return subject + ": " + WalletApplication.versionLine(application.packageInfo()); } @Override protected CharSequence collectApplicationInfo() throws IOException { final StringBuilder applicationInfo = new StringBuilder(); appendApplicationInfo(applicationInfo, application); return applicationInfo; } @Override protected CharSequence collectStackTrace() throws IOException { final StringBuilder stackTrace = new StringBuilder(); CrashReporter.appendSavedCrashTrace(stackTrace); return stackTrace.length() > 0 ? stackTrace : null; } @Override protected CharSequence collectDeviceInfo() throws IOException { final StringBuilder deviceInfo = new StringBuilder(); appendDeviceInfo(deviceInfo, activity); return deviceInfo; } @Override protected CharSequence collectContextualData() { return contextualData; } @Override protected CharSequence collectWalletDump() { return viewModel.wallet.getValue().toString(false, true, true, null); } }; final AlertDialog dialog = builder.create(); dialog.setOnShowListener(new OnShowListener() { @Override public void onShow(final DialogInterface d) { positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); positiveButton.setEnabled(false); viewModel.wallet.observe(ReportIssueDialogFragment.this, new Observer<Wallet>() { @Override public void onChanged(final Wallet wallet) { positiveButton.setEnabled(true); } }); } }); return dialog; }
From source file:de.spiritcroc.ownlog.ui.fragment.TagItemEditFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(activity); final View view = activity.getLayoutInflater().inflate(R.layout.tag_edit_item, null); mEditTagName = (EditText) view.findViewById(R.id.name_edit); mEditTagDescription = (EditText) view.findViewById(R.id.description_edit); boolean restoredValues = restoreValues(savedInstanceState); builder.setTitle(mAddItem ? R.string.title_tag_item_add : R.string.title_tag_item_edit).setView(view) .setPositiveButton(R.string.dialog_ok, null) .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { @Override// w w w . j a va2 s .com public void onClick(DialogInterface dialog, int which) { // Only dismiss (and hide keyboard) hideKeyboard(); } }); if (!mAddItem) { builder.setNeutralButton(R.string.dialog_delete, null); } final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { saveChanges(); } }); if (!mAddItem) { alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { promptDelete(); } }); } } }); if (!restoredValues) { // Edit text requires user interaction, so show keyboard alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); if (mAddItem) { initValues(); } else { loadContent(); } } return alertDialog; }
From source file:se.frikod.payday.DailyBudgetFragment.java
public void editBudgetItem(final View v, final int currentIndex) { LayoutInflater inflater = activity.getLayoutInflater(); final View dialogView = inflater.inflate(R.layout.daily_budget_edit_budget_item, null); AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext()); builder.setTitle(getString(R.string.edit_budget_item_title)); final BudgetItem budgetItem; final EditText titleView = (EditText) dialogView.findViewById(R.id.budget_item_title); final Spinner typeView = (Spinner) dialogView.findViewById(R.id.budget_item_type); final EditText amountView = (EditText) dialogView.findViewById(R.id.budget_item_amount); if (currentIndex == NEW_BUDGET_ITEM) { budgetItem = null;//from w ww . j a v a 2 s. c o m builder.setTitle(getString(R.string.add_budget_item_dialog_title)); builder.setPositiveButton(R.string.add_budget_item, null); } else { builder.setTitle(getString(R.string.edit_budget_item_title)); budgetItem = budget.budgetItems.get(currentIndex); String title = budgetItem.title; BigDecimal amount = budgetItem.amount; int type; if (amount.signum() < 0) { type = 0; amount = amount.negate(); } else { type = 1; } titleView.setText(title); typeView.setSelection(type); amountView.setText(amount.toString()); builder.setNeutralButton(getString(R.string.delete_budget_item_yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(100); budget.budgetItems.remove(currentIndex); budget.saveBudgetItems(); updateBudgetItems(); dialog.dismiss(); } }); builder.setPositiveButton(R.string.update_budget_item, null); } builder.setNegativeButton(getString(R.string.delete_budget_item_no), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); /* onClick listener for update needs to be setup like this to prevent closing dialog on error */ final AlertDialog d = builder.create(); d.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button b = d.getButton(AlertDialog.BUTTON_POSITIVE); assert b != null; b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { BigDecimal amount; try { amount = new BigDecimal(amountView.getText().toString()); if (typeView.getSelectedItemId() == 0) amount = amount.negate(); } catch (NumberFormatException e) { Toast.makeText(activity.getApplicationContext(), getString(R.string.new_budget_item_no_amount_specified), Toast.LENGTH_SHORT) .show(); return; } String title = titleView.getText().toString(); if (budgetItem != null) { budgetItem.amount = amount; budgetItem.title = title; } else { budget.budgetItems.add(new BudgetItem(title, amount)); } budget.saveBudgetItems(); updateBudgetItems(); d.dismiss(); } }); } }); d.setView(dialogView); d.show(); }
From source file:de.schildbach.wallet.ui.backup.BackupWalletDialogFragment.java
@Override public Dialog onCreateDialog(final Bundle savedInstanceState) { final View view = LayoutInflater.from(activity).inflate(R.layout.backup_wallet_dialog, null); passwordView = (EditText) view.findViewById(R.id.backup_wallet_dialog_password); passwordView.setText(null);/*w ww . j a va 2 s . c o m*/ passwordAgainView = (EditText) view.findViewById(R.id.backup_wallet_dialog_password_again); passwordAgainView.setText(null); passwordStrengthView = (TextView) view.findViewById(R.id.backup_wallet_dialog_password_strength); passwordMismatchView = view.findViewById(R.id.backup_wallet_dialog_password_mismatch); showView = (CheckBox) view.findViewById(R.id.backup_wallet_dialog_show); warningView = (TextView) view.findViewById(R.id.backup_wallet_dialog_warning_encrypted); final DialogBuilder builder = new DialogBuilder(activity); builder.setTitle(R.string.export_keys_dialog_title); builder.setView(view); // dummies, just to make buttons show builder.setPositiveButton(R.string.button_ok, null); builder.setNegativeButton(R.string.button_cancel, null); builder.setCancelable(false); final AlertDialog dialog = builder.create(); dialog.setOnShowListener(new OnShowListener() { @Override public void onShow(final DialogInterface d) { positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); positiveButton.setTypeface(Typeface.DEFAULT_BOLD); positiveButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { handleGo(); } }); negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE); negativeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { dismissAllowingStateLoss(); } }); passwordView.addTextChangedListener(textWatcher); passwordAgainView.addTextChangedListener(textWatcher); showView.setOnCheckedChangeListener(new ShowPasswordCheckListener(passwordView, passwordAgainView)); viewModel.wallet.observe(BackupWalletDialogFragment.this, new Observer<Wallet>() { @Override public void onChanged(final Wallet wallet) { warningView.setVisibility(wallet.isEncrypted() ? View.VISIBLE : View.GONE); } }); viewModel.password.observe(BackupWalletDialogFragment.this, new Observer<String>() { @Override public void onChanged(final String password) { passwordMismatchView.setVisibility(View.INVISIBLE); final int passwordLength = password.length(); passwordStrengthView.setVisibility(passwordLength > 0 ? View.VISIBLE : View.INVISIBLE); if (passwordLength < 6) { passwordStrengthView.setText(R.string.encrypt_keys_dialog_password_strength_weak); passwordStrengthView .setTextColor(getResources().getColor(R.color.fg_password_strength_weak)); } else if (passwordLength < 8) { passwordStrengthView.setText(R.string.encrypt_keys_dialog_password_strength_fair); passwordStrengthView .setTextColor(getResources().getColor(R.color.fg_password_strength_fair)); } else if (passwordLength < 10) { passwordStrengthView.setText(R.string.encrypt_keys_dialog_password_strength_good); passwordStrengthView.setTextColor(getResources().getColor(R.color.fg_less_significant)); } else { passwordStrengthView.setText(R.string.encrypt_keys_dialog_password_strength_strong); passwordStrengthView .setTextColor(getResources().getColor(R.color.fg_password_strength_strong)); } final boolean hasPassword = !password.isEmpty(); final boolean hasPasswordAgain = !passwordAgainView.getText().toString().trim().isEmpty(); if (positiveButton != null) positiveButton.setEnabled( viewModel.wallet.getValue() != null && hasPassword && hasPasswordAgain); } }); } }); return dialog; }
From source file:com.otaupdater.SettingsActivity.java
private void showGetProKeyDialog() { if (cfg.hasProKey()) return;//from w w w . j a v a 2 s . c om AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.settings_prokey_title); final boolean playServices = Utils.checkPlayServices(this); builder.setItems(playServices ? R.array.prokey_ops : R.array.prokey_ops_nomarket, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { which -= playServices ? 1 : 0; switch (which) { case -1: try { Bundle buyIntentBundle = service.getBuyIntent(3, getPackageName(), Config.PROKEY_SKU, "inapp", null); PendingIntent buyIntent = buyIntentBundle.getParcelable("BUY_INTENT"); if (buyIntent != null) startIntentSenderForResult(buyIntent.getIntentSender(), PROKEY_REQ_CODE, new Intent(), 0, 0, 0); } catch (Exception e) { Toast.makeText(SettingsActivity.this, R.string.prokey_error_init, Toast.LENGTH_SHORT).show(); } break; case 0: redeemProKey(); break; // case 1: // startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Config.SITE_BASE_URL + Config.DONATE_URL))); // break; } } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { onDialogClosed(dlg); } }); dlg.show(); }
From source file:de.schildbach.wallet.ui.send.RaiseFeeDialogFragment.java
@Override public Dialog onCreateDialog(final Bundle savedInstanceState) { final View view = LayoutInflater.from(activity).inflate(R.layout.raise_fee_dialog, null); messageView = (TextView) view.findViewById(R.id.raise_fee_dialog_message); passwordGroup = view.findViewById(R.id.raise_fee_dialog_password_group); passwordView = (EditText) view.findViewById(R.id.raise_fee_dialog_password); passwordView.setText(null);/*from w w w . j a v a 2 s . c o m*/ badPasswordView = view.findViewById(R.id.raise_fee_dialog_bad_password); final DialogBuilder builder = new DialogBuilder(activity); builder.setTitle(R.string.raise_fee_dialog_title); builder.setView(view); // dummies, just to make buttons show builder.setPositiveButton(R.string.raise_fee_dialog_button_raise, null); builder.setNegativeButton(R.string.button_dismiss, null); builder.setCancelable(false); final AlertDialog dialog = builder.create(); dialog.setCanceledOnTouchOutside(false); dialog.setOnShowListener(new OnShowListener() { @Override public void onShow(final DialogInterface d) { positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE); positiveButton.setTypeface(Typeface.DEFAULT_BOLD); positiveButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { handleGo(); } }); negativeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { dismissAllowingStateLoss(); } }); passwordView.addTextChangedListener(textWatcher); RaiseFeeDialogFragment.this.dialog = dialog; updateView(); } }); log.info("showing raise fee dialog"); return dialog; }