Exemplo n.º 1
0
    // Once complete, see if ImageView is still around and set bitmap.
    @Override
    protected void onPostExecute(Bitmap bitmap) {
      if (isCancelled()) {
        bitmap = null;
      }

      if (mCallback != null && bitmap != null) {
        final AppearBitmapLoader.Callback callback = mCallback.get();
        if (callback != null) {
          callback.onBitmapLoaded(bitmap);
          callback.setTextureLoadTask(null);
        }
      }
    }
Exemplo n.º 2
0
  public void loadBitmap(
      final AppearBitmapData data,
      final AppearBitmapLoader.Callback callback,
      final int reqW,
      final int reqH,
      final boolean doCache) {

    final String imageKey = getCacheKey(data);
    Bitmap bitmap = getBitmapFromMemCache(imageKey);

    if (bitmap != null) {
      callback.onBitmapLoaded(bitmap);
    } else {
      Activity av = (Activity) mContext;
      av.runOnUiThread(
          new Runnable() {
            public void run() {
              if (cancelPotentialWork(data, callback)) {
                final TextureLoadTask task = new TextureLoadTask(callback, reqW, reqH, doCache);
                callback.setTextureLoadTask(task);
                task.execute(data);
              }
            }
          });
    }
  }
Exemplo n.º 3
0
  public static boolean cancelPotentialWork(
      AppearBitmapData data, AppearBitmapLoader.Callback callback) {
    final TextureLoadTask task = (TextureLoadTask) callback.getTextureLoadTask();

    if (task != null && task instanceof TextureLoadTask) {
      final AppearBitmapData prevData = task.data;
      if (prevData != data) {
        // Cancel previous task
        task.cancel(true);
      } else {
        // The same work is already in progress
        return false;
      }
    }

    // No task associated with the ImageView, or an existing task was cancelled
    return true;
  }