wpc
2018-11-27 c52fb0e4d9168e75390b3cf3536d66c06c50d605
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
121
122
123
124
125
126
127
128
129
130
131
package com.haicaojie.android.ui.mine.weex;
 
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.Toast;
 
import com.haicaojie.android.R;
import com.lcjian.library.util.security.MD5Utils;
import com.taobao.weex.IWXRenderListener;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.common.WXRenderStrategy;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * Created by weikou2015 on 2018/6/13.
 * weex---调用页面
 */
 
public class WeexApplicationActivity extends AppCompatActivity implements IWXRenderListener {
 
    WXSDKInstance mWXSDKInstance;
    FrameLayout fl_weex_show;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_weex_show);
        /*
         * 计算状态栏高度并设置
         */
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            int result = 0;
            int resourceId = getResources().getIdentifier("status_bar_height",
                    "dimen", "android");
            if (resourceId > 0) {
                result = getResources().getDimensionPixelSize(resourceId);
            }
            //设置状态栏文字颜色及图标为深色
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    result);
            findViewById(R.id.v_status_bar).setLayoutParams(params);
        } else {
            findViewById(R.id.v_status_bar).setVisibility(View.GONE);
        }
 
        fl_weex_show = (FrameLayout) findViewById(R.id.fl_weex_show);
        /**
         * bundleUrl source http://dotwe.org/vue/38e202c16bdfefbdb88a8754f975454c
         */
        final String bundleUrl = "http://192.168.1.122:9000/weex/gonglue_android.js";
        final String pageName = MD5Utils.getMD532(bundleUrl);
 
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Map<String, Object> options = new HashMap<>();
                options.put(WXSDKInstance.BUNDLE_URL, bundleUrl);
                mWXSDKInstance = new WXSDKInstance(WeexApplicationActivity.this);
                mWXSDKInstance.registerRenderListener(WeexApplicationActivity.this);
 
                mWXSDKInstance.renderByUrl(pageName, bundleUrl, options, null, WXRenderStrategy.APPEND_ASYNC);
            }
        });
    }
 
    @Override
    public void onViewCreated(WXSDKInstance instance, View view) {
//        setContentView(view);
        fl_weex_show.addView(view);
    }
 
 
    @Override
    public void onRenderSuccess(WXSDKInstance instance, int width, int height) {
    }
 
    @Override
    public void onRefreshSuccess(WXSDKInstance instance, int width, int height) {
    }
 
    @Override
    public void onException(WXSDKInstance instance, String errCode, String msg) {
        Log.e("mResult", "错误码" + errCode + "\n错误信息" + msg);
        Toast.makeText(WeexApplicationActivity.this, msg, Toast.LENGTH_SHORT).show();
    }
 
    @Override
    protected void onResume() {
        super.onResume();
        if (mWXSDKInstance != null) {
            mWXSDKInstance.onActivityResume();
        }
    }
 
    @Override
    protected void onPause() {
        super.onPause();
        if (mWXSDKInstance != null) {
            mWXSDKInstance.onActivityPause();
        }
    }
 
    @Override
    protected void onStop() {
        super.onStop();
        if (mWXSDKInstance != null) {
            mWXSDKInstance.onActivityStop();
        }
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mWXSDKInstance != null) {
            mWXSDKInstance.onActivityDestroy();
        }
    }
}