diff --git a/Application/application.android.ts b/Application/application.android.ts index aa23f6c7a..8b5f8f8d6 100644 --- a/Application/application.android.ts +++ b/Application/application.android.ts @@ -1,14 +1,13 @@ -import app_common_module = require("Application/application_common"); +import appModule = require("Application/application_common"); // merge the exports of the application_common file with the exports of this file declare var exports; -require("Utils/module_merge").merge(app_common_module, exports); +require("Utils/module_merge").merge(appModule, exports); -var currentApp = app_common_module.Application.current; var callbacks = android.app.Application.ActivityLifecycleCallbacks; var initEvents = function () { - var androidApp = app_common_module.Application.current.android; + var androidApp = appModule.current.android; var lifecycleCallbacks = new callbacks({ onActivityCreated: function (activity: any, bundle: any) { if (!androidApp.startActivity) { @@ -92,8 +91,8 @@ var initEvents = function () { export var init = function (nativeApp: android.app.Application) { var app = new AndroidApplication(nativeApp); - currentApp.os = app_common_module.TargetOS.Android; - currentApp.android = app; + appModule.current.os = appModule.TargetOS.Android; + appModule.current.android = app; app.init(); } diff --git a/Application/application.d.ts b/Application/application.d.ts index ffb84e531..3bf09baf1 100644 --- a/Application/application.d.ts +++ b/Application/application.d.ts @@ -3,8 +3,9 @@ Android } +export declare var current: Application; + export declare class Application { - static current: Application; public os: TargetOS; public onLaunch: () => any; diff --git a/Application/application.ios.ts b/Application/application.ios.ts index a4ed63311..e0a895efd 100644 --- a/Application/application.ios.ts +++ b/Application/application.ios.ts @@ -20,19 +20,17 @@ log("JavaScript loading ended."); */ -import app_common_module = require("Application/application_common"); +import appModule = require("Application/application_common"); // merge the exports of the application_common file with the exports of this file declare var exports; -require("Utils/module_merge").merge(app_common_module, exports); - -var currentApp = app_common_module.Application.current; +require("Utils/module_merge").merge(appModule, exports); // TODO: Declarations export var init = function (nativeApp: any) { var app = new iOSApplication(nativeApp); - currentApp.os = app_common_module.TargetOS.iOS; - currentApp.ios = app; + appModule.current.os = appModule.TargetOS.iOS; + appModule.current.ios = app; app.init(); } @@ -57,10 +55,10 @@ class iOSApplication { this.window.backgroundColor = UIKit.UIColor.whiteColor(); this.window.makeKeyAndVisible(); - var iosApp = currentApp.ios; + var iosApp = appModule.current.ios; - if (currentApp.onLaunch) { - this.window.rootViewController = currentApp.onLaunch(); + if (appModule.current.onLaunch) { + this.window.rootViewController = appModule.current.onLaunch(); } else { log("Missing TK.UI.Application.current.onLaunch"); } @@ -71,8 +69,8 @@ class iOSApplication { applicationDidBecomeActive: function (application) { log("applicationDidBecomeActive: " + application); - if (currentApp.onResume) { - currentApp.onResume(); + if (appModule.current.onResume) { + appModule.current.onResume(); } }, @@ -82,8 +80,8 @@ class iOSApplication { applicationDidEnterBackground: function (application) { log("applicationDidEnterBackground: " + application); - if (currentApp.onSuspend) { - currentApp.onSuspend(); + if (appModule.current.onSuspend) { + appModule.current.onSuspend(); } }, @@ -93,15 +91,15 @@ class iOSApplication { applicationWillTerminate: function (application) { log("applicationWillTerminate: " + application); - if (currentApp.onExit) { - currentApp.onExit(); + if (appModule.current.onExit) { + appModule.current.onExit(); } }, applicationDidReceiveMemoryWarning: function (application) { log("applicationDidReceiveMemoryWarning: " + application); - if (currentApp.onLowMemory) { - currentApp.onLowMemory(); + if (appModule.current.onLowMemory) { + appModule.current.onLowMemory(); } } } diff --git a/Application/application_common.ts b/Application/application_common.ts index 76b215764..8072e6062 100644 --- a/Application/application_common.ts +++ b/Application/application_common.ts @@ -18,9 +18,9 @@ export class Application { public onExit: () => any; public onLowMemory: () => any; - public static current: Application = new Application(); - // TODO: These fields are declared by the application.d.ts file and intellisense will come from there public android: any; public ios: any; -} \ No newline at end of file +} + +export var current = new Application(); \ No newline at end of file diff --git a/Camera/camera.android.ts b/Camera/camera.android.ts index 4d3d7c6f8..93ebf5e2d 100644 --- a/Camera/camera.android.ts +++ b/Camera/camera.android.ts @@ -1,4 +1,4 @@ -import app_module = require("Application/application"); +import appModule = require("Application/application"); var REQUEST_IMAGE_CAPTURE: number = 1; var REQUEST_SELECT_PICTURE: number = 2; @@ -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 = app_module.Application.current.android; + var androidApp = appModule.current.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 = app_module.Application.current.android; + var androidApp = appModule.current.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 3ef789f14..d20672f4f 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.Application.current.android.context; + var context = appModule.current.android.context; var dir = context.getFilesDir(); return dir.getAbsolutePath(); } public getTempFolderPath(): string { - var context = appModule.Application.current.android.context; + var context = appModule.current.android.context; var dir = context.getCacheDir(); return dir.getAbsolutePath(); } diff --git a/Image/image.android.ts b/Image/image.android.ts index b1648f293..cc6b88a3c 100644 --- a/Image/image.android.ts +++ b/Image/image.android.ts @@ -1,4 +1,4 @@ -import app_module = require("Application/application"); +import appModule = require("Application/application"); export enum ImageType { PNG = 0, @@ -33,7 +33,7 @@ export class Image { } public loadFromResource(name: string): boolean { - var androidApp = app_module.Application.current.android; + var androidApp = appModule.current.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 0546f84eb..9d71527bf 100644 --- a/Location/location.android.ts +++ b/Location/location.android.ts @@ -1,5 +1,5 @@ import types = require("Location/location_types"); -import app_module = require("Application/application"); +import appModule = require("Application/application"); // merge the exports of the types module with the exports of this file declare var exports; @@ -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 = app_module.Application.current.android.context.getSystemService(android.content.Context.LOCATION_SERVICE); + var lm = appModule.current.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 = app_module.Application.current.android.context.getSystemService(android.content.Context.LOCATION_SERVICE); + this.androidLocationManager = appModule.current.android.context.getSystemService(android.content.Context.LOCATION_SERVICE); } //////////////////////// diff --git a/UserPreferences/user_preferences.android.ts b/UserPreferences/user_preferences.android.ts index 6035983ba..e2f5218f6 100644 --- a/UserPreferences/user_preferences.android.ts +++ b/UserPreferences/user_preferences.android.ts @@ -1,11 +1,11 @@ import utils_module = require("Utils/utils_android"); -import app_module = require("Application/application"); +import appModule = require("Application/application"); export class UserPreferences { private sharedPreferences: any; constructor() { - this.sharedPreferences = app_module.Application.current.android.context.getSharedPreferences("prefs.db", 0); + this.sharedPreferences = appModule.current.android.context.getSharedPreferences("prefs.db", 0); } public containsKey(key: string): boolean {