Skip to content

Commit

Permalink
add setIconResource(Drawable) and fix fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
medyo committed May 2, 2016
1 parent 546b3d0 commit f53b78f
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public class FancyButton extends LinearLayout{
public static final int POSITION_TOP = 3;
public static final int POSITION_BOTTOM = 4;

private String mDefaultIconFont = "fonts/fontawesome.ttf";
private String mDefaultTextFont = "fonts/robotoregular.ttf";
private String mDefaultIconFont = "fontawesome.ttf";
private String mDefaultTextFont = "robotoregular.ttf";

private ImageView mIconView;
private TextView mFontIconView;
Expand All @@ -86,8 +86,8 @@ public FancyButton(Context context){
super(context);
this.mContext = context;

mTextTypeFace = Typeface.createFromAsset(mContext.getAssets(), String.format("%s",mDefaultTextFont));
mIconTypeFace = Typeface.createFromAsset(mContext.getAssets(), String.format("%s",mDefaultIconFont));
mTextTypeFace = Utils.findFont(mContext, mDefaultTextFont, null);
mIconTypeFace = Utils.findFont(mContext, mDefaultIconFont, null);
initializeFancyButton();
}

Expand Down Expand Up @@ -324,13 +324,13 @@ private void initAttributesArray(TypedArray attrsArray){
if(iconFontFamily!=null){
mIconTypeFace = Utils.findFont(mContext, iconFontFamily, mDefaultIconFont);
}else{
mIconTypeFace = Typeface.createFromAsset(mContext.getAssets(), String.format("%s",mDefaultIconFont));
mIconTypeFace = Utils.findFont(mContext, mDefaultIconFont, null);
}

if(textFontFamily!=null){
mTextTypeFace = Utils.findFont(mContext, textFontFamily, mDefaultTextFont);
}else{
mTextTypeFace= Typeface.createFromAsset(mContext.getAssets(), String.format("%s",mDefaultTextFont));
mTextTypeFace = Utils.findFont(mContext, mDefaultTextFont, null);
}
}
}
Expand Down Expand Up @@ -543,7 +543,7 @@ public void setIconPadding(int paddingLeft, int paddingTop, int paddingRight, in

/**
* Set an icon from resources to the button
* @param drawable : Drawable resource
* @param drawable : Int resource
*/
public void setIconResource(int drawable){
this.mIconResource = mContext.getResources().getDrawable(drawable);
Expand All @@ -555,6 +555,20 @@ public void setIconResource(int drawable){
mIconView.setImageDrawable(mIconResource);
}

/**
* Set a drawable to the button
* @param drawable : Drawable resource
*/
public void setIconResource(Drawable drawable){
this.mIconResource = drawable;
if(mIconView == null || mFontIconView != null) {
mFontIconView= null;
initializeFancyButton();
}
else
mIconView.setImageDrawable(mIconResource);
}

/**
* Set a font icon to the button (eg FFontAwesome or Entypo...)
* @param icon : Icon value eg : \uf082
Expand Down

0 comments on commit f53b78f

Please sign in to comment.