Пример #1
0
    @Override
    public void run() {
      try {
        synchronized (imageCache) {
          mCallback.onStart(url);
        }

        Bitmap bitmap = null;
        if (url != null && !"".equals(url)) {
          byte[] b = getUrlBytes(url);
          /*
           * BitmapFactory.Options opts = new
           * BitmapFactory.Options(); opts.inJustDecodeBounds
           * = true;
           * BitmapFactory.decodeStream(getUrlInputStream
           * (imgUrl), null, opts);
           *
           * opts.inSampleSize = computeSampleSize(opts, -1,
           * 128*128); opts.inJustDecodeBounds = false; try {
           * bitmap =
           * BitmapFactory.decodeStream(getUrlInputStream
           * (imgUrl), null, opts); } catch (OutOfMemoryError
           * err) { }
           */
          bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
          // Bitmap bitmap = BitmapFactory.decodeStream(bis);
        }
        Message msg = mHandler.obtainMessage();
        Map<String, Bitmap> bitmapMap = new HashMap<String, Bitmap>();
        bitmapMap.put(url, bitmap);
        msg.obj = bitmapMap;
        mHandler.sendMessage(msg);
      } catch (Exception e) {
        e.printStackTrace();
        synchronized (imageCache) {
          mCallback.onFailed(url);
        }
      }
    }