com.taobao.weex.utils.WXFileUtils Java Examples

The following examples show how to use com.taobao.weex.utils.WXFileUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WeexActivity.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mWXSDKInstance = new WXSDKInstance(this);
    mWXSDKInstance.registerRenderListener(this);
    final Intent intent = getIntent();
    mWXSDKInstance.render(intent.getStringExtra(ActivityConstant.PAGE), WXFileUtils.loadAsset(intent.getStringExtra(ActivityConstant.PATH), this), null, null, WXRenderStrategy.APPEND_ASYNC);
}
 
Example #2
Source File: TabPagerFragment.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    String type = getArguments().getString("type");
    mGankIoContent = (FrameLayout) inflater.inflate(R.layout.layout_weex_gank_io, container, false);
    final Context context = getActivity();
    mWXSDKInstance = new WXSDKInstance(context);
    mWXSDKInstance.registerRenderListener(this);
    Map<String, Object> options = new HashMap<>();
    options.put("type", type);
    mWXSDKInstance.render("GankioList", WXFileUtils.loadAsset("weex/gankio/gankiolist.js", context), options, null, WXRenderStrategy.APPEND_ASYNC);
    return mGankIoContent;
}
 
Example #3
Source File: WXSDKInstance.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private void renderByUrlInternal(String pageName,
                                 final String url,
                                 Map<String, Object> options,
                                 final String jsonInitData,
                                 final WXRenderStrategy flag) {

  ensureRenderArchor();
  pageName = wrapPageName(pageName, url);
  mBundleUrl = url;
  if(WXSDKManager.getInstance().getValidateProcessor()!=null) {
    mNeedValidate = WXSDKManager.getInstance().getValidateProcessor().needValidate(mBundleUrl);
  }

  Map<String, Object> renderOptions = options;
  if (renderOptions == null) {
    renderOptions = new HashMap<>();
  }
  if (!renderOptions.containsKey(BUNDLE_URL)) {
    renderOptions.put(BUNDLE_URL, url);
  }

  Uri uri = Uri.parse(url);
  if (uri != null && TextUtils.equals(uri.getScheme(), "file")) {
    render(pageName, WXFileUtils.loadFileOrAsset(assembleFilePath(uri), mContext), renderOptions, jsonInitData, flag);
    return;
  }

  IWXHttpAdapter adapter = WXSDKManager.getInstance().getIWXHttpAdapter();

  WXRequest wxRequest = new WXRequest();
  wxRequest.url = rewriteUri(Uri.parse(url),URIAdapter.BUNDLE).toString();
  if (wxRequest.paramMap == null) {
    wxRequest.paramMap = new HashMap<String, String>();
  }
  wxRequest.paramMap.put(KEY_USER_AGENT, WXHttpUtil.assembleUserAgent(mContext,WXEnvironment.getConfig()));
  WXHttpListener httpListener =
      new WXHttpListener(pageName, renderOptions, jsonInitData, flag, System.currentTimeMillis());
  httpListener.setSDKInstance(this);
  adapter.sendRequest(wxRequest, (IWXHttpAdapter.OnHttpListener) httpListener);
}
 
Example #4
Source File: WXSDKInstanceTest.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  mockStatic(WXSoInstallMgrSdk.class);
  when(WXSoInstallMgrSdk.initSo("weexv8", 1, null)).thenReturn(true);
  WXSDKEngine.initialize(RuntimeEnvironment.application,new InitConfig.Builder().build());
  mInstance = createInstance();
  WXBridgeManagerTest.getLooper().idle();

  mockStatic(WXFileUtils.class);
  when(WXFileUtils.loadAsset(null,null)).thenReturn("{}");
}
 
Example #5
Source File: WXSDKInstance.java    From weex-uikit with MIT License 5 votes vote down vote up
private void renderByUrlInternal(String pageName,
                                 final String url,
                                 Map<String, Object> options,
                                 final String jsonInitData,
                                 final WXRenderStrategy flag) {

  ensureRenderArchor();
  pageName = wrapPageName(pageName, url);
  mBundleUrl = url;

  Map<String, Object> renderOptions = options;
  if (renderOptions == null) {
    renderOptions = new HashMap<>();
  }
  if (!renderOptions.containsKey(BUNDLE_URL)) {
    renderOptions.put(BUNDLE_URL, url);
  }

  Uri uri = Uri.parse(url);
  if (uri != null && TextUtils.equals(uri.getScheme(), "file")) {
    render(pageName, WXFileUtils.loadAsset(assembleFilePath(uri), mContext), renderOptions, jsonInitData, flag);
    return;
  }

  IWXHttpAdapter adapter = WXSDKManager.getInstance().getIWXHttpAdapter();

  WXRequest wxRequest = new WXRequest();
  wxRequest.url = rewriteUri(Uri.parse(url),URIAdapter.BUNDLE).toString();
  if (wxRequest.paramMap == null) {
    wxRequest.paramMap = new HashMap<String, String>();
  }
  wxRequest.paramMap.put(KEY_USER_AGENT, WXHttpUtil.assembleUserAgent(mContext,WXEnvironment.getConfig()));
  adapter.sendRequest(wxRequest, new WXHttpListener(pageName, renderOptions, jsonInitData, flag, System.currentTimeMillis()));
}
 
Example #6
Source File: WXSDKInstanceTest.java    From weex-uikit with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
  mockStatic(WXSoInstallMgrSdk.class);
  when(WXSoInstallMgrSdk.initSo("weexv8", 1, null)).thenReturn(true);
  WXSDKEngine.initialize(RuntimeEnvironment.application,new InitConfig.Builder().build());
  mInstance = createInstance();
  WXBridgeManagerTest.getLooper().idle();

  mockStatic(WXFileUtils.class);
  when(WXFileUtils.loadAsset(null,null)).thenReturn("{}");
}
 
Example #7
Source File: IndexActivity.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
  int id = item.getItemId();
  if (id == R.id.action_refresh) {
    if(!TextUtils.equals(CURRENT_IP,DEFAULT_IP)){
      createWeexInstance();
      if(TextUtils.equals(CURRENT_IP,DEFAULT_IP)){
        renderPage(WXFileUtils.loadAsset("index.js", this),WEEX_INDEX_URL);
      }else{
        renderPageByURL(WEEX_INDEX_URL);
      }
      mProgressBar.setVisibility(View.VISIBLE);
      return true;
    }
  } else if (id == R.id.action_scan) {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
      if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
        Toast.makeText(this, "please give me the permission", Toast.LENGTH_SHORT).show();
      } else {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, CAMERA_PERMISSION_REQUEST_CODE);
      }
    } else {
      startActivity(new Intent(this, CaptureActivity.class));
    }
    return true;
  }
  return super.onOptionsItemSelected(item);
}
 
Example #8
Source File: IndexActivity.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_index);
  setContainer((ViewGroup) findViewById(R.id.index_container));
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  toolbar.setTitle("WEEX");
  setSupportActionBar(toolbar);

  mProgressBar = (ProgressBar) findViewById(R.id.index_progressBar);
  mTipView = (TextView) findViewById(R.id.index_tip);
  mProgressBar.setVisibility(View.VISIBLE);
  mTipView.setVisibility(View.VISIBLE);


  if(!WXSoInstallMgrSdk.isCPUSupport()){
    mProgressBar.setVisibility(View.INVISIBLE);
    mTipView.setText(R.string.cpu_not_support_tip);
    return;
  }

  if(TextUtils.equals(CURRENT_IP,DEFAULT_IP)){
    renderPage(WXFileUtils.loadFileContent("index.js", this),WEEX_INDEX_URL);
  }else{
    renderPageByURL(WEEX_INDEX_URL);
  }
}
 
Example #9
Source File: IndexActivity.java    From incubator-weex-playground with Apache License 2.0 4 votes vote down vote up
@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_index);
    setContainer((ViewGroup) findViewById(R.id.index_container));
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getWindow().setFormat(PixelFormat.TRANSLUCENT);

    mProgressBar = (ProgressBar) findViewById(R.id.index_progressBar);
    mTipView = (TextView) findViewById(R.id.index_tip);
    mProgressBar.setVisibility(View.VISIBLE);
    mTipView.setVisibility(View.VISIBLE);


    if (!WXSoInstallMgrSdk.isCPUSupport()) {
      mProgressBar.setVisibility(View.INVISIBLE);
      mTipView.setText(R.string.cpu_not_support_tip);
      return;
    }

    if (TextUtils.equals(sCurrentIp, DEFAULT_IP)) {
      renderPage(WXFileUtils.loadAsset("landing.weex.js", this), getIndexUrl());
//      renderPageByURL("http://dotwe.org/raw/dist/2bbe1860da4669a68595c1aed01d7fd2.bundle.wx");
    } else {
      renderPageByURL(getIndexUrl());
    }


    mReloadReceiver = new BroadcastReceiver() {
      @Override
      public void onReceive(Context context, Intent intent) {
        createWeexInstance();
        if (TextUtils.equals(sCurrentIp, DEFAULT_IP)) {
          renderPage(WXFileUtils.loadAsset("landing.weex.js", getApplicationContext()), getIndexUrl());
        } else {
          renderPageByURL(getIndexUrl());
        }
        mProgressBar.setVisibility(View.VISIBLE);
      }
    };

    LocalBroadcastManager.getInstance(this).registerReceiver(mReloadReceiver, new IntentFilter(WXSDKEngine.JS_FRAMEWORK_RELOAD));

    CheckForUpdateUtil.checkForUpdate(this);
  }
 
Example #10
Source File: IndexActivity.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_index);
  setContainer((ViewGroup) findViewById(R.id.index_container));
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  toolbar.setTitle("WEEX");
  setSupportActionBar(toolbar);

  mProgressBar = (ProgressBar) findViewById(R.id.index_progressBar);
  mTipView = (TextView) findViewById(R.id.index_tip);
  mProgressBar.setVisibility(View.VISIBLE);
  mTipView.setVisibility(View.VISIBLE);


  if(!WXSoInstallMgrSdk.isCPUSupport()){
    mProgressBar.setVisibility(View.INVISIBLE);
    mTipView.setText(R.string.cpu_not_support_tip);
    return;
  }

  if(TextUtils.equals(CURRENT_IP,DEFAULT_IP)){
    renderPage(WXFileUtils.loadAsset("index.js", this),WEEX_INDEX_URL);
  }else{
    renderPageByURL(WEEX_INDEX_URL);
  }


  mReloadReceiver=new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
      createWeexInstance();
      if(TextUtils.equals(CURRENT_IP,DEFAULT_IP)){
        renderPage(WXFileUtils.loadAsset("index.js", IndexActivity.this),WEEX_INDEX_URL);
      }else{
        renderPageByURL(WEEX_INDEX_URL);
      }
      mProgressBar.setVisibility(View.VISIBLE);
    }
  };

  LocalBroadcastManager.getInstance(this).registerReceiver(mReloadReceiver,new IntentFilter(WXSDKEngine.JS_FRAMEWORK_RELOAD));
}
 
Example #11
Source File: WXSDKInstanceTest.java    From ucar-weex-core with Apache License 2.0 3 votes vote down vote up
@Test
public void testRender() throws Exception {
  assertEquals(WXFileUtils.loadAsset(null,null),"{}");

  mInstance.render("{}",null,null,null);

}
 
Example #12
Source File: MainActivity.java    From weex-uikit with MIT License 3 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);


    mWXSDKInstance = new WXSDKInstance(this);
    mWXSDKInstance.registerRenderListener(this);

    mWXSDKInstance.render(WXFileUtils.loadAsset("index.js", this));
}
 
Example #13
Source File: WXSDKInstanceTest.java    From weex-uikit with MIT License 3 votes vote down vote up
@Test
public void testRender() throws Exception {
  assertEquals(WXFileUtils.loadAsset(null,null),"{}");

  mInstance.render("{}",null,null,null);

}