Skip to content

Commit f09ab8f

Browse files
committed
Added private Kimera build for UnitTestApp. Added Application module snippets.
1 parent 6eeffa3 commit f09ab8f

File tree

5 files changed

+85
-5
lines changed

5 files changed

+85
-5
lines changed

Tests/TKUnit.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,14 @@ export var waitUntilReady = function (isReady: () => boolean, timeoutSec?: numbe
114114
}
115115
};
116116

117-
var doModalAndroid = function (quitLoop: () => boolean, timeoutSec: number) {
118-
if (!quitLoop) {
117+
// Setup for the Android modal loop implementation
118+
// TODO: If these platform-specific implementations continue to grow, think of per-platform separation (TKUnit.android)
119+
var nextMethod;
120+
var targetField;
121+
var prepared;
122+
123+
var prepareModal = function () {
124+
if (prepared) {
119125
return;
120126
}
121127

@@ -143,6 +149,16 @@ var doModalAndroid = function (quitLoop: () => boolean, timeoutSec: number) {
143149
}
144150
}
145151

152+
prepared = true;
153+
}
154+
155+
var doModalAndroid = function (quitLoop: () => boolean, timeoutSec: number) {
156+
if (!quitLoop) {
157+
return;
158+
}
159+
160+
prepareModal();
161+
146162
var queue = android.os.Looper.myQueue();
147163

148164
var quit = false;

Tests/application-tests-common.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1-
import app = require("application/application");
1+
// <snippet name="application">
2+
// # Application
3+
// The Application module provides abstraction over the platform-specific Application implementations.
4+
// It is the main BCL module and is required for other BCL modules to work properly.
5+
// The default bootstrap.js implementation for each platform loads and initializes this module.
6+
// ``` JavaScript
7+
import app = require("application/application");
8+
// ```
9+
// The pre-required `app` module is used throughout the following code snippets.
10+
// </snippet>
11+
12+
// <snippet name="application">
13+
// ### Initialization
14+
// ``` JavaScript
15+
//// The native app instance depends on the target platform
16+
var nativeAppInstance;
17+
app.init(nativeAppInstance);
18+
// ```
19+
// </snippet>
20+
21+
// <snippet name="application">
22+
// ### Checking the target platform
23+
// Use the following code in case you need to check somewhere in your code the platform you are running against:
24+
// ``` JavaScript
25+
if (app.android) {
26+
//// we are running on Android device
27+
} else if (app.ios) {
28+
//// we are running on iOS device
29+
}
30+
// ```
31+
// </snippet>
32+
233
import TKUnit = require("Tests/TKUnit");
334

435
export var testInitDefined = function () {

Tests/application-tests.android.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,31 @@ import commonTests = require("Tests/application-tests-common");
66
declare var exports;
77
require("utils/module-merge").merge(commonTests, exports);
88

9+
// <snippet name="application">
10+
// ### Using the Android-specific implementation
11+
// ``` JavaScript
12+
// Accessing the Android-specific object instance (will be undefined if running on iOS)
13+
var androidApp = app.android;
14+
// ```
15+
// Using the Android Application context
16+
// ``` JavaScript
17+
var context = app.android.context;
18+
//// get the Files (Documents) folder (directory)
19+
var dir = context.getFilesDir();
20+
// ```
21+
// Tracking the current Activity
22+
// ``` JavaScript
23+
if (androidApp.currentActivity === androidApp.startActivity) {
24+
//// We are currently in the main (start) activity of the application
25+
}
26+
// ```
27+
// </snippet>
28+
929
export var testAndroidApplicationInitialized = function () {
1030
TKUnit.assert(app.android, "Android application not initialized.");
1131
TKUnit.assert(app.android.context, "Android context not initialized.");
1232
TKUnit.assert(app.android.currentActivity, "Android currentActivity not initialized.");
13-
TKUnit.assert(app.android.startActivity, "Android mainActivity not initialized.");
33+
TKUnit.assert(app.android.startActivity, "Android startActivity not initialized.");
1434
TKUnit.assert(app.android.nativeApp, "Android nativeApp not initialized.");
1535
TKUnit.assert(app.android.packageName, "Android packageName not initialized.");
1636
}

application/application.android.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,17 @@ var initEvents = function () {
8585
return lifecycleCallbacks;
8686
}
8787

88+
var initialized;
8889
export var init = function (nativeApp: android.app.Application) {
90+
if (initialized) {
91+
return;
92+
}
93+
8994
var app = new AndroidApplication(nativeApp);
9095
exports.android = app;
9196
app.init();
97+
98+
initialized = true;
9299
}
93100

94101
class AndroidApplication {

application/application.ios.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,17 @@ import appModule = require("application/application-common");
2626
declare var exports;
2727
require("utils/module-merge").merge(appModule, exports);
2828

29-
// TODO: Declarations
29+
var initialized;
3030
export var init = function (nativeApp: any) {
31+
if (initialized) {
32+
return;
33+
}
34+
3135
var app = new iOSApplication(nativeApp);
3236
exports.ios = app;
3337
app.init();
38+
39+
initialized = true;
3440
}
3541

3642
class iOSApplication {

0 commit comments

Comments
 (0)