com.taobao.weex.adapter.URIAdapter Java Examples

The following examples show how to use com.taobao.weex.adapter.URIAdapter. 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: WXStreamModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
private void sendRequest(Options options,ResponseCallback callback,JSCallback progressCallback){
  WXRequest wxRequest = new WXRequest();
  wxRequest.method = options.getMethod();
  wxRequest.url = mWXSDKInstance.rewriteUri(Uri.parse(options.getUrl()), URIAdapter.REQUEST).toString();
  wxRequest.body = options.getBody();
  wxRequest.timeoutMs = options.getTimeout();

  if(options.getHeaders()!=null)
  if (wxRequest.paramMap == null) {
    wxRequest.paramMap = options.getHeaders();
  }else{
    wxRequest.paramMap.putAll(options.getHeaders());
  }


  IWXHttpAdapter adapter = ( mAdapter==null && mWXSDKInstance != null) ? mWXSDKInstance.getWXHttpAdapter() : mAdapter;
  if (adapter != null) {
    adapter.sendRequest(wxRequest, new StreamHttpListener(callback,progressCallback));
  }else{
    WXLogUtils.e("WXStreamModule","No HttpAdapter found,request failed.");
  }
}
 
Example #2
Source File: WXStreamModule.java    From weex-uikit with MIT License 6 votes vote down vote up
private void sendRequest(Options options,ResponseCallback callback,JSCallback progressCallback){
  WXRequest wxRequest = new WXRequest();
  wxRequest.method = options.getMethod();
  wxRequest.url = mWXSDKInstance.rewriteUri(Uri.parse(options.getUrl()), URIAdapter.REQUEST).toString();
  wxRequest.body = options.getBody();
  wxRequest.timeoutMs = options.getTimeout();

  if(options.getHeaders()!=null)
  if (wxRequest.paramMap == null) {
    wxRequest.paramMap = options.getHeaders();
  }else{
    wxRequest.paramMap.putAll(options.getHeaders());
  }


  IWXHttpAdapter adapter = ( mAdapter==null && mWXSDKInstance != null) ? mWXSDKInstance.getWXHttpAdapter() : mAdapter;
  if (adapter != null) {
    adapter.sendRequest(wxRequest, new StreamHttpListener(callback,progressCallback));
  }else{
    WXLogUtils.e("WXStreamModule","No HttpAdapter found,request failed.");
  }
}
 
Example #3
Source File: ATagUtil.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static void onClick(View widget, String instanceId, String url) {
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
  if (instance == null) {
    return;
  }
  String href = instance.rewriteUri(Uri.parse(url), URIAdapter.LINK).toString();
  JSONArray array = new JSONArray();
  array.add(href);
  WXSDKManager.getInstance().getWXBridgeManager().
      callModuleMethod(instanceId, "event", "openURL", array);
}
 
Example #4
Source File: WXWeb.java    From weex-uikit with MIT License 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.SRC)
public void setUrl(String url) {
    if (TextUtils.isEmpty(url) || getHostView() == null) {
        return;
    }
    if (!TextUtils.isEmpty(url)) {
        loadUrl(getInstance().rewriteUri(Uri.parse(url), URIAdapter.WEB).toString());
    }
}
 
Example #5
Source File: ATagUtil.java    From weex-uikit with MIT License 5 votes vote down vote up
public static void onClick(View widget, String instanceId, String url) {
  String href = WXSDKManager.getInstance().getSDKInstance(instanceId).
      rewriteUri(Uri.parse(url), URIAdapter.LINK).toString();
  JSONArray array = new JSONArray();
  array.add(href);
  WXSDKManager.getInstance().getWXBridgeManager().
      callModuleMethod(instanceId, "event", "openURL", array);
}
 
Example #6
Source File: WXImage.java    From weex-uikit with MIT License 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.SRC)
public void setSrc(String src) {
  if (src == null) {
    return;
  }

  WXSDKInstance instance = getInstance();
  Uri rewrited = instance.rewriteUri(Uri.parse(src), URIAdapter.IMAGE);

  if (Constants.Scheme.LOCAL.equals(rewrited.getScheme())) {
    setLocalSrc(rewrited);
  } else {
    setRemoteSrc(rewrited);
  }
}
 
Example #7
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 #8
Source File: WXVideo.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.SRC)
public void setSrc(String src) {
  if (TextUtils.isEmpty(src) || getHostView() == null) {
    return;
  }

  if (!TextUtils.isEmpty(src)) {
    WXSDKInstance instance = getInstance();
    mWrapper.setVideoURI(instance.rewriteUri(Uri.parse(src), URIAdapter.VIDEO));
    mWrapper.getProgressBar().setVisibility(View.VISIBLE);
  }
}
 
Example #9
Source File: WXImage.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private void setBlurRadius(@NonNull String src, int blurRadius) {
  if(getInstance() != null && blurRadius != mBlurRadius) {
    Uri parsedUri = getInstance().rewriteUri(Uri.parse(src), URIAdapter.IMAGE);
    if(!Constants.Scheme.LOCAL.equals(parsedUri.getScheme())) {
      setRemoteSrc(parsedUri,blurRadius);
    }
  }
}
 
Example #10
Source File: WXImage.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.SRC)
public void setSrc(String src) {
  if (src == null) {
    return;
  }

  ImageView image = getHostView();
  if("".equals(src) && image != null){
    image.setImageDrawable(null);
    return;
  }

  this.mSrc = src;
  WXSDKInstance instance = getInstance();
  Uri rewrited = instance.rewriteUri(Uri.parse(src), URIAdapter.IMAGE);

  if (Constants.Scheme.LOCAL.equals(rewrited.getScheme())) {
    setLocalSrc(rewrited);
  } else {
    int blur = 0;
    if(getDomObject() != null) {
      String blurStr = getDomObject().getStyles().getBlur();
      blur = parseBlurRadius(blurStr);
    }
    setRemoteSrc(rewrited, blur);
  }
}
 
Example #11
Source File: WXWeb.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.SRC)
public void setUrl(String url) {
    if (TextUtils.isEmpty(url) || getHostView() == null) {
        return;
    }
    if (!TextUtils.isEmpty(url)) {
        loadUrl(getInstance().rewriteUri(Uri.parse(url), URIAdapter.WEB).toString());
    }
}
 
Example #12
Source File: WXVideo.java    From weex-uikit with MIT License 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.SRC)
public void setSrc(String src) {
  if (TextUtils.isEmpty(src) || getHostView() == null) {
    return;
  }

  if (!TextUtils.isEmpty(src)) {
    WXSDKInstance instance = getInstance();
    mWrapper.setVideoURI(instance.rewriteUri(Uri.parse(src), URIAdapter.VIDEO));
    mWrapper.getProgressBar().setVisibility(View.VISIBLE);
  }
}
 
Example #13
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 #14
Source File: WXWebComponent.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.SRC)
public void setUrl(String url) {
    if (TextUtils.isEmpty(url) || getHostView() == null) {
        return;
    }
    if (!TextUtils.isEmpty(url)) {
        loadUrl(getInstance().rewriteUri(Uri.parse(url), URIAdapter.WEB).toString());
    }
}
 
Example #15
Source File: WXImage.java    From weex-uikit with MIT License 4 votes vote down vote up
private void setRemoteSrc(Uri rewrited) {

      WXImageStrategy imageStrategy = new WXImageStrategy();
      imageStrategy.isClipping = true;

      WXImageSharpen imageSharpen = getDomObject().getAttrs().getImageSharpen();
      imageStrategy.isSharpen = imageSharpen == WXImageSharpen.SHARPEN;

      int radius = getDomObject().getStyles().getBlur();
      radius = Math.max(0, radius);
      imageStrategy.blurRadius = Math.min(10, radius);

      imageStrategy.setImageListener(new WXImageStrategy.ImageListener() {
        @Override
        public void onImageFinish(String url, ImageView imageView, boolean result, Map extra) {
          if (getDomObject() != null && getDomObject().getEvents().contains(Constants.Event.ONLOAD)) {
            Map<String, Object> params = new HashMap<String, Object>();
            Map<String, Object> size = new HashMap<>(2);
            if (imageView != null && imageView.getDrawable() != null && imageView.getDrawable() instanceof ImageDrawable) {
              size.put("naturalWidth", ((ImageDrawable) imageView.getDrawable()).getBitmapWidth());
              size.put("naturalHeight", ((ImageDrawable) imageView.getDrawable()).getBitmapHeight());
            } else {
              size.put("naturalWidth", 0);
              size.put("naturalHeight", 0);
            }

            if (getDomObject() != null && containsEvent(Constants.Event.ONLOAD)) {
              params.put("success", result);
              params.put("size", size);
              fireEvent(Constants.Event.ONLOAD, params);
            }
          }
        }
      });

      WXSDKInstance instance = getInstance();
      if (getDomObject().getAttrs().containsKey(Constants.Name.PLACE_HOLDER)) {
        String attr = (String) getDomObject().getAttrs().get(Constants.Name.PLACE_HOLDER);
        if (TextUtils.isEmpty(attr)) {
          imageStrategy.placeHolder = instance.rewriteUri(Uri.parse(attr), URIAdapter.IMAGE).toString();
        }
      }

      IWXImgLoaderAdapter imgLoaderAdapter = getInstance().getImgLoaderAdapter();
      if (imgLoaderAdapter != null) {
        imgLoaderAdapter.setImage(rewrited.toString(), getHostView(),
            getDomObject().getAttrs().getImageQuality(), imageStrategy);
      }
  }
 
Example #16
Source File: WXSDKInstance.java    From weex-uikit with MIT License 4 votes vote down vote up
public URIAdapter getURIAdapter(){
  return WXSDKManager.getInstance().getURIAdapter();
}
 
Example #17
Source File: InitConfig.java    From weex-uikit with MIT License 4 votes vote down vote up
public Builder setURIAdapter(URIAdapter URIAdapter) {
  mURIAdapter = URIAdapter;
  return this;
}
 
Example #18
Source File: InitConfig.java    From weex-uikit with MIT License 4 votes vote down vote up
public URIAdapter getURIAdapter() {
  return mURIAdapter;
}
 
Example #19
Source File: WXSDKManager.java    From weex-uikit with MIT License 4 votes vote down vote up
public @NonNull URIAdapter getURIAdapter() {
  if(mURIAdapter == null){
    mURIAdapter = new DefaultUriAdapter();
  }
  return mURIAdapter;
}
 
Example #20
Source File: WXSDKInstance.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
public URIAdapter getURIAdapter(){
  return WXSDKManager.getInstance().getURIAdapter();
}
 
Example #21
Source File: WXImage.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
private void setRemoteSrc(Uri rewrited,int blurRadius) {

      WXImageStrategy imageStrategy = new WXImageStrategy();
      imageStrategy.isClipping = true;

      WXImageSharpen imageSharpen = getDomObject().getAttrs().getImageSharpen();
      imageStrategy.isSharpen = imageSharpen == WXImageSharpen.SHARPEN;

      imageStrategy.blurRadius = Math.max(0, blurRadius);
      this.mBlurRadius = blurRadius;

      imageStrategy.setImageListener(new WXImageStrategy.ImageListener() {
        @Override
        public void onImageFinish(String url, ImageView imageView, boolean result, Map extra) {
          if (getDomObject() != null && getDomObject().getEvents().contains(Constants.Event.ONLOAD)) {
            Map<String, Object> params = new HashMap<String, Object>();
            Map<String, Object> size = new HashMap<>(2);
            if (imageView != null && imageView instanceof Measurable) {
              size.put("naturalWidth", ((Measurable) imageView).getNaturalWidth());
              size.put("naturalHeight", ((Measurable) imageView).getNaturalHeight());
            } else {
              size.put("naturalWidth", 0);
              size.put("naturalHeight", 0);
            }

            if (getDomObject() != null && containsEvent(Constants.Event.ONLOAD)) {
              params.put("success", result);
              params.put("size", size);
              fireEvent(Constants.Event.ONLOAD, params);
            }
          }
        }
      });

        String placeholder=null;
        if(getDomObject().getAttrs().containsKey(Constants.Name.PLACEHOLDER)){
            placeholder= (String) getDomObject().getAttrs().get(Constants.Name.PLACEHOLDER);
        }else if(getDomObject().getAttrs().containsKey(Constants.Name.PLACE_HOLDER)){
            placeholder=(String)getDomObject().getAttrs().get(Constants.Name.PLACE_HOLDER);
        }
        if(placeholder!=null){
            imageStrategy.placeHolder = getInstance().rewriteUri(Uri.parse(placeholder),URIAdapter.IMAGE).toString();
        }

      IWXImgLoaderAdapter imgLoaderAdapter = getInstance().getImgLoaderAdapter();
      if (imgLoaderAdapter != null) {
        imgLoaderAdapter.setImage(rewrited.toString(), getHostView(),
            getDomObject().getAttrs().getImageQuality(), imageStrategy);
      }
  }
 
Example #22
Source File: InitConfig.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
public Builder setURIAdapter(URIAdapter URIAdapter) {
  mURIAdapter = URIAdapter;
  return this;
}
 
Example #23
Source File: InitConfig.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
public URIAdapter getURIAdapter() {
  return mURIAdapter;
}
 
Example #24
Source File: WXSDKManager.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
public @NonNull URIAdapter getURIAdapter() {
  if(mURIAdapter == null){
    mURIAdapter = new DefaultUriAdapter();
  }
  return mURIAdapter;
}