android application fixed + web client android implementation

This commit is contained in:
Vladimir Enchev
2014-03-20 16:17:49 +02:00
parent aeadb82cb2
commit bbd8fd92ea
4 changed files with 51 additions and 7 deletions

View File

@ -1,4 +1,5 @@
import image_module = require("Image/image");
import app_module = require("Application/application");
export module tk {
export module web {
@ -12,12 +13,17 @@ export module tk {
public getString(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);
var context = app_module.tk.ui.Application.current.android.context;
com.koushikdutta.ion.Ion.with(context, url).asString().setCallback(new com.koushikdutta.async.future.FutureCallback({
onCompleted: function (e, result) {
if (e && errorCallback) {
errorCallback(e.toString());
return;
}
successCallback(responseBody);
successCallback(result);
}
})).get();
}
} catch (ex) {
@ -28,6 +34,14 @@ export module tk {
}
}
public getJSON(url: string, successCallback: (result: Object) => void, errorCallback?: (e: Error) => void) {
this.getString(url, function (data) {
if (successCallback) {
successCallback(JSON.parse(data));
}
}, errorCallback);
}
public getImage(url: string, successCallback: (result: image_module.tk.ui.Image) => void, errorCallback?: (e: Error) => void) {
try {
if (successCallback) {
@ -43,6 +57,16 @@ export module tk {
}
}
public static get(url: string, successCallback: (result: any) => void, errorCallback?: (e: Error) => void) {
try {
} catch (ex) {
if (errorCallback) {
errorCallback(ex);
}
}
}
}
}
}