protected void setFontForDialog(AlertDialog d) { Button b = d.getButton(AlertDialog.BUTTON_POSITIVE); if (b != null) b.setTypeface(unispace); b = d.getButton(AlertDialog.BUTTON_NEGATIVE); if (b != null) b.setTypeface(unispace); // nice hack to get the message in the dialog TextView t = (TextView) d.findViewById(android.R.id.message); if (t != null) t.setTypeface(unispace); }
public static void showPasswordDialog(Activity ctx, AlertDialog dialog) { ctx.findViewById(android.R.id.content).setVisibility(View.GONE); if (ctx instanceof ActionBarActivity) { ((ActionBarActivity) ctx).getSupportActionBar().hide(); } dialog.show(); PasswordDialogListener l = new PasswordDialogListener(ctx, dialog); Button b = dialog.getButton(DialogInterface.BUTTON_POSITIVE); if (b != null) b.setOnClickListener(l); b = dialog.getButton(DialogInterface.BUTTON_NEGATIVE); if (b != null) b.setOnClickListener(l); }
@Override public void onClick(View v) { final SharedPreferences settings = MyApplication.getInstance().getSettings(); final String securityQuestion = MyApplication.PrefKey.SECURITY_QUESTION.getString(""); EditText input = (EditText) dialog.findViewById(R.id.password); TextView error = (TextView) dialog.findViewById(R.id.passwordInvalid); if (v == dialog.getButton(AlertDialog.BUTTON_NEGATIVE)) { if ((Boolean) input.getTag()) { input.setTag(Boolean.valueOf(false)); ((Button) v).setText(R.string.password_lost); dialog.setTitle(R.string.password_prompt); } else { input.setTag(Boolean.valueOf(true)); dialog.setTitle(securityQuestion); ((Button) v).setText(android.R.string.cancel); } } else { String value = input.getText().toString(); boolean isInSecurityQuestion = (Boolean) input.getTag(); if (Utils.md5(value) .equals( (isInSecurityQuestion ? MyApplication.PrefKey.SECURITY_ANSWER : MyApplication.PrefKey.SET_PASSWORD) .getString(""))) { input.setText(""); error.setText(""); MyApplication.getInstance().setLocked(false); ctx.findViewById(android.R.id.content).setVisibility(View.VISIBLE); if (ctx instanceof ActionBarActivity) { ((ActionBarActivity) ctx).getSupportActionBar().show(); } if (isInSecurityQuestion) { MyApplication.PrefKey.PERFORM_PROTECTION.putBoolean(false); Toast.makeText( ctx.getBaseContext(), R.string.password_disabled_reenable, Toast.LENGTH_LONG) .show(); dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setText(R.string.password_lost); dialog.setTitle(R.string.password_prompt); input.setTag(Boolean.valueOf(false)); } dialog.dismiss(); } else { input.setText(""); error.setText( isInSecurityQuestion ? R.string.password_security_answer_not_valid : R.string.password_not_valid); } } }
@Override protected void showDialog(Bundle state) { super.showDialog(state); TypedValue typedValue = new TypedValue(); Resources.Theme theme = getContext().getTheme(); theme.resolveAttribute(R.attr.colorAccent, typedValue, true); AlertDialog dialog = (AlertDialog) getDialog(); dialog.show(); Button cancel = dialog.getButton(AlertDialog.BUTTON_NEGATIVE); Button ok = dialog.getButton(AlertDialog.BUTTON_POSITIVE); ok.setVisibility(View.GONE); cancel.setTextColor(typedValue.data); dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg); }
@Override public void onClick(View dialog) { handler.removeCallbacks(alertcallCountdown); String message = "Der Assistenzruf wurde abgebrochen"; alertTextview.setText(message); Speak.speak(message); alertStatus = ALERTCALL_CANCELED; alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setText("Schliessen"); alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL).setVisibility(INVISIBLE); }
@Override public void onStart() { super.onStart(); AlertDialog alertDialog = (AlertDialog) getDialog(); final Button buttonNeutral = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL); buttonNeutral.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (isRunning) { dataFileWriter.writeToFile( "Magnetic_Field_Uncalibrated", "Calculated_bias: " + Arrays.toString(magneticFieldBias.getBias())); dismissDialog(); } else { sensorManager.registerListener( MagCalibrationDialogFragment.this, sensorMagneticField, SensorManager.SENSOR_DELAY_FASTEST); isRunning = true; buttonNeutral.setText("Stop Calibration"); } } }); }
/** * 添加备注 * * @param childName 好友名字 * @param groupIndex 当前所在组的下标 * @param childIndex 当前所在组的联系人下标 */ private void addMark(String childName, final int groupIndex, final int childIndex) { final EditText input = new EditText(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("给“" + childName + "”输入备注名:"); builder.setView(input); builder.setPositiveButton("确定", null); builder.setNegativeButton("取消", null); final AlertDialog alertDialog = builder.create(); alertDialog.show(); alertDialog .getButton(AlertDialog.BUTTON_POSITIVE) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String value = input.getText().toString().trim(); if (value.length() == 0) { Toast.makeText(getActivity(), "不能为空", Toast.LENGTH_SHORT); return; } list.get(groupIndex).get(childIndex).add(value); updateData(ArrayList, null); alertDialog.dismiss(); } }); }
@Override public Dialog onCreateDialog(Bundle savedState) { View dialogView = getActivity().getLayoutInflater().inflate(R.layout.dialog_change_password, null, false); currentPassword = (EditText) dialogView.findViewById(R.id.dialog_change_password_currentPassword); newPassword = (EditText) dialogView.findViewById(R.id.dialog_change_password_newPassword); connfirmNewPassword = (EditText) dialogView.findViewById(R.id.dialog_change_password_confirmNewPassword); if (!application.getAuth().getUser().isHasPassword()) { currentPassword.setVisibility(View.GONE); } // Alert Dialog Builder used to create dialog AlertDialog dialog = new AlertDialog.Builder(getActivity()) .setView(dialogView) .setPositiveButton("Update", null) .setNegativeButton("Cancel", null) .setTitle("Change Password") .show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(this); return dialog; }
@Override protected void showDialog(Bundle state) { super.showDialog(state); // If the dialog isn't an instance of alert dialog this code is useless if (super.getDialog() instanceof AlertDialog) { final AlertDialog theDialog = (AlertDialog) super.getDialog(); // get originalBottomPadding to know when adjust the underlying // layouts bottom padding (ie has room already // been created for an error message) int padding = Integer.MIN_VALUE; try { padding = ((LinearLayout) getEditText().getParent()).getPaddingBottom(); } catch (Exception e) { // some exception thrown. Unable to do increase space for error // message } final int originalBottomPadding = padding; Button b = theDialog.getButton(AlertDialog.BUTTON_POSITIVE); // attach our validating on click listener ValidatingOnClickListener l = new ValidatingOnClickListener(originalBottomPadding, theDialog); b.setOnClickListener(l); // add an editor action listener for the 'done/next' buttons on a // soft keyboard getEditText().setOnEditorActionListener(l); } }
@Override public void onShow(DialogInterface dialog) { // We need to override the default dismissal effect when a dialog button is clicked. // The solution is to set an onClick listener to the button itself to deprive the // dialog from having the opportunity to dismiss the dialog. mNameDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(this); }
@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 final AlertDialog d = (AlertDialog) getDialog(); if (d != null) { TextView spotET = (TextView) getDialog().findViewById(R.id.spot_to_add); spotET.setText("Plaça " + mSpot); EditText inputCar = (EditText) getDialog().findViewById(R.id.licensePlateEditText); inputCar.setFilters(new InputFilter[] {new InputFilter.AllCaps()}); Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE); positiveButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // Send the positive button event back to the host activity EditText inputCar = (EditText) getDialog().findViewById(R.id.licensePlateEditText); String licensePlate = inputCar.getText().toString(); Log.d("Dialog", "Input: " + licensePlate); if (!licensePlate.equals("")) { mListener.onDialogPositiveClick(AddCarDialogFragment.this, mSpot, licensePlate); d.dismiss(); } else { Toast.makeText( getActivity().getApplicationContext(), "Escriu la matrícula del vehicle", Toast.LENGTH_SHORT) .show(); } } }); } }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Build the dialog and set up the button click handlers AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater and the view from it final LayoutInflater inflater = getActivity().getLayoutInflater(); final View view = inflater.inflate(R.layout.dialog_deposit_money, null); mEditText_money = (EditText) view.findViewById(R.id.editText_depositMoney); builder .setMessage(i18n(R.string.builder_deposit)) .setView(view) .setPositiveButton( i18n(R.string.builder_deposit_positive), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String deposit = mEditText_money.getText().toString().trim(); ((AccountActivity) getActivity()).doPositiveClickDepositMoneyDialog(deposit); dialog.cancel(); } }) .setNegativeButton( i18n(R.string.text_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); final AlertDialog dialog = builder.create(); dialog.show(); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); // Disabled by default. // Code to enable positive button only when all data have been provided final TextWatcher watcher = 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) {} @Override public void afterTextChanged(Editable s) { dialog .getButton(AlertDialog.BUTTON_POSITIVE) .setEnabled( !mEditText_money.getText().toString().trim().isEmpty() && !mEditText_money.getText().toString().trim().isEmpty()); } }; // Text fields must be completed to enable positive button mEditText_money.addTextChangedListener(watcher); return dialog; }
@Override public void afterTextChanged(Editable s) { if (dialog == null) return; String text = input.getText().toString(); boolean disabled = TextUtils.isEmpty(text); dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(!disabled); }
public void handle() { final boolean needsPassword = needsPassword(); final boolean hasPassword = !passwordView.getText().toString().trim().isEmpty(); final boolean hasFile = hasFile(); final Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE); button.setEnabled(hasFile && (!needsPassword || hasPassword)); }
@Override public void onClick(View v) { if (accbank.getText().length() == 0) return; if (accamount.getText().length() == 0) return; if (accname.getText().length() == 0) return; if (accnumber.getText().length() == 0) return; HashMap<String, Object> pars = new HashMap<String, Object>(); pars.put("loginkey", Shared.loginkey); pars.put("bank", accbank.getText()); pars.put("amount", accamount.getText()); pars.put("name", accname.getText()); pars.put("number", accnumber.getText()); request = SimpleHttp.request("request", Shared.url + "profile/requestPayment", pars, this); Button buttonok = dialog.getButton(DialogInterface.BUTTON_POSITIVE); buttonok.setText("Please wait..."); buttonok.setEnabled(false); dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.GONE); }
@Test public void skipLogin() { ((TextView) loginActivity.findViewById(R.id.skipLogin)).performClick(); AlertDialog latestAlertDialog = ShadowAlertDialog.getLatestAlertDialog(); ShadowAlertDialog dialog = Robolectric.shadowOf(latestAlertDialog); assertEquals(loginActivity.getString(R.string.noLoginWarn), dialog.getMessage()); assertTrue(latestAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick()); assertNextActivity(loginActivity, StackNetworkListActivity.class); }
public void afterTextChanged(Editable s) { if (dialog == null) return; String text1 = input1.getText().toString(); String text2 = input2.getText().toString(); boolean disabled = TextUtils.isEmpty(text1) || TextUtils.isEmpty(text2) || !text1.equals(text2); dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(!disabled); }
public void showAlert(String title, String msg) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(CollageEditorActivity.this); // set title alertDialogBuilder.setTitle(title); // set dialog message alertDialogBuilder .setMessage(msg) .setCancelable(true) .setNegativeButton( "Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }) .setPositiveButton( "No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.setCancelable(false); // show it alertDialog.show(); Button b = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); Button b1 = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE); if (b != null) b.setTextColor(Color.RED); if (b1 != null) b1.setTextColor(Color.RED); }
// Executed prior to installation. This gives user the option to accept or decline our // terms and conditions. The app will only be installed when they accept. private final void showConsentForm() { // Workaround for a small bug which displays the consent form two times if (!consentShownTwice) { consentShownTwice = true; // Load the customized layout final View consentLayout = this.getLayoutInflater().inflate(R.layout.consent, null); final WebView consentWebView = (WebView) consentLayout.findViewById(R.id.consent_form); consentWebView.loadUrl(getString(R.string.html_file_location)); final Builder consentFormBuilder = new AlertDialog.Builder(this) .setView(consentLayout) .setTitle(R.string.consent_title) // force exit on decline .setNegativeButton( "Decline", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { android.os.Process.killProcess(android.os.Process.myPid()); } }) // else continue with installation .setPositiveButton( "Accept", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showEmailPrompt(); dialog.dismiss(); } }); consentFormBuilder.setCancelable(false); // force user to accept or decline final AlertDialog consentFormDialog = consentFormBuilder.create(); // allow user to press accept only if user is above 18/owner of device final CheckBox ageCheckBox = (CheckBox) consentLayout.findViewById(R.id.age_box); ageCheckBox.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton checkBox, boolean isChecked) { if (checkBox.isChecked()) { consentFormDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true); } else { consentFormDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false); } } }); consentFormDialog.show(); // Note: Android Bug #6360: https://code.google.com/p/android/issues/detail?id=6360 // AlertDialog.show must be defined before AlertDialog.getButton.setEnabled(...) consentFormDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false); } }
public void show(MySocketAddress addr) { mDialog.show(); if (addr != null) { mDialog.setTitle(R.string.title_edit_socket_address); mDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setVisibility(View.VISIBLE); mCurrentId = addr.getId(); mHostNameEdit.setText(addr.getHostName()); if (addr.getPort() != null) { mPortEdit.setText(String.valueOf(addr.getPort())); } else { mPortEdit.setText(String.valueOf(net.cattaka.libgeppa.Constants.DEFAULT_SERVER_PORT)); } } else { mDialog.setTitle(R.string.title_input_socket_address); mDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setVisibility(View.INVISIBLE); mHostNameEdit.setText(""); mPortEdit.setText(String.valueOf(net.cattaka.libgeppa.Constants.DEFAULT_SERVER_PORT)); mCurrentId = null; } }
/** Associate the "done" button on the soft keyboard with the okay button in the view */ @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; }
@Test public void skipLoginAndCancel() { ShadowActivity shadowActivity = Robolectric.shadowOf(loginActivity); ((TextView) loginActivity.findViewById(R.id.skipLogin)).performClick(); AlertDialog latestAlertDialog = ShadowAlertDialog.getLatestAlertDialog(); ShadowAlertDialog dialog = Robolectric.shadowOf(latestAlertDialog); assertEquals(loginActivity.getString(R.string.noLoginWarn), dialog.getMessage()); assertTrue(latestAlertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick()); assertNull(shadowActivity.getNextStartedActivity()); }
@Override public void onStart() { super.onStart(); final AlertDialog dialog = (AlertDialog) getDialog(); if (dialog != null) { okay = dialog.getButton(Dialog.BUTTON_POSITIVE); okay.setOnClickListener(this); okay.setEnabled(false); } }
@Override public void run() { if (!alertDialog.isShowing()) return; if (alertCountdown == 0) { alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setText("Ok"); alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL).setVisibility(INVISIBLE); alertStatus = ALERTCALL_EXECUTED; alertcallExecute(); } else { String message = String.format(alertMessage, alertCountdown); alertTextview.setText(message); if ((alertCountdown % 5) == 0) Speak.speak(message); alertCountdown -= 1; handler.postDelayed(alertcallCountdown, 1000); } }
/** * M: change the buttons to disable or enable * * @param whichButton to be setting state * @param isEnable whether enable button or disable */ public void setButton(int whichButton, boolean isEnable) { AlertDialog dialog = (AlertDialog) getDialog(); if (null != dialog) { Button btn = dialog.getButton(whichButton); if (btn != null) { btn.setEnabled(isEnable); LogUtils.d(TAG, " set button state to " + btn.isEnabled()); } else { LogUtils.d(TAG, "get button" + whichButton + " from dialog is null "); } } }
private void alertcallShowDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Assistenz rufen..."); alertTextview = new TextView(context); alertTextview.setPadding(40, 40, 40, 40); alertTextview.setTextSize(24f); builder.setView(alertTextview); builder.setPositiveButton("Jetzt sofort", null); builder.setNeutralButton("Abbrechen", null); alertDialog = builder.create(); alertDialog.show(); alertDialog.setCancelable(false); Button positive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); positive.setTextSize(24f); positive.setTransformationMethod(null); positive.setOnClickListener(alertOnClickPositive); Button neutral = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL); neutral.setTextSize(24f); neutral.setTransformationMethod(null); neutral.setOnClickListener(alertOnClickNeutral); alertMessage = "Der Assistenzruf wird in %d Sekunden ausgelöst"; alertStatus = ALERTCALL_COUNTDOWN; alertCountdown = 20; if (handler == null) handler = new Handler(); handler.post(alertcallCountdown); }
@Override protected void onPrepareDialog(int id, Dialog dialog, Bundle args) { switch (id) { // A workaround to handle the OK button. We can't access the button with getButton() // when building the dialog in AlertDialogs, hence we postpone the enabling/disabling // of the positive button until the dialog is to be shown here. case DIALOG_NEW_PROJECT_ID: final AlertDialog newProjectDialog = (AlertDialog) dialog; Button positiveButton = newProjectDialog.getButton(AlertDialog.BUTTON_POSITIVE); final TextView inputField = (TextView) newProjectDialog.findViewById(R.id.text_1); positiveButton.setEnabled(inputField.getText().toString().trim().length() > 0); default: return; } }
public void afterTextChanged(Editable text) { AlertDialog dialog = (AlertDialog) UnitValuePickerPreference.this.getDialog(); if (null == dialog) { return; } Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE); String valueString = text.toString(); if (0 == valueString.length()) { return; } int value = Integer.valueOf(valueString); if ((mMinValue > 0 && value < mMinValue) || (mMaxValue > 0 && value > mMaxValue)) { button.setEnabled(false); } else { button.setEnabled(true); } }
@Override protected void showDialog(Bundle state) { super.showDialog(state); AlertDialog alertDialog = (AlertDialog) getDialog(); if (alertDialog == null) { return; } if (getContext().getPackageManager().hasSystemFeature("android.hardware.touchscreen")) { /* Disable focus for buttons to prevent them being highlighted when keys are pressed */ alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setFocusable(false); alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setFocusable(false); } alertDialog.setOnKeyListener(this); setPositiveButtonText(R.string.save); setNegativeButtonText(android.R.string.cancel); setDialogIcon(null); }
@Override protected void showDialog(Bundle state) { super.showDialog(state); // Can't use onPrepareDialogBuilder for this as we want the dialog // to be kept open on click AlertDialog d = (AlertDialog) getDialog(); Button defaultsButton = d.getButton(DialogInterface.BUTTON_NEUTRAL); defaultsButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { int defaultValue = DisplayColorCalibration.getMaxValue(); for (int i = 0; i < mSeekBars.length; i++) { mSeekBars[i].mSeekBar.setProgress(defaultValue); mCurrentColors[i] = String.valueOf(defaultValue); } DisplayColorCalibration.setColors(TextUtils.join(" ", mCurrentColors)); } }); }