mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
28
WebClient/web_client.d.ts
vendored
28
WebClient/web_client.d.ts
vendored
@ -1,17 +1,11 @@
|
||||
import image_module = require("Image/image");
|
||||
/**
|
||||
* Web (WebClient) module.
|
||||
*/
|
||||
export declare module tk {
|
||||
export module web {
|
||||
/**
|
||||
* The Client interface.
|
||||
*/
|
||||
export class Client {
|
||||
private static get(url: string, successCallback: (result: any) => void, errorCallback?: (e: Error) => void)
|
||||
getString(url: string, successCallback: (result: string) => void, errorCallback?: (e: Error) => void)
|
||||
getJSON(url: string, successCallback: (result: Object) => void, errorCallback?: (e: Error) => void)
|
||||
getImage(url: string, successCallback: (result: image_module.tk.ui.Image) => void, errorCallback?: (e: Error) => void)
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The Client interface.
|
||||
*/
|
||||
import image_module = require("Image/image");
|
||||
|
||||
declare class Client {
|
||||
private static get(url: string, successCallback: (result: any) => void, errorCallback?: (e: Error) => void)
|
||||
getString(url: string, successCallback: (result: string) => void, errorCallback?: (e: Error) => void)
|
||||
getJSON(url: string, successCallback: (result: Object) => void, errorCallback?: (e: Error) => void)
|
||||
getImage(url: string, successCallback: (result: image_module.Image) => void, errorCallback?: (e: Error) => void)
|
||||
}
|
@ -1,75 +1,72 @@
|
||||
import image_module = require("Image/image");
|
||||
/**
|
||||
* iOS specific WebClient implementation.
|
||||
*/
|
||||
|
||||
export module tk {
|
||||
export module web {
|
||||
/**
|
||||
* iOS specific WebClient implementation.
|
||||
*/
|
||||
export class Client {
|
||||
/**
|
||||
* Downloads string from url.
|
||||
*/
|
||||
public getString(url: string, successCallback: (result: string) => void, errorCallback?: (e: Error) => void) {
|
||||
try {
|
||||
Client.get(url, function (data) {
|
||||
if (successCallback) {
|
||||
successCallback(Foundation.NSString.initWithDataEncoding(data, 4));
|
||||
}
|
||||
}, errorCallback);
|
||||
} 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));
|
||||
}
|
||||
}, errorCallback);
|
||||
} catch (ex) {
|
||||
if (errorCallback) {
|
||||
errorCallback(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getImage(url: string, successCallback: (result: image_module.tk.ui.Image) => void, errorCallback?: (e: Error) => void) {
|
||||
Client.get(url, function (data) {
|
||||
if (successCallback) {
|
||||
var image = new image_module.tk.ui.Image();
|
||||
image.loadFromData(data);
|
||||
successCallback(image);
|
||||
}
|
||||
}, errorCallback);
|
||||
}
|
||||
|
||||
private static get(url: string, successCallback: (result: any) => void, errorCallback?: (e: Error) => void) {
|
||||
try {
|
||||
var sessionConfig = Foundation.NSURLSessionConfiguration.defaultSessionConfiguration();
|
||||
var queue = Foundation.NSOperationQueue.mainQueue();
|
||||
var session = Foundation.NSURLSession.sessionWithConfigurationDelegateDelegateQueue(sessionConfig, null, queue);
|
||||
var dataTask = session.dataTaskWithURLCompletionHandler(Foundation.NSURL.URLWithString(url), function (data, response, error) {
|
||||
if (error) {
|
||||
if (errorCallback) {
|
||||
errorCallback(new Error(error.localizedDescription()));
|
||||
}
|
||||
} else if (successCallback) {
|
||||
successCallback(data);
|
||||
}
|
||||
});
|
||||
|
||||
dataTask.resume();
|
||||
session.finishTasksAndInvalidate();
|
||||
} catch (ex) {
|
||||
if (errorCallback) {
|
||||
errorCallback(ex);
|
||||
}
|
||||
import image_module = require("Image/image");
|
||||
|
||||
export class Client {
|
||||
/**
|
||||
* Downloads string from url.
|
||||
*/
|
||||
public getString(url: string, successCallback: (result: string) => void, errorCallback?: (e: Error) => void) {
|
||||
try {
|
||||
Client.get(url, function (data) {
|
||||
if (successCallback) {
|
||||
successCallback(Foundation.NSString.initWithDataEncoding(data, 4));
|
||||
}
|
||||
}, errorCallback);
|
||||
} 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));
|
||||
}
|
||||
}, errorCallback);
|
||||
} catch (ex) {
|
||||
if (errorCallback) {
|
||||
errorCallback(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getImage(url: string, successCallback: (result: image_module.Image) => void, errorCallback?: (e: Error) => void) {
|
||||
Client.get(url, function (data) {
|
||||
if (successCallback) {
|
||||
var image = new image_module.Image();
|
||||
image.loadFromData(data);
|
||||
successCallback(image);
|
||||
}
|
||||
}, errorCallback);
|
||||
}
|
||||
|
||||
private static get(url: string, successCallback: (result: any) => void, errorCallback?: (e: Error) => void) {
|
||||
try {
|
||||
var sessionConfig = Foundation.NSURLSessionConfiguration.defaultSessionConfiguration();
|
||||
var queue = Foundation.NSOperationQueue.mainQueue();
|
||||
var session = Foundation.NSURLSession.sessionWithConfigurationDelegateDelegateQueue(sessionConfig, null, queue);
|
||||
var dataTask = session.dataTaskWithURLCompletionHandler(Foundation.NSURL.URLWithString(url), function (data, response, error) {
|
||||
if (error) {
|
||||
if (errorCallback) {
|
||||
errorCallback(new Error(error.localizedDescription()));
|
||||
}
|
||||
} else if (successCallback) {
|
||||
successCallback(data);
|
||||
}
|
||||
});
|
||||
|
||||
dataTask.resume();
|
||||
session.finishTasksAndInvalidate();
|
||||
} catch (ex) {
|
||||
if (errorCallback) {
|
||||
errorCallback(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user