diff options
author | Danny Epstein <depstein@google.com> | 2020-09-04 03:58:45 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-09-04 03:58:45 +0000 |
commit | 62f7efaaf88420486373f48001726ae1344465f5 (patch) | |
tree | 329b05418a0f59137848de93f54c0c25df959831 /RotaryPlayground | |
parent | 133ba730aab3d6dc65e2a758c75199661e55662f (diff) | |
parent | 7e62bff8188978f3353f34a8055ac8e226c6c145 (diff) | |
download | tests-62f7efaaf88420486373f48001726ae1344465f5.tar.gz |
Merge "Add a WebView to the reference app" into rvc-qpr-dev
Diffstat (limited to 'RotaryPlayground')
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; + } +} |