示例#1
0
 public static ImageCache findOrCreateCache(FragmentActivity activity, ImageCacheParams params) {
   RetainFragment fragment = findOrCreateRetainFragment(activity.getSupportFragmentManager());
   ImageCache cache = (ImageCache) fragment.getObject();
   if (cache == null) {
     cache = new ImageCache(activity, params);
     fragment.setObject(cache);
   }
   return cache;
 }
 /**
  * Find and return an existing ImageCache stored in a RetainFragment, if not found a new one is
  * created using the supplied parameter and saved to a RetainFragment.
  *
  * @param fragmentManager The fragment manager to use if creating the ImageCache
  * @param cacheParams The cache parameters to use if creating the ImageCache
  * @return An exist retained ImageCache object or a new one if one did not exist
  */
 public static ImageCache findOrCreateCache(
     FragmentManager fragmentManager, ImageCacheParams cacheParams) {
   // Search for, or create an instance of the non-UI RetainFragment
   final RetainFragment mRetainFragment = findOrCreateRetainFragment(fragmentManager);
   // Check if we already have an ImageCache stored in RetainFragment
   ImageCache imageCache = (ImageCache) mRetainFragment.getObject();
   // No existing ImageCache, create one and store it in RetainFragment
   if (imageCache == null) {
     imageCache = new ImageCache(cacheParams);
     mRetainFragment.setObject(imageCache);
   }
   return imageCache;
 }
 public static final ImageCache findOrCreateCache(final Activity activity) {
   FragmentManager nFragmentManager = activity.getFragmentManager();
   RetainFragment retainFragment = (RetainFragment) nFragmentManager.findFragmentByTag(TAG);
   if (retainFragment == null) {
     retainFragment = new RetainFragment();
     nFragmentManager.beginTransaction().add(retainFragment, TAG).commit();
   }
   ImageCache cache = (ImageCache) retainFragment.getObject();
   if (cache == null) {
     cache = getInstance(activity);
     retainFragment.setObject(cache);
   }
   return cache;
 }
示例#4
0
  /**
   * Find and return an existing ImageCache stored in a {@link RetainFragment} , if not found a new
   * one is created using the supplied params and saved to a {@link RetainFragment}
   *
   * @param activity The calling {@link FragmentActivity}
   * @return An existing retained ImageCache object or a new one if one did not exist
   */
  public static final ImageCache findOrCreateCache(final Activity activity) {

    // Search for, or create an instance of the non-UI RetainFragment
    final RetainFragment retainFragment = findOrCreateRetainFragment(activity.getFragmentManager());

    // See if we already have an ImageCache stored in RetainFragment
    ImageCache cache = (ImageCache) retainFragment.getObject();

    // No existing ImageCache, create one and store it in RetainFragment
    if (cache == null) {
      cache = getInstance(activity);
      retainFragment.setObject(cache);
    }
    return cache;
  }
示例#5
0
  /**
   * Find and return an existing ImageCache stored in a {@link RetainFragment}, if not found a new
   * one is created using the supplied params and saved to a {@link RetainFragment}.
   *
   * @param fragmentManager The fragment manager to use when dealing with the retained fragment.
   * @param memCacheSizePercent The cache size as a percent of available app memory.
   * @return An existing retained ImageCache object or a new one if one did not exist
   */
  public static ImageCache getInstance(FragmentManager fragmentManager, float memCacheSizePercent) {

    // Search for, or create an instance of the non-UI RetainFragment
    final RetainFragment mRetainFragment = findOrCreateRetainFragment(fragmentManager);

    // See if we already have an ImageCache stored in RetainFragment
    ImageCache imageCache = (ImageCache) mRetainFragment.getObject();

    // No existing ImageCache, create one and store it in RetainFragment
    if (imageCache == null) {
      imageCache = new ImageCache(memCacheSizePercent);
      mRetainFragment.setObject(imageCache);
    }

    return imageCache;
  }
示例#6
0
  /**
   * Find and return an existing ImageCache stored in a {@link RetainFragment}, if not found a new
   * one is created using the supplied params and saved to a {@link RetainFragment}.
   *
   * @param activity The calling {@link FragmentActivity}
   * @param cacheParams The cache parameters to use if creating the ImageCache
   * @return An existing retained ImageCache object or a new one if one did not exist
   */
  public static ImageCache findOrCreateCache(
      final FragmentActivity activity, ImageCacheParams cacheParams) {

    // Search for, or create an instance of the non-UI RetainFragment
    final RetainFragment mRetainFragment =
        RetainFragment.findOrCreateRetainFragment(activity.getSupportFragmentManager());

    // See if we already have an ImageCache stored in RetainFragment
    ImageCache imageCache = (ImageCache) mRetainFragment.getObject();

    // No existing ImageCache, create one and store it in RetainFragment
    if (imageCache == null) {
      imageCache = new ImageCache(activity, cacheParams);
      mRetainFragment.setObject(imageCache);
    }

    return imageCache;
  }
示例#7
0
  /**
   * Find and return an existing BitmapCache stored in a {@link RetainFragment}, if not found a new
   * one is created using the supplied params and saved to a {@link RetainFragment}.
   *
   * @param fragmentManager The fragment manager to use when dealing with the retained fragment.
   * @param fragmentTag The tag of the retained fragment (should be unique for each memory cache
   *     that needs to be retained).
   * @param memCacheSize Memory cache size in KB.
   */
  public static BitmapCache getInstance(
      FragmentManager fragmentManager, String fragmentTag, int memCacheSize) {
    BitmapCache bitmapCache = null;
    RetainFragment mRetainFragment = null;

    if (fragmentManager != null) {
      // Search for, or create an instance of the non-UI RetainFragment
      mRetainFragment = getRetainFragment(fragmentManager, fragmentTag);

      // See if we already have a BitmapCache stored in RetainFragment
      bitmapCache = (BitmapCache) mRetainFragment.getObject();
    }

    // No existing BitmapCache, create one and store it in RetainFragment
    if (bitmapCache == null) {
      bitmapCache = new BitmapCache(memCacheSize);
      if (mRetainFragment != null) {
        mRetainFragment.setObject(bitmapCache);
      }
    }
    return bitmapCache;
  }