Java Code Examples for android.widget.RadioGroup#setPadding()

The following examples show how to use android.widget.RadioGroup#setPadding() . 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: FeedbackActivity.java    From zhizhihu with Apache License 2.0 5 votes vote down vote up
@NonNull
private FrameLayout createRadioGroupLayout(final String[] typeList, RadioGroup.OnCheckedChangeListener listener) {
    final List<RadioButton> rbList = new ArrayList<>();
    final RadioGroup radioGroup = new RadioGroup(this);
    radioGroup.setPadding(24, 24, 24, 24);
    for (int i = 0; i < typeList.length; i++) {
        RadioButton rb = new RadioButton(this);
        rb.setText(typeList[i]);
        rbList.add(rb);
        radioGroup.addView(rb);
    }
    String curType = mFeedbackTypeTxt.getText().toString();
    for (RadioButton btn : rbList) {
        if (btn.getText().toString().equals(curType)) {
            radioGroup.check(btn.getId());
        }
    }
    radioGroup.setOnCheckedChangeListener(listener);
    FrameLayout frameLayout = new FrameLayout(this);
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    lp.leftMargin = DimenUtil.dip2px(this, 24);
    lp.rightMargin = lp.leftMargin;
    frameLayout.addView(radioGroup, lp);
    return frameLayout;
}
 
Example 2
Source File: SettingFragment.java    From ClassSchedule with Apache License 2.0 4 votes vote down vote up
private void showThemeDialog() {
    ScrollView scrollView = new ScrollView(getActivity());
    RadioGroup radioGroup = new RadioGroup(getActivity());
    scrollView.addView(radioGroup);
    int margin = ScreenUtils.dp2px(16);
    radioGroup.setPadding(margin / 2, margin, margin, margin);

    for (int i = 0; i < themeColorArray.length; i++) {
        AppCompatRadioButton arb = new AppCompatRadioButton(getActivity());

        RadioGroup.LayoutParams params =
                new RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);

        arb.setLayoutParams(params);
        arb.setId(i);
        arb.setTextColor(getResources().getColor(themeColorArray[i]));
        arb.setText(themeNameArray[i]);
        arb.setTextSize(16);
        arb.setPadding(0, margin / 2, 0, margin / 2);
        radioGroup.addView(arb);
    }

    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            theme = checkedId;
        }
    });

    DialogHelper dialogHelper = new DialogHelper();
    dialogHelper.showCustomDialog(getActivity(), scrollView,
            getString(R.string.theme_preference), new DialogListener() {
                @Override
                public void onPositive(DialogInterface dialog, int which) {
                    super.onPositive(dialog, which);
                    dialog.dismiss();
                    String key = getString(R.string.app_preference_theme);
                    int oldTheme = Preferences.getInt(key, 0);

                    if (theme != oldTheme) {
                        Preferences.putInt(key, theme);
                        ActivityUtil.finishAll();
                        startActivity(new Intent(app.mContext, CourseActivity.class));
                    }
                }
            });
}
 
Example 3
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 4
Source File: WidgetFragment.java    From mobile-android-survey-app with MIT License 4 votes vote down vote up
protected RadioGroup getRadioGroup(String tag, int left, int top, int right, int bottom) {
    RadioGroup radioGroup = new RadioGroup(getActivity());
    radioGroup.setPadding(left, top, right, bottom);
    radioGroup.setTag(tag);
    return radioGroup;
}
 
Example 5
Source File: ReencodingDialog.java    From Dashchan with Apache License 2.0 4 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
	Context context = getActivity();
	qualityForm = new SeekBarForm(false);
	qualityForm.setConfiguration(1, 100, 1, 1);
	qualityForm.setValueFormat(getString(R.string.text_quality_format));
	qualityForm.setCurrentValue(savedInstanceState != null ? savedInstanceState.getInt(EXTRA_QUALITY) : 100);
	reduceForm = new SeekBarForm(false);
	reduceForm.setConfiguration(1, 8, 1, 1);
	reduceForm.setValueFormat(getString(R.string.text_reduce_format));
	reduceForm.setCurrentValue(savedInstanceState != null ? savedInstanceState.getInt(EXTRA_REDUCE) : 1);
	int padding = getResources().getDimensionPixelSize(R.dimen.dialog_padding_view);
	View qualityView = qualityForm.inflate(context);
	qualityForm.getSeekBar().setSaveEnabled(false);
	qualityView.setPadding(qualityView.getPaddingLeft(), 0, qualityView.getPaddingRight(), padding / 2);
	View reduceView = reduceForm.inflate(context);
	reduceForm.getSeekBar().setSaveEnabled(false);
	reduceView.setPadding(reduceView.getPaddingLeft(), 0, reduceView.getPaddingRight(),
			reduceView.getPaddingBottom());
	radioGroup = new RadioGroup(context);
	radioGroup.setOrientation(RadioGroup.VERTICAL);
	radioGroup.setPadding(padding, padding, padding, padding / 2);
	radioGroup.setOnCheckedChangeListener(this);
	for (int i = 0; i < OPTIONS.length; i++) {
		RadioButton radioButton = new RadioButton(context);
		radioButton.setText(OPTIONS[i]);
		radioButton.setId(IDS[i]);
		radioGroup.addView(radioButton);
	}
	radioGroup.check(IDS[0]);
	LinearLayout linearLayout = new LinearLayout(context);
	linearLayout.setOrientation(LinearLayout.VERTICAL);
	FrameLayout qualityLayout = new FrameLayout(context);
	qualityLayout.setId(android.R.id.text1);
	qualityLayout.addView(qualityView);
	FrameLayout reduceLayout = new FrameLayout(context);
	reduceLayout.setId(android.R.id.text2);
	reduceLayout.addView(reduceView);
	linearLayout.addView(radioGroup, LinearLayout.LayoutParams.MATCH_PARENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	linearLayout.addView(qualityLayout, LinearLayout.LayoutParams.MATCH_PARENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	linearLayout.addView(reduceLayout, LinearLayout.LayoutParams.MATCH_PARENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	ScrollView scrollView = new ScrollView(context);
	scrollView.addView(linearLayout, ScrollView.LayoutParams.MATCH_PARENT,
			ScrollView.LayoutParams.WRAP_CONTENT);
	return new AlertDialog.Builder(context).setTitle(R.string.text_reencode_image)
			.setView(scrollView).setNegativeButton(android.R.string.cancel, null)
			.setPositiveButton(android.R.string.ok, this).create();
}