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();
}
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();
}
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;
}
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();
}
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();
}
Aggregations