mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
android application fixed + web client android implementation
This commit is contained in:
@ -124,6 +124,7 @@ export module tk {
|
|||||||
constructor(nativeApp: any) {
|
constructor(nativeApp: any) {
|
||||||
this.nativeApp = nativeApp;
|
this.nativeApp = nativeApp;
|
||||||
this.packageName = nativeApp.getPackageName();
|
this.packageName = nativeApp.getPackageName();
|
||||||
|
this.context = nativeApp.getApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import image_module = require("Image/image");
|
import image_module = require("Image/image");
|
||||||
|
import app_module = require("Application/application");
|
||||||
|
|
||||||
export module tk {
|
export module tk {
|
||||||
export module web {
|
export module web {
|
||||||
@ -12,12 +13,17 @@ export module tk {
|
|||||||
public getString(url: string, successCallback: (result: string) => void, errorCallback?: (e: Error) => void) {
|
public getString(url: string, successCallback: (result: string) => void, errorCallback?: (e: Error) => void) {
|
||||||
try {
|
try {
|
||||||
if (successCallback) {
|
if (successCallback) {
|
||||||
var httpClient = new org.apache.http.impl.client.DefaultHttpClient();
|
var context = app_module.tk.ui.Application.current.android.context;
|
||||||
var httpGet = new org.apache.http.client.methods.HttpGet(url);
|
com.koushikdutta.ion.Ion.with(context, url).asString().setCallback(new com.koushikdutta.async.future.FutureCallback({
|
||||||
var responseHandler = new org.apache.http.impl.client.BasicResponseHandler();
|
onCompleted: function (e, result) {
|
||||||
var responseBody = httpClient.execute(httpGet, responseHandler);
|
if (e && errorCallback) {
|
||||||
|
errorCallback(e.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
successCallback(responseBody);
|
successCallback(result);
|
||||||
|
}
|
||||||
|
})).get();
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} 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) {
|
public getImage(url: string, successCallback: (result: image_module.tk.ui.Image) => void, errorCallback?: (e: Error) => void) {
|
||||||
try {
|
try {
|
||||||
if (successCallback) {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
21
declarations.android.d.ts
vendored
21
declarations.android.d.ts
vendored
@ -337,4 +337,23 @@ declare module android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
declare var app;
|
declare var app;
|
||||||
declare var telerik;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
declarations.d.ts
vendored
2
declarations.d.ts
vendored
@ -23,4 +23,4 @@ declare module i {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare var console: i.IConsole;
|
declare var console: i.IConsole;
|
Reference in New Issue
Block a user