Java Code Examples for androidx.appcompat.widget.AppCompatRadioButton#setOnClickListener()
The following examples show how to use
androidx.appcompat.widget.AppCompatRadioButton#setOnClickListener() .
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 |
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: LayoutSelector.java From Twire with GNU General Public License v3.0 | 4 votes |
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 3
Source File: MainNavigationDrawer.java From onpc with GNU General Public License v3.0 | 4 votes |
@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 4
Source File: LayoutSelector.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 4 votes |
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(); } } }