diff options
author | Maurice Lam <yukl@google.com> | 2018-02-20 12:55:09 -0800 |
---|---|---|
committer | Maurice Lam <yukl@google.com> | 2018-02-20 12:55:09 -0800 |
commit | b3617935a276aab4c72c11da340a1096d96225d7 (patch) | |
tree | 0263e4bd9582092cf26cc5d8561971a3470967d6 /library | |
parent | 53c263400cd8f58044490994337c27198f03132a (diff) | |
download | setupwizard-b3617935a276aab4c72c11da340a1096d96225d7.tar.gz |
Set CheckableLinearLayout to focusable
So that the layout can be expanded using keyboard navigation.
Test: ./gradlew test
Bug: 72835973
Change-Id: I4fb22e0579c73cb423d52354a5887b13cc1ea77d
Diffstat (limited to 'library')
-rw-r--r-- | library/gingerbread/test/robotest/src/com/android/setupwizardlib/items/ExpandableSwitchItemTest.java | 69 | ||||
-rw-r--r-- | library/main/src/com/android/setupwizardlib/view/CheckableLinearLayout.java | 4 |
2 files changed, 23 insertions, 50 deletions
diff --git a/library/gingerbread/test/robotest/src/com/android/setupwizardlib/items/ExpandableSwitchItemTest.java b/library/gingerbread/test/robotest/src/com/android/setupwizardlib/items/ExpandableSwitchItemTest.java index 3020ed3..6192061 100644 --- a/library/gingerbread/test/robotest/src/com/android/setupwizardlib/items/ExpandableSwitchItemTest.java +++ b/library/gingerbread/test/robotest/src/com/android/setupwizardlib/items/ExpandableSwitchItemTest.java @@ -16,32 +16,27 @@ package com.android.setupwizardlib.items; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.not; +import static com.google.common.truth.Truth.assertThat; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.robolectric.RuntimeEnvironment.application; -import android.support.v7.widget.SwitchCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.FrameLayout; -import android.widget.ImageView; import android.widget.TextView; import com.android.setupwizardlib.R; import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; +import com.android.setupwizardlib.view.CheckableLinearLayout; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.annotation.Config; -import java.util.ArrayList; - @RunWith(SuwLibRobolectricTestRunner.class) @Config(sdk = { Config.OLDEST_SDK, Config.NEWEST_SDK }) public class ExpandableSwitchItemTest { @@ -72,6 +67,12 @@ public class ExpandableSwitchItemTest { "TestSummary", mSummaryView.getText()); assertFalse("Expandable switch item itself should not be focusable", view.isFocusable()); + + View switchContent = view.findViewById(R.id.suw_items_expandable_switch_content); + assertThat(switchContent).isInstanceOf(CheckableLinearLayout.class); + assertThat(switchContent.isFocusable()) + .named("expandable content focusable") + .isTrue(); } @Test @@ -133,57 +134,25 @@ public class ExpandableSwitchItemTest { mItem.onBindView(view); final View titleView = view.findViewById(R.id.suw_items_title); - assertThat("state_checked should not be set initially", - toArrayList(titleView.getDrawableState()), - not(hasItem(android.R.attr.state_checked))); + assertThat(titleView.getDrawableState()).asList().named("Drawable state") + .doesNotContain(android.R.attr.state_checked); mItem.setExpanded(true); mItem.onBindView(view); - assertThat("state_checked should not be set initially", - toArrayList(titleView.getDrawableState()), - hasItem(android.R.attr.state_checked)); + assertThat(titleView.getDrawableState()).asList().named("Drawable state") + .contains(android.R.attr.state_checked); mItem.setExpanded(false); mItem.onBindView(view); - assertThat("state_checked should not be set initially", - toArrayList(titleView.getDrawableState()), - not(hasItem(android.R.attr.state_checked))); - } - - private ArrayList<Integer> toArrayList(int[] array) { - ArrayList<Integer> arrayList = new ArrayList<>(array.length); - for (int i : array) { - arrayList.add(i); - } - return arrayList; + assertThat(titleView.getDrawableState()).asList().named("Drawable state") + .doesNotContain(android.R.attr.state_checked); } private ViewGroup createLayout() { - ViewGroup root = new FrameLayout(application); - - ViewGroup content = new FrameLayout(application); - content.setId(R.id.suw_items_expandable_switch_content); - root.addView(content); - - TextView titleView = new TextView(application); - titleView.setId(R.id.suw_items_title); - content.addView(titleView); - - mSummaryView = new TextView(application); - mSummaryView.setId(R.id.suw_items_summary); - content.addView(mSummaryView); - - FrameLayout iconContainer = new FrameLayout(application); - iconContainer.setId(R.id.suw_items_icon_container); - content.addView(iconContainer); - - ImageView iconView = new ImageView(application); - iconView.setId(R.id.suw_items_icon); - iconContainer.addView(iconView); - - SwitchCompat switchView = new SwitchCompat(application); - switchView.setId(R.id.suw_items_switch); - root.addView(switchView); + ViewGroup root = + (ViewGroup) LayoutInflater.from(application) + .inflate(R.layout.suw_items_expandable_switch, null); + mSummaryView = root.findViewById(R.id.suw_items_summary); return root; } diff --git a/library/main/src/com/android/setupwizardlib/view/CheckableLinearLayout.java b/library/main/src/com/android/setupwizardlib/view/CheckableLinearLayout.java index 3c678f8..bd0aead 100644 --- a/library/main/src/com/android/setupwizardlib/view/CheckableLinearLayout.java +++ b/library/main/src/com/android/setupwizardlib/view/CheckableLinearLayout.java @@ -58,6 +58,10 @@ public class CheckableLinearLayout extends LinearLayout implements Checkable { super(context, attrs, defStyleAttr, defStyleRes); } + { + setFocusable(true); + } + @Override protected int[] onCreateDrawableState(int extraSpace) { if (mChecked) { |