List of usage examples for android.app AlertDialog getButton
public Button getButton(int whichButton)
From source file:com.bt.heliniumstudentapp.DayActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() != R.id.i_hwfloating_md) return super.onOptionsItemSelected(item); final ScheduleFragment.week.day day_data = schedule.day_get(schedule.day_get_index(lastPosition) + 2); if (day_data.floatings_get() == 0) { Toast.makeText(this, getString(R.string.homework_floating_no), Toast.LENGTH_SHORT).show(); return true; }//from www .ja v a 2 s .c o m final AlertDialog.Builder hwf_dialog_builder = new AlertDialog.Builder( new ContextThemeWrapper(this, MainActivity.themeDialog)); AlertDialog hwf_dialog; StringBuilder s; int i; hwf_dialog_builder.setTitle(getString(R.string.homework_floating)); hwf_dialog_builder.setPositiveButton(android.R.string.ok, null); s = new StringBuilder(); for (i = 0; i < day_data.floatings_get(); i++) { s.append(day_data.floating_get(i).course); s.append("\n"); s.append(Html.fromHtml(day_data.floating_get(i).text)); } hwf_dialog_builder.setMessage(s.toString()); hwf_dialog = hwf_dialog_builder.create(); hwf_dialog.setCanceledOnTouchOutside(true); hwf_dialog.show(); hwf_dialog.getButton(AlertDialog.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(this, MainActivity.accentSecondaryColor)); return true; }
From source file:org.deviceconnect.android.deviceplugin.hue.activity.fragment.HueFragment04.java
/** * Edit serial./*from ww w . j av a 2 s . c o m*/ */ private void editSerial() { final EditText editText = new EditText(getActivity()); editText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { InputMethodManager inputMethodManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0); return true; } return false; } }); AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.frag04_serial_number_title) .setMessage(R.string.frag04_serial_number_message).setView(editText) .setPositiveButton(R.string.frag04_serial_ok, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int whichButton) { String serial = editText.getText().toString(); searchLightManually(serial); } }).setNegativeButton(R.string.frag04_serial_cancel, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int whichButton) { } }).show(); final Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE); positiveButton.setEnabled(false); // Input limit of the serial number InputFilter inputFilter = new InputFilter() { @Override public CharSequence filter(final CharSequence source, final int start, final int end, final Spanned dest, final int dstart, final int dend) { if (source.toString().matches("[0-9a-fA-F]+")) { return source; } else { return ""; } } }; InputFilter[] filters = new InputFilter[] { inputFilter, new InputFilter.LengthFilter(6) }; editText.setFilters(filters); editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) { } @Override public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { positiveButton.setEnabled(editText.length() == 6); } @Override public void afterTextChanged(final Editable s) { } }); editText.setHint(R.string.frag04_serial_number_hint); }
From source file:id.satusatudua.sigap.ui.fragment.TrustedsFragment.java
@OnClick(R.id.fab) public void addNewContact() { EditText editText = new EditText(getActivity()); editText.setHint("Email"); editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setIcon(R.mipmap.ic_launcher) .setTitle("Masukan alamat email kontak").setView(editText) .setPositiveButton("Kirim", (dialog, which) -> { String email = editText.getText().toString(); if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) { showError("Mohon masukan alamat email yang valid!"); } else if (email.equalsIgnoreCase(CacheManager.pluck().getCurrentUser().getEmail())) { showError("Mohon masukan alamat email selain email anda sendiri!"); } else { trustedUserPresenter.searchUser(email); KeyboardUtil.hideKeyboard(getActivity(), editText); dialog.dismiss();// www . j av a 2s. c om } }).setNegativeButton("Batal", (dialog, which1) -> { dialog.dismiss(); }).show(); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(getActivity(), R.color.primary_text)); alertDialog.show(); }
From source file:com.cuddlesoft.nori.fragment.EditAPISettingDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Get database row ID of the object being edited (if any) from the arguments bundle. if (getArguments() != null && getArguments().containsKey(BUNDLE_ID_ROW_ID)) { rowId = getArguments().getLong(BUNDLE_ID_ROW_ID); }/* w w w . j av a2s. com*/ // Inflate XML for the dialog's main view. LayoutInflater inflater = LayoutInflater.from(getActivity()); @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.dialog_edit_api_setting, null, false); // Get references to the parent view's subviews. name = (AutoCompleteTextView) view.findViewById(R.id.name); uri = (EditText) view.findViewById(R.id.uri); username = (EditText) view.findViewById(R.id.username); passphrase = (EditText) view.findViewById(R.id.passphrase); // Set service name autosuggestion adapter. name.setAdapter(new ArrayAdapter<>(getActivity(), R.layout.simple_dropdown_item, getResources().getStringArray(R.array.service_suggestions_names))); name.setThreshold(1); name.setOnItemClickListener(this); // Set service URI TextChangedListener to show optional authentication fields when the Danbooru endpoint is used. uri.addTextChangedListener(this); // Set service URI OnFocusChangeListener to prepend "http://" to the text field when the user clicks on it. uri.setOnFocusChangeListener(this); // Populate views from an existing SearchClient.Settings object, if it was passed in the arguments bundle. if (savedInstanceState == null && getArguments() != null && getArguments().containsKey(BUNDLE_ID_SETTINGS)) { // Get the SearchClient.Settings object from this fragment's arguments bundle. SearchClient.Settings settings = getArguments().getParcelable(BUNDLE_ID_SETTINGS); // Populate subviews with content. name.setText(settings.getName()); uri.setText(settings.getEndpoint()); username.setText(settings.getUsername()); passphrase.setText(settings.getPassword()); } // Dismiss dropdown when the view is first shown. name.dismissDropDown(); // Create the AlertDialog object. final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setView(view) .setTitle(rowId == -1 ? R.string.dialog_title_addService : R.string.dialog_title_editService) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { // Dismiss dialog without saving changes. dismiss(); } }).create(); // Use OnShowListener to override positive button behaviour. alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { // OnShowListener here is used as a hack to override Android Dialog's default OnClickListener // that doesn't provide a way to prevent the dialog from getting dismissed when a button is clicked. alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setOnClickListener(EditAPISettingDialogFragment.this); } }); return alertDialog; }
From source file:org.mitre.svmp.activities.SvmpActivity.java
protected void passwordChangePrompt(final ConnectionInfo connectionInfo) { // if this connection uses password authentication, proceed if ((connectionInfo.getAuthType() & PasswordModule.AUTH_MODULE_ID) == PasswordModule.AUTH_MODULE_ID) { // the service is running for this connection, stop it so we can re-authenticate if (SessionService.isRunningForConn(connectionInfo.getConnectionID())) stopService(new Intent(SvmpActivity.this, SessionService.class)); // create the input container final LinearLayout inputContainer = (LinearLayout) getLayoutInflater().inflate(R.layout.auth_prompt, null);/*from w w w . j a v a2s . co m*/ // set the message TextView message = (TextView) inputContainer.findViewById(R.id.authPrompt_textView_message); message.setText(connectionInfo.getUsername()); final HashMap<IAuthModule, View> moduleViewMap = new HashMap<IAuthModule, View>(); // populate module view map, add input views for each required auth module // (we know at least password input is required) addAuthModuleViews(connectionInfo, moduleViewMap, inputContainer); // loop through the Auth module(s) to find the View for the old password input (needed for validation) View oldPasswordView = null; for (Map.Entry<IAuthModule, View> entry : moduleViewMap.entrySet()) { if (entry.getKey().getID() == PasswordModule.AUTH_MODULE_ID) { oldPasswordView = entry.getValue(); break; } } // add "new password" and "confirm new password" views final PasswordChangeModule module = new PasswordChangeModule(oldPasswordView); View moduleView = module.generateUI(this); moduleViewMap.put(module, moduleView); inputContainer.addView(moduleView); // create a dialog final AlertDialog dialog = new AlertDialog.Builder(SvmpActivity.this).setCancelable(false) .setTitle(R.string.authPrompt_title_passwordChange).setView(inputContainer) .setPositiveButton(R.string.authPrompt_button_positive_text, null).setNegativeButton( R.string.authPrompt_button_negative_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { busy = false; } }) .create(); // override positive button dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface d) { Button positive = dialog.getButton(AlertDialog.BUTTON_POSITIVE); if (positive != null) { positive.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // before continuing, validate the new password inputs int resId = module.areInputsValid(); if (resId == 0) { dialog.dismiss(); // inputs are valid, dismiss the dialog startAppRTCWithAuth(connectionInfo, moduleViewMap); } else { // tell the user that the new password is not valid toastShort(resId); } } }); } } }); // show the dialog dialog.show(); // request keyboard dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } }
From source file:io.github.tjg1.nori.fragment.EditAPISettingDialogFragment.java
@NonNull @Override// www.j a v a2 s . c om public Dialog onCreateDialog(Bundle savedInstanceState) { // Get database row ID of the object being edited (if any) from the arguments bundle. if (getArguments() != null && getArguments().containsKey(BUNDLE_ID_ROW_ID)) { rowId = getArguments().getLong(BUNDLE_ID_ROW_ID); } // Inflate XML for the dialog's main view. LayoutInflater inflater = LayoutInflater.from(getContext()); @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.dialog_edit_api_setting, null, false); // Get references to the parent view's subviews. name = (AutoCompleteTextView) view.findViewById(R.id.name); uri = (EditText) view.findViewById(R.id.uri); username = (EditText) view.findViewById(R.id.username); passphrase = (EditText) view.findViewById(R.id.passphrase); // Set service name autosuggestion adapter. name.setAdapter(new ArrayAdapter<>(getContext(), R.layout.api_suggestion_dropdown_item, getResources().getStringArray(R.array.service_suggestions_names))); name.setThreshold(1); name.setOnItemClickListener(this); // Set service URI TextChangedListener to show optional authentication fields when the Danbooru endpoint is used. uri.addTextChangedListener(this); // Set service URI OnFocusChangeListener to prepend "http://" to the text field when the user clicks on it. uri.setOnFocusChangeListener(this); // Populate views from an existing SearchClient.Settings object, if it was passed in the arguments bundle. if (savedInstanceState == null && getArguments() != null && getArguments().containsKey(BUNDLE_ID_SETTINGS)) { // Get the SearchClient.Settings object from this fragment's arguments bundle. SearchClient.Settings settings = getArguments().getParcelable(BUNDLE_ID_SETTINGS); // Populate subviews with content. if (settings != null) { name.setText(settings.getName()); uri.setText(settings.getEndpoint()); username.setText(settings.getUsername()); passphrase.setText(settings.getPassword()); } } // Dismiss dropdown when the view is first shown. name.dismissDropDown(); // Create the AlertDialog object. final AlertDialog alertDialog = new AlertDialog.Builder(getContext()).setView(view) .setTitle(rowId == -1 ? R.string.dialog_title_addService : R.string.dialog_title_editService) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { // Dismiss dialog without saving changes. dismiss(); } }).create(); // Use OnShowListener to override positive button behaviour. alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { // OnShowListener here is used as a hack to override Android Dialog's default OnClickListener // that doesn't provide a way to prevent the dialog from getting dismissed when a button is clicked. alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setOnClickListener(EditAPISettingDialogFragment.this); } }); return alertDialog; }
From source file:nkarasch.repeatingreminder.gui.AlertView.java
@OnClick(R.id.text_label_display) public void labelOnClick() { final EditText input = new EditText(mContext); input.setSingleLine();//from w ww .ja v a 2 s . c om final int accentColor = getResources().getColor(R.color.accent); final int textColor = Color.WHITE; final AlertDialog labelDialog = new DialogBuilder(mContext).setTitle("Set Label").setTitleColor(accentColor) .setDividerColor(accentColor).setView(input) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mAlert.setLabel(input.getText().toString()); textLabel.setText(mAlert.getLabel()); stopAlert(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).create(); labelDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { labelDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(textColor); labelDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(textColor); } }); labelDialog.show(); }
From source file:org.sufficientlysecure.ical.ui.UrlDialog.java
@Override public void onStart() { super.onStart(); final AlertDialog dlg = (AlertDialog) getDialog(); if (dlg == null) return;//from w ww . ja v a 2 s. c o m View.OnClickListener onClickTask; onClickTask = new View.OnClickListener() { @Override public void onClick(View view) { String url = mTextCalendarUrl.getText().toString(); boolean loginRequired = mCheckboxLoginRequired.isChecked(); String username = loginRequired ? mTextUsername.getText().toString() : ""; String password = loginRequired ? mTextPassword.getText().toString() : ""; if (!mActivity.setSource(url, null, username, password)) { TextView label = (TextView) dlg.findViewById(R.id.TextViewUrlError); label.setText(R.string.invalid_url); return; } Settings settings = mActivity.getSettings(); settings.putString(Settings.PREF_LASTURL, url); if (loginRequired) { settings.putString(Settings.PREF_LASTURLUSERNAME, username); if (settings.getSavePasswords()) settings.putString(Settings.PREF_LASTURLPASSWORD, password); } dlg.dismiss(); } }; dlg.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(onClickTask); }
From source file:id.satusatudua.sigap.ui.AddTrustedUserActivity.java
@Override public void onNotFoundUser(String email) { AlertDialog alertDialog = new AlertDialog.Builder(this).setIcon(R.mipmap.ic_launcher) .setTitle("Email Tidak Terdaftar") .setMessage("Email yang anda masukan tidak terdaftar, undang teman anda untuk bergabung ke Sigap?") .setPositiveButton("YA, Undang Dia", (dialog, which) -> { Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("mailto:" + email)); intent.putExtra(Intent.EXTRA_SUBJECT, "Saya Mengundang Anda Bergabung Ke Sigap"); intent.putExtra(Intent.EXTRA_TEXT, "Halo...!\nSaya membutuhkan anda untuk menjadi kontak yang saya percayai di Sigap, mari bergabung bersama saya di Sigap untuk mewujudkan kehidupan yang lebih Siap dan Tanggap terhadap segala ancaman bahaya. Untuk bergabung ke Sigap silahkan download aplikasinya di url ini [URL].\nTerimakasih banyak atas perhatiannya.\n\nSalam,\n" + CacheManager.pluck().getCurrentUser().getName()); startActivity(intent);/* ww w. ja v a 2s .com*/ }).setNegativeButton("TIDAK", (dialog, which1) -> { dialog.dismiss(); }).show(); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(this, R.color.colorPrimary)); alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(this, R.color.primary_text)); alertDialog.show(); }
From source file:id.satusatudua.sigap.ui.fragment.TrustedsFragment.java
@Override public void onNotFoundUser(String email) { AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setIcon(R.mipmap.ic_launcher) .setTitle("Email Tidak Terdaftar") .setMessage("Email yang anda masukan tidak terdaftar, undang teman anda untuk bergabung ke Sigap?") .setPositiveButton("YA, Undang Dia", (dialog, which) -> { Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("mailto:" + email)); intent.putExtra(Intent.EXTRA_SUBJECT, "Saya Mengundang Anda Bergabung Ke Sigap"); intent.putExtra(Intent.EXTRA_TEXT, "Halo...!\nSaya membutuhkan anda untuk menjadi kontak yang saya percayai di Sigap, mari bergabung bersama saya di Sigap untuk mewujudkan kehidupan yang lebih Siap dan Tanggap terhadap segala ancaman bahaya. Untuk bergabung ke Sigap silahkan download aplikasinya di url ini [URL].\nTerimakasih banyak atas perhatiannya.\n\nSalam,\n" + CacheManager.pluck().getCurrentUser().getName()); startActivity(intent);/*w w w. j a v a 2s . co m*/ }).setNegativeButton("TIDAK", (dialog, which1) -> { dialog.dismiss(); }).show(); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(getActivity(), R.color.primary_text)); alertDialog.show(); }