ImageDownloader

public class ImageDownloader

This class provides utility methods for downloading, storing and loading images from/to the internal storage. Note that the image downloading process is asynchronous, so it uses the interface ImageDownloader.IBitmapReceiver for notifying the user about the downloading outcomes.

Fields

receiver

IBitmapReceiver receiver

Constructors

ImageDownloader

public ImageDownloader(IBitmapReceiver receiver, Context ctx, String username, String password)

This class handles asynchronous image downloads. Once a image has been successfully downloaded, it calls the method ImageDownloader.IBitmapReceiver.onBitmapReady(Bitmap)}

Parameters:
  • receiver – the object that will receive the downloaded image
  • ctx – the activity context
  • username – the user name (needed for authentication)
  • password – the password (needed for authentication)

Methods

deleteInternalFile

public static boolean deleteInternalFile(Context ctx, String filename)

Deletes an image from the internal storage

Parameters:
  • ctx – the context the activity context
  • filename – the name (no path) )of the file to be deleted
Returns:

true if the file was deleted , false otherwise

downloadImage

public void downloadImage(String url)

asynchronously downloads an image from the web

Parameters:
  • url – the url image

getInternalImages

public static File[] getInternalImages(Context ctx)

Get the list of .jpeg images stored in the internal archive (private to the activity context passed as argument)

Parameters:
  • ctx – the activity context
Returns:

the list of .jpg images

getInternalImages

public static File[] getInternalImages(Context ctx, String filter)

Get the list of images stored in the internal archive (private to the activity context passed as argument)

Parameters:
  • ctx – the activity context
  • filter – the image type filter (e.g: ”.jpg”)
Returns:

the list of images

loadImageFromInternalStorage

public void loadImageFromInternalStorage(String filename)

Loads an image from the internal storage. The loaded bitmap will be sent to the callback method IBitmapReceiver.onBitmapDownloaded(ImageDownloader,Bitmap)

Parameters:
  • filename – the name of the file to load

logAppFileNames

public void logAppFileNames()

saveImageToInternalStorage

public void saveImageToInternalStorage(Bitmap image, String filename)

Save a bitmap into to internal storage

Parameters:
  • image – the bitmap to save
  • filename – the filename of the saved bitmap