Exemple #1
0
    @Override
    protected Void doInBackground(Void... params) {
      File f = null;
      if (image.getFile_url() != null) {
        f = new File(image.getFile_url());
      }
      if (image.getFile_url() != null && f.exists()) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(image.getFile_url(), options);
        int sampleSize = calculateSampleSize(options.outWidth, options.outHeight);

        options.inJustDecodeBounds = false;
        options.inSampleSize = sampleSize;
        decodedBitmap = BitmapFactory.decodeFile(image.getFile_url(), options);
        if (decodedBitmap == null) {
          Log.i(
              TAG,
              "Bitmap could not be decoded in custom sample size. Trying default sample size (path was "
                  + image.getFile_url()
                  + ")");
          decodedBitmap = BitmapFactory.decodeFile(image.getFile_url());
        }
        if (decodedBitmap != null) {
          bitmap =
              Bitmap.createScaledBitmap(decodedBitmap, PREFERRED_LENGTH, PREFERRED_LENGTH, false);
          if (baseLength == LENGTH_BASE_COVER) {
            addBitmapToCoverCache(image.getId(), bitmap);
          } else if (baseLength == LENGTH_BASE_THUMBNAIL) {
            addBitmapToThumbnailCache(image.getId(), bitmap);
          }
        } else {
          Log.w(TAG, "Could not load bitmap. Using default image.");
          bitmap = BitmapFactory.decodeResource(target.getResources(), R.drawable.default_cover);
        }
        if (AppConfig.DEBUG) Log.d(TAG, "Finished loading bitmaps");
      } else {
        Log.e(TAG, "FeedImage has no valid file url. Using default image");
        bitmap = BitmapFactory.decodeResource(target.getResources(), R.drawable.default_cover);
        if (image.getFile_url() != null
            && !DownloadRequester.getInstance().isDownloadingFile(image)) {
          FeedManager.getInstance().notifyInvalidImageFile(PodcastApp.getInstance(), image);
        }
      }
      return null;
    }
Exemple #2
0
 @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);
   }
 }
Exemple #3
0
 public boolean isInCoverCache(FeedImage image) {
   return coverCache.get(image.getId()) != null;
 }
Exemple #4
0
 public boolean isInThumbnailCache(FeedImage image) {
   return thumbnailCache.get(image.getId()) != null;
 }