List of usage examples for android.app AlertDialog getButton
public Button getButton(int whichButton)
From source file:id.nci.stm_9.PassphraseDialogFragment.java
/** * Associate the "done" button on the soft keyboard with the okay button in the view *///from www . j a v a 2 s . c o m @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (EditorInfo.IME_ACTION_DONE == actionId) { AlertDialog dialog = ((AlertDialog) getDialog()); Button bt = dialog.getButton(AlertDialog.BUTTON_POSITIVE); bt.performClick(); return true; } return false; }
From source file:org.projectbuendia.client.ui.dialogs.NewUserDialogFragment.java
@Override public @NonNull Dialog onCreateDialog(Bundle savedInstanceState) { View fragment = mInflater.inflate(R.layout.new_user_dialog_fragment, null); ButterKnife.inject(this, fragment); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()).setCancelable(false) // Disable auto-cancel. .setTitle(getResources().getString(R.string.title_new_user)) .setPositiveButton(getResources().getString(R.string.ok), null) .setNegativeButton(getResources().getString(R.string.cancel), null).setView(fragment); final AlertDialog dialog = dialogBuilder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override//from w ww.ja v a 2 s . co m public void onShow(DialogInterface dialogInterface) { dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Validate the user. String givenName = mGivenName.getText() == null ? "" : mGivenName.getText().toString().trim(); String familyName = mFamilyName.getText() == null ? "" : mFamilyName.getText().toString().trim(); boolean valid = true; if (givenName.isEmpty()) { setError(mGivenName, R.string.given_name_cannot_be_null); valid = false; } if (familyName.isEmpty()) { setError(mFamilyName, R.string.family_name_cannot_be_null); valid = false; } Utils.logUserAction("add_user_submitted", "valid", "" + valid, "given_name", givenName, "family_name", familyName); if (!valid) return; App.getUserManager().addUser(new JsonNewUser(givenName, familyName)); if (mActivityUi != null) { mActivityUi.showSpinner(true); } dialog.dismiss(); } }); } }); // Open the keyboard, ready to type into the given name field. dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); return dialog; }
From source file:org.projectbuendia.client.ui.dialogs.AddNewUserDialogFragment.java
@NonNull @Override//from w w w .j av a 2 s. c o m public Dialog onCreateDialog(Bundle savedInstanceState) { View fragment = mInflater.inflate(R.layout.dialog_fragment_add_new_user, null); ButterKnife.inject(this, fragment); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()).setCancelable(false) // Disable auto-cancel. .setTitle(getResources().getString(R.string.title_add_new_user)) .setPositiveButton(getResources().getString(R.string.ok), null) .setNegativeButton(getResources().getString(R.string.cancel), null).setView(fragment); final AlertDialog dialog = dialogBuilder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Validate the user. String givenName = mGivenName.getText() == null ? "" : mGivenName.getText().toString().trim(); String familyName = mFamilyName.getText() == null ? "" : mFamilyName.getText().toString().trim(); boolean valid = true; if (givenName.isEmpty()) { setError(mGivenName, R.string.given_name_cannot_be_null); valid = false; } if (familyName.isEmpty()) { setError(mFamilyName, R.string.family_name_cannot_be_null); valid = false; } Utils.logUserAction("add_user_submitted", "valid", "" + valid, "given_name", givenName, "family_name", familyName); if (!valid) { return; } App.getUserManager().addUser(new NewUser(givenName, familyName)); if (mActivityUi != null) { mActivityUi.showSpinner(true); } dialog.dismiss(); } }); } }); return dialog; }
From source file:com.munger.passwordkeeper.alert.InputFragment.java
@Override public void onStart() { super.onStart(); //super.onStart() is where dialog.show() is actually called on the underlying dialog, so we have to do it after this point AlertDialog d = (AlertDialog) getDialog(); if (d != null) { //this is the actual okay handler //it was created like this so the event listener would have the chance to keep the alert open Button positiveButton = (Button) d.getButton(Dialog.BUTTON_POSITIVE); positiveButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { okay();/*w w w . ja va 2 s.c om*/ } }); } }
From source file:com.hijacker.FeedbackDialog.java
@Override public void onStart() { super.onStart(); final AlertDialog d = (AlertDialog) getDialog(); if (d != null) { Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE); positiveButton.setOnClickListener(new View.OnClickListener() { @Override/* w ww. j a v a 2s . co m*/ public void onClick(final View v) { attemptSend(); } }); } }
From source file:org.ciasaboark.tacere.activity.fragment.EventDetailsFragment.java
@Override public void onResume() { super.onResume(); AlertDialog thisDialog = (AlertDialog) getDialog(); positiveButton = thisDialog.getButton(AlertDialog.BUTTON_POSITIVE); if (positiveButton != null) { positiveButton.setEnabled(event.getRingerType() == RingerType.UNDEFINED ? false : true); }//www . j av a 2s. c o m }
From source file:org.sufficientlysecure.keychain.ui.dialog.AddKeyserverDialogFragment.java
@Override public void onStart() { super.onStart(); AlertDialog addKeyserverDialog = (AlertDialog) getDialog(); if (addKeyserverDialog != null) { Button positiveButton = addKeyserverDialog.getButton(Dialog.BUTTON_POSITIVE); positiveButton.setOnClickListener(new View.OnClickListener() { @Override/*from w w w. jav a2 s .co m*/ public void onClick(View v) { String keyserverUrl = mKeyserverEditText.getText().toString(); if (mVerifyKeyserverCheckBox.isChecked()) { verifyConnection(keyserverUrl); } else { dismiss(); // return unverified keyserver back to activity addKeyserver(keyserverUrl, false); } } }); } }
From source file:io.jari.geenstijl.Dialogs.ReplyDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); final View view = inflater.inflate(R.layout.dialog_reply, null); builder.setView(view).setPositiveButton(R.string.reply, null) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { ReplyDialog.this.getDialog().cancel(); }// ww w . j a v a 2s. c o m }).setTitle(R.string.reply); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { 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() { @Override public void onClick(View v) { positive.setEnabled(false); negative.setEnabled(false); final TextView reply = (TextView) view.findViewById(R.id.reply); final View loading = view.findViewById(R.id.loading); reply.setVisibility(View.GONE); loading.setVisibility(View.VISIBLE); error.setVisibility(View.GONE); alertDialog.setCancelable(false); new Thread(new Runnable() { @Override public void run() { boolean success; try { success = API.reply(artikel, reply.getText().toString(), activity); } catch (Exception e) { e.printStackTrace(); success = false; } alertDialog.setCancelable(true); if (!success) activity.runOnUiThread(new Runnable() { @Override public void run() { reply.setVisibility(View.VISIBLE); error.setVisibility(View.VISIBLE); positive.setEnabled(true); negative.setEnabled(true); loading.setVisibility(View.GONE); } }); else activity.runOnUiThread(new Runnable() { @Override public void run() { alertDialog.dismiss(); Crouton.makeText(activity, getString(R.string.reply_success), Style.CONFIRM).show(); } }); } }).start(); } }); } }); return alertDialog; }
From source file:com.jaspersoft.android.jaspermobile.dialog.PageDialogFragment.java
@NonNull @Override// w w w. j a v a 2 s . c om public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater layoutInflater = LayoutInflater.from(getActivity()); ViewGroup customView = (ViewGroup) layoutInflater.inflate(R.layout.page_dialog_layout, (ViewGroup) getActivity().getWindow().getDecorView(), false); final EditText numberEditText = (EditText) customView.findViewById(R.id.customNumber); builder.setTitle(R.string.rv_select_page); builder.setView(customView); builder.setNegativeButton(android.R.string.cancel, null); builder.setPositiveButton(android.R.string.ok, null); final AlertDialog dialog = builder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { numberEditText.requestFocus(); inputMethodManager.showSoftInput(numberEditText, 0); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (numberEditText.length() == 0) { numberEditText.setError(getString(R.string.sp_error_field_required)); } else { int page; try { page = Integer.valueOf(numberEditText.getText().toString()); } catch (NumberFormatException ex) { page = Integer.MAX_VALUE; numberEditText.setText(String.valueOf(page)); } if (onPageSelectedListener != null) { onPageSelectedListener.onPageSelected(page); dismiss(); } } } }); } }); return dialog; }
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.SaveCalibrationDialogFragment.java
@Override public void onStart() { super.onStart(); final Context context = getActivity(); final AlertDialog d = (AlertDialog) getDialog(); if (d != null) { Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE); positiveButton.setOnClickListener(new View.OnClickListener() { @Override/*w ww. j ava 2 s .c o m*/ public void onClick(View v) { if (formEntryValid()) { final String testCode = CaddisflyApp.getApp().getCurrentTestInfo().getId(); if (!editName.getText().toString().trim().isEmpty()) { final File path = FileHelper.getFilesDir(FileHelper.FileType.CALIBRATION, testCode); File file = new File(path, editName.getText().toString()); if (file.exists()) { AlertUtil.askQuestion(context, R.string.fileAlreadyExists, R.string.doYouWantToOverwrite, R.string.overwrite, R.string.cancel, true, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { saveCalibrationDetails(path); saveDetails(testCode); closeKeyboard(context, editName); dismiss(); } }, null); } else { saveCalibrationDetails(path); saveDetails(testCode); closeKeyboard(context, editName); dismiss(); } } else { saveDetails(testCode); closeKeyboard(context, editExpiryDate); dismiss(); } } } void saveDetails(String testCode) { PreferencesUtil.setLong(context, testCode, R.string.calibrationExpiryDateKey, calendar.getTimeInMillis()); PreferencesUtil.setString(context, testCode, R.string.batchNumberKey, editBatchCode.getText().toString().trim()); PreferencesUtil.setString(context, testCode, R.string.ledRgbKey, editRgb.getText().toString().trim()); ((CalibrationDetailsSavedListener) getActivity()).onCalibrationDetailsSaved(); } private boolean formEntryValid() { if (!isEditing && AppPreferences.isDiagnosticMode() && editName.getText().toString().trim().isEmpty()) { editName.setError(getString(R.string.saveInvalidFileName)); return false; } if (editBatchCode.getText().toString().trim().isEmpty()) { editBatchCode.setError(getString(R.string.required)); return false; } if (editExpiryDate.getText().toString().trim().isEmpty()) { editExpiryDate.setError(getString(R.string.required)); return false; } return true; } }); } }