aboutsummaryrefslogtreecommitdiff
path: root/RotaryPlayground
diff options
context:
space:
mode:
authorDanny Epstein <depstein@google.com>2020-07-18 12:17:50 -0700
committerDanny Epstein <depstein@google.com>2020-07-18 12:17:50 -0700
commitfcf79e37ad837cdf2c99bf785d0154e66a302e7f (patch)
treecffcb4541e95c970bb801c0e38fd5d84ec258fc9 /RotaryPlayground
parent41af77ce3fcd704f6738f8edf9ffc1de3a7be4d4 (diff)
downloadtests-fcf79e37ad837cdf2c99bf785d0154e66a302e7f.tar.gz
Improve tabs in reference app.
For now, don't switch tabs on focus. Select the button for the active tab and visually indicate the selected button. Bug: 157241844 Test: manual Change-Id: I3f99b9a9a2a8c48d33e7852a75b4ecf3483280ba
Diffstat (limited to 'RotaryPlayground')
-rw-r--r--RotaryPlayground/res/drawable/selected_tab.xml25
-rw-r--r--RotaryPlayground/res/drawable/tab.xml20
-rw-r--r--RotaryPlayground/res/layout/rotary_menu.xml18
-rw-r--r--RotaryPlayground/res/values/colors.xml1
-rw-r--r--RotaryPlayground/res/values/styles.xml21
-rw-r--r--RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java108
6 files changed, 129 insertions, 64 deletions
diff --git a/RotaryPlayground/res/drawable/selected_tab.xml b/RotaryPlayground/res/drawable/selected_tab.xml
new file mode 100644
index 0000000..9b694f7
--- /dev/null
+++ b/RotaryPlayground/res/drawable/selected_tab.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2020 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <gradient
+ android:angle="0"
+ android:startColor="@color/tab_color"
+ android:centerColor="@android:color/transparent"
+ android:centerX="0.08" />
+</shape>
diff --git a/RotaryPlayground/res/drawable/tab.xml b/RotaryPlayground/res/drawable/tab.xml
new file mode 100644
index 0000000..b943ad5
--- /dev/null
+++ b/RotaryPlayground/res/drawable/tab.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2020 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_selected="true" android:drawable="@drawable/selected_tab" />
+</selector>
diff --git a/RotaryPlayground/res/layout/rotary_menu.xml b/RotaryPlayground/res/layout/rotary_menu.xml
index df3ec19..38a0b8d 100644
--- a/RotaryPlayground/res/layout/rotary_menu.xml
+++ b/RotaryPlayground/res/layout/rotary_menu.xml
@@ -25,35 +25,41 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
- android:text="Cards" />
+ android:text="Cards"
+ style="@style/tab" />
<Button
android:id="@+id/direct_manipulation"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
- android:text="Direct Manipulation" />
+ android:text="Direct Manipulation"
+ style="@style/tab" />
<Button
android:id="@+id/sys_ui_direct_manipulation"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
- android:text="Sys UI Manipulation" />
+ android:text="Sys UI Manipulation"
+ style="@style/tab" />
<Button
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
- android:text="Grid" />
+ android:text="Grid"
+ style="@style/tab" />
<Button
android:id="@+id/notification"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
- android:text="Notification" />
+ android:text="Notification"
+ style="@style/tab" />
<Button
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
- android:text="Scroll" />
+ android:text="Scroll"
+ style="@style/tab" />
</com.android.car.ui.FocusArea>
diff --git a/RotaryPlayground/res/values/colors.xml b/RotaryPlayground/res/values/colors.xml
index 87480a0..ca3e4c6 100644
--- a/RotaryPlayground/res/values/colors.xml
+++ b/RotaryPlayground/res/values/colors.xml
@@ -21,4 +21,5 @@
<color name="button_background_color">#660000</color>
<color name="button_disabled_background_color">#61646b</color>
<color name="scroll_text_background_color">#61646b</color>
+ <color name="tab_color">#808080</color>
</resources> \ No newline at end of file
diff --git a/RotaryPlayground/res/values/styles.xml b/RotaryPlayground/res/values/styles.xml
new file mode 100644
index 0000000..f195f5c
--- /dev/null
+++ b/RotaryPlayground/res/values/styles.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2020 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<resources>
+ <style name="tab" parent="ButtonStyle">
+ <item name="android:background">@drawable/tab</item>
+ </style>
+</resources>
diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java
index c87fe1b..fd3baa8 100644
--- a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java
+++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java
@@ -38,64 +38,68 @@ public class RotaryMenu extends Fragment {
private Fragment mNotificationFragment = null;
private Fragment mScrollFragment = null;
- private Button mCardButton;
- private Button mGridButton;
- private Button mDirectManipulationButton;
- private Button mSysUiDirectManipulationButton;
- private Button mNotificationButton;
- private Button mScrollButton;
-
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.rotary_menu, container, false);
- mCardButton = view.findViewById(R.id.cards);
- mCardButton.setOnFocusChangeListener((v, hasFocus) -> showRotaryCards(hasFocus));
- mCardButton.setOnClickListener(v -> showRotaryCards(/* hasFocus= */ true));
-
- mGridButton = view.findViewById(R.id.grid);
- mGridButton.setOnFocusChangeListener((v, hasFocus) -> showGridExample(hasFocus));
- mGridButton.setOnClickListener(v -> showGridExample(/* hasFocus= */ true));
-
- mDirectManipulationButton = view.findViewById(R.id.direct_manipulation);
- mDirectManipulationButton.setOnFocusChangeListener(
- (v, hasFocus) -> showDirectManipulationExamples(hasFocus));
- mDirectManipulationButton.setOnClickListener(
- (v -> showDirectManipulationExamples(/* hasFocus= */ true)));
-
- mSysUiDirectManipulationButton = view.findViewById(R.id.sys_ui_direct_manipulation);
- mSysUiDirectManipulationButton.setOnFocusChangeListener(
- (v, hasFocus) -> showSysUiDirectManipulationExamples(hasFocus));
- mSysUiDirectManipulationButton.setOnClickListener(
- (v -> showSysUiDirectManipulationExamples(/* hasFocus= */ true)));
-
- mNotificationButton = view.findViewById(R.id.notification);
- mNotificationButton.setOnFocusChangeListener(
- (v, hasFocus) -> showNotificationExample(hasFocus));
- mNotificationButton.setOnClickListener(v -> showNotificationExample(/* hasFocus= */ true));
-
- mScrollButton = view.findViewById(R.id.scroll);
- mScrollButton.setOnFocusChangeListener((v, hasFocus) -> showScrollFragment(hasFocus));
- mScrollButton.setOnClickListener(v -> showScrollFragment(/* hasFocus= */ true));
+ Button cardButton = view.findViewById(R.id.cards);
+ cardButton.setOnClickListener(v -> {
+ selectTab(v);
+ showRotaryCards();
+ });
+
+ Button gridButton = view.findViewById(R.id.grid);
+ gridButton.setOnClickListener(v -> {
+ selectTab(v);
+ showGridExample();
+ });
+
+ Button directManipulationButton = view.findViewById(R.id.direct_manipulation);
+ directManipulationButton.setOnClickListener(
+ (v -> {
+ selectTab(v);
+ showDirectManipulationExamples();
+ }));
+
+ Button sysUiDirectManipulationButton = view.findViewById(R.id.sys_ui_direct_manipulation);
+ sysUiDirectManipulationButton.setOnClickListener(
+ (v -> {
+ selectTab(v);
+ showSysUiDirectManipulationExamples();
+ }));
+
+ Button notificationButton = view.findViewById(R.id.notification);
+ notificationButton.setOnClickListener(v -> {
+ selectTab(v);
+ showNotificationExample();
+ });
+
+ Button scrollButton = view.findViewById(R.id.scroll);
+ scrollButton.setOnClickListener(v -> {
+ selectTab(v);
+ showScrollFragment();
+ });
return view;
}
- private void showRotaryCards(boolean hasFocus) {
- if (!hasFocus) {
- return; // Do nothing if no focus.
+ private void selectTab(View view) {
+ ViewGroup container = (ViewGroup) view.getParent();
+ for (int i = 0; i < container.getChildCount(); i++) {
+ container.getChildAt(i).setSelected(false);
}
+ view.setSelected(true);
+ }
+
+ private void showRotaryCards() {
if (mRotaryCards == null) {
mRotaryCards = new RotaryCards();
}
showFragment(mRotaryCards);
}
- private void showGridExample(boolean hasFocus) {
- if (!hasFocus) {
- return; // do nothing if no focus.
- }
+ private void showGridExample() {
if (mRotaryGrid == null) {
mRotaryGrid = new RotaryGrid();
}
@@ -104,40 +108,28 @@ public class RotaryMenu extends Fragment {
// TODO(agathaman): refactor this and the showRotaryCards above into a
// showFragment(Fragment fragment, boolean hasFocus); method.
- private void showDirectManipulationExamples(boolean hasFocus) {
- if (!hasFocus) {
- return; // Do nothing if no focus.
- }
+ private void showDirectManipulationExamples() {
if (mDirectManipulation == null) {
mDirectManipulation = new RotaryDirectManipulationWidgets();
}
showFragment(mDirectManipulation);
}
- private void showSysUiDirectManipulationExamples(boolean hasFocus) {
- if (!hasFocus) {
- return; // Do nothing if no focus.
- }
+ private void showSysUiDirectManipulationExamples() {
if (mSysUiDirectManipulation == null) {
mSysUiDirectManipulation = new RotarySysUiDirectManipulationWidgets();
}
showFragment(mSysUiDirectManipulation);
}
- private void showNotificationExample(boolean hasFocus) {
- if (!hasFocus) {
- return; // do nothing if no focus.
- }
+ private void showNotificationExample() {
if (mNotificationFragment == null) {
mNotificationFragment = new HeadsUpNotificationFragment();
}
showFragment(mNotificationFragment);
}
- private void showScrollFragment(boolean hasFocus) {
- if (!hasFocus) {
- return; // Do nothing if no focus.
- }
+ private void showScrollFragment() {
if (mScrollFragment == null) {
mScrollFragment = new ScrollFragment();
}