mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
android application fixed + web client android implementation
This commit is contained in:
@ -124,6 +124,7 @@ export module tk {
|
||||
constructor(nativeApp: any) {
|
||||
this.nativeApp = nativeApp;
|
||||
this.packageName = nativeApp.getPackageName();
|
||||
this.context = nativeApp.getApplicationContext();
|
||||
}
|
||||
|
||||
public init() {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
19
declarations.android.d.ts
vendored
19
declarations.android.d.ts
vendored
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user