mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 05:18:39 +08:00
New BCL approach & BuildTasks
This commit is contained in:
25
WebClient/Readme.md
Normal file
25
WebClient/Readme.md
Normal 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);
|
||||
});
|
||||
```
|
48
WebClient/web_client.android.ts
Normal file
48
WebClient/web_client.android.ts
Normal 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
15
WebClient/web_client.d.ts
vendored
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
40
WebClient/web_client.ios.ts
Normal file
40
WebClient/web_client.ios.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user