List of usage examples for android.app AlertDialog getButton
public Button getButton(int whichButton)
From source file:io.jari.geenstijl.Dialogs.LoginDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout final View view = inflater.inflate(R.layout.dialog_login, null); builder.setView(view)// w w w .j a va2s.c o m // Add action buttons .setPositiveButton(R.string.signin, null) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { LoginDialog.this.getDialog().cancel(); } }).setTitle(R.string.signin); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { //i wrote this code with a certain amount of alcohol in my blood, so i can't vouch for it's readability final View error = view.findViewById(R.id.error); final Button positive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); final Button negative = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE); positive.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { positive.setEnabled(false); negative.setEnabled(false); final TextView username = (TextView) view.findViewById(R.id.username); final TextView password = (TextView) view.findViewById(R.id.password); final View loading = view.findViewById(R.id.loading); username.setVisibility(View.GONE); password.setVisibility(View.GONE); loading.setVisibility(View.VISIBLE); error.setVisibility(View.GONE); alertDialog.setCancelable(false); new Thread(new Runnable() { public void run() { boolean success; try { success = API.logIn(username.getText().toString(), password.getText().toString(), LoginDialog.this.getActivity()); } catch (Exception e) { e.printStackTrace(); success = false; } alertDialog.setCancelable(true); if (!success) activity.runOnUiThread(new Runnable() { public void run() { username.setVisibility(View.VISIBLE); password.setVisibility(View.VISIBLE); error.setVisibility(View.VISIBLE); positive.setEnabled(true); negative.setEnabled(true); loading.setVisibility(View.GONE); } }); else activity.runOnUiThread(new Runnable() { public void run() { alertDialog.dismiss(); forceOptionsReload(); Crouton.makeText(activity, getString(R.string.loggedin, API.getUsername(activity)), Style.CONFIRM).show(); } }); } }).start(); } }); } }); return alertDialog; }
From source file:com.itude.mobile.mobbl.core.controller.util.MBBasicViewController.java
private void styleCloseButton() { final AlertDialog alertDialog = (AlertDialog) getDialog(); Button button = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL); if (button != null) { MBViewBuilderFactory.getInstance().getStyleHandler().styleCloseButtonDialog(button); }/*w w w . j a v a2 s. c o m*/ }
From source file:com.shalzz.attendance.fragment.CaptchaDialogFragment.java
@NonNull @Override/*from w w w . j a v a2 s.com*/ 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:com.ADORCE.controls.MainViewActivity.java
private void showThemeChooserDialog() { AlertDialog.Builder b = new AlertDialog.Builder(this); Adapter adapter = new ArrayAdapter<>(this, R.layout.simple_list_item_single_choice, getResources().getStringArray(R.array.theme_items)); b.setTitle(getString(R.string.theme_chooser_dialog_title)).setSingleChoiceItems((ListAdapter) adapter, PreferenceManager.getDefaultSharedPreferences(this).getInt("theme_prefs", 0), new DialogInterface.OnClickListener() { @Override//from w w w .ja v a 2s .co m public void onClick(DialogInterface dialog, int which) { //Invokes method initTheme(int) - next method based on chosen theme initTheme(which); } }); AlertDialog d = b.create(); d.show(); TypedValue typedValue = new TypedValue(); Resources.Theme theme = this.getTheme(); theme.resolveAttribute(R.attr.colorAccent, typedValue, true); Button cancel = d.getButton(AlertDialog.BUTTON_NEGATIVE); cancel.setTextColor(typedValue.data); Button ok = d.getButton(AlertDialog.BUTTON_POSITIVE); ok.setTextColor(typedValue.data); d.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg); ListView lv = d.getListView(); int paddingTop = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_top_padding)); int paddingBottom = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_bottom_padding)); lv.setPadding(0, paddingTop, 0, paddingBottom); }
From source file:org.sufficientlysecure.keychain.ui.dialog.CreateKeyDialogFragment.java
private void setOkButtonAvailability(AlertDialog alertDialog) { final Choice selectedAlgorithm = (Choice) mAlgorithmSpinner.getSelectedItem(); final int selectedKeySize = getSelectedKeyLength(); //Integer.parseInt((String) mKeySizeSpinner.getSelectedItem()); final int properKeyLength = getProperKeyLength(selectedAlgorithm.getId(), selectedKeySize); alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(properKeyLength > 0); }
From source file:id.satusatudua.sigap.ui.HelpingActivity.java
@Override public void onCaseClosed(Case theCase) { AlertDialog alertDialog = new AlertDialog.Builder(this).setIcon(R.mipmap.ic_launcher) .setTitle("Pelapor Selamat") .setMessage("Pelapor telah menyatakan bahwa dia selamat, terimakasih atas partisipasi anda.") .setPositiveButton("OK", (dialog, which) -> { startActivity(FeedbackCaseActivity.generateIntent(this, theCase)); dialog.dismiss();/*from ww w .j a v a 2 s .com*/ }).setCancelable(false).show(); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(this, R.color.colorPrimary)); alertDialog.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);/*from w w w . ja v a 2s . c om*/ 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: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);/* w ww . ja v a 2 s . c om*/ 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; }
From source file:im.vector.fragments.GroupsFragment.java
@Override public boolean onFabClick() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); View dialogView = getActivity().getLayoutInflater().inflate(R.layout.dialog_create_group, null); alertDialogBuilder.setView(dialogView); final EditText nameEditText = dialogView.findViewById(R.id.community_name_edit_text); final EditText idEditText = dialogView.findViewById(R.id.community_id_edit_text); final String hostName = mSession.getHomeServerConfig().getHomeserverUri().getHost(); TextView hsNameView = dialogView.findViewById(R.id.community_hs_name_text_view); hsNameView.setText(":" + hostName); // set dialog message alertDialogBuilder.setCancelable(false).setTitle(R.string.create_community) .setPositiveButton(R.string.create, new DialogInterface.OnClickListener() { @Override//from w ww .j a v a 2 s .com public void onClick(final DialogInterface dialog, final int which) { String localPart = idEditText.getText().toString().trim(); String groupName = nameEditText.getText().toString().trim(); mActivity.showWaitingView(); mGroupsManager.createGroup(localPart, groupName, new ApiCallback<String>() { private void onDone(String errorMessage) { if (null != getActivity()) { if (null != errorMessage) { Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_LONG).show(); } mActivity.hideWaitingView(); refreshGroups(); } } @Override public void onSuccess(String groupId) { onDone(null); } @Override public void onNetworkError(Exception e) { onDone(e.getLocalizedMessage()); } @Override public void onMatrixError(MatrixError e) { onDone(e.getLocalizedMessage()); } @Override public void onUnexpectedError(Exception e) { onDone(e.getLocalizedMessage()); } }); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); final Button createButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); idEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { createButton.setEnabled( MXSession.isGroupId("+" + idEditText.getText().toString().trim() + ":" + hostName)); } @Override public void afterTextChanged(Editable s) { } }); createButton.setEnabled(false); return true; }
From source file:com.danielme.muspyforandroid.activities.base.AbstractActivity.java
/** * <b>Call always after dialog.show!!!!!!!!!</b> * //from w ww. j a v a2 s . co m * @param alertDialog */ public void dialogStyle(AlertDialog alertDialog) { TextView textView = (TextView) alertDialog.findViewById(android.R.id.message); if (textView != null) { textView.setBackgroundDrawable(null); textView.setTextAppearance(this, R.style.muspydialogmessage); } Button button = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE); if (button != null) { button.setBackgroundDrawable(getResources().getDrawable(R.drawable.textbuttonselector)); } button = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); if (button != null) { button.setBackgroundDrawable(getResources().getDrawable(R.drawable.textbuttonselector)); } button = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL); if (button != null) { button.setBackgroundDrawable(getResources().getDrawable(R.drawable.textbuttonselector)); } }