@@ -3,6 +3,8 @@ import definition = require("application");
33import frame = require( "ui/frame" ) ;
44import observable = require( "data/observable" ) ;
55import * as typesModule from "utils/types" ;
6+ import * as enumsModule from "ui/enums" ;
7+ let enums : typeof enumsModule ;
68
79global . moduleMerge ( appModule , exports ) ;
810var typedExports : typeof definition = exports ;
@@ -121,28 +123,30 @@ function initLifecycleCallbacks() {
121123let currentOrientation : number ;
122124function initComponentCallbacks ( ) {
123125 let componentCallbacks = new android . content . ComponentCallbacks2 ( {
124- onLowMemory : function ( ) {
126+ onLowMemory : function ( ) {
125127 gc ( ) ;
126128 java . lang . System . gc ( ) ;
127129 typedExports . notify ( < definition . ApplicationEventData > { eventName : typedExports . lowMemoryEvent , object : this , android : this } ) ;
128130 } ,
129-
130- onTrimMemory : function ( level : number ) {
131+
132+ onTrimMemory : function ( level : number ) {
131133 // TODO: This is skipped for now, test carefully for OutOfMemory exceptions
132134 } ,
133-
134- onConfigurationChanged : function ( newConfig : android . content . res . Configuration ) {
135+
136+ onConfigurationChanged : function ( newConfig : android . content . res . Configuration ) {
135137 let newOrientation = newConfig . orientation ;
136- if ( newOrientation === currentOrientation ) {
138+ if ( newOrientation === currentOrientation ) {
137139 return ;
138140 }
139-
140- currentOrientation = newOrientation ;
141141
142- let enums = require ( "ui/enums" ) ;
142+ if ( ! enums ) {
143+ enums = require ( "ui/enums" ) ;
144+ }
145+
146+ currentOrientation = newOrientation ;
143147 let newValue ;
144-
145- switch ( orientation ) {
148+
149+ switch ( newOrientation ) {
146150 case android . content . res . Configuration . ORIENTATION_LANDSCAPE :
147151 newValue = enums . DeviceOrientation . landscape ;
148152 break ;
@@ -162,7 +166,7 @@ function initComponentCallbacks() {
162166 } ) ;
163167 }
164168 } ) ;
165-
169+
166170 return componentCallbacks ;
167171}
168172
@@ -204,10 +208,10 @@ export class AndroidApplication extends observable.Observable implements definit
204208 public onActivityResult : ( requestCode : number , resultCode : number , data : android . content . Intent ) => void ;
205209
206210 public init ( nativeApp : any ) {
207- if ( this . nativeApp ) {
211+ if ( this . nativeApp ) {
208212 throw new Error ( "application.android already initialized." )
209213 }
210-
214+
211215 this . nativeApp = nativeApp ;
212216 this . packageName = nativeApp . getPackageName ( ) ;
213217 this . context = nativeApp . getApplicationContext ( ) ;
@@ -216,7 +220,7 @@ export class AndroidApplication extends observable.Observable implements definit
216220 let componentCallbacks = initComponentCallbacks ( ) ;
217221 this . nativeApp . registerActivityLifecycleCallbacks ( lifecycleCallbacks ) ;
218222 this . nativeApp . registerComponentCallbacks ( componentCallbacks ) ;
219-
223+
220224 this . _registerPendingReceivers ( ) ;
221225 }
222226
@@ -295,8 +299,8 @@ export function start(entry?: frame.NavigationEntry) {
295299 if ( started ) {
296300 throw new Error ( "Application is already started." ) ;
297301 }
298-
299- if ( ! androidApp . nativeApp ) {
302+
303+ if ( ! androidApp . nativeApp ) {
300304 // we are still not initialized, this is possible if no 'androidApp.init' call has been made
301305 let utils = require ( "utils/utils" ) ;
302306 let nativeApp = utils . ad . getApplication ( ) ;
@@ -332,7 +336,7 @@ global.__onLiveSync = function () {
332336 if ( typedExports . android && typedExports . android . paused ) {
333337 return ;
334338 }
335-
339+
336340 appModule . __onLiveSync ( ) ;
337341}
338342
0 commit comments