lwb
2020-12-07 60c805f6f058cdf8ef1ff3c35e788c18cc7b58fb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.secondworld.demo;
 
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.widget.RelativeLayout;
 
import com.secondworld.sdk.GTGameApp;
import com.secondworld.sdk.GameActivityProxy;
import com.secondworld.sdk.UnityMsgHandler;
import com.secondworld.sdk.utils.CodeU2A;
import com.secondworld.sdk.utils.LogUtil;
import com.secondworld.sdk.utils.WebViewUtil;
 
import org.json.JSONException;
import org.json.JSONObject;
 
public class MainActivity extends Activity {
 
    private static Class<? extends GameActivityProxy> proxyClass;
 
    GameActivityProxy proxy;
 
    //注册代理类
    public static void registerProxy(Class<? extends GameActivityProxy> proxyClass) {
        MainActivity.proxyClass = proxyClass;
    }
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        RelativeLayout webContainer = findViewById(com.secondworld.sdk.R.id.webContainer);
        WebViewUtil.I.init(this, webContainer);
        try {
            if (proxyClass != null) {
                proxy = proxyClass.newInstance();
                proxy.onCreate(this);
            } else
                LogUtil.w("GameActivity", "proxyClass 不存在");
        } catch (IllegalAccessException | InstantiationException e) {
            e.printStackTrace();
            LogUtil.e("GameActivity", e);
        }
        addEvent();
    }
 
    private void addEvent() {
        findViewById(R.id.login).setOnClickListener((v ->
        {
            JSONObject json = new JSONObject();
            try {
                json.put("code", CodeU2A.OpenWebView);
                json.put("url", "http://sydownload.secondworld.net.cn/xmzc/notice/noticeweb/notice_bt.html");
            } catch (JSONException e) {
                e.printStackTrace();
            }
            UnityMsgHandler.onUnityMessage(json.toString());
        }));
 
        findViewById(R.id.pay).setOnClickListener((v -> {
            JSONObject json = new JSONObject();
            try {
                json.put("code", CodeU2A.PlatformPay);
                json.put("cpInfo", "com.sanxiagame.zmjgp099");
                json.put("orderId", System.currentTimeMillis() / 1000 + "");
                json.put("sid", "1");
                json.put("roleID", "test_role");
                json.put("title", "goods_100");
                json.put("mount", "0.01");
            } catch (JSONException e) {
                e.printStackTrace();
            }
            UnityMsgHandler.onUnityMessage(json.toString());
        }));
    }
 
    @Override
    protected void onStart() {
        super.onStart();
        if (proxy != null)
            proxy.onStart();
    }
 
    @Override
    protected void onResume() {
        super.onResume();
        if (proxy != null)
            proxy.onResume();
    }
 
    @Override
    protected void onPause() {
        super.onPause();
        if (proxy != null)
            proxy.onPause();
    }
 
    @Override
    protected void onStop() {
        super.onStop();
        if (proxy != null)
            proxy.onStop();
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (proxy != null)
            proxy.onDestroy();
    }
 
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (proxy != null)
            proxy.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
 
}