src/main/java/de/blau/android/propertyeditor/tagform/ComboDialogRow.java
/**
     * Build a dialog for selecting a single value or none via a scrollable list of radio buttons
     * 
     * @param caller the calling TagFormFragment instance
     * @param hint a description to display
     * @param key the key
     * @param adapter the ArrayAdapter holding the values
     * @param row the row we are started from
     * @param preset the relevant PresetItem
     * @return an AlertDialog
     */
Build a dialog for selecting a single value or none via a scrollable list of radio buttons


Build a dialog for selecting a single value or none via a scrollable list of radio buttons
private static AlertDialog buildComboDialog(@NonNull final TagFormFragment caller, @NonNull String hint, @NonNull String key,
            @Nullable final ArrayAdapter<?> adapter, @NonNull final DialogRow row, @NonNull final PresetItem preset) {
        String value = row.getValue();
        Builder builder = new AlertDialog.Builder(caller.getActivity());
        builder.setTitle(hint);
        final LayoutInflater themedInflater = ThemeUtils.getLayoutInflater(caller.getActivity());
        final View layout = themedInflater.inflate(R.layout.form_combo_dialog, null);
        final View divider = themedInflater.inflate(R.layout.divider2, null);
        divider.setLayoutParams(new RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 2));
        RadioGroup valueGroup = (RadioGroup) layout.findViewById(R.id.valueGroup);
        builder.setView(layout);
        View.OnClickListener listener = v -> {
            Log.d(DEBUG_TAG, "radio button clicked " + row.getValue() + " " + v.getTag());
            if (!row.hasChanged()) {
                RadioGroup g = (RadioGroup) v.getParent();
                g.clearCheck();
            } else {
                row.setChanged(false);
            }
        };
        android.view.ViewGroup.LayoutParams buttonLayoutParams = valueGroup.getLayoutParams();
        buttonLayoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        if (adapter != null) {
            for (int i = 0; i < adapter.getCount(); i++) {
                Object o = adapter.getItem(i);
                if (o instanceof TagFormFragment.Ruler) {
                    valueGroup.addView(divider);
                } else {
                    StringWithDescription swd;
                    Drawable icon = null;
                    if (o instanceof StringWithDescriptionAndIcon) {
                        icon = ((StringWithDescriptionAndIcon) o).getIcon(caller.getContext(), preset);
                        if (icon != null) {
                            swd = new StringWithDescriptionAndIcon(o);
                        } else {
                            swd = new StringWithDescription(o);
                        }
                    } else {
                        swd = new StringWithDescription(o);
                    }
                    String v = swd.getValue();
                    if (v == null || "".equals(v)) {
                        continue;
                    }
                    addButton(caller.getActivity(), valueGroup, i, swd, v.equals(value), icon, listener, buttonLayoutParams);
                }
            }
        }
        builder.setPositiveButton(R.string.clear, (dialog, which) -> {
            View groupView = ((AlertDialog) dialog).findViewById(R.id.valueGroup);
            String k = (String) groupView.getTag();
            updateTag(((AlertDialog) dialog).getContext(), k, new StringWithDescription(""));
            groupView.postDelayed(dialog::dismiss, 100);
        });
        builder.setNegativeButton(R.string.cancel, null);
        final AlertDialog dialog = builder.create();
        valueGroup.setTag(key);
        valueGroup.setOnCheckedChangeListener((group, checkedId) -> {
            Log.d(DEBUG_TAG, "radio group onCheckedChanged");
            StringWithDescription ourValue = null;
            if (checkedId != -1) {
                RadioButton button = (RadioButton) group.findViewById(checkedId);
                ourValue = (StringWithDescription) button.getTag();
                updateTag(button.getContext(), (String) group.getTag(), ourValue);
            }
            group.postDelayed(dialog::dismiss, 100);
        });
        return dialog;
    }
private static AlertDialog buildComboDialog ( @ NonNull final TagFormFragment caller , @ NonNull String hint , @ NonNull String key , @ Nullable final ArrayAdapter < ? > adapter , @ NonNull final DialogRow row , @ NonNull final PresetItem preset ) { String value = row . getValue ( ) ; Builder builder = new AlertDialog . Builder ( caller . getActivity ( ) ) ; builder . setTitle ( hint ) ; final LayoutInflater themedInflater = ThemeUtils . getLayoutInflater ( caller . getActivity ( ) ) ; final View layout = themedInflater . inflate ( R . layout . form_combo_dialog , null ) ; final View divider = themedInflater . inflate ( R . layout . divider2 , null ) ; divider . setLayoutParams ( new RadioGroup . LayoutParams ( ViewGroup . LayoutParams . MATCH_PARENT , 2 ) ) ; RadioGroup valueGroup = ( RadioGroup ) layout . findViewById ( R . id . valueGroup ) ; builder . setView ( layout ) ; View . OnClickListener listener = v -> { Log . d ( DEBUG_TAG , "radio button clicked " + row . getValue ( ) + " " + v . getTag ( ) ) ; if ( ! row . hasChanged ( ) ) { RadioGroup g = ( RadioGroup ) v . getParent ( ) ; g . clearCheck ( ) ; } else { row . setChanged ( false ) ; } } ; android . view . ViewGroup . LayoutParams buttonLayoutParams = valueGroup . getLayoutParams ( ) ; buttonLayoutParams . width = ViewGroup . LayoutParams . MATCH_PARENT ; if ( adapter != null ) { for ( int i = 0 ; i < adapter . getCount ( ) ; i ++ ) { Object o = adapter . getItem ( i ) ; if ( o instanceof TagFormFragment . Ruler ) { valueGroup . addView ( divider ) ; } else { StringWithDescription swd ; Drawable icon = null ; if ( o instanceof StringWithDescriptionAndIcon ) { icon = ( ( StringWithDescriptionAndIcon ) o ) . getIcon ( caller . getContext ( ) , preset ) ; if ( icon != null ) { swd = new StringWithDescriptionAndIcon ( o ) ; } else { swd = new StringWithDescription ( o ) ; } } else { swd = new StringWithDescription ( o ) ; } String v = swd . getValue ( ) ; if ( v == null || "" . equals ( v ) ) { continue ; } addButton ( caller . getActivity ( ) , valueGroup , i , swd , v . equals ( value ) , icon , listener , buttonLayoutParams ) ; } } } builder . setPositiveButton ( R . string . clear , ( dialog , which ) -> { View groupView = ( ( AlertDialog ) dialog ) . findViewById ( R . id . valueGroup ) ; String k = ( String ) groupView . getTag ( ) ; updateTag ( ( ( AlertDialog ) dialog ) . getContext ( ) , k , new StringWithDescription ( "" ) ) ; groupView . postDelayed ( dialog :: dismiss , 100 ) ; } ) ; builder . setNegativeButton ( R . string . cancel , null ) ; final AlertDialog dialog = builder . create ( ) ; valueGroup . setTag ( key ) ; valueGroup . setOnCheckedChangeListener ( ( group , checkedId ) -> { Log . d ( DEBUG_TAG , "radio group onCheckedChanged" ) ; StringWithDescription ourValue = null ; if ( checkedId != - 1 ) { RadioButton button = ( RadioButton ) group . findViewById ( checkedId ) ; ourValue = ( StringWithDescription ) button . getTag ( ) ; updateTag ( button . getContext ( ) , ( String ) group . getTag ( ) , ourValue ) ; } group . postDelayed ( dialog :: dismiss , 100 ) ; } ) ; return dialog ; }
Build a dialog for selecting a single value or none via a scrollable list of radio buttons
Build a dialog for selecting a single value or none via a scrollable list of radio buttons
// allow a tiny bit of time to see that the action actually worked // allow a tiny bit of time to see that the action actually worked