diff --git a/.idea/compiler.xml b/.idea/compiler.xml
deleted file mode 100644
index 96cc43e..0000000
--- a/.idea/compiler.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml
deleted file mode 100644
index e7bedf3..0000000
--- a/.idea/copyright/profiles_settings.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 586fd4e..99202cc 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,18 +1,16 @@
-
-
-
@@ -27,26 +25,10 @@
-
+
-
-
-
-
- 1.8
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 35eb1dd..94a25f7 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index de19a70..b924821 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
+ google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.3'
+ classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// NOTE: Do not place your application dependencies here; they belong
@@ -16,6 +17,7 @@ buildscript {
allprojects {
repositories {
jcenter()
+ google()
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 1540144..f8f2f44 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Mon Aug 07 02:27:44 EET 2017
+#Thu Aug 09 14:39:02 KST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
diff --git a/library/build.gradle b/library/build.gradle
index e50ed68..1eab793 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -4,12 +4,12 @@ apply plugin: 'com.github.dcendents.android-maven'
group = 'com.github.ceryle'
android {
- compileSdkVersion 25
- buildToolsVersion "25.0.2"
+ compileSdkVersion 27
+ buildToolsVersion "27.0.3"
defaultConfig {
- minSdkVersion 11
- targetSdkVersion 25
+ minSdkVersion 14
+ targetSdkVersion 27
versionCode 1
versionName "1.0"
}
@@ -44,7 +44,7 @@ artifacts {
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- testCompile 'junit:junit:4.12'
- compile 'com.android.support:appcompat-v7:25.3.1'
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ testImplementation 'junit:junit:4.12'
+ implementation 'com.android.support:appcompat-v7:27.1.1'
}
\ No newline at end of file
diff --git a/library/src/main/java/co/ceryle/segmentedbutton/SegmentedButton.java b/library/src/main/java/co/ceryle/segmentedbutton/SegmentedButton.java
index 2022f2d..c2287e4 100644
--- a/library/src/main/java/co/ceryle/segmentedbutton/SegmentedButton.java
+++ b/library/src/main/java/co/ceryle/segmentedbutton/SegmentedButton.java
@@ -17,26 +17,22 @@
import android.content.Context;
import android.content.res.TypedArray;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
-import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
-import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
+import android.support.v4.content.res.ResourcesCompat;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.View;
public class SegmentedButton extends View {
@@ -113,7 +109,9 @@ private void initText() {
mTextPaint.setTextSize(textSize);
mTextPaint.setColor(textColor);
- if (hasTextTypefacePath)
+ if (hasTextFont)
+ setTextFont(textFont);
+ else if (hasTextTypefacePath)
setTypeface(textTypefacePath);
else if (null != textTypeface) {
setTypeface(textTypeface);
@@ -418,9 +416,9 @@ public void clipToRight(float clip) {
}
private int drawableTintOnSelection, textColorOnSelection, textColor, rippleColor, buttonWidth,
- drawable, drawableTint, drawableWidth, drawableHeight, drawablePadding;
+ drawable, drawableTint, drawableWidth, drawableHeight, drawablePadding, textFont;
private boolean hasTextColorOnSelection, hasRipple, hasWidth, hasWeight, hasDrawableTintOnSelection,
- hasDrawableWidth, hasDrawableHeight, hasDrawableTint, hasTextTypefacePath;
+ hasDrawableWidth, hasDrawableHeight, hasDrawableTint, hasTextTypefacePath, hasTextFont;
private float buttonWeight, textSize;
private String textTypefacePath, text;
private Typeface textTypeface;
@@ -441,7 +439,10 @@ private void getAttributes(AttributeSet attrs) {
hasText = ta.hasValue(R.styleable.SegmentedButton_sb_text);
textSize = ta.getDimension(R.styleable.SegmentedButton_sb_textSize, ConversionHelper.spToPx(getContext(), 14));
textColor = ta.getColor(R.styleable.SegmentedButton_sb_textColor, Color.GRAY);
+ textFont = ta.getResourceId(R.styleable.SegmentedButton_sb_textFont, 0);
textTypefacePath = ta.getString(R.styleable.SegmentedButton_sb_textTypefacePath);
+
+ hasTextFont = ta.hasValue(R.styleable.SegmentedButton_sb_textFont);
hasTextTypefacePath = ta.hasValue(R.styleable.SegmentedButton_sb_textTypefacePath);
int typeface = ta.getInt(R.styleable.SegmentedButton_sb_textTypeface, 1);
switch (typeface) {
@@ -485,7 +486,6 @@ private void getAttributes(AttributeSet attrs) {
drawableGravity = DrawableGravity.getById(ta.getInteger(R.styleable.SegmentedButton_sb_drawableGravity, 0));
-
ta.recycle();
}
@@ -504,6 +504,7 @@ public void setTypeface(Typeface typeface) {
/**
* @param location is .ttf file's path in assets folder. Example: 'fonts/my_font.ttf'
*/
+
public void setTypeface(String location) {
if (null != location && !location.equals("")) {
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), location);
@@ -511,6 +512,17 @@ public void setTypeface(String location) {
}
}
+ /**
+ * @param font is R reference. Example: 'res/font/my_font.ttf' to R.font.my_font
+ */
+
+ public void setTextFont(int font) {
+ if (0 < font) {
+ Typeface typeface = ResourcesCompat.getFont(context, font);
+ mTextPaint.setTypeface(typeface);
+ }
+ }
+
/**
* GRAVITY
*/
diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml
index 7855076..0811b92 100644
--- a/library/src/main/res/values/attrs.xml
+++ b/library/src/main/res/values/attrs.xml
@@ -29,6 +29,7 @@
+
diff --git a/sample/build.gradle b/sample/build.gradle
index 3bfec9a..5b52dcf 100644
--- a/sample/build.gradle
+++ b/sample/build.gradle
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 25
- buildToolsVersion "25.0.2"
+ compileSdkVersion 27
+ buildToolsVersion "27.0.3"
defaultConfig {
applicationId "co.ceryle.segmentedbutton.sample"
- minSdkVersion 11
- targetSdkVersion 25
+ minSdkVersion 14
+ targetSdkVersion 27
versionCode 1
versionName "1.0"
}
@@ -20,8 +20,8 @@ android {
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- testCompile 'junit:junit:4.12'
- compile 'com.android.support:appcompat-v7:25.3.1'
- compile project(":library")
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ testImplementation 'junit:junit:4.12'
+ implementation 'com.android.support:appcompat-v7:27.1.1'
+ implementation project(":library")
}
diff --git a/sample/src/main/assets/fonts/aniron.ttf b/sample/src/main/res/font/aniron.ttf
similarity index 100%
rename from sample/src/main/assets/fonts/aniron.ttf
rename to sample/src/main/res/font/aniron.ttf
diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml
index 07b022b..7744ae6 100644
--- a/sample/src/main/res/layout/activity_main.xml
+++ b/sample/src/main/res/layout/activity_main.xml
@@ -89,7 +89,7 @@
app:sb_drawableGravity="top"
app:sb_text="Aragorn"
app:sb_textColor_onSelection="@color/orange_700"
- app:sb_textTypefacePath="fonts/aniron.ttf"/>
+ app:sb_textFont="@font/aniron"/>
+ app:sb_textFont="@font/aniron"/>
+ app:sb_textFont="@font/aniron"/>