Search in sources :

Example 11 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project collect by opendatakit.

the class BackgroundAudioPermissionDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    setCancelable(false);
    final FragmentActivity activity = requireActivity();
    return new MaterialAlertDialogBuilder(requireContext()).setMessage(R.string.background_audio_permission_explanation).setPositiveButton(R.string.ok, (dialog, which) -> {
        onOKClicked(activity);
    }).create();
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Dialog(android.app.Dialog) PermissionListener(org.odk.collect.permissions.PermissionListener) Timber(timber.log.Timber) FragmentActivity(androidx.fragment.app.FragmentActivity) Inject(javax.inject.Inject) DaggerUtils(org.odk.collect.android.injection.DaggerUtils) Nullable(androidx.annotation.Nullable) Toast(android.widget.Toast) R(org.odk.collect.android.R) DialogFragment(androidx.fragment.app.DialogFragment) PermissionsProvider(org.odk.collect.permissions.PermissionsProvider) FragmentActivity(androidx.fragment.app.FragmentActivity) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) NonNull(androidx.annotation.NonNull)

Example 12 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project collect by opendatakit.

the class CustomDatePickerDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new MaterialAlertDialogBuilder(getActivity()).setTitle(R.string.select_date).setView(R.layout.custom_date_picker_dialog).setPositiveButton(R.string.ok, (dialog, id) -> {
        LocalDateTime date = DateTimeUtils.getDateAsGregorian(getOriginalDate());
        viewModel.setSelectedDate(date.getYear(), date.getMonthOfYear() - 1, date.getDayOfMonth());
        dismiss();
    }).setNegativeButton(R.string.cancel, (dialog, id) -> dismiss()).create();
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Context(android.content.Context) Bundle(android.os.Bundle) DateTimeUtils(org.odk.collect.android.utilities.DateTimeUtils) ViewModelProvider(androidx.lifecycle.ViewModelProvider) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) DateTimeViewModel(org.odk.collect.android.widgets.viewmodels.DateTimeViewModel) Dialog(android.app.Dialog) LocalDateTime(org.joda.time.LocalDateTime) DatePickerDetails(org.odk.collect.android.logic.DatePickerDetails) TextView(android.widget.TextView) DateTimeWidgetUtils(org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils) R(org.odk.collect.android.R) View(android.view.View) NumberPicker(android.widget.NumberPicker) DialogFragment(androidx.fragment.app.DialogFragment) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Example 13 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder 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 14 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project collect by opendatakit.

the class QuitFormDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    String title = formSaveViewModel.getFormName() == null ? getActivity().getString(R.string.no_form_loaded) : formSaveViewModel.getFormName();
    List<IconMenuItem> items;
    if (settingsProvider.getProtectedSettings().getBoolean(ProtectedProjectKeys.KEY_SAVE_MID)) {
        items = ImmutableList.of(new IconMenuItem(R.drawable.ic_save, R.string.keep_changes), new IconMenuItem(R.drawable.ic_delete, R.string.do_not_save));
    } else {
        items = ImmutableList.of(new IconMenuItem(R.drawable.ic_delete, R.string.do_not_save));
    }
    ListView listView = DialogUtils.createActionListView(getActivity());
    final IconMenuListAdapter adapter = new IconMenuListAdapter(getActivity(), items);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener((parent, view, position, id) -> {
        IconMenuItem item = (IconMenuItem) adapter.getItem(position);
        if (item.getTextResId() == R.string.keep_changes) {
            if (listener != null) {
                listener.onSaveChangesClicked();
            }
        } else {
            formSaveViewModel.ignoreChanges();
            String action = getActivity().getIntent().getAction();
            if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_EDIT.equals(action)) {
                // caller is waiting on a picked form
                Uri uri = null;
                String path = formSaveViewModel.getAbsoluteInstancePath();
                if (path != null) {
                    Instance instance = new InstancesRepositoryProvider(requireContext()).get().getOneByPath(path);
                    if (instance != null) {
                        uri = InstancesContract.getUri(currentProjectProvider.getCurrentProject().getUuid(), instance.getDbId());
                    }
                }
                if (uri != null) {
                    getActivity().setResult(RESULT_OK, new Intent().setData(uri));
                }
            }
            getActivity().finish();
        }
        if (getDialog() != null) {
            getDialog().dismiss();
        }
    });
    return new MaterialAlertDialogBuilder(getActivity()).setTitle(getString(R.string.quit_application, title)).setNegativeButton(getActivity().getString(R.string.do_not_exit), (dialog, id) -> {
        dialog.cancel();
        dismiss();
    }).setView(listView).create();
}
Also used : InstancesRepositoryProvider(org.odk.collect.android.utilities.InstancesRepositoryProvider) ListView(android.widget.ListView) Instance(org.odk.collect.forms.instances.Instance) IconMenuListAdapter(org.odk.collect.android.adapters.IconMenuListAdapter) IconMenuItem(org.odk.collect.android.adapters.model.IconMenuItem) Intent(android.content.Intent) Uri(android.net.Uri) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) NonNull(androidx.annotation.NonNull)

Example 15 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project collect by opendatakit.

the class AuthDialogUtility method createDialog.

/**
 * @deprecated should use {@link ServerAuthDialogFragment} instead
 */
@Deprecated
public AlertDialog createDialog(final Context context, final AuthDialogUtilityResultListener resultListener, String url) {
    final View dialogView = LayoutInflater.from(context).inflate(R.layout.server_auth_dialog, null);
    String overriddenUrl = null;
    if (url != null) {
        if (!url.startsWith(webCredentialsUtils.getServerUrlFromPreferences())) {
            overriddenUrl = url;
            if (overriddenUrl.contains("?deviceID=")) {
                overriddenUrl = overriddenUrl.substring(0, overriddenUrl.indexOf("?deviceID="));
            }
        }
    }
    username = dialogView.findViewById(R.id.username_edit);
    password = dialogView.findViewById(R.id.password_edit);
    // The custom username\password take precedence
    username.setText(customUsername != null ? customUsername : overriddenUrl != null ? null : webCredentialsUtils.getUserNameFromPreferences());
    password.setText(customPassword != null ? customPassword : overriddenUrl != null ? null : webCredentialsUtils.getPasswordFromPreferences());
    MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
    builder.setTitle(context.getString(R.string.server_requires_auth));
    builder.setMessage(context.getString(R.string.server_auth_credentials, overriddenUrl != null ? overriddenUrl : webCredentialsUtils.getServerUrlFromPreferences()));
    builder.setView(dialogView);
    String finalOverriddenUrl = overriddenUrl;
    builder.setPositiveButton(context.getString(R.string.ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String userNameValue = username.getText().toString();
            String passwordValue = password.getText().toString();
            // save the credentials provided in the dialog to user preferences.
            if (customUsername != null && customPassword != null) {
                webCredentialsUtils.saveCredentials(finalOverriddenUrl != null ? finalOverriddenUrl : webCredentialsUtils.getServerUrlFromPreferences(), userNameValue, passwordValue);
            } else if (finalOverriddenUrl == null) {
                webCredentialsUtils.saveCredentialsPreferences(userNameValue, passwordValue, propertyManager);
            } else {
                webCredentialsUtils.saveCredentials(finalOverriddenUrl, userNameValue, passwordValue);
            }
            resultListener.updatedCredentials();
        }
    });
    builder.setNegativeButton(context.getString(R.string.cancel), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            resultListener.cancelledUpdatingCredentials();
        }
    });
    builder.setCancelable(false);
    return builder.create();
}
Also used : DialogInterface(android.content.DialogInterface) View(android.view.View) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Aggregations

MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)69 NonNull (androidx.annotation.NonNull)36 View (android.view.View)32 AlertDialog (androidx.appcompat.app.AlertDialog)32 Bundle (android.os.Bundle)29 Nullable (androidx.annotation.Nullable)24 R (org.thoughtcrime.securesms.R)22 Context (android.content.Context)20 TextView (android.widget.TextView)18 Log (org.signal.core.util.logging.Log)16 LayoutInflater (android.view.LayoutInflater)15 Toast (android.widget.Toast)15 DialogInterface (android.content.DialogInterface)14 Intent (android.content.Intent)14 R (org.odk.collect.android.R)14 Dialog (android.app.Dialog)11 DialogFragment (androidx.fragment.app.DialogFragment)11 Resources (android.content.res.Resources)10 SignalStore (org.thoughtcrime.securesms.keyvalue.SignalStore)10 ViewUtil (org.thoughtcrime.securesms.util.ViewUtil)10