diff options
author | cretin45 <cretin45@gmail.com> | 2015-05-05 16:46:38 -0700 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-11-07 14:29:56 -0800 |
commit | 0476898b43cf50152e058835bbf1d242355ce0d7 (patch) | |
tree | 4debf892743bb9b6b56bc08ac188cdba61845b2f | |
parent | e4c6afbae3123595bdd84e7db6494c9c3a8619c7 (diff) | |
download | android_packages_apps_HTMLViewer-0476898b43cf50152e058835bbf1d242355ce0d7.tar.gz android_packages_apps_HTMLViewer-0476898b43cf50152e058835bbf1d242355ce0d7.tar.bz2 android_packages_apps_HTMLViewer-0476898b43cf50152e058835bbf1d242355ce0d7.zip |
HTMLViewer: Added custom viewer for legalese
Change-Id: Ia6f2aeb5d30b327c0d9758c701a26f88b4d75717
-rw-r--r-- | AndroidManifest.xml | 18 | ||||
-rw-r--r-- | res/layout/legal.xml | 47 | ||||
-rw-r--r-- | res/values/styles.xml | 23 | ||||
-rw-r--r-- | src/com/android/htmlviewer/ExternalLegalViewerActivity.java | 111 |
4 files changed, 198 insertions, 1 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 9a2ccd0..3b06ecf 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -22,6 +22,11 @@ <original-package android:name="com.android.htmlviewer" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> + <uses-permission android:name="android.permission.INTERNET"/> + + <permission + android:name="cyanogenmod.permission.LEGALESE" + android:protectionLevel="signatureOrSystem"/> <application android:label="@string/app_label"> <activity android:name="HTMLViewerActivity" @@ -37,6 +42,17 @@ <data android:mimeType="application/xhtml+xml"/> <data android:mimeType="application/vnd.wap.xhtml+xml"/> </intent-filter> - </activity> + </activity> + <activity android:name="com.android.htmlviewer.ExternalLegalViewerActivity" + android:permission="cyanogenmod.permission.LEGALESE" + android:theme="@style/Theme.Legal" + android:exported="true"> + <intent-filter> + <category android:name="android.intent.category.DEFAULT" /> + <action android:name="cyanogenmod.intent.action.LEGALESE" /> + <data android:scheme="http" /> + <data android:scheme="https" /> + </intent-filter> + </activity> </application> </manifest> diff --git a/res/layout/legal.xml b/res/layout/legal.xml new file mode 100644 index 0000000..0b62f87 --- /dev/null +++ b/res/layout/legal.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 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. +--> + +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@*android:color/white"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + <WebView + android:id="@+id/webview" + android:layout_width="match_parent" + android:layout_height="0px" + android:layout_weight="1"/> + <Button + android:id="@+id/dismiss" + android:layout_width="match_parent" + android:layout_height="wrap_content" + style="@android:style/Widget.Material.Light.ActionButton" + android:text="@android:string/ok"/> + </LinearLayout> + + <ProgressBar + android:id="@+id/loading" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:indeterminate="true" + style="?android:attr/progressBarStyle" /> + +</FrameLayout> diff --git a/res/values/styles.xml b/res/values/styles.xml new file mode 100644 index 0000000..34b3ec5 --- /dev/null +++ b/res/values/styles.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2013 The CyanogenMod 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="Theme.Legal" parent="@android:style/Theme.Material.Light"> + <item name="android:windowActionBar">false</item> + <item name="android:windowNoTitle">true</item> + <item name="android:windowBackground">@android:color/white</item> + </style> +</resources> diff --git a/src/com/android/htmlviewer/ExternalLegalViewerActivity.java b/src/com/android/htmlviewer/ExternalLegalViewerActivity.java new file mode 100644 index 0000000..31b6d0a --- /dev/null +++ b/src/com/android/htmlviewer/ExternalLegalViewerActivity.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2008 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.app.Activity; +import android.content.ContentResolver; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.webkit.WebResourceRequest; +import android.webkit.WebResourceResponse; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; + +import java.io.IOException; +import java.io.InputStream; +import java.util.zip.GZIPInputStream; + +/** + * Simple activity that shows the requested HTML page. + */ +public class ExternalLegalViewerActivity extends Activity { + private static final String TAG = "ExternalLegalViewerActivity"; + + private WebView mWebView; + private View mLoading; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.legal); + + findViewById(R.id.dismiss).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + finish(); + } + }); + + mWebView = (WebView) findViewById(R.id.webview); + mLoading = findViewById(R.id.loading); + + mWebView.setWebViewClient(new ViewClient()); + + WebSettings s = mWebView.getSettings(); + s.setUseWideViewPort(true); + s.setSupportZoom(true); + s.setBuiltInZoomControls(true); + s.setDisplayZoomControls(false); + s.setSavePassword(false); + s.setSaveFormData(false); + + s.setDefaultTextEncodingName("utf-8"); + + final Intent intent = getIntent(); + + mWebView.loadUrl(String.valueOf(intent.getData())); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mWebView.destroy(); + } + + private class ViewClient extends WebViewClient { + @Override + public void onPageFinished(WebView view, String url) { + mLoading.setVisibility(View.GONE); + } + + @Override + public WebResourceResponse shouldInterceptRequest(WebView view, + WebResourceRequest request) { + final Uri uri = request.getUrl(); + if (ContentResolver.SCHEME_FILE.equals(uri.getScheme()) + && uri.getPath().endsWith(".gz")) { + Log.d(TAG, "Trying to decompress " + uri + " on the fly"); + try { + final InputStream in = new GZIPInputStream( + getContentResolver().openInputStream(uri)); + final WebResourceResponse resp = new WebResourceResponse( + getIntent().getType(), "utf-8", in); + resp.setStatusCodeAndReasonPhrase(200, "OK"); + return resp; + } catch (IOException e) { + Log.w(TAG, "Failed to decompress; falling back", e); + } + } + return null; + } + } +} |