Ejemplo n.º 1
0
  /**
   * Load Boot image from network if it does not exist in the cache, and then store it.
   *
   * @param bootUrl The URL to load the image.
   */
  public void loadAndStoreBootImage(String bootUrl) {
    if (TextUtils.isEmpty(bootUrl)) {
      return;
    }

    SharedStore sharedStore = new SharedStore(mContext, null);
    String bootUrlSaved = sharedStore.getString("boot_url", null);

    File bootCacheDirectory = mContext.getCacheDir();
    String imageName = "boot";
    File imageFile = new File(bootCacheDirectory, imageName);
    FastBitmapDrawable drawable = getImageFromCache(bootCacheDirectory, imageName);
    if (bootUrl.equals(bootUrlSaved) && drawable != null) {
      // same url and downloaded
      return;
    }

    int orientation = mContext.getResources().getConfiguration().orientation;
    DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
    int width = metrics.widthPixels;
    int height = metrics.heightPixels;
    if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
      width = metrics.heightPixels;
      height = metrics.widthPixels;
    }

    Bitmap bootImage = loadImage(bootUrl, true);
    if (bootImage != null) {
      if (imageFile.exists()) {
        imageFile.delete();
      }
      putBootImageToCache(bootImage, width, height, imageName, bootCacheDirectory);
      sharedStore.putString("boot_url", bootUrl);
    }
  }
Ejemplo n.º 2
0
  /**
   * Load LOGO image from network if it does not exist in the cache, and then store it.
   *
   * @param logoUrl The URL to load the LOGO image.
   */
  public void loadAndStoreLogoImage(String logoUrl) {
    if (TextUtils.isEmpty(logoUrl)) {
      return;
    }

    SharedStore sharedStore = new SharedStore(mContext, null);

    String logoUrlSaved = sharedStore.getString("logo_url", null);

    File logoCacheDir = mContext.getCacheDir();
    String imageName = "logo";
    File imageFile = new File(logoCacheDir, imageName);
    FastBitmapDrawable drawable = getImageFromCache(logoCacheDir, imageName);
    if (drawable != null && logoUrl.equals(logoUrlSaved)) {
      // same url and downloaded
      return;
    }

    DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
    int width = (int) (172 * metrics.density);
    int height = (int) (44 * metrics.density);

    Bitmap logoImage = loadImage(logoUrl, true);
    if (logoImage != null) {
      imageFile.delete();
      putImageToCache(logoImage, width, height, imageName, logoCacheDir, true);
      sharedStore.putString("logo_url", logoUrl);
    }
  }