New BCL approach & BuildTasks

This commit is contained in:
atanasovg
2014-03-12 18:26:58 +02:00
commit 39b505384a
42 changed files with 2907 additions and 0 deletions

5
Image/Readme.md Normal file
View File

@@ -0,0 +1,5 @@
The way we get local path here is different for now. Maybe we should get it from FS module in the future samples. Sample code Android:
```
// TODO: Update code sample using require and BCL File/Folder
```

68
Image/image.android.ts Normal file
View File

@@ -0,0 +1,68 @@
import app_module = require("Application/application");
export module tk {
export module ui {
export enum ImageType {
PNG = 0,
JPEG = 1,
}
export class Image {
private _nativeImage: any;
constructor() {
this._nativeImage = null;
}
public loadFromResource(name: string): boolean {
var androidApp = app_module.tk.ui.Application.current.android;
var res = androidApp.context.getResources();
if (res) {
var identifier: number = res.getIdentifier(name, 'drawable', androidApp.packageName);
if (0 < identifier) {
this._nativeImage = android.graphics.BitmapFactory.decodeResource(res, identifier);
return (this._nativeImage != null);
}
}
return false;
}
public loadFromFile(path: string): boolean {
this._nativeImage = android.graphics.BitmapFactory.decodeFile(path, null);
return (this._nativeImage != null);
}
public loadFromData(data: any): boolean {
this._nativeImage = android.graphics.BitmapFactory.decodeStream(data);
return (this._nativeImage != null);
}
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
if (this._nativeImage) {
var targetFormat = android.graphics.Bitmap.CompressFormat.PNG;
switch (format) {
case ImageType.JPEG:
targetFormat = android.graphics.Bitmap.CompressFormat.JPEG;
break;
}
// TODO add exception handling
var outputStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(path));
// FIXME compress is not found
var res = this._nativeImage.compress(targetFormat, outputStream);
outputStream.close();
return res;
}
return false;
}
public getHeight(): number {
return (this._nativeImage) ? this._nativeImage.getHeight() : NaN;
}
public getWidth(): number {
return (this._nativeImage) ? this._nativeImage.getWidth() : NaN;
}
}
}
}

18
Image/image.d.ts vendored Normal file
View File

@@ -0,0 +1,18 @@
export declare module tk {
export module ui {
export enum ImageType {
PNG = 0,
JPEG = 1,
}
export class Image {
loadFromResource(name: string): boolean;
loadFromFile(path: string): boolean;
loadFromData(data: any): boolean;
saveToFile(path: string, format: ImageType, quality?: number): boolean;
getHeight(): number;
getWidth(): number;
}
}
}

59
Image/image.ios.ts Normal file
View File

@@ -0,0 +1,59 @@
module tk {
export module ui {
export enum ImageType {
PNG = 0,
JPEG = 1,
}
export class Image {
private _nativeImage: any;
constructor() {
this._nativeImage = null;
}
public loadFromResource(name: string): boolean {
this._nativeImage = UIKit.UIImage.imageNamed(name);
return (this._nativeImage != null);
}
public loadFromFile(path: string): boolean {
this._nativeImage = UIKit.UIImage.imageWithContentsOfFile(path);
return (this._nativeImage != null);
}
public loadFromData(data: any): boolean {
this._nativeImage = UIKit.UIImage.imageWithData(data);
return (this._nativeImage != null);
}
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
if (null == this._nativeImage) {
return false;
}
var res = false;
var data = null;
switch (format) {
case ImageType.JPEG:
data = UIKit.UIImageJPEGRepresentation(this._nativeImage, ('undefined' == typeof quality) ? 1.0 : quality);
break;
case ImageType.PNG:
data = UIKit.UIImagePNGRepresentation(this._nativeImage);
break;
}
if (null != data) {
res = data.writeToFileAtomically(path, true);
}
return res;
}
public getHeight(): number {
return (this._nativeImage) ? this._nativeImage.size().height : NaN;
}
public getWidth(): number {
return (this._nativeImage) ? this._nativeImage.size().width : NaN;
}
}
}
}