Package 

Class ImageModule

  • All Implemented Interfaces:
    android.content.ComponentCallbacks , android.content.ComponentCallbacks2

    
    public class ImageModule
     implements ComponentCallbacks2
                        

    A singleton to present a simple static interface for building requests with and maintaining an Engine, BitmapPool, and MemoryCache.

    • Method Detail

      • getBitmapPool

        @NonNull() BitmapPool getBitmapPool()

        Returns the com.mobwith.imgmodule.load.engine.bitmap_recycle.BitmapPool used totemporarily store Bitmaps so they can be reused to avoid garbagecollections.

        Note - Using this pool directly can lead to undefined behavior and strange drawing errors.Any Bitmap added to the pool must not be currently in use in any otherpart of the application. Any Bitmap added to the pool must be removedfrom the pool before it is added a second time.

        Note - To make effective use of the pool, any Bitmap removed fromthe pool must eventually be re-added. Otherwise the pool will eventually empty and will notserve any useful purpose.

        The primary reason this object is exposed is for use in custom s and com.mobwith.imgmodule.load.Transformations.Use outside of these classes is not generally recommended.

      • setMemoryCategory

        @NonNull() MemoryCategory setMemoryCategory(@NonNull() MemoryCategory memoryCategory)

        Adjusts ImageModule current and maximum memory usage based on the given MemoryCategory.

        The default MemoryCategory is NORMAL. increases ImageModule maximum memory usage by up to 50% and decreases ImageModule maximum memory usage by 50%. This method should be usedto temporarily increase or decrease memory usage for a single Activity or part of the app. Use setMemoryCache to put a permanent memory size if you want tochange the default.

      • setMemoryCategory

        @NonNull() MemoryCategory setMemoryCategory(@NonNull() MemoryCategory memoryCategory)

        Adjusts ImageModule current and maximum memory usage based on the given MemoryCategory.

        The default MemoryCategory is NORMAL. increases ImageModule maximum memory usage by up to 50% and decreases ImageModule maximum memory usage by 50%. This method should be usedto temporarily increase or decrease memory usage for a single Activity or part of the app. Use setMemoryCache to put a permanent memory size if you want tochange the default.

      • getPhotoCacheDir

        @Nullable() static File getPhotoCacheDir(@NonNull() Context context)

        Returns a directory with a default name in the private cache directory of the application touse to store retrieved media and thumbnails.

        Parameters:
        context - A context.
      • getPhotoCacheDir

        @Nullable() static File getPhotoCacheDir(@NonNull() Context context, @NonNull() String cacheName)

        Returns a directory with the given name in the private cache directory of the application touse to store retrieved media and thumbnails.

        Parameters:
        context - A context.
        cacheName - The name of the subdirectory in which to store the cache.
      • enableHardwareBitmaps

         static void enableHardwareBitmaps()

        Allows hardware Bitmaps to be used prior to the first frame in the app being drawn as soon asthis method is called.

        If you use this method in non-test code, your app will experience native crashes on someversions of Android if you try to decode a hardware Bitmap. This method is only useful fortesting.

      • preFillBitmapPool

         synchronized void preFillBitmapPool(@NonNull() Array<PreFillType.Builder> bitmapAttributeBuilders)

        Pre-fills the BitmapPool using the given sizes.

        Enough Bitmaps are added to completely fill the pool, so most or all of the Bitmapscurrently in the pool will be evicted. Bitmaps are allocated according to the weights of thegiven sizes, where each size gets (weight / prefillWeightSum) percent of the pool to fill.

        Note - Pre-filling is done asynchronously using and IdleHandler. Any currentlyrunning pre-fill will be cancelled and replaced by a call to this method.

        This method should be used with caution, overly aggressive pre-filling is substantiallyworse than not pre-filling at all. Pre-filling should only be started in onCreate to avoidconstantly clearing and re-filling the BitmapPool. Rotation should be carefullyconsidered as well. It may be worth calling this method only when no saved instance stateexists so that pre-filling only happens when the Activity is first created, rather than onevery rotation.

        Parameters:
        bitmapAttributeBuilders - The list of Builders representing individualsizes and configurations of Bitmaps to be pre-filled.
      • clearMemory

         void clearMemory()

        Clears as much memory as possible.

      • trimMemory

         void trimMemory(int level)

        Clears some memory with the exact amount depending on the given level.

      • clearDiskCache

         void clearDiskCache()

        Clears disk cache.

        This method should always be called on a background thread, since it is a blocking call.

      • with

        @NonNull() static RequestManager with(@NonNull() Context context)

        Begin a load with ImageModule by passing in a context.

        Any requests started using a context will only have the application level options appliedand will not be started or stopped based on lifecycle events. In general, loads should bestarted at the level the result will be used in. If the resource will be used in a view in achild fragment, the load should be started with with} using thatchild fragment. Similarly, if the resource will be used in a view in the parent fragment, theload should be started with with using the parent fragment. Inthe same vein, if the resource will be used in a view in an activity, the load should bestarted with with}.

        This method is appropriate for resources that will be used outside of the normal fragment oractivity lifecycle (For example in services, or for notification thumbnails).

        Parameters:
        context - Any context, will not be retained.
      • with

        @NonNull() static RequestManager with(@NonNull() FragmentActivity activity)

        Begin a load with ImageModule that will tied to the give 's lifecycle and that uses the given 's default options.

        Parameters:
        activity - The activity to use.
      • with

        @NonNull() static RequestManager with(@NonNull() View view)

        Begin a load with ImageModule that will be tied to the lifecycle of the Fragment, , or Activity that contains the View.

        A Fragment or android.app.Fragment is assumed to contain a View if the Viewis a child of the View returned by the getView} method.

        This method will not work if the View is not attached. Prefer the Activity and Fragmentvariants unless you're loading in a View subclass.

        This method may be inefficient aways and is definitely inefficient for large hierarchies.Consider memoizing the result after the View is attached or again, prefer the Activity andFragment variants whenever possible.

        When used in Applications that use the non-support android.app.Fragment classes,calling this method will produce noisy logs from android.app.FragmentManager. Consideravoiding entirely or using the Fragments from the support library instead.

        If the support FragmentActivity class is used, this method will only attempt todiscover support Fragments. Any non-support android.app.Fragments attached tothe FragmentActivity will be ignored.

        Parameters:
        view - The view to search for a containing Fragment or Activity from.