From 19df5df1a26dbc1f48a11adbe5ab3a13c0b5a33e Mon Sep 17 00:00:00 2001 From: EGE <ege> Date: Mon, 7 Aug 2017 02:23:52 +0300 Subject: [PATCH] fixed exceed border issue and added getters/setters --- .idea/misc.xml | 15 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- library/proguard-rules.pro | 17 -- .../radiorealbutton/BackgroundHelper.java | 2 +- .../radiorealbutton/ConversionHelper.java | 2 +- .../radiorealbutton/RadioRealButton.java | 2 +- .../radiorealbutton/RadioRealButtonGroup.java | 283 ++++++++---------- .../ceryle/radiorealbutton/RippleHelper.java | 2 +- .../ceryle/radiorealbutton/RoundHelper.java | 2 +- .../radiorealbutton/RoundedCornerLayout.java | 37 ++- library/src/main/res/values/attrs.xml | 1 - .../radiorealbutton/sample/MainActivity.java | 3 +- sample/src/main/res/layout/activity_main.xml | 4 +- 14 files changed, 171 insertions(+), 205 deletions(-) delete mode 100644 library/proguard-rules.pro diff --git a/.idea/misc.xml b/.idea/misc.xml index 1dccf50..656f5d4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> - <component name="EntryPointsManager"> - <entry_points version="2.0" /> - </component> <component name="NullableNotNullManager"> <option name="myDefaultNullable" value="android.support.annotation.Nullable" /> <option name="myDefaultNotNull" value="android.support.annotation.NonNull" /> @@ -27,17 +24,7 @@ </value> </option> </component> - <component name="ProjectLevelVcsManager" settingsEditedManually="false"> - <OptionsSetting value="true" id="Add" /> - <OptionsSetting value="true" id="Remove" /> - <OptionsSetting value="true" id="Checkout" /> - <OptionsSetting value="true" id="Update" /> - <OptionsSetting value="true" id="Status" /> - <OptionsSetting value="true" id="Edit" /> - <ConfirmationsSetting value="0" id="Add" /> - <ConfirmationsSetting value="0" id="Remove" /> - </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/build/classes" /> </component> <component name="ProjectType"> diff --git a/build.gradle b/build.gradle index 2d2e616..67c8e24 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.2' + classpath 'com.android.tools.build:gradle:3.0.0-alpha9' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d3410ea..50e05ac 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Mar 03 09:20:49 EET 2017 +#Wed Jul 19 11:30:51 EET 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip diff --git a/library/proguard-rules.pro b/library/proguard-rules.pro deleted file mode 100644 index 8dde354..0000000 --- a/library/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in C:\Users\egeak\Documents\Programming\Android_SDK/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/library/src/main/java/co/ceryle/radiorealbutton/BackgroundHelper.java b/library/src/main/java/co/ceryle/radiorealbutton/BackgroundHelper.java index 0c1ae93..f194983 100644 --- a/library/src/main/java/co/ceryle/radiorealbutton/BackgroundHelper.java +++ b/library/src/main/java/co/ceryle/radiorealbutton/BackgroundHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Ege Aker <egeaker@gmail.com> + * Copyright (C) 2016 ceryle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/src/main/java/co/ceryle/radiorealbutton/ConversionHelper.java b/library/src/main/java/co/ceryle/radiorealbutton/ConversionHelper.java index 30e56de..3b7caa8 100644 --- a/library/src/main/java/co/ceryle/radiorealbutton/ConversionHelper.java +++ b/library/src/main/java/co/ceryle/radiorealbutton/ConversionHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Ege Aker <egeaker@gmail.com> + * Copyright (C) 2016 ceryle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/src/main/java/co/ceryle/radiorealbutton/RadioRealButton.java b/library/src/main/java/co/ceryle/radiorealbutton/RadioRealButton.java index 9639fba..1502cd0 100644 --- a/library/src/main/java/co/ceryle/radiorealbutton/RadioRealButton.java +++ b/library/src/main/java/co/ceryle/radiorealbutton/RadioRealButton.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Ege Aker <egeaker@gmail.com> + * Copyright (C) 2016 ceryle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/src/main/java/co/ceryle/radiorealbutton/RadioRealButtonGroup.java b/library/src/main/java/co/ceryle/radiorealbutton/RadioRealButtonGroup.java index 81b5142..984918b 100644 --- a/library/src/main/java/co/ceryle/radiorealbutton/RadioRealButtonGroup.java +++ b/library/src/main/java/co/ceryle/radiorealbutton/RadioRealButtonGroup.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Ege Aker <egeaker@gmail.com> + * Copyright (C) 2016 ceryle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -105,7 +105,6 @@ private void init(AttributeSet attrs) { setBottomLineAttrs(); setSelectorAttrs(); - setGroupBackgroundColor(); initInterpolations(); @@ -214,17 +213,8 @@ private void initInterpolations() { } } - public void setGroupBackgroundColor() { - // setBackgroundColor(groupBackgroundColor); - // container.setBackgroundColor(groupBackgroundColor); - // container.setBackgroundColor(hasDividerBackgroundColor ? dividerBackgroundColor : groupBackgroundColor); - } - private void setBorderAttrs() { - if (!hasBorder) - return; - - setStroke(true); + setStroke(hasBorder); setStrokeColor(borderColor); setStrokeSize(borderSize); } @@ -232,7 +222,7 @@ private void setBorderAttrs() { private int borderSize, borderColor, dividerColor, bottomLineColor, selectorColor, animateDrawablesEnter, animateTextsEnter, animationType, animateDrawablesEnterDuration, animateTextsEnterDuration, animateSelector, animateSelectorDuration, animateSelectorDelay, animateDrawablesExit, animateDrawablesExitDuration, animateTextsExit, animateTextsExitDuration, lastPosition, buttonPadding, - buttonPaddingLeft, buttonPaddingRight, buttonPaddingTop, buttonPaddingBottom, groupBackgroundColor, dividerBackgroundColor, + buttonPaddingLeft, buttonPaddingRight, buttonPaddingTop, buttonPaddingBottom, groupBackgroundColor, dividerPadding, dividerSize, dividerRadius, bottomLineSize, bottomLineRadius, selectorSize, selectorRadius, initialPosition, selectorDividerSize, selectorDividerRadius, selectorDividerColor, selectorDividerPadding, checkedButtonId, animateTextsColorExit, animateTextsColorEnter, animateTextsColorDuration, animateTextsColorDurationExit, animateTextsColorDurationEnter, @@ -241,7 +231,7 @@ private void setBorderAttrs() { private float radius, animateDrawablesScale, animateTextsScale; private boolean bottomLineBringToFront, selectorBringToFront, selectorAboveOfBottomLine, selectorTop, selectorBottom, hasPadding, - hasPaddingLeft, hasPaddingRight, hasPaddingTop, hasPaddingBottom, hasDividerBackgroundColor, clickable, enabled, + hasPaddingLeft, hasPaddingRight, hasPaddingTop, hasPaddingBottom, clickable, enabled, enableDeselection, hasEnabled, hasClickable, hasBorder, hasAnimateDrawables, hasAnimateTexts, hasAnimation, selectorFullSize, hasAnimateTextsColor, hasAnimateDrawablesTint; @@ -283,8 +273,6 @@ private void getAttributes(AttributeSet attrs) { dividerRadius = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_dividerRadius, 0); dividerPadding = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_dividerPadding, 30); dividerColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_dividerColor, Color.TRANSPARENT); - dividerBackgroundColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_dividerBackgroundColor, Color.WHITE); - hasDividerBackgroundColor = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_dividerBackgroundColor); selectorDividerSize = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorDividerSize, dividerSize); if (!hasDividerSize) { @@ -452,7 +440,7 @@ private void createSelectorItem(int position, RadioRealButton button) { break; } button.setOnSelectorColorChangedListener(this, position); - updateViewSelector(view, button.hasSelectorColor() ? button.getSelectorColor() : selectorColor); + updateViewSelectorColor(view, button.hasSelectorColor() ? button.getSelectorColor() : selectorColor); v_selectors.add(view); selectorContainer.addView(view); @@ -841,69 +829,6 @@ public void setInterpolatorTextExit(Interpolator interpolatorTextExit) { this.interpolatorTextExit = interpolatorTextExit; } - public int getBorderSize() { - return borderSize; - } - - public void setBorderSize(int borderSize) { - this.borderSize = borderSize; - } - - public int getBorderColor() { - return borderColor; - } - - public void setBorderColor(int borderColor) { - this.borderColor = borderColor; - } - - public int getDividerColor() { - return dividerColor; - } - - public void setDividerColor(int dividerColor) { - this.dividerColor = dividerColor; - } - - public int getBottomLineColor() { - return bottomLineColor; - } - - public void setBottomLineColor(int bottomLineColor) { - this.bottomLineColor = bottomLineColor; - updateViewBottomLine(); - } - - private void updateViewBottomLine() { - RoundHelper.makeRound(v_bottomLine, bottomLineColor, bottomLineRadius, bottomLineRadius); - } - - public int getSelectorColor() { - return selectorColor; - } - - public void setSelectorColor(int selectorColor) { - this.selectorColor = selectorColor; - - for (View selector : v_selectors) { - updateViewSelector(selector, selectorColor); - } - } - - @Override - public void onSelectorColorChanged(int position, int selectorColor) { - updateViewSelector(v_selectors.get(position), selectorColor); - } - - private void updateViewSelector(View view, int color) { - RoundHelper.makeRound( - view, - color, - selectorRadius, - selectorFullSize ? null : selectorSize - ); - } - public int getAnimateTextsEnter() { return animateTextsEnter; } @@ -984,60 +909,47 @@ public void setAnimateTextsExitDuration(int animateTextsExitDuration) { this.animateTextsExitDuration = animateTextsExitDuration; } - public int getButtonPadding() { - return buttonPadding; - } + private void setButtonsPadding(int left, int top, int right, int bottom){ + buttonPaddingLeft = left; + buttonPaddingTop = top; + buttonPaddingRight = right; + buttonPaddingBottom = bottom; - public void setButtonPadding(int buttonPadding) { - this.buttonPadding = buttonPadding; + for (RadioRealButton button : buttons) { + setButtonPadding(button); + } } - public int getButtonPaddingLeft() { - return buttonPaddingLeft; + public int getButtonsPadding() { + return buttonPadding; } - public void setButtonPaddingLeft(int buttonPaddingLeft) { - this.buttonPaddingLeft = buttonPaddingLeft; + public int getButtonsPaddingLeft() { + return buttonPaddingLeft; } - public int getButtonPaddingRight() { + public int getButtonsPaddingRight() { return buttonPaddingRight; } - public void setButtonPaddingRight(int buttonPaddingRight) { - this.buttonPaddingRight = buttonPaddingRight; - } - - public int getButtonPaddingTop() { + public int getButtonsPaddingTop() { return buttonPaddingTop; } - public void setButtonPaddingTop(int buttonPaddingTop) { - this.buttonPaddingTop = buttonPaddingTop; - } - - public int getButtonPaddingBottom() { + public int getButtonsPaddingBottom() { return buttonPaddingBottom; } - public void setButtonPaddingBottom(int buttonPaddingBottom) { - this.buttonPaddingBottom = buttonPaddingBottom; - } - - public int getDividerBackgroundColor() { - return dividerBackgroundColor; - } - - public void setDividerBackgroundColor(int dividerBackgroundColor) { - this.dividerBackgroundColor = dividerBackgroundColor; - } - public int getDividerPadding() { return dividerPadding; } public void setDividerPadding(int dividerPadding) { this.dividerPadding = dividerPadding; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + container.setDividerPadding(dividerPadding); + } } public int getDividerSize() { @@ -1046,6 +958,7 @@ public int getDividerSize() { public void setDividerSize(int dividerSize) { this.dividerSize = dividerSize; + RoundHelper.makeDividerRound(container, dividerColor, dividerRadius, dividerSize); } public int getDividerRadius() { @@ -1054,6 +967,7 @@ public int getDividerRadius() { public void setDividerRadius(int dividerRadius) { this.dividerRadius = dividerRadius; + RoundHelper.makeDividerRound(container, dividerColor, dividerRadius, dividerSize); } public int getBottomLineSize() { @@ -1062,6 +976,7 @@ public int getBottomLineSize() { public void setBottomLineSize(int bottomLineSize) { this.bottomLineSize = bottomLineSize; + setBottomLineAttrs(); } public int getBottomLineRadius() { @@ -1070,6 +985,81 @@ public int getBottomLineRadius() { public void setBottomLineRadius(int bottomLineRadius) { this.bottomLineRadius = bottomLineRadius; + updateViewBottomLine(); + } + + public int getBorderSize() { + return borderSize; + } + + public void setBorderSize(int borderSize) { + this.borderSize = borderSize; + setBorderAttrs(); + } + + public int getBorderColor() { + return borderColor; + } + + public void setBorderColor(int borderColor) { + this.borderColor = borderColor; + setBorderAttrs(); + } + + public int getDividerColor() { + return dividerColor; + } + + public void setDividerColor(int dividerColor) { + this.dividerColor = dividerColor; + RoundHelper.makeDividerRound(container, dividerColor, dividerRadius, dividerSize); + } + + public int getBottomLineColor() { + return bottomLineColor; + } + + public void setBottomLineColor(int bottomLineColor) { + this.bottomLineColor = bottomLineColor; + updateViewBottomLine(); + } + + private void updateViewBottomLine() { + RoundHelper.makeRound(v_bottomLine, bottomLineColor, bottomLineRadius, bottomLineRadius); + } + + public int getSelectorColor() { + return selectorColor; + } + + private void updateViewSelectorColor(View view, int color) { + updateViewSelector(view, color, selectorRadius, selectorSize); + } + + public void setSelectorColor(int selectorColor) { + this.selectorColor = selectorColor; + + for (View selector : v_selectors) { + updateViewSelectorColor(selector, selectorColor); + } + } + + @Override + public void onSelectorColorChanged(int position, int selectorColor) { + updateViewSelectorColor(v_selectors.get(position), selectorColor); + } + + private void updateViewSelector(View view, int color, int radius, int size) { + RoundHelper.makeRound( + view, + color, + radius, + selectorFullSize ? null : size + ); + } + + private void updateViewSelector(View view) { + updateViewSelector(view, selectorColor, selectorRadius, selectorSize); } public int getSelectorSize() { @@ -1078,6 +1068,15 @@ public int getSelectorSize() { public void setSelectorSize(int selectorSize) { this.selectorSize = selectorSize; + + selectorContainer.getLayoutParams().height = selectorSize; + + for (View selector : v_selectors) { + updateViewSelector(selector); + + selector.getLayoutParams().height = selectorSize; + selector.requestLayout(); + } } public int getSelectorRadius() { @@ -1086,6 +1085,10 @@ public int getSelectorRadius() { public void setSelectorRadius(int selectorRadius) { this.selectorRadius = selectorRadius; + + for (View selector : v_selectors) { + updateViewSelector(selector); + } } public float getRadius() { @@ -1094,6 +1097,7 @@ public float getRadius() { public void setRadius(float radius) { this.radius = radius; + setCornerRadius(radius); } public float getAnimateDrawablesScale() { @@ -1112,20 +1116,22 @@ public void setAnimateTextsScale(float animateTextsScale) { this.animateTextsScale = animateTextsScale; } - public boolean isBottomLineBringToFront() { + public boolean isBottomLineOnFront() { return bottomLineBringToFront; } - public void setBottomLineBringToFront(boolean bottomLineBringToFront) { + public void setBottomLineToFront(boolean bottomLineBringToFront) { this.bottomLineBringToFront = bottomLineBringToFront; + setBottomLineAttrs(); } - public boolean isSelectorBringToFront() { + public boolean isSelectorOnFront() { return selectorBringToFront; } - public void setSelectorBringToFront(boolean selectorBringToFront) { + public void setSelectorToFront(boolean selectorBringToFront) { this.selectorBringToFront = selectorBringToFront; + setSelectorAttrs(); } public boolean isSelectorAboveOfBottomLine() { @@ -1134,6 +1140,7 @@ public boolean isSelectorAboveOfBottomLine() { public void setSelectorAboveOfBottomLine(boolean selectorAboveOfBottomLine) { this.selectorAboveOfBottomLine = selectorAboveOfBottomLine; + setSelectorAttrs(); } public boolean isSelectorTop() { @@ -1152,54 +1159,26 @@ public void setSelectorBottom(boolean selectorBottom) { this.selectorBottom = selectorBottom; } - public boolean isHasPadding() { + public boolean hasPadding() { return hasPadding; } - public void setHasPadding(boolean hasPadding) { - this.hasPadding = hasPadding; - } - - public boolean isHasPaddingLeft() { + public boolean hasPaddingLeft() { return hasPaddingLeft; } - public void setHasPaddingLeft(boolean hasPaddingLeft) { - this.hasPaddingLeft = hasPaddingLeft; - } - - public boolean isHasPaddingRight() { + public boolean hasPaddingRight() { return hasPaddingRight; } - public void setHasPaddingRight(boolean hasPaddingRight) { - this.hasPaddingRight = hasPaddingRight; - } - - public boolean isHasPaddingTop() { + public boolean hasPaddingTop() { return hasPaddingTop; } - public void setHasPaddingTop(boolean hasPaddingTop) { - this.hasPaddingTop = hasPaddingTop; - } - - public boolean isHasPaddingBottom() { + public boolean hasPaddingBottom() { return hasPaddingBottom; } - public void setHasPaddingBottom(boolean hasPaddingBottom) { - this.hasPaddingBottom = hasPaddingBottom; - } - - public boolean isHasDividerBackgroundColor() { - return hasDividerBackgroundColor; - } - - public void setHasDividerBackgroundColor(boolean hasDividerBackgroundColor) { - this.hasDividerBackgroundColor = hasDividerBackgroundColor; - } - @Override public boolean isClickable() { return clickable; @@ -1210,11 +1189,11 @@ public boolean isEnabled() { return enabled; } - public boolean isEnableDeselection() { + public boolean hasDeselection() { return enableDeselection; } - public void setEnableDeselection(boolean enableDeselection) { - this.enableDeselection = enableDeselection; + public void setDeselection(boolean deselection) { + this.enableDeselection = deselection; } } diff --git a/library/src/main/java/co/ceryle/radiorealbutton/RippleHelper.java b/library/src/main/java/co/ceryle/radiorealbutton/RippleHelper.java index 3124e8b..f44ef05 100644 --- a/library/src/main/java/co/ceryle/radiorealbutton/RippleHelper.java +++ b/library/src/main/java/co/ceryle/radiorealbutton/RippleHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Ege Aker <egeaker@gmail.com> + * Copyright (C) 2016 ceryle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/src/main/java/co/ceryle/radiorealbutton/RoundHelper.java b/library/src/main/java/co/ceryle/radiorealbutton/RoundHelper.java index 0d6ffa8..58b4e8e 100644 --- a/library/src/main/java/co/ceryle/radiorealbutton/RoundHelper.java +++ b/library/src/main/java/co/ceryle/radiorealbutton/RoundHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Ege Aker <egeaker@gmail.com> + * Copyright (C) 2016 ceryle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/src/main/java/co/ceryle/radiorealbutton/RoundedCornerLayout.java b/library/src/main/java/co/ceryle/radiorealbutton/RoundedCornerLayout.java index a6e0ab9..fa308bd 100644 --- a/library/src/main/java/co/ceryle/radiorealbutton/RoundedCornerLayout.java +++ b/library/src/main/java/co/ceryle/radiorealbutton/RoundedCornerLayout.java @@ -18,6 +18,8 @@ import android.graphics.Outline; import android.graphics.Paint; import android.graphics.Path; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Region; @@ -58,10 +60,6 @@ private void init(Context context) { cornerRadius = ConversionHelper.dpToPx(context, 1); setLayerType(View.LAYER_TYPE_SOFTWARE, null); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - setOutlineProvider(new ButtonOutlineProvider()); - } } //Fixes incorrect outline drawn by default @@ -81,36 +79,53 @@ protected void dispatchDraw(Canvas canvas) { path.addRoundRect(new RectF(0, 0, canvas.getWidth(), canvas.getHeight()), cornerRadius, cornerRadius, Path.Direction.CW); canvas.clipPath(path, Region.Op.REPLACE); canvas.clipPath(path); + super.dispatchDraw(canvas); + canvas.restoreToCount(count); if (hasStroke) { + + Rect rect = canvas.getClipBounds(); + + RectF rectF = new RectF(strokeSize, strokeSize, rect.right - strokeSize, rect.bottom - strokeSize); + + Path clipPath = new Path(); + float corner = cornerRadius - strokeSize; + clipPath.addRoundRect(rectF, corner, corner, Path.Direction.CW); + canvas.clipPath(clipPath, Region.Op.DIFFERENCE); + Paint p_stroke = new Paint(); p_stroke.setAntiAlias(true); p_stroke.setColor(strokeColor); - p_stroke.setStyle(Paint.Style.STROKE); - p_stroke.setStrokeWidth(strokeSize); - Rect r = canvas.getClipBounds(); + p_stroke.setStyle(Paint.Style.FILL); - int size = strokeSize / 2; - Rect outline = new Rect(size, size, r.right - size, r.bottom - size); - canvas.drawRoundRect(new RectF(outline), cornerRadius, cornerRadius, p_stroke); + canvas.drawRoundRect(new RectF(rect), cornerRadius, cornerRadius, p_stroke); } } - public void setCornerRadius(float radius) { + void setCornerRadius(float radius) { cornerRadius = radius; + requestLayout(); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + setOutlineProvider(new ButtonOutlineProvider()); + } } public void setStroke(boolean hasStroke) { this.hasStroke = hasStroke; + invalidate(); } public void setStrokeColor(int strokeColor) { this.strokeColor = strokeColor; + invalidate(); } public void setStrokeSize(int strokeSize) { this.strokeSize = strokeSize; + invalidate(); } + } \ No newline at end of file diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 117aeab..99471af 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -92,7 +92,6 @@ <attr name="rrbg_dividerPadding" format="dimension"/> <attr name="rrbg_dividerColor" format="color"/> <attr name="rrbg_dividerRadius" format="dimension"/> - <attr name="rrbg_dividerBackgroundColor" format="color"/> <attr name="rrbg_selectorDividerSize" format="dimension"/> <attr name="rrbg_selectorDividerPadding" format="dimension"/> diff --git a/sample/src/main/java/co/ceryle/radiorealbutton/sample/MainActivity.java b/sample/src/main/java/co/ceryle/radiorealbutton/sample/MainActivity.java index 9a07919..0deeecb 100644 --- a/sample/src/main/java/co/ceryle/radiorealbutton/sample/MainActivity.java +++ b/sample/src/main/java/co/ceryle/radiorealbutton/sample/MainActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Ege Aker <egeaker@gmail.com> + * Copyright (C) 2016 ceryle * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,4 +76,5 @@ public void onClickedButton(RadioRealButton button, int position) { private void updateText(int position) { button.setText("Position: " + position); } + } diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 127582e..b76ead9 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -181,8 +181,10 @@ app:rrbg_dividerPadding="10dp" app:rrbg_dividerRadius="2dp" app:rrbg_dividerSize="1dp" + app:rrbg_borderSize="1dp" + app:rrbg_borderColor="@color/green_700" app:rrbg_enableDeselection="true" - app:rrbg_radius="2dp" + app:rrbg_radius="4dp" app:rrbg_selectorAnimationType="scale_x" app:rrbg_selectorColor="@color/grey_800" app:rrbg_selectorRadius="0dp"