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

25
WebClient/Readme.md Normal file
View File

@ -0,0 +1,25 @@
Sample code:
```
var web_module = require("web_client");
var image_module = require("image");
var client = new web_module.tk.web.Client();
client.downloadString("http://www.reddit.com/r/aww.json?limit=10",
function(result) {
Log("Result:" + result);
},
function(e) {
Log("Error:" + e.message);
});
```
```
var client = new web_module.tk.web.Client();
client.downloadImage("http://www.telerik.com/sfimages/default-source/Homepage/hp_any_approachf6e4079a7a99493a8ab2e367b9cb3f7d.png",
function(image){ // This is image_module.tk.ui.Image
},
function(e) {
Log("Error:" + e.message);
});
```

View File

@ -0,0 +1,48 @@
import image_module = require("Image/image");
export module tk {
export module web {
/**
* Android specific WebClient implementation.
*/
export class Client {
/**
* Downloads string from url.
*/
public downloadString(url: string, successCallback: (result: string) => void, errorCallback?: (e: Error) => void) {
try {
if (successCallback) {
var httpClient = new org.apache.http.impl.client.DefaultHttpClient();
var httpGet = new org.apache.http.client.methods.HttpGet(url);
var responseHandler = new org.apache.http.impl.client.BasicResponseHandler();
var responseBody = httpClient.execute(httpGet, responseHandler);
successCallback(responseBody);
}
} catch (ex) {
if (errorCallback) {
errorCallback(ex);
}
}
}
public downloadImage(url: string, successCallback: (image: 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);
}
} catch (ex) {
if (errorCallback) {
errorCallback(ex);
}
}
}
}
}
}

15
WebClient/web_client.d.ts vendored Normal file
View File

@ -0,0 +1,15 @@
import image_module = require("Image/image");
/**
* Web (WebClient) module.
*/
export declare module tk {
export module web {
/**
* The Client interface.
*/
export class Client {
downloadString(url: string, successCallback: (result: string) => void, errorCallback?: (e: Error) => void)
downloadImage(url: string, successCallback: (image: image_module.tk.ui.Image) => void, errorCallback?: (e: Error) => void)
}
}
}

View File

@ -0,0 +1,40 @@
import image_module = require("Image/image");
// TODO: Not implemented for iOS
export module tk {
export module web {
/**
* iOS specific WebClient implementation.
*/
export class Client {
/**
* Downloads string from url.
*/
public downloadString(url: string, successCallback: (result: string) => void, errorCallback?: (e: Error) => void) {
try {
if (successCallback) {
// successCallback(result);
}
} catch (ex) {
if (errorCallback) {
errorCallback(ex);
}
}
}
public downloadImage(url: string, successCallback: (image: image_module.tk.ui.Image) => void, errorCallback?: (e: Error) => void) {
try {
if (successCallback) {
// successCallback(response);
}
} catch (ex) {
if (errorCallback) {
errorCallback(ex);
}
}
}
}
}
}