Skip to content

Commit 55cf558

Browse files
Piotr Zawadzkizawadz88
authored andcommitted
Hard-coded StepperLayout's orientation to VERTICAL (issue #124)
1 parent dfe6fbf commit 55cf558

22 files changed

+47
-20
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import android.support.v4.content.res.ResourcesCompat;
3535
import android.support.v4.view.ViewPager;
3636
import android.support.v7.view.ContextThemeWrapper;
37+
import android.support.v7.widget.LinearLayoutCompat;
3738
import android.util.AttributeSet;
3839
import android.view.LayoutInflater;
3940
import android.view.MotionEvent;
@@ -285,6 +286,12 @@ public StepperLayout(Context context, AttributeSet attrs, int defStyleAttr) {
285286
init(attrs, defStyleAttr);
286287
}
287288

289+
@Override
290+
public final void setOrientation(@LinearLayoutCompat.OrientationMode int orientation) {
291+
//only vertical orientation is supported
292+
super.setOrientation(VERTICAL);
293+
}
294+
288295
public void setListener(@NonNull StepperListener listener) {
289296
this.mListener = listener;
290297
}
@@ -591,6 +598,9 @@ private void init(AttributeSet attrs, @AttrRes int defStyleAttr) {
591598
contextThemeWrapper.setTheme(mStepperLayoutTheme);
592599

593600
LayoutInflater.from(contextThemeWrapper).inflate(R.layout.ms_stepper_layout, this, true);
601+
602+
setOrientation(VERTICAL);
603+
594604
bindViews();
595605

596606
mPager.setOnTouchListener(new View.OnTouchListener() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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+
tools:orientation="vertical"
55
tools:layout_height="match_parent"
66
tools:layout_width="match_parent"
77
tools:parentTag="LinearLayout"

material-stepper/src/test/java/com/stepstone/stepper/StepperLayoutSanityTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.support.v4.app.FragmentActivity;
88
import android.support.v4.app.FragmentManager;
99
import android.util.AttributeSet;
10+
import android.widget.LinearLayout;
1011

1112
import com.stepstone.stepper.adapter.AbstractFragmentStepAdapter;
1213
import com.stepstone.stepper.test.runner.StepperRobolectricTestRunner;
@@ -18,6 +19,7 @@
1819
import org.robolectric.Robolectric;
1920

2021
import static com.stepstone.stepper.test.assertion.StepperLayoutAssert.assertThat;
22+
import static org.junit.Assert.assertEquals;
2123
import static org.mockito.Mockito.mock;
2224

2325

@@ -31,6 +33,8 @@ public class StepperLayoutSanityTest {
3133
private static final String TYPE_DOTS = "dots";
3234
private static final String TYPE_TABS = "tabs";
3335

36+
private static final String ORIENTATION_HORIZONTAL = "horizontal";
37+
3438
FragmentActivity activity;
3539

3640
@Before
@@ -131,6 +135,38 @@ public void should_show_tabs_when_adapter_is_set_for_tabs_type() {
131135
.hasDottedProgressBarHidden();
132136
}
133137

138+
@Test
139+
public void should_ignore_horizontal_orientation_if_provided_from_attributes() {
140+
//given
141+
AttributeSet attributeSet = Robolectric.buildAttributeSet()
142+
.addAttribute(R.attr.ms_stepperType, TYPE_DOTS)
143+
.addAttribute(android.R.attr.orientation, ORIENTATION_HORIZONTAL)
144+
.build();
145+
146+
//when
147+
StepperLayout stepperLayout = new StepperLayout(activity, attributeSet);
148+
149+
//then
150+
assertVerticalOrientationUsed(stepperLayout);
151+
}
152+
153+
@Test
154+
public void should_ignore_horizontal_orientation_if_provided_programmatically() {
155+
//given
156+
AttributeSet attributeSet = createAttributeSetWithStepperType(TYPE_DOTS);
157+
StepperLayout stepperLayout = new StepperLayout(activity, attributeSet);
158+
159+
//when
160+
stepperLayout.setOrientation(LinearLayout.HORIZONTAL);
161+
162+
//then
163+
assertVerticalOrientationUsed(stepperLayout);
164+
}
165+
166+
private void assertVerticalOrientationUsed(StepperLayout stepperLayout) {
167+
assertEquals("Invalid orientation", stepperLayout.getOrientation(), LinearLayout.VERTICAL);
168+
}
169+
134170
private void whenAdapterIsSet(StepperLayout stepperLayout) {
135171
stepperLayout.setAdapter(new DummyStepAdapter(activity.getSupportFragmentManager(), activity));
136172
}

sample/src/main/res/layout-land/activity_combination.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
android:id="@+id/stepperLayout"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:orientation="vertical"
87
app:ms_stepperType="tabs" />

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
android:id="@+id/stepperLayout"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:orientation="vertical"
87
app:ms_stepperType="dots" />

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
android:id="@+id/stepperLayout"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:orientation="vertical"
87
app:ms_showBackButtonOnFirstStep="true"
98
app:ms_stepperType="dots"/>
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:id="@+id/stepperLayout"
4-
android:orientation="vertical"
54
android:layout_width="match_parent"
65
android:layout_height="match_parent" />

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
android:id="@+id/stepperLayout"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:orientation="vertical"
87
app:ms_stepperType="dots"/>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
android:id="@+id/stepperLayout"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:orientation="vertical"
87
app:ms_stepperType="progress_bar" />

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
android:id="@+id/stepperLayout"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:orientation="vertical"
87
app:ms_stepperType="tabs" />

0 commit comments

Comments
 (0)