Commit a96c3ba2 by 刘鹏

feat: WebView埋点添加完成

parent e8d8c821
......@@ -36,7 +36,7 @@ ext {
"ydl-platform" : "0.0.39.97",
//第二步 若干
"ydl-webview" : "0.0.38.36",
"ydl-webview" : "0.0.38.38",
"ydl-media" : "0.0.21.6",
"ydl-pay" : "0.0.18.15",
"m-audioim" : "0.0.49.29.32",
......@@ -118,7 +118,7 @@ ext {
"ydl-platform" : "0.0.39.97",
//第二步 若干
"ydl-webview" : "0.0.38.36",
"ydl-webview" : "0.0.38.38",
"ydl-media" : "0.0.21.6",
"ydl-pay" : "0.0.18.15",
"m-audioim" : "0.0.49.29.32",
......
......@@ -51,6 +51,8 @@ import com.ydl.ydlcommon.utils.URLUtils;
import com.ydl.ydlcommon.view.TitleBar;
import com.ydl.ydlcommon.view.dialog.YDLCommonDialog;
import com.ydl.ydlcommon.view.dialog.YDLShareDialog;
import com.ydl.ydlnet.utils.log.AliYunLogConfig;
import com.ydl.ydlnet.utils.log.AliYunLogHelper;
import com.yidianling.common.tools.RxDeviceTool;
import com.yidianling.common.tools.RxImageTool;
import com.yidianling.common.tools.ToastUtil;
......@@ -81,24 +83,21 @@ import static android.view.View.VISIBLE;
/**
* 通用h5显示页面
* <p>
* 跳转此h5页面,请使用唯一参数 H5ParamsBaseActivity
*/
@Route(path = "/new_h5/h5")
public class NewH5Activity extends BaseActivity implements PtrHandler {
public static final String PARAMS = "h5Params";
/**
* 路由传递过来的参数
*/
/*** 路由传递过来的参数*/
public static final String ROUTER_PARAMS = "routerParam";
//下单选择时间请求吗
/***下单选择时间请求吗*/
public static final int ORDER_TIME_REQUEST_CODE = 110;
//启动类型
private int startType = 0;//0正常模式 1从下至上打开页面
//右侧按钮文字
/***启动类型 0正常模式 1从下至上打开页面*/
private int startType = 0;
/***右侧按钮文字*/
private String rightText = "";
protected TitleBar tb_title;
......@@ -107,10 +106,10 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
protected ProgressWebView wv_content;
protected PtrFrameLayout store_house_ptr_frame;
protected SafeTipView safeTipView;
//接收参数
/***接收参数*/
private H5Params h5Params;
protected String purl;//分享到发布需要的url
/***分享到发布需要的url*/
protected String purl;
protected String shareUrl;
protected String shareTitle;
protected String shareDesc;
......@@ -121,11 +120,9 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
protected ValueCallback<Uri> uploadMessage;
protected ValueCallback<Uri[]> uploadMessageAboveL;
private boolean shouldClearHistory = false;
//要分享出去的url
/***要分享出去的url*/
private String shareToUrl;
/**
* 拍照/选择文件请求码
*/
/*** 拍照/选择文件请求码*/
protected final static int FILE_CHOOSER_RESULT_CODE = 10000;
protected IJavascriptHandler jtoJHandle;
......@@ -133,37 +130,46 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
private LinearLayout llWebView;
private long loadStartTime = 0;//加载url开始的时间
private long initStartTime = 0;//webview初始化开始的时间
private long initDuration = 0;//webview初始化耗时
private long loadDuration = 0;//加载url耗时
/***加载url开始的时间*/
private long loadStartTime = 0;
/***webview初始化开始的时间*/
private long initStartTime = 0;
/***webview初始化耗时*/
private long initDuration = 0;
/***加载url耗时*/
private long loadDuration = 0;
private NetWorkSpeedUtils workSpeedUtils;
private boolean hasLoad = false;//部分机型中webview加载完成回调方法会调用多次,增加本地标识符
//是否跳转到动态
/***部分机型中webview加载完成回调方法会调用多次,增加本地标识符*/
private boolean hasLoad = false;
/***是否跳转到动态*/
private boolean isToTrend = false;
private LogoLoadingView v_loading;
private boolean isTimeOut = false; //是否超时
private Handler mTimeOutHandler = null; //超时处理handler
private int timeOutLong = 15000; //超时限定时间
private int TIME_OUT_TYPE = 0x1000; //超时消息
// 设置微信 H5 支付调用 loadDataWithBaseURL 的标记位,避免循环调用,
// 再次进入微信 H5 支付流程时记得重置此标记位状态
/***是否超时*/
private boolean isTimeOut = false;
/***超时处理handler*/
private Handler mTimeOutHandler = null;
/***超时限定时间*/
private int timeOutLong = 15000;
/***超时消息*/
private int TIME_OUT_TYPE = 0x1000;
/**
* 设置微信 H5 支付调用 loadDataWithBaseURL 的标记位,避免循环调用,
* 再次进入微信 H5 支付流程时记得重置此标记位状态
*/
boolean firstVisitWXH5PayUrl = true;
private String WX_H5_PAY_HOST = "http://testnewm.ydl.com";
/**
* 当前页面类型
*/
/*** 当前页面类型*/
private int selfPageType = -1;
private int TEST_QUESTIONS_PAGE_TYPE = 1000001; //测评题页面
/***测评题页面*/
private int TEST_QUESTIONS_PAGE_TYPE = 1000001;
private YDLCommonDialog testQuestionsPageReturnDialog = null;
private boolean isTitleBarCover = false; // 标题栏是否被覆盖隐藏
private static IWebRightClickListener webRightClickListener= null;
/*** 标题栏是否被覆盖隐藏*/
private boolean isTitleBarCover = false;
private static IWebRightClickListener webRightClickListener = null;
/**
* 设置当前h5页面类型
*
......@@ -202,7 +208,7 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
context.startActivity(intent);
}
public static void start(Context context, H5Params h5Params1,String rightText,IWebRightClickListener listener) {
public static void start(Context context, H5Params h5Params1, String rightText, IWebRightClickListener listener) {
if (null == context) {
return;
}
......@@ -238,9 +244,6 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
intent.putExtra(PARAMS, h5Params1);
context.startActivity(intent);
// if (startType == 1) {
// context.overridePendingTransition(R.anim.activity_open_up, 0);
// }
}
public static void startForResult(Activity context, H5Params h5Params1, int requestCode) {
......@@ -299,9 +302,10 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
* 15秒后发送一条消息通知展示无网络页面
*/
private void sendNetLossMessage() {
if (null != mTimeOutHandler)
if (null != mTimeOutHandler) {
mTimeOutHandler.sendEmptyMessageDelayed(TIME_OUT_TYPE, timeOutLong);
}
}
/**
* 取消预定15秒后发送的消息
......@@ -372,6 +376,7 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
rightText = getIntent().getStringExtra("rightText");
if (h5Params == null) {
ToastUtil.toastShort("参数错误");
AliYunLogHelper.Companion.getInstance().sendLog(AliYunLogConfig.WEB, "参数错误 Params == null");
finish();
return;
}
......@@ -387,7 +392,7 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
tb_title.setOnRightTextClick((view, isActive) -> {
finish();
});
}else if(!TextUtils.isEmpty(rightText)&&webRightClickListener!=null) {
} else if (!TextUtils.isEmpty(rightText) && webRightClickListener != null) {
tb_title.setmRightText(rightText);
tb_title.setOnRightTextClick((view, isActive) -> {
webRightClickListener.onCLick(view);
......@@ -438,7 +443,7 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
if (null != uri && !TextUtils.isEmpty(host) && host.contains("nodeapi.ydl")) {
//马亮的需求,在nodeapi.ydl.com 地址后面拼上公共参数,用于判断是否为app
String uriAppendSuffix = jtoJHandle.getUriAppendSuffix();
resultUrl = WebUrlParamsUtils.getSuffix(url,uriAppendSuffix);
resultUrl = WebUrlParamsUtils.getSuffix(url, uriAppendSuffix);
}
} catch (Exception e) {
e.printStackTrace();
......@@ -479,7 +484,7 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
hideJavaTitleBar();
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
......@@ -616,15 +621,18 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
tb_title.setImage(getResources().getDrawable(R.drawable.web_common_back));
WebSettings setting = wv_content.getSettings();
setting.setJavaScriptEnabled(true);//支持js
setting.setDefaultTextEncodingName("GBK");//设置字符编码
//支持js
setting.setJavaScriptEnabled(true);
//设置字符编码
setting.setDefaultTextEncodingName("GBK");
setting.setDomStorageEnabled(true);
String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
setting.setAppCachePath(appCachePath);
setting.setAllowFileAccessFromFileURLs(true);
setting.setAppCacheEnabled(true);
setting.setAllowFileAccess(true);
setting.setBlockNetworkImage(false); // 解决图片不显示
// 解决图片不显示
setting.setBlockNetworkImage(false);
//设置自动缩放 degmi的测试题不能设置 不然界面展示有问题
if (h5Params.getUrl().contains("l.yidianling.com") || h5Params.getUrl().contains("l.ydl.com")) {
//l.yidianling.com 这个域名 只有云凤蝶使用 这个平台需要设置自适应 不然显示有问题
......@@ -641,8 +649,7 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
WebModularServiceUtils.Companion.startMain(NewH5Activity.this);
finish();
}
else {
} else {
if (ActivityManager.Companion.getInstance().getActivitys().size() == 1) {
WebModularServiceUtils.Companion.startMain(NewH5Activity.this);
}
......@@ -666,8 +673,9 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
if (newProgress == 100) {
wv_content.getProgressbar().setVisibility(GONE);
} else {
if (wv_content.getProgressbar().getVisibility() == GONE)
if (wv_content.getProgressbar().getVisibility() == GONE) {
wv_content.getProgressbar().setVisibility(VISIBLE);
}
wv_content.getProgressbar().setProgress(newProgress);
}
super.onProgressChanged(view, newProgress);
......@@ -682,6 +690,10 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
safeTipView.updateVisibility();
safeTipView.setLocation("orderList");
}
if (title.contains("404") || title.contains("500") || title.contains("Error")) {
AliYunLogHelper.Companion.getInstance()
.sendLog(AliYunLogConfig.WEB, "页面错误 : url:" + view.getUrl() + "title:" + title);
}
}
// For Android < 3.0
......@@ -697,12 +709,14 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
}
//For Android >= 4.1
@Override
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, WebChromeClient.FileChooserParams fileChooserParams) {
uploadMessageAboveL = filePathCallback;
openImageChooserActivity();
......@@ -721,15 +735,13 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
return overridePayUrl;
}
if (!TextUtils.isEmpty(url)&&url.endsWith(".apk")){
if (!TextUtils.isEmpty(url) && url.endsWith(".apk")) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
} else if (!TextUtils.isEmpty(url) && url.startsWith("http")) {
loadUrl(setUrlHeightParams(url));
} else {
if (YDLRouterManager.Companion.router(url)) {
} else {
if (!YDLRouterManager.Companion.router(url)) {
loadUrl(setUrlHeightParams(url));
}
}
......@@ -772,6 +784,8 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
AliYunLogHelper.Companion.getInstance()
.sendLog(AliYunLogConfig.WEB, "onReceivedError---- errorCode: " + errorCode + "----failingUrl:" + failingUrl);
loadFailed = true;
tb_title.setTitle("加载中");
if (wv_content != null) {
......@@ -803,20 +817,16 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
return overridePayUrl;
}
if (!TextUtils.isEmpty(url)&&url.endsWith(".apk")){
if (!TextUtils.isEmpty(url) && url.endsWith(".apk")) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
} else if (!TextUtils.isEmpty(url) && url.startsWith("http")) {
loadUrl(setUrlHeightParams(url));
} else {
if (YDLRouterManager.Companion.router(url)) {
} else {
if (!YDLRouterManager.Companion.router(url)) {
loadUrl(setUrlHeightParams(url));
}
}
return true;
}
......@@ -844,8 +854,7 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
tb_title.setImageListener(v -> {
if (wv_content.canGoBack()) {
wv_content.goBack();
}
else {
} else {
finish();
}
});
......@@ -859,8 +868,7 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
if (h5Params.getShowUrlTitle()) {
WebModularServiceUtils.Companion.startMain(NewH5Activity.this);
finish();
}
else {
} else {
if (ActivityManager.Companion.getInstance().getActivitys().size() == 1) {
WebModularServiceUtils.Companion.startMain(NewH5Activity.this);
}
......@@ -887,6 +895,8 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
AliYunLogHelper.Companion.getInstance()
.sendLog(AliYunLogConfig.WEB, "onReceivedError---- errorCode: " + errorCode + "----failingUrl:" + failingUrl);
tb_title.setTitle("加载中");
loadFailed = true;
if (wv_content != null) {
......@@ -909,8 +919,9 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
});
}
wv_content.setDownloadListener((url, userAgent, contentDisposition, mimetype, contentLength) -> {
if (url != null && url.startsWith("http://"))
if (url != null && url.startsWith("http://")) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
});
initDuration = System.currentTimeMillis() - initStartTime;
workSpeedUtils = new NetWorkSpeedUtils(this);
......@@ -1079,7 +1090,7 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
return;
}
String resultUrl = h5Params.getSuffix() ? WebUrlParamsUtils.getSuffix(url,jtoJHandle.getUriAppendSuffix()) : url;
String resultUrl = h5Params.getSuffix() ? WebUrlParamsUtils.getSuffix(url, jtoJHandle.getUriAppendSuffix()) : url;
Log.e("AAAA", resultUrl);
wv_content.loadUrl(resultUrl);
pointBI(resultUrl);
......@@ -1097,7 +1108,7 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
private void initHead() {
// header
final MaterialHeader header = new MaterialHeader(this);
int[] colors = new int[]{getResources().getColor(R.color.platform_main_theme )};
int[] colors = new int[]{getResources().getColor(R.color.platform_main_theme)};
header.setColorSchemeColors(colors);
header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
int padding = (int) getResources().getDimension(R.dimen.platform_default_dis_size);
......@@ -1155,8 +1166,7 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
if (h5Params.isSplash()) {
WebModularServiceUtils.Companion.startMain(NewH5Activity.this);
finish();
}
else {
} else {
if (ActivityManager.Companion.getInstance().getActivitys().size() == 1) {
WebModularServiceUtils.Companion.startMain(NewH5Activity.this);
}
......@@ -1213,10 +1223,15 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
startActivityForResult(Intent.createChooser(i, "Image Chooser"), FILE_CHOOSER_RESULT_CODE);
}
//最后在OnActivityResult中接受返回的结果
/**
* 最后在OnActivityResult中接受返回的结果
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == FILE_CHOOSER_RESULT_CODE) {
if (null == uploadMessage && null == uploadMessageAboveL) return;
if (null == uploadMessage && null == uploadMessageAboveL) {
return;
}
Uri result = data == null || resultCode != RESULT_OK ? null : data.getData();
if (uploadMessageAboveL != null) {
onActivityResultAboveL(requestCode, resultCode, data);
......@@ -1250,8 +1265,9 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void onActivityResultAboveL(int requestCode, int resultCode, Intent intent) {
if (requestCode != FILE_CHOOSER_RESULT_CODE || uploadMessageAboveL == null)
if (requestCode != FILE_CHOOSER_RESULT_CODE || uploadMessageAboveL == null) {
return;
}
Uri[] results = null;
if (resultCode == Activity.RESULT_OK) {
if (intent != null) {
......@@ -1264,10 +1280,11 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
results[i] = item.getUri();
}
}
if (dataString != null)
if (dataString != null) {
results = new Uri[]{Uri.parse(dataString)};
}
}
}
uploadMessageAboveL.onReceiveValue(results);
uploadMessageAboveL = null;
}
......@@ -1278,8 +1295,6 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
/**
* 判断是否是测评题页面,如果是,则走测评题页面的返回逻辑
*/
if (keyCode == KeyEvent.KEYCODE_BACK) {
/**
* 是否是测评题目页面
......@@ -1358,7 +1373,9 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
} else {
tb_title.setImage_right(getResources().getDrawable(R.drawable.web_common_notice_more_un));
}
} catch (Exception e) {}
} catch (Exception e) {
e.printStackTrace();
}
}
if (backgroundView.getVisibility() == View.VISIBLE) {
backgroundView.setVisibility(View.GONE);
......@@ -1387,19 +1404,18 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
if (params != null && !TextUtils.isEmpty(params.getCourse_id())) {
dialog = YDLShareDialog.Companion.style5(this, shareTitle, shareUrl, shareDesc, cover);
} else {
if(!H5RouterUtils.INSTANCE.isDependByClz(IDynamicService.class)) {
if (!H5RouterUtils.INSTANCE.isDependByClz(IDynamicService.class)) {
//如果未引入动态模块的话,隐藏分享至动态按钮
dialog = YDLShareDialog.Companion.style4(this, shareTitle, shareUrl, shareDesc, cover);
}else {
} else {
dialog = YDLShareDialog.Companion.style1(this, shareTitle, shareUrl, shareDesc, cover, minPath, minId);
}
}
dialog.setCallBack(type -> {
if (1 == type) {
if (!WebModularServiceUtils.Companion.getUserService().loginByOneKeyLogin(NewH5Activity.this,true)) {
if (!WebModularServiceUtils.Companion.getUserService().loginByOneKeyLogin(NewH5Activity.this, true)) {
isToTrend = true;
} else {
//分享到心事动态
......
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