Skip to content

Commit

Permalink
custom typeface
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhart committed Feb 4, 2018
1 parent 15d03c9 commit 54ffeba
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 15 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Usage
-----

1. Add jcenter() to repositories block in your gradle file.
2. Add `compile 'com.shuhart.stepview:stepview:1.2.0'` to your dependencies.
2. Add `compile 'com.shuhart.stepview:stepview:1.2.1'` to your dependencies.
3. Add `StepView` into your layouts or view hierarchy.

Supported animations:
Expand Down Expand Up @@ -68,7 +68,8 @@ Styling:
app:stepViewStyle="@style/StepView"
app:doneStepMarkColor="@color/colorPrimary"
app:stepNumberTextSize="12sp"
app:animationType="Line"/>
app:animationType="Line"
app:typeface="@font/roboto_italic"/>
```

or instantiate and setup it in runtime with handy state builder:
Expand All @@ -94,6 +95,7 @@ or instantiate and setup it in runtime with handy state builder:
.stepLineWidth(getResources().getDimensionPixelSize(R.dimen.dp1))
.textSize(getResources().getDimensionPixelSize(R.dimen.sp14))
.stepNumberTextSize(getResources().getDimensionPixelSize(R.dimen.sp16))
.typeface(ResourcesCompat.getFont(context, R.font.roboto_italic))
// other state methods are equal to the corresponding xml attributes
.commit();
```
Expand All @@ -109,6 +111,9 @@ If you want to allow going back after that, you should unmark the done state:
stepView.done(false)
```

If you want a custom typeface you should add font files to the resource folder "font" and reference any in xml layout.
Alternatively you can specify typeface using the state builder in your code. Look into the sample for additional details on that.

License
=======

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
google()
jcenter()
Expand All @@ -16,6 +15,7 @@ buildscript {
}

allprojects {
ext.supportVersion = "27.0.2"
repositories {
google()
jcenter()
Expand Down
8 changes: 4 additions & 4 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
compileSdkVersion 27
defaultConfig {
applicationId "com.shuhart.stepview"
minSdkVersion 16
targetSdkVersion 26
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -20,7 +20,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation project(':stepview')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
Expand Down
7 changes: 4 additions & 3 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#25448a"
android:gravity="center"
android:orientation="vertical"
Expand All @@ -14,9 +14,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
app:stepPadding="12dp"
app:animationType="All"
app:steps="@array/steps"/>
app:stepPadding="12dp"
app:steps="@array/steps"
app:typeface="@font/roboto_italic" />

<Button
android:id="@+id/next"
Expand Down
9 changes: 5 additions & 4 deletions stepview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ext {
siteUrl = 'https://github.com/shuhart/StepView'
gitUrl = 'https://github.com/shuhart/StepView.git'

libraryVersion = '1.2.0'
libraryVersion = '1.2.1'

developerId = 'shuhart'
developerName = 'Redrick Shuhart'
Expand All @@ -37,11 +37,11 @@ buildscript {
}

android {
compileSdkVersion 26
compileSdkVersion 27

defaultConfig {
minSdkVersion 14
targetSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName "1.0"

Expand All @@ -58,7 +58,8 @@ android {
}

dependencies {
implementation 'com.android.support:support-annotations:26.1.0'
implementation "com.android.support:support-annotations:$supportVersion"
implementation "com.android.support:appcompat-v7:$supportVersion"
}

group = publishedGroupId
Expand Down
18 changes: 17 additions & 1 deletion stepview/src/main/java/com/shuhart/stepview/StepView.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.Dimension;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.support.v4.content.res.ResourcesCompat;
import android.util.AttributeSet;
import android.view.View;

Expand Down Expand Up @@ -112,9 +114,9 @@ public StepView(Context context, AttributeSet attrs) {

public StepView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
applyStyles(context, attrs, defStyleAttr);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextAlign(Paint.Align.CENTER);
applyStyles(context, attrs, defStyleAttr);
drawEditMode();
}

Expand Down Expand Up @@ -152,6 +154,13 @@ private void applyStyles(Context context, AttributeSet attrs, int defStyleAttr)
if (background != null) {
setBackgroundDrawable(background);
}
int fontId = ta.getResourceId(R.styleable.StepView_typeface, 0);
if (fontId != 0) {
Typeface typeface = ResourcesCompat.getFont(context, fontId);
if (typeface != null) {
paint.setTypeface(typeface);
}
}
ta.recycle();
}

Expand Down Expand Up @@ -624,6 +633,7 @@ public class State {
@ColorInt
private int doneStepMarkColor = StepView.this.doneStepMarkColor;
private int animationDuration = StepView.this.animationDuration;
private Typeface typeface = paint.getTypeface();

public State animationType(@AnimationType int animationType) {
this.animationType = animationType;
Expand Down Expand Up @@ -725,6 +735,11 @@ public State stepsNumber(int stepsNumber) {
return this;
}

public State typeface(Typeface typeface) {
this.typeface = typeface;
return this;
}

public void commit() {
StepView.this.animationType = animationType;
StepView.this.selectedTextColor = selectedTextColor;
Expand All @@ -751,6 +766,7 @@ public void commit() {
} else {
StepView.this.invalidate();
}
paint.setTypeface(typeface);
}
}
}
Binary file added stepview/src/main/res/font/roboto_bold.ttf
Binary file not shown.
Binary file added stepview/src/main/res/font/roboto_italic.ttf
Binary file not shown.
Binary file added stepview/src/main/res/font/roboto_regular.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions stepview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
</attr>
<attr name="stepsNumber" format="integer" />
<attr name="steps" format="reference" />
<attr name="typeface" format="reference" />
</declare-styleable>
</resources>

0 comments on commit 54ffeba

Please sign in to comment.