From bbd8fd92ea0170bf488e3c564d73b4633aed7ff5 Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Thu, 20 Mar 2014 16:17:49 +0200 Subject: [PATCH] android application fixed + web client android implementation --- Application/application.android.ts | 1 + WebClient/web_client.android.ts | 34 +++++++++++++++++++++++++----- declarations.android.d.ts | 21 +++++++++++++++++- declarations.d.ts | 2 +- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Application/application.android.ts b/Application/application.android.ts index 299d38042..605dbd934 100644 --- a/Application/application.android.ts +++ b/Application/application.android.ts @@ -124,6 +124,7 @@ export module tk { constructor(nativeApp: any) { this.nativeApp = nativeApp; this.packageName = nativeApp.getPackageName(); + this.context = nativeApp.getApplicationContext(); } public init() { diff --git a/WebClient/web_client.android.ts b/WebClient/web_client.android.ts index 1c4567dff..a110e229d 100644 --- a/WebClient/web_client.android.ts +++ b/WebClient/web_client.android.ts @@ -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); + } + } + } } } } \ No newline at end of file diff --git a/declarations.android.d.ts b/declarations.android.d.ts index 004a346cc..6462d65ea 100644 --- a/declarations.android.d.ts +++ b/declarations.android.d.ts @@ -337,4 +337,23 @@ declare module android { } declare var app; -declare var telerik; \ No newline at end of file +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); + } + } + } + } +} \ No newline at end of file diff --git a/declarations.d.ts b/declarations.d.ts index 7fe071ae8..9abb332d8 100644 --- a/declarations.d.ts +++ b/declarations.d.ts @@ -23,4 +23,4 @@ declare module i { } } -declare var console: i.IConsole; +declare var console: i.IConsole; \ No newline at end of file