Js调用原生整改
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import static com.yunbao.common.CommonAppConfig.isGetNewWrap;
|
||||
import static com.yunbao.common.CommonAppContext.logger;
|
||||
import static com.yunbao.common.CommonAppContext.mFirebaseAnalytics;
|
||||
import static com.yunbao.common.utils.RouteUtil.PATH_COIN;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.adjust.sdk.Adjust;
|
||||
import com.adjust.sdk.AdjustEvent;
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@@ -37,6 +37,7 @@ public class JavascriptInterfaceUtils {
|
||||
private WebView mWebView;
|
||||
//判断是页面关闭还是网页回退
|
||||
private boolean pageClose = false;
|
||||
private boolean dialogClose = false;
|
||||
//同名activity跳转问题
|
||||
private boolean LiveZhuangBana = true;
|
||||
|
||||
@@ -45,6 +46,11 @@ public class JavascriptInterfaceUtils {
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavascriptInterfaceUtils setDialogClose(boolean dialogClose) {
|
||||
this.dialogClose = dialogClose;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JavascriptInterfaceUtils setLiveZhuangBana(boolean liveZhuangBana) {
|
||||
LiveZhuangBana = liveZhuangBana;
|
||||
return this;
|
||||
@@ -68,7 +74,13 @@ public class JavascriptInterfaceUtils {
|
||||
if (pageClose) {
|
||||
mContext.finish();
|
||||
} else {
|
||||
mContext.runOnUiThread(() -> mWebView.goBack());
|
||||
if (dialogClose) {
|
||||
Bus.get().post(new JavascriptInterfaceEvent()
|
||||
.setMethod("androidGoBack"));
|
||||
} else {
|
||||
mContext.runOnUiThread(() -> mWebView.goBack());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -419,11 +431,39 @@ public class JavascriptInterfaceUtils {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void AndroidAdjustPrank() {
|
||||
AdjustEvent adjustEvent1 = new AdjustEvent("v1nekv");
|
||||
Adjust.trackEvent(adjustEvent1);
|
||||
mFirebaseAnalytics.logEvent("FS_prank_interaction", null);
|
||||
logger.logEvent("FB_prank_interaction", null);
|
||||
Bus.get().post(new JavascriptInterfaceEvent()
|
||||
.setMethod("AndroidAdjustPrank"));
|
||||
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void openWrap() {
|
||||
Bus.get().post(new JavascriptInterfaceEvent()
|
||||
.setMethod("openWrap"));
|
||||
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void androidSignGift(String json) {
|
||||
Bus.get().post(new JavascriptInterfaceEvent()
|
||||
.setMethod("androidSignGift")
|
||||
.setData(json));
|
||||
|
||||
}
|
||||
@JavascriptInterface
|
||||
public void setHeight(String height, String width) {
|
||||
if ("0".equals(height)) {
|
||||
return;
|
||||
}
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(() -> {
|
||||
ViewGroup.LayoutParams params = mWebView.getLayoutParams();
|
||||
params.height = DpUtil.dp2px(Integer.parseInt(height));
|
||||
mWebView.setLayoutParams(params);
|
||||
mWebView.setVisibility(View.VISIBLE);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user