Java Code Examples for android.content.DialogInterface#BUTTON_POSITIVE

The following examples show how to use android.content.DialogInterface#BUTTON_POSITIVE . 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: InvalidConnectionCertActivity.java    From tapchat-android with Apache License 2.0 6 votes vote down vote up
@Override public void onServiceConnected(final TapchatService service) {
    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            boolean accept = (which == DialogInterface.BUTTON_POSITIVE);
            service.getConnection(mCid).acceptCert(mFingerprint, accept);
            finish();
        }
    };

    new AlertDialog.Builder(this)
        .setTitle(R.string.cert_dialog_title)
        .setMessage(Html.fromHtml(getString(R.string.connection_cert_dialog_message, mHostname, mError, mFingerprint)))
        .setPositiveButton(R.string.accept, listener)
        .setNegativeButton(R.string.reject, listener)
        .show();
}
 
Example 3
Source File: ColorDialogPreference.java    From LokiBoard-Android-Keylogger with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(final DialogInterface dialog, final int which) {
    super.onClick(dialog, which);
    final String key = getKey();
    if (which == DialogInterface.BUTTON_POSITIVE) {
        super.onClick(dialog, which);
        final int value = Color.rgb(
                mSeekBarRed.getProgress(),
                mSeekBarGreen.getProgress(),
                mSeekBarBlue.getProgress());
        mValueProxy.writeValue(value, key);
        return;
    }
    if (which == DialogInterface.BUTTON_NEUTRAL) {
        super.onClick(dialog, which);
        mValueProxy.writeDefaultValue(key);
        return;
    }
}
 
Example 4
Source File: AccountsSettingsFragment.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(final DialogInterface dialog, final int which) {
    final String oldAccount = getSignedInAccountName();
    switch (which) {
        case DialogInterface.BUTTON_POSITIVE: // Signed in
            final ListView lv = ((AlertDialog)dialog).getListView();
            final String newAccount =
                    (String) lv.getItemAtPosition(lv.getCheckedItemPosition());
            getSharedPreferences()
                    .edit()
                    .putString(PREF_ACCOUNT_NAME, newAccount)
                    .apply();
            AccountStateChangedListener.onAccountSignedIn(oldAccount, newAccount);
            if (mDependentPreference != null) {
                mDependentPreference.setChecked(true);
            }
            break;
        case DialogInterface.BUTTON_NEUTRAL: // Signed out
            AccountStateChangedListener.onAccountSignedOut(oldAccount);
            getSharedPreferences()
                    .edit()
                    .remove(PREF_ACCOUNT_NAME)
                    .apply();
            break;
    }
}
 
Example 5
Source File: BootstrapDialogUtil.java    From gandalf with Apache License 2.0 5 votes vote down vote up
public static void showOptionalUpdateDialog(@NonNull final Activity activity,
                                            @NonNull final Gandalf gandalf,
                                            @NonNull final OptionalUpdate optionalUpdate,
                                            @NonNull final BootstrapDialogListener bootstrapDialogListener) {

    DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                gandalf.getOnUpdateSelectedListener().onUpdateSelected(activity);
            } else if (which == DialogInterface.BUTTON_NEUTRAL) {
                gandalf.save(optionalUpdate);
                bootstrapDialogListener.continueLoading();
            } else {
                if (ActivityStateUtil.isActivityValid(activity)) {
                    activity.finish();
                }
            }
        }
    };

    if (ActivityStateUtil.isActivityValid(activity)) {
        DialogStringsHolder dialogStringsHolder = gandalf.getDialogStringsHolder();

        String optionalUpdateMessage = dialogStringsHolder.getUpdateAvailableMessage();
        if (StringUtils.isBlank(optionalUpdateMessage)) {
            optionalUpdateMessage = optionalUpdate.getMessage();
        }

        new AlertDialog.Builder(activity)
                .setTitle(dialogStringsHolder.getUpdateAvailableTitle())
                .setMessage(optionalUpdateMessage)
                .setPositiveButton(dialogStringsHolder.getDownloadUpdateButtonText(), onClickListener)
                .setNeutralButton(dialogStringsHolder.getSkipUpdateButtonText(), onClickListener)
                .setNegativeButton(dialogStringsHolder.getCloseAppButtonText(), onClickListener)
                .setCancelable(false)
                .show();
    }
}
 
Example 6
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 7
Source File: MainActivity.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    if (which >= 0) {
        index = which;
    } else {
        //用户单击的是【确定】按钮
        if (which == DialogInterface.BUTTON_POSITIVE) {
            SharedPreferenceUtils.putString(MainActivity.this, "select_ua", index + "");
            WebViewFragment.getInstance().setUserAgent();
        }
    }
}
 
Example 8
Source File: FolderAddDialog.java    From Man-Man with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    switch (which) {
        case DialogInterface.BUTTON_POSITIVE:
            listener.receiveResult(pwd);
            return;
        default:
            break;
    }
}
 
Example 9
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 10
Source File: AlertController.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
/**
 * Sets a click listener or a message to be sent when the button is clicked.
 * You only need to pass one of {@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 button.
 * @param icon The icon to display in button.
 * @param listener The {@link DialogInterface.OnClickListener} to use.
 * @param msg The {@link Message} to be sent when clicked.
 */
public void setButton(int whichButton, CharSequence text, Drawable icon,
                      DialogInterface.OnClickListener listener, Message msg) {

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

    switch (whichButton) {

        case DialogInterface.BUTTON_POSITIVE:
            mButtonBundlePositive.buttonText = text;
            mButtonBundlePositive.buttonIcon = icon;
            mButtonBundlePositive.buttonMessage = msg;
            break;

        case DialogInterface.BUTTON_NEGATIVE:
            mButtonBundleNegative.buttonText = text;
            mButtonBundleNegative.buttonIcon = icon;
            mButtonBundleNegative.buttonMessage = msg;
            break;

        case DialogInterface.BUTTON_NEUTRAL:
            mButtonBundleNeutral.buttonText = text;
            mButtonBundleNeutral.buttonIcon = icon;
            mButtonBundleNeutral.buttonMessage = msg;
            break;

        default:
            throw new IllegalArgumentException("Button does not exist");
    }
}
 
Example 11
Source File: MLAlertController.java    From NewXmPluginSDK 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 12
Source File: LibraryAdapter.java    From TextFiction with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
	if (which == DialogInterface.BUTTON_POSITIVE) {
		FileUtil.deleteGame(deleteMe);
		remove(deleteMe);
		notifyDataSetChanged();
	}
}
 
Example 13
Source File: JavascriptAppModalDialog.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:
            onPositiveButtonClicked();
            break;
        case DialogInterface.BUTTON_NEGATIVE:
            onNegativeButtonClicked();
            break;
        default:
            Log.e(TAG, "Unexpected button pressed in dialog: " + which);
    }
}
 
Example 14
Source File: MeteredDataRestrictionInfoAdapter.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    if (which == DialogInterface.BUTTON_POSITIVE) {
        final List<String> pkgNames = new ArrayList<>();
        final int size = mIsComponentCheckedList.size();
        for (int i = 0; i < size; ++i) {
            if (mIsComponentCheckedList.get(i)) {
                pkgNames.add(getItem(i).resolvePackageName);
            }
        }
        setMeteredDataRestrictedPkgs(pkgNames);
    }
}
 
Example 15
Source File: AlertController.java    From PreferenceFragment 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 16
Source File: ConnectionFragment.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialogInterface, int which) {
    switch (which) {
        case DialogInterface.BUTTON_POSITIVE:
            mPresenter.executeConnect(getConnectModel());
            break;
    }
}
 
Example 17
Source File: BootstrapDialogUtil.java    From gandalf with Apache License 2.0 5 votes vote down vote up
public static void showRequiredUpdateDialog(@NonNull final Activity activity,
                                            @NonNull final Gandalf gandalf,
                                            @NonNull final RequiredUpdate requiredUpdate) {

    DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                gandalf.getOnUpdateSelectedListener().onUpdateSelected(activity);
            } else {
                if (ActivityStateUtil.isActivityValid(activity)) {
                    activity.finish();
                }
            }
        }
    };

    if (ActivityStateUtil.isActivityValid(activity)) {
        DialogStringsHolder dialogStringsHolder = gandalf.getDialogStringsHolder();

        String requiredUpdateMessage = dialogStringsHolder.getUpdateRequiredMessage();
        if (StringUtils.isBlank(requiredUpdateMessage)) {
            requiredUpdateMessage = requiredUpdate.getMessage();
        }

        new AlertDialog.Builder(activity)
                .setTitle(dialogStringsHolder.getUpdateRequiredTitle())
                .setMessage(requiredUpdateMessage)
                .setPositiveButton(dialogStringsHolder.getDownloadUpdateButtonText(), onClickListener)
                .setNegativeButton(dialogStringsHolder.getCloseAppButtonText(), onClickListener)
                .setCancelable(false)
                .show();
    }
}
 
Example 18
Source File: CommandDialogFragment.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    String command = mEditText.getText().toString();
    int id = 0;
    if (getArguments() != null) id = getArguments().getInt(DIALOG_ID_KEY);
    switch (which) {
        case DialogInterface.BUTTON_POSITIVE:
            mListener.onDialogFinish(command, false, id);
            break;
        case DialogInterface.BUTTON_NEUTRAL:
            mListener.onDialogFinish(command, true, id);
            break;
    }
}
 
Example 19
Source File: MemorizingActivity.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
public void onClick(DialogInterface dialog, int btnId) {
    int decision;
    dialog.dismiss();
    switch (btnId) {
        case DialogInterface.BUTTON_POSITIVE:
            decision = MTMDecision.DECISION_ALWAYS;
            break;
        case DialogInterface.BUTTON_NEUTRAL:
            decision = MTMDecision.DECISION_ONCE;
            break;
        default:
            decision = MTMDecision.DECISION_ABORT;
    }
    sendDecision(decision);
}
 
Example 20
Source File: RuleSeekBar.java    From talkback with Apache License 2.0 4 votes vote down vote up
@Override
public void handleDialogClick(int buttonClicked) {
  if (buttonClicked == DialogInterface.BUTTON_POSITIVE) {
    submitDialog();
  }
}