Java Code Examples for android.app.AlertDialog#BUTTON_POSITIVE

The following examples show how to use android.app.AlertDialog#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: DlgConfirmReplace.java    From drmips with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
	switch(which) {
		case AlertDialog.BUTTON_POSITIVE: // OK
			Bundle args = getArguments();
			DrMIPSActivity activity = (DrMIPSActivity)getActivity();
			String path = args.getString("path");
			if(path != null) {
				activity.saveFile(new File(path));
			}
			break;

		case AlertDialog.BUTTON_NEGATIVE: // Cancel
			dismiss();
			break;
	}
}
 
Example 2
Source File: ExecuteRecoveryMeasuresPresenter.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private void showInstallMethodChooser() {
    String title = StringUtils.getStringRobust(mActivity, R.string.recovery_measure_reinstall_method);
    String message = StringUtils.getStringRobust(mActivity, R.string.recovery_measure_reinstall_detail);
    StandardAlertDialog d = new StandardAlertDialog(mActivity, title, message);
    DialogInterface.OnClickListener listener = (dialog, which) -> {
        mActivity.dismissAlertDialog();
        if (which == AlertDialog.BUTTON_POSITIVE) {
            doOnlineAppInstall();
        } else if (which == AlertDialog.BUTTON_NEGATIVE) {
            showOfflineInstallActivity();
        }
    };
    d.setPositiveButton(StringUtils.getStringRobust(mActivity, R.string.recovery_measure_reinstall_online_method), listener);
    d.setNegativeButton(StringUtils.getStringRobust(mActivity, R.string.recovery_measure_reinstall_offline_method), listener);
    mActivity.showAlertDialog(d);
}
 
Example 3
Source File: AppManagerActivity.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
/**
 * Warns user that the action they are trying to conduct will result in the current
 * session being logged out
 */
private void triggerLogoutWarning() {
    String title = getString(R.string.logging_out);
    String message = getString(R.string.logout_warning);
    StandardAlertDialog d = new StandardAlertDialog(this, title, message);
    DialogInterface.OnClickListener listener = (dialog, which) -> {
        dismissAlertDialog();
        if (which == AlertDialog.BUTTON_POSITIVE) {
            CommCareApplication.instance().expireUserSession();
            installApp();
        }
    };
    d.setPositiveButton(getString(R.string.ok), listener);
    d.setNegativeButton(getString(R.string.cancel), listener);
    showAlertDialog(d);
}
 
Example 4
Source File: SingleAppManagerActivity.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
/**
 * Warns a user that the action they are trying to conduct will result in the current
 * session being logged out
 */
private void triggerLogoutWarning(final int actionKey) {
    StandardAlertDialog d = new StandardAlertDialog(this, getString(R.string.logging_out),
            getString(R.string.logout_warning));
    DialogInterface.OnClickListener listener = (dialog, which) -> {
        dismissAlertDialog();
        if (which == AlertDialog.BUTTON_POSITIVE) {
            CommCareApplication.instance().expireUserSession();
            switch (actionKey) {
                case LOGOUT_FOR_UPDATE:
                    update();
                    break;
                case LOGOUT_FOR_VERIFY_MM:
                    verifyResources();
                    break;
                case LOGOUT_FOR_ARCHIVE:
                    toggleArchived();
            }
        }
    };
    d.setPositiveButton(getString(R.string.ok), listener);
    d.setNegativeButton(getString(R.string.cancel), listener);
    showAlertDialog(d);
}
 
Example 5
Source File: CommCareFormDumpActivity.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private void showWarningMessage() {
    StandardAlertDialog d = new StandardAlertDialog(this,
            Localization.get("bulk.form.alert.title"), Localization.get("bulk.form.warning"));
    DialogInterface.OnClickListener listener = (dialog, id) -> {
        dialog.dismiss();
        if (id == AlertDialog.BUTTON_POSITIVE) {
            acknowledgedRisk = true;
            dismissAlertDialog();
        } else {
            exitDump();
        }
    };
    d.setPositiveButton("OK", listener);
    d.setNegativeButton("NO", listener);
    showAlertDialog(d);
}
 
Example 6
Source File: CommCareWiFiDirectActivity.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private void showDialog(Activity activity, String title, String message) {
    StandardAlertDialog d = new StandardAlertDialog(activity, title, message);
    DialogInterface.OnClickListener listener = (dialog, which) -> {
        switch (which) {
            case AlertDialog.BUTTON_POSITIVE:
                beSubmitter();
                break;
            case AlertDialog.BUTTON_NEUTRAL:
                beReceiver();
                break;
            case AlertDialog.BUTTON_NEGATIVE:
                beSender();
                break;
        }
        dismissAlertDialog();
    };
    d.setNeutralButton(localize("wifi.direct.receive.forms"), listener);
    d.setNegativeButton(localize("wifi.direct.transfer.forms"), listener);
    d.setPositiveButton(localize("wifi.direct.submit.forms"), listener);
    showAlertDialog(d);
}
 
Example 7
Source File: DlgConfirmDelete.java    From drmips with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
	switch(which) {
		case AlertDialog.BUTTON_POSITIVE: // OK
			Bundle args = getArguments();
			DrMIPSActivity activity = (DrMIPSActivity)getActivity();
			String path = args.getString("path");
			File file;

			if(path != null && (file = new File(path)).exists()) {
				if(file.delete()) {
					Toast.makeText(getActivity(), R.string.file_deleted, Toast.LENGTH_SHORT).show();
					activity.newFile();
				} else
					Toast.makeText(getActivity(), R.string.error_deleting_file, Toast.LENGTH_SHORT).show();
			}
			break;

		case AlertDialog.BUTTON_NEGATIVE: // Cancel
			dismiss();
			break;
	}
}
 
Example 8
Source File: PdfActivity.java    From Reader with Apache License 2.0 6 votes vote down vote up
@Override
public void onBackPressed() {
    if (core != null && core.hasChanges()) {
        mAlertBuilder = new AlertDialog.Builder(mContext);
        DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                if (which == AlertDialog.BUTTON_POSITIVE)
                    core.save();

                finish();
            }
        };
        AlertDialog alert = mAlertBuilder.create();
        alert.setTitle("MuPDF");
        alert.setMessage(getString(R.string.document_has_changes_save_them_));
        alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.yes), listener);
        alert.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.no), listener);
        alert.show();
    } else {
        super.onBackPressed();
    }
}
 
Example 9
Source File: DlgSave.java    From drmips with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
	switch(which) {
		case AlertDialog.BUTTON_POSITIVE: // OK
			String path = txtFilename.getText().toString().trim();
			if(!path.isEmpty()) { // save the file
				if(!path.contains(".")) path += ".asm"; // append extension if missing
				File file = new File(DrMIPS.getApplication().getCodeDir().getAbsolutePath() + File.separator + path);
				DrMIPSActivity activity = (DrMIPSActivity)getActivity();

				if(!file.exists()) { // new file
					activity.saveFile(file);
				} else { // file exists
					DlgConfirmReplace.newInstance(file.getPath()).show(getFragmentManager(), "confirm-replace-dialog");
				}
			}
			break;

		case AlertDialog.BUTTON_NEGATIVE: // Cancel
			dismiss();
			break;
	}
}
 
Example 10
Source File: MuPDFActivity.java    From mupdf-android with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onBackPressed() {
	if (core != null && core.hasChanges()) {
		DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				if (which == AlertDialog.BUTTON_POSITIVE)
					core.save();

				finish();
			}
		};
		AlertDialog alert = mAlertBuilder.create();
		alert.setTitle("MuPDF");
		alert.setMessage(getString(R.string.document_has_changes_save_them_));
		alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.yes), listener);
		alert.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.no), listener);
		alert.show();
	} else {
		super.onBackPressed();
	}
}
 
Example 11
Source File: AbstractListenerWrapper.java    From AndroidMaterialDialog with Apache License 2.0 6 votes vote down vote up
/**
 * Attempts to close the dialog depending on the type of the buttonType or list view, the
 * listener belongs to.
 */
protected final void attemptCloseDialog() {
    switch (buttonType) {
        case AlertDialog.BUTTON_NEGATIVE:
            dialog.cancel();
            break;
        case AlertDialog.BUTTON_NEUTRAL:
            dialog.cancel();
            break;
        case AlertDialog.BUTTON_POSITIVE:
            dialog.dismiss();
            break;
        default:
            break;
    }
}
 
Example 12
Source File: DlgEditRegister.java    From drmips with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
	switch(which) {
		case AlertDialog.BUTTON_POSITIVE: //OK
			String value = txtRegisterValue.getText().toString().trim();
			int val;
			if(!value.isEmpty()) {
				try {
					Bundle args = getArguments();
					DrMIPSActivity activity = (DrMIPSActivity)getActivity();
					int index = args.getInt("index");
					if (index >= 0 && index <= activity.getCPU().getRegBank().getNumberOfRegisters()) {
						val = Integer.parseInt(value);
						activity.setRegisterValue(index, val);
						activity.refreshRegistersTableValues();
					}
				} catch(NumberFormatException ex) {
					Toast.makeText(getActivity(), R.string.invalid_value, Toast.LENGTH_SHORT).show();
				}
			}
			break;

		case AlertDialog.BUTTON_NEGATIVE: // Cancel
			dismiss();
			break;
	}
}
 
Example 13
Source File: DlgEditDataMemory.java    From drmips with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
	switch(which) {
		case AlertDialog.BUTTON_POSITIVE: // OK
			String value = txtDataMemoryValue.getText().toString().trim();
			int val;
			if(!value.isEmpty()) {
				try {
					Bundle args = getArguments();
					DrMIPSActivity activity = (DrMIPSActivity)getActivity();
					int index = args.getInt("index");

					if(index >= 0 && index < activity.getCPU().getDataMemory().getMemorySize()) {
						val = Integer.parseInt(value);
						activity.getCPU().getDataMemory().setDataInIndex(index, val);
						activity.refreshDataMemoryTableValues();
						if(activity.getDatapath() != null) activity.getDatapath().refresh();
					}
				} catch(NumberFormatException ex) {
					Toast.makeText(getActivity(), R.string.invalid_value, Toast.LENGTH_SHORT).show();
				}
			}
			break;

		case AlertDialog.BUTTON_NEGATIVE: // Cancel
			dismiss();
			break;
	}
}
 
Example 14
Source File: DlgConfirmExit.java    From drmips with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
	switch(which) {
		case AlertDialog.BUTTON_POSITIVE: // OK
			dismiss();
			getActivity().finish();
			break;
		case AlertDialog.BUTTON_NEGATIVE: // Cancel
			dismiss();
			break;
	}
}
 
Example 15
Source File: DlgChangeLatency.java    From drmips with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
	switch(which) {
		case AlertDialog.BUTTON_POSITIVE: // OK
			try {
				Bundle args = getArguments();
				DrMIPSActivity activity = (DrMIPSActivity)getActivity();
				Component component = activity.getCPU().getComponent(args.getString("id", ""));

				int lat = Integer.parseInt(txtLatency.getText().toString());
				if(lat >= 0 && component != null) {
					component.setLatency(lat);
					activity.getCPU().calculatePerformance();
					activity.getDatapath().refresh();
					activity.getDatapath().invalidate();
				} else {
					Toast.makeText(getActivity(), R.string.invalid_value, Toast.LENGTH_SHORT).show();
				}
			} catch(NumberFormatException ex) {
				Toast.makeText(getActivity(), R.string.invalid_value, Toast.LENGTH_SHORT).show();
			}
			break;

		case AlertDialog.BUTTON_NEGATIVE: // Cancel
			dismiss();
			break;
	}
}
 
Example 16
Source File: DlgAbout.java    From drmips with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
	switch(which) {
		case AlertDialog.BUTTON_POSITIVE: // OK
			dismiss();
			break;
		case AlertDialog.BUTTON_NEUTRAL: // License
			DlgLicense.newInstance().show(getFragmentManager(), "license-dialog");
			break;
		case AlertDialog.BUTTON_NEGATIVE: // Credits
			DlgCredits.newInstance().show(getFragmentManager(), "credits-dialog");
			break;
	}
}
 
Example 17
Source File: SingleAppManagerActivity.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
/**
 * onClick method for Uninstall button. Before actually conducting the uninstall, warns
 * the user that it will also result in a reboot of CC
 *
 * @param v linter sees this as unused, but is required for a button to find its onClick method
 */
public void rebootAlertDialog(View v) {
    StandardAlertDialog d = new StandardAlertDialog(this, getString(R.string.uninstalling),
            getString(R.string.uninstall_reboot_warning));
    DialogInterface.OnClickListener listener = (dialog, which) -> {
        dismissAlertDialog();
        if (which == AlertDialog.BUTTON_POSITIVE) {
            uninstall();
        }
    };
    d.setPositiveButton(getString(R.string.ok), listener);
    d.setNegativeButton(getString(R.string.cancel), listener);
    showAlertDialog(d);
}
 
Example 18
Source File: SizeLimitActivity.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    boolean isRequired =
            mCurrentIntent.getExtras().getBoolean(DownloadInfo.EXTRA_IS_WIFI_REQUIRED);
    if (isRequired && which == AlertDialog.BUTTON_NEGATIVE) {
        getContentResolver().delete(mCurrentUri, null, null);
    } else if (!isRequired && which == AlertDialog.BUTTON_POSITIVE) {
        ContentValues values = new ContentValues();
        values.put(Downloads.COLUMN_BYPASS_RECOMMENDED_SIZE_LIMIT, true);
        getContentResolver().update(mCurrentUri, values , null, null);
    }
    dialogClosed();
}
 
Example 19
Source File: WVersionManager.java    From KinoCast with MIT License 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    switch (which) {
        case AlertDialog.BUTTON_POSITIVE:
            updateNow(getUpdateUrl());
            break;
        case AlertDialog.BUTTON_NEUTRAL:
            remindMeLater(getReminderTimer());
            break;
        case AlertDialog.BUTTON_NEGATIVE:
            ignoreThisVersion();
            break;
    }
}
 
Example 20
Source File: NumberPickerPreference.java    From ForceDoze with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onClick(DialogInterface dialog, int which) {
    if (AlertDialog.BUTTON_POSITIVE == which) {
        save(getValue());
    }
}