Skip to content
This repository was archived by the owner on Mar 27, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private void setBorderAttrs() {
animateDrawablesEnterDuration, animateTextsEnterDuration, animateSelector, animateSelectorDuration, animateSelectorDelay, animateDrawablesExit,
animateDrawablesExitDuration, animateTextsExit, animateTextsExitDuration, lastPosition, buttonPadding,
buttonPaddingLeft, buttonPaddingRight, buttonPaddingTop, buttonPaddingBottom, groupBackgroundColor,
dividerPadding, dividerSize, dividerRadius, bottomLineSize, bottomLineRadius, selectorSize, selectorRadius, initialPosition,
dividerPadding, dividerSize, dividerRadius, bottomLineSize, bottomLineRadius, selectorSize, selectorWidth, selectorRadius, initialPosition,
selectorDividerSize, selectorDividerRadius, selectorDividerColor, selectorDividerPadding, checkedButtonId,
animateTextsColorExit, animateTextsColorEnter, animateTextsColorDuration, animateTextsColorDurationExit, animateTextsColorDurationEnter,
animateDrawablesTintExit, animateDrawablesTintEnter, animateDrawablesTintDuration, animateDrawablesTintDurationExit, animateDrawablesTintDurationEnter;
Expand All @@ -233,7 +233,7 @@ private void setBorderAttrs() {
private boolean bottomLineBringToFront, selectorBringToFront, selectorAboveOfBottomLine, selectorTop, selectorBottom, hasPadding,
hasPaddingLeft, hasPaddingRight, hasPaddingTop, hasPaddingBottom, clickable, enabled,
enableDeselection, hasEnabled, hasClickable, hasBorder, hasAnimateDrawables, hasAnimateTexts, hasAnimation, selectorFullSize,
hasAnimateTextsColor, hasAnimateDrawablesTint;
hasAnimateTextsColor, hasAnimateDrawablesTint, hasSelectorWidth;

private void getAttributes(AttributeSet attrs) {
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.RadioRealButtonGroup);
Expand Down Expand Up @@ -262,6 +262,8 @@ private void getAttributes(AttributeSet attrs) {
selectorBringToFront = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_selectorBringToFront, false);
selectorAboveOfBottomLine = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_selectorAboveOfBottomLine, false);
selectorSize = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorSize, 12);
selectorWidth = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorWidth, 0);
hasSelectorWidth = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_selectorSize);
selectorRadius = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorRadius, 0);

animateSelector = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateSelector, 0);
Expand Down Expand Up @@ -414,7 +416,18 @@ private void createSelectorItem(int position, RadioRealButton button) {
int height = selectorSize;
if (selectorFullSize)
height = LayoutParams.MATCH_PARENT;
view.setLayoutParams(new LinearLayout.LayoutParams(0, height, 1));

if (hasSelectorWidth) {
view.setLayoutParams(new LinearLayout.LayoutParams(selectorWidth, height));
} else {
view.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height));
}

LinearLayout wrapperView = new LinearLayout(getContext());
wrapperView.setLayoutParams(new LinearLayout.LayoutParams(0, height, 1));
wrapperView.setOrientation(LinearLayout.HORIZONTAL);
wrapperView.setGravity(Gravity.CENTER);
wrapperView.addView(view);

int value = 0;
if (position == lastPosition) {
Expand All @@ -423,27 +436,27 @@ private void createSelectorItem(int position, RadioRealButton button) {

switch (animationType) {
case ANIM_SCALE_X:
view.setScaleX(value);
wrapperView.setScaleX(value);
break;
case ANIM_SCALE_Y:
view.setScaleY(value);
wrapperView.setScaleY(value);
break;
case ANIM_TRANSLATE_X:
if (value == 0)
view.setVisibility(INVISIBLE);
wrapperView.setVisibility(INVISIBLE);
break;
case ANIM_TRANSLATE_Y:
view.setTranslationY(value == 1 ? value : selectorSize);
wrapperView.setTranslationY(value == 1 ? value : selectorSize);
break;
case ANIM_ALPHA:
view.setAlpha(value);
wrapperView.setAlpha(value);
break;
}
button.setOnSelectorColorChangedListener(this, position);
updateViewSelectorColor(view, button.hasSelectorColor() ? button.getSelectorColor() : selectorColor);
updateViewSelectorColor(wrapperView, button.hasSelectorColor() ? button.getSelectorColor() : selectorColor);

v_selectors.add(view);
selectorContainer.addView(view);
v_selectors.add(wrapperView);
selectorContainer.addView(wrapperView);
}

private void initButtonListener(RadioRealButton button, final int position) {
Expand Down Expand Up @@ -1051,7 +1064,7 @@ public void onSelectorColorChanged(int position, int selectorColor) {

private void updateViewSelector(View view, int color, int radius, int size) {
RoundHelper.makeRound(
view,
((LinearLayout) view).getChildAt(0),
color,
radius,
selectorFullSize ? null : size
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 @@ -108,6 +108,7 @@
<attr name="rrbg_selectorBottom" format="boolean"/>
<attr name="rrbg_selectorColor" format="color"/>
<attr name="rrbg_selectorSize" format="dimension"/>
<attr name="rrbg_selectorWidth" format="dimension" />
<attr name="rrbg_selectorBringToFront" format="boolean"/>
<attr name="rrbg_selectorAboveOfBottomLine" format="boolean"/>
<attr name="rrbg_selectorRadius" format="dimension"/>
Expand Down