Skip to content

Commit e6f4b69

Browse files
Piotr Zawadzkizawadz88
Piotr Zawadzki
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

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
}

sample/src/main/res/layout/activity_custom_stepper_layout_theme_tabs.xml

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

sample/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,11 @@
111111
android:layout_width="wrap_content"
112112
android:layout_height="wrap_content"
113113
android:text="@string/no_fragments" />
114-
115-
<Button
116-
android:id="@+id/customStepperLayoutThemeWithProgressBar"
117-
android:layout_width="wrap_content"
118-
android:layout_height="wrap_content"
119-
android:text="@string/custom_stepperlayout_theme_progress_bar" />
120-
121114
<Button
122-
android:id="@+id/customStepperLayoutThemeWithTabs"
115+
android:id="@+id/customStepperLayoutTheme"
123116
android:layout_width="wrap_content"
124117
android:layout_height="wrap_content"
125-
android:text="@string/custom_stepperlayout_theme_tabs" />
118+
android:text="@string/custom_stepperlayout_theme" />
126119

127120
</LinearLayout>
128121
</ScrollView>

sample/src/main/res/values/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
<string name="different_navigation_buttons">Different navigation buttons</string>
1717
<string name="show_back_button">Show Back button on first step</string>
1818
<string name="no_fragments">No Fragment Stepper</string>
19-
<string name="custom_stepperlayout_theme_progress_bar">Custom StepperLayout theme - progress bar</string>
20-
<string name="custom_stepperlayout_theme_tabs">Custom StepperLayout theme - Tabs dark</string>
19+
<string name="custom_stepperlayout_theme">Custom StepperLayout theme</string>
2120

2221
<string name="tab_title">Tab title</string>
2322
<string name="lorem_ipsum">Lorem ipsum dolor sit amet, sale viris intellegam usu eu, persius patrioque sea at. Ne salutandi repudiandae mei, cu mollis accusam mediocrem mea. Altera dolorem praesent at vis. Torquatos philosophia ad quo. Omnis adipiscing has ea, mel no hinc iudico percipit.</string>

sample/src/main/res/values/styles.xml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010
<item name="ms_stepperStyle">@style/DotStepperStyle</item>
1111
</style>
1212

13-
<style name="AppTheme.CustomStepperLayoutThemeProgressBarSample">
14-
<item name="ms_stepperStyle">@style/CustomStepperLayoutThemeProgressBarSample</item>
15-
</style>
16-
1713
<style name="AppThemeDark" parent="Theme.AppCompat">
1814
<item name="colorPrimary">@color/darkColorPrimary</item>
1915
<item name="colorPrimaryDark">@color/darkColorPrimaryDark</item>
2016
<item name="colorAccent">@color/colorAccent</item>
21-
<item name="ms_stepperStyle">@style/CustomStepperLayoutThemeTabsSample</item>
17+
<item name="ms_stepperStyle">@style/CustomStepperLayoutThemeSample</item>
2218
<item name="ms_showErrorState">true</item>
2319
</style>
2420

@@ -33,50 +29,36 @@
3329
<item name="ms_bottomNavigationBackground">?attr/colorAccent</item>
3430
</style>
3531

36-
<style name="CustomStepperLayoutThemeTabsSample">
32+
<style name="CustomStepperLayoutThemeSample">
3733
<item name="ms_stepperType">tabs</item>
3834
<item name="ms_stepperLayoutTheme">@style/DarkCustomStepperLayoutTheme</item>
3935
<item name="ms_activeStepColor">#006867</item>
4036
<item name="ms_inactiveStepColor">#62807f</item>
4137
</style>
4238

43-
<style name="CustomStepperLayoutThemeProgressBarSample">
44-
<item name="ms_stepperType">progress_bar</item>
45-
<item name="ms_stepperLayoutTheme">@style/CustomStepperLayoutTheme</item>
46-
</style>
47-
4839
<style name="DarkCustomStepperLayoutTheme" parent="MSDefaultStepperLayoutTheme">
4940
<item name="ms_bottomNavigationStyle">@style/DarkBottomNavigationStyle</item>
5041
<item name="ms_tabsContainerStyle">@style/DarkStepTabsContainerStyle</item>
5142
<item name="ms_stepTabTitleStyle">@style/DarkStepTabTitleStyle</item>
52-
</style>
53-
54-
<style name="CustomStepperLayoutTheme" parent="MSDefaultStepperLayoutTheme">
55-
<item name="ms_bottomNavigationStyle">@style/CustomBottomNavigationStyle</item>
5643
<item name="ms_backNavigationButtonStyle">@style/CustomBackButtonStyle</item>
5744
<item name="ms_nextNavigationButtonStyle">@style/CustomNextButtonStyle</item>
5845
<item name="ms_completeNavigationButtonStyle">@style/CustomCompleteButtonStyle</item>
59-
<item name="ms_colorableProgressBarStyle">@style/CustomColorableProgressBarStyle</item>
6046
</style>
6147

6248
<style name="CustomBottomNavigationStyle" parent="MSBottomNavigation">
6349
<item name="android:layout_height">40dp</item>
6450
</style>
6551

6652
<style name="CustomBackButtonStyle" parent="MSNavBarButton.Back">
67-
<item name="android:textSize">12sp</item>
53+
<item name="fontPath">fonts/Oswald-Stencbab.ttf</item>
6854
</style>
6955

7056
<style name="CustomNextButtonStyle" parent="MSNavBarButton.Next">
71-
<item name="android:textSize">12sp</item>
57+
<item name="fontPath">fonts/Oswald-Stencbab.ttf</item>
7258
</style>
7359

7460
<style name="CustomCompleteButtonStyle" parent="MSNavBarButton.Complete">
75-
<item name="android:textSize">12sp</item>
76-
</style>
77-
78-
<style name="CustomColorableProgressBarStyle" parent="MSColorableProgressBar">
79-
<item name="android:layout_height">6dp</item>
61+
<item name="fontPath">fonts/Oswald-Stencbab.ttf</item>
8062
</style>
8163

8264
<style name="DarkBottomNavigationStyle" parent="MSBottomNavigation">
@@ -89,6 +71,7 @@
8971

9072
<style name="DarkStepTabTitleStyle" parent="MSStepTabTitle">
9173
<item name="android:textColor">@color/ms_white</item>
74+
<item name="fontPath">fonts/Oswald-Stencbab.ttf</item>
9275
</style>
9376

9477
</resources>

0 commit comments

Comments
 (0)