Skip to content

Instantly share code, notes, and snippets.

@robUx4
Created December 18, 2014 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robUx4/913ac48cd9a834720714 to your computer and use it in GitHub Desktop.
Save robUx4/913ac48cd9a834720714 to your computer and use it in GitHub Desktop.
Picture Cache abstraction interface
import java.io.IOException;
import android.widget.ImageView;
public interface PictureCache<L, R extends RunningLoad, AUTH_COOKIE, AUTH_LOADER, VIEW_TYPE extends ImageView> {
R load(VIEW_TYPE view, String imageUrl, PictureLoader loader, SizeConstraint sizeConstraint, AUTH_LOADER networkLoader, AUTH_COOKIE cookie, long freshness);
void loadFromAnyThread(String imageUrl, PictureLoader loader, SizeConstraint sizeConstraint, AUTH_LOADER withAuth, AUTH_COOKIE cookie);
boolean isAvailableWithoutDownload(String imageUrl, SizeConstraint sizeConstraint);
void loadBytesInArray(String imageUrl, SizeConstraint sizeConstraint, Object[] array, int index, AUTH_COOKIE cookie);
/**
* Save a picture from the cache into the Android Gallery
* @param imageUrl The URL corresponding to the image stored in the cache
* @return whether the picture was stored successfully
* @throws IOException
* @throws SecurityException
*/
boolean saveInGallery(String imageUrl, AUTH_COOKIE cookie) throws SecurityException;
/**
* Get the {@link PictureLoader} that will perform the precache
*/
PictureLoader getPrecacheLoader();
/**
* Clear the Bitmaps cached in memory
*/
void clearMemory();
/**
* Remove all the data stored in the cache
*/
void clear();
}
import android.graphics.drawable.BitmapDrawable;
public interface PictureLoader {
void onShowBitmap(String url, BitmapDrawable bitmap, boolean doDisplay);
void onShowDefault(boolean doDisplay);
void onShowError(boolean doDisplay);
}
public interface SizeConstraint {
public static enum SizeType {
/** Use the picture in its original size to be deep zoomed */
DEEP_ZOOM,
/** Use the picture in its original size */
ORIGINAL,
/** Use the picture not to be bigger than the screen */
FULLSCREEN,
/** Resize the picture to fill an area of the specified width, keeping the aspect ratio */
FILL_MAX_WIDTH,
/** Resize the picture to fill an area of the specified height, keeping the aspect ratio */
FILL_MAX_HEIGHT,
/** Resize the picture to fill the whole area, keeping the aspect ratio */
FILL_AREA,
}
SizeType getSizeType();
int getWidthConstraint();
int getHeightConstraint();
public static final SizeConstraint DeepZoom = new SizeConstraint() {
@Override
public SizeType getSizeType() {
return SizeType.DEEP_ZOOM;
}
public int getWidthConstraint() {
return -1;
}
public int getHeightConstraint() {
return -1;
}
};
public static final SizeConstraint OriginalSize = new SizeConstraint() {
@Override
public SizeType getSizeType() {
return SizeType.ORIGINAL;
}
public int getWidthConstraint() {
return -1;
}
public int getHeightConstraint() {
return -1;
}
};
public static final SizeConstraint FullScreen = new SizeConstraint() {
@Override
public SizeType getSizeType() {
return SizeType.FULLSCREEN;
}
public int getWidthConstraint() {
return -1;
}
public int getHeightConstraint() {
return -1;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment