Skip to content

Commit

Permalink
upgrad library version to 1.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
medyo committed Jul 26, 2017
2 parents 905f73c + aa6a118 commit 4b7bd96
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 21 deletions.
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ Icons, Borders, Radius ... for Android buttons

* Border (stroke, radius, color)
* Background (normal, focus)
* Icon (Drawable, font icon)
* FontAwesome
* Custom font
* Icon (Drawable, font Icon)
* Icon (Position, size)
* right
* left
* top
* bottom
* Icon Size
* Icon Padding

### Changelog

- 1.8.4
- Fix Text Gravity
- Add Ability to define custom radius value for each corner

- 1.8.3
- Fixed long searching of font
- Added ability to use android:text, android:textSize, android:testAllCaps attributes
Expand Down Expand Up @@ -57,7 +55,7 @@ Icons, Borders, Radius ... for Android buttons

### Installation

compile 'com.github.medyo:fancybuttons:1.8.3'
compile 'com.github.medyo:fancybuttons:1.8.4'

### Usage

Expand All @@ -82,7 +80,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|
Expand All @@ -94,6 +92,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|
Expand All @@ -112,8 +111,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|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,6 +63,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;
Expand Down Expand Up @@ -299,6 +306,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);
Expand Down Expand Up @@ -364,14 +377,27 @@ 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);


if (mGhost){
defaultDrawable.setColor(getResources().getColor(android.R.color.transparent)); // Hollow Background
} else {
Expand All @@ -380,12 +406,14 @@ private void setupBackground(){

//Focus Drawable
GradientDrawable focusDrawable = new GradientDrawable();
focusDrawable.setCornerRadius(mRadius);
applyRadius(focusDrawable);

focusDrawable.setColor(mFocusBackgroundColor);

// Disabled Drawable
GradientDrawable disabledDrawable = new GradientDrawable();
disabledDrawable.setCornerRadius(mRadius);
applyRadius(disabledDrawable);

disabledDrawable.setColor(mDisabledBackgroundColor);
disabledDrawable.setStroke(mBorderWidth, mDisabledBorderColor);

Expand Down Expand Up @@ -413,7 +441,8 @@ private void setupBackground(){

// Focus/Pressed Drawable
GradientDrawable drawable2 = new GradientDrawable();
drawable2.setCornerRadius(mRadius);
applyRadius(drawable2);

if (mGhost){
drawable2.setColor(getResources().getColor(android.R.color.transparent)); // No focus color
} else {
Expand Down Expand Up @@ -609,7 +638,7 @@ public void setTextSize(int textSize){
public void setTextGravity(int gravity) {
this.mDefaultTextGravity = gravity;
if (mTextView != null) {
mTextView.setGravity(gravity);
this.setGravity(gravity);
}
}

Expand Down Expand Up @@ -733,6 +762,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
Expand Down
7 changes: 6 additions & 1 deletion fancybuttons_library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
<attr name="fb_iconPaddingTop" format="dimension" />
<attr name="fb_iconPaddingBottom" format="dimension" />

<attr name="fb_radiusTopLeft" format="dimension"/>
<attr name="fb_radiusTopRight" format="dimension"/>
<attr name="fb_radiusBottomLeft" format="dimension"/>
<attr name="fb_radiusBottomRight" format="dimension"/>

<attr name="fb_borderColor" format="color" />
<attr name="fb_borderWidth" format="dimension" />
<attr name="fb_focusColor" format="color" />
Expand All @@ -70,4 +75,4 @@
<attr name="fb_useSystemFont" format="boolean" />
</declare-styleable>

</resources>
</resources>
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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
ANDROID_BUILD_SDK_VERSION=25
VERSION_NAME=1.8.3
VERSION_NAME=1.8.4
Binary file modified resources/fancybuttons_samples.apk
Binary file not shown.
2 changes: 2 additions & 0 deletions samples/src/main/res/layout/activity_xml_buttons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down

0 comments on commit 4b7bd96

Please sign in to comment.