Browse Source

web transparent call other web

hanjing 7 years ago
parent
commit
fec34ef7f9

+ 16 - 0
app/src/main/java/com/sheep/gamegroup/event/WebViewEvent.java

@@ -0,0 +1,16 @@
+package com.sheep.gamegroup.event;
+
+public class WebViewEvent {
+
+    public final static int ACTION_REFRESH_GAME_MALL = 0;
+
+    public int action;
+    public String data;
+    public String callback;
+
+    public WebViewEvent(int action, String data, String callback) {
+        this.action = action;
+        this.data = data;
+        this.callback = callback;
+    }
+}

+ 29 - 1
app/src/main/java/com/sheep/gamegroup/module/game/fragment/FgtGameCenter.java

@@ -1,5 +1,6 @@
 package com.sheep.gamegroup.module.game.fragment;
 
+import android.os.Bundle;
 import android.support.design.widget.TabLayout;
 import android.support.v4.view.ViewPager;
 import android.text.TextUtils;
@@ -9,6 +10,7 @@ import android.widget.Button;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 
+import com.sheep.gamegroup.event.WebViewEvent;
 import com.sheep.gamegroup.model.entity.ArticleTag;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.UserEntity;
@@ -31,6 +33,9 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.base.BaseFragment;
 import com.sheep.jiuyan.samllsheep.utils.G;
 
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+
 import butterknife.BindView;
 import butterknife.OnClick;
 import io.reactivex.android.schedulers.AndroidSchedulers;
@@ -44,6 +49,20 @@ import rx.functions.Action1;
  */
 public class FgtGameCenter extends BaseFragment {
 
+    private FgtWebX5 gameMallFgt;
+
+    @Override
+    public void onCreate(Bundle bundle) {
+        super.onCreate(bundle);
+        EventBus.getDefault().register(this);
+    }
+
+    @Override
+    public void onDestroy() {
+        EventBus.getDefault().unregister(this);
+        super.onDestroy();
+    }
+
     @Override
     public int getLayoutId() {
         return R.layout.fgt_game_center;
@@ -77,7 +96,8 @@ public class FgtGameCenter extends BaseFragment {
         mAdapter.add(new FgtPlayGame(), "玩转游戏");
         mAdapter.add(FgtWebX5.newInstance(new WebParams(Config.getUrlByPath(Config.PATH_WELFARE_HOME))), "福利中心");
         mAdapter.add(FgtFindChild.newInstance(new ArticleTag(-1, 1)), "游戏资讯");
-        mAdapter.add(FgtWebX5.newInstance(new WebParams(Config.getUrlByPath(Config.PATH_GAME_SHOP_HOME))), "游戏商城");
+        gameMallFgt = FgtWebX5.newInstance(new WebParams(Config.getUrlByPath(Config.PATH_GAME_SHOP_HOME)));
+        mAdapter.add(gameMallFgt, "游戏商城");
         pager.setAdapter(mAdapter);
         indicator.setupWithViewPager(pager);
         CommonUtil.getInstance().reflex(indicator, getActivity(), false, G.WIDTH - G.getRealPix(144));
@@ -157,9 +177,17 @@ public class FgtGameCenter extends BaseFragment {
     public void doGoMyWalfare(View v) {
         Jump2View.getInstance().goMyWelfare(getActivity());
     }
+
     @OnClick(R.id.fgt_gc_hb_500_yuan_drl)
     public void goGet500YuanHb(View v) {
         Jump2View.getInstance().goWeb(SheepApp.getInstance().getCurrentActivity(), new WebParams(Config.getUrlByPath(Config.PATH_WELFARE_MONEY_REWARD_LIST)).setTitle(Config.NAME_WELFARE_MONEY_REWARD_LIST));
     }
 
+    @Subscribe
+    public void WhenWebViewEventComing(WebViewEvent ev) {
+        if (gameMallFgt != null) {
+            gameMallFgt.callTransparent(ev.callback, ev.data);
+        }
+    }
+
 }

+ 4 - 0
app/src/main/java/com/sheep/gamegroup/module/webview/fragment/FgtWebX5.java

@@ -618,4 +618,8 @@ public class FgtWebX5 extends BaseFgtWeb {
         });
     }
 
+    public void callTransparent(String callback, String data) {
+        loadJs(callback + "(" + data + ")");
+    }
+
 }

+ 8 - 0
app/src/main/java/com/sheep/gamegroup/util/js/KFZSJs.java

@@ -11,6 +11,7 @@ import android.webkit.JavascriptInterface;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.sheep.gamegroup.absBase.AbsObserver;
+import com.sheep.gamegroup.event.WebViewEvent;
 import com.sheep.gamegroup.model.api.IWeb;
 import com.sheep.gamegroup.model.entity.Article;
 import com.sheep.gamegroup.model.entity.BaseMessage;
@@ -46,6 +47,8 @@ import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
 import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
 
+import org.greenrobot.eventbus.EventBus;
+
 import java.util.Locale;
 
 import io.reactivex.android.schedulers.AndroidSchedulers;
@@ -511,4 +514,9 @@ public class KFZSJs {
             e.printStackTrace();
         }
     }
+
+    @JavascriptInterface
+    public void postEvent(int action, String data, String callback) {
+        EventBus.getDefault().post(new WebViewEvent(action, data, callback));
+    }
 }