Search in sources :

Example 26 with RadioGroup

use of android.widget.RadioGroup in project AndroidDevelop by 7449.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    viewPager = (ViewPager) findViewById(R.id.viewpager);
    RadioGroup radioGroup = (RadioGroup) findViewById(R.id.rg_group);
    imageView = (ImageView) findViewById(R.id.iv_line);
    Display display = getWindow().getWindowManager().getDefaultDisplay();
    DisplayMetrics dm = new DisplayMetrics();
    display.getMetrics(dm);
    ivWidth = (dm.widthPixels / 3);
    viewPager.addOnPageChangeListener(this);
    radioGroup.setOnCheckedChangeListener(this);
    viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            return ViewPagerFragment.startFragment(position);
        }

        @Override
        public int getCount() {
            return 3;
        }
    });
}
Also used : RadioGroup(android.widget.RadioGroup) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) DisplayMetrics(android.util.DisplayMetrics) Fragment(android.support.v4.app.Fragment) Display(android.view.Display)

Example 27 with RadioGroup

use of android.widget.RadioGroup in project JustAndroid by chinaltz.

the class SegmentedGroup method updateBackground.

private void updateBackground(View view) {
    if (!isInEditMode()) {
        int checked = mLayoutSelector.getSelected();
        int unchecked = mLayoutSelector.getUnselected();
        //Set text color
        ColorStateList colorStateList = new ColorStateList(new int[][] { { -android.R.attr.state_checked }, { android.R.attr.state_checked } }, new int[] { mTintColor, mCheckedTextColor });
        ((Button) view).setTextColor(colorStateList);
        //Redraw with tint color
        Drawable checkedDrawable = resources.getDrawable(checked).mutate();
        Drawable uncheckedDrawable = resources.getDrawable(unchecked).mutate();
        ((GradientDrawable) checkedDrawable).setColor(mTintColor);
        ((GradientDrawable) checkedDrawable).setStroke(mMarginDp, mTintColor);
        ((GradientDrawable) uncheckedDrawable).setStroke(mMarginDp, mTintColor);
        ((GradientDrawable) uncheckedDrawable).setColor(mUnCheckedTintColor);
        //Set proper radius
        ((GradientDrawable) checkedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view));
        ((GradientDrawable) uncheckedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view));
        GradientDrawable maskDrawable = (GradientDrawable) resources.getDrawable(unchecked).mutate();
        maskDrawable.setStroke(mMarginDp, mTintColor);
        maskDrawable.setColor(mUnCheckedTintColor);
        maskDrawable.setCornerRadii(mLayoutSelector.getChildRadii(view));
        int maskColor = Color.argb(50, Color.red(mTintColor), Color.green(mTintColor), Color.blue(mTintColor));
        maskDrawable.setColor(maskColor);
        LayerDrawable pressedDrawable = new LayerDrawable(new Drawable[] { uncheckedDrawable, maskDrawable });
        Drawable[] drawables = { uncheckedDrawable, checkedDrawable };
        TransitionDrawable transitionDrawable = new TransitionDrawable(drawables);
        if (((RadioButton) view).isChecked()) {
            transitionDrawable.reverseTransition(0);
        }
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_pressed }, pressedDrawable);
        stateListDrawable.addState(StateSet.WILD_CARD, transitionDrawable);
        mDrawableMap.put(view.getId(), transitionDrawable);
        //Set button background
        if (Build.VERSION.SDK_INT >= 16) {
            view.setBackground(stateListDrawable);
        } else {
            view.setBackgroundDrawable(stateListDrawable);
        }
        super.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                TransitionDrawable current = mDrawableMap.get(checkedId);
                current.reverseTransition(200);
                if (mLastCheckId != 0) {
                    TransitionDrawable last = mDrawableMap.get(mLastCheckId);
                    if (last != null)
                        last.reverseTransition(200);
                }
                mLastCheckId = checkedId;
                if (mCheckedChangeListener != null) {
                    mCheckedChangeListener.onCheckedChanged(group, checkedId);
                }
            }
        });
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) RadioGroup(android.widget.RadioGroup) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ColorStateList(android.content.res.ColorStateList) RadioButton(android.widget.RadioButton) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) RadioButton(android.widget.RadioButton) Button(android.widget.Button) LayerDrawable(android.graphics.drawable.LayerDrawable)

Example 28 with RadioGroup

use of android.widget.RadioGroup in project ngAndroid by davityle.

the class NgChange method attach.

@Override
public void attach(Scope scope, View view, int layoutId, int viewId, Tuple<String, String>[] models) {
    Executor executor = new Executor(scope, layoutId, viewId, getAttribute());
    if (view instanceof CompoundButton) {
        CompoundButton button = (CompoundButton) view;
        button.setOnCheckedChangeListener(executor);
    } else if (view instanceof TextView) {
        TextView textView = (TextView) view;
        textView.addTextChangedListener(executor);
    } else if (view instanceof Spinner) {
        Spinner spinner = (Spinner) view;
        spinner.setOnItemSelectedListener(executor);
    } else if (view instanceof RadioGroup) {
        RadioGroup group = (RadioGroup) view;
        group.setOnCheckedChangeListener(executor);
    }
}
Also used : RadioGroup(android.widget.RadioGroup) Spinner(android.widget.Spinner) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Example 29 with RadioGroup

use of android.widget.RadioGroup in project android_frameworks_base by crdroidandroid.

the class NotificationBuilderTest method getRadioTag.

private String getRadioTag(int id) {
    final RadioGroup g = (RadioGroup) findViewById(id);
    final View v = findViewById(g.getCheckedRadioButtonId());
    return (String) v.getTag();
}
Also used : RadioGroup(android.widget.RadioGroup) View(android.view.View)

Example 30 with RadioGroup

use of android.widget.RadioGroup in project LiveLessons by douglascraigschmidt.

the class AndroidPlatform method buttonToggled.

/**
     * Retrieves textual input of the toggled button determined by the
     * user.
     */
private String buttonToggled() {
    Log.e("AndroidPlatform", "buttonToggled");
    /** Checks the format radio group for checked buttons. */
    RadioGroup rg = (RadioGroup) activity.findViewById(R.id.rad1);
    for (int i = 0; i < rg.getChildCount(); i++) if (((RadioButton) rg.getChildAt(i)).isChecked() && ((RadioButton) rg.getChildAt(i)).isEnabled())
        return ("format" + " " + (String) ((TextView) rg.getChildAt(i)).getText()).toLowerCase();
    /** Checks the print radio group for checked buttons. */
    rg = (RadioGroup) activity.findViewById(R.id.rad2);
    for (int i = 0; i < rg.getChildCount(); i++) if (((RadioButton) rg.getChildAt(i)).isChecked() && ((RadioButton) rg.getChildAt(i)).isEnabled()) {
        ((TextView) activity.findViewById(R.id.tv)).setText("");
        return ("print" + " " + (String) ((TextView) rg.getChildAt(i)).getText()).toLowerCase();
    }
    /** Checks the eval radio group for checked buttons. */
    rg = (RadioGroup) activity.findViewById(R.id.rad3);
    for (int i = 0; i < rg.getChildCount(); i++) if (((RadioButton) rg.getChildAt(i)).isChecked() && ((RadioButton) rg.getChildAt(i)).isEnabled())
        return ("eval" + " " + (String) ((TextView) rg.getChildAt(i)).getText()).toLowerCase();
    /** Checks the set checkbox. */
    CheckBox cb = (CheckBox) activity.findViewById(R.id.cb);
    if (cb.isChecked() && cb.isEnabled())
        return ("set" + (String) ((TextView) cb).getText()).toLowerCase();
    return "expr";
}
Also used : RadioGroup(android.widget.RadioGroup) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) RadioButton(android.widget.RadioButton)

Aggregations

RadioGroup (android.widget.RadioGroup)62 View (android.view.View)26 TextView (android.widget.TextView)19 RadioButton (android.widget.RadioButton)13 OnCheckedChangeListener (android.widget.RadioGroup.OnCheckedChangeListener)13 Button (android.widget.Button)9 CompoundButton (android.widget.CompoundButton)8 Validator (com.mobsandgeeks.saripaar.Validator)8 CheckBox (android.widget.CheckBox)5 IOException (java.io.IOException)5 RandomAccessFile (java.io.RandomAccessFile)5 Test (org.junit.Test)5 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)4 ImageView (android.widget.ImageView)4 ScrollView (android.widget.ScrollView)4 Paint (android.graphics.Paint)3 AlertDialog (android.support.v7.app.AlertDialog)3 LinearLayout (android.widget.LinearLayout)3 SeekBar (android.widget.SeekBar)3