aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Epstein <depstein@google.com>2020-09-02 16:26:40 -0700
committerDanny Epstein <depstein@google.com>2020-09-02 21:49:59 -0700
commit7e62bff8188978f3353f34a8055ac8e226c6c145 (patch)
tree5459b91a8da23eb4672b625468d62df815b3040a
parentc1aae2bda8ef4c2693ce37cd65d44783391e3e10 (diff)
downloadtests-7e62bff8188978f3353f34a8055ac8e226c6c145.tar.gz
Add a WebView to the reference app
Add another fragment to the RotaryPlayground reference app for testing rotary navigation into, out of, and within WebViews. The WebView's content is chosen to include sections without any focusable elements. Includes a button to toggle the visibility of two buttons in the same focus area with the WebView. This enables testing: - nudging into a focus area with only a WebView without any visible focusable elements - rotating into a WebView without any visible focusable elements. Bug: 159936127 Test: manual Change-Id: I1273e32eec49ad0983f8875c4ad95938c7e50211
-rw-r--r--RotaryPlayground/res/layout/rotary_menu.xml7
-rw-r--r--RotaryPlayground/res/layout/rotary_web_view.xml67
-rw-r--r--RotaryPlayground/res/raw/web_view_html.xml130
-rw-r--r--RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java32
-rw-r--r--RotaryPlayground/src/com/android/car/rotaryplayground/WebViewFragment.java69
5 files changed, 295 insertions, 10 deletions
diff --git a/RotaryPlayground/res/layout/rotary_menu.xml b/RotaryPlayground/res/layout/rotary_menu.xml
index 38a0b8d..452fdc1 100644
--- a/RotaryPlayground/res/layout/rotary_menu.xml
+++ b/RotaryPlayground/res/layout/rotary_menu.xml
@@ -62,4 +62,11 @@
android:layout_weight="1"
android:text="Scroll"
style="@style/tab" />
+ <Button
+ android:id="@+id/web_view"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:text="WebView"
+ style="@style/tab" />
</com.android.car.ui.FocusArea>
diff --git a/RotaryPlayground/res/layout/rotary_web_view.xml b/RotaryPlayground/res/layout/rotary_web_view.xml
new file mode 100644
index 0000000..7995dc6
--- /dev/null
+++ b/RotaryPlayground/res/layout/rotary_web_view.xml
@@ -0,0 +1,67 @@
+<?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.
+ -->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <com.android.car.ui.FocusArea
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <Button
+ android:id="@+id/toggle_buttons"
+ android:layout_width="match_parent"
+ android:layout_height="50dp"
+ android:text="Toggle Buttons"/>
+
+ </com.android.car.ui.FocusArea>
+
+ <com.android.car.ui.FocusArea
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:orientation="vertical">
+
+ <Button
+ android:id="@+id/top_button"
+ android:layout_width="match_parent"
+ android:layout_height="50dp"
+ android:onClick="onRotaryButtonClick"
+ android:tag="test_button"
+ android:text="Top Button"
+ android:visibility="gone" />
+
+ <WebView
+ android:id="@+id/web_view"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1" />
+
+ <Button
+ android:id="@+id/bottom_button"
+ android:layout_width="match_parent"
+ android:layout_height="50dp"
+ android:onClick="onRotaryButtonClick"
+ android:tag="test_button"
+ android:text="Bottom Button"
+ android:visibility="gone" />
+
+ </com.android.car.ui.FocusArea>
+
+</LinearLayout> \ No newline at end of file
diff --git a/RotaryPlayground/res/raw/web_view_html.xml b/RotaryPlayground/res/raw/web_view_html.xml
new file mode 100644
index 0000000..d6e128a
--- /dev/null
+++ b/RotaryPlayground/res/raw/web_view_html.xml
@@ -0,0 +1,130 @@
+<!--
+ ~ 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.
+ -->
+
+<html>
+ <head>
+ <title>Sample Web Page</title>
+ </head>
+
+ <body>
+
+ <h1>1. Lists</h1>
+ <ol>
+ <li><b>First</b></li>
+ <li><i>Second</i></li>
+ <li>Third</li>
+ <li>Fourth</li>
+ <li>Fifth</li>
+ </ol>
+ <ul>
+ <li><b>1st</b></li>
+ <li><i>2nd</i></li>
+ <li>3rd</li>
+ <li>4th</li>
+ <li>5th</li>
+ </ul>
+
+ <h1>2. Text</h1>
+ <p>Paragraph</p>
+ <p>Another paragraph</p>
+
+ <h1>3. Links</h1>
+ <a href="https://en.wikipedia.org/wiki/Breakout_(video_game)">Breakout</a>
+ <br/>
+ <a href="https://en.wikipedia.org/wiki/Pong">Pong</a>
+ <br/>
+ <a href="https://en.wikipedia.org/wiki/Space_Invaders">Space Invaders</a>
+ <br/>
+ <a href="https://en.wikipedia.org/wiki/Lunar_Lander_(1979_video_game)">Lunar Lander</a>
+ <a href="https://en.wikipedia.org/wiki/Asteroids_(video_game)">Asteroids</a>
+ <br/>
+ <a href="https://en.wikipedia.org/wiki/Battlezone_(1980_video_game)">Battlezone</a>
+ <a href="https://en.wikipedia.org/wiki/Centipede_(video_game)">Centipede</a>
+ <a href="https://en.wikipedia.org/wiki/Missile_Command">Missile Command</a>
+
+ <h1>4. Lists</h1>
+ <ol>
+ <li><b>Sixth</b></li>
+ <li><i>Seventh</i></li>
+ <li>Eighth</li>
+ <li>Ninth</li>
+ <li>Tenth</li>
+ </ol>
+ <ul>
+ <li><b>6th</b></li>
+ <li><i>7th</i></li>
+ <li>8th</li>
+ <li>9th</li>
+ <li>10th</li>
+ </ul>
+
+ <h1>5. More Lists</h1>
+ <ol>
+ <li><b>Eleventh</b></li>
+ <li><i>Twelfth</i></li>
+ <li>Thirteenth</li>
+ <li>Fourteenth</li>
+ <li>Fifteenth</li>
+ </ol>
+ <ul>
+ <li><b>11th</b></li>
+ <li><i>12th</i></li>
+ <li>13th</li>
+ <li>14th</li>
+ <li>15th</li>
+ </ul>
+
+ <h1>6. More Links</h1>
+ <a href="https://en.wikipedia.org/wiki/Defender_(1981_video_game)">Defender</a>
+ <a href="https://en.wikipedia.org/wiki/Donkey_Kong_(video_game)">Donkey Kong</a>
+ <a href="https://en.wikipedia.org/wiki/Tempest_(video_game)">Tempest</a>
+ <a href="https://en.wikipedia.org/wiki/Frogger">Frogger</a>
+ <a href="https://en.wikipedia.org/wiki/Qix">Qix</a>
+
+ <h1>7. Lists</h1>
+ <ol>
+ <li><b>Sixteenth</b></li>
+ <li><i>Seventeenth</i></li>
+ <li>Eighteenth</li>
+ <li>Nineteenth</li>
+ <li>Twentieth</li>
+ </ol>
+ <ul>
+ <li><b>16th</b></li>
+ <li><i>17th</i></li>
+ <li>18th</li>
+ <li>19th</li>
+ <li>20th</li>
+ </ul>
+
+ <h1>8. More Lists</h1>
+ <ol>
+ <li><b>Twenty-first</b></li>
+ <li><i>Twenty-second</i></li>
+ <li>Twenty-third</li>
+ <li>Twenty-fourth</li>
+ <li>Twenty-fifth</li>
+ </ol>
+ <ul>
+ <li><b>21st</b></li>
+ <li><i>22nd</i></li>
+ <li>23rd</li>
+ <li>24th</li>
+ <li>25th</li>
+ </ul>
+
+ </body>
+</html>
diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java
index fd3baa8..048686e 100644
--- a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java
+++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java
@@ -37,6 +37,7 @@ public class RotaryMenu extends Fragment {
private Fragment mSysUiDirectManipulation = null;
private Fragment mNotificationFragment = null;
private Fragment mScrollFragment = null;
+ private Fragment mWebViewFragment = null;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@@ -56,18 +57,16 @@ public class RotaryMenu extends Fragment {
});
Button directManipulationButton = view.findViewById(R.id.direct_manipulation);
- directManipulationButton.setOnClickListener(
- (v -> {
- selectTab(v);
- showDirectManipulationExamples();
- }));
+ directManipulationButton.setOnClickListener(v -> {
+ selectTab(v);
+ showDirectManipulationExamples();
+ });
Button sysUiDirectManipulationButton = view.findViewById(R.id.sys_ui_direct_manipulation);
- sysUiDirectManipulationButton.setOnClickListener(
- (v -> {
- selectTab(v);
- showSysUiDirectManipulationExamples();
- }));
+ sysUiDirectManipulationButton.setOnClickListener(v -> {
+ selectTab(v);
+ showSysUiDirectManipulationExamples();
+ });
Button notificationButton = view.findViewById(R.id.notification);
notificationButton.setOnClickListener(v -> {
@@ -81,6 +80,12 @@ public class RotaryMenu extends Fragment {
showScrollFragment();
});
+ Button webViewButton = view.findViewById(R.id.web_view);
+ webViewButton.setOnClickListener(v -> {
+ selectTab(v);
+ showWebViewFragment();
+ });
+
return view;
}
@@ -136,6 +141,13 @@ public class RotaryMenu extends Fragment {
showFragment(mScrollFragment);
}
+ private void showWebViewFragment() {
+ if (mWebViewFragment == null) {
+ mWebViewFragment = new WebViewFragment();
+ }
+ showFragment(mWebViewFragment);
+ }
+
private void showFragment(Fragment fragment) {
getFragmentManager().beginTransaction()
.replace(R.id.rotary_content, fragment)
diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/WebViewFragment.java b/RotaryPlayground/src/com/android/car/rotaryplayground/WebViewFragment.java
new file mode 100644
index 0000000..033b6a8
--- /dev/null
+++ b/RotaryPlayground/src/com/android/car/rotaryplayground/WebViewFragment.java
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+package com.android.car.rotaryplayground;
+
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.util.Base64;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.webkit.WebView;
+import android.widget.Button;
+import android.widget.CheckBox;
+
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/** Fragment to demo a layout with a {@link WebView}. */
+public class WebViewFragment extends Fragment {
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
+ @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.rotary_web_view, container, false);
+ Button toggleButtonsButton = view.findViewById(R.id.toggle_buttons);
+ Button topButton = view.findViewById(R.id.top_button);
+ WebView webView = view.findViewById(R.id.web_view);
+ Button bottomButton = view.findViewById(R.id.bottom_button);
+
+ toggleButtonsButton.setOnClickListener(v -> {
+ int buttonVisibility =
+ topButton.getVisibility() == View.GONE ? View.VISIBLE : View.GONE;
+ topButton.setVisibility(buttonVisibility);
+ bottomButton.setVisibility(buttonVisibility);
+ });
+
+ Resources res = getResources();
+ InputStream inputStream = res.openRawResource(R.raw.web_view_html);
+ byte[] byteArray = new byte[0];
+ try {
+ byteArray = new byte[inputStream.available()];
+ inputStream.read(byteArray);
+ } catch (IOException e) {
+ Log.w("WebViewFragment", "Can't read HTML");
+ }
+ String webViewHtml = new String(byteArray);
+ String encodedHtml = Base64.encodeToString(webViewHtml.getBytes(), Base64.NO_PADDING);
+ webView.loadData(encodedHtml, "text/html", "base64");
+ return view;
+ }
+}