コード例 #1
0
  private Bitmap getBitmap(int page) {
    Bitmap bitmap = null;
    if (cache != null && cache.containsKey("page_" + page)) {
      SoftReference<Bitmap> bitmapRef = cache.get("page_" + page);
      bitmap = bitmapRef.get();
      Log.d(TAG, "reading image for page " + page + " from cache!");
    } else {
      Log.d(TAG, "loading image for page " + page + " from sdcard");
    }

    boolean outOfMemory = false;
    // Bitmap not found in cache..
    if (bitmap == null) {
      String filename = mContext.getPageFileName(page);
      try {
        bitmap = QuranUtils.getImageFromSD(filename);
      } catch (OutOfMemoryError oe) {
        bitmap = null;
        outOfMemory = true;
        mHasBeenOutOfMemory = true;
      }

      // Add Bitmap to cache..
      if (bitmap != null) {
        cache.put("page_" + page, new SoftReference<Bitmap>(bitmap));
        Log.d(TAG, "page " + page + " added to cache!");
      } else {
        if (!outOfMemory) {
          Log.d(TAG, "page " + page + " not found on sdcard");
          bitmap = QuranUtils.getImageFromWeb(filename);
        }

        if (bitmap != null) cache.put("page_" + page, new SoftReference<Bitmap>(bitmap));
        else
          Log.d(
              TAG,
              "page "
                  + page
                  + " could not be fetched "
                  + (outOfMemory ? "due to being out of memory" : "from the web"));
      }
    }

    return bitmap;
  }
コード例 #2
0
 @Override
 public void bind(BookmarksFragment fragment) {
   mFragment = fragment;
   boolean isRtl = mQuranSettings.isArabicNames() || QuranUtils.isRtl();
   if (isRtl == mIsRtl) {
     requestData(true);
   } else {
     // don't use the cache if rtl changed
     mIsRtl = isRtl;
     requestData(false);
   }
 }
コード例 #3
0
 @Override
 protected void onPostExecute(RectF[] rect) {
   if (rect != null && rect.length == 1 && isAdded()) {
     mImageView.setPageBounds(rect[0]);
     if (overlayText) {
       int page = pageNumber;
       Context context = getContext();
       String suraText = QuranInfo.getSuraNameFromPage(context, page, true);
       String juzText = QuranInfo.getJuzString(context, page);
       String pageText = QuranUtils.getLocalizedNumber(context, page);
       String rub3Text = QuranDisplayHelper.displayRub3(context, page);
       mImageView.setOverlayText(suraText, juzText, pageText, rub3Text);
     }
   }
 }