Search in sources :

Example 1 with AppCompatCheckedTextView

use of androidx.appcompat.widget.AppCompatCheckedTextView in project collect by opendatakit.

the class ShowQRCodeFragment method passwordWarningClicked.

private void passwordWarningClicked() {
    if (dialog == null) {
        final String[] items = { getString(R.string.admin_password), getString(R.string.server_password) };
        dialog = new MaterialAlertDialogBuilder(getActivity()).setTitle(R.string.include_password_dialog).setMultiChoiceItems(items, checkedItems, (dialog, which, isChecked) -> checkedItems[which] = isChecked).setCancelable(false).setPositiveButton(R.string.generate, (dialog, which) -> {
            qrCodeViewModel.setIncludedKeys(getSelectedPasswordKeys());
            dialog.dismiss();
        }).setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()).create();
        // disable checkbox if password not set
        dialog.getListView().setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {

            @Override
            public void onChildViewAdded(View parent, View child) {
                CharSequence text = ((AppCompatCheckedTextView) child).getText();
                int itemIndex = Arrays.asList(items).indexOf(text);
                if (!passwordsSet[itemIndex]) {
                    child.setEnabled(passwordsSet[itemIndex]);
                    child.setOnClickListener(null);
                }
            }

            @Override
            public void onChildViewRemoved(View view, View view1) {
            }
        });
    }
    dialog.show();
}
Also used : Context(android.content.Context) Arrays(java.util.Arrays) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) SettingsProvider(org.odk.collect.settings.SettingsProvider) ViewModelProvider(androidx.lifecycle.ViewModelProvider) LayoutInflater(android.view.LayoutInflater) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Collection(java.util.Collection) KEY_ADMIN_PW(org.odk.collect.settings.keys.ProtectedProjectKeys.KEY_ADMIN_PW) ShowQrcodeFragmentBinding(org.odk.collect.android.databinding.ShowQrcodeFragmentBinding) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) DaggerUtils(org.odk.collect.android.injection.DaggerUtils) Nullable(androidx.annotation.Nullable) GONE(android.view.View.GONE) Fragment(androidx.fragment.app.Fragment) R(org.odk.collect.android.R) VISIBLE(android.view.View.VISIBLE) View(android.view.View) AppCompatCheckedTextView(androidx.appcompat.widget.AppCompatCheckedTextView) Scheduler(org.odk.collect.async.Scheduler) KEY_PASSWORD(org.odk.collect.settings.keys.ProjectKeys.KEY_PASSWORD) ViewGroup(android.view.ViewGroup) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) View(android.view.View) AppCompatCheckedTextView(androidx.appcompat.widget.AppCompatCheckedTextView)

Aggregations

Context (android.content.Context)1 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 GONE (android.view.View.GONE)1 VISIBLE (android.view.View.VISIBLE)1 ViewGroup (android.view.ViewGroup)1 Nullable (androidx.annotation.Nullable)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 AppCompatCheckedTextView (androidx.appcompat.widget.AppCompatCheckedTextView)1 Fragment (androidx.fragment.app.Fragment)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Inject (javax.inject.Inject)1 R (org.odk.collect.android.R)1 ShowQrcodeFragmentBinding (org.odk.collect.android.databinding.ShowQrcodeFragmentBinding)1 DaggerUtils (org.odk.collect.android.injection.DaggerUtils)1