コード例 #1
0
  /**
   * Load an image specified by the data parameter into an ImageView (override {@link
   * ImageWorker#processBitmap(Object)} to define the processing logic). A memory and disk cache
   * will be used if an {@link ImageCache} has been set using {@link
   * ImageWorker#setImageCache(ImageCache)}. If the image is found in the memory cache, it is set
   * immediately, otherwise an {@link AsyncTask} will be created to asynchronously load the bitmap.
   *
   * @param data The URL of the image to download.
   * @param imageView The ImageView to bind the downloaded image to.
   * @param isFromDisk TODO
   */
  public void loadImage(Object data, ImageView imageView, int width, boolean isFromDisk) {
    Bitmap bitmap = null;
    if (isFromDisk) {

      final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
      final AsyncDrawable asyncDrawable =
          new AsyncDrawable(mContext.getResources(), mLoadingBitmap, task);
      imageView.setImageDrawable(asyncDrawable);
      task.execute(data, width);

    } else {

      if (mImageCache != null) {
        bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data));
      }

      if (bitmap != null) {
        // Bitmap found in memory cache
        imageView.setImageBitmap(zoomImg(bitmap, width));
      } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        final AsyncDrawable asyncDrawable =
            new AsyncDrawable(mContext.getResources(), mLoadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);
        task.execute(data, width);
      }
    }
  }
コード例 #2
0
 public void loadBitmap(Message message, ImageView imageView) {
   Bitmap bm;
   try {
     bm =
         xmppConnectionService
             .getFileBackend()
             .getThumbnail(message, (int) (metrics.density * 288), true);
   } catch (FileNotFoundException e) {
     bm = null;
   }
   if (bm != null) {
     imageView.setImageBitmap(bm);
     imageView.setBackgroundColor(0x00000000);
   } else {
     if (cancelPotentialWork(message, imageView)) {
       imageView.setBackgroundColor(0xff333333);
       final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
       final AsyncDrawable asyncDrawable = new AsyncDrawable(getResources(), null, task);
       imageView.setImageDrawable(asyncDrawable);
       try {
         task.execute(message);
       } catch (final RejectedExecutionException ignored) {
       }
     }
   }
 }
コード例 #3
0
  // Called when a new Loader needs to be created
  public AsyncTaskLoader<List<LCBOEntity>> onCreateLoader(int id, Bundle args) {

    if (lastResult.image_thumb_url == null || lastResult.image_thumb_url.isEmpty()) {
      BitmapWorkerTask task = new BitmapWorkerTask(this, lastResult.itemNumber);
      task.execute(lastResult.itemNumber);
    }

    if (MainActivity.mCurrentLocation != null) {
      spinner.setVisibility(View.VISIBLE);
      LocationFetchTask locTask =
          new LocationFetchTask(
              MainActivity.mCurrentLocation,
              lastResult.itemNumber,
              new LocationFetchTask.LocationListener() {
                @Override
                public void onLocationsFetched(List<LCBOEntity> locations) {
                  lastLocations = locations;
                  addLastLocationsData();
                  spinner.setVisibility(View.GONE);
                }
              });
      locTask.execute(MainActivity.mCurrentLocation);
    }

    return new LCBOAPILoader(this, args, LCBOAPIParser.QueryType.kProductDetail);
  }
コード例 #4
0
ファイル: ListAdapter.java プロジェクト: sebas1989/AHRApp
 public void loadBitmap(int resId, ImageView imageView) {
   if (cancelPotentialWork(resId, imageView)) {
     final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
     imageView.setBackgroundResource(R.drawable.alexander_rossi_pilot);
     task.execute(resId);
   }
 }
コード例 #5
0
ファイル: ImageWorker.java プロジェクト: jpforny/Batuck
  /**
   * Load an image specified by the data parameter into an ImageView (override {@link
   * ImageWorker#processBitmap(Object)} to define the processing logic). A memory and disk cache
   * will be used if an {@link ImageCache} has been set using {@link ImageWorker#addImageCache}. If
   * the image is found in the memory cache, it is set immediately, otherwise an {@link AsyncTask}
   * will be created to asynchronously load the bitmap.
   *
   * @param data The URL of the image to download.
   * @param imageView The ImageView to bind the downloaded image to.
   */
  public void loadImage(Object data, ImageView imageView, Bitmap loadingBitmap) {
    if (data == null) {
      return;
    }

    Bitmap bitmap = null;

    if (mImageCache != null) {
      bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data));
    }

    if (bitmap != null) {
      // Bitmap found in memory cache
      imageView.setImageBitmap(bitmap);
    } else if (cancelPotentialWork(data, imageView)) {
      final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
      final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, loadingBitmap, task);
      imageView.setImageDrawable(asyncDrawable);

      if (UIUtils.hasHoneycomb()) {
        // On HC+ we execute on a dual thread executor. There really isn't much extra
        // benefit to having a really large pool of threads. Having more than one will
        // likely benefit network bottlenecks though.
        task.executeOnExecutor(DUAL_THREAD_EXECUTOR, data);
      } else {
        // Otherwise pre-HC the default is a thread pool executor (not ideal, serial
        // execution or a smaller number of threads would be better).
        task.execute(data);
      }
    }
  }
コード例 #6
0
 private void loadBitmap(int resId, ImageView imageView) {
   if (cancelPotentialWork(resId, imageView)) {
     final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
     final AsyncDrawable asyncDrawable = new AsyncDrawable(context.getResources(), null, task);
     imageView.setImageDrawable(asyncDrawable);
     task.execute(resId);
   }
 }
コード例 #7
0
 /**
  * Executes the given {@link BitmapWorkerTask} in parallel. On Honeycomb the default executor is a
  * serial executor so we explicitly use a parallel (thread pool) executor.
  */
 @TargetApi(Build.VERSION_CODES.HONEYCOMB)
 private void executeTaskInParallel(Object data, BitmapWorkerTask task) {
   if (EtcUtils.hasHoneycomb()) {
     // Execute in parallel
     task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, data);
   } else {
     task.execute(data);
   }
 }
コード例 #8
0
 public void loadImage(Object data, ImageSwitcher imageSwitcher, boolean fullScale, int width) {
   final BitmapWorkerTask task = new BitmapWorkerTask(imageSwitcher);
   final AsyncDrawable asyncDrawable =
       new AsyncDrawable(context.getResources(), loadingBitmap, task);
   imageSwitcher.setImageDrawable(asyncDrawable);
   task.fullScale = fullScale;
   task.width = width;
   task.imageSwitcher = imageSwitcher;
   task.execute(data);
 }
コード例 #9
0
 public static void loadBitmap(
     ViewerFragment hostFragment, String key, int position, ImageView imageView) {
   if (cancelPotentialWork(key, imageView)) {
     final BitmapWorkerTask task = new BitmapWorkerTask(hostFragment, imageView);
     final AsyncDrawable asyncDrawable =
         new AsyncDrawable(hostFragment.getResources(), hostFragment.mPlaceHolderBitmap, task);
     imageView.setImageDrawable(asyncDrawable);
     task.execute(key, position);
   }
 }
コード例 #10
0
 public void loadBitmap(String path, ImageView imageView, String name) {
   if (BitmapWorkerTask.cancelPotentialWork(path, imageView)) {
     final BitmapWorkerTask task = new BitmapWorkerTask(imageView, name);
     Bitmap bm =
         BitmapTools.decodeBitmapFromResource(context.getResources(), R.drawable.white, 200, 240);
     final AsyncDrawable asyncDrawable = new AsyncDrawable(context.getResources(), bm, task);
     imageView.setImageDrawable(asyncDrawable);
     task.execute(path);
   }
 }
コード例 #11
0
 /**
  * 异步加载图片,防止并发
  *
  * @param mContext
  * @param resId
  * @param imageView
  * @param reqHeight
  * @param reqWidth
  */
 public static void loadAsyncBitmap(
     Context mContext, int resId, ImageView imageView, int reqWidth, int reqHeight) {
   if (cancelPotentialWork(resId, imageView)) {
     Bitmap placeHolder =
         BitmapFactory.decodeResource(mContext.getResources(), R.drawable.icon_geo);
     final BitmapWorkerTask task = new BitmapWorkerTask(mContext, imageView);
     task.reqWidth = reqWidth;
     task.reqHeight = reqHeight;
     final AsyncDrawable asyncDrawable =
         new AsyncDrawable(mContext.getResources(), placeHolder, task);
     imageView.setImageDrawable(asyncDrawable);
     task.execute(resId);
   }
 }
コード例 #12
0
 private void loadBitmaps(int position, ImageView imageView) {
   ImgInfo data = imginfos.getItemAt(position);
   Bitmap bitmap = getBitmapFromMemoryCache(String.valueOf(data));
   if (bitmap == null) {
     imageView.setImageResource(R.drawable.empty_photo);
     BitmapWorkerTask task = new BitmapWorkerTask();
     taskCollection.add(task);
     task.execute(position);
   } else {
     if (imageView != null && bitmap != null) {
       imageView.setImageBitmap(bitmap);
     }
   }
 }
コード例 #13
0
ファイル: FeedImageLoader.java プロジェクト: pkkr/AntennaPod
 @SuppressLint("NewApi")
 public void loadThumbnailBitmap(FeedImage image, ImageView target) {
   if (image != null) {
     Bitmap bitmap = getBitmapFromThumbnailCache(image.getId());
     if (bitmap != null) {
       target.setImageBitmap(bitmap);
     } else {
       target.setImageResource(R.drawable.default_cover);
       BitmapWorkerTask worker = new BitmapWorkerTask(target, image, LENGTH_BASE_THUMBNAIL);
       if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
         worker.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
       } else {
         worker.execute();
       }
     }
   } else {
     target.setImageResource(R.drawable.default_cover);
   }
 }
  public void loadBitmap(String filePath, ImageView imageView, Context context) {
    if (cancelPotentialWork(filePath, imageView)) {

      BitmapFactory.Options options = new BitmapFactory.Options();

      // options.inSampleSize = 8;
      Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);
      if (bitmap != null) {
        bitmap = Bitmap.createScaledBitmap(bitmap, 110, 110, false);
        imageView.setImageBitmap(bitmap);
      } else {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        final AsyncDrawable asyncDrawable =
            new AsyncDrawable(context.getResources(), utils.icon, task);
        imageView.setImageDrawable(asyncDrawable);
        task.execute(filePath);
      }
    }
  }
コード例 #15
0
 /**
  * 加载Bitmap对象。此方法会在LruCache中检查所有屏幕中可见的ImageView的Bitmap对象,
  * 如果发现任何一个ImageView的Bitmap对象不在缓存中,就会开启异步线程去下载图片。
  *
  * @param firstVisibleItem 第一个可见的ImageView的下标
  * @param visibleItemCount 屏幕中总共可见的元素数
  */
 private void loadBitmaps(int firstVisibleItem, int visibleItemCount) {
   try {
     for (int i = firstVisibleItem; i < firstVisibleItem + visibleItemCount; i++) {
       String imageUrl = fileList.get(i);
       Bitmap bitmap = getBitmapFromMemoryCache(imageUrl);
       if (bitmap == null) { // 如果缓存没有
         BitmapWorkerTask task = new BitmapWorkerTask();
         taskCollection.add(task);
         task.execute(imageUrl); // 执行异步任务,并传入加载的图片url地址(这里是sd卡上的图片)
       } else {
         ImageView imageView = (ImageView) mImageWall.findViewWithTag(imageUrl);
         if (imageView != null && bitmap != null) {
           imageView.setImageBitmap(bitmap);
         }
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }