androidx.appcompat.widget.AppCompatRadioButton Java Examples

The following examples show how to use androidx.appcompat.widget.AppCompatRadioButton. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeviceList.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
private void updateRadioGroup(final Map<String, DeviceInfo> devices)
{
    if (dialogList != null)
    {
        dialogList.removeAllViews();
        for (DeviceInfo deviceInfo : devices.values())
        {
            deviceInfo.selected = false;
            if (deviceInfo.responses > 0)
            {
                final ContextThemeWrapper wrappedContext = new ContextThemeWrapper(context, R.style.RadioButtonStyle);
                final AppCompatRadioButton b = new AppCompatRadioButton(wrappedContext, null, 0);
                final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                b.setLayoutParams(lp);
                b.setText(deviceInfo.message.getDescription());
                b.setTextColor(Utils.getThemeColorAttr(context, android.R.attr.textColor));
                b.setOnClickListener(v ->
                {
                    deviceInfo.selected = true;
                    stop();
                });
                dialogList.addView(b);
            }
        }
        dialogList.invalidate();
    }
}
 
Example #2
Source File: MainNavigationDrawer.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
private void onRadioBtnChange(final AppCompatRadioButton[] radioGroup, AppCompatRadioButton v)
{
    for (AppCompatRadioButton r : radioGroup)
    {
        r.setChecked(false);
    }
    v.setChecked(true);
}
 
Example #3
Source File: ThemeSwitcherDialogFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
private AppCompatRadioButton createCompatRadioButton(
    RadioGroup group, String contentDescription) {
  AppCompatRadioButton button = new AppCompatRadioButton(getContext());
  button.setContentDescription(contentDescription);
  group.addView(button);
  return button;
}
 
Example #4
Source File: ThemeSwitcherDialogFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void customizeRadioButton(AppCompatRadioButton button) {
  button.setText(contentDescription);
  LinearLayout.LayoutParams size =
      new LinearLayout.LayoutParams(
          LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  MarginLayoutParamsCompat.setMarginEnd(
      size, button.getResources().getDimensionPixelSize(R.dimen.theme_switcher_radio_spacing));
  button.setLayoutParams(size);
}
 
Example #5
Source File: LayoutSelector.java    From Twire with GNU General Public License v3.0 4 votes vote down vote up
private void init() {
    layoutSelectorView = activity.getLayoutInflater().inflate(R.layout.stream_layout_preview, null);
    final RadioGroup rg = layoutSelectorView.findViewById(R.id.layouts_radiogroup);
    final FrameLayout previewWrapper = layoutSelectorView.findViewById(R.id.preview_wrapper);

    if (previewMaxHeightRes != -1) {
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                (int) activity.getResources().getDimension(previewMaxHeightRes)
        );
        previewWrapper.setLayoutParams(lp);
        //previewWrapper.setMinimumHeight((int) activity.getResources().getDimension(previewMaxHeightRes));
    }

    ViewStub preview = layoutSelectorView.findViewById(R.id.layout_stub);
    preview.setLayoutResource(previewLayout);
    final View inflated = preview.inflate();

    for (int i = 0; i < layoutTitles.length; i++) {
        final String layoutTitle = layoutTitles[i];

        final AppCompatRadioButton radioButton = new AppCompatRadioButton(activity);
        radioButton.setText(layoutTitle);

        final int finalI = i;
        radioButton.setOnClickListener(v -> selectCallback.onSelected(layoutTitle, finalI, inflated));

        if (textColor != -1) {
            radioButton.setTextColor(Service.getColorAttribute(textColor, R.color.black_text, activity));

            ColorStateList colorStateList = new ColorStateList(
                    new int[][]{
                            new int[]{-android.R.attr.state_checked},
                            new int[]{android.R.attr.state_checked}
                    },
                    new int[]{

                            Color.GRAY, //Disabled
                            Service.getColorAttribute(R.attr.colorAccent, R.color.accent, activity), //Enabled
                    }
            );
            radioButton.setSupportButtonTintList(colorStateList);
        }


        radioButton.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, // Width
                (int) activity.getResources().getDimension(R.dimen.layout_selector_height) // Height
        ));


        rg.addView(radioButton, i);


        if ((selectedLayoutIndex != -1 && selectedLayoutIndex == i) || (selectedLayoutTitle != null && selectedLayoutTitle.equals(layoutTitle))) {
            radioButton.performClick();
        }
    }
}
 
Example #6
Source File: MainNavigationDrawer.java    From onpc with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint("DefaultLocale")
private void editFavoriteConnection(@NonNull final MenuItem m, final BroadcastResponseMsg msg)
{
    final FrameLayout frameView = new FrameLayout(activity);
    activity.getLayoutInflater().inflate(R.layout.dialog_favorite_connect_layout, frameView);

    final TextView deviceAddress = frameView.findViewById(R.id.device_address);
    deviceAddress.setText(String.format("%s %s",
            activity.getString(R.string.connect_dialog_address),
            msg.getHostAndPort()));

    // Connection alias
    final EditText deviceAlias = frameView.findViewById(R.id.device_alias);
    deviceAlias.setText(msg.getAlias());

    // Optional identifier
    final EditText deviceIdentifier = frameView.findViewById(R.id.device_identifier);
    deviceIdentifier.setText(msg.getIdentifier());

    final AppCompatRadioButton renameBtn = frameView.findViewById(R.id.device_rename_connection);
    final AppCompatRadioButton deleteBtn = frameView.findViewById(R.id.device_delete_connection);
    final AppCompatRadioButton[] radioGroup = {renameBtn, deleteBtn};
    for (AppCompatRadioButton r : radioGroup)
    {
        r.setOnClickListener((View v) ->
        {
            if (v != renameBtn)
            {
                deviceAlias.clearFocus();
                deviceIdentifier.clearFocus();
            }
            onRadioBtnChange(radioGroup, (AppCompatRadioButton)v);
        });
    }
    deviceAlias.setOnFocusChangeListener((v, hasFocus) -> {
        if (hasFocus)
        {
            onRadioBtnChange(radioGroup, renameBtn);
        }
    });
    deviceIdentifier.setOnFocusChangeListener((v, hasFocus) -> {
        if (hasFocus)
        {
            onRadioBtnChange(radioGroup, renameBtn);
        }
    });

    final Drawable icon = Utils.getDrawable(activity, R.drawable.drawer_edit_item);
    Utils.setDrawableColorAttr(activity, icon, android.R.attr.textColorSecondary);
    final AlertDialog dialog = new AlertDialog.Builder(activity)
            .setTitle(R.string.favorite_connection_edit)
            .setIcon(icon)
            .setCancelable(false)
            .setView(frameView)
            .setNegativeButton(activity.getResources().getString(R.string.action_cancel), (dialog1, which) ->
            {
                Utils.showSoftKeyboard(activity, deviceAlias, false);
                dialog1.dismiss();
            })
            .setPositiveButton(activity.getResources().getString(R.string.action_ok), (dialog12, which) ->
            {
                Utils.showSoftKeyboard(activity, deviceAlias, false);
                // rename or delete favorite connection
                if (renameBtn.isChecked() && deviceAlias.getText().length() > 0)
                {
                    final String alias = deviceAlias.getText().toString();
                    final String identifier = deviceIdentifier.getText().length() > 0 ?
                            deviceIdentifier.getText().toString() : null;
                    final BroadcastResponseMsg newMsg = configuration.favoriteConnections.updateDevice(
                            msg, alias, identifier);
                    updateItem(m, R.drawable.drawer_favorite_device, newMsg.getAlias(), () -> editFavoriteConnection(m, newMsg));
                }
                if (deleteBtn.isChecked())
                {
                    configuration.favoriteConnections.deleteDevice(msg);
                    m.setVisible(false);
                    m.setChecked(false);
                }
                activity.getDeviceList().updateFavorites(false);
                dialog12.dismiss();
            }).create();

    dialog.show();
    Utils.fixIconColor(dialog, android.R.attr.textColorSecondary);
}
 
Example #7
Source File: LayoutSelector.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 4 votes vote down vote up
private void init() {
	layoutSelectorView = activity.getLayoutInflater().inflate(R.layout.stream_layout_preview, null);
	final RadioGroup rg = (RadioGroup) layoutSelectorView.findViewById(R.id.layouts_radiogroup);
	final FrameLayout previewWrapper = (FrameLayout) layoutSelectorView.findViewById(R.id.preview_wrapper);

	if (previewMaxHeightRes != -1) {
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
				ViewGroup.LayoutParams.MATCH_PARENT,
				(int) activity.getResources().getDimension(previewMaxHeightRes)
		);
		previewWrapper.setLayoutParams(lp);
		//previewWrapper.setMinimumHeight((int) activity.getResources().getDimension(previewMaxHeightRes));
	}

	ViewStub preview = (ViewStub) layoutSelectorView.findViewById(R.id.layout_stub);
	preview.setLayoutResource(previewLayout);
	final View inflated = preview.inflate();

	for (int i = 0; i < layoutTitles.length; i++) {
		final String layoutTitle = layoutTitles[i];

		final AppCompatRadioButton radioButton = new AppCompatRadioButton(activity);
		radioButton.setText(layoutTitle);

		final int finalI = i;
		radioButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				selectCallback.onSelected(layoutTitle, finalI, inflated);
			}
		});

		if (textColor != -1) {
			radioButton.setTextColor(Service.getColorAttribute(textColor, R.color.black_text, activity));

			ColorStateList colorStateList = new ColorStateList(
					new int[][]{
							new int[]{-android.R.attr.state_checked},
							new int[]{android.R.attr.state_checked}
					},
					new int[]{

							Color.GRAY, //Disabled
							Service.getColorAttribute(R.attr.colorAccent, R.color.accent, activity), //Enabled
					}
			);
			radioButton.setSupportButtonTintList(colorStateList);
		}


		radioButton.setLayoutParams(new ViewGroup.LayoutParams(
				ViewGroup.LayoutParams.MATCH_PARENT, // Width
				(int) activity.getResources().getDimension(R.dimen.layout_selector_height) // Height
		));


		rg.addView(radioButton, i);


		if ((selectedLayoutIndex != -1 && selectedLayoutIndex == i) || (selectedLayoutTitle != null && selectedLayoutTitle.equals(layoutTitle))) {
			radioButton.performClick();
		}
	}
}
 
Example #8
Source File: FontPreferenceData.java    From Status with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(View v) {
    ScrollView scrollView = new ScrollView(getContext());

    RadioGroup group = new RadioGroup(getContext());
    int vPadding = DimenUtils.dpToPx(12);
    group.setPadding(0, vPadding, 0, vPadding);

    AppCompatRadioButton normalButton = (AppCompatRadioButton) LayoutInflater.from(getContext()).inflate(R.layout.item_dialog_radio_button, group, false);
    normalButton.setId(0);
    normalButton.setText(R.string.font_default);
    normalButton.setChecked(preference == null || preference.length() == 0);
    group.addView(normalButton);

    for (int i = 0; i < items.size(); i++) {
        String item = items.get(i);

        AppCompatRadioButton button = (AppCompatRadioButton) LayoutInflater.from(getContext()).inflate(R.layout.item_dialog_radio_button, group, false);
        button.setId(i + 1);
        button.setText(item.replace(".ttf", ""));
        button.setTag(item);
        try {
            button.setTypeface(Typeface.createFromAsset(getContext().getAssets(), item));
        } catch (Exception e) {
            continue;
        }
        button.setChecked(preference != null && preference.equals(item));
        group.addView(button);
    }

    group.setOnCheckedChangeListener((group1, checkedId) -> {
        for (int i = 0; i < group1.getChildCount(); i++) {
            RadioButton child = (RadioButton) group1.getChildAt(i);
            child.setChecked(child.getId() == checkedId);
            if (child.getId() == checkedId)
                selectedPreference = (String) child.getTag();
        }
    });

    scrollView.addView(group);

    new AlertDialog.Builder(getContext())
            .setTitle(getIdentifier().getTitle())
            .setView(scrollView)
            .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                FontPreferenceData.this.preference = selectedPreference;

                getIdentifier().setPreferenceValue(getContext(), selectedPreference);
                onPreferenceChange(selectedPreference);
                selectedPreference = null;
            })
            .setNegativeButton(android.R.string.cancel, (dialog, which) -> selectedPreference = null)
            .show();
}
 
Example #9
Source File: ThemeSwitcherDialogFragment.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private void initializeThemingValues(
    RadioGroup group,
    @ArrayRes int overlays,
    @ArrayRes int contentDescriptions,
    @StyleableRes int[] themeOverlayAttrs,
    @IdRes int overlayId,
    ThemingType themingType) {
  TypedArray themingValues = getResources().obtainTypedArray(overlays);
  TypedArray contentDescriptionArray = getResources().obtainTypedArray(contentDescriptions);
  if (themingValues.length() != contentDescriptionArray.length()) {
    throw new IllegalArgumentException(
        "Feature array length doesn't match its content description array length.");
  }

  for (int i = 0; i < themingValues.length(); i++) {
    @StyleRes int valueThemeOverlay = themingValues.getResourceId(i, 0);
    ThemeAttributeValues themeAttributeValues = null;
    // Create RadioButtons for themeAttributeValues values
    switch (themingType) {
      case COLOR:
        themeAttributeValues = new ColorPalette(valueThemeOverlay, themeOverlayAttrs);
        break;
      case SHAPE_CORNER_FAMILY:
        themeAttributeValues = new ThemeAttributeValues(valueThemeOverlay);
        break;
      case SHAPE_CORNER_SIZE:
        themeAttributeValues =
            new ThemeAttributeValuesWithContentDescription(
                valueThemeOverlay, contentDescriptionArray.getString(i));
        break;
    }

    // Expect the radio group to have a RadioButton as child for each themeAttributeValues value.
    AppCompatRadioButton button =
        themingType.radioButtonType == RadioButtonType.XML
            ? ((AppCompatRadioButton) group.getChildAt(i))
            : createCompatRadioButton(group, contentDescriptionArray.getString(i));

    button.setTag(themeAttributeValues);
    themeAttributeValues.customizeRadioButton(button);

    int currentThemeOverlay = ThemeOverlayUtils.getThemeOverlay(overlayId);
    if (themeAttributeValues.themeOverlay == currentThemeOverlay) {
      group.check(button.getId());
    }
  }

  themingValues.recycle();
  contentDescriptionArray.recycle();
}
 
Example #10
Source File: ThemeSwitcherDialogFragment.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
public void customizeRadioButton(AppCompatRadioButton button) {
  CompoundButtonCompat.setButtonTintList(
      button, ColorStateList.valueOf(convertToDisplay(main)));
}
 
Example #11
Source File: MaterialComponentsViewInflater.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
protected AppCompatRadioButton createRadioButton(Context context, AttributeSet attrs) {
  return new MaterialRadioButton(context, attrs);
}
 
Example #12
Source File: ThemeSwitcherDialogFragment.java    From material-components-android with Apache License 2.0 votes vote down vote up
public void customizeRadioButton(AppCompatRadioButton button) {}