diff --git a/README.md b/README.md
index 920cd4c..6d243a4 100644
--- a/README.md
+++ b/README.md
@@ -21,6 +21,14 @@ Icons, Borders, Radius ... for Android buttons
### Changelog
+- 1.9.0
+ - Add support for font resources (For text font only)
+ - Increase min API level to 14
+ - Now you can use these to set text font (res/font/roboto_slab_bold.ttf):
+ android:fontFamily="@font/roboto_slab_bold"
+ fancy:fb_textFontRes="@font/roboto_slab_bold"
+ - Add dependency on support library used only when using font resources.
+
- 1.8.4
- Fix Text Gravity
- Add Ability to define custom radius value for each corner
@@ -55,7 +63,11 @@ Icons, Borders, Radius ... for Android buttons
### Installation
- compile 'com.github.medyo:fancybuttons:1.8.4'
+ implementation 'com.github.medyo:fancybuttons:1.9.0'
+
+### To use font resources add support library to your dependencies:
+
+ implementation "com.android.support:appcompat-v7:$support_lib_version"
### Usage
@@ -78,6 +90,7 @@ Icons, Borders, Radius ... for Android buttons
| fancy:fb_textColor | setTextColor(int) | Text Color of the button |
| fancy:fb_textSize | setTextSize(int) | Size of the text |
| fancy:fb_textFont | setCustomTextFont(String) | FontFamily of the text|
+| fancy:fb_textFontRes | setCustomTextFont(int) | FontFamily of the text using font resource. REQUIRES support library|
| fancy:fb_textGravity | setTextGravity(Int) | Gravity of the text|
| fancy:fb_iconResource | setIconResource(Drawable) | Drawable icon of the button|
| fancy:fb_iconPosition | setIconPosition(int) | Position of the icon : Left, Right, Top, Bottom|
@@ -110,6 +123,7 @@ Default Attributes have more priority than Attributes with prefix fancy.
| android:text |
| android:textSize |
| android:textAllCaps |
+| android:fontFamily |
#### Supported Getters
| Function | Description |
@@ -174,6 +188,7 @@ Fancybuttons is delivered with :
**How to add new fonts ?**
Just Paste your font inside `assets/fonts/` folder for Text fonts or inside `assets/iconfonts/` for icon fonts eg : entypo
+OR for text fonts add it to res/font/ and use android:fontFamily or fancy:fb_textFontRes to use it.
## Contributions
Fancybuttons needs you to build the missing features :
diff --git a/build.gradle b/build.gradle
index 46344fb..905c7e6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,11 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
+ ext.support_lib_version = '27.1.1'
repositories {
jcenter()
+ google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.0.1'
+ classpath 'com.android.tools.build:gradle:3.2.0-beta05'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
@@ -14,5 +16,6 @@ buildscript {
allprojects {
repositories {
jcenter()
+ google()
}
}
diff --git a/fancybuttons_library/build.gradle b/fancybuttons_library/build.gradle
index 64dc177..0ee7c13 100644
--- a/fancybuttons_library/build.gradle
+++ b/fancybuttons_library/build.gradle
@@ -20,7 +20,9 @@ android {
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ implementation "com.android.support:support-annotations:$support_lib_version"
+ api "com.android.support:appcompat-v7:$support_lib_version"
}
archivesBaseName = 'fancybuttons'
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 1912245..c739af3 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.support.annotation.FontRes;
+import android.support.v4.content.res.ResourcesCompat;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
@@ -360,12 +362,31 @@ private void initAttributesArray(TypedArray attrsArray) {
? Utils.findFont(mContext, iconFontFamily, mDefaultIconFont)
: Utils.findFont(mContext, mDefaultIconFont, null);
- mTextTypeFace = textFontFamily != null
- ? Utils.findFont(mContext, textFontFamily, mDefaultTextFont)
- : Utils.findFont(mContext, mDefaultTextFont, null);
+ Typeface fontResource = getTypeface(attrsArray);
+ if (fontResource != null) {
+ mTextTypeFace = fontResource;
+ } else {
+ mTextTypeFace = textFontFamily != null
+ ? Utils.findFont(mContext, textFontFamily, mDefaultTextFont)
+ : Utils.findFont(mContext, mDefaultTextFont, null);
+ }
}
}
+ private Typeface getTypeface(TypedArray ta) {
+ if (ta.hasValue(R.styleable.FancyButtonsAttrs_android_fontFamily)) {
+ int fontId = ta.getResourceId(R.styleable.FancyButtonsAttrs_android_fontFamily, 0);
+ if (fontId != 0)
+ return ResourcesCompat.getFont(getContext(), fontId);
+ }
+ if(ta.hasValue(R.styleable.FancyButtonsAttrs_fb_textFontRes)){
+ int fontId = ta.getResourceId(R.styleable.FancyButtonsAttrs_fb_textFontRes, 0);
+ if (fontId != 0)
+ return ResourcesCompat.getFont(getContext(), fontId);
+ }
+ return null;
+ }
+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable getRippleDrawable(Drawable defaultDrawable, Drawable focusDrawable, Drawable disabledDrawable) {
if (!mEnabled) {
@@ -807,6 +828,22 @@ public void setCustomTextFont(String fontName) {
mTextView.setTypeface(mTextTypeFace, textStyle);
}
+ /**
+ * Set custom font for button Text
+ *
+ * @param fontId : Font id
+ * Place your text fonts in font resources.
+ * Eg. res/font/roboto.ttf or res/font/roboto.xml
+ */
+ public void setCustomTextFont(@FontRes int fontId) {
+ mTextTypeFace = ResourcesCompat.getFont(getContext(), fontId);
+
+ if (mTextView == null)
+ initializeFancyButton();
+ else
+ mTextView.setTypeface(mTextTypeFace, textStyle);
+ }
+
/**
* Set Custom font for button icon
*
diff --git a/fancybuttons_library/src/main/res/values/attrs.xml b/fancybuttons_library/src/main/res/values/attrs.xml
index bac5af8..a91f880 100644
--- a/fancybuttons_library/src/main/res/values/attrs.xml
+++ b/fancybuttons_library/src/main/res/values/attrs.xml
@@ -8,6 +8,7 @@
+
@@ -16,6 +17,7 @@
+
diff --git a/gradle.properties b/gradle.properties
index 6543249..7d0d289 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,6 +1,6 @@
VERSION_CODE=25
-ANDROID_BUILD_MIN_SDK_VERSION=8
+ANDROID_BUILD_MIN_SDK_VERSION=14
ANDROID_BUILD_TARGET_SDK_VERSION=27
ANDROID_BUILD_TOOLS_VERSION=27.0.3
ANDROID_BUILD_SDK_VERSION=27
-VERSION_NAME=1.8.4
\ No newline at end of file
+VERSION_NAME=1.9.0
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 7051332..6191a9a 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Sun Feb 11 09:10:35 WIB 2018
+#Sat Aug 04 21:48:19 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
diff --git a/samples/build.gradle b/samples/build.gradle
index 4b3c25c..2d1eb2a 100644
--- a/samples/build.gradle
+++ b/samples/build.gradle
@@ -19,8 +19,8 @@ android {
}
dependencies {
- compile 'com.android.support:appcompat-v7:22.2.1'
- compile project(':fancybuttons_library')
+ implementation "com.android.support:appcompat-v7:$support_lib_version"
+ implementation project(':fancybuttons_library')
- compile fileTree(dir: 'libs', include: ['*.jar'])
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
}
diff --git a/samples/src/main/java/mehdi/sakout/fancybuttons/samples/MainActivity.java b/samples/src/main/java/mehdi/sakout/fancybuttons/samples/MainActivity.java
index e7b14ff..fd71c52 100644
--- a/samples/src/main/java/mehdi/sakout/fancybuttons/samples/MainActivity.java
+++ b/samples/src/main/java/mehdi/sakout/fancybuttons/samples/MainActivity.java
@@ -2,19 +2,12 @@
import android.app.ListActivity;
import android.content.Intent;
-import android.graphics.Color;
-import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
-import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
-import android.widget.LinearLayout;
-
-import mehdi.sakout.fancybuttons.FancyButton;
public class MainActivity extends ListActivity implements AdapterView.OnItemClickListener {
@@ -34,7 +27,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
-
+
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
@@ -54,17 +47,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onItemClick(AdapterView> adapterView, View view, int position, long l) {
- switch(position){
- case 0 :
- Intent intentXML = new Intent(MainActivity.this,XmlButtons.class);
+ switch (position) {
+ case 0:
+ Intent intentXML = new Intent(MainActivity.this, XmlButtons.class);
startActivity(intentXML);
break;
- case 1 :
- Intent intentProg = new Intent(MainActivity.this,ProgramButtons.class);
+ case 1:
+ Intent intentProg = new Intent(MainActivity.this, ProgramButtons.class);
startActivity(intentProg);
break;
- default: throw new IllegalArgumentException("Hold up, hold my phone :)");
+ default:
+ throw new IllegalArgumentException("Hold up, hold my phone :)");
}
}
}
diff --git a/samples/src/main/java/mehdi/sakout/fancybuttons/samples/ProgramButtons.java b/samples/src/main/java/mehdi/sakout/fancybuttons/samples/ProgramButtons.java
index 321f0ec..e6b8569 100644
--- a/samples/src/main/java/mehdi/sakout/fancybuttons/samples/ProgramButtons.java
+++ b/samples/src/main/java/mehdi/sakout/fancybuttons/samples/ProgramButtons.java
@@ -1,8 +1,6 @@
package mehdi.sakout.fancybuttons.samples;
import android.graphics.Color;
-import android.support.v7.app.ActionBar;
-import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
@@ -47,7 +45,8 @@ protected void onCreate(Bundle savedInstanceState) {
installBtn.setFocusBackgroundColor(Color.parseColor("#bfe156"));
installBtn.setTextSize(17);
installBtn.setRadius(5);
- installBtn.setIconPadding(0,30,0,0);
+ installBtn.setCustomTextFont(R.font.roboto_slab_bold);
+ installBtn.setIconPadding(0, 30, 0, 0);
installBtn.setEnabled(false);
FancyButton signupBtn = new FancyButton(this);
@@ -58,15 +57,15 @@ protected void onCreate(Bundle savedInstanceState) {
signupBtn.setFocusBackgroundColor(Color.parseColor("#ffa43c"));
signupBtn.setTextSize(20);
signupBtn.setCustomTextFont("robotothin.ttf");
- signupBtn.setIconPadding(10,0,10,0);
+ signupBtn.setIconPadding(10, 0, 10, 0);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- layoutParams.setMargins(0,0,0,10);
+ layoutParams.setMargins(0, 0, 0, 10);
- LinearLayout container = (LinearLayout)findViewById(R.id.container);
- container.addView(facebookLoginBtn,layoutParams);
- container.addView(foursquareBtn,layoutParams);
- container.addView(installBtn,layoutParams);
+ LinearLayout container = (LinearLayout) findViewById(R.id.container);
+ container.addView(facebookLoginBtn, layoutParams);
+ container.addView(foursquareBtn, layoutParams);
+ container.addView(installBtn, layoutParams);
container.addView(signupBtn);
}
diff --git a/samples/src/main/res/font/roboto_slab_bold.ttf b/samples/src/main/res/font/roboto_slab_bold.ttf
new file mode 100644
index 0000000..df5d1df
Binary files /dev/null and b/samples/src/main/res/font/roboto_slab_bold.ttf differ
diff --git a/samples/src/main/res/layout/activity_xml_buttons.xml b/samples/src/main/res/layout/activity_xml_buttons.xml
index 49b5d0c..735d80e 100644
--- a/samples/src/main/res/layout/activity_xml_buttons.xml
+++ b/samples/src/main/res/layout/activity_xml_buttons.xml
@@ -1,6 +1,7 @@
@@ -587,6 +588,57 @@
+
+
+
+
+
+