diff --git a/Application/application.android.ts b/Application/application.android.ts index 5b149defb..e8f331e8a 100644 --- a/Application/application.android.ts +++ b/Application/application.android.ts @@ -7,7 +7,7 @@ require("Utils/module_merge").merge(appModule, exports); var callbacks = android.app.Application.ActivityLifecycleCallbacks; var initEvents = function () { - var androidApp = appModule.current.android; + var androidApp = exports.android; var lifecycleCallbacks = new callbacks({ onActivityCreated: function (activity: any, bundle: any) { if (!androidApp.startActivity) { @@ -87,8 +87,7 @@ var initEvents = function () { export var init = function (nativeApp: android.app.Application) { var app = new AndroidApplication(nativeApp); - appModule.current.os = appModule.TargetOS.Android; - appModule.current.android = app; + exports.android = app; app.init(); } diff --git a/Application/application.d.ts b/Application/application.d.ts index 5747d434a..6b9a0ec13 100644 --- a/Application/application.d.ts +++ b/Application/application.d.ts @@ -1,67 +1,42 @@ /** -* Defines the available target operating systems. +* The main entry point event. This method is expected to return an instance of the root UI for the application. +* This will be an Activity extends for Android and a RootViewController for iOS. */ -export declare enum TargetOS { - /** - * iOS operating system. - */ - iOS, - - /** - * Android operating system. - */ - Android -} +export declare function onLaunch(): any; /** -* The abstraction of an Application object, common for each target OS. +* This method will be called when the Application is suspended. */ -export declare class Application { - /** - * The target operating system of the application. - */ - public os: TargetOS; +export declare function onSuspend(); - /** - * The main entry point event. This method is expected to return an instance of the root UI for the application. - * This will be an Activity extends for Android and a RootViewController for iOS. - */ - public onLaunch: () => any; +/** +* This method will be called when the Application is resumed after it has been suspended. +*/ +export declare function onResume(); - /** - * This method will be called when the Application is suspended. - */ - public onSuspend: () => any; +/** +* This method will be called when the Application is about to exit. +*/ +export declare function onExit(); - /** - * This method will be called when the Application is resumed after it has been suspended. - */ - public onResume: () => any; +/** +* This method will be called when there is low memory on the target device. +*/ +export declare function onLowMemory(); - /** - * This method will be called when the Application is about to exit. - */ - public onExit: () => any; +/** +* This is the Android-specific application object instance. +* Encapsulates methods and properties specific to the Android platform. +* Will be undefined when TargetOS is iOS. +*/ +export declare var android: AndroidApplication; - /** - * This method will be called when there is low memory on the target device. - */ - public onLowMemory: () => any; - - /** - * This is the Android-specific application object instance. - * Encapsulates methods and properties specific to the Android platform. - * Will be undefined when TargetOS is iOS. - */ - public android: AndroidApplication; - - /** - * This is the iOS-specific application object instance. - * Encapsulates methods and properties specific to the iOS platform. - * Will be undefined when TargetOS is Android. - */ - public ios: iOSApplication; -} +/** +* This is the iOS-specific application object instance. +* Encapsulates methods and properties specific to the iOS platform. +* Will be undefined when TargetOS is Android. +*/ +export declare var ios: iOSApplication; /** * The abstraction of an Android-specific application object. @@ -147,9 +122,4 @@ export declare class iOSApplication { /** * Entry point for the module. Initializes the Application singleton and hooks application lifecycle events. */ -export declare function init(nativeApp: any); - -/** -* The current singleton instance of the application object. -*/ -export declare var current: Application; \ No newline at end of file +export declare function init(nativeApp: any); \ No newline at end of file diff --git a/Application/application.ios.ts b/Application/application.ios.ts index e0a895efd..6a91198d2 100644 --- a/Application/application.ios.ts +++ b/Application/application.ios.ts @@ -29,8 +29,7 @@ require("Utils/module_merge").merge(appModule, exports); // TODO: Declarations export var init = function (nativeApp: any) { var app = new iOSApplication(nativeApp); - appModule.current.os = appModule.TargetOS.iOS; - appModule.current.ios = app; + exports.ios = app; app.init(); } @@ -55,10 +54,8 @@ class iOSApplication { this.window.backgroundColor = UIKit.UIColor.whiteColor(); this.window.makeKeyAndVisible(); - var iosApp = appModule.current.ios; - - if (appModule.current.onLaunch) { - this.window.rootViewController = appModule.current.onLaunch(); + if (appModule.onLaunch) { + this.window.rootViewController = appModule.onLaunch(); } else { log("Missing TK.UI.Application.current.onLaunch"); } @@ -69,8 +66,8 @@ class iOSApplication { applicationDidBecomeActive: function (application) { log("applicationDidBecomeActive: " + application); - if (appModule.current.onResume) { - appModule.current.onResume(); + if (appModule.onResume) { + appModule.onResume(); } }, @@ -80,8 +77,8 @@ class iOSApplication { applicationDidEnterBackground: function (application) { log("applicationDidEnterBackground: " + application); - if (appModule.current.onSuspend) { - appModule.current.onSuspend(); + if (appModule.onSuspend) { + appModule.onSuspend(); } }, @@ -91,15 +88,15 @@ class iOSApplication { applicationWillTerminate: function (application) { log("applicationWillTerminate: " + application); - if (appModule.current.onExit) { - appModule.current.onExit(); + if (appModule.onExit) { + appModule.onExit(); } }, applicationDidReceiveMemoryWarning: function (application) { log("applicationDidReceiveMemoryWarning: " + application); - if (appModule.current.onLowMemory) { - appModule.current.onLowMemory(); + if (appModule.onLowMemory) { + appModule.onLowMemory(); } } } diff --git a/Application/application_common.ts b/Application/application_common.ts index 682d1f8b7..69b3413da 100644 --- a/Application/application_common.ts +++ b/Application/application_common.ts @@ -1,27 +1,23 @@ import consoleModule = require("Console/console"); -export enum TargetOS { - iOS, - Android -} - -export class Application { - public os: TargetOS; +// TODO: This is put in the global context, is this the preferred approach +console = new consoleModule.Console(); - constructor() { - // TODO: This is put in the global context, is this the preferred approach - console = new consoleModule.Console(); - } - - public onLaunch: () => any; - public onSuspend: () => any; - public onResume: () => any; - public onExit: () => any; - public onLowMemory: () => any; - - // TODO: These fields are declared by the application.d.ts file and intellisense will come from there - public android: any; - public ios: any; +export var onLaunch = function (): any { } -export var current = new Application(); \ No newline at end of file +export var onSuspend = function (): void { +} + +export var onResume = function (): void { +} + +export var onExit = function (): void { +} + +export var onLowMemory = function (): void { +} + +export var android = undefined; + +export var ios = undefined; \ No newline at end of file diff --git a/Camera/camera.android.ts b/Camera/camera.android.ts index 93ebf5e2d..2ba1bc140 100644 --- a/Camera/camera.android.ts +++ b/Camera/camera.android.ts @@ -6,7 +6,7 @@ var REQUEST_SELECT_PICTURE: number = 2; export class CameraManager { public takePicture(params: any, onSuccess: (imageData: any) => any, onError?: (error: any) => any) { var takePictureIntent = new android.content.Intent('android.media.action.IMAGE_CAPTURE'); - var androidApp = appModule.current.android; + var androidApp = appModule.android; if (takePictureIntent.resolveActivity(androidApp.context.getPackageManager()) !== null) { androidApp.currentActivity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); @@ -16,7 +16,7 @@ export class CameraManager { // options { useSavedPhotos: true } public pictureFromLibrary(params: any, onSuccess: (imageData: any) => any, onError?: (error: any) => any) { var readPictureIntent = new android.content.Intent(); - var androidApp = appModule.current.android; + var androidApp = appModule.android; readPictureIntent.setType('image/*'); readPictureIntent.setAction('android.intent.action.GET_CONTENT'); diff --git a/FileSystem/file_system_access.android.ts b/FileSystem/file_system_access.android.ts index 1129e12f4..2ffcfd5a7 100644 --- a/FileSystem/file_system_access.android.ts +++ b/FileSystem/file_system_access.android.ts @@ -207,13 +207,13 @@ export class FileSystemAccess { } public getDocumentsFolderPath(): string { - var context = appModule.current.android.context; + var context = appModule.android.context; var dir = context.getFilesDir(); return dir.getAbsolutePath(); } public getTempFolderPath(): string { - var context = appModule.current.android.context; + var context = appModule.android.context; var dir = context.getCacheDir(); return dir.getAbsolutePath(); } diff --git a/Image/image.android.ts b/Image/image.android.ts index 458e6ffbb..fee065f60 100644 --- a/Image/image.android.ts +++ b/Image/image.android.ts @@ -13,7 +13,7 @@ export class Image { } public loadFromResource(name: string): boolean { - var androidApp = appModule.current.android; + var androidApp = appModule.android; var res = androidApp.context.getResources(); if (res) { var identifier: number = res.getIdentifier(name, 'drawable', androidApp.packageName); diff --git a/Location/location.android.ts b/Location/location.android.ts index c308ddc7b..5f64d4a28 100644 --- a/Location/location.android.ts +++ b/Location/location.android.ts @@ -59,7 +59,7 @@ export class LocationManager { public static isEnabled(): boolean { var criteria = new android.location.Criteria(); criteria.setAccuracy(1); // low ? fine ? who knows what 1 means (bug in android docs?) - var lm = appModule.current.android.context.getSystemService(android.content.Context.LOCATION_SERVICE); + var lm = appModule.android.context.getSystemService(android.content.Context.LOCATION_SERVICE); return (lm.getBestProvider(criteria, true) != null) ? true : false; } @@ -80,7 +80,7 @@ export class LocationManager { this.minimumUpdateTime = 200; this.isStarted = false; - this.androidLocationManager = appModule.current.android.context.getSystemService(android.content.Context.LOCATION_SERVICE); + this.androidLocationManager = appModule.android.context.getSystemService(android.content.Context.LOCATION_SERVICE); } //////////////////////// diff --git a/UserPreferences/user_preferences.android.ts b/UserPreferences/user_preferences.android.ts index e2f5218f6..97e593d33 100644 --- a/UserPreferences/user_preferences.android.ts +++ b/UserPreferences/user_preferences.android.ts @@ -5,7 +5,7 @@ export class UserPreferences { private sharedPreferences: any; constructor() { - this.sharedPreferences = appModule.current.android.context.getSharedPreferences("prefs.db", 0); + this.sharedPreferences = appModule.android.context.getSharedPreferences("prefs.db", 0); } public containsKey(key: string): boolean { diff --git a/http/http_request.android.ts b/http/http_request.android.ts index ce2768261..479da201c 100644 --- a/http/http_request.android.ts +++ b/http/http_request.android.ts @@ -11,7 +11,7 @@ export function request(options: http.HttpRequestOptions): promises.Promise