测试更改

This commit is contained in:
18401019693 2022-11-18 15:49:24 +08:00
parent 4a28abf5b7
commit 859d884941
20 changed files with 157 additions and 147 deletions

View File

@ -139,7 +139,7 @@ public class WebViewActivity extends AbsActivity {
}
});
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, mWebView).setPageClose(true).setLiveZhuangBana(false), "androidObject");
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);

View File

@ -40,6 +40,7 @@ public class JavascriptInterfaceUtils {
private boolean dialogClose = false;
//同名activity跳转问题
private boolean LiveZhuangBana = true;
private static JavascriptInterfaceUtils sInstance;
public JavascriptInterfaceUtils setPageClose(boolean pageClose) {
this.pageClose = pageClose;
@ -56,9 +57,21 @@ public class JavascriptInterfaceUtils {
return this;
}
public JavascriptInterfaceUtils(Activity mContext, WebView mWebView) {
public JavascriptInterfaceUtils setmContext(Activity mContext, WebView mWebView) {
this.mContext = mContext;
this.mWebView = mWebView;
return this;
}
public static JavascriptInterfaceUtils getInstance() {
if (sInstance == null) {
synchronized (CityUtil.class) {
if (sInstance == null) {
sInstance = new JavascriptInterfaceUtils();
}
}
}
return sInstance;
}
@ -453,6 +466,7 @@ public class JavascriptInterfaceUtils {
.setData(json));
}
@JavascriptInterface
public void setHeight(String height, String width) {
if ("0".equals(height)) {

View File

@ -140,7 +140,7 @@ public class WebViewActivityMedal extends AbsActivity {
}
});
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, mWebView), "androidObject");
mWebView.addJavascriptInterface( JavascriptInterfaceUtils.getInstance().setmContext(mContext, mWebView), "androidObject");
mWebView.getSettings().setJavaScriptEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

View File

@ -199,7 +199,7 @@ public class ZhuangBanActivity extends AbsActivity {
}
});
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, mWebView)
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(mContext, mWebView)
.setPageClose(true)
.setLiveZhuangBana(true), "androidObject");
mWebView.getSettings().setJavaScriptEnabled(true);

View File

@ -95,7 +95,7 @@ public class LiveFansFragment extends AbsDialogFragment {
});
mWebView.getSettings().setJavaScriptEnabled(true); // 是否开启JS支持
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, mWebView).setPageClose(false), "androidObject");
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(mContext, mWebView).setPageClose(false), "androidObject");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}

View File

@ -159,7 +159,7 @@ public class LiveGameDialogFragment extends AbsDialogFragment {
mWebView = (WebView) findViewById(R.id.rlWebview);
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
layout = (LinearLayout) findViewById(R.id.bg_layout);
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(getActivity(), mWebView)
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(getActivity(), mWebView)
.setLiveZhuangBana(true).
setDialogClose(true).
setPageClose(false), "androidObject");

View File

@ -146,7 +146,7 @@ public class LiveHDDialogFragment extends AbsDialogFragment {
mWebView = (WebView) findViewById(R.id.rlWebview);
htmlError = (TextView) findViewById(R.id.html_error);
findViewById(R.id.btn_back).setOnClickListener(v -> dismiss());
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(getActivity(), mWebView)
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(getActivity(), mWebView)
.setLiveZhuangBana(true).
setDialogClose(true).
setPageClose(false), "androidObject");

View File

@ -76,7 +76,7 @@ public class LiveOneDialogFragment extends AbsDialogFragment {
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mWebView = (WebView) findViewById(R.id.rlWebview);
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, mWebView), "androidObject");
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(mContext, mWebView), "androidObject");
mWebView.getSettings().setJavaScriptEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

View File

@ -75,7 +75,7 @@ public class TurnTableWebViewHolder extends AbsLivePageViewHolder implements Vie
});
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, mWebView), "androidObject");
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(mContext, mWebView), "androidObject");
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {

View File

@ -97,7 +97,7 @@ public class WishlistWebViewHolder extends AbsLivePageViewHolder implements View
// 自适应 屏幕大小界面
webSettings.setLoadWithOverviewMode(true);
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils((Activity) mContext, mWebView).setPageClose(false), "androidObject");
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext((Activity) mContext, mWebView).setPageClose(false), "androidObject");
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {

View File

@ -6,18 +6,17 @@ import static com.yunbao.common.CommonAppContext.mFirebaseAnalytics;
import static com.yunbao.main.activity.MyWalletActivity.dis;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.adjust.sdk.Adjust;
@ -28,19 +27,13 @@ import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.event.JavascriptInterfaceEvent;
import com.yunbao.common.http.CommonHttpUtil;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.GoogleBillingUtilNew;
import com.yunbao.common.utils.JavascriptInterfaceUtils;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.main.R;
import com.yunbao.main.views.TestWebViewClient;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.io.IOException;
import java.util.List;
@ -54,24 +47,11 @@ public class GoogleFragment extends Fragment {
private WebView rlWebview;
private String url;
String adid = null;
private Activity mContext;
@SuppressLint("ValidFragment")
public GoogleFragment(Activity context, String urls) {
public GoogleFragment(String urls) {
url = urls;
mContext = context;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bus.getOn(this);
}
@Override
public void onDetach() {
super.onDetach();
Bus.getOff(this);
Log.e("google", "111aa");
}
@Override
@ -114,7 +94,7 @@ public class GoogleFragment extends Fragment {
webSettings.setBuiltInZoomControls(true); // 是否支持缩放变焦前提是支持缩放
rlWebview.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, rlWebview).setPageClose(true), "androidObject");
rlWebview.addJavascriptInterface(new JsInteration(), "androidObject");
TestWebViewClient testWebViewClient = new TestWebViewClient(getActivity(), rlWebview);
@ -131,20 +111,19 @@ public class GoogleFragment extends Fragment {
}
private Handler payHandler = new Handler();
//js调用原生
public class JsInteration {
public void release() {
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onJavascriptInterfaceEvent(JavascriptInterfaceEvent event) {
if (!TextUtils.isEmpty(event.getMethod())) {
if (TextUtils.equals(event.getMethod(), "androidNewGoToGooglePay")) {
mProductId = event.getProductId();
mOrderid = event.getOrderNumber();
MoneyUsds = event.getMoneyUsd();
@JavascriptInterface
public void androidNewGoToGooglePay(String ProductId, String OrderNumber, String MoneyUsd) {
Log.e(TAG, "ProductId" + ProductId + "OrderNumber" + OrderNumber + "MoneyUsd" + MoneyUsd);
mProductId = ProductId;
mOrderid = OrderNumber;
MoneyUsds = MoneyUsd;
// googleBillingUtil.purchaseInApp(getActivity(), mProductId);
GoogleBillingUtilNew.getInstance().setBillingListener(new GoogleBillingUtilNew.GoogleBillingListener() {
@Override
public void onPaySuccess(List<Purchase> list) {
@ -198,11 +177,11 @@ public class GoogleFragment extends Fragment {
});
AdjustEvent adjustEvent2 = new AdjustEvent("tr8lb9");
adjustEvent2.setRevenue(Double.parseDouble(MoneyUsds), "HKD");
adjustEvent2.addCallbackParameter("GOrderid", purchase.getOrderId());
adjustEvent2.addCallbackParameter("POrderid", mOrderid);
adjustEvent2.setRevenue(Double.parseDouble(MoneyUsds),"HKD");
adjustEvent2.addCallbackParameter("GOrderid",purchase.getOrderId());
adjustEvent2.addCallbackParameter("POrderid",mOrderid);
adjustEvent2.addCallbackParameter("Uid", CommonAppConfig.getInstance().getUid());
adjustEvent2.addCallbackParameter("GADid", adid);
adjustEvent2.addCallbackParameter("GADid",adid);
adjustEvent2.setOrderId(mOrderid);
Adjust.trackEvent(adjustEvent2);
@ -220,9 +199,9 @@ public class GoogleFragment extends Fragment {
@Override
public void onPayFailed(int code, String msg) {
Log.e("谷歌支付",code+msg);
}
}).checkSku(event.getProductId())
}).checkSku(ProductId)
;
//下单
Bundle params = new Bundle();
@ -230,7 +209,24 @@ public class GoogleFragment extends Fragment {
params.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "HKD");
logger.logEvent(AppEventsConstants.EVENT_NAME_INITIATED_CHECKOUT, Double.parseDouble(MoneyUsds),
params);
}
@JavascriptInterface
public void androidMethodBack() {
getActivity().onBackPressed();
}
@JavascriptInterface
public void androidGoBack() {
getActivity().onBackPressed();
}
}
public void release() {
}
}

View File

@ -121,26 +121,26 @@ public class MyWalletActivity extends AbsActivity {
Log.i("tss", "首充");
if (CommonAppConfig.IS_GOOGLE_PLAY == false) {
//链接版本
fragments = new Fragment[]{new GoogleFragment(this, CommonAppConfig.HOST + "/index.php?g=Appapi&first_page=1&m=Mall&a=walletcoin&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
new GoogleFragment(this, CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&first_page=1&a=walletgold&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
fragments = new Fragment[]{new GoogleFragment(CommonAppConfig.HOST + "/index.php?g=Appapi&first_page=1&m=Mall&a=walletcoin&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
new GoogleFragment(CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&first_page=1&a=walletgold&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
new WalletFragment(this, CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&first_page=1&a=walletbean&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd")};
} else {
rView.setVisibility(View.VISIBLE);
fragments = new Fragment[]{new GoogleFragment(this, CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=googlepaycoin&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
new GoogleFragment(this, CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=googlepaygole&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
fragments = new Fragment[]{new GoogleFragment(CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=googlepaycoin&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
new GoogleFragment( CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=googlepaygole&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
new WalletFragment(this, CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&first_page=1&a=walletbean&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken())};
}
} else {
if (CommonAppConfig.IS_GOOGLE_PLAY == false) {
Log.i("tss", "不是首充");
//链接版本
fragments = new Fragment[]{new GoogleFragment(this, CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=walletcoin&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
new GoogleFragment(this, CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=walletgold&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
fragments = new Fragment[]{new GoogleFragment(CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=walletcoin&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
new GoogleFragment(CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=walletgold&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
new WalletFragment(this, CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=walletbean&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd")};
} else {
rView.setVisibility(View.VISIBLE);
fragments = new Fragment[]{new GoogleFragment(this, CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=googlepaycoin&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
new GoogleFragment(this, CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=googlepaygole&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
fragments = new Fragment[]{new GoogleFragment(CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=googlepaycoin&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
new GoogleFragment(CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=googlepaygole&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd"),
new WalletFragment(this, CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&first_page=1&a=walletbean&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken())};
}
}

View File

@ -200,7 +200,7 @@ public class MyWebViewActivity extends AbsActivity {
}
});
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, mWebView).setPageClose(true), "androidObject");
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(mContext, mWebView).setPageClose(true), "androidObject");
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);

View File

@ -172,7 +172,7 @@ public class MyWebViewActivity2 extends AbsActivity {
}
});
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, mWebView)
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(mContext, mWebView)
.setPageClose(true)
.setLiveZhuangBana(false), "androidObject");
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口

View File

@ -32,7 +32,7 @@ public class RechargeActivity extends AbsActivity {
webSettings.setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
rlWebview.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, rlWebview).setPageClose(true), "androidObject");
rlWebview.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(mContext, rlWebview).setPageClose(true), "androidObject");
TestWebViewClient testWebViewClient = new TestWebViewClient(this, rlWebview);

View File

@ -153,7 +153,7 @@ public class RewardActivity extends AbsActivity {
});
mWebView.getSettings().setJavaScriptEnabled(true); // 是否开启JS支持
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, mWebView)
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(mContext, mWebView)
.setPageClose(true)
.setLiveZhuangBana(false), "androidObject");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

View File

@ -53,7 +53,7 @@ public class WalletFragment extends Fragment {
webSettings.setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
rlWebview.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, rlWebview).setPageClose(true), "androidObject");
rlWebview.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(mContext, rlWebview).setPageClose(true), "androidObject");
TestWebViewClient testWebViewClient = new TestWebViewClient(getActivity(), rlWebview);

View File

@ -135,7 +135,7 @@ public class WeekWebViewActivity extends AbsActivity {
}
});
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, mWebView).setPageClose(true), "androidObject");
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(mContext, mWebView).setPageClose(true), "androidObject");
mWebView.getSettings().setJavaScriptEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

View File

@ -175,7 +175,7 @@ public class ZhuangBanActivity extends AbsActivity {
mWebView.getSettings().setJavaScriptEnabled(true); // 是否开启JS支持
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(mContext, mWebView)
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(mContext, mWebView)
.setPageClose(true)
.setLiveZhuangBana(false), "androidObject");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

View File

@ -111,7 +111,7 @@ public class MainHomeCommunityViewHolder extends AbsMainHomeChildViewHolder impl
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);// 不加载缓存内容
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
mWebView.addJavascriptInterface(new JavascriptInterfaceUtils(nowMainActivity, mWebView), "androidObject");
mWebView.addJavascriptInterface(JavascriptInterfaceUtils.getInstance().setmContext(nowMainActivity, mWebView), "androidObject");
rootView.addView(mWebView);