async image loading from data, files and resources for ios

Use the tns_safeDecodeImageNamedCompletion from the widgets framework

Add loadMode on Image with sync and async options for local images
This commit is contained in:
Nedyalko Nikolov
2016-04-15 09:04:02 +03:00
committed by Panayot Cankov
parent b8785afd74
commit 1b395aac7f
10 changed files with 266 additions and 108 deletions

View File

@@ -44,7 +44,7 @@ export class ImageSource implements definition.ImageSource {
// Load BitmapDrawable with getDrawable to make use of Android internal caching
var bitmapDrawable = <android.graphics.drawable.BitmapDrawable>res.getDrawable(identifier);
if (bitmapDrawable && bitmapDrawable.getBitmap) {
this.android = bitmapDrawable.getBitmap();
this.android = bitmapDrawable.getBitmap();
}
}
}
@@ -52,6 +52,12 @@ export class ImageSource implements definition.ImageSource {
return this.android != null;
}
public fromResource(name: string): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
resolve(this.loadFromResource(name));
});
}
public loadFromFile(path: string): boolean {
ensureFS();
@@ -64,11 +70,23 @@ export class ImageSource implements definition.ImageSource {
return this.android != null;
}
public fromFile(path: string): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
resolve(this.loadFromFile(path));
});
}
public loadFromData(data: any): boolean {
this.android = android.graphics.BitmapFactory.decodeStream(data);
return this.android != null;
}
public fromData(data: any): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
resolve(this.loadFromData(data));
});
}
public loadFromBase64(source: string): boolean {
if (types.isString(source)) {
var bytes = android.util.Base64.decode(source, android.util.Base64.DEFAULT);
@@ -77,6 +95,12 @@ export class ImageSource implements definition.ImageSource {
return this.android != null;
}
public fromBase64(data: any): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
resolve(this.loadFromBase64(data));
});
}
public setNativeSource(source: any): boolean {
this.android = source;
return source != null;