Skip to content

Commit e6f4b69

Browse files
Piotr Zawadzkizawadz88
authored andcommitted
Added an example of how to use custom fonts with StepperLayout
1 parent 3d07fd4 commit e6f4b69

File tree

14 files changed

+39
-85
lines changed

14 files changed

+39
-85
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ For an example of how to use it with views please see the sample app.
317317
Basic styling can be done by choosing the active and inactive step colors.
318318
There are some additional properties which can be changed directly from StepperLayout's attributes e.g. the background of bottom navigation buttons (see <a href="#stepperlayout-attributes">StepperLayout attributes</a>)
319319
For advanced styling you can use `ms_stepperLayoutTheme` StepperLayout's attribute and provide your custom style to be used.
320-
See 'Custom StepperLayout theme - progress bar' and 'Custom StepperLayout theme - Tabs dark' in the sample app for an example.
320+
See 'Custom StepperLayout theme' in the sample app for an example.
321321

322322
### Advanced usage
323323
For other examples, e.g. persisting state on rotation, displaying errors, changing whether the user can go to the next step, etc. check out the sample app.

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ configure(allprojects) {
2727

2828
/* Sample only */
2929
butterknifeVersion = "7.0.1"
30+
calligraphyVersion = "2.2.0"
3031
}
3132

3233
}

material-stepper/src/main/java/com/stepstone/stepper/internal/StepTab.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ public class StepTab extends RelativeLayout {
6666

6767
private int mDividerWidth = StepperLayout.DEFAULT_TAB_DIVIDER_WIDTH;
6868

69-
private boolean hasError;
69+
private boolean mHasError;
70+
71+
private Typeface mNormalTypeface;
72+
73+
private Typeface mBoldTypeface;
7074

7175
public StepTab(Context context) {
7276
this(context, null);
@@ -91,6 +95,10 @@ public StepTab(Context context, AttributeSet attrs, int defStyleAttr) {
9195
mStepTitle = ((TextView) findViewById(R.id.ms_stepTitle));
9296

9397
mTitleColor = mStepTitle.getCurrentTextColor();
98+
99+
Typeface typeface = mStepTitle.getTypeface();
100+
mNormalTypeface = Typeface.create(typeface, Typeface.NORMAL);
101+
mBoldTypeface = Typeface.create(typeface, Typeface.BOLD);
94102
}
95103

96104
/**
@@ -111,7 +119,7 @@ public void toggleDividerVisibility(boolean show) {
111119
*/
112120
public void updateState(final boolean done, final boolean showErrorOnBack, final boolean current) {
113121
//if this tab has errors and the user decide not to clear when going backwards, simply ignore the update
114-
if (this.hasError && showErrorOnBack) {
122+
if (this.mHasError && showErrorOnBack) {
115123
return;
116124
}
117125

@@ -120,10 +128,10 @@ public void updateState(final boolean done, final boolean showErrorOnBack, final
120128
mStepErrorIndicator.setVisibility(GONE);
121129
colorViewBackground(done ? mStepDoneIndicator : mStepNumber, done || current);
122130

123-
this.hasError = false;
131+
this.mHasError = false;
124132

125133
mStepTitle.setTextColor(mTitleColor);
126-
mStepTitle.setTypeface(current ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
134+
mStepTitle.setTypeface(current ? mBoldTypeface : mNormalTypeface);
127135
mStepTitle.setAlpha(done || current ? OPAQUE_ALPHA : INACTIVE_STEP_TITLE_ALPHA);
128136
}
129137

@@ -148,7 +156,7 @@ public void updateErrorState(boolean isLastStep, boolean hasError) {
148156
mStepTitle.setTextColor(mTitleColor);
149157
}
150158

151-
this.hasError = hasError;
159+
this.mHasError = hasError;
152160
}
153161

154162
/**

sample/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ dependencies {
2626
compile project(':material-stepper')
2727
compile ("com.android.support:appcompat-v7:$androidSupportLibraryVersion")
2828
compile ("com.jakewharton:butterknife:$butterknifeVersion")
29+
compile ("uk.co.chrisjenx:calligraphy:$calligraphyVersion")
2930
}

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@
3434
<activity android:name=".ReturnButtonActivity" />
3535
<activity android:name=".NoFragmentsActivity" />
3636
<activity
37-
android:name=".CustomStepperLayoutThemeProgressBarActivity"
38-
android:theme="@style/AppTheme.CustomStepperLayoutThemeProgressBarSample" />
39-
<activity
40-
android:name=".CustomStepperLayoutThemeTabsActivity"
37+
android:name=".CustomStepperLayoutThemeActivity"
4138
android:theme="@style/AppThemeDark" />
4239
</application>
4340

75 KB
Binary file not shown.
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@
1616

1717
package com.stepstone.stepper.sample;
1818

19-
public class CustomStepperLayoutThemeProgressBarActivity extends AbstractStepperActivity {
19+
import android.content.Context;
20+
21+
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
22+
23+
public class CustomStepperLayoutThemeActivity extends AbstractStepperActivity {
2024

2125
@Override
2226
protected int getLayoutResId() {
23-
return R.layout.activity_custom_stepper_layout_theme_progress_bar;
27+
return R.layout.activity_custom_stepper_layout_theme;
28+
}
29+
30+
@Override
31+
protected void attachBaseContext(Context newBase) {
32+
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
2433
}
2534

2635
}

sample/src/main/java/com/stepstone/stepper/sample/CustomStepperLayoutThemeTabsActivity.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

sample/src/main/java/com/stepstone/stepper/sample/MainActivity.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,9 @@ public void onNoFrag(View view){
113113
startActivity(new Intent(this, NoFragmentsActivity.class));
114114
}
115115

116-
@OnClick(R.id.customStepperLayoutThemeWithProgressBar)
117-
public void onCustomStepperLayoutThemeWithProgressBar(View view){
118-
startActivity(new Intent(this, CustomStepperLayoutThemeProgressBarActivity.class));
119-
}
120-
121-
@OnClick(R.id.customStepperLayoutThemeWithTabs)
116+
@OnClick(R.id.customStepperLayoutTheme)
122117
public void onCustomStepperLayoutThemeWithTabs(View view){
123-
startActivity(new Intent(this, CustomStepperLayoutThemeTabsActivity.class));
118+
startActivity(new Intent(this, CustomStepperLayoutThemeActivity.class));
124119
}
125120

126121
}
File renamed without changes.

0 commit comments

Comments
 (0)