Search in sources :

Example 51 with MaterialAlertDialogBuilder

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;
    }
}
Also used : KEY_BACKGROUND_LOCATION(org.odk.collect.settings.keys.ProjectKeys.KEY_BACKGROUND_LOCATION) SettingsProvider(org.odk.collect.settings.SettingsProvider) AnswersProvider(org.odk.collect.android.formentry.questions.AnswersProvider) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) DialogFragmentUtils(org.odk.collect.androidshared.ui.DialogFragmentUtils) ProjectPreferencesActivity(org.odk.collect.android.preferences.screens.ProjectPreferencesActivity) Intent(android.content.Intent) FormController(org.odk.collect.android.javarosawrapper.FormController) ApplicationConstants(org.odk.collect.android.utilities.ApplicationConstants) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) PlayServicesChecker(org.odk.collect.android.utilities.PlayServicesChecker) MenuItem(android.view.MenuItem) BackgroundLocationViewModel(org.odk.collect.android.formentry.backgroundlocation.BackgroundLocationViewModel) Nullable(androidx.annotation.Nullable) MenuInflater(android.view.MenuInflater) MenuDelegate(org.odk.collect.android.utilities.MenuDelegate) ProtectedProjectKeys(org.odk.collect.settings.keys.ProtectedProjectKeys) Menu(android.view.Menu) R(org.odk.collect.android.R) FormSaveViewModel(org.odk.collect.android.formentry.saving.FormSaveViewModel) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) NotNull(org.jetbrains.annotations.NotNull) FormHierarchyActivity(org.odk.collect.android.activities.FormHierarchyActivity) FormHierarchyActivity(org.odk.collect.android.activities.FormHierarchyActivity) Intent(android.content.Intent) ProjectPreferencesActivity(org.odk.collect.android.preferences.screens.ProjectPreferencesActivity) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Example 52 with MaterialAlertDialogBuilder

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();
}
Also used : BlankFormsListViewModel(org.odk.collect.android.formmanagement.BlankFormsListViewModel) Bundle(android.os.Bundle) Parcelable(android.os.Parcelable) SettingsProvider(org.odk.collect.settings.SettingsProvider) ViewModelProvider(androidx.lifecycle.ViewModelProvider) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Intent(android.content.Intent) AnalyticsEvents(org.odk.collect.android.analytics.AnalyticsEvents) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Inject(javax.inject.Inject) DaggerUtils(org.odk.collect.android.injection.DaggerUtils) List(java.util.List) AnalyticsUtils(org.odk.collect.android.analytics.AnalyticsUtils) R(org.odk.collect.android.R) BlankForm(org.odk.collect.android.formmanagement.BlankFormsListViewModel.BlankForm) NotNull(org.jetbrains.annotations.NotNull) Intent(android.content.Intent) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Example 53 with MaterialAlertDialogBuilder

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

Example 54 with MaterialAlertDialogBuilder

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();
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Context(android.content.Context) Analytics(org.odk.collect.analytics.Analytics) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) RESULT_OK(android.app.Activity.RESULT_OK) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Intent(android.content.Intent) PermissionListener(org.odk.collect.permissions.PermissionListener) Inject(javax.inject.Inject) DaggerUtils(org.odk.collect.android.injection.DaggerUtils) ByteArrayInputStream(java.io.ByteArrayInputStream) GoogleAccountsManager(org.odk.collect.android.gdrive.GoogleAccountsManager) ToastUtils(org.odk.collect.androidshared.ui.ToastUtils) R(org.odk.collect.android.R) EditTextPreference(androidx.preference.EditTextPreference) ControlCharacterFilter(org.odk.collect.android.preferences.filters.ControlCharacterFilter) PermissionsProvider(org.odk.collect.permissions.PermissionsProvider) AccountManager(android.accounts.AccountManager) KEY_PROTOCOL(org.odk.collect.settings.keys.ProjectKeys.KEY_PROTOCOL) ProjectKeys(org.odk.collect.settings.keys.ProjectKeys) Validator(org.odk.collect.shared.strings.Validator) SET_FALLBACK_SHEETS_URL(org.odk.collect.android.analytics.AnalyticsEvents.SET_FALLBACK_SHEETS_URL) TextUtils(android.text.TextUtils) Preference(androidx.preference.Preference) FormUpdateScheduler(org.odk.collect.android.backgroundwork.FormUpdateScheduler) OnBackPressedListener(org.odk.collect.android.listeners.OnBackPressedListener) PlayServicesChecker(org.odk.collect.android.utilities.PlayServicesChecker) DialogUtils.showDialog(org.odk.collect.android.utilities.DialogUtils.showDialog) ListPreference(androidx.preference.ListPreference) Md5(org.odk.collect.shared.strings.Md5) KEY_SELECTED_GOOGLE_ACCOUNT(org.odk.collect.settings.keys.ProjectKeys.KEY_SELECTED_GOOGLE_ACCOUNT) InputFilter(android.text.InputFilter) NotNull(org.jetbrains.annotations.NotNull) ServerPreferencesAdder(org.odk.collect.android.preferences.ServerPreferencesAdder) WhitespaceFilter(org.odk.collect.android.preferences.filters.WhitespaceFilter) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Example 55 with MaterialAlertDialogBuilder

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();
}
Also used : Context(android.content.Context) ProjectKeys(org.odk.collect.settings.keys.ProjectKeys) Bundle(android.os.Bundle) SettingsProvider(org.odk.collect.settings.SettingsProvider) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Dialog(android.app.Dialog) Inject(javax.inject.Inject) DaggerUtils(org.odk.collect.android.injection.DaggerUtils) Nullable(androidx.annotation.Nullable) ServerAuthDialogBinding(org.odk.collect.android.databinding.ServerAuthDialogBinding) R(org.odk.collect.android.R) View(android.view.View) Settings(org.odk.collect.shared.settings.Settings) DialogFragment(androidx.fragment.app.DialogFragment) ServerAuthDialogBinding(org.odk.collect.android.databinding.ServerAuthDialogBinding) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Settings(org.odk.collect.shared.settings.Settings) NonNull(androidx.annotation.NonNull)

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