use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project collect by opendatakit.
the class FormEntryMenuDelegate method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_add_repeat) {
if (audioRecorder.isRecording() && !backgroundAudioViewModel.isBackgroundRecording()) {
DialogFragmentUtils.showIfNotShowing(RecordingWarningDialogFragment.class, activity.getSupportFragmentManager());
} else {
formSaveViewModel.saveAnswersForScreen(answersProvider.getAnswers());
formEntryViewModel.promptForNewRepeat();
formIndexAnimationHandler.handle(formEntryViewModel.getCurrentIndex());
}
return true;
} else if (item.getItemId() == R.id.menu_preferences) {
if (audioRecorder.isRecording()) {
DialogFragmentUtils.showIfNotShowing(RecordingWarningDialogFragment.class, activity.getSupportFragmentManager());
} else {
Intent pref = new Intent(activity, ProjectPreferencesActivity.class);
activity.startActivityForResult(pref, ApplicationConstants.RequestCodes.CHANGE_SETTINGS);
}
return true;
} else if (item.getItemId() == R.id.track_location) {
backgroundLocationViewModel.backgroundLocationPreferenceToggled(settingsProvider.getUnprotectedSettings());
return true;
} else if (item.getItemId() == R.id.menu_goto) {
if (audioRecorder.isRecording() && !backgroundAudioViewModel.isBackgroundRecording()) {
DialogFragmentUtils.showIfNotShowing(RecordingWarningDialogFragment.class, activity.getSupportFragmentManager());
} else {
formSaveViewModel.saveAnswersForScreen(answersProvider.getAnswers());
formEntryViewModel.openHierarchy();
Intent i = new Intent(activity, FormHierarchyActivity.class);
activity.startActivityForResult(i, ApplicationConstants.RequestCodes.HIERARCHY_ACTIVITY);
}
return true;
} else if (item.getItemId() == R.id.menu_record_audio) {
boolean enabled = !item.isChecked();
if (!enabled) {
new MaterialAlertDialogBuilder(activity).setMessage(R.string.stop_recording_confirmation).setPositiveButton(R.string.disable_recording, (dialog, which) -> backgroundAudioViewModel.setBackgroundRecordingEnabled(false)).setNegativeButton(R.string.cancel, null).create().show();
} else {
new MaterialAlertDialogBuilder(activity).setMessage(R.string.background_audio_recording_enabled_explanation).setCancelable(false).setPositiveButton(R.string.ok, null).create().show();
backgroundAudioViewModel.setBackgroundRecordingEnabled(true);
}
return true;
} else {
return false;
}
}
use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project collect by opendatakit.
the class AndroidShortcutsActivity method showFormListDialog.
private void showFormListDialog(List<BlankForm> forms) {
new MaterialAlertDialogBuilder(this).setTitle(R.string.select_odk_shortcut).setItems(forms.stream().map(BlankForm::getName).toArray(String[]::new), (dialog, item) -> {
AnalyticsUtils.logServerEvent(AnalyticsEvents.CREATE_SHORTCUT, settingsProvider.getUnprotectedSettings());
Intent intent = getShortcutIntent(forms, item);
setResult(RESULT_OK, intent);
finish();
}).setOnCancelListener(dialog -> {
setResult(RESULT_CANCELED);
finish();
}).create().show();
}
use of com.google.android.material.dialog.MaterialAlertDialogBuilder 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();
}
use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project collect by opendatakit.
the class ServerPreferencesFragment method runGoogleAccountValidation.
private void runGoogleAccountValidation() {
String account = settingsProvider.getUnprotectedSettings().getString(KEY_SELECTED_GOOGLE_ACCOUNT);
String protocol = settingsProvider.getUnprotectedSettings().getString(KEY_PROTOCOL);
if (TextUtils.isEmpty(account) && protocol.equals(ProjectKeys.PROTOCOL_GOOGLE_SHEETS)) {
AlertDialog alertDialog = new MaterialAlertDialogBuilder(getActivity()).setTitle(R.string.missing_google_account_dialog_title).setMessage(R.string.missing_google_account_dialog_desc).setPositiveButton(getString(R.string.ok), (dialog, which) -> dialog.dismiss()).create();
showDialog(alertDialog, getActivity());
} else {
continueOnBackPressed();
}
}
use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project collect by opendatakit.
the class ServerAuthDialogFragment method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
ServerAuthDialogBinding binding = ServerAuthDialogBinding.inflate(requireActivity().getLayoutInflater());
dialogView = binding.getRoot();
Settings generalSettings = settingsProvider.getUnprotectedSettings();
binding.usernameEdit.setText(generalSettings.getString(ProjectKeys.KEY_USERNAME));
binding.passwordEdit.setText(generalSettings.getString(ProjectKeys.KEY_PASSWORD));
return new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.server_requires_auth).setMessage(requireContext().getString(R.string.server_auth_credentials, generalSettings.getString(ProjectKeys.KEY_SERVER_URL))).setView(dialogView).setPositiveButton(R.string.ok, (dialogInterface, i) -> {
generalSettings.save(ProjectKeys.KEY_USERNAME, binding.usernameEdit.getText().toString());
generalSettings.save(ProjectKeys.KEY_PASSWORD, binding.passwordEdit.getText().toString());
}).create();
}
Aggregations