Merge branch 'fix_webview' into 6.5.3

This commit is contained in:
zlzw 2023-06-25 15:50:04 +08:00
commit f3ff37aea7
7 changed files with 420 additions and 4 deletions

View File

@ -110,10 +110,10 @@ public class WebViewActivity extends AbsActivity {
} }
//真实屏幕高度-(ft_title的高度+导航栏高度) //真实屏幕高度-(ft_title的高度+导航栏高度)
//屏蔽掉是因为在线客服页面 AndroidBug5497Workaround会失效 //屏蔽掉是因为在线客服页面 AndroidBug5497Workaround会失效
/* int height = DeviceUtils.getScreenRealHeight(mContext) - DpUtil.dp2px(72) - getCurrentNavigationBarHeight(mContext); int height = DeviceUtils.getScreenRealHeight(mContext) - DpUtil.dp2px(72) - getCurrentNavigationBarHeight(mContext);
if (!navigationGestureEnabled(mContext)) { if (!navigationGestureEnabled(mContext)) {
view.loadUrl("javascript:window.androidObject.setHeight(" + height + ",0,false)"); view.loadUrl("javascript:window.androidObject.setHeight(" + height + ",0,false)");
}*/ }
} }
}); });

View File

@ -38,6 +38,7 @@ public class RouteUtil {
public static final String PATH_FANSACTIVITY = "/main/FansActivity"; public static final String PATH_FANSACTIVITY = "/main/FansActivity";
public static final String PATH_MYWEBVIEWACTIVTITY2 = "/main/MyWebViewActivity2"; public static final String PATH_MYWEBVIEWACTIVTITY2 = "/main/MyWebViewActivity2";
public static final String PATH_LOGIN = "/main/LoginActivity"; public static final String PATH_LOGIN = "/main/LoginActivity";
public static final String PATH_CS = "/main/CustomerServiceWebViewActivity";
public static void forwardFansActivity(String uid) { public static void forwardFansActivity(String uid) {
ARouter.getInstance().build(PATH_FANSACTIVITY) ARouter.getInstance().build(PATH_FANSACTIVITY)
@ -251,4 +252,13 @@ public class RouteUtil {
ARouter.getInstance().build(PATH_FACEBOOKACTIVITY) ARouter.getInstance().build(PATH_FACEBOOKACTIVITY)
.navigation(); .navigation();
} }
/**
* 客服页面
*/
public static void forwardCustomerService(String url){
ARouter.getInstance().build(PATH_CS)
.withString(Constants.URL,url)
.navigation();
}
} }

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="@+id/v_spacing"
android:layout_width="match_parent"
android:layout_height="24dp"
android:visibility="gone" />
<FrameLayout
android:id="@+id/ft_title"
android:layout_width="match_parent"
android:layout_height="72dp"
android:paddingTop="24dp"
android:background="@color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/titleView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textColor="@color/textColor"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/btn_back"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:onClick="backClick"
android:padding="9dp"
android:src="@mipmap/icon_back"
android:tint="@color/textColor" />
<ImageView
android:id="@+id/btn_edit"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_marginRight="6dp"
android:padding="11dp"
android:src="@mipmap/icon_user_home_edit"
android:tint="@color/white"
android:visibility="gone" />
</RelativeLayout>
</FrameLayout>
<ProgressBar
android:id="@+id/progressbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="3dp"
android:progressDrawable="@drawable/bg_horizontal_progressbar"
android:visibility="gone" />
<FrameLayout
android:id="@+id/webView_root"
android:layout_width="match_parent"
android:layout_marginBottom="15dp"
android:layout_height="match_parent">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</LinearLayout>

View File

@ -144,6 +144,9 @@
<activity <activity
android:name=".activity.MsgSettActivity" android:name=".activity.MsgSettActivity"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity
android:name=".activity.CustomerServiceWebViewActivity"
android:screenOrientation="portrait" />
</application> </application>
</manifest> </manifest>

View File

@ -0,0 +1,320 @@
package com.yunbao.main.activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import androidx.annotation.RequiresApi;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.opensource.svgaplayer.SVGACallback;
import com.opensource.svgaplayer.SVGADrawable;
import com.opensource.svgaplayer.SVGAImageView;
import com.opensource.svgaplayer.SVGAParser;
import com.opensource.svgaplayer.SVGAVideoEntity;
import com.yunbao.common.Constants;
import com.yunbao.common.R;
import com.yunbao.common.activity.AbsActivity;
import com.yunbao.common.event.JavascriptInterfaceEvent;
import com.yunbao.common.utils.AndroidBug5497Workaround;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.JavascriptInterfaceUtils;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.SVGAViewUtils;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.share.ui.InvitePopDialog;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.net.MalformedURLException;
import java.net.URL;
/**
* 专门给客服页面的WebView
*/
@Route(path = RouteUtil.PATH_CS)
public class CustomerServiceWebViewActivity extends AbsActivity {
private ProgressBar mProgressBar;
private WebView mWebView;
private final int CHOOSE = 100;//Android 5.0以下的
private final int CHOOSE_ANDROID_5 = 200;//Android 5.0以上的
private ValueCallback<Uri> mValueCallback;
private ValueCallback<Uri[]> mValueCallback2;
private FrameLayout rootView;
@Override
protected int getLayoutId() {
return R.layout.activity_webview_cs;
}
@Override
protected void main() {
super.main();
Bus.getOn(this);
String url = getIntent().getStringExtra(Constants.URL);
L.e("H5-------->" + url);
mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
rootView = findViewById(R.id.webView_root);
mWebView = findViewById(R.id.webView);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.topMargin = DpUtil.dp2px(1);
if (getNavigationBarHeight(mContext) != 0) {
params.bottomMargin = getNavigationBarHeight(mContext);
}
mWebView.setLayoutParams(params);
mWebView.setOverScrollMode(View.OVER_SCROLL_NEVER);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
L.e("H5-------->" + url);
if (url.startsWith(Constants.COPY_PREFIX)) {
String content = url.substring(Constants.COPY_PREFIX.length());
if (!TextUtils.isEmpty(content)) {
copy(content);
}
} else {
mWebView.post(new Runnable() {
@Override
public void run() {
view.loadUrl(url);
}
});
}
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
setTitle(view.getTitle());
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
// 这个方法在6.0才出现
int statusCode = errorResponse.getStatusCode();
Log.e("WebView", "code = " + statusCode + " failingUrl:" + request.getUrl());
}
});
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) {
mProgressBar.setVisibility(View.GONE);
} else {
mProgressBar.setProgress(newProgress);
}
}
//以下是在各个Android版本中 WebView调用文件选择器的方法
// For Android < 3.0
public void openFileChooser(ValueCallback<Uri> valueCallback) {
openImageChooserActivity(valueCallback);
}
// For Android >= 3.0
public void openFileChooser(ValueCallback valueCallback, String acceptType) {
openImageChooserActivity(valueCallback);
}
//For Android >= 4.1
public void openFileChooser(ValueCallback<Uri> valueCallback,
String acceptType, String capture) {
openImageChooserActivity(valueCallback);
}
// For Android >= 5.0
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean onShowFileChooser(WebView webView,
ValueCallback<Uri[]> filePathCallback,
FileChooserParams fileChooserParams) {
mValueCallback2 = filePathCallback;
Intent intent = fileChooserParams.createIntent();
startActivityForResult(intent, CHOOSE_ANDROID_5);
return true;
}
});
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(mContext, mWebView).setPageClose(true).setLiveZhuangBana(false), "androidObject");
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
String appCachePath = mContext.getCacheDir().getAbsolutePath();
mWebView.getSettings().setAppCachePath(appCachePath);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setUseWideViewPort(true); // 关键点
mWebView.getSettings().setAllowFileAccess(true); // 允许访问文件
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
mWebView.loadUrl(url);
AndroidBug5497Workaround.assistActivity(this);
}
private void openImageChooserActivity(ValueCallback<Uri> valueCallback) {
mValueCallback = valueCallback;
Intent intent = new Intent();
if (Build.VERSION.SDK_INT < 19) {
intent.setAction(Intent.ACTION_GET_CONTENT);
} else {
intent.setAction(Intent.ACTION_PICK);
intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
}
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, mContext.getString(R.string.choose_flie)), CHOOSE);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
switch (requestCode) {
case CHOOSE://5.0以下选择图片后的回调
processResult(resultCode, intent);
break;
case CHOOSE_ANDROID_5://5.0以上选择图片后的回调
processResultAndroid5(resultCode, intent);
break;
}
}
private void processResult(int resultCode, Intent intent) {
if (mValueCallback == null) {
return;
}
if (resultCode == RESULT_OK && intent != null) {
Uri result = intent.getData();
mValueCallback.onReceiveValue(result);
} else {
mValueCallback.onReceiveValue(null);
}
mValueCallback = null;
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void processResultAndroid5(int resultCode, Intent intent) {
if (mValueCallback2 == null) {
return;
}
if (resultCode == RESULT_OK && intent != null) {
mValueCallback2.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));
} else {
mValueCallback2.onReceiveValue(null);
}
mValueCallback2 = null;
}
protected boolean canGoBack() {
return mWebView != null && mWebView.canGoBack();
}
@Override
public void onBackPressed() {
finish();
}
@Override
protected void onDestroy() {
Bus.getOff(this);
if (mWebView != null) {
ViewGroup parent = (ViewGroup) mWebView.getParent();
if (parent != null) {
parent.removeView(mWebView);
}
mWebView.destroy();
}
super.onDestroy();
}
/**
* 复制到剪贴板
*/
private void copy(String content) {
ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("text", content);
cm.setPrimaryClip(clipData);
ToastUtil.show(getString(R.string.copy_success));
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onJavascriptInterfaceEvent(JavascriptInterfaceEvent event) {
if (!TextUtils.isEmpty(event.getMethod())) {
if (TextUtils.equals(event.getMethod(), "androidOpeningNoble")) {
try {
SVGAImageView svga = new SVGAImageView(mContext);
rootView.addView(svga);
new SVGAParser(mContext).parse(new URL(event.getSvg()), new SVGAParser.ParseCompletion() {
@Override
public void onComplete(SVGAVideoEntity videoItem) {
svga.setVisibility(View.VISIBLE);
SVGADrawable drawable = new SVGADrawable(videoItem);
svga.setImageDrawable(drawable);
svga.setLoops(1);
SVGAViewUtils.playEndClear(svga);
}
@Override
public void onError() {
}
});
svga.setCallback(new SVGACallback() {
@Override
public void onPause() {
}
@Override
public void onFinished() {
svga.clear();
svga.setVisibility(View.GONE);
rootView.removeView(svga);
}
@Override
public void onRepeat() {
}
@Override
public void onStep(int i, double v) {
}
});
} catch (MalformedURLException e) {
e.printStackTrace();
}
} else if (event.getMethod().equals("androidInviteShare")) {
new InvitePopDialog(mContext)
.setUrl(event.getData())
.showDialog();
}
}
}
}

View File

@ -615,7 +615,12 @@ public class MainMeViewHolder extends AbsMainViewHolder implements OnItemClickLi
if (!bean.getSlide_url().equals("")) { if (!bean.getSlide_url().equals("")) {
Constants.isTitle = true; Constants.isTitle = true;
String url = bean.getSlide_url() + "?uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken(); String url = bean.getSlide_url() + "?uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken();
ZhuangBanActivity.forward(mContext, url, false); RouteUtil.forwardCustomerService(url);
/*if(bean.getSlide_id().equals("95")){
RouteUtil.forwardCustomerService(url);
}else {
ZhuangBanActivity.forward(mContext, url, false);
}*/
} }
} }
} }

View File

@ -275,7 +275,8 @@ public class MainMessageViewHolder extends AbsMainViewHolder {
FirebaseAnalytics.getInstance(mContext).logEvent("FS_customer_service", null); FirebaseAnalytics.getInstance(mContext).logEvent("FS_customer_service", null);
AppEventsLogger.newLogger(mContext).logEvent("FB_customer_service"); AppEventsLogger.newLogger(mContext).logEvent("FB_customer_service");
if (userBean.getLink() != null && !"".equals(userBean.getLink())) { if (userBean.getLink() != null && !"".equals(userBean.getLink())) {
WebViewActivity.forward(mContext, userBean.getLink()); // WebViewActivity.forward(mContext, userBean.getLink());
RouteUtil.forwardCustomerService(userBean.getLink());
} else { } else {
mContext.startActivity(new Intent(mContext, SystemMessageActivity.class) mContext.startActivity(new Intent(mContext, SystemMessageActivity.class)
.putExtra("type", userBean.getType()) .putExtra("type", userBean.getType())