From 6da8058cedfeb1aca38ee901c0d6a0b280c2a18c Mon Sep 17 00:00:00 2001 From: Yabin Huang Date: Wed, 21 Apr 2021 18:06:55 -0700 Subject: Relaunch "Create CarHTMLViewer for car builds" ag/14276507 got reverted because of a build error. The build error was fixed by allowing CarHTMLViewer to be in /system partition. Bug: 185951366 Test: lunch gsi_car_arm64 && make CarHTMLViewer Test: manual test Change-Id: I2c4729ab6352a6b06bdb9969c17ff3ee64ea3331 --- Android.bp | 12 ++++++ AndroidManifest-car.xml | 42 ++++++++++++++++++++ res/layout/main_car.xml | 24 ++++++++++++ .../android/htmlviewer/CarHTMLViewerActivity.java | 45 ++++++++++++++++++++++ src/com/android/htmlviewer/HTMLViewerActivity.java | 6 ++- 5 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 AndroidManifest-car.xml create mode 100644 res/layout/main_car.xml create mode 100644 src/com/android/htmlviewer/CarHTMLViewerActivity.java diff --git a/Android.bp b/Android.bp index 679d50a..c85f4fb 100644 --- a/Android.bp +++ b/Android.bp @@ -17,6 +17,18 @@ license { android_app { name: "HTMLViewer", + manifest: "AndroidManifest.xml", srcs: ["**/*.java"], + exclude_srcs: ["src/com/android/htmlviewer/CarHTMLViewerActivity.java"], + sdk_version: "current", +} + +android_app { + name: "CarHTMLViewer", + manifest: "AndroidManifest-car.xml", + overrides: ["HTMLViewer"], + srcs: ["**/*.java"], + libs: ["android.car-stubs"], + static_libs: ["car-ui-lib"], sdk_version: "current", } diff --git a/AndroidManifest-car.xml b/AndroidManifest-car.xml new file mode 100644 index 0000000..2c737ea --- /dev/null +++ b/AndroidManifest-car.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/layout/main_car.xml b/res/layout/main_car.xml new file mode 100644 index 0000000..1577ec4 --- /dev/null +++ b/res/layout/main_car.xml @@ -0,0 +1,24 @@ + + + + + + + + diff --git a/src/com/android/htmlviewer/CarHTMLViewerActivity.java b/src/com/android/htmlviewer/CarHTMLViewerActivity.java new file mode 100644 index 0000000..de31bff --- /dev/null +++ b/src/com/android/htmlviewer/CarHTMLViewerActivity.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 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.htmlviewer; + +import android.webkit.WebView; + +import com.android.car.ui.core.CarUi; +import com.android.car.ui.toolbar.Toolbar; +import com.android.car.ui.toolbar.ToolbarController; + +/** + * An HTMLViewerActivity used for car builds. + */ +public class CarHTMLViewerActivity extends HTMLViewerActivity { + private ToolbarController mToolbar; + + @Override + protected void setContentView() { + setContentView(R.layout.main_car); + WebView webView = requireViewById(R.id.webview); + webView.setDefaultFocusHighlightEnabled(false); + mToolbar = CarUi.requireToolbar(this); + mToolbar.setState(Toolbar.State.SUBPAGE); + } + + @Override + public void setTitle(CharSequence title) { + super.setTitle(title); + mToolbar.setTitle(title); + } +} diff --git a/src/com/android/htmlviewer/HTMLViewerActivity.java b/src/com/android/htmlviewer/HTMLViewerActivity.java index 1aa1f68..233a87d 100644 --- a/src/com/android/htmlviewer/HTMLViewerActivity.java +++ b/src/com/android/htmlviewer/HTMLViewerActivity.java @@ -55,7 +55,7 @@ public class HTMLViewerActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.main); + setContentView(); mWebView = findViewById(R.id.webview); mLoading = findViewById(R.id.loading); @@ -83,6 +83,10 @@ public class HTMLViewerActivity extends Activity { loadUrl(); } + protected void setContentView() { + setContentView(R.layout.main); + } + private void loadUrl() { if (mIntent.hasExtra(Intent.EXTRA_TITLE)) { setTitle(mIntent.getStringExtra(Intent.EXTRA_TITLE)); -- cgit v1.2.3