async load of images in web client + loadFromBitmap for Image

This commit is contained in:
Vladimir Enchev
2014-03-20 16:50:38 +02:00
parent bbd8fd92ea
commit 65c920c8c1
4 changed files with 25 additions and 4 deletions

View File

@@ -37,6 +37,11 @@ export module tk {
return (this._nativeImage != null);
}
public loadFromBitmap(source: any): boolean {
this._nativeImage = source;
return (this._nativeImage != null);
}
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
if (this._nativeImage) {
var targetFormat = android.graphics.Bitmap.CompressFormat.PNG;

1
Image/image.d.ts vendored
View File

@@ -9,6 +9,7 @@
loadFromResource(name: string): boolean;
loadFromFile(path: string): boolean;
loadFromData(data: any): boolean;
loadFromBitmap(source: any): boolean;
saveToFile(path: string, format: ImageType, quality?: number): boolean;
getHeight(): number;

View File

@@ -27,6 +27,11 @@
return (this._nativeImage != null);
}
public loadFromBitmap(source: any): boolean {
this._nativeImage = source;
return (this._nativeImage != null);
}
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
if (null == this._nativeImage) {
return false;

View File

@@ -20,7 +20,6 @@ export module tk {
errorCallback(e.toString());
return;
}
successCallback(result);
}
})).get();
@@ -45,9 +44,20 @@ export module tk {
public getImage(url: string, successCallback: (result: image_module.tk.ui.Image) => void, errorCallback?: (e: Error) => void) {
try {
if (successCallback) {
var image = new image_module.tk.ui.Image();
image.loadFromData(new java.net.URL(url).getContent());
successCallback(image);
var context = app_module.tk.ui.Application.current.android.context;
com.koushikdutta.ion.Ion.with(context, url).asBitmap().setCallback(new com.koushikdutta.async.future.FutureCallback({
onCompleted: function (e, result) {
if (e && errorCallback) {
errorCallback(e.toString());
return;
}
var image = new image_module.tk.ui.Image();
image.loadFromBitmap(result);
successCallback(image);
}
})).get();
}
} catch (ex) {