ShadowDrawable.java 文件源码

java
阅读 27 收藏 0 点赞 0 评论 0

项目:FullRobolectricTestSample 作者:
@Implementation // todo: this sucks, it's all just so we can detect 9-patches
public static Drawable createFromResourceStream(Resources res, TypedValue value,
                        InputStream is, String srcName, BitmapFactory.Options opts) {
  if (is == null) {
    return null;
  }
  Rect pad = new Rect();
  if (opts == null) opts = new BitmapFactory.Options();
  opts.inScreenDensity = DisplayMetrics.DENSITY_DEFAULT;

  Bitmap  bm = BitmapFactory.decodeResourceStream(res, value, is, pad, opts);
  if (bm != null) {
    boolean isNinePatch = srcName != null && srcName.contains(".9.");
    if (isNinePatch) {
      method("setNinePatchChunk").withParameterTypes(byte[].class).in(bm).invoke(new byte[0]);
    }

    byte[] np = bm.getNinePatchChunk();
    if (np == null || !NinePatch.isNinePatchChunk(np)) {
      np = null;
      pad = null;
    }
    int[] layoutBounds = method("getLayoutBounds").withReturnType(int[].class).in(bm).invoke();
    Rect layoutBoundsRect = null;
    if (layoutBounds != null) {
      layoutBoundsRect = new Rect(layoutBounds[0], layoutBounds[1],
          layoutBounds[2], layoutBounds[3]);
    }
    if (np != null) {
      // todo: wrong
      return new NinePatchDrawable(res, bm, np, pad, /*layoutBoundsRect,*/ srcName);
    }

    return new BitmapDrawable(res, bm);
  }
  return null;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号