| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3e7c24a commit 0b9bd9d
14 files changed
| 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 | |
|---|---|---|---|
@@ -13,24 +13,23 @@ export function test_platform() { | |||
| 13 | 13 | } | |
| 14 | 14 | ||
| 15 | 15 | export function test_device_screen() { | |
| 16 | - console.log("Device model: " + platformModule.device.model); | ||
| 17 | - console.log("Device manufacturer: " + platformModule.device.manufacturer); | ||
| 18 | - console.log("Device orientation: " + platformModule.device.orientation); | ||
| 19 | - console.log("Device type: " + platformModule.device.deviceType); | ||
| 20 | - console.log("Device UUID: " + platformModule.device.uuid); | ||
| 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."); | ||
| 21 | 20 | ||
| 22 | - console.log("Preferred language: " + platformModule.device.language); | ||
| 23 | - console.log("Preferred region: " + platformModule.device.region); | ||
| 21 | + TKUnit.assert(platformModule.device.language, "Preferred language not initialized."); | ||
| 22 | + TKUnit.assert(platformModule.device.region, "Preferred region not initialized."); | ||
| 24 | 23 | ||
| 25 | - console.log("OS: " + platformModule.device.os); | ||
| 26 | - console.log("OS version: " + platformModule.device.osVersion); | ||
| 27 | - console.log("SDK version: " + platformModule.device.sdkVersion); | ||
| 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."); | ||
| 28 | 27 | ||
| 29 | - console.log("Screen width (px): " + platformModule.screen.mainScreen.widthPixels); | ||
| 30 | - console.log("Screen height (px): " + platformModule.screen.mainScreen.heightPixels); | ||
| 31 | - console.log("Screen width (DIPs): " + platformModule.screen.mainScreen.widthDIPs); | ||
| 32 | - console.log("Screen height (DIPs): " + platformModule.screen.mainScreen.heightDIPs); | ||
| 33 | - console.log("Screen scale: " + platformModule.screen.mainScreen.scale); | ||
| 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."); | ||
| 34 | 33 | } | |
| 35 | 34 | ||
| 36 | 35 | export function test_IsAndroid_IsIOS() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,8 +125,8 @@ export function addCss(cssText: string): void { | |||
| 125 | 125 | } | |
| 126 | 126 | ||
| 127 | 127 | on(orientationChangedEvent, (args: OrientationChangedEventData) => { | |
| 128 | - if (device.orientation !== args.newValue) { | ||
| 129 | - device.orientation = args.newValue; | ||
| 128 | + if (app.orientation !== args.newValue) { | ||
| 129 | + app.orientation = args.newValue; | ||
| 130 | 130 | } | |
| 131 | 131 | }); | |
| 132 | 132 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,6 +41,7 @@ export class AndroidApplication extends Observable implements AndroidApplication | |||
| 41 | 41 | public static activityNewIntentEvent = ActivityNewIntent; | |
| 42 | 42 | public static activityRequestPermissionsEvent = ActivityRequestPermissions; | |
| 43 | 43 | ||
| 44 | + private _orientation: "portrait" | "landscape" | "unknown"; | ||
| 44 | 45 | public paused: boolean; | |
| 45 | 46 | public nativeApp: android.app.Application; | |
| 46 | 47 | public context: android.content.Context; | |
@@ -79,6 +80,22 @@ export class AndroidApplication extends Observable implements AndroidApplication | |||
| 79 | 80 | this._pendingReceiverRegistrations.length = 0; | |
| 80 | 81 | } | |
| 81 | 82 | ||
| 83 | + get orientation(): "portrait" | "landscape" | "unknown" { | ||
| 84 | + if (!this._orientation) { | ||
| 85 | + const resources = this.context.getResources(); | ||
| 86 | + const configuration = <android.content.res.Configuration>resources.getConfiguration(); | ||
| 87 | + const orientation = configuration.orientation; | ||
| 88 | + | ||
| 89 | + this._orientation = getOrientationValue(orientation); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + return this._orientation; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + set orientation(value: "portrait" | "landscape" | "unknown") { | ||
| 96 | + this._orientation = value; | ||
| 97 | + } | ||
| 98 | + | ||
| 82 | 99 | public registerBroadcastReceiver(intentFilter: string, onReceiveCallback: (context: android.content.Context, intent: android.content.Intent) => void) { | |
| 83 | 100 | ensureBroadCastReceiverClass(); | |
| 84 | 101 | const that = this; | |
@@ -223,6 +240,17 @@ global.__onLiveSync = function __onLiveSync(context?: ModuleContext) { | |||
| 223 | 240 | livesync(rootView, context); | |
| 224 | 241 | }; | |
| 225 | 242 | ||
| 243 | + function getOrientationValue(orientation: number): "portrait" | "landscape" | "unknown" { | ||
| 244 | + switch (orientation) { | ||
| 245 | + case android.content.res.Configuration.ORIENTATION_LANDSCAPE: | ||
| 246 | + return "landscape"; | ||
| 247 | + case android.content.res.Configuration.ORIENTATION_PORTRAIT: | ||
| 248 | + return "portrait"; | ||
| 249 | + default: | ||
| 250 | + return "unknown"; | ||
| 251 | + } | ||
| 252 | + } | ||
| 253 | + | ||
| 226 | 254 | function initLifecycleCallbacks() { | |
| 227 | 255 | const setThemeOnLaunch = profile("setThemeOnLaunch", (activity: androidx.appcompat.app.AppCompatActivity) => { | |
| 228 | 256 | // Set app theme after launch screen was used during startup | |
@@ -312,7 +340,6 @@ function initLifecycleCallbacks() { | |||
| 312 | 340 | return lifecycleCallbacks; | |
| 313 | 341 | } | |
| 314 | 342 | ||
| 315 | - let currentOrientation: number; | ||
| 316 | 343 | function initComponentCallbacks() { | |
| 317 | 344 | let componentCallbacks = new android.content.ComponentCallbacks2({ | |
| 318 | 345 | onLowMemory: profile("onLowMemory", function () { | |
@@ -326,32 +353,19 @@ function initComponentCallbacks() { | |||
| 326 | 353 | }), | |
| 327 | 354 | ||
| 328 | 355 | onConfigurationChanged: profile("onConfigurationChanged", function (newConfig: android.content.res.Configuration) { | |
| 329 | - const newOrientation = newConfig.orientation; | ||
| 330 | - if (newOrientation === currentOrientation) { | ||
| 331 | - return; | ||
| 356 | + const newConfigOrientation = newConfig.orientation; | ||
| 357 | + const newOrientation = getOrientationValue(newConfigOrientation); | ||
| 358 | + | ||
| 359 | + if (androidApp.orientation !== newOrientation) { | ||
| 360 | + androidApp.orientation = newOrientation; | ||
| 361 | + | ||
| 362 | + notify(<OrientationChangedEventData>{ | ||
| 363 | + eventName: orientationChangedEvent, | ||
| 364 | + android: androidApp.nativeApp, | ||
| 365 | + newValue: androidApp.orientation, | ||
| 366 | + object: androidApp | ||
| 367 | + }); | ||
| 332 | 368 | } | |
| 333 | - | ||
| 334 | - currentOrientation = newOrientation; | ||
| 335 | - let newValue; | ||
| 336 | - | ||
| 337 | - switch (newOrientation) { | ||
| 338 | - case android.content.res.Configuration.ORIENTATION_LANDSCAPE: | ||
| 339 | - newValue = "landscape"; | ||
| 340 | - break; | ||
| 341 | - case android.content.res.Configuration.ORIENTATION_PORTRAIT: | ||
| 342 | - newValue = "portrait"; | ||
| 343 | - break; | ||
| 344 | - default: | ||
| 345 | - newValue = "unknown"; | ||
| 346 | - break; | ||
| 347 | - } | ||
| 348 | - | ||
| 349 | - notify(<OrientationChangedEventData>{ | ||
| 350 | - eventName: orientationChangedEvent, | ||
| 351 | - android: androidApp.nativeApp, | ||
| 352 | - newValue: newValue, | ||
| 353 | - object: androidApp | ||
| 354 | - }); | ||
| 355 | 369 | }) | |
| 356 | 370 | }); | |
| 357 | 371 | ||
@@ -390,4 +404,4 @@ declare namespace com { | |||
| 390 | 404 | static getInstance(): NativeScriptApplication; | |
| 391 | 405 | } | |
| 392 | 406 | } | |
| 393 | - } | ||
| 407 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -409,6 +409,12 @@ export class AndroidApplication extends Observable { | |||
| 409 | 409 | */ | |
| 410 | 410 | startActivity: any /* androidx.appcompat.app.AppCompatActivity */; | |
| 411 | 411 | ||
| 412 | + /** | ||
| 413 | + * Gets or sets the orientation of the application. | ||
| 414 | + * Available values: "portrait", "landscape", "unknown". | ||
| 415 | + */ | ||
| 416 | + orientation: "portrait" | "landscape" | "unknown"; | ||
| 417 | + | ||
| 412 | 418 | /** | |
| 413 | 419 | * The name of the application package. | |
| 414 | 420 | */ | |
@@ -578,14 +584,20 @@ export interface iOSApplication { | |||
| 578 | 584 | window: any /* UIWindow */; | |
| 579 | 585 | ||
| 580 | 586 | /** | |
| 581 | - * The [UIApplication](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html). | ||
| 587 | + * The [UIApplicationDelegate](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html) class. | ||
| 582 | 588 | */ | |
| 583 | - nativeApp: any /* UIApplication */; | ||
| 589 | + delegate: any /* typeof UIApplicationDelegate */; | ||
| 584 | 590 | ||
| 585 | 591 | /** | |
| 586 | - * The [UIApplicationDelegate](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html) class. | ||
| 592 | + * Gets or sets the orientation of the application. | ||
| 593 | + * Available values: "portrait", "landscape", "unknown". | ||
| 587 | 594 | */ | |
| 588 | - delegate: any /* typeof UIApplicationDelegate */; | ||
| 595 | + orientation: "portrait" | "landscape" | "unknown"; | ||
| 596 | + | ||
| 597 | + /** | ||
| 598 | + * The [UIApplication](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html). | ||
| 599 | + */ | ||
| 600 | + nativeApp: any /* UIApplication */; | ||
| 589 | 601 | ||
| 590 | 602 | /** | |
| 591 | 603 | * Adds an observer to the default notification center for the specified notification. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments