com.taobao.weex.common.WXImageStrategy Java Examples

The following examples show how to use com.taobao.weex.common.WXImageStrategy. 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: WXImageAdapter.java    From CrazyDaily with Apache License 2.0 6 votes vote down vote up
@Override
public void setImage(String url, ImageView view, WXImageQuality quality, WXImageStrategy strategy) {

    if (TextUtils.isEmpty(url)) {
        return;
    }
    final Context context = view.getContext();

    if (url.startsWith("mipmap://")) {
        String resIdStr = getResIdStr(url);
        if (TextUtils.isEmpty(resIdStr)) {
            return;
        }
        int imgId = context.getResources().getIdentifier(resIdStr, "mipmap", context.getPackageName());
        view.setImageResource(imgId);
        return;
    }
    ImageLoader.load(context, url, view);
}
 
Example #2
Source File: ImageAdapter.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
public void setImage(final String url, final ImageView view,
                     WXImageQuality quality, WXImageStrategy strategy) {

  WXSDKManager.getInstance().postOnUiThread(new Runnable() {

    @Override
    public void run() {
      if(view==null||view.getLayoutParams()==null){
        return;
      }
      if (TextUtils.isEmpty(url)) {
        view.setImageBitmap(null);
        return;
      }
      String temp = url;
      if (url.startsWith("//")) {
        temp = "http:" + url;
      }
      if (view.getLayoutParams().width <= 0 || view.getLayoutParams().height <= 0) {
        return;
      }
      Picasso.with(WXEnvironment.getApplication())
          .load(temp)
          .into(view);
    }
  },0);
}
 
Example #3
Source File: WXImage.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = WXDomPropConstant.WX_ATTR_SRC)
public void setSrc(String src) {

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

    WXImageSharpen imageSharpen = mDomObj.attr.getImageSharpen();
    imageStrategy.isSharpen = imageSharpen == WXImageSharpen.SHARPEN;

    IWXImgLoaderAdapter imgLoaderAdapter = mInstance.getImgLoaderAdapter();
    if (imgLoaderAdapter != null) {
        imgLoaderAdapter.setImage(src, ((ImageView) getView()),
                mDomObj.attr.getImageQuality(), imageStrategy);
    }
}
 
Example #4
Source File: ImageAdapter.java    From incubator-weex-playground with Apache License 2.0 4 votes vote down vote up
@Override
public void setImage(final String url, final ImageView view,
                     WXImageQuality quality, final WXImageStrategy strategy) {
  Runnable runnable = new Runnable() {

    @Override
    public void run() {
      if(view==null||view.getLayoutParams()==null){
        return;
      }
      if (TextUtils.isEmpty(url)) {
        view.setImageBitmap(null);
        return;
      }
      if (null != strategy){
        recordImgLoadAction(strategy.instanceId);
      }

      String temp = url;
      if (url.startsWith("//")) {
        temp = "http:" + url;
      }

      if(!TextUtils.isEmpty(strategy.placeHolder)){
        Picasso.Builder builder=new Picasso.Builder(WXEnvironment.getApplication());
        Picasso picasso=builder.build();
        picasso.load(Uri.parse(strategy.placeHolder)).into(view);

        view.setTag(strategy.placeHolder.hashCode(),picasso);
      }

      Picasso.with(WXEnvironment.getApplication())
              .load(temp)
              .transform(new BlurTransformation(strategy.blurRadius))
              .into(view, new Callback() {
                @Override
                public void onSuccess() {
                  if(strategy.getImageListener()!=null){
                    strategy.getImageListener().onImageFinish(url,view,true,null);
                  }
                  recordImgLoadResult(strategy.instanceId,true,null);

                  if(!TextUtils.isEmpty(strategy.placeHolder)){
                    ((Picasso) view.getTag(strategy.placeHolder.hashCode())).cancelRequest(view);
                  }
                }

                @Override
                public void onError() {
                  if(strategy.getImageListener()!=null){
                    strategy.getImageListener().onImageFinish(url,view,false,null);
                  }
                  recordImgLoadResult(strategy.instanceId,false,null);
                }
              });
    }
  };
  if(Thread.currentThread() == Looper.getMainLooper().getThread()){
    runnable.run();
  }else {
    WXSDKManager.getInstance().postOnUiThread(runnable, 0);
  }
}
 
Example #5
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 #6
Source File: ImageAdapter.java    From yanxuan-weex-demo with MIT License 4 votes vote down vote up
@Override
public void setImage(final String url, final ImageView view,
                     WXImageQuality quality, final WXImageStrategy strategy) {

  WXSDKManager.getInstance().postOnUiThread(new Runnable() {

    @Override
    public void run() {
      if(view==null||view.getLayoutParams()==null){
        return;
      }
      if (TextUtils.isEmpty(url)) {
        view.setImageBitmap(null);
        return;
      }
      String temp = url;
      if (url.startsWith("//")) {
        temp = "http:" + url;
      }
      if (view.getLayoutParams().width <= 0 || view.getLayoutParams().height <= 0) {
        return;
      }


      if(!TextUtils.isEmpty(strategy.placeHolder)){
        Picasso.Builder builder=new Picasso.Builder(WXEnvironment.getApplication());
        Picasso picasso=builder.build();
        picasso.load(Uri.parse(strategy.placeHolder)).into(view);

        view.setTag(strategy.placeHolder.hashCode(),picasso);
      }

      Picasso.with(WXEnvironment.getApplication())
          .load(temp)
          .transform(new BlurTransformation(strategy.blurRadius))
          .into(view, new Callback() {
            @Override
            public void onSuccess() {
              if(strategy.getImageListener()!=null){
                strategy.getImageListener().onImageFinish(url,view,true,null);
              }

              if(!TextUtils.isEmpty(strategy.placeHolder)){
                ((Picasso) view.getTag(strategy.placeHolder.hashCode())).cancelRequest(view);
              }
            }

            @Override
            public void onError() {
              if(strategy.getImageListener()!=null){
                strategy.getImageListener().onImageFinish(url,view,false,null);
              }
            }
          });
    }
  },0);
}
 
Example #7
Source File: ImageAdapter.java    From weex-uikit with MIT License 4 votes vote down vote up
@Override
public void setImage(final String url, final ImageView view, WXImageQuality quality, final WXImageStrategy strategy) {
    WXSDKManager.getInstance().postOnUiThread(new Runnable() {
        @Override
        public void run() {
            if(view==null||view.getLayoutParams()==null){
                return;
            }
            if (TextUtils.isEmpty(url)) {
                view.setImageBitmap(null);
                return;
            }
            String temp = url;
            if (url.startsWith("//")) {
                temp = "https:" + url;
            }
            if (view.getLayoutParams().width <= 0 || view.getLayoutParams().height <= 0) {
                return;
            }
            if(!TextUtils.isEmpty(strategy.placeHolder)){
                Picasso.Builder builder=new Picasso.Builder(WXEnvironment.getApplication());
                Picasso picasso=builder.build();
                picasso.load(Uri.parse(strategy.placeHolder)).into(view);

                view.setTag(strategy.placeHolder.hashCode(),picasso);
            }
            Picasso.with(WXEnvironment.getApplication())
                    .load(temp)
                    .into(view, new Callback() {
                        @Override
                        public void onSuccess() {
                            if(strategy.getImageListener()!=null){
                                strategy.getImageListener().onImageFinish(url,view,true,null);
                            }

                            if(!TextUtils.isEmpty(strategy.placeHolder)){
                                ((Picasso) view.getTag(strategy.placeHolder.hashCode())).cancelRequest(view);
                            }
                        }
                        @Override
                        public void onError() {
                            if(strategy.getImageListener()!=null){
                                strategy.getImageListener().onImageFinish(url,view,false,null);
                            }
                        }
                    });
        }
    });
}
 
Example #8
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 #9
Source File: ImageAdapter.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
@Override
public void setImage(final String url, final ImageView view,
                     WXImageQuality quality, final WXImageStrategy strategy) {

  WXSDKManager.getInstance().postOnUiThread(new Runnable() {

    @Override
    public void run() {
      if(view==null||view.getLayoutParams()==null){
        return;
      }
      if (TextUtils.isEmpty(url)) {
        view.setImageBitmap(null);
        return;
      }
      String temp = url;
      if (url.startsWith("//")) {
        temp = "http:" + url;
      }
      if (view.getLayoutParams().width <= 0 || view.getLayoutParams().height <= 0) {
        return;
      }


      if(!TextUtils.isEmpty(strategy.placeHolder)){
        Picasso.Builder builder=new Picasso.Builder(WXEnvironment.getApplication());
        Picasso picasso=builder.build();
        picasso.load(Uri.parse(strategy.placeHolder)).into(view);

        view.setTag(strategy.placeHolder.hashCode(),picasso);
      }


      Picasso.with(WXEnvironment.getApplication())
          .load(temp)
          .into(view, new Callback() {
            @Override
            public void onSuccess() {
              if(strategy.getImageListener()!=null){
                strategy.getImageListener().onImageFinish(url,view,true,null);
              }

              if(!TextUtils.isEmpty(strategy.placeHolder)){
                ((Picasso) view.getTag(strategy.placeHolder.hashCode())).cancelRequest(view);
              }
            }

            @Override
            public void onError() {
              if(strategy.getImageListener()!=null){
                strategy.getImageListener().onImageFinish(url,view,false,null);
              }
            }
          });
    }
  },0);
}
 
Example #10
Source File: ImageAdapter.java    From WeexOne with MIT License 4 votes vote down vote up
@Override
public void setImage(final String url, final ImageView view,
                     WXImageQuality quality, final WXImageStrategy strategy) {

  WXSDKManager.getInstance().postOnUiThread(new Runnable() {

    @Override
    public void run() {
      if(view==null||view.getLayoutParams()==null){
        return;
      }
      if (TextUtils.isEmpty(url)) {
        view.setImageBitmap(null);
        return;
      }
      String temp = url;
      if (url.startsWith("//")) {
        temp = "http:" + url;
      }
      if (view.getLayoutParams().width <= 0 || view.getLayoutParams().height <= 0) {
        return;
      }


      if(!TextUtils.isEmpty(strategy.placeHolder)){
        Picasso.Builder builder=new Picasso.Builder(WXEnvironment.getApplication());
        Picasso picasso=builder.build();
        picasso.load(Uri.parse(strategy.placeHolder)).into(view);

        view.setTag(strategy.placeHolder.hashCode(),picasso);
      }


      Picasso.with(WXEnvironment.getApplication())
          .load(temp)
          .into(view, new Callback() {
            @Override
            public void onSuccess() {
              if(strategy.getImageListener()!=null){
                strategy.getImageListener().onImageFinish(url,view,true,null);
              }

              if(!TextUtils.isEmpty(strategy.placeHolder)){
                ((Picasso) view.getTag(strategy.placeHolder.hashCode())).cancelRequest(view);
              }
            }

            @Override
            public void onError() {
              if(strategy.getImageListener()!=null){
                strategy.getImageListener().onImageFinish(url,view,false,null);
              }
            }
          });
    }
  },0);
}
 
Example #11
Source File: IWXImgLoaderAdapter.java    From ucar-weex-core with Apache License 2.0 votes vote down vote up
void setImage(String url, ImageView view, WXImageQuality quality, WXImageStrategy strategy); 
Example #12
Source File: IWXImgLoaderAdapter.java    From weex-uikit with MIT License votes vote down vote up
void setImage(String url, ImageView view, WXImageQuality quality, WXImageStrategy strategy); 
Example #13
Source File: IWXImgLoaderAdapter.java    From weex with Apache License 2.0 votes vote down vote up
void setImage(String url, ImageView view, WXImageQuality quality, WXImageStrategy strategy);