优化:内嵌 WebView 打开使用帮助

This commit is contained in:
pppscn 2022-03-06 16:01:08 +08:00
parent bed675fb0d
commit 733f375821
4 changed files with 83 additions and 3 deletions

View File

@ -117,6 +117,10 @@
android:name=".AppListActivity"
android:exported="true"
android:label="@string/app_list" />
<activity
android:name=".HelpActivity"
android:exported="true"
android:label="@string/help" />
<activity
android:name=".OnePixelActivity"
android:configChanges="keyboardHidden|orientation|screenSize|navigation|keyboard"

View File

@ -0,0 +1,60 @@
package com.idormy.sms.forwarder;
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
@SuppressWarnings("deprecation")
public class HelpActivity extends AppCompatActivity {
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
//获得控件
WebView webView = findViewById(R.id.wv_webview);
//设置
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
webView.getSettings().setSafeBrowsingEnabled(false);
}
WebSettings webSetting = webView.getSettings();
webSetting.setJavaScriptEnabled(true);
webSetting.setBuiltInZoomControls(true);
webSetting.setDisplayZoomControls(false);
webSetting.setUseWideViewPort(true);
webSetting.setBlockNetworkImage(false);
//缓存模式
webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSetting.setDatabaseEnabled(true);
webSetting.setDomStorageEnabled(true);
webSetting.setAppCacheMaxSize(1024 * 1024 * 8);
webSetting.setAppCachePath(getFilesDir().getAbsolutePath());
webSetting.setDatabasePath(getFilesDir().getAbsolutePath());
webSetting.setAllowFileAccess(true);
webSetting.setAppCacheEnabled(true);
//webSetting.setTextZoom(100);
webSetting.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
//访问网页
webView.loadUrl("https://gitee.com/pp/SmsForwarder/wikis/pages");
//系统默认会通过手机浏览器打开网页为了能够直接通过WebView显示网页则必须设置
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//使用WebView加载显示url
view.loadUrl(url);
//返回true
return true;
}
});
}
}

View File

@ -5,7 +5,6 @@ import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@ -59,6 +58,7 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("CommentedOutCode")
public class MainActivity extends AppCompatActivity implements RefreshListView.IRefreshListener {
private final String TAG = "MainActivity";
@ -513,8 +513,9 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
intent = new Intent(this, AboutActivity.class);
break;
case R.id.to_help:
Uri uri = Uri.parse("https://gitee.com/pp/SmsForwarder/wikis/pages");
intent = new Intent(Intent.ACTION_VIEW, uri);
//Uri uri = Uri.parse("https://gitee.com/pp/SmsForwarder/wikis/pages");
//intent = new Intent(Intent.ACTION_VIEW, uri);
intent = new Intent(this, HelpActivity.class);
break;
default:
return super.onOptionsItemSelected(item);

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HelpActivity">
<WebView
android:id="@+id/wv_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>