byte[] assetData;
// Do we have this image in the cache?
if (Client.assets.Cache.hasAsset(textureID)
&& (assetData = Client.assets.Cache.getCachedAssetBytes(textureID)) != null)
{
ImageDownload image = new ImageDownload();
image.ID = textureID;
image.AssetData = assetData;
image.Size = image.AssetData.length;
image.Transferred = image.AssetData.length;
image.ImageType = imageType;
image.AssetType = AssetType.Texture;
image.Success = true;
callback.execute(new TextureDownloadCallbackArgs(TextureRequestState.Finished, new AssetTexture(image.ID, image.AssetData)));
FireImageProgressEvent(image.ID, (int)image.Transferred, image.Size);
return;
}
MethodDelegate<Void, HttpBaseDownloadProgressArg> progressHandler = null;
if (progress)
{
progressHandler = new MethodDelegate<Void, HttpBaseDownloadProgressArg>(){
public Void execute(HttpBaseDownloadProgressArg e) {
// HttpRequestBase request = e.getRequest();
// HttpResponse response = e.getResponse();
int bytesReceived = e.getBytesReceived();
int totalBytesToReceive = e.getTotalBytesToReceive();
FireImageProgressEvent(textureID, bytesReceived, totalBytesToReceive);
return null;
}
};
}
MethodDelegate<Void,HttpBaseRequestCompletedArg> downloadCompletedHanlder = new MethodDelegate<Void,HttpBaseRequestCompletedArg>()
{
public Void execute(HttpBaseRequestCompletedArg e) {
// HttpRequestBase request = e.getRequest();
// HttpResponse response = e.getResponse();
byte[] responseData = e.getResponseData();
Exception error = e.getError();
if (error == null && responseData != null) // success
{
ImageDownload image = new ImageDownload();
image.ID = textureID;
image.AssetData = responseData;
image.Size = image.AssetData.length;
image.Transferred = image.AssetData.length;
image.ImageType = imageType;