Java Code Examples for androidx.appcompat.app.AlertDialog#getButton()
The following examples show how to use
androidx.appcompat.app.AlertDialog#getButton() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FirstRunDialogFragment.java From SecondScreen with Apache License 2.0 | 6 votes |
private void startCountdown(AlertDialog dialog) { if(!isStarted) return; Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE); if(secondsLeft == 0) { button.setEnabled(true); button.setText(getString(R.string.accept)); return; } button.setEnabled(false); button.setText(getString(R.string.accept_alt, secondsLeft)); secondsLeft--; new Handler().postDelayed(() -> startCountdown(dialog), 1000); }
Example 2
Source File: AppSettingsDialogTest.java From easypermissions with Apache License 2.0 | 6 votes |
@Test public void shouldNegativeListener_whenClickingPositiveButtonFromSupportFragment() { AlertDialog alertDialog = new AppSettingsDialog.Builder(spyFragment) .setTitle(TITLE) .setRationale(RATIONALE) .setPositiveButton(POSITIVE) .setNegativeButton(NEGATIVE) .setThemeResId(R.style.Theme_AppCompat) .build() .showDialog(positiveListener, negativeListener); Button positive = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE); positive.performClick(); verify(negativeListener, times(1)) .onClick(any(DialogInterface.class), anyInt()); }
Example 3
Source File: AppSettingsDialogTest.java From easypermissions with Apache License 2.0 | 6 votes |
@Test public void shouldNegativeListener_whenClickingPositiveButtonFromActivity() { AlertDialog alertDialog = new AppSettingsDialog.Builder(spyActivity) .setTitle(TITLE) .setRationale(RATIONALE) .setPositiveButton(POSITIVE) .setNegativeButton(NEGATIVE) .setThemeResId(R.style.Theme_AppCompat) .build() .showDialog(positiveListener, negativeListener); Button positive = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE); positive.performClick(); verify(negativeListener, times(1)) .onClick(any(DialogInterface.class), anyInt()); }
Example 4
Source File: AppSettingsDialogTest.java From easypermissions with Apache License 2.0 | 6 votes |
@Test public void shouldPositiveListener_whenClickingPositiveButtonFromActivity() { AlertDialog alertDialog = new AppSettingsDialog.Builder(spyActivity) .setTitle(TITLE) .setRationale(RATIONALE) .setPositiveButton(POSITIVE) .setNegativeButton(NEGATIVE) .setThemeResId(R.style.Theme_AppCompat) .build() .showDialog(positiveListener, negativeListener); Button positive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); positive.performClick(); verify(positiveListener, times(1)) .onClick(any(DialogInterface.class), anyInt()); }
Example 5
Source File: ATH.java From a with GNU General Public License v3.0 | 5 votes |
public static AlertDialog setAlertDialogTint(@NonNull AlertDialog dialog) { ColorStateList colorStateList = Selector.colorBuild() .setDefaultColor(ThemeStore.accentColor(dialog.getContext())) .setPressedColor(ColorUtil.darkenColor(ThemeStore.accentColor(dialog.getContext()))) .create(); if (dialog.getButton(androidx.appcompat.app.AlertDialog.BUTTON_NEGATIVE) != null) { dialog.getButton(androidx.appcompat.app.AlertDialog.BUTTON_NEGATIVE).setTextColor(colorStateList); } if (dialog.getButton(androidx.appcompat.app.AlertDialog.BUTTON_POSITIVE) != null) { dialog.getButton(androidx.appcompat.app.AlertDialog.BUTTON_POSITIVE).setTextColor(colorStateList); } return dialog; }
Example 6
Source File: MainActivity.java From arcgis-runtime-samples-android with Apache License 2.0 | 5 votes |
/** * Inflates the save map dialog allowing the user to enter title, tags and description for their map. */ private void showSaveMapDialog() { // inflate save map dialog layout LayoutInflater inflater = LayoutInflater.from(this); View saveMapDialogView = inflater.inflate(R.layout.save_map_dialog, null, false); // get references to edit text views EditText titleEditText = saveMapDialogView.findViewById(R.id.titleEditText); EditText tagsEditText = saveMapDialogView.findViewById(R.id.tagsEditText); EditText descriptionEditText = saveMapDialogView.findViewById(R.id.descriptionEditText); // build the dialog AlertDialog saveMapDialog = new AlertDialog.Builder(this) .setView(saveMapDialogView) .setPositiveButton(R.string.save_map, null) .setNegativeButton(R.string.cancel, null) .show(); // click handling for the save map button Button saveMapButton = saveMapDialog.getButton(DialogInterface.BUTTON_POSITIVE); saveMapButton.setOnClickListener(v -> { Iterable<String> tags = Arrays.asList(tagsEditText.getText().toString().split(",")); // make sure the title edit text view has text if (titleEditText.getText().length() > 0) { // call save map passing in title, tags and description saveMap(titleEditText.getText().toString(), tags, descriptionEditText.getText().toString()); saveMapDialog.dismiss(); } else { Toast.makeText(this, "A title is required to save your map.", Toast.LENGTH_LONG).show(); } }); // click handling for the cancel button Button cancelButton = saveMapDialog.getButton(DialogInterface.BUTTON_NEGATIVE); cancelButton.setOnClickListener(v -> saveMapDialog.dismiss()); }
Example 7
Source File: DownloadLabelsScene.java From EhViewer with Apache License 2.0 | 5 votes |
public NewLabelDialogHelper(EditTextDialogBuilder builder, AlertDialog dialog) { mBuilder = builder; mDialog = dialog; Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE); if (button != null) { button.setOnClickListener(this); } }
Example 8
Source File: EditItemDialog.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
private void updateOkButtonState(AlertDialog dialog, EditText editText) { Button buttonOK = dialog.getButton(DialogInterface.BUTTON_POSITIVE); if (editText == null || (editText.getText().toString().trim()).length() == 0) { buttonOK.setEnabled(false); return; } if (mTitle != null && !mTitle.equalsIgnoreCase(editText.getText().toString().trim())) { buttonOK.setEnabled(true); } else { editText.setError(getActivity().getString(R.string.err_no_edit)); buttonOK.setEnabled(false); } }
Example 9
Source File: UARTNewConfigurationDialogFragment.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override @NonNull public Dialog onCreateDialog(final Bundle savedInstanceState) { final Bundle args = requireArguments(); final String oldName = args.getString(NAME); final boolean duplicate = args.getBoolean(DUPLICATE); final int titleResId = duplicate || oldName == null ? R.string.uart_new_configuration_title : R.string.uart_rename_configuration_title; final LayoutInflater inflater = LayoutInflater.from(requireContext()); final View view = inflater.inflate(R.layout.feature_uart_dialog_new_configuration, null); final EditText editText = this.editText = view.findViewById(R.id.name); editText.setText(args.getString(NAME)); final View actionClear = view.findViewById(R.id.action_clear); actionClear.setOnClickListener(v -> editText.setText(null)); final AlertDialog dialog = new AlertDialog.Builder(requireContext()) .setTitle(titleResId) .setView(view) .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.ok, null) .setCancelable(false) .show(); // this must be show() or the getButton() below will return null. final Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE); okButton.setOnClickListener(this); return dialog; }
Example 10
Source File: ColorPickerDialog.java From ColorPicker with Apache License 2.0 | 5 votes |
@Override public void onStart() { super.onStart(); AlertDialog dialog = (AlertDialog) getDialog(); // http://stackoverflow.com/a/16972670/1048340 //noinspection ConstantConditions dialog.getWindow() .clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); // Do not dismiss the dialog when clicking the neutral button. Button neutralButton = dialog.getButton(AlertDialog.BUTTON_NEUTRAL); if (neutralButton != null) { neutralButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { rootView.removeAllViews(); switch (dialogType) { case TYPE_CUSTOM: dialogType = TYPE_PRESETS; ((Button) v).setText(customButtonStringRes != 0 ? customButtonStringRes : R.string.cpv_custom); rootView.addView(createPresetsView()); break; case TYPE_PRESETS: dialogType = TYPE_CUSTOM; ((Button) v).setText(presetsButtonStringRes != 0 ? presetsButtonStringRes : R.string.cpv_presets); rootView.addView(createPickerView()); } } }); } }
Example 11
Source File: FilterActivity.java From EhViewer with Apache License 2.0 | 5 votes |
public void setDialog(AlertDialog dialog) { mDialog = dialog; mSpinner = (Spinner) ViewUtils.$$(dialog, R.id.spinner); mInputLayout = (TextInputLayout) ViewUtils.$$(dialog, R.id.text_input_layout); mEditText = mInputLayout.getEditText(); View button = dialog.getButton(DialogInterface.BUTTON_POSITIVE); if (null != button) { button.setOnClickListener(this); } }
Example 12
Source File: BatchBackupDialogFragment.java From SAI with GNU General Public License v3.0 | 5 votes |
private void bindDialog(AlertDialog dialog) { Button positiveButton = dialog.getButton(Dialog.BUTTON_POSITIVE); Button negativeButton = dialog.getButton(Dialog.BUTTON_NEGATIVE); positiveButton.setOnClickListener((v) -> { enqueueBackup(); }); mViewModel.getIsPreparing().observe(this, (isPreparing) -> { positiveButton.setVisibility(isPreparing ? View.GONE : View.VISIBLE); negativeButton.setVisibility(isPreparing ? View.GONE : View.VISIBLE); dialog.setMessage(isPreparing ? getString(R.string.backup_preparing) : getExportPromptText()); }); }
Example 13
Source File: DialogFragmentAuthenticationInput.java From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License | 5 votes |
@NonNull @Override public Dialog onCreateDialog(final Bundle savedInstanceState) { @SuppressLint("InflateParams") final View rootView = LayoutInflater.from(requireActivity()).inflate(R.layout.dialog_fragment_auth_input, null); ButterKnife.bind(this, rootView); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(requireContext()). setIcon(R.drawable.ic_lock_open_24dp). setTitle(getString(R.string.provisioner_authentication_title)). setView(rootView); updateAuthUI(alertDialogBuilder); final AlertDialog alertDialog = alertDialogBuilder.show(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.setCancelable(false); final Button button = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); if(button != null) { button.setOnClickListener(v -> { final String pin = pinInput.getEditableText().toString().trim(); if (validateInput(pin)) { ((ProvisionerInputFragmentListener) requireActivity()).onPinInputComplete(pin); dismiss(); } }); } return alertDialog; }
Example 14
Source File: LoadableContentView.java From CommonUtils with Apache License 2.0 | 5 votes |
private static void toggleButtons(@NonNull AlertDialog dialog, boolean enabled) { if (!dialog.isShowing()) return; dialog.setCancelable(enabled); Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE); if (button != null) button.setEnabled(enabled); button = dialog.getButton(AlertDialog.BUTTON_NEGATIVE); if (button != null) button.setEnabled(enabled); button = dialog.getButton(AlertDialog.BUTTON_NEUTRAL); if (button != null) button.setEnabled(enabled); }
Example 15
Source File: DownloadLabelsScene.java From MHViewer with Apache License 2.0 | 5 votes |
public RenameLabelDialogHelper(EditTextDialogBuilder builder, AlertDialog dialog, String originalLabel, int position) { mBuilder = builder; mDialog = dialog; mOriginalLabel = originalLabel; mPosition = position; Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE); if (button != null) { button.setOnClickListener(this); } }
Example 16
Source File: DownloadLabelsScene.java From MHViewer with Apache License 2.0 | 5 votes |
public NewLabelDialogHelper(EditTextDialogBuilder builder, AlertDialog dialog) { mBuilder = builder; mDialog = dialog; Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE); if (button != null) { button.setOnClickListener(this); } }
Example 17
Source File: FilterActivity.java From MHViewer with Apache License 2.0 | 5 votes |
public void setDialog(AlertDialog dialog) { mDialog = dialog; mSpinner = (Spinner) ViewUtils.$$(dialog, R.id.spinner); mInputLayout = (TextInputLayout) ViewUtils.$$(dialog, R.id.text_input_layout); mEditText = mInputLayout.getEditText(); View button = dialog.getButton(DialogInterface.BUTTON_POSITIVE); if (null != button) { button.setOnClickListener(this); } }
Example 18
Source File: DialogUtils.java From Field-Book with GNU General Public License v2.0 | 5 votes |
public static void setButtonSize(AlertDialog dialog) { int buttonSize = 19; Button buttonPos = dialog.getButton(AlertDialog.BUTTON_POSITIVE); buttonPos.setTextSize(buttonSize); Button buttonNeg = dialog.getButton(AlertDialog.BUTTON_NEGATIVE); buttonNeg.setTextSize(buttonSize); Button buttonNeu = dialog.getButton(AlertDialog.BUTTON_NEUTRAL); buttonNeu.setTextSize(buttonSize); }
Example 19
Source File: CreatePublicChannelDialog.java From Pix-Art-Messenger with GNU General Public License v3.0 | 4 votes |
private void updateButtons(AlertDialog dialog) { final Button positive = dialog.getButton(DialogInterface.BUTTON_POSITIVE); final Button negative = dialog.getButton(DialogInterface.BUTTON_NEGATIVE); positive.setText(nameEntered ? R.string.create : R.string.next); negative.setText(nameEntered ? R.string.back : R.string.cancel); }
Example 20
Source File: UARTEditDialog.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 4 votes |
@NonNull @Override public Dialog onCreateDialog(final Bundle savedInstanceState) { final LayoutInflater inflater = LayoutInflater.from(getActivity()); // Read button configuration final Bundle args = requireArguments(); final int index = args.getInt(ARG_INDEX); final String command = args.getString(ARG_COMMAND); final int eol = args.getInt(ARG_EOL); final int iconIndex = args.getInt(ARG_ICON_INDEX); final boolean active = true; // change to active by default activeIcon = iconIndex; // Create view final View view = inflater.inflate(R.layout.feature_uart_dialog_edit, null); final EditText field = this.field = view.findViewById(R.id.field); final GridView grid = view.findViewById(R.id.grid); final CheckBox checkBox = activeCheckBox = view.findViewById(R.id.active); checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> { field.setEnabled(isChecked); grid.setEnabled(isChecked); if (iconAdapter != null) iconAdapter.notifyDataSetChanged(); }); final RadioGroup eolGroup = this.eolGroup = view.findViewById(R.id.uart_eol); switch (Command.Eol.values()[eol]) { case CR_LF: eolGroup.check(R.id.uart_eol_cr_lf); break; case CR: eolGroup.check(R.id.uart_eol_cr); break; case LF: default: eolGroup.check(R.id.uart_eol_lf); break; } field.setText(command); field.setEnabled(active); checkBox.setChecked(active); grid.setOnItemClickListener(this); grid.setEnabled(active); grid.setAdapter(iconAdapter = new IconAdapter()); // As we want to have some validation we can't user the DialogInterface.OnClickListener as it's always dismissing the dialog. final AlertDialog dialog = new AlertDialog.Builder(requireContext()) .setCancelable(false) .setTitle(R.string.uart_edit_title) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .setView(view) .show(); final Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE); okButton.setOnClickListener(this); return dialog; }