| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,21 +1,16 @@ | |||
| 1 | - // >> application-require | ||
| 2 | - import * as app from "tns-core-modules/application"; | ||
| 1 | + import * as app from "tns-core-modules/application"; | ||
| 3 | 2 | import * as platform from "tns-core-modules/platform"; | |
| 4 | - // << application-require | ||
| 5 | 3 | ||
| 6 | - // >> application-app-check | ||
| 4 | + import * as TKUnit from "../tk-unit"; | ||
| 5 | + | ||
| 7 | 6 | if (app.android) { | |
| 8 | - console.log("We are running on Android device!"); | ||
| 7 | + console.log("We are running on an Android device!"); | ||
| 9 | 8 | } else if (app.ios) { | |
| 10 | - console.log("We are running on iOS device"); | ||
| 9 | + console.log("We are running on an iOS device!"); | ||
| 11 | 10 | } | |
| 12 | - // << application-app-check | ||
| 13 | - | ||
| 14 | - import * as TKUnit from "../tk-unit"; | ||
| 15 | 11 | ||
| 16 | 12 | export function testInitialized() { | |
| 17 | 13 | if (platform.device.os === platform.platformNames.android) { | |
| 18 | - // we have the android defined | ||
| 19 | 14 | TKUnit.assert(app.android, "Application module not properly intialized"); | |
| 20 | 15 | } else if (platform.device.os === platform.platformNames.ios) { | |
| 21 | 16 | TKUnit.assert(app.ios, "Application module not properly intialized"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,12 +37,13 @@ if (app.android) { | |||
| 37 | 37 | } | |
| 38 | 38 | // << application-app-android-broadcast | |
| 39 | 39 | ||
| 40 | - export var testAndroidApplicationInitialized = function () { | ||
| 40 | + export function testAndroidApplicationInitialized() { | ||
| 41 | 41 | TKUnit.assert(app.android, "Android application not initialized."); | |
| 42 | 42 | TKUnit.assert(app.android.context, "Android context not initialized."); | |
| 43 | 43 | TKUnit.assert(app.android.foregroundActivity, "Android foregroundActivity not initialized."); | |
| 44 | - TKUnit.assert(app.android.foregroundActivity.isNativeScriptActivity, "Andorid foregroundActivity.isNativeScriptActivity is true"); | ||
| 44 | + TKUnit.assert(app.android.foregroundActivity.isNativeScriptActivity, "Andorid foregroundActivity.isNativeScriptActivity is false."); | ||
| 45 | 45 | TKUnit.assert(app.android.startActivity, "Android startActivity not initialized."); | |
| 46 | 46 | TKUnit.assert(app.android.nativeApp, "Android nativeApp not initialized."); | |
| 47 | + TKUnit.assert(app.android.orientation, "Android orientation not initialized."); | ||
| 47 | 48 | TKUnit.assert(app.android.packageName, "Android packageName not initialized."); | |
| 48 | - }; | ||
| 49 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,2 @@ | |||
| 1 | - /* tslint:disable */ | ||
| 2 | - //@private | ||
| 3 | 1 | import * as android from "./application-tests.android"; | |
| 4 | - import * as iOS from "./application-tests.ios"; | ||
| 2 | + import * as iOS from "./application-tests.ios"; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | /* tslint:disable:no-unused-variable */ | |
| 2 | 2 | import * as app from "tns-core-modules/application"; | |
| 3 | + import * as TKUnit from "../tk-unit"; | ||
| 3 | 4 | ||
| 4 | 5 | export * from "./application-tests-common"; | |
| 5 | 6 | ||
@@ -39,3 +40,12 @@ if (app.ios) { | |||
| 39 | 40 | } | |
| 40 | 41 | ||
| 41 | 42 | // << application-ios-delegate | |
| 43 | + | ||
| 44 | + export function testIOSApplicationInitialized() { | ||
| 45 | + TKUnit.assert(app.ios, "iOS application not initialized."); | ||
| 46 | + TKUnit.assert(app.ios.delegate, "iOS delegate not initialized."); | ||
| 47 | + TKUnit.assert(app.ios.nativeApp, "iOS nativeApp not initialized."); | ||
| 48 | + TKUnit.assert(app.ios.orientation, "iOS orientation not initialized."); | ||
| 49 | + TKUnit.assert(app.ios.window, "iOS window not initialized."); | ||
| 50 | + TKUnit.assert(app.ios.rootController, "iOS root controller not initialized."); | ||
| 51 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,46 +1,41 @@ | |||
| 1 | 1 | import * as TKUnit from "../tk-unit"; | |
| 2 | 2 | import * as app from "tns-core-modules/application"; | |
| 3 | - import { isIOS, isAndroid } from "tns-core-modules/platform"; | ||
| 4 | - | ||
| 5 | - // >> platform-require | ||
| 6 | 3 | import * as platformModule from "tns-core-modules/platform"; | |
| 7 | - // << platform-require | ||
| 8 | 4 | ||
| 9 | - export function test_setTimeout_isDefined() { | ||
| 10 | - var expected; | ||
| 5 | + export function test_platform() { | ||
| 6 | + let expectedPlatform; | ||
| 11 | 7 | if (app.android) { | |
| 12 | - expected = "Android"; | ||
| 13 | - } | ||
| 14 | - else { | ||
| 15 | - expected = "iOS"; | ||
| 8 | + expectedPlatform = "Android"; | ||
| 9 | + } else { | ||
| 10 | + expectedPlatform = "iOS"; | ||
| 16 | 11 | } | |
| 17 | - TKUnit.assertEqual(platformModule.device.os, expected, "device.os"); | ||
| 12 | + TKUnit.assertEqual(platformModule.device.os, expectedPlatform); | ||
| 18 | 13 | } | |
| 19 | 14 | ||
| 20 | - export function snippet_print_all() { | ||
| 21 | - // >> platform-current | ||
| 22 | - console.log("Device model: " + platformModule.device.model); | ||
| 23 | - console.log("Device type: " + platformModule.device.deviceType); | ||
| 24 | - console.log("Device manufacturer: " + platformModule.device.manufacturer); | ||
| 25 | - console.log("Preferred language: " + platformModule.device.language); | ||
| 26 | - console.log("Preferred region: " + platformModule.device.region); | ||
| 27 | - console.log("OS: " + platformModule.device.os); | ||
| 28 | - console.log("OS version: " + platformModule.device.osVersion); | ||
| 29 | - console.log("SDK version: " + platformModule.device.sdkVersion); | ||
| 30 | - console.log("Device UUID: " + platformModule.device.uuid); | ||
| 15 | + export function test_device_screen() { | ||
| 16 | + TKUnit.assert(platformModule.device.model, "Device model not initialized."); | ||
| 17 | + TKUnit.assert(platformModule.device.manufacturer, "Device manufacturer not initialized."); | ||
| 18 | + TKUnit.assert(platformModule.device.deviceType, "Device type not initialized."); | ||
| 19 | + TKUnit.assert(platformModule.device.uuid, "Device UUID not initialized."); | ||
| 20 | + | ||
| 21 | + TKUnit.assert(platformModule.device.language, "Preferred language not initialized."); | ||
| 22 | + TKUnit.assert(platformModule.device.region, "Preferred region not initialized."); | ||
| 23 | + | ||
| 24 | + TKUnit.assert(platformModule.device.os, "OS not initialized."); | ||
| 25 | + TKUnit.assert(platformModule.device.osVersion, "OS version not initialized."); | ||
| 26 | + TKUnit.assert(platformModule.device.sdkVersion, "SDK version not initialized."); | ||
| 31 | 27 | ||
| 32 | - console.log("Screen width (px): " + platformModule.screen.mainScreen.widthPixels); | ||
| 33 | - console.log("Screen height (px): " + platformModule.screen.mainScreen.heightPixels); | ||
| 34 | - console.log("Screen width (DIPs): " + platformModule.screen.mainScreen.widthDIPs); | ||
| 35 | - console.log("Screen height (DIPs): " + platformModule.screen.mainScreen.heightDIPs); | ||
| 36 | - console.log("Screen scale: " + platformModule.screen.mainScreen.scale); | ||
| 37 | - // << platform-current | ||
| 28 | + TKUnit.assert(platformModule.screen.mainScreen.widthPixels, "Screen width (px) not initialized."); | ||
| 29 | + TKUnit.assert(platformModule.screen.mainScreen.heightPixels, "Screen height (px) not initialized."); | ||
| 30 | + TKUnit.assert(platformModule.screen.mainScreen.widthDIPs, "Screen width (DIPs) not initialized."); | ||
| 31 | + TKUnit.assert(platformModule.screen.mainScreen.heightDIPs, "Screen height (DIPs) not initialized."); | ||
| 32 | + TKUnit.assert(platformModule.screen.mainScreen.scale, "Screen scale not initialized."); | ||
| 38 | 33 | } | |
| 39 | 34 | ||
| 40 | - export function testIsIOSandIsAndroid() { | ||
| 41 | - if (isIOS) { | ||
| 35 | + export function test_IsAndroid_IsIOS() { | ||
| 36 | + if (platformModule.isIOS) { | ||
| 42 | 37 | TKUnit.assertTrue(!!NSObject, "isIOS is true-ish but common iOS APIs are not available."); | |
| 43 | - } else if (isAndroid) { | ||
| 44 | - TKUnit.assertTrue(!!android, "isAndroid is true but common 'android' package is not available."); | ||
| 38 | + } else if (platformModule.isAndroid) { | ||
| 39 | + TKUnit.assertTrue(!!android, "isAndroid is true-ish but common 'android' package is not available."); | ||
| 45 | 40 | } | |
| 46 | 41 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,10 +35,10 @@ export { Observable }; | |||
| 35 | 35 | import { | |
| 36 | 36 | AndroidApplication, | |
| 37 | 37 | CssChangedEventData, | |
| 38 | + DiscardedErrorEventData, | ||
| 38 | 39 | iOSApplication, | |
| 39 | 40 | LoadAppCSSEventData, | |
| 40 | - UnhandledErrorEventData, | ||
| 41 | - DiscardedErrorEventData, | ||
| 41 | + UnhandledErrorEventData | ||
| 42 | 42 | } from "./application"; | |
| 43 | 43 | ||
| 44 | 44 | export { UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,6 +42,7 @@ export class AndroidApplication extends Observable implements AndroidApplication | |||
| 42 | 42 | public static activityNewIntentEvent = ActivityNewIntent; | |
| 43 | 43 | public static activityRequestPermissionsEvent = ActivityRequestPermissions; | |
| 44 | 44 | ||
| 45 | + private _orientation: "portrait" | "landscape" | "unknown"; | ||
| 45 | 46 | public paused: boolean; | |
| 46 | 47 | public nativeApp: android.app.Application; | |
| 47 | 48 | public context: android.content.Context; | |
@@ -80,6 +81,22 @@ export class AndroidApplication extends Observable implements AndroidApplication | |||
| 80 | 81 | this._pendingReceiverRegistrations.length = 0; | |
| 81 | 82 | } | |
| 82 | 83 | ||
| 84 | + get orientation(): "portrait" | "landscape" | "unknown" { | ||
| 85 | + if (!this._orientation) { | ||
| 86 | + const resources = this.context.getResources(); | ||
| 87 | + const configuration = <android.content.res.Configuration>resources.getConfiguration(); | ||
| 88 | + const orientation = configuration.orientation; | ||
| 89 | + | ||
| 90 | + this._orientation = getOrientationValue(orientation); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + return this._orientation; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + set orientation(value: "portrait" | "landscape" | "unknown") { | ||
| 97 | + this._orientation = value; | ||
| 98 | + } | ||
| 99 | + | ||
| 83 | 100 | public registerBroadcastReceiver(intentFilter: string, onReceiveCallback: (context: android.content.Context, intent: android.content.Intent) => void) { | |
| 84 | 101 | ensureBroadCastReceiverClass(); | |
| 85 | 102 | const that = this; | |
@@ -232,6 +249,17 @@ global.__onLiveSync = function __onLiveSync(context?: ModuleContext) { | |||
| 232 | 249 | livesync(rootView, context); | |
| 233 | 250 | }; | |
| 234 | 251 | ||
| 252 | + function getOrientationValue(orientation: number): "portrait" | "landscape" | "unknown" { | ||
| 253 | + switch (orientation) { | ||
| 254 | + case android.content.res.Configuration.ORIENTATION_LANDSCAPE: | ||
| 255 | + return "landscape"; | ||
| 256 | + case android.content.res.Configuration.ORIENTATION_PORTRAIT: | ||
| 257 | + return "portrait"; | ||
| 258 | + default: | ||
| 259 | + return "unknown"; | ||
| 260 | + } | ||
| 261 | + } | ||
| 262 | + | ||
| 235 | 263 | function initLifecycleCallbacks() { | |
| 236 | 264 | const setThemeOnLaunch = profile("setThemeOnLaunch", (activity: androidx.appcompat.app.AppCompatActivity) => { | |
| 237 | 265 | // Set app theme after launch screen was used during startup | |
@@ -321,7 +349,6 @@ function initLifecycleCallbacks() { | |||
| 321 | 349 | return lifecycleCallbacks; | |
| 322 | 350 | } | |
| 323 | 351 | ||
| 324 | - let currentOrientation: number; | ||
| 325 | 352 | function initComponentCallbacks() { | |
| 326 | 353 | let componentCallbacks = new android.content.ComponentCallbacks2({ | |
| 327 | 354 | onLowMemory: profile("onLowMemory", function () { | |
@@ -335,32 +362,19 @@ function initComponentCallbacks() { | |||
| 335 | 362 | }), | |
| 336 | 363 | ||
| 337 | 364 | onConfigurationChanged: profile("onConfigurationChanged", function (newConfig: android.content.res.Configuration) { | |
| 338 | - const newOrientation = newConfig.orientation; | ||
| 339 | - if (newOrientation === currentOrientation) { | ||
| 340 | - return; | ||
| 365 | + const newConfigOrientation = newConfig.orientation; | ||
| 366 | + const newOrientation = getOrientationValue(newConfigOrientation); | ||
| 367 | + | ||
| 368 | + if (androidApp.orientation !== newOrientation) { | ||
| 369 | + androidApp.orientation = newOrientation; | ||
| 370 | + | ||
| 371 | + notify(<OrientationChangedEventData>{ | ||
| 372 | + eventName: orientationChangedEvent, | ||
| 373 | + android: androidApp.nativeApp, | ||
| 374 | + newValue: androidApp.orientation, | ||
| 375 | + object: androidApp | ||
| 376 | + }); | ||
| 341 | 377 | } | |
| 342 | - | ||
| 343 | - currentOrientation = newOrientation; | ||
| 344 | - let newValue; | ||
| 345 | - | ||
| 346 | - switch (newOrientation) { | ||
| 347 | - case android.content.res.Configuration.ORIENTATION_LANDSCAPE: | ||
| 348 | - newValue = "landscape"; | ||
| 349 | - break; | ||
| 350 | - case android.content.res.Configuration.ORIENTATION_PORTRAIT: | ||
| 351 | - newValue = "portrait"; | ||
| 352 | - break; | ||
| 353 | - default: | ||
| 354 | - newValue = "unknown"; | ||
| 355 | - break; | ||
| 356 | - } | ||
| 357 | - | ||
| 358 | - notify(<OrientationChangedEventData>{ | ||
| 359 | - eventName: orientationChangedEvent, | ||
| 360 | - android: androidApp.nativeApp, | ||
| 361 | - newValue: newValue, | ||
| 362 | - object: androidApp | ||
| 363 | - }); | ||
| 364 | 378 | }) | |
| 365 | 379 | }); | |
| 366 | 380 | ||
@@ -399,4 +413,4 @@ declare namespace com { | |||
| 399 | 413 | static getInstance(): NativeScriptApplication; | |
| 400 | 414 | } | |
| 401 | 415 | } | |
| 402 | - } | ||
| 416 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -413,6 +413,12 @@ export class AndroidApplication extends Observable { | |||
| 413 | 413 | */ | |
| 414 | 414 | startActivity: any /* androidx.appcompat.app.AppCompatActivity */; | |
| 415 | 415 | ||
| 416 | + /** | ||
| 417 | + * Gets the orientation of the application. | ||
| 418 | + * Available values: "portrait", "landscape", "unknown". | ||
| 419 | + */ | ||
| 420 | + orientation: "portrait" | "landscape" | "unknown"; | ||
| 421 | + | ||
| 416 | 422 | /** | |
| 417 | 423 | * The name of the application package. | |
| 418 | 424 | */ | |
@@ -582,14 +588,20 @@ export interface iOSApplication { | |||
| 582 | 588 | window: any /* UIWindow */; | |
| 583 | 589 | ||
| 584 | 590 | /** | |
| 585 | - * The [UIApplication](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html). | ||
| 591 | + * The [UIApplicationDelegate](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html) class. | ||
| 586 | 592 | */ | |
| 587 | - nativeApp: any /* UIApplication */; | ||
| 593 | + delegate: any /* typeof UIApplicationDelegate */; | ||
| 588 | 594 | ||
| 589 | 595 | /** | |
| 590 | - * The [UIApplicationDelegate](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html) class. | ||
| 596 | + * Gets or sets the orientation of the application. | ||
| 597 | + * Available values: "portrait", "landscape", "unknown". | ||
| 591 | 598 | */ | |
| 592 | - delegate: any /* typeof UIApplicationDelegate */; | ||
| 599 | + orientation: "portrait" | "landscape" | "unknown"; | ||
| 600 | + | ||
| 601 | + /** | ||
| 602 | + * The [UIApplication](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html). | ||
| 603 | + */ | ||
| 604 | + nativeApp: any /* UIApplication */; | ||
| 593 | 605 | ||
| 594 | 606 | /** | |
| 595 | 607 | * Adds an observer to the default notification center for the specified notification. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments