Skip to content

Commit 3619529

Browse files
Piotr Zawadzkizawadz88
authored andcommitted
- fixed "Failed to find style 'ms_stepperStyle' in current theme" error when rendering StepperLayout in Android Studio preview (issue #60)
- fixed rendering of internal layouts in Android Studio preview - Added sample data in Edit Mode for StepperLayout
1 parent fc38ce2 commit 3619529

File tree

10 files changed

+54
-19
lines changed

10 files changed

+54
-19
lines changed

material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ public StepperLayout(Context context) {
246246
}
247247

248248
public StepperLayout(Context context, AttributeSet attrs) {
249-
this(context, attrs, R.attr.ms_stepperStyle);
249+
super(context, attrs);
250+
//Fix for issue #60 with AS Preview editor
251+
init(attrs, isInEditMode() ? 0 : R.attr.ms_stepperStyle);
250252
}
251253

252254
public StepperLayout(Context context, AttributeSet attrs, int defStyleAttr) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import android.graphics.drawable.Drawable;
2222
import android.support.annotation.ColorInt;
2323
import android.support.v4.content.ContextCompat;
24-
import android.support.v7.widget.AppCompatImageView;
2524
import android.util.AttributeSet;
2625
import android.view.LayoutInflater;
2726
import android.view.View;
@@ -62,7 +61,7 @@ public class StepTab extends RelativeLayout {
6261

6362
private final ImageView mStepDoneIndicator;
6463

65-
private final AppCompatImageView mStepErrorIndicator;
64+
private final ImageView mStepErrorIndicator;
6665

6766
private int mDividerWidth = StepperLayout.DEFAULT_TAB_DIVIDER_WIDTH;
6867

@@ -90,7 +89,7 @@ public StepTab(Context context, AttributeSet attrs, int defStyleAttr) {
9089

9190
mStepNumber = (TextView) findViewById(R.id.ms_stepNumber);
9291
mStepDoneIndicator = (ImageView) findViewById(R.id.ms_stepDoneIndicator);
93-
mStepErrorIndicator = (AppCompatImageView) findViewById(R.id.ms_stepErrorIndicator);
92+
mStepErrorIndicator = (ImageView) findViewById(R.id.ms_stepErrorIndicator);
9493
mStepDivider = findViewById(R.id.ms_stepDivider);
9594
mStepTitle = ((TextView) findViewById(R.id.ms_stepTitle));
9695

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void onTabClicked(int position) {
7373

7474
private int mDividerWidth = StepperLayout.DEFAULT_TAB_DIVIDER_WIDTH;
7575

76-
private final int mContainerLateralPadding;
76+
private int mContainerLateralPadding;
7777

7878
private HorizontalScrollView mTabsScrollView;
7979

material-stepper/src/main/java/com/stepstone/stepper/type/DotsStepperType.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*/
3030
public class DotsStepperType extends AbstractStepperType {
3131

32+
private static final int EDIT_MODE_DOT_COUNT = 3;
33+
3234
private final DottedProgressBar mDottedProgressBar;
3335

3436
public DotsStepperType(StepperLayout stepperLayout) {
@@ -37,6 +39,11 @@ public DotsStepperType(StepperLayout stepperLayout) {
3739

3840
mDottedProgressBar.setSelectedColor(getSelectedColor());
3941
mDottedProgressBar.setUnselectedColor(getUnselectedColor());
42+
43+
if (stepperLayout.isInEditMode()) {
44+
mDottedProgressBar.setDotCount(EDIT_MODE_DOT_COUNT);
45+
mDottedProgressBar.setVisibility(View.VISIBLE);
46+
}
4047
}
4148

4249
/**

material-stepper/src/main/java/com/stepstone/stepper/type/TabsStepperType.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@
2626
import com.stepstone.stepper.viewmodel.StepViewModel;
2727

2828
import java.util.ArrayList;
29+
import java.util.Arrays;
2930
import java.util.List;
3031

3132
/**
3233
* Stepper type which displays horizontal stepper with tabs.
3334
*/
3435
public class TabsStepperType extends AbstractStepperType {
3536

37+
private static final List<CharSequence> EDIT_MODE_STEP_TITLES = Arrays.<CharSequence>asList("Step 1", "Step 2");
38+
3639
private final TabsContainer mTabsContainer;
3740

3841
public TabsStepperType(StepperLayout stepperLayout) {
@@ -44,6 +47,11 @@ public TabsStepperType(StepperLayout stepperLayout) {
4447
mTabsContainer.setErrorColor(stepperLayout.getErrorColor());
4548
mTabsContainer.setDividerWidth(stepperLayout.getTabStepDividerWidth());
4649
mTabsContainer.setListener(stepperLayout);
50+
51+
if (stepperLayout.isInEditMode()) {
52+
mTabsContainer.setSteps(EDIT_MODE_STEP_TITLES);
53+
mTabsContainer.setVisibility(View.VISIBLE);
54+
}
4755
}
4856

4957
/**

material-stepper/src/main/res/layout/ms_step_tab.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<merge xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:orientation="vertical">
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:orientation="vertical"
5+
tools:layout_height="wrap_content"
6+
tools:layout_width="wrap_content"
7+
tools:parentTag="RelativeLayout"
8+
tools:theme="@style/MSDefaultStepperLayoutTheme">
49

510
<FrameLayout
611
android:id="@+id/ms_iconContainer"
@@ -12,12 +17,12 @@
1217
android:id="@+id/ms_stepNumber"
1318
style="?attr/ms_stepTabNumberStyle" />
1419

15-
<android.support.v7.widget.AppCompatImageView
20+
<ImageView
1621
android:id="@+id/ms_stepDoneIndicator"
1722
style="?attr/ms_stepTabDoneIndicatorStyle"
1823
android:visibility="gone" />
1924

20-
<android.support.v7.widget.AppCompatImageView
25+
<ImageView
2126
android:id="@+id/ms_stepErrorIndicator"
2227
style="?attr/ms_stepTabErrorIndicatorStyle"
2328
android:visibility="gone" />
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<com.stepstone.stepper.internal.StepTab style="?attr/ms_stepTabContainerStyle" />
2+
<!--suppress XmlUnusedNamespaceDeclaration -->
3+
<com.stepstone.stepper.internal.StepTab xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
style="?attr/ms_stepTabContainerStyle"
6+
tools:layout_height="@dimen/ms_step_tab_height"
7+
tools:layout_width="wrap_content"
8+
tools:theme="@style/MSDefaultStepperLayoutTheme" />

material-stepper/src/main/res/layout/ms_stepper_layout.xml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<merge xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4-
android:orientation="vertical">
4+
android:orientation="vertical"
5+
tools:layout_height="match_parent"
6+
tools:layout_width="match_parent"
7+
tools:parentTag="LinearLayout"
8+
tools:theme="@style/MSDefaultStepperLayoutTheme">
59

610
<com.stepstone.stepper.internal.TabsContainer
711
android:id="@+id/ms_stepTabsContainer"
@@ -27,6 +31,7 @@
2731
android:layout_centerVertical="true"
2832
android:drawableLeft="@drawable/ic_chevron_start"
2933
android:drawableStart="@drawable/ic_chevron_start"
34+
tools:drawableTint="@color/ms_material_grey_400"
3035
tools:text="@string/ms_back"
3136
tools:textColor="@color/ms_bottomNavigationButtonTextColor" />
3237

@@ -46,8 +51,8 @@
4651
android:id="@+id/ms_stepProgressBar"
4752
style="?attr/ms_colorableProgressBarStyle"
4853
android:indeterminate="false"
49-
android:progress="1"
5054
android:visibility="gone"
55+
tools:progress="33"
5156
tools:visibility="visible" />
5257

5358
</FrameLayout>
@@ -60,9 +65,10 @@
6065
android:layout_centerVertical="true"
6166
tools:drawableEnd="@drawable/ic_chevron_end"
6267
tools:drawableRight="@drawable/ic_chevron_end"
68+
tools:drawableTint="@color/ms_material_grey_400"
6369
tools:text="@string/ms_next"
6470
tools:textColor="@color/ms_bottomNavigationButtonTextColor"
65-
tools:visibility="gone" />
71+
tools:visibility="visible" />
6672

6773
<com.stepstone.stepper.internal.RightNavigationButton
6874
android:id="@+id/ms_stepCompleteButton"
@@ -73,8 +79,7 @@
7379
android:alpha="0"
7480
android:visibility="gone"
7581
tools:text="@string/ms_complete"
76-
tools:textColor="@color/ms_bottomNavigationButtonTextColor"
77-
tools:visibility="visible" />
82+
tools:textColor="@color/ms_bottomNavigationButtonTextColor" />
7883

7984
</RelativeLayout>
8085

material-stepper/src/main/res/layout/ms_tabs_container.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<merge xmlns:android="http://schemas.android.com/apk/res/android">
2+
<merge xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
tools:layout_height="wrap_content"
5+
tools:layout_width="match_parent"
6+
tools:parentTag="FrameLayout"
7+
tools:theme="@style/MSDefaultStepperLayoutTheme">
38

49
<HorizontalScrollView
510
android:id="@+id/ms_stepTabsScrollView"

material-stepper/src/main/res/values/attrs.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ limitations under the License.
9191
<declare-styleable name="RightNavigationButton">
9292
<attr name="state_verification_failed" format="boolean" />
9393
</declare-styleable>
94-
95-
<declare-styleable name="Theme">
96-
<attr name="ms_stepperStyle" format="reference" />
97-
</declare-styleable>
94+
95+
<attr name="ms_stepperStyle" format="reference" />
9896

9997
<declare-styleable name="StepperLayoutTheme">
10098

0 commit comments

Comments
 (0)