@LevelUpApi(contract=PUBLIC) public abstract class LevelUpCodeLoader extends Object implements PendingImage.LoadCancelable
Constructor and Description |
---|
LevelUpCodeLoader(LevelUpQrCodeGenerator qrCodeGenerator,
LevelUpCodeCache codeCache) |
Modifier and Type | Method and Description |
---|---|
void |
cancelLoad(String loadKey)
Cancel the load associated with the given key.
|
void |
cancelLoads()
Cancel all loads.
|
protected boolean |
dispatchOnImageLoaded(String key,
LevelUpQrCodeGenerator.LevelUpQrCodeImage image)
Dispatches calls to a previously registered
PendingImage.OnImageLoaded . |
protected LevelUpQrCodeGenerator.LevelUpQrCodeImage |
generateQrCode(String key,
String qrCodeContents)
Generates the QR code using the supplied generator and caches the result.
|
protected LevelUpCodeCache |
getCodeCache() |
protected String |
getKey(String qrCodeContents)
Creates a key that's unique to the given contents for use with all image load tracking.
|
PendingImage<LevelUpQrCodeGenerator.LevelUpQrCodeImage> |
getLevelUpCode(String qrCodeContents,
PendingImage.OnImageLoaded<LevelUpQrCodeGenerator.LevelUpQrCodeImage> onImageLoaded)
Gets a minimally-small bitmap from the cache whose contents encode
qrCodeContents . |
protected LevelUpQrCodeGenerator |
getQrCodeGenerator() |
void |
loadLevelUpCode(String codeData)
Generate and cache the code image.
|
protected abstract void |
onCancelLoad(String loadKey)
Implement this to handle any load cancellation.
|
protected abstract void |
onCancelLoads()
Cancel all loads.
|
protected abstract void |
onStartLoadInBackground(String qrCodeContents,
String key,
PendingImage.OnImageLoaded<LevelUpQrCodeGenerator.LevelUpQrCodeImage> onImageLoaded)
Implement this to start the loading of the given QR code into an image in the background.
|
protected void |
registerOnImageLoadedCallback(String key,
PendingImage.OnImageLoaded<LevelUpQrCodeGenerator.LevelUpQrCodeImage> onImageLoaded)
Register an
PendingImage.OnImageLoaded callback with the given key. |
protected void |
startLoadInBackground(String qrCodeContents,
String key,
PendingImage.OnImageLoaded<LevelUpQrCodeGenerator.LevelUpQrCodeImage> onImageLoaded)
Start the loading of the given QR code into an image in the background.
|
protected void |
unregisterOnImageLoadedCallback(String key)
Remove the given
PendingImage.OnImageLoaded callbacks. |
public LevelUpCodeLoader(LevelUpQrCodeGenerator qrCodeGenerator, LevelUpCodeCache codeCache)
qrCodeGenerator
- the QR code generator to render the codes.codeCache
- the cache to use for this code loader.public final void cancelLoad(String loadKey)
PendingImage.LoadCancelable
cancelLoad
in interface PendingImage.LoadCancelable
loadKey
- the key.public final void cancelLoads()
cancelLoad(String)
or
PendingImage.cancelLoad()
. This must be called on the main thread.public final PendingImage<LevelUpQrCodeGenerator.LevelUpQrCodeImage> getLevelUpCode(String qrCodeContents, PendingImage.OnImageLoaded<LevelUpQrCodeGenerator.LevelUpQrCodeImage> onImageLoaded)
qrCodeContents
.
This returns a PendingImage
, which will either contain the resulting image if the
code has been cached or will be loaded eventually and the onImageLoaded
callback will
be called. This must be called on the main thread.qrCodeContents
- the data to display to the user. This is the raw string to encode in
the QR code.onImageLoaded
- callback that gets called when the image is loaded. This will always be
called on the UI thread and is called even if this class returns a cached result.public final void loadLevelUpCode(String codeData)
getLevelUpCode(String, com.scvngr.levelup.core.ui.view.PendingImage.OnImageLoaded)
,
but does not return a result to the user. This can be used for pre-caching codes. This must
be called on the main thread.codeData
- the data to display to the user.protected final boolean dispatchOnImageLoaded(String key, LevelUpQrCodeGenerator.LevelUpQrCodeImage image)
PendingImage.OnImageLoaded
. The PendingImage.OnImageLoaded
will be unregistered. This must be called after loading a QR code in the background. This
must be called on the main thread.key
- the key under which the QR code is tracked.image
- the image of the QR code.@SlowOperation protected final LevelUpQrCodeGenerator.LevelUpQrCodeImage generateQrCode(String key, String qrCodeContents)
key
- the key under which this QR code is tracked.qrCodeContents
- the contents of the QR code.protected final LevelUpCodeCache getCodeCache()
protected final String getKey(String qrCodeContents)
qrCodeContents
- the contents to create a key for.protected final LevelUpQrCodeGenerator getQrCodeGenerator()
protected abstract void onCancelLoad(String loadKey)
loadKey
- the key under which the QR code is tracked.protected abstract void onCancelLoads()
protected abstract void onStartLoadInBackground(String qrCodeContents, String key, PendingImage.OnImageLoaded<LevelUpQrCodeGenerator.LevelUpQrCodeImage> onImageLoaded)
Implement this to start the loading of the given QR code into an image in the background. If an existing request for the same content has been made, the second request will be dropped unless the previous request has been cancelled. This must be called on the main thread.
Subclasses shouldn't call this method directly, instead call
startLoadInBackground(String, String,
com.scvngr.levelup.core.ui.view.PendingImage.OnImageLoaded)
)}.
qrCodeContents
- the contents to render into a QR code.key
- the key under which the QR code is tracked.onImageLoaded
- called when the image has been loaded.protected final void registerOnImageLoadedCallback(String key, PendingImage.OnImageLoaded<LevelUpQrCodeGenerator.LevelUpQrCodeImage> onImageLoaded)
PendingImage.OnImageLoaded
callback with the given key. This must be called on the
main thread.key
- the key under which the image is tracked.onImageLoaded
- the callback to register.protected void startLoadInBackground(String qrCodeContents, String key, PendingImage.OnImageLoaded<LevelUpQrCodeGenerator.LevelUpQrCodeImage> onImageLoaded)
Start the loading of the given QR code into an image in the background. If an existing request for the same content has been made, the second request will be dropped unless the previous request has been cancelled. This must be called on the main thread.
qrCodeContents
- the contents to render into a QR code.key
- the key under which the QR code is tracked.onImageLoaded
- called when the image has been loaded. Existing callbacks registered for
this key will be overwritten unless this parameter is null
.protected final void unregisterOnImageLoadedCallback(String key)
PendingImage.OnImageLoaded
callbacks. This must be called on the main thread.key
- the key under which the image is tracked.