├── Android.bp
├── AndroidManifest-car.xml
├── AndroidManifest.xml
├── CleanSpec.mk
├── OWNERS
├── res
├── layout
│ ├── main.xml
│ └── main_car.xml
├── values-af
│ └── strings.xml
├── values-am
│ └── strings.xml
├── values-ar
│ └── strings.xml
├── values-b+sr+Latn
│ └── strings.xml
├── values-be
│ └── strings.xml
├── values-bg
│ └── strings.xml
├── values-bn
│ └── strings.xml
├── values-ca
│ └── strings.xml
├── values-cs
│ └── strings.xml
├── values-da
│ └── strings.xml
├── values-de
│ └── strings.xml
├── values-el
│ └── strings.xml
├── values-en-rGB
│ └── strings.xml
├── values-en-rIN
│ └── strings.xml
├── values-es-rUS
│ └── strings.xml
├── values-es
│ └── strings.xml
├── values-et
│ └── strings.xml
├── values-fa
│ └── strings.xml
├── values-fi
│ └── strings.xml
├── values-fr
│ └── strings.xml
├── values-hi
│ └── strings.xml
├── values-hr
│ └── strings.xml
├── values-hu
│ └── strings.xml
├── values-in
│ └── strings.xml
├── values-it
│ └── strings.xml
├── values-iw
│ └── strings.xml
├── values-ja
│ └── strings.xml
├── values-ko
│ └── strings.xml
├── values-lt
│ └── strings.xml
├── values-lv
│ └── strings.xml
├── values-ms
│ └── strings.xml
├── values-nb
│ └── strings.xml
├── values-nl
│ └── strings.xml
├── values-pl
│ └── strings.xml
├── values-pt-rPT
│ └── strings.xml
├── values-pt
│ └── strings.xml
├── values-ro
│ └── strings.xml
├── values-ru
│ └── strings.xml
├── values-sk
│ └── strings.xml
├── values-sl
│ └── strings.xml
├── values-sr
│ └── strings.xml
├── values-sv
│ └── strings.xml
├── values-sw
│ └── strings.xml
├── values-th
│ └── strings.xml
├── values-tl
│ └── strings.xml
├── values-tr
│ └── strings.xml
├── values-uk
│ └── strings.xml
├── values-vi
│ └── strings.xml
├── values-zh-rCN
│ └── strings.xml
├── values-zh-rHK
│ └── strings.xml
├── values-zh-rTW
│ └── strings.xml
├── values-zu
│ └── strings.xml
└── values
│ └── strings.xml
└── src
└── com
└── android
└── htmlviewer
├── CarHTMLViewerActivity.java
└── HTMLViewerActivity.java
/Android.bp:
--------------------------------------------------------------------------------
1 | package {
2 | // See: http://go/android-license-faq
3 | default_applicable_licenses: ["Android-Apache-2.0"],
4 | }
5 |
6 | android_app {
7 | name: "HTMLViewer",
8 | manifest: "AndroidManifest.xml",
9 | srcs: ["**/*.java"],
10 | exclude_srcs: ["src/com/android/htmlviewer/CarHTMLViewerActivity.java"],
11 | static_libs: ["androidx.core_core"],
12 | sdk_version: "current",
13 | }
14 |
15 | android_app {
16 | name: "CarHTMLViewer",
17 | manifest: "AndroidManifest-car.xml",
18 | overrides: ["HTMLViewer"],
19 | srcs: ["**/*.java"],
20 | libs: ["android.car-stubs"],
21 | static_libs: [
22 | "androidx.core_core",
23 | "car-ui-lib",
24 | ],
25 | sdk_version: "current",
26 | }
27 |
--------------------------------------------------------------------------------
/AndroidManifest-car.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 |
20 |
21 |
23 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
39 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
23 |
24 |
25 |
27 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
43 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/CleanSpec.mk:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2007 The Android Open Source Project
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | #
15 |
16 | # If you don't need to do a full clean build but would like to touch
17 | # a file or delete some intermediate files, add a clean step to the end
18 | # of the list. These steps will only be run once, if they haven't been
19 | # run before.
20 | #
21 | # E.g.:
22 | # $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
23 | # $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
24 | #
25 | # Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
26 | # files that are missing or have been moved.
27 | #
28 | # Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
29 | # Use $(OUT_DIR) to refer to the "out" directory.
30 | #
31 | # If you need to re-do something that's already mentioned, just copy
32 | # the command and add it to the bottom of the list. E.g., if a change
33 | # that you made last week required touching a file and a change you
34 | # made today requires touching the same file, just copy the old
35 | # touch step and add it to the end of the list.
36 | #
37 | # ************************************************
38 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
39 | # ************************************************
40 |
41 | # For example:
42 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
43 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
44 | #$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
45 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
46 |
47 | # ************************************************
48 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
49 | # ************************************************
50 |
--------------------------------------------------------------------------------
/OWNERS:
--------------------------------------------------------------------------------
1 | # Default code reviewers picked from top 3 or more developers.
2 | # Please update this list if you find better candidates.
3 | tmfang@google.com
4 |
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
21 |
22 |
26 |
27 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/res/layout/main_car.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-af/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML-bekyker"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-am/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML አሳይ"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-ar/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "عارض HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-b+sr+Latn/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML prikazivač"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-be/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML Viewer"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-bg/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML визуализатор"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-bn/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML-leser"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-ca/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Lector d\'HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-cs/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Zobrazovač HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-da/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML-fremviser"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-de/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML-Anzeige"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-el/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Πρόγραμμα προβολής HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-en-rGB/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML Viewer"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-en-rIN/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML Viewer"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-es-rUS/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Visualizador de HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-es/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Visor de HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-et/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML Viewer"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-fa/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "مشاهده گر HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-fi/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML-lukija"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-fr/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Visionneuse HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-hi/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML व्यूअर"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-hr/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML pregledač"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-hu/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML megtekintő"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-in/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Penampil HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-it/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Visualizzatore HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-iw/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "מציג HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-ja/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTMLビューア"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-ko/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML 뷰어"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-lt/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML skaitytojas"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-lv/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML skatītājs"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-ms/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Pemapar HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-nb/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML-leser"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-nl/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML-viewer"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-pl/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Przeglądarka HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-pt-rPT/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Visualizador de HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-pt/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Leitor de HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-ro/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Ecran de vizualizare HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-ru/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Средство просмотра HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-sk/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Zobrazovač HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-sl/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Pregledovalnik HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-sr/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML приказивач"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-sv/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML-visningsprogram"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-sw/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Kitazamaji cha HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-th/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "โปรแกรมดู HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-tl/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Tagatingin ng HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-tr/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML Görüntüleyici"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-uk/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML Viewer"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-vi/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Trình xem HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-zh-rCN/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML 查看程序"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-zh-rHK/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML 檢視器"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-zh-rTW/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "HTML 檢視器"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values-zu/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
19 | "Umbukeli we-HTML"
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 | HTML Viewer
20 | No application can open this link.
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/com/android/htmlviewer/CarHTMLViewerActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2021 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.htmlviewer;
18 |
19 | import android.webkit.WebView;
20 |
21 | import com.android.car.ui.core.CarUi;
22 | import com.android.car.ui.toolbar.NavButtonMode;
23 | import com.android.car.ui.toolbar.ToolbarController;
24 |
25 | /**
26 | * An HTMLViewerActivity used for car builds.
27 | */
28 | public class CarHTMLViewerActivity extends HTMLViewerActivity {
29 | private ToolbarController mToolbar;
30 |
31 | @Override
32 | protected void setContentView() {
33 | setContentView(R.layout.main_car);
34 | WebView webView = requireViewById(R.id.webview);
35 | webView.setDefaultFocusHighlightEnabled(false);
36 | mToolbar = CarUi.requireToolbar(this);
37 | mToolbar.setNavButtonMode(NavButtonMode.BACK);
38 | }
39 |
40 | @Override
41 | public void setTitle(CharSequence title) {
42 | super.setTitle(title);
43 | mToolbar.setTitle(title);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/com/android/htmlviewer/HTMLViewerActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.htmlviewer;
18 |
19 | import android.app.Activity;
20 | import android.content.ActivityNotFoundException;
21 | import android.content.ContentResolver;
22 | import android.content.Intent;
23 | import android.net.Uri;
24 | import android.os.Bundle;
25 | import android.provider.Browser;
26 | import android.util.Log;
27 | import android.view.MenuItem;
28 | import android.view.View;
29 | import android.webkit.WebChromeClient;
30 | import android.webkit.WebResourceRequest;
31 | import android.webkit.WebResourceResponse;
32 | import android.webkit.WebSettings;
33 | import android.webkit.WebView;
34 | import android.webkit.WebViewClient;
35 | import android.widget.Toast;
36 |
37 | import androidx.core.graphics.Insets;
38 | import androidx.core.view.ViewCompat;
39 | import androidx.core.view.WindowCompat;
40 | import androidx.core.view.WindowInsetsCompat;
41 |
42 | import java.io.IOException;
43 | import java.io.InputStream;
44 | import java.net.URISyntaxException;
45 | import java.util.zip.GZIPInputStream;
46 |
47 | /**
48 | * Simple activity that shows the requested HTML page. This utility is
49 | * purposefully very limited in what it supports, including no network or
50 | * JavaScript.
51 | */
52 | public class HTMLViewerActivity extends Activity {
53 | private static final String TAG = "HTMLViewer";
54 |
55 | private WebView mWebView;
56 | private View mLoading;
57 | private Intent mIntent;
58 |
59 | @Override
60 | protected void onCreate(Bundle savedInstanceState) {
61 | super.onCreate(savedInstanceState);
62 |
63 | setContentView();
64 |
65 | mWebView = findViewById(R.id.webview);
66 | mLoading = findViewById(R.id.loading);
67 |
68 | mWebView.setWebChromeClient(new ChromeClient());
69 | mWebView.setWebViewClient(new ViewClient());
70 |
71 | WebSettings s = mWebView.getSettings();
72 | s.setUseWideViewPort(true);
73 | s.setSupportZoom(true);
74 | s.setBuiltInZoomControls(true);
75 | s.setDisplayZoomControls(false);
76 | s.setSavePassword(false);
77 | s.setSaveFormData(false);
78 | s.setBlockNetworkLoads(true);
79 | s.setAllowFileAccess(true);
80 |
81 | // Javascript is purposely disabled, so that nothing can be
82 | // automatically run.
83 | s.setJavaScriptEnabled(false);
84 | s.setDefaultTextEncodingName("utf-8");
85 |
86 | mIntent = getIntent();
87 | setBackButton();
88 | loadUrl();
89 | }
90 |
91 | protected void setContentView() {
92 | setupEdgeToEdge();
93 | setContentView(R.layout.main);
94 | }
95 |
96 | private void loadUrl() {
97 | if (mIntent.hasExtra(Intent.EXTRA_TITLE)) {
98 | setTitle(mIntent.getStringExtra(Intent.EXTRA_TITLE));
99 | }
100 | mWebView.loadUrl(String.valueOf(mIntent.getData()));
101 | }
102 |
103 | private void setBackButton() {
104 | if (getActionBar() != null) {
105 | getActionBar().setDisplayHomeAsUpEnabled(true);
106 | }
107 | }
108 |
109 | @Override
110 | public boolean onOptionsItemSelected(MenuItem item) {
111 | if (item.getItemId() == android.R.id.home) {
112 | finish();
113 | return true;
114 | }
115 | return super.onOptionsItemSelected(item);
116 | }
117 |
118 | @Override
119 | protected void onDestroy() {
120 | super.onDestroy();
121 | mWebView.destroy();
122 | }
123 |
124 | private class ChromeClient extends WebChromeClient {
125 | @Override
126 | public void onReceivedTitle(WebView view, String title) {
127 | if (!getIntent().hasExtra(Intent.EXTRA_TITLE)) {
128 | HTMLViewerActivity.this.setTitle(title);
129 | }
130 | }
131 | }
132 |
133 | private class ViewClient extends WebViewClient {
134 | @Override
135 | public void onPageFinished(WebView view, String url) {
136 | mLoading.setVisibility(View.GONE);
137 | }
138 |
139 | @Override
140 | public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
141 | String url = request.getUrl().toString();
142 | Intent intent;
143 | // Perform generic parsing of the URI to turn it into an Intent.
144 | try {
145 | intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
146 | } catch (URISyntaxException ex) {
147 | Log.w(TAG, "Bad URI " + url + ": " + ex.getMessage());
148 | Toast.makeText(HTMLViewerActivity.this,
149 | R.string.cannot_open_link, Toast.LENGTH_SHORT).show();
150 | return true;
151 | }
152 | // Sanitize the Intent, ensuring web pages can not bypass browser
153 | // security (only access to BROWSABLE activities).
154 | intent.addCategory(Intent.CATEGORY_BROWSABLE);
155 | intent.setComponent(null);
156 | Intent selector = intent.getSelector();
157 | if (selector != null) {
158 | selector.addCategory(Intent.CATEGORY_BROWSABLE);
159 | selector.setComponent(null);
160 | }
161 | // Pass the package name as application ID so that the intent from the
162 | // same application can be opened in the same tab.
163 | intent.putExtra(Browser.EXTRA_APPLICATION_ID,
164 | view.getContext().getPackageName());
165 | try {
166 | view.getContext().startActivity(intent);
167 | } catch (ActivityNotFoundException | SecurityException ex) {
168 | Log.w(TAG, "No application can handle " + url);
169 | Toast.makeText(HTMLViewerActivity.this,
170 | R.string.cannot_open_link, Toast.LENGTH_SHORT).show();
171 | }
172 | return true;
173 | }
174 |
175 | @Override
176 | public WebResourceResponse shouldInterceptRequest(WebView view,
177 | WebResourceRequest request) {
178 | final Uri uri = request.getUrl();
179 | if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())
180 | && uri.getPath().endsWith(".gz")) {
181 | Log.d(TAG, "Trying to decompress " + uri + " on the fly");
182 | try {
183 | final InputStream in = new GZIPInputStream(
184 | getContentResolver().openInputStream(uri));
185 | final WebResourceResponse resp = new WebResourceResponse(
186 | getIntent().getType(), "utf-8", in);
187 | resp.setStatusCodeAndReasonPhrase(200, "OK");
188 | return resp;
189 | } catch (IOException e) {
190 | Log.w(TAG, "Failed to decompress; falling back", e);
191 | }
192 | }
193 | return null;
194 | }
195 | }
196 |
197 | private void setupEdgeToEdge() {
198 | // Shamelessly copied from SettingsHomepageActivity
199 | // https://cs.android.com/android/platform/superproject/main/+/main:packages/apps/Settings/src/com/android/settings/homepage/SettingsHomepageActivity.java;l=355;drc=6b4b7336bc0bdbbdbd144429b8dfb006503d6a7b
200 | WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
201 | ViewCompat.setOnApplyWindowInsetsListener(findViewById(android.R.id.content),
202 | (v, windowInsets) -> {
203 | Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
204 | // Apply the insets paddings to the view.
205 | v.setPadding(insets.left, insets.top, insets.right, insets.bottom);
206 |
207 | // Return CONSUMED if you don't want the window insets to keep being
208 | // passed down to descendant views.
209 | return WindowInsetsCompat.CONSUMED;
210 | });
211 | }
212 | }
213 |
--------------------------------------------------------------------------------