diff --git a/apps/automated/app/application/application-tests.android.ts b/apps/automated/app/application/application-tests.android.ts index 8e8b9142c..80f899652 100644 --- a/apps/automated/app/application/application-tests.android.ts +++ b/apps/automated/app/application/application-tests.android.ts @@ -1,17 +1,17 @@ /* tslint:disable:no-unused-variable */ -import { Application, isAndroid } from '@nativescript/core'; +import { Application } from '@nativescript/core'; import * as TKUnit from '../tk-unit'; export * from './application-tests-common'; // >> application-app-android -var androidApp = Application.android; +let androidApp = Application.android; // << application-app-android // >> application-app-android-context -var context = Application.android.context; +let context = Application.android.context; //// get the Files (Documents) folder (directory) -var dir = context.getFilesDir(); +let dir = context.getFilesDir(); // << application-app-android-context // >> application-app-android-current @@ -22,16 +22,16 @@ if (androidApp.foregroundActivity === androidApp.startActivity) { // >> application-app-android-broadcast //// Register the broadcast receiver -if (isAndroid) { +if (androidApp) { Application.android.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED, function onReceiveCallback(context: android.content.Context, intent: android.content.Intent) { - var level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1); - var scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1); - var percent = (level / scale) * 100.0; + const level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1); + const scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1); + const percent = (level / scale) * 100.0; ////console.log("Battery: " + percent + "%"); }); } //// When no longer needed, unregister the broadcast receiver -if (isAndroid) { +if (androidApp) { Application.android.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED); } // << application-app-android-broadcast diff --git a/apps/automated/app/font/FontAwesome.ttf b/apps/automated/app/fonts/FontAwesome.ttf similarity index 100% rename from apps/automated/app/font/FontAwesome.ttf rename to apps/automated/app/fonts/FontAwesome.ttf diff --git a/apps/automated/app/ui/frame/frame-tests.android.ts b/apps/automated/app/ui/frame/frame-tests.android.ts index a0b7da5fd..27a049a89 100644 --- a/apps/automated/app/ui/frame/frame-tests.android.ts +++ b/apps/automated/app/ui/frame/frame-tests.android.ts @@ -1,9 +1,10 @@ import { Frame } from '@nativescript/core/ui/frame'; import * as TKUnit from '../../tk-unit'; -import { unsetValue, PercentLength } from '@nativescript/core/ui/core/view'; - +import { unsetValue } from '@nativescript/core/ui/core/view'; +import { PercentLength } from '@nativescript/core/ui/styling/style-properties'; export * from './frame-tests-common'; + export function test_percent_width_and_height_set_to_page_support() { let topFrame = Frame.topmost(); let currentPage = topFrame.currentPage; diff --git a/apps/automated/app/ui/view/view-tests.android.ts b/apps/automated/app/ui/view/view-tests.android.ts index 43c76848f..a94c286a4 100644 --- a/apps/automated/app/ui/view/view-tests.android.ts +++ b/apps/automated/app/ui/view/view-tests.android.ts @@ -1,12 +1,14 @@ import * as TKUnit from '../../tk-unit'; import * as helper from '../../ui-helper'; -import { View, isIOS, unsetValue } from '@nativescript/core/ui/core/view'; +import { View, unsetValue } from '@nativescript/core/ui/core/view'; import { Button } from '@nativescript/core/ui/button'; import * as types from '@nativescript/core/utils/types'; import { StackLayout } from '@nativescript/core/ui/layouts/stack-layout'; import { Label } from '@nativescript/core/ui/label'; import { Trace } from '@nativescript/core'; import { Color } from '@nativescript/core/color'; +import { isIOS } from '@nativescript/core'; + // enable the trace, it is disabled by default Trace.enable(); diff --git a/packages/core/application/index.android.ts b/packages/core/application/index.android.ts index 15bd26ce6..773108d6d 100644 --- a/packages/core/application/index.android.ts +++ b/packages/core/application/index.android.ts @@ -49,7 +49,7 @@ export class AndroidApplication extends Observable implements AndroidApplication // we are using these property to store the callbacks to avoid early GC collection which would trigger MarkReachableObjects private callbacks: any = {}; - public init(nativeApp: android.app.Application) { + public init(nativeApp: android.app.Application): void { if (this.nativeApp === nativeApp) { return; } @@ -107,13 +107,12 @@ export class AndroidApplication extends Observable implements AndroidApplication this._systemAppearance = value; } - public registerBroadcastReceiver(intentFilter: string, onReceiveCallback: (context: android.content.Context, intent: android.content.Intent) => void) { + public registerBroadcastReceiver(intentFilter: string, onReceiveCallback: (context: android.content.Context, intent: android.content.Intent) => void): void { ensureBroadCastReceiverClass(); - const that = this; - const registerFunc = function (context: android.content.Context) { + const registerFunc = (context: android.content.Context) => { const receiver: android.content.BroadcastReceiver = new BroadcastReceiverClass(onReceiveCallback); context.registerReceiver(receiver, new android.content.IntentFilter(intentFilter)); - that._registeredReceivers[intentFilter] = receiver; + this._registeredReceivers[intentFilter] = receiver; }; if (this.context) { @@ -123,7 +122,7 @@ export class AndroidApplication extends Observable implements AndroidApplication } } - public unregisterBroadcastReceiver(intentFilter: string) { + public unregisterBroadcastReceiver(intentFilter: string): void { const receiver = this._registeredReceivers[intentFilter]; if (receiver) { this.context.unregisterReceiver(receiver); @@ -188,7 +187,7 @@ export function addCss(cssText: string, attributeScoped?: boolean): void { const CALLBACKS = '_callbacks'; -export function _resetRootView(entry?: NavigationEntry | string) { +export function _resetRootView(entry?: NavigationEntry | string): void { const activity = androidApp.foregroundActivity; if (!activity) { throw new Error('Cannot find android activity.'); @@ -322,7 +321,7 @@ function initLifecycleCallbacks() { object: androidApp, activity, }); - let viewTreeObserver = rootView.getViewTreeObserver(); + const viewTreeObserver = rootView.getViewTreeObserver(); viewTreeObserver.removeOnGlobalLayoutListener(global.onGlobalLayoutListener); }, }); @@ -419,7 +418,7 @@ function initLifecycleCallbacks() { } function initComponentCallbacks() { - let componentCallbacks = new android.content.ComponentCallbacks2({ + const componentCallbacks = new android.content.ComponentCallbacks2({ onLowMemory: profile('onLowMemory', function () { gc(); java.lang.System.gc(); @@ -477,51 +476,24 @@ function ensureBroadCastReceiverClass() { return; } - const BroadcastReceiver = (android.content.BroadcastReceiver).extend({ - init(onReceiveCallback: (context: android.content.Context, intent: android.content.Intent) => void) { - // super(); - this._onReceiveCallback = onReceiveCallback; + @NativeClass + class BroadcastReceiver extends android.content.BroadcastReceiver { + private _onReceiveCallback: (context: android.content.Context, intent: android.content.Intent) => void; - // return global.__native(this); - }, - _onReceiveCallback(context: android.content.Context, intent: android.content.Intent) { - if (this._onReceiveCallback) { - this._onReceiveCallback(context, intent); - } - }, - }); + constructor(onReceiveCallback: (context: android.content.Context, intent: android.content.Intent) => void) { + super(); + this._onReceiveCallback = onReceiveCallback; - // @NativeClass - // class BroadcastReceiver extends android.content.BroadcastReceiver { - // private _onReceiveCallback: (context: android.content.Context, intent: android.content.Intent) => void; + return global.__native(this); + } - // constructor(onReceiveCallback: (context: android.content.Context, intent: android.content.Intent) => void) { - // super(); - // this._onReceiveCallback = onReceiveCallback; + public onReceive(context: android.content.Context, intent: android.content.Intent) { + if (this._onReceiveCallback) { + this._onReceiveCallback(context, intent); + } + } + } - // return global.__native(this); - // } - - // public onReceive(context: android.content.Context, intent: android.content.Intent) { - // if (this._onReceiveCallback) { - // this._onReceiveCallback(context, intent); - // } - // } - // } - // var BroadcastReceiver = (function (_super) { - // __extends(BroadcastReceiver, _super); - // function BroadcastReceiver(onReceiveCallback) { - // var _this = _super.call(this) || this; - // _this._onReceiveCallback = onReceiveCallback; - // return global.__native(_this); - // } - // BroadcastReceiver.prototype.onReceive = function (context, intent) { - // if (this._onReceiveCallback) { - // this._onReceiveCallback(context, intent); - // } - // }; - // return BroadcastReceiver; - // })(android.content.BroadcastReceiver); BroadcastReceiverClass = BroadcastReceiver; } diff --git a/packages/core/file-system/index.ts b/packages/core/file-system/index.ts index 3cd7cccc9..c499abb43 100644 --- a/packages/core/file-system/index.ts +++ b/packages/core/file-system/index.ts @@ -577,7 +577,7 @@ export module knownFolders { export module ios { function _checkPlatform(knownFolderName: string) { if (!global.isIOS) { - console.log(`The "${knownFolderName}" known folder is available on iOS only!`); + throw new Error(`The "${knownFolderName}" known folder is available on iOS only!`); } } diff --git a/packages/core/ui/core/view/view-common.ts b/packages/core/ui/core/view/view-common.ts index 3ee2d3d2e..73809dff2 100644 --- a/packages/core/ui/core/view/view-common.ts +++ b/packages/core/ui/core/view/view-common.ts @@ -10,7 +10,7 @@ import { EventData } from '../../../data/observable'; import { Trace } from '../../../trace'; import { ViewHelper } from './view-helper'; -import { HorizontalAlignment, VerticalAlignment, Visibility, Length, PercentLength } from '../../styling/style-properties'; +import { HorizontalAlignment, VerticalAlignment, Visibility, Length, PercentLength, BackgroundRepeat } from '../../styling/style-properties'; import { observe as gestureObserve, GesturesObserver, GestureTypes, GestureEventData, fromString as gestureFromString } from '../../gestures'; @@ -19,7 +19,6 @@ import { Builder } from '../../builder'; import { sanitizeModuleName } from '../../builder/module-name-sanitizer'; import { StyleScope } from '../../styling/style-scope'; import { LinearGradient } from '../../styling/linear-gradient'; -import { BackgroundRepeat } from '../../styling/style-properties'; import { TextTransform } from '../../text-base'; import * as am from '../../animation'; diff --git a/tools/assets/App_Resources/Android/src/main/AndroidManifest.xml b/tools/assets/App_Resources/Android/src/main/AndroidManifest.xml index 1bd6826c3..a0c6d1a06 100644 --- a/tools/assets/App_Resources/Android/src/main/AndroidManifest.xml +++ b/tools/assets/App_Resources/Android/src/main/AndroidManifest.xml @@ -13,6 +13,8 @@ + +