From 29cbe66c7d623a2bea7fb74474a1a8520cc5b809 Mon Sep 17 00:00:00 2001 From: Muyuan Li Date: Tue, 29 Mar 2016 16:22:05 -0700 Subject: [PATCH] sysui: refactored for extensibility. refactored button inflate code and add a logic to handle selected style update. Change-Id: I61f9c77396bea63a24fc78bf02ebad54a426a3ed (cherry picked from commit b865ae2a4c892e2ffd83947e40ebd27d35b18fa6) --- .../systemui/volume/SegmentedButtons.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/volume/SegmentedButtons.java b/packages/SystemUI/src/com/android/systemui/volume/SegmentedButtons.java index f4328089bf0fc..c6e4356aa4201 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/SegmentedButtons.java +++ b/packages/SystemUI/src/com/android/systemui/volume/SegmentedButtons.java @@ -35,11 +35,11 @@ public class SegmentedButtons extends LinearLayout { private static final Typeface MEDIUM = Typeface.create("sans-serif-medium", Typeface.NORMAL); private final Context mContext; - private final LayoutInflater mInflater; + protected final LayoutInflater mInflater; private final SpTexts mSpTexts; private Callback mCallback; - private Object mSelectedValue; + protected Object mSelectedValue; public SegmentedButtons(Context context, AttributeSet attrs) { super(context, attrs); @@ -65,13 +65,21 @@ public class SegmentedButtons extends LinearLayout { final Object tag = c.getTag(); final boolean selected = Objects.equals(mSelectedValue, tag); c.setSelected(selected); - c.setTypeface(selected ? MEDIUM : REGULAR); + setSelectedStyle(c, selected); } fireOnSelected(fromClick); } + protected void setSelectedStyle(TextView textView, boolean selected) { + textView.setTypeface(selected ? MEDIUM : REGULAR); + } + + public Button inflateButton() { + return (Button) mInflater.inflate(R.layout.segmented_button, this, false); + } + public void addButton(int labelResId, int contentDescriptionResId, Object value) { - final Button b = (Button) mInflater.inflate(R.layout.segmented_button, this, false); + final Button b = inflateButton(); b.setTag(LABEL_RES_KEY, labelResId); b.setText(labelResId); b.setContentDescription(getResources().getString(contentDescriptionResId));