From 2ba00b662a3dcddb5d269000b95577635e31501c Mon Sep 17 00:00:00 2001 From: Nikolay Iliev Date: Fri, 15 Feb 2019 14:11:50 +0200 Subject: [PATCH 1/3] docs: fix boradcast receiver exmaple + minor article improvments --- .../app-checking-target/article.md | 4 +--- .../app-using-android-specifics.component.ts | 22 ++++++++++++++++++- .../app-using-android-specifics/article.md | 20 ++++++++++++++--- .../app-using-ios-specifics.component.ts | 11 ++++++++++ .../app-using-ios-specifics/article.md | 9 ++++++-- 5 files changed, 57 insertions(+), 9 deletions(-) diff --git a/app/ng-framework-modules-category/application/app-checking-target/article.md b/app/ng-framework-modules-category/application/app-checking-target/article.md index f83fd7c0..fcf385d5 100644 --- a/app/ng-framework-modules-category/application/app-checking-target/article.md +++ b/app/ng-framework-modules-category/application/app-checking-target/article.md @@ -1,4 +1,2 @@ -Use the following code in case you need to check somewhere in your code the platform you are running against: - -Basic usage of the `application` module in a component: +Basic usage of the `application` module in a component to apply different code on Android and iOS \ No newline at end of file diff --git a/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts b/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts index 04f57256..d867c555 100644 --- a/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts +++ b/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts @@ -20,10 +20,23 @@ export class AppUsingAndroidExampleComponent { console.log("We are running on Android device!"); this.isItemVisible = true; + // >> app-class-properties + let isPaused = androidApp.paused; // e.g. false + let packageName = androidApp.packageName; // The package ID e.g. org.nativescript.nativescriptsdkexamplesng + let nativeApp = androidApp.nativeApp; // The native APplication reference + let foregroundActivity = androidApp.foregroundActivity; // The current Activity reference + let currentContext = androidApp.currentContext; // The current Android context + let context = androidApp.context; console.log(context); // The current Android context + // << app-class-properties + // >> app-android-dirs-code this.fileList = []; this.appContext = androidApp.context; + + // https://developer.android.com/reference/android/content/Context.html#getFilesDir() this.filesDir = this.appContext.getFilesDir(); + + // https://developer.android.com/reference/android/content/Context.html#getCacheDir() this.cacheDir = this.appContext.getCacheDir(); let files = this.appContext.fileList(); @@ -37,8 +50,9 @@ export class AppUsingAndroidExampleComponent { this.batteryLife = "0"; let that = this; + // Broadcast Receiver https://developer.android.com/reference/android/content/BroadcastReceiver androidApp.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED, - function onReceiveCallback(context: android.content.Context, intent: android.content.Intent) { + function onReceiveCallback(androidContext: android.content.Context, intent: android.content.Intent) { let level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1); let scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1); let percent = (level / scale) * 100.0; @@ -51,6 +65,12 @@ export class AppUsingAndroidExampleComponent { this.isItemVisible = false; } } + + unregister() { + // >> app-android-broadcast-unregister-code + androidApp.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED); + // << app-android-broadcast-unregister-code + } } class File { diff --git a/app/ng-framework-modules-category/application/app-using-android-specifics/article.md b/app/ng-framework-modules-category/application/app-using-android-specifics/article.md index 90fb7c81..053279de 100644 --- a/app/ng-framework-modules-category/application/app-using-android-specifics/article.md +++ b/app/ng-framework-modules-category/application/app-using-android-specifics/article.md @@ -1,5 +1,19 @@ -Using the Android Application context to get the absolute path to Files directory: +### Application Module Android Specific Properties + +The application module provides a number of Android specific properties to access the Android app, context and activities. + + +### Using the Android Application Context + +In the extended example below, the Android context is used to get the absolute path to Files directory. +We are accessing methods from the Android SDK (like `getCacheDir` and `getFilesDir`) -Registering a Broadcast Receiver (Android) - \ No newline at end of file +### Registering a Broadcast Receiver (Android) + +NativeScript can send/receive messages and system information though broadcast receivers. +More on broadcast receivers in Android [here](https://developer.android.com/guide/components/broadcasts). + + +### Unregistering a Broadcast Receiver (Android) + \ No newline at end of file diff --git a/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts b/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts index c04ed624..23ce509f 100644 --- a/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts +++ b/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts @@ -15,6 +15,17 @@ export class AppUsingIosExampleComponent { constructor() { if (iosApp) { + // >> app-class-properties-ios + // https://developer.apple.com/documentation/uikit/uiapplicationdelegate?language=objc + let delegate = iosApp.delegate; // the iOS application delegate + + let nativeApp = iosApp.nativeApp; // The native iOS app + + // https://developer.apple.com/documentation/uikit/uiwindow/1621581-rootviewcontroller?language=objc + let rootController = iosApp.rootController; // the iOS rootViewController + + let window = iosApp.window; // UIWindow + // << app-class-properties-ios this.isItemVisible = true; this.batteryLife = 0; diff --git a/app/ng-framework-modules-category/application/app-using-ios-specifics/article.md b/app/ng-framework-modules-category/application/app-using-ios-specifics/article.md index 63b5dcdc..9f2cad48 100644 --- a/app/ng-framework-modules-category/application/app-using-ios-specifics/article.md +++ b/app/ng-framework-modules-category/application/app-using-ios-specifics/article.md @@ -1,5 +1,10 @@ -Adding a Notification Observer (iOS) +## Application MOdule iOS Specific Properties + +The application module provides a number of iOS specific properties to access the iOS app, delegate and root view controller, etc.. + + +### Adding a Notification Observer (iOS) -Removing a notification observer +### Removing a notification observer From bb91177169519aa7835556ceee9e6aed0fd6a572 Mon Sep 17 00:00:00 2001 From: Nikolay Iliev Date: Fri, 15 Feb 2019 14:22:44 +0200 Subject: [PATCH 2/3] docs: article improvment --- .../app-using-android-specifics.component.ts | 1 + .../app-using-ios-specifics.component.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts b/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts index d867c555..9c923ccb 100644 --- a/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts +++ b/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts @@ -21,6 +21,7 @@ export class AppUsingAndroidExampleComponent { this.isItemVisible = true; // >> app-class-properties + // import { android as androidApp } from "tns-core-modules/application"; let isPaused = androidApp.paused; // e.g. false let packageName = androidApp.packageName; // The package ID e.g. org.nativescript.nativescriptsdkexamplesng let nativeApp = androidApp.nativeApp; // The native APplication reference diff --git a/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts b/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts index 23ce509f..e966149b 100644 --- a/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts +++ b/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts @@ -16,6 +16,8 @@ export class AppUsingIosExampleComponent { if (iosApp) { // >> app-class-properties-ios + // import { ios as iosApp } from "tns-core-modules/application"; + // https://developer.apple.com/documentation/uikit/uiapplicationdelegate?language=objc let delegate = iosApp.delegate; // the iOS application delegate From c0cf81b7e4cb17679f8da31c01be8da23e1e5b2a Mon Sep 17 00:00:00 2001 From: Nikolay Iliev Date: Fri, 15 Feb 2019 14:25:04 +0200 Subject: [PATCH 3/3] docs: title improvments --- .../application/app-using-ios-specifics/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ng-framework-modules-category/application/app-using-ios-specifics/article.md b/app/ng-framework-modules-category/application/app-using-ios-specifics/article.md index 9f2cad48..864d7948 100644 --- a/app/ng-framework-modules-category/application/app-using-ios-specifics/article.md +++ b/app/ng-framework-modules-category/application/app-using-ios-specifics/article.md @@ -1,4 +1,4 @@ -## Application MOdule iOS Specific Properties +### Application Module iOS Specific Properties The application module provides a number of iOS specific properties to access the iOS app, delegate and root view controller, etc..