Java Code Examples for com.taobao.weex.WXEnvironment#getApplication()

The following examples show how to use com.taobao.weex.WXEnvironment#getApplication() . 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: 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 2
Source File: CheckForUpdateUtil.java    From incubator-weex-playground with Apache License 2.0 4 votes vote down vote up
public static String getStringRes(int id) {
  if (WXEnvironment.getApplication() != null) {
    return WXEnvironment.getApplication().getString(id);
  }
  return "";
}