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();
|
}
|
}
|
}
|