新增SimpleWebViewActivity打开隐私协议页面
This commit is contained in:
@@ -686,6 +686,9 @@
|
||||
<activity
|
||||
android:name=".ui.webview.CommonWebViewActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".ui.webview.SimpleWebViewActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".bills.activities.RedBagBillsActivity"
|
||||
android:screenOrientation="portrait" />
|
||||
|
@@ -5,7 +5,6 @@ import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
@@ -16,9 +15,11 @@ import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.yizhuan.erban.R;
|
||||
import com.yizhuan.erban.common.widget.OriginalDrawStatusClickSpan;
|
||||
import com.yizhuan.erban.ui.webview.CommonWebViewActivity;
|
||||
import com.yizhuan.erban.ui.webview.SimpleWebViewActivity;
|
||||
import com.yizhuan.erban.ui.widget.magicindicator.buildins.UIUtil;
|
||||
import com.yizhuan.xchat_android_core.UriProvider;
|
||||
import com.yizhuan.xchat_android_library.utils.ScreenUtils;
|
||||
@@ -56,14 +57,14 @@ public class PrivacyAgreementDialog extends Dialog implements View.OnClickListen
|
||||
ss.setSpan(new OriginalDrawStatusClickSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
CommonWebViewActivity.start(getContext(), UriProvider.getPrivacyAgreement());
|
||||
SimpleWebViewActivity.start(getContext(), UriProvider.getPrivacyAgreement());
|
||||
}
|
||||
}, privacyAgreementTipIndex, privacyAgreementTipIndex + privacyAgreementTip.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
ss.setSpan(new ForegroundColorSpan(Color.parseColor("#34a7ff")), userAgreementTipIndex, userAgreementTipIndex + userAgreementTip.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
ss.setSpan(new OriginalDrawStatusClickSpan() {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
CommonWebViewActivity.start(getContext(), UriProvider.getUserProtocolUrl());
|
||||
SimpleWebViewActivity.start(getContext(), UriProvider.getUserProtocolUrl());
|
||||
}
|
||||
}, userAgreementTipIndex, userAgreementTipIndex + privacyAgreementTip.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
||||
|
@@ -0,0 +1,123 @@
|
||||
package com.yizhuan.erban.ui.webview;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.webkit.JavascriptInterface;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.yizhuan.xchat_android_constants.XChatConstants;
|
||||
import com.yizhuan.xchat_android_core.auth.AuthModel;
|
||||
import com.yizhuan.xchat_android_library.utils.AppMetaDataUtil;
|
||||
import com.yizhuan.xchat_android_library.utils.AppUtils;
|
||||
import com.yizhuan.xchat_android_library.utils.VersionUtil;
|
||||
|
||||
/**
|
||||
* <p> html js 与webview 交互接口</p>
|
||||
* Created by ${user} on 2017/11/6.
|
||||
*/
|
||||
public class SimpleJSInterface {
|
||||
private static final String TAG = SimpleJSInterface.class.getSimpleName();
|
||||
private final Context context;
|
||||
|
||||
public SimpleJSInterface(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备ID
|
||||
*
|
||||
* @return 设备id
|
||||
*/
|
||||
@JavascriptInterface
|
||||
public String getDeviceId() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取uid
|
||||
*
|
||||
* @return uid
|
||||
*/
|
||||
@JavascriptInterface
|
||||
public String getUid() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void initNav(String json) {
|
||||
Logger.e("initNav: " + json);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭浏览器
|
||||
*/
|
||||
@JavascriptInterface
|
||||
public void closeWebView() {
|
||||
if (context instanceof Activity) {
|
||||
((Activity) context).finish();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户ticket
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@JavascriptInterface
|
||||
public String getTicket() {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取应用版本号
|
||||
*/
|
||||
@JavascriptInterface
|
||||
public String getAppVersion() {
|
||||
return VersionUtil.getLocalName(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取渠道
|
||||
*
|
||||
* @return 渠道名称
|
||||
*/
|
||||
@JavascriptInterface
|
||||
public String getChannel() {
|
||||
String channel = "";
|
||||
try {
|
||||
ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
|
||||
channel = appInfo.metaData.getString("CHANNEL");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (TextUtils.isEmpty(channel)) {
|
||||
channel = "official";
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取 deviceInfo
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@JavascriptInterface
|
||||
public String getDeviceInfo() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("os", "android");
|
||||
jsonObject.put("app", XChatConstants.APP_MARK);
|
||||
jsonObject.put("appVersion", VersionUtil.getLocalName(context));
|
||||
jsonObject.put("appVersionCode", String.valueOf(AppUtils.getVersionCode(context)));
|
||||
jsonObject.put("channel", getChannel());
|
||||
Log.e(TAG, "getDeviceInfo: " + jsonObject);
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,226 @@
|
||||
package com.yizhuan.erban.ui.webview;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.net.http.SslError;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.webkit.SslErrorHandler;
|
||||
import android.webkit.ValueCallback;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.netease.nim.uikit.StatusBarUtil;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.yizhuan.erban.R;
|
||||
import com.yizhuan.erban.utils.WebViewUtils;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
|
||||
/**
|
||||
* 最简单的H5页面,用于隐私协议弹窗,不继承BaseActivity
|
||||
*/
|
||||
public class SimpleWebViewActivity extends AppCompatActivity {
|
||||
|
||||
protected FrameLayout layoutTitleBar;
|
||||
protected WebView webView;
|
||||
private ProgressBar mProgressBar;
|
||||
private WebChromeClient wvcc;
|
||||
private ImageView mIvBack;
|
||||
private ImageView mIvClose;
|
||||
private TextView mTitle;
|
||||
private String url;
|
||||
|
||||
private int mProgress;
|
||||
|
||||
private Handler mHandler = new Handler();
|
||||
|
||||
private ProgressRunnable mProgressRunnable = new ProgressRunnable(this);
|
||||
|
||||
public static void start(Context context, String url) {
|
||||
Intent intent = new Intent(context, SimpleWebViewActivity.class);
|
||||
intent.putExtra("url", url);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(getLayoutId());
|
||||
Intent intent = getIntent();
|
||||
url = intent.getStringExtra("url");
|
||||
StatusBarUtil.transparencyBar(this);
|
||||
initView();
|
||||
initData();
|
||||
setListener();
|
||||
showWebView(url);
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_simple_web_view;
|
||||
}
|
||||
|
||||
private void setListener() {
|
||||
mIvBack.setOnClickListener(v -> {
|
||||
if (webView.canGoBack()) {
|
||||
webView.goBack();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
mIvClose.setOnClickListener(v -> {
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
private void initData() {
|
||||
mHandler.post(mProgressRunnable);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
webView.getSettings().setUseWideViewPort(true);
|
||||
webView.getSettings().setLoadWithOverviewMode(true);
|
||||
// 设置 WebView 可以在 HTTPS 通道上加载 HTTP 资源,Android 4.4 后的暗坑
|
||||
// 因为 Android 4.4 后默认不允许在 HTTPS 通道上加载 HTTP 资源
|
||||
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
|
||||
webView.getSettings().setTextZoom(100);
|
||||
SimpleJSInterface jsInterface = new SimpleJSInterface(this);
|
||||
webView.addJavascriptInterface(jsInterface, "androidJsObj");
|
||||
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
|
||||
webView.setWebViewClient(new WebViewClient() {
|
||||
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
|
||||
if (!(url.startsWith("http") || url.startsWith("https"))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
view.loadUrl(url);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
|
||||
// super.onReceivedSslError(view, handler, error); //一定要去掉
|
||||
// handler.cancel();// Android默认的处理方式
|
||||
handler.proceed();// 接受所有网站的证书
|
||||
// handleMessage(Message msg);// 进行其他处理
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
Logger.e("onPageFinished--------" + url);
|
||||
mProgressBar.setProgress(100);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
super.onPageFinished(view, url);
|
||||
}
|
||||
});
|
||||
//获取webviewtitle作为titlebar的title
|
||||
wvcc = new WebChromeClient() {
|
||||
|
||||
@Override
|
||||
public void onReceivedTitle(WebView view, String title) {
|
||||
super.onReceivedTitle(view, title);
|
||||
mTitle.setText(title + "");
|
||||
}
|
||||
|
||||
// For Android >= 4.1
|
||||
public void openFileChooser(ValueCallback<Uri> uploadMsg,
|
||||
String acceptType, String capture) {
|
||||
|
||||
}
|
||||
|
||||
// For Lollipop 5.0+ Devices
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public boolean onShowFileChooser(WebView mWebView,
|
||||
ValueCallback<Uri[]> filePathCallback,
|
||||
FileChooserParams fileChooserParams) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
// 设置setWebChromeClient对象
|
||||
webView.setWebChromeClient(wvcc);
|
||||
// 设置Webview的user-agent
|
||||
webView.getSettings().setUserAgentString(webView.getSettings().getUserAgentString() + " tutuAppAndroid erbanAppAndroid");
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
layoutTitleBar = findViewById(R.id.layout_title_bar);
|
||||
webView = (WebView) findViewById(R.id.webview);
|
||||
mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
|
||||
mIvBack = findViewById(R.id.iv_back);
|
||||
mIvClose = findViewById(R.id.iv_close);
|
||||
mTitle = findViewById(R.id.tv_title);
|
||||
}
|
||||
|
||||
public void showWebView(String url) {
|
||||
Logger.d("ShowWebView--------" + url);
|
||||
if (!TextUtils.isEmpty(url)) {
|
||||
webView.loadUrl(url);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (webView.canGoBack()) {
|
||||
webView.goBack();
|
||||
|
||||
} else {
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (mHandler != null) {
|
||||
mHandler.removeCallbacks(mProgressRunnable);
|
||||
mProgressRunnable = null;
|
||||
mHandler = null;
|
||||
}
|
||||
super.onDestroy();
|
||||
WebViewUtils.releaseWeb(webView);
|
||||
}
|
||||
|
||||
private static class ProgressRunnable implements Runnable {
|
||||
private WeakReference<SimpleWebViewActivity> mWeakReference;
|
||||
|
||||
ProgressRunnable(SimpleWebViewActivity activity) {
|
||||
mWeakReference = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
SimpleWebViewActivity activity = mWeakReference.get();
|
||||
if (activity == null) return;
|
||||
if (activity.mProgress < 96) {
|
||||
activity.mProgress += 3;
|
||||
activity.mProgressBar.setProgress(activity.mProgress);
|
||||
activity.mHandler.postDelayed(activity.mProgressRunnable, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
85
app/src/main/res/layout/activity_simple_web_view.xml
Normal file
85
app/src/main/res/layout/activity_simple_web_view.xml
Normal file
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout 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"
|
||||
android:orientation="vertical"
|
||||
android:background="@color/bg_normal_1c1b22"
|
||||
tools:context="com.yizhuan.erban.ui.webview.CommonWebViewActivity">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/layout_title_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_marginTop="@dimen/dp_25"
|
||||
android:layout_height="48dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_back"
|
||||
android:layout_width="45dp"
|
||||
android:layout_height="45dp"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/arrow_left_white" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_close"
|
||||
android:layout_width="45dp"
|
||||
android:layout_height="45dp"
|
||||
android:scaleType="center"
|
||||
android:layout_gravity="center_vertical|start"
|
||||
android:src="@drawable/icon_close_labe" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_title"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="match_parent"
|
||||
android:textColor="@color/text_title_white"
|
||||
android:gravity="center"
|
||||
tools:text="这是标题"
|
||||
android:layout_gravity="center"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/img_share"
|
||||
android:layout_width="22dp"
|
||||
android:layout_height="22dp"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:src="@drawable/ic_share_white"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_title_right"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
tools:text="常见问题"
|
||||
android:textSize="14sp"
|
||||
android:visibility="gone"
|
||||
android:textColor="@color/text_normal_c6c6e9"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</FrameLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_bar"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:max="100"
|
||||
android:progress="0"
|
||||
android:progressDrawable="@drawable/progress_drawable" />
|
||||
|
||||
<WebView
|
||||
android:id="@+id/webview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</WebView>
|
||||
</LinearLayout>
|
@@ -45,8 +45,8 @@ public class UriProvider {
|
||||
/**
|
||||
* 默认以下生产环境地址
|
||||
*/
|
||||
public static String JAVA_WEB_URL = "http://www.daxiaomao.com";
|
||||
public static String IM_SERVER_URL = "https://www.daxiaomao.com";
|
||||
public static String JAVA_WEB_URL = "https://api.lecheng163.com/";
|
||||
public static String IM_SERVER_URL = "https://api.lecheng163.com/";
|
||||
|
||||
/**
|
||||
* @return
|
||||
|
Reference in New Issue
Block a user