Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/unselect_segment' into feature/a…
Browse files Browse the repository at this point in the history
…nimate-background-change
  • Loading branch information
tuanna-hsp committed Mar 15, 2016
2 parents a17616d + 0b1e544 commit d713366
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class SegmentedGroup extends RadioGroup {
private int mMarginDp;
private Resources resources;
private int mTintColor;
private int mUnCheckedTintColor;
private int mCheckedTextColor = Color.WHITE;
private LayoutSelector mLayoutSelector;
private Float mCornerRadius;
Expand All @@ -32,6 +33,7 @@ public SegmentedGroup(Context context) {
super(context);
resources = getResources();
mTintColor = resources.getColor(R.color.radio_button_selected_color);
mUnCheckedTintColor = resources.getColor(R.color.radio_button_unselected_color);
mMarginDp = (int) getResources().getDimension(R.dimen.radio_button_stroke_border);
mCornerRadius = getResources().getDimension(R.dimen.radio_button_conner_radius);
mLayoutSelector = new LayoutSelector(mCornerRadius);
Expand All @@ -41,6 +43,7 @@ public SegmentedGroup(Context context, AttributeSet attrs) {
super(context, attrs);
resources = getResources();
mTintColor = resources.getColor(R.color.radio_button_selected_color);
mUnCheckedTintColor = resources.getColor(R.color.radio_button_unselected_color);
mMarginDp = (int) getResources().getDimension(R.dimen.radio_button_stroke_border);
mCornerRadius = getResources().getDimension(R.dimen.radio_button_conner_radius);
initAttrs(attrs);
Expand Down Expand Up @@ -71,6 +74,9 @@ private void initAttrs(AttributeSet attrs) {
R.styleable.SegmentedGroup_sc_checked_text_color,
getResources().getColor(android.R.color.white));

mUnCheckedTintColor = typedArray.getColor(
R.styleable.SegmentedGroup_sc_unchecked_tint_color,
getResources().getColor(R.color.radio_button_unselected_color));
} finally {
typedArray.recycle();
}
Expand All @@ -94,6 +100,11 @@ public void setTintColor(int tintColor, int checkedTextColor) {
updateBackground();
}

public void setUnCheckedTintColor(int unCheckedTintColor, int unCheckedTextColor) {
mUnCheckedTintColor = unCheckedTintColor;
updateBackground();
}

public void updateBackground() {
int count = super.getChildCount();
for (int i = 0; i < count; i++) {
Expand Down Expand Up @@ -132,6 +143,7 @@ private void updateBackground(View view) {
((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));
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<attr name="sc_border_width" format="dimension" />
<attr name="sc_tint_color" format="color" />
<attr name="sc_checked_text_color" format="color" />
<attr name="sc_unchecked_tint_color" format="color"/>
</declare-styleable>

</resources>

0 comments on commit d713366

Please sign in to comment.