FileDocCategorySizeDatePackage
SegmentedButtons.javaAPI DocAndroid 5.1 API3856Thu Mar 12 22:22:42 GMT 2015com.android.systemui.volume

SegmentedButtons

public class SegmentedButtons extends android.widget.LinearLayout

Fields Summary
private static final int
LABEL_RES_KEY
private final android.content.Context
mContext
private final android.view.LayoutInflater
mInflater
private Callback
mCallback
private Object
mSelectedValue
private final View.OnClickListener
mClick
Constructors Summary
public SegmentedButtons(android.content.Context context, android.util.AttributeSet attrs)


         
        super(context, attrs);
        mContext = context;
        mInflater = LayoutInflater.from(mContext);
        setOrientation(HORIZONTAL);
    
Methods Summary
public voidaddButton(int labelResId, int iconResId, java.lang.Object value)

        final Button b = (Button) mInflater.inflate(R.layout.segmented_button, this, false);
        b.setTag(LABEL_RES_KEY, labelResId);
        b.setText(labelResId);
        b.setCompoundDrawablesWithIntrinsicBounds(0, iconResId, 0, 0);
        final LayoutParams lp = (LayoutParams) b.getLayoutParams();
        if (getChildCount() == 0) {
            lp.leftMargin = lp.rightMargin = 0; // first button has no margin
        }
        b.setLayoutParams(lp);
        addView(b);
        b.setTag(value);
        b.setOnClickListener(mClick);
        Interaction.register(b, new Interaction.Callback() {
            @Override
            public void onInteraction() {
                fireInteraction();
            }
        });
    
private voidfireInteraction()

        if (mCallback != null) {
            mCallback.onInteraction();
        }
    
private voidfireOnSelected()

        if (mCallback != null) {
            mCallback.onSelected(mSelectedValue);
        }
    
public java.lang.ObjectgetSelectedValue()

        return mSelectedValue;
    
public voidsetCallback(com.android.systemui.volume.SegmentedButtons$Callback callback)

        mCallback = callback;
    
public voidsetSelectedValue(java.lang.Object value)

        if (Objects.equals(value, mSelectedValue)) return;
        mSelectedValue = value;
        for (int i = 0; i < getChildCount(); i++) {
            final TextView c = (TextView) getChildAt(i);
            final Object tag = c.getTag();
            final boolean selected = Objects.equals(mSelectedValue, tag);
            c.setSelected(selected);
            c.getCompoundDrawables()[1].setTint(mContext.getResources().getColor(selected
                    ? R.color.segmented_button_selected : R.color.segmented_button_unselected));
        }
        fireOnSelected();
    
public voidupdateLocale()

        for (int i = 0; i < getChildCount(); i++) {
            final Button b = (Button) getChildAt(i);
            final int labelResId = (Integer) b.getTag(LABEL_RES_KEY);
            b.setText(labelResId);
        }