Commit 24029d6e authored by 王雪伟's avatar 王雪伟

[提交人]:王雪伟

[提交简述] :1.1.0
[实现方案] :客服跳转
parent c4f34198
......@@ -2,7 +2,16 @@
package="com.zxhl.cms">
<application>
<activity android:name=".udesk.UdeskWebViewActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="udesk"
android:scheme="xxsqshop" />
</intent-filter>
</activity>
<activity android:name=".common.WebActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
......@@ -37,8 +46,7 @@
android:name="com.alipay.sdk.app.H5PayActivity"
android:configChanges="orientation|keyboardHidden|navigation"
android:exported="false"
android:screenOrientation="behind" >
</activity>
android:screenOrientation="behind"></activity>
<!-- 友盟配置 -->
<meta-data
android:name="UMENG_APPKEY"
......
......@@ -33,6 +33,9 @@ interface RounterApi {
@RounterParam("url") url: String
): Intent
@RounterUri(Constant.scheme + "://udesk")
fun getIntentActivityUdesk(): Intent
@RounterUri(Constant.scheme + "://h5")
fun getIntentActivityH5(
@RounterParam("url") url: String
......
package com.zxhl.cms.udesk;
/**
* @author (wangXuewei)
* @datetime 2022-06-09 17:32 GMT+8
* @detail :
*/
public interface ICloseWindow {
void closeActivity();
}
package com.zxhl.cms.udesk;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ClipData;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebStorage;
import android.webkit.WebView;
/**
* @author (wangXuewei)
* @datetime 2022-06-09 17:31 GMT+8
* @detail :
*/
public class UdeskWebChromeClient extends WebChromeClient {
private Activity mContext;
private ValueCallback<Uri> uploadMessage;
private ValueCallback<Uri[]> uploadMessageAboveL;
private final static int FILE_CHOOSER_RESULT_CODE = 10000;
ICloseWindow closeWindow = null;
public UdeskWebChromeClient(Activity context,ICloseWindow closeWindow) {
mContext = context;
this.closeWindow = closeWindow;
}
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
}
// For Android < 3.0
public void openFileChooser(ValueCallback<Uri> valueCallback) {
uploadMessage = valueCallback;
openImageChooserActivity();
}
// For Android >= 3.0
public void openFileChooser(ValueCallback valueCallback, String acceptType) {
uploadMessage = valueCallback;
openImageChooserActivity();
}
//For Android >= 4.1
public void openFileChooser(ValueCallback<Uri> valueCallback, String acceptType, String capture) {
uploadMessage = valueCallback;
openImageChooserActivity();
}
// For Android >= 5.0
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
uploadMessageAboveL = filePathCallback;
openImageChooserActivity();
return true;
}
//窗口关闭事件,默认处理关闭activty界面,可以通过ICloseWindow 回到处理对应的逻辑
@Override
public void onCloseWindow(WebView window) {
if (closeWindow !=null){
// closeWindow.closeActivty();
}
// super.onCloseWindow(window);
}
@Override
//扩容
public void onReachedMaxAppCacheSize(long requiredStorage, long quota, WebStorage.QuotaUpdater quotaUpdater) {
quotaUpdater.updateQuota(requiredStorage*2);
}
@Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
Log.e("h5端的log", String.format("%s -- From line %s of %s", message, lineNumber, sourceID));
}
private void openImageChooserActivity() {
Intent i=createFileItent();
mContext.startActivityForResult(Intent.createChooser(i, "Image Chooser"), FILE_CHOOSER_RESULT_CODE);
}
/**
* 创建选择图库的intent
* @return
*/
private Intent createFileItent(){
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
// intent.setType("image/*");
// Intent intent = new Intent(
// Intent.ACTION_PICK,
// MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// intent.setDataAndType(
// MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
// "image/*");
return intent;
}
public void onActivityResult(int requestCode, int resultCode, Intent data){
if (requestCode == FILE_CHOOSER_RESULT_CODE) {
if (null == uploadMessage&& null == uploadMessageAboveL){
return;
}
//上传文件 点取消需要如下设置。 否则再次点击上传文件没反应
if (data == null){
if (uploadMessage != null){
uploadMessage.onReceiveValue(null);
uploadMessage = null;
}
if (uploadMessageAboveL != null){
uploadMessageAboveL.onReceiveValue(null);
uploadMessageAboveL = null;
}
return;
}
if (uploadMessageAboveL != null) {//5.0以上
onActivityResultAboveL(requestCode, resultCode, data);
}else if(uploadMessage != null) {
if (data != null && resultCode == Activity.RESULT_OK ){
Uri result = data.getData();
Log.e("xxx","5.0-result="+result);
uploadMessage.onReceiveValue(result);
uploadMessage = null;
}
}
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void onActivityResultAboveL(int requestCode, int resultCode, Intent intent) {
Log.e("xxx","5.0+ 返回了");
if (requestCode != FILE_CHOOSER_RESULT_CODE || uploadMessageAboveL == null){
return;
}
Uri[] results = null;
if (resultCode == Activity.RESULT_OK) {
if (intent != null) {
String dataString = intent.getDataString();
ClipData clipData = intent.getClipData();
if (clipData != null) {
results = new Uri[clipData.getItemCount()];
for (int i = 0; i < clipData.getItemCount(); i++) {
ClipData.Item item = clipData.getItemAt(i);
results[i] = item.getUri();
}
}
if (dataString != null)
results = new Uri[]{Uri.parse(dataString)};
}
}
uploadMessageAboveL.onReceiveValue(results);
uploadMessageAboveL = null;
}
}
package com.zxhl.cms.udesk;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.webkit.DownloadListener;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.zxhl.cms.R;
import com.zxhl.cms.common.NetConfig;
import me.jessyan.autosize.utils.ScreenUtils;
/**
* @author (wangXuewei)
* @datetime 2022-06-09 17:32 GMT+8
* @detail :
*/
public class UdeskWebViewActivity extends Activity {
private WebView mwebView;
UdeskWebChromeClient udeskWebChromeClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.udesk_webview);
int statusBarHeight = ScreenUtils.getStatusBarHeight();
if (statusBarHeight <= 0) {
statusBarHeight = 40;
}
findViewById(R.id.id_sys_bar_view).getLayoutParams().height = statusBarHeight;
findViewById(R.id.id_img_kefu_close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
initViews();
}
private void initViews() {
try {
udeskWebChromeClient = new UdeskWebChromeClient(this, new ICloseWindow() {
@Override
public void closeActivity() {
finish();
}
});
mwebView = (WebView) findViewById(R.id.webview);
settingWebView(NetConfig.H5.WEB_URL_CUSTOMER_SERVICE);
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressLint("NewApi")
private void settingWebView(String url) {
//支持获取手势焦点,输入用户名、密码或其他
mwebView.requestFocusFromTouch();
mwebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mwebView.setScrollbarFadingEnabled(false);
final WebSettings settings = mwebView.getSettings();
settings.setJavaScriptEnabled(true); //支持js
// 设置自适应屏幕,两者合用
settings.setUseWideViewPort(true); //将图片调整到适合webview的大小
settings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
//若setSupportZoom是false,则该WebView不可缩放,这个不管设置什么都不能缩放。
settings.setSupportZoom(true); //支持缩放,默认为true。是setBuiltInZoomControls的前提。
settings.setBuiltInZoomControls(true); //设置内置的缩放控件。
settings.supportMultipleWindows(); //多窗口
settings.setAllowFileAccess(true); //设置可以访问文件
settings.setNeedInitialFocus(true); //当webview调用requestFocus时为webview设置节点
settings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
//设置编码格式
settings.setDefaultTextEncodingName("UTF-8");
// 关于是否缩放
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
settings.setDisplayZoomControls(false);
}
/**
* Webview在安卓5.0之前默认允许其加载混合网络协议内容
* 在安卓5.0之后,默认不允许加载http与https混合内容,需要设置webview允许其加载混合网络协议内容
*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
settings.setLoadsImagesAutomatically(true); //支持自动加载图片
settings.setDomStorageEnabled(true); //开启DOM Storage
mwebView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
// 监听下载功能,当用户点击下载链接的时候,直接调用系统的浏览器来下载
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
mwebView.setWebChromeClient(udeskWebChromeClient);
mwebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
UdeskWebViewActivity.this.finish();
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
// super.onReceivedSslError(view, handler, error);
handler.proceed();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
mwebView.loadUrl(url);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
udeskWebChromeClient.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onDestroy() {
super.onDestroy();
try {
mwebView.removeAllViews();
mwebView.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
}
......@@ -352,6 +352,16 @@ public class JumpUtils {
}
}
public static void UDesk() {
try {
Intent intent = RounterBus.getRounter(RounterApi.class).getIntentActivityUdesk();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
AppContext.get().startActivity(intent);
} catch (Exception e) {
Utils.showToast(AppContext.get(), "该版本暂不支持,请更新版本!");
}
}
public static void webJump(String title, String url) {
try {
Intent intent = RounterBus.getRounter(RounterApi.class).getIntentActivityWeb(title, url);
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="@+id/id_sys_bar_view"
android:layout_width="match_parent"
android:layout_height="40dp"
android:visibility="gone"
android:layout_marginBottom="10dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingTop="5dp"
android:paddingRight="16dp"
android:paddingBottom="5dp">
<ImageView
android:id="@+id/id_img_kefu_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/incon_back" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:text="客服"
android:textColor="@color/color_333333"
android:textSize="17sp"
android:textStyle="bold" />
</RelativeLayout>
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
\ No newline at end of file
......@@ -81,7 +81,9 @@ class OrderDetailActivity : BaseActivity(), OrderDetailContract.View, PayContrac
finish()
}
id_tv_kefu?.setOnClickListener {
JumpUtils.webJump("客服", NetConfig.H5.WEB_URL_CUSTOMER_SERVICE)
// JumpUtils.webJump("客服", NetConfig.H5.WEB_URL_CUSTOMER_SERVICE)
JumpUtils.UDesk()
}
id_rl_no_address?.setOnClickListener {
val intent = Intent(mActivity, ReceiveAddressActivity::class.java)
......
......@@ -56,7 +56,8 @@ class HomeFragment : BaseFragment(), HomeContract.View, UpdateCallback {
showToast("搜索")
}
id_img_kefu.setOnClickListener {
JumpUtils.webJump("客服", NetConfig.H5.WEB_URL_CUSTOMER_SERVICE)
// JumpUtils.webJump("客服", NetConfig.H5.WEB_URL_CUSTOMER_SERVICE)
JumpUtils.UDesk()
}
val config = SettingPreference.getConfig();
......
......@@ -30,7 +30,8 @@ class UserCenterFragment : BaseFragment(), AdCallback<String> {
}
id_img_kefu?.setOnClickListener {
JumpUtils.webJump("客服", NetConfig.H5.WEB_URL_CUSTOMER_SERVICE)
// JumpUtils.webJump("客服", NetConfig.H5.WEB_URL_CUSTOMER_SERVICE)
JumpUtils.UDesk()
}
id_tv_kaitong?.setOnClickListener {
JumpUtils.MemberOrderJump()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment