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

@ -124,6 +124,7 @@ export module tk {
constructor(nativeApp: any) {
this.nativeApp = nativeApp;
this.packageName = nativeApp.getPackageName();
this.context = nativeApp.getApplicationContext();
}
public init() {

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);
}
}
}
}
}
}

View File

@ -338,3 +338,22 @@ declare module android {
declare var app;
declare var telerik;
declare module com {
export module koushikdutta {
export module ion {
export class Ion {
static with(context: any, url : string) : any;
}
}
export module async {
export module future {
export class FutureCallback {
constructor(context: any);
}
}
}
}
}