Search in sources :

Example 1 with BUTTON_NEGATIVE

use of android.content.DialogInterface.BUTTON_NEGATIVE in project collect by opendatakit.

the class DeleteRepeatDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    String name = formController.getLastRepeatedGroupName();
    int repeatCount = formController.getLastRepeatedGroupRepeatCount();
    if (repeatCount != -1) {
        name += " (" + (repeatCount + 1) + ")";
    }
    AlertDialog alertDialog = new MaterialAlertDialogBuilder(getActivity()).create();
    alertDialog.setTitle(getActivity().getString(R.string.delete_repeat_ask));
    alertDialog.setMessage(getActivity().getString(R.string.delete_repeat_confirm, name));
    DialogInterface.OnClickListener quitListener = (dialog, i) -> {
        if (i == BUTTON_POSITIVE) {
            // yes
            formController.getAuditEventLogger().logEvent(AuditEvent.AuditEventType.DELETE_REPEAT, true, System.currentTimeMillis());
            formController.deleteRepeat();
            callback.deleteGroup();
        }
        alertDialog.cancel();
        dismiss();
    };
    setCancelable(false);
    alertDialog.setCancelable(false);
    alertDialog.setButton(BUTTON_POSITIVE, getActivity().getString(R.string.discard_group), quitListener);
    alertDialog.setButton(BUTTON_NEGATIVE, getActivity().getString(R.string.delete_repeat_no), quitListener);
    return alertDialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Context(android.content.Context) BUTTON_POSITIVE(android.content.DialogInterface.BUTTON_POSITIVE) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Dialog(android.app.Dialog) FormController(org.odk.collect.android.javarosawrapper.FormController) Nullable(androidx.annotation.Nullable) AuditEvent(org.odk.collect.android.formentry.audit.AuditEvent) R(org.odk.collect.android.R) BUTTON_NEGATIVE(android.content.DialogInterface.BUTTON_NEGATIVE) Collect(org.odk.collect.android.application.Collect) DialogInterface(android.content.DialogInterface) DialogFragment(androidx.fragment.app.DialogFragment) DialogInterface(android.content.DialogInterface) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) NonNull(androidx.annotation.NonNull)

Example 2 with BUTTON_NEGATIVE

use of android.content.DialogInterface.BUTTON_NEGATIVE in project collect by opendatakit.

the class AddRepeatDialog method show.

public static void show(Context context, String groupLabel, Listener listener) {
    AlertDialog alertDialog = new MaterialAlertDialogBuilder(context).create();
    DialogInterface.OnClickListener repeatListener = (dialog, i) -> {
        switch(i) {
            case BUTTON_POSITIVE:
                listener.onAddRepeatClicked();
                break;
            case BUTTON_NEGATIVE:
                listener.onCancelClicked();
                break;
        }
    };
    alertDialog.setMessage(context.getString(R.string.add_repeat_question, groupLabel));
    alertDialog.setButton(BUTTON_POSITIVE, context.getString(R.string.add_repeat), repeatListener);
    alertDialog.setButton(BUTTON_NEGATIVE, context.getString(R.string.dont_add_repeat), repeatListener);
    alertDialog.setCancelable(false);
    alertDialog.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Context(android.content.Context) BUTTON_POSITIVE(android.content.DialogInterface.BUTTON_POSITIVE) AlertDialog(androidx.appcompat.app.AlertDialog) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) R(org.odk.collect.android.R) BUTTON_NEGATIVE(android.content.DialogInterface.BUTTON_NEGATIVE) DialogInterface(android.content.DialogInterface) DialogInterface(android.content.DialogInterface) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Aggregations

Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 BUTTON_NEGATIVE (android.content.DialogInterface.BUTTON_NEGATIVE)2 BUTTON_POSITIVE (android.content.DialogInterface.BUTTON_POSITIVE)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)2 R (org.odk.collect.android.R)2 Dialog (android.app.Dialog)1 Bundle (android.os.Bundle)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 DialogFragment (androidx.fragment.app.DialogFragment)1 Collect (org.odk.collect.android.application.Collect)1 AuditEvent (org.odk.collect.android.formentry.audit.AuditEvent)1 FormController (org.odk.collect.android.javarosawrapper.FormController)1