Java Code Examples for android.content.DialogInterface#BUTTON_NEGATIVE

The following examples show how to use android.content.DialogInterface#BUTTON_NEGATIVE . 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: ServerDetails.java    From product-emm with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
	switch (which) {
		case DialogInterface.BUTTON_POSITIVE:
			if (!evServerIP.getText().toString().trim().isEmpty()) {
				String host = evServerIP.getText().toString().trim();
				saveHostDetails(host);

				startAuthenticationActivity();
			} else {
				Toast.makeText(context.getApplicationContext(),
						getResources().getString(
								R.string.toast_message_enter_server_address),
						Toast.LENGTH_LONG).show();
			}
			break;

		case DialogInterface.BUTTON_NEGATIVE:
			dialog.dismiss();
			break;

		default:
			break;
	}
}
 
Example 2
Source File: TypeSendFragment.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private void tryGettingCookies() {
    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
                case DialogInterface.BUTTON_POSITIVE:
                    showRegisterDialog();
                    break;
                case DialogInterface.BUTTON_NEGATIVE:
                    showAddCookieDialog();
                    break;
                case DialogInterface.BUTTON_NEUTRAL:
                    doAction();
                    break;
            }
        }
    };

    new AlertDialog.Builder(getContext()).setTitle(R.string.no_cookies)
            .setMessage(R.string.no_cookies_ac)
            .setPositiveButton(R.string.register, listener)
            .setNegativeButton(R.string.add_cookies, listener)
            .setNeutralButton(R.string.i_dont_care, listener).show();
}
 
Example 3
Source File: DynamicAlertController.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * Sets an icon, a click listener or a message to be sent when the button is clicked.
 * You only need to pass one of {@code icon}, {@code listener} or {@code msg}.
 *
 * @param whichButton Which button, can be one of
 *                    {@link DialogInterface#BUTTON_POSITIVE},
 *                    {@link DialogInterface#BUTTON_NEGATIVE}, or
 *                    {@link DialogInterface#BUTTON_NEUTRAL}
 * @param text        The text to display in positive button.
 * @param listener    The {@link DialogInterface.OnClickListener} to use.
 * @param msg         The {@link Message} to be sent when clicked.
 * @param icon        The (@link Drawable) to be used as an icon for the button.
 *
 */
public void setButton(int whichButton, CharSequence text,
        DialogInterface.OnClickListener listener, Message msg, Drawable icon) {

    if (msg == null && listener != null) {
        msg = mHandler.obtainMessage(whichButton, listener);
    }

    switch (whichButton) {

        case DialogInterface.BUTTON_POSITIVE:
            mButtonPositiveText = text;
            mButtonPositiveMessage = msg;
            mButtonPositiveIcon = icon;
            break;

        case DialogInterface.BUTTON_NEGATIVE:
            mButtonNegativeText = text;
            mButtonNegativeMessage = msg;
            mButtonNegativeIcon = icon;
            break;

        case DialogInterface.BUTTON_NEUTRAL:
            mButtonNeutralText = text;
            mButtonNeutralMessage = msg;
            mButtonNeutralIcon = icon;
            break;

        default:
            throw new IllegalArgumentException("Button does not exist");
    }
}
 
Example 4
Source File: SignoutFragment.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    switch (which) {
        case DialogInterface.BUTTON_POSITIVE: {
            SigninManager.get(getActivity()).signOut(getActivity(), null);
            break;
        }
        case DialogInterface.BUTTON_NEGATIVE: {
            dismiss();
            break;
        }
        default:
            break;
    }
}
 
Example 5
Source File: StartUpCommandsFragment.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    switch (which){
        case DialogInterface.BUTTON_POSITIVE:
            //Yes button clicked
            Control.deletespecificcommand(getActivity(), null, null);
            forcerefresh(getActivity());
            break;

        case DialogInterface.BUTTON_NEGATIVE:
            //No button clicked
            break;
    }
}
 
Example 6
Source File: SignoutFragment.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    switch (which) {
        case DialogInterface.BUTTON_POSITIVE: {
            SigninManager.get(getActivity()).signOut(getActivity(), null);
            break;
        }
        case DialogInterface.BUTTON_NEGATIVE: {
            dismiss();
            break;
        }
        default:
            break;
    }
}
 
Example 7
Source File: TroubleshootingActivity.java    From screenstandby with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    switch (which){
    case DialogInterface.BUTTON_POSITIVE:
    	PreferenceManager.getDefaultSharedPreferences(TroubleshootingActivity.this).edit().clear().commit();
    	TroubleshootingActivity.this.finish();
        break;

    case DialogInterface.BUTTON_NEGATIVE:
        dialog.dismiss();
        break;
    }
}
 
Example 8
Source File: CameraDialog.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public void onClick(final DialogInterface dialog, final int which) {
	switch (which) {
	case DialogInterface.BUTTON_POSITIVE:
		final Object item = mSpinner.getSelectedItem();
		if (item instanceof UsbDevice) {
			mUSBMonitor.requestPermission((UsbDevice)item);
			((CameraDialogParent)getActivity()).onDialogResult(false);
		}
		break;
	case DialogInterface.BUTTON_NEGATIVE:
		((CameraDialogParent)getActivity()).onDialogResult(true);
		break;
	}
}
 
Example 9
Source File: WantToRateDialogListener.java    From RateMyApp with MIT License 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialogInterface, int buttonPressed, Context context, FragmentManager fragmentManager) {
    switch(buttonPressed){
        case DialogInterface.BUTTON_POSITIVE:
            action.execute(context, fragmentManager);
            break;
        case DialogInterface.BUTTON_NEUTRAL:
            preferencesManager.resetFirstLaunchTimestamp();
            break;
        case DialogInterface.BUTTON_NEGATIVE:
            preferencesManager.setAlertEnabled(false);
            break;
    }
    dialogInterface.dismiss();
}
 
Example 10
Source File: DynamicAlertController.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
public Button getButton(int whichButton) {
    switch (whichButton) {
        case DialogInterface.BUTTON_POSITIVE:
            return mButtonPositive;
        case DialogInterface.BUTTON_NEGATIVE:
            return mButtonNegative;
        case DialogInterface.BUTTON_NEUTRAL:
            return mButtonNeutral;
        default:
            return null;
    }
}
 
Example 11
Source File: DialogPreference.java    From PreferenceFragment with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the dialog associated with this Preference. This is normally initiated
 * automatically on clicking on the preference. Call this method if you need to
 * show the dialog on some other event.
 * 
 * @param state Optional instance state to restore on the dialog
 */
protected void showDialog(Bundle state) {
    Context context = getContext();

    mWhichButtonClicked = DialogInterface.BUTTON_NEGATIVE;
    
    mBuilder = new AlertDialog.Builder(context)
        .setTitle(mDialogTitle)
        .setIcon(mDialogIcon)
        .setPositiveButton(mPositiveButtonText, this)
        .setNegativeButton(mNegativeButtonText, this);

    View contentView = onCreateDialogView();
    if (contentView != null) {
        onBindDialogView(contentView);
        mBuilder.setView(contentView);
    } else {
        mBuilder.setMessage(mDialogMessage);
    }
    
    onPrepareDialogBuilder(mBuilder);
    
    getPreferenceManager().registerOnActivityDestroyListener(this);
    
    // Create the dialog
    final Dialog dialog = mDialog = mBuilder.create();
    if (state != null) {
        dialog.onRestoreInstanceState(state);
    }
    if (needInputMethod()) {
        requestInputMethod(dialog);
    }
    dialog.setOnDismissListener(this);
    dialog.show();
}
 
Example 12
Source File: DynamicAlertController.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    switch (msg.what) {

        case DialogInterface.BUTTON_POSITIVE:
        case DialogInterface.BUTTON_NEGATIVE:
        case DialogInterface.BUTTON_NEUTRAL:
            ((DialogInterface.OnClickListener) msg.obj).onClick(mDialog.get(), msg.what);
            break;

        case MSG_DISMISS_DIALOG:
            ((DialogInterface) msg.obj).dismiss();
    }
}
 
Example 13
Source File: PreferenceDialogFragment.java    From MaterialPreference with Apache License 2.0 5 votes vote down vote up
@Override
public @NonNull
Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity();
    mWhichButtonClicked = DialogInterface.BUTTON_NEGATIVE;

    final PreferenceDialogBuilder builder = new PreferenceDialogBuilder(context)
            .setTitle(mDialogTitle)
            .setIcon(mDialogIcon)
            .setPositiveButton(mPositiveButtonText, this)
            .setNegativeButton(mNegativeButtonText, this);

    View contentView = onCreateDialogView(context);
    if (contentView != null) {
        onBindDialogView(contentView);
        builder.setView(contentView);
    } else {
        builder.setMessage(mDialogMessage);
    }

    onPrepareDialogBuilder(builder);

    // Create the dialog
    final Dialog dialog = builder.create();
    if (needInputMethod()) {
        requestInputMethod(dialog);
    }

    return dialog;
}
 
Example 14
Source File: PinCodeActivity.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
	switch (which) {
		case DialogInterface.BUTTON_POSITIVE:
			savePin();
			break;

		case DialogInterface.BUTTON_NEGATIVE:
			dialog.dismiss();
			break;
	}
}
 
Example 15
Source File: GeneralDialog.java    From pandora with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    switch (which) {
        case DialogInterface.BUTTON_POSITIVE:
            getParentFragment().onActivityResult(code, Activity.RESULT_OK, null);
            break;
        case DialogInterface.BUTTON_NEGATIVE:
            getParentFragment().onActivityResult(code, Activity.RESULT_CANCELED, null);
            break;
    }
}
 
Example 16
Source File: CustomInputStylePreference.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(final DialogInterface dialog, final int which) {
    super.onClick(dialog, which);
    switch (which) {
    case DialogInterface.BUTTON_POSITIVE:
        final boolean isEditing = !isIncomplete();
        final SubtypeLocaleItem locale =
                (SubtypeLocaleItem) mSubtypeLocaleSpinner.getSelectedItem();
        final KeyboardLayoutSetItem layout =
                (KeyboardLayoutSetItem) mKeyboardLayoutSetSpinner.getSelectedItem();
        final InputMethodSubtype subtype =
                AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
                        locale.mLocaleString, layout.mLayoutName);
        setSubtype(subtype);
        notifyChanged();
        if (isEditing) {
            mProxy.onSaveCustomInputStyle(this);
        } else {
            mProxy.onAddCustomInputStyle(this);
        }
        break;
    case DialogInterface.BUTTON_NEUTRAL:
        // Nothing to do
        break;
    case DialogInterface.BUTTON_NEGATIVE:
        mProxy.onRemoveCustomInputStyle(this);
        break;
    }
}
 
Example 17
Source File: MLAlertController.java    From NewXmPluginSDK with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case DialogInterface.BUTTON_POSITIVE:
        case DialogInterface.BUTTON_NEGATIVE:
        case DialogInterface.BUTTON_NEUTRAL:
            ((DialogInterface.OnClickListener) msg.obj).onClick(mDialog.get(), msg.what);
            break;
        case MSG_DISMISS_DIALOG:
            ((DialogInterface) msg.obj).dismiss();
    }
}
 
Example 18
Source File: DialogPreference.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the dialog associated with this Preference. This is normally initiated
 * automatically on clicking on the preference. Call this method if you need to
 * show the dialog on some other event.
 *
 * @param state Optional instance state to restore on the dialog
 */
protected void showDialog(Bundle state) {
    Context context = getContext();

    mWhichButtonClicked = DialogInterface.BUTTON_NEGATIVE;

    mBuilder = new AlertDialog.Builder(context)
            .setTitle(mDialogTitle)
            .setIcon(mDialogIcon)
            .setPositiveButton(mPositiveButtonText, this)
            .setNegativeButton(mNegativeButtonText, this);

    View contentView = onCreateDialogView();
    if (contentView != null) {
        onBindDialogView(contentView);
        mBuilder.setView(contentView);
    }

    onPrepareDialogBuilder(mBuilder);

    PreferenceUtils.registerOnActivityDestroyListener(this, this);

    // Create the dialog
    final AlertDialog dialog = mDialog = mBuilder.create();
    if (state != null) {
        dialog.onRestoreInstanceState(state);
    }
    if (needInputMethod()) {
        requestInputMethod(dialog);
    }
    dialog.setOnDismissListener(this);
    dialog.show();

    onDialogCreated(dialog);
}
 
Example 19
Source File: CustomInputStylePreference.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(final DialogInterface dialog, final int which) {
    super.onClick(dialog, which);
    switch (which) {
    case DialogInterface.BUTTON_POSITIVE:
        final boolean isEditing = !isIncomplete();
        final SubtypeLocaleItem locale =
                (SubtypeLocaleItem) mSubtypeLocaleSpinner.getSelectedItem();
        final KeyboardLayoutSetItem layout =
                (KeyboardLayoutSetItem) mKeyboardLayoutSetSpinner.getSelectedItem();
        final InputMethodSubtype subtype =
                AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(
                        locale.mLocaleString, layout.mLayoutName);
        setSubtype(subtype);
        notifyChanged();
        if (isEditing) {
            mProxy.onSaveCustomInputStyle(this);
        } else {
            mProxy.onAddCustomInputStyle(this);
        }
        break;
    case DialogInterface.BUTTON_NEUTRAL:
        // Nothing to do
        break;
    case DialogInterface.BUTTON_NEGATIVE:
        mProxy.onRemoveCustomInputStyle(this);
        break;
    }
}
 
Example 20
Source File: PaycardActivity.java    From NFC-EMV-Reader with GNU General Public License v3.0 4 votes vote down vote up
private void wipePaycard() {
    LogUtil.i(TAG, "Wipe paycard");

    DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which){
                case DialogInterface.BUTTON_POSITIVE:
                    // Wipe paycard relative
                    boolean hasException = false;

                    try {
                        mRealm.beginTransaction();

                        mPaycardObject.deleteFromRealm();

                        mRealm.commitTransaction();

                        mRealm.refresh();
                    } catch (Exception e) {
                        hasException = true;

                        LogUtil.e(TAG, e.getMessage());
                        LogUtil.e(TAG, e.toString());

                        e.printStackTrace();
                    }

                    if (!hasException) {
                        LogUtil.i(TAG, getString(R.string.paycard_wipe_success));

                        Toast.makeText(PaycardActivity.this, getString(R.string.paycard_wipe_success), Toast.LENGTH_SHORT).show();
                    } else {
                        LogUtil.w(TAG, getString(R.string.paycard_wipe_no_success));

                        Toast.makeText(PaycardActivity.this, getString(R.string.paycard_wipe_no_success), Toast.LENGTH_SHORT).show();
                    }
                    // - Wipe paycard relative

                    finish();

                    break;

                case DialogInterface.BUTTON_NEGATIVE:
                    dialog.dismiss();

                    break;
            }
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Wipe Paycard");
    builder.setMessage("Are you sure you want to wipe out this paycard?");
    // builder.setPositiveButton(android.R.string.yes, onClickListener).setNegativeButton(android.R.string.no, onClickListener);
    builder.setPositiveButton(android.R.string.ok, onClickListener).setNegativeButton(android.R.string.cancel, onClickListener);
    builder.setCancelable(true);
    builder.show();
}