From 02448868a914612a22222257ef910bf49b04d674 Mon Sep 17 00:00:00 2001 From: Mahdi Pishguy Date: Tue, 13 Jun 2017 13:53:58 +0430 Subject: [PATCH 1/7] Update FancyButton.java --- .../src/main/java/mehdi/sakout/fancybuttons/FancyButton.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java b/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java index 8b716b5..060357a 100644 --- a/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java +++ b/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java @@ -607,7 +607,7 @@ public void setTextSize(int textSize){ public void setTextGravity(int gravity) { this.mDefaultTextGravity = gravity; if (mTextView != null) { - mTextView.setGravity(gravity); + this.setGravity(gravity); } } From 877acb9a1d7390c8f0152cb86ea9d3488d4a99c8 Mon Sep 17 00:00:00 2001 From: Mahdi Pishguy Date: Fri, 16 Jun 2017 17:38:02 +0430 Subject: [PATCH 2/7] Using custom button radius --- .../sakout/fancybuttons/FancyButton.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java b/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java index 060357a..698871f 100644 --- a/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java +++ b/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java @@ -59,6 +59,11 @@ public class FancyButton extends LinearLayout{ private int mBorderWidth = 0; private int mRadius = 0; + private int mRadiusTopLeft = 0; + private int mRadiusTopRight = 0; + private int mRadiusBottomLeft = 0; + private int mRadiusBottomRight = 0; + private boolean mEnabled = true; private boolean mTextAllCaps = false; @@ -297,6 +302,12 @@ private void initAttributesArray(TypedArray attrsArray){ mBorderWidth = (int) attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_borderWidth,mBorderWidth); mRadius = (int)attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_radius,mRadius); + + mRadiusTopLeft = (int) attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_radiusTopLeft, mRadius); + mRadiusTopRight = (int) attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_radiusTopRight, mRadius); + mRadiusBottomLeft = (int) attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_radiusBottomLeft, mRadius); + mRadiusBottomRight = (int) attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_radiusBottomRight, mRadius); + mFontIconSize = (int)attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_fontIconSize, mFontIconSize); mIconPaddingLeft = (int)attrsArray.getDimension(R.styleable.FancyButtonsAttrs_fb_iconPaddingLeft,mIconPaddingLeft); @@ -365,11 +376,13 @@ private Drawable getRippleDrawable(Drawable defaultDrawable, Drawable focusDrawa @SuppressLint("NewApi") private void setupBackground(){ - - // Default Drawable GradientDrawable defaultDrawable = new GradientDrawable(); defaultDrawable.setCornerRadius(mRadius); + + defaultDrawable.setCornerRadii(new float[]{mRadiusTopLeft, mRadiusTopLeft, mRadiusTopRight, mRadiusTopRight, + mRadiusBottomRight, mRadiusBottomRight, mRadiusBottomLeft, mRadiusBottomLeft}); + if (mGhost){ defaultDrawable.setColor(getResources().getColor(android.R.color.transparent)); // Hollow Background } else { @@ -379,11 +392,19 @@ private void setupBackground(){ //Focus Drawable GradientDrawable focusDrawable = new GradientDrawable(); focusDrawable.setCornerRadius(mRadius); + + focusDrawable.setCornerRadii(new float[]{mRadiusTopLeft, mRadiusTopLeft, mRadiusTopRight, mRadiusTopRight, + mRadiusBottomRight, mRadiusBottomRight, mRadiusBottomLeft, mRadiusBottomLeft}); + focusDrawable.setColor(mFocusBackgroundColor); // Disabled Drawable GradientDrawable disabledDrawable = new GradientDrawable(); disabledDrawable.setCornerRadius(mRadius); + + focusDrawable.setCornerRadii(new float[]{mRadiusTopLeft, mRadiusTopLeft, mRadiusTopRight, mRadiusTopRight, + mRadiusBottomRight, mRadiusBottomRight, mRadiusBottomLeft, mRadiusBottomLeft}); + disabledDrawable.setColor(mDisabledBackgroundColor); disabledDrawable.setStroke(mBorderWidth, mDisabledBorderColor); @@ -412,6 +433,10 @@ private void setupBackground(){ // Focus/Pressed Drawable GradientDrawable drawable2 = new GradientDrawable(); drawable2.setCornerRadius(mRadius); + + focusDrawable.setCornerRadii(new float[]{mRadiusTopLeft, mRadiusTopLeft, mRadiusTopRight, mRadiusTopRight, + mRadiusBottomRight, mRadiusBottomRight, mRadiusBottomLeft, mRadiusBottomLeft}); + if (mGhost){ drawable2.setColor(getResources().getColor(android.R.color.transparent)); // No focus color } else { From 14fecc94c3234cea3454d8eac0e0fe350031eea1 Mon Sep 17 00:00:00 2001 From: Mahdi Pishguy Date: Fri, 16 Jun 2017 17:38:46 +0430 Subject: [PATCH 3/7] add custom attributes for custom button radius --- fancybuttons_library/src/main/res/values/attrs.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fancybuttons_library/src/main/res/values/attrs.xml b/fancybuttons_library/src/main/res/values/attrs.xml index 6c2ca48..768975c 100644 --- a/fancybuttons_library/src/main/res/values/attrs.xml +++ b/fancybuttons_library/src/main/res/values/attrs.xml @@ -57,6 +57,12 @@ + + + + + + @@ -70,4 +76,4 @@ - \ No newline at end of file + From 57d719d73173d297e2b0fd8e08ae19b2d3787173 Mon Sep 17 00:00:00 2001 From: medyo Date: Wed, 26 Jul 2017 22:42:50 +0100 Subject: [PATCH 4/7] applies custom corners radius only if main radius isn't defined --- .../sakout/fancybuttons/FancyButton.java | 32 ++++++++++--------- .../main/res/layout/activity_xml_buttons.xml | 2 ++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java b/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java index a47ba2b..efbc4cd 100644 --- a/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java +++ b/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java @@ -375,15 +375,26 @@ private Drawable getRippleDrawable(Drawable defaultDrawable, Drawable focusDrawa } + /** + * This method applies radius to the drawable corners + * Specify radius for each corner if radius attribute is not defined + * @param drawable Drawable + */ + private void applyRadius(GradientDrawable drawable){ + if (mRadius > 0){ + drawable.setCornerRadius(mRadius); + } else { + drawable.setCornerRadii(new float[]{mRadiusTopLeft, mRadiusTopLeft, mRadiusTopRight, mRadiusTopRight, + mRadiusBottomRight, mRadiusBottomRight, mRadiusBottomLeft, mRadiusBottomLeft}); + } + } @SuppressLint("NewApi") private void setupBackground(){ // Default Drawable GradientDrawable defaultDrawable = new GradientDrawable(); - defaultDrawable.setCornerRadius(mRadius); + applyRadius(defaultDrawable); - defaultDrawable.setCornerRadii(new float[]{mRadiusTopLeft, mRadiusTopLeft, mRadiusTopRight, mRadiusTopRight, - mRadiusBottomRight, mRadiusBottomRight, mRadiusBottomLeft, mRadiusBottomLeft}); if (mGhost){ defaultDrawable.setColor(getResources().getColor(android.R.color.transparent)); // Hollow Background @@ -393,19 +404,13 @@ private void setupBackground(){ //Focus Drawable GradientDrawable focusDrawable = new GradientDrawable(); - focusDrawable.setCornerRadius(mRadius); - - focusDrawable.setCornerRadii(new float[]{mRadiusTopLeft, mRadiusTopLeft, mRadiusTopRight, mRadiusTopRight, - mRadiusBottomRight, mRadiusBottomRight, mRadiusBottomLeft, mRadiusBottomLeft}); + applyRadius(focusDrawable); focusDrawable.setColor(mFocusBackgroundColor); // Disabled Drawable GradientDrawable disabledDrawable = new GradientDrawable(); - disabledDrawable.setCornerRadius(mRadius); - - focusDrawable.setCornerRadii(new float[]{mRadiusTopLeft, mRadiusTopLeft, mRadiusTopRight, mRadiusTopRight, - mRadiusBottomRight, mRadiusBottomRight, mRadiusBottomLeft, mRadiusBottomLeft}); + applyRadius(disabledDrawable); disabledDrawable.setColor(mDisabledBackgroundColor); disabledDrawable.setStroke(mBorderWidth, mDisabledBorderColor); @@ -434,10 +439,7 @@ private void setupBackground(){ // Focus/Pressed Drawable GradientDrawable drawable2 = new GradientDrawable(); - drawable2.setCornerRadius(mRadius); - - focusDrawable.setCornerRadii(new float[]{mRadiusTopLeft, mRadiusTopLeft, mRadiusTopRight, mRadiusTopRight, - mRadiusBottomRight, mRadiusBottomRight, mRadiusBottomLeft, mRadiusBottomLeft}); + applyRadius(drawable2); if (mGhost){ drawable2.setColor(getResources().getColor(android.R.color.transparent)); // No focus color diff --git a/samples/src/main/res/layout/activity_xml_buttons.xml b/samples/src/main/res/layout/activity_xml_buttons.xml index 2c1cbb8..24c62ca 100644 --- a/samples/src/main/res/layout/activity_xml_buttons.xml +++ b/samples/src/main/res/layout/activity_xml_buttons.xml @@ -268,6 +268,8 @@ fancy:fb_borderWidth="2dp" fancy:fb_defaultColor="#55acee" fancy:fb_focusColor="#8cc9f8" + fancy:fb_radiusTopLeft="10dp" + fancy:fb_radiusBottomRight="10dp" fancy:fb_iconResource="@drawable/twitter" fancy:fb_text="Follow me on Twitter" fancy:fb_textColor="#FFFFFF"/> From 1dc208a6cae2babf5246e610692959929f9aa647 Mon Sep 17 00:00:00 2001 From: medyo Date: Wed, 26 Jul 2017 22:49:04 +0100 Subject: [PATCH 5/7] add a setter to define bottom borders --- .../mehdi/sakout/fancybuttons/FancyButton.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java b/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java index efbc4cd..a5d7148 100644 --- a/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java +++ b/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java @@ -760,6 +760,22 @@ public void setRadius(int radius){ } } + /** + * Set Border Radius for each button corner + * Top Left, Top Right, Bottom Left, Bottom Right + * @param radius : Array of int + */ + public void setRadius(int[] radius){ + this.mRadiusTopLeft = radius[0]; + this.mRadiusTopRight = radius[1]; + this.mRadiusBottomLeft = radius[2]; + this.mRadiusBottomRight = radius[3]; + + if(mIconView != null || mFontIconView != null || mTextView != null){ + this.setupBackground(); + } + } + /** * Set custom font for button Text * @param fontName : Font Name From ec4768a476f7f0d00a92d5172f64d69a93ee2cc5 Mon Sep 17 00:00:00 2001 From: medyo Date: Wed, 26 Jul 2017 23:02:39 +0100 Subject: [PATCH 6/7] remove space --- .../src/main/java/mehdi/sakout/fancybuttons/FancyButton.java | 2 ++ fancybuttons_library/src/main/res/values/attrs.xml | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java b/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java index a5d7148..9942e8d 100644 --- a/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java +++ b/fancybuttons_library/src/main/java/mehdi/sakout/fancybuttons/FancyButton.java @@ -13,6 +13,8 @@ import android.graphics.drawable.RippleDrawable; import android.graphics.drawable.StateListDrawable; import android.os.Build; +import android.text.Html; +import android.text.SpannableString; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; diff --git a/fancybuttons_library/src/main/res/values/attrs.xml b/fancybuttons_library/src/main/res/values/attrs.xml index 768975c..995ec40 100644 --- a/fancybuttons_library/src/main/res/values/attrs.xml +++ b/fancybuttons_library/src/main/res/values/attrs.xml @@ -57,7 +57,6 @@ - From aa6a1180a0e84a21a134d4a9714816428ad28163 Mon Sep 17 00:00:00 2001 From: medyo Date: Thu, 27 Jul 2017 00:00:35 +0100 Subject: [PATCH 7/7] add corners radius to the documentation --- README.md | 6 +++--- gradle.properties | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 23920f1..46061a3 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ Icons, Borders, Radius ... for Android buttons | fancy:fb_textFont | setCustomTextFont(String) | FontFamily of the text| | fancy:fb_textGravity | setTextGravity(Int) | Gravity of the text| | fancy:fb_iconResource | setIconResource(Drawable) | Drawable icon of the button| -| fancy:fb_iconPosition | setsetIconPosition(int) | Position of the icon : Left, Right, Top, Bottom| +| fancy:fb_iconPosition | setIconPosition(int) | Position of the icon : Left, Right, Top, Bottom| | fancy:fb_fontIconResource | setIconResource(String) | font icon of the button| | fancy:fb_fontIconSize | setFontIconSize(int) | Size of the icon | | fancy:fb_iconFont | setCustomIconFont(String) | FontFamily of the icon| @@ -94,6 +94,7 @@ Icons, Borders, Radius ... for Android buttons | fancy:fb_disabledTextColor | setDisableTextColor(int) | Disabled Color of button text| | fancy:fb_disabledBorderColor | setDisableBorderColor(int) | Disabled Color of button border| | fancy:fb_radius | setRadius(int) | Radius of the button| +| fancy:fb_radius(TopLeft, TopRight,BottomLeft,BottomRight) | setRadius(int[] radius) | Custom Radius for each button corner| | fancy:fb_iconPaddingLeft | setIconPadding(int,int,int,int) | Icon Padding| | fancy:fb_iconPaddingRight | setIconPadding(int,int,int,int) | Icon Padding| | fancy:fb_iconPaddingTop | setIconPadding(int,int,int,int) | Icon Padding| @@ -112,8 +113,7 @@ Default Attributes have more priority than Attributes with prefix fancy. | android:textSize | | android:textAllCaps | -#### Supported Getters - +#### Supported Getters | Function | Description | | ------------- |:-------------:| -----:| | getText() | Returns Text Value of the button| diff --git a/gradle.properties b/gradle.properties index d82dc6a..21b390b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_CODE=24 +VERSION_CODE=25 ANDROID_BUILD_MIN_SDK_VERSION=8 ANDROID_BUILD_TARGET_SDK_VERSION=25 ANDROID_BUILD_TOOLS_VERSION=25.0.1