/** * Default constructor * * @param context : Context */ public FancyButton(Context context) { super(context); this.mContext = context; mTextTypeFace = Utils.findFont(mContext, mDefaultTextFont, null); mIconTypeFace = Utils.findFont(mContext, mDefaultIconFont, null); initializeFancyButton(); }
/** * Set Width of the button * * @param width : Width */ public void setBorderWidth(int width) { this.mBorderWidth = width; if (mIconView != null || mFontIconView != null || mTextView != null) { this.setupBackground(); } }
/** * Set the capitalization of text * * @param textAllCaps : is text to be capitalized */ public void setTextAllCaps(boolean textAllCaps) { this.mTextAllCaps = textAllCaps; setText(mText); }
/** * Set the size of Text in sp * * @param textSize : Text Size */ public void setTextSize(int textSize) { this.mDefaultTextSize = Utils.spToPx(getContext(), textSize); if (mTextView != null) mTextView.setTextSize(textSize); }
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setOutlineProvider(new CustomOutline(w, h)); } }
/** * Set Icon Position * Use the global variables (FancyButton.POSITION_LEFT, FancyButton.POSITION_RIGHT, FancyButton.POSITION_TOP, FancyButton.POSITION_BOTTOM) * * @param position : Position */ public void setIconPosition(int position) { if (position > 0 && position < 5) mIconPosition = position; else mIconPosition = POSITION_LEFT; initializeFancyButton(); }
/** * Set the gravity of Text * * @param gravity : Text Gravity */ public void setTextGravity(int gravity) { this.mDefaultTextGravity = gravity; if (mTextView != null) { this.setGravity(gravity); } }
/** * Set custom font for button Text * * @param fontName : Font Name * Place your text fonts in assets */ public void setCustomTextFont(String fontName) { mTextTypeFace = Utils.findFont(mContext, fontName, mDefaultTextFont); if (mTextView == null) initializeFancyButton(); else mTextView.setTypeface(mTextTypeFace, textStyle); }
/** * Set Background color of the button * * @param color : use Color.parse('#code') */ public void setBackgroundColor(int color) { this.mDefaultBackgroundColor = color; if (mIconView != null || mFontIconView != null || mTextView != null) { this.setupBackground(); } }
/** * Set Icon size of the button (for only font icons) in sp * * @param iconSize : Icon Size */ public void setFontIconSize(int iconSize) { this.mFontIconSize = Utils.spToPx(getContext(), iconSize); if (mFontIconView != null) mFontIconView.setTextSize(iconSize); }
/** * Set a font icon to the button (eg FFontAwesome or Entypo...) * * @param icon : Icon value eg : \uf082 */ public void setIconResource(String icon) { this.mFontIcon = icon; if (mFontIconView == null) { mIconView = null; initializeFancyButton(); } else mFontIconView.setText(icon); }
/** * Set Custom font for button icon * * @param fontName : Font Name * Place your icon fonts in assets */ public void setCustomIconFont(String fontName) { mIconTypeFace = Utils.findFont(mContext, fontName, mDefaultIconFont); if (mFontIconView == null) initializeFancyButton(); else mFontIconView.setTypeface(mIconTypeFace); }
/** * Set Disabled state color of the button border * * @param color : use Color.parse('#code') */ public void setDisableBorderColor(int color) { this.mDisabledBorderColor = color; if (mIconView != null || mFontIconView != null || mTextView != null) { this.setupBackground(); } }
/** * Override setEnabled and rebuild the fancybutton view * To redraw the button according to the state : enabled or disabled * * @param value */ @Override public void setEnabled(boolean value) { super.setEnabled(value); this.mEnabled = value; initializeFancyButton(); }
/** * Set Focus color of the button * * @param color : use Color.parse('#code') */ public void setFocusBackgroundColor(int color) { this.mFocusBackgroundColor = color; if (mIconView != null || mFontIconView != null || mTextView != null) this.setupBackground(); }
/** * Setting the button to have hollow or solid shape * * @param ghost */ public void setGhost(boolean ghost) { this.mGhost = ghost; if (mIconView != null || mFontIconView != null || mTextView != null) { this.setupBackground(); } }
/** * Set Disabled state color of the button * * @param color : use Color.parse('#code') */ public void setDisableBackgroundColor(int color) { this.mDisabledBackgroundColor = color; if (mIconView != null || mFontIconView != null || mTextView != null) this.setupBackground(); }
/** * Set color of the button border * * @param color : Color * use Color.parse('#code') */ public void setBorderColor(int color) { this.mBorderColor = color; if (mIconView != null || mFontIconView != null || mTextView != null) { this.setupBackground(); } }
/** * Set Border Radius of the button * * @param radius : Radius */ public void setRadius(int radius) { this.mRadius = radius; if (mIconView != null || mFontIconView != null || mTextView != null) { this.setupBackground(); } }
/** * 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(); } }