Example #1
0
  @Kroll.method
  public TiBlob getFilteredImage(Object image, @Kroll.argument(optional = true) HashMap options) {
    String cacheKey = null;
    if (image instanceof String) {
      cacheKey = (String) image;
    } else if (image instanceof TiBlob) {
      cacheKey = ((TiBlob) image).getCacheKey();
    } else {
      cacheKey = java.lang.System.identityHashCode(image) + "";
    }
    Drawable drawable = TiUIHelper.buildImageDrawable(getActivity(), image, false, this);
    if (drawable == null) {
      return null;
    }

    Pair<Drawable, KrollDict> result = null;
    if (options != null) {
      if (options.containsKey("callback")) {
        KrollFunction callback = (KrollFunction) options.get("callback");
        options.remove("callback");
        if (callback != null) {
          (new FilterDrawableTask()).execute(this, drawable, options, callback);
          return null;
        }
      }
      result = TiImageHelper.drawableFiltered(drawable, options, cacheKey, false);
    }

    if (result != null) {
      TiBlob blob = TiBlob.blobFromObject(result.first);
      blob.addInfo(result.second);
      return blob;
    }
    return null;
  }