mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 05:18:39 +08:00
namespaces removed (except Application)
This commit is contained in:
@ -1,89 +1,85 @@
|
||||
import image_module = require("Image/image");
|
||||
/**
|
||||
* Android specific WebClient implementation.
|
||||
*/
|
||||
|
||||
import image_module = require("Image/image");
|
||||
import app_module = require("Application/application");
|
||||
|
||||
export module tk {
|
||||
export module web {
|
||||
/**
|
||||
* Android specific WebClient implementation.
|
||||
*/
|
||||
export class Client {
|
||||
/**
|
||||
* Downloads string from url.
|
||||
*/
|
||||
public getString(url: string, successCallback: (result: string) => void, errorCallback?: (e: Error) => void) {
|
||||
try {
|
||||
if (successCallback) {
|
||||
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(new Error(e.toString()));
|
||||
return;
|
||||
}
|
||||
successCallback(result);
|
||||
}
|
||||
})).get();
|
||||
}
|
||||
} catch (ex) {
|
||||
|
||||
if (errorCallback) {
|
||||
errorCallback(ex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public getJSON(url: string, successCallback: (result: Object) => void, errorCallback?: (e: Error) => void) {
|
||||
try
|
||||
{
|
||||
this.getString(url, function (data) {
|
||||
if (successCallback) {
|
||||
successCallback(JSON.parse(data));
|
||||
export class Client {
|
||||
/**
|
||||
* Downloads string from url.
|
||||
*/
|
||||
public getString(url: string, successCallback: (result: string) => void, errorCallback?: (e: Error) => void) {
|
||||
try {
|
||||
if (successCallback) {
|
||||
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(new Error(e.toString()));
|
||||
return;
|
||||
}
|
||||
}, errorCallback);
|
||||
} catch (ex) {
|
||||
if (errorCallback) {
|
||||
errorCallback(ex);
|
||||
successCallback(result);
|
||||
}
|
||||
}
|
||||
})).get();
|
||||
}
|
||||
} catch (ex) {
|
||||
|
||||
if (errorCallback) {
|
||||
errorCallback(ex);
|
||||
}
|
||||
|
||||
public getImage(url: string, successCallback: (result: image_module.tk.ui.Image) => void, errorCallback?: (e: Error) => void) {
|
||||
try {
|
||||
if (successCallback) {
|
||||
var context = app_module.tk.ui.Application.current.android.context;
|
||||
com.koushikdutta.ion.Ion.with(context, url).asBitmap().setCallback(new com.koushikdutta.async.future.FutureCallback({
|
||||
onCompleted: function (e, result) {
|
||||
if (e && errorCallback) {
|
||||
errorCallback(new Error(e.toString()));
|
||||
return;
|
||||
}
|
||||
|
||||
var image = new image_module.tk.ui.Image();
|
||||
image.loadFromBitmap(result);
|
||||
|
||||
successCallback(image);
|
||||
}
|
||||
})).get();
|
||||
}
|
||||
} catch (ex) {
|
||||
|
||||
if (errorCallback) {
|
||||
errorCallback(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getJSON(url: string, successCallback: (result: Object) => void, errorCallback?: (e: Error) => void) {
|
||||
try {
|
||||
this.getString(url, function (data) {
|
||||
if (successCallback) {
|
||||
successCallback(JSON.parse(data));
|
||||
}
|
||||
}
|
||||
|
||||
private static get(url: string, successCallback: (result: any) => void, errorCallback?: (e: Error) => void) {
|
||||
try {
|
||||
|
||||
} catch (ex) {
|
||||
if (errorCallback) {
|
||||
errorCallback(ex);
|
||||
}
|
||||
}
|
||||
}, errorCallback);
|
||||
} catch (ex) {
|
||||
if (errorCallback) {
|
||||
errorCallback(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getImage(url: string, successCallback: (result: image_module.Image) => void, errorCallback?: (e: Error) => void) {
|
||||
try {
|
||||
if (successCallback) {
|
||||
var context = app_module.tk.ui.Application.current.android.context;
|
||||
com.koushikdutta.ion.Ion.with(context, url).asBitmap().setCallback(new com.koushikdutta.async.future.FutureCallback({
|
||||
onCompleted: function (e, result) {
|
||||
if (e && errorCallback) {
|
||||
errorCallback(new Error(e.toString()));
|
||||
return;
|
||||
}
|
||||
|
||||
var image = new image_module.Image();
|
||||
image.loadFromBitmap(result);
|
||||
|
||||
successCallback(image);
|
||||
}
|
||||
})).get();
|
||||
}
|
||||
} catch (ex) {
|
||||
|
||||
if (errorCallback) {
|
||||
errorCallback(ex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static get(url: string, successCallback: (result: any) => void, errorCallback?: (e: Error) => void) {
|
||||
try {
|
||||
|
||||
} catch (ex) {
|
||||
if (errorCallback) {
|
||||
errorCallback(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user