mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
New BCL approach & BuildTasks
This commit is contained in:
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user