Java Code Examples for android.content.DialogInterface.OnClickListener

The following are Jave code examples for showing how to use OnClickListener of the android.content.DialogInterface class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: pets   File: EditorActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // User clicked on a menu option in the app bar overflow menu
    switch (item.getItemId()) {
        // Respond to a click on the "Save" menu option
        case R.id.action_save:
            // insert the pet to database
            savePet();
            // close the windows with the forms
            finish();
            return true;
        // Respond to a click on the "Delete" menu option
        case R.id.action_delete:
            // Do nothing for now
            return true;
        // Respond to a click on the "Up" arrow button in the app bar
        case android.R.id.home:
            // Navigate back to parent activity (CatalogActivity)
            // if no changes, continue back to parent activity
            if (!mPetHasChanged) {
                NavUtils.navigateUpFromSameTask(EditorActivity.this);
                return true;
            }

            // if there are unsaved changes
            DialogInterface.OnClickListener discardButtonClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // User clicked "Discard Button"
                    NavUtils.navigateUpFromSameTask(EditorActivity.this);
                }
            };

            // Show Dialog
            showUnsavedChangesDialog(discardButtonClickListener);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 2
Project: Aardvark   File: App_Framework.java   View Source Code Vote up 6 votes
/**CUSTOMIZEABLE pop up input text for positive button (right button) and negative button (left button)*/
public void popup_show(String popup_title, String popup_hint, DialogInterface.OnClickListener positiveOCL,DialogInterface.OnClickListener negativeOCL, String positiveText, String negativeText)
{
    //build popup dialogue
    popUpWindow = new AlertDialog.Builder(context);
    popUpWindow.setTitle(popup_title);

    //set up the input field
    popup_inputText = new EditText(context);
    popup_inputText.setInputType(InputType.TYPE_CLASS_TEXT);
    popup_inputText.setHint(popup_hint); //set hint on what value the user should enter
    popUpWindow.setView(popup_inputText);

    //set up positive button
    popUpWindow.setPositiveButton(positiveText, positiveOCL);

    //set up negative button
    popUpWindow.setNegativeButton(negativeText, negativeOCL);

    popUpWindow.show();
}
 
Example 3
Project: OSchina_resources_android   File: DialogHelper.java   View Source Code Vote up 6 votes
/**
 * 获取一个验证对话框
 */
public static AlertDialog.Builder getConfirmDialog(
        Context context,
        String title,
        String message,
        String positiveText,
        String negativeText,
        boolean cancelable,
        DialogInterface.OnClickListener positiveListener,
        DialogInterface.OnClickListener negativeListener) {
    return getDialog(context)
            .setCancelable(cancelable)
            .setTitle(title)
            .setMessage(message)
            .setPositiveButton(positiveText, positiveListener)
            .setNegativeButton(negativeText, negativeListener);
}
 
Example 4
Project: OSchina_resources_android   File: DialogHelper.java   View Source Code Vote up 6 votes
/**
 * 获取一个输入对话框
 */
public static AlertDialog.Builder getInputDialog(
        Context context,
        String title,
        AppCompatEditText editText,
        String positiveText,
        String negativeText,
        boolean cancelable,
        DialogInterface.OnClickListener positiveListener,
        DialogInterface.OnClickListener negativeListener) {
    return getDialog(context)
            .setCancelable(cancelable)
            .setTitle(title)
            .setView(editText)
            .setPositiveButton(positiveText, positiveListener)
            .setNegativeButton(negativeText, negativeListener);
}
 
Example 5
Project: Fuse   File: BarcodeCaptureActivity.java   View Source Code Vote up 5 votes
/**
 * Callback for the result from requesting permissions. This method
 * is invoked for every call on {@link #requestPermissions(String[], int)}.
 * <p>
 * <strong>Note:</strong> It is possible that the permissions request interaction
 * with the user is interrupted. In this case you will receive empty permissions
 * and results arrays which should be treated as a cancellation.
 * </p>
 *
 * @param requestCode  The request code passed in {@link #requestPermissions(String[], int)}.
 * @param permissions  The requested permissions. Never null.
 * @param grantResults The grant results for the corresponding permissions
 *                     which is either {@link PackageManager#PERMISSION_GRANTED}
 *                     or {@link PackageManager#PERMISSION_DENIED}. Never null.
 * @see #requestPermissions(String[], int)
 */
@Override
public void onRequestPermissionsResult(int requestCode,
                                       @NonNull String[] permissions,
                                       @NonNull int[] grantResults) {
    if (requestCode != RC_HANDLE_CAMERA_PERM) {
        Log.d(TAG, "Got unexpected permission result: " + requestCode);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        return;
    }

    if (grantResults.length != 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        Log.d(TAG, "Camera permission granted - initialize the camera source");
        // we have permission, so create the camerasource
        //boolean autoFocus = getIntent().getBooleanExtra(AutoFocus,false);

        //boolean useFlash = getIntent().getBooleanExtra(UseFlash, false);
        createCameraSource(true);
        return;
    }

    Log.e(TAG, "Permission not granted: results len = " + grantResults.length +
            " Result code = " + (grantResults.length > 0 ? grantResults[0] : "(empty)"));

    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            finish();
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("QR Scanner")
            .setMessage("This application cannot run because it does not have the camera permission.  The application will now exit.")
            .setPositiveButton("OK", listener)
            .show();
}
 
Example 6
Project: Veggietizer   File: Popup.java   View Source Code Vote up 5 votes
/**
 * Shows an already unlocked achievement listed in the achievement activity.
    *
 * @param achievement The unlocked achievement to show.
 * @param context The application context.
    * @return  The achievement.
 */
public static AlertDialog showAchievement(Achievement achievement, Context context,
                                      DialogInterface.OnClickListener onSubmitListener) {
	return showAchievement(achievement, context, onSubmitListener, achievement.getHeading(),
               achievement.getShareText(),
               context.getResources().getString(R.string.achievement_requirements_heading_unlocked),
               achievement.getRequirements());
}
 
Example 7
Project: hey-permission   File: PermissionDialogs.java   View Source Code Vote up 5 votes
private static void showDefaultAppSettingsDialog(@NonNull final BasePermissionInvoker invoker,
                                                 final int requestCode) {
    final Context context = invoker.getContext();
    final DialogInterface.OnClickListener settingListener =
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    invoker.startActivityForResult(
                            PermissionDialogs.appSettingsIntent(context), requestCode);
                }
            };
    showAppSettingsDialog(context, R.string.hey_permission_permission_denied,
            settingListener, null);
}
 
Example 8
Project: AOSP-Kayboard-7.1.2   File: AccountsSettingsFragment.java   View Source Code Vote up 5 votes
/**
 * Creates an account picker dialog showing the given accounts in a list and selecting
 * the selected account by default.  The list of accounts must not be null/empty.
 *
 * Package-private for testing.
 *
 * @param accounts list of accounts on the device.
 * @param selectedAccount currently selected account
 * @param positiveButtonClickListener listener that gets called when positive button is
 * clicked
 */
@UsedForTesting
AlertDialog createAccountPicker(final String[] accounts,
        final String selectedAccount,
        final DialogInterface.OnClickListener positiveButtonClickListener) {
    if (accounts == null || accounts.length == 0) {
        throw new IllegalArgumentException("List of accounts must not be empty");
    }

    // See if the currently selected account is in the list.
    // If it is, the entry is selected, and a sign-out button is provided.
    // If it isn't, select the 0th account by default which will get picked up
    // if the user presses OK.
    int index = 0;
    boolean isSignedIn = false;
    for (int i = 0;  i < accounts.length; i++) {
        if (TextUtils.equals(accounts[i], selectedAccount)) {
            index = i;
            isSignedIn = true;
            break;
        }
    }
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
            .setTitle(R.string.account_select_title)
            .setSingleChoiceItems(accounts, index, null)
            .setPositiveButton(R.string.account_select_ok, positiveButtonClickListener)
            .setNegativeButton(R.string.account_select_cancel, null);
    if (isSignedIn) {
        builder.setNeutralButton(R.string.account_select_sign_out, positiveButtonClickListener);
    }
    return builder.create();
}
 
Example 9
Project: TripBuyer   File: MMAlert.java   View Source Code Vote up 5 votes
public static AlertDialog showAlert(final Context context, final int msg, final int title, final int yes, final int no, final DialogInterface.OnClickListener lOk,
									final DialogInterface.OnClickListener lCancel) {
	if (context instanceof Activity && ((Activity) context).isFinishing()) {
		return null;
	}

	final Builder builder = new AlertDialog.Builder(context);
	builder.setIcon(R.drawable.ic_dialog_alert);
	builder.setTitle(title);
	builder.setMessage(msg);
	builder.setPositiveButton(yes, lOk);
	builder.setNegativeButton(no, lCancel);
	// builder.setCancelable(false);
	final AlertDialog alert = builder.create();
	alert.show();
	return alert;
}
 
Example 10
Project: kyandroid   File: AlertUtils.java   View Source Code Vote up 5 votes
public static void showDialogDualActions(Context context, String title, String message, String positive, String negative, DialogInterface.OnClickListener positiveCallback, DialogInterface.OnClickListener negativeCallback) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(title)
            .setMessage(message)
            .setPositiveButton(positive, positiveCallback)
            .setNegativeButton(negative, negativeCallback);
    builder.create().show();
}
 
Example 11
Project: KernelAdiutor-Mod   File: Dialog.java   View Source Code Vote up 4 votes
@Override
public Dialog setNegativeButton(CharSequence text, DialogInterface.OnClickListener listener) {
    return (Dialog) super.setNegativeButton(text, listener);
}
 
Example 12
Project: AndroidModules-Samples   File: AlertDialogHelper.java   View Source Code Vote up 4 votes
@SuppressWarnings({"WeakerAccess", "unused"})
public Dialog showError(Throwable e, DialogInterface.OnClickListener clickListener) {
    return showError(e.getMessage(), clickListener);
}
 
Example 13
Project: couch-potatoes   File: UploadImageFragment.java   View Source Code Vote up 4 votes
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if ( resultCode != RESULT_OK )
        return;

    // Get photo URI if photo chosen from SD Card
    if ( requestCode == PICK_FROM_FILE) {
        imageCaptureUri = data.getData();
    }

    // Get an InputStream of the photo
    try {
        is = view.getContext().getContentResolver().openInputStream(imageCaptureUri);
    } catch ( FileNotFoundException e ) {
        e.printStackTrace();
    }

    // Handler for photo upload AlertDialog
    dialogClickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which){
                // Case to upload photo
                case DialogInterface.BUTTON_POSITIVE:
                    UploadImage( is );
                    break;
                // Case to cancel photo upload
                case DialogInterface.BUTTON_NEGATIVE:
                    break;
            }
        }
    };

    // Create EditText field for AlertDialog
    input = new EditText(view.getContext());
    input.setInputType(InputType.TYPE_CLASS_TEXT);

    // Prompt user to upload the photo and allow user to enter a photo description
    AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
    builder.setMessage( "Enter description:" )
            .setNegativeButton("Cancel", dialogClickListener)
            .setPositiveButton("Upload", dialogClickListener)
            .setView(input)
            .show();
}
 
Example 14
Project: CompatAlertDialog   File: AlertDialog.java   View Source Code Vote up 4 votes
@Override
public Builder setSingleChoiceItems(ListAdapter adapter, int checkedItem, final DialogInterface
        .OnClickListener listener) {
    builder.setSingleChoiceItems(adapter, checkedItem, listener);
    return this;
}
 
Example 15
Project: javaide   File: ColorPickerDialogBuilder.java   View Source Code Vote up 4 votes
public ColorPickerDialogBuilder setNegativeButton(CharSequence text, DialogInterface.OnClickListener onClickListener) {
	builder.setNegativeButton(text, onClickListener);
	return this;
}
 
Example 16
Project: CompatAlertDialog   File: AlertDialog.java   View Source Code Vote up 4 votes
public Builder setSingleChoiceItems(CharSequence[] items, int checkedItem, final DialogInterface
        .OnClickListener listener) {
    builder.setSingleChoiceItems(items, checkedItem, listener);
    return this;
}
 
Example 17
Project: CompatAlertDialog   File: AlertDialog.java   View Source Code Vote up 4 votes
public Builder setItems(@ArrayRes int itemsId, final DialogInterface.OnClickListener listener) {
    builder.setItems(itemsId, listener);
    return this;
}
 
Example 18
Project: quickhybrid-android   File: QuickDialog.java   View Source Code Vote up 2 votes
/**
 * 设置取消按钮
 *
 * @param negativeButtonText
 * @param listener
 * @return
 */
public Builder setNegativeButton(int negativeButtonText, DialogInterface.OnClickListener listener) {
    this.negativeButtonText = (String) context.getText(negativeButtonText);
    this.negativeButtonClickListener = listener;
    return this;
}
 
Example 19
Project: quickhybrid-android   File: DialogUtil.java   View Source Code Vote up 2 votes
/**
 * 自定义对话框
 *
 * @param con
 * @param title
 * @param cancelable
 * @param view
 * @param gravity
 * @param listener1
 * @param listener2
 */
public static void showCustomeDialog(Context con, String title, boolean cancelable, View view, int gravity,
                                     DialogInterface.OnClickListener listener1, DialogInterface.OnClickListener listener2) {
    showCustomeDialog(con, title, cancelable, view, gravity, con.getString(R.string.confirm), con.getString(R.string.cancel), listener1, listener2);
}
 
Example 20
Project: UIWidget   File: UIAlertView.java   View Source Code Vote up 2 votes
/**
 * 设置右边按钮
 *
 * @param text
 * @param listener
 * @return
 */
public UIAlertView setPositiveButton(int text,
                                     final DialogInterface.OnClickListener listener) {
    return setPositiveButton(context.getString(text), listener);
}