diff --git a/Application/application.android.ts b/Application/application.android.ts index 8b5f8f8d6..5b149defb 100644 --- a/Application/application.android.ts +++ b/Application/application.android.ts @@ -13,10 +13,6 @@ var initEvents = function () { if (!androidApp.startActivity) { androidApp.startActivity = activity; - //if (UI.Application.current.onLaunch) { - // UI.Application.current.onLaunch(); - //} - if (androidApp.onActivityCreated) { androidApp.onActivityCreated(activity, bundle); } diff --git a/Application/application.d.ts b/Application/application.d.ts index a0c851200..0b2043884 100644 --- a/Application/application.d.ts +++ b/Application/application.d.ts @@ -90,7 +90,6 @@ export declare class AndroidApplication { * This method is called by the JavaScript Bridge when navigation to a new activity is triggered. * The return value of this method should be com.tns.NativeScriptActivity.extends implementation. */ - // TODO: Why is the android.content.Intent module rather than a class? public getActivity: (intent: android.content.Intent) => any; /** diff --git a/Application/application_common.ts b/Application/application_common.ts index 8072e6062..682d1f8b7 100644 --- a/Application/application_common.ts +++ b/Application/application_common.ts @@ -1,4 +1,4 @@ -import console_module = require("Console/console_common"); +import consoleModule = require("Console/console"); export enum TargetOS { iOS, @@ -9,7 +9,8 @@ export class Application { public os: TargetOS; constructor() { - console = new console_module.TKConsole(); + // TODO: This is put in the global context, is this the preferred approach + console = new consoleModule.Console(); } public onLaunch: () => any; diff --git a/BCL.csproj b/BCL.csproj index e12b2fcbc..ae40c527a 100644 --- a/BCL.csproj +++ b/BCL.csproj @@ -77,6 +77,16 @@ application.d.ts + + console.d.ts + + + console_helper.d.ts + + + + console_helper.d.ts + declarations.d.ts @@ -160,16 +170,7 @@ - - console.d.ts - - - console.d.ts - - - console.d.ts - diff --git a/Console/console.android.ts b/Console/console.android.ts deleted file mode 100644 index f59e5c4ba..000000000 --- a/Console/console.android.ts +++ /dev/null @@ -1,24 +0,0 @@ -export class ConsoleHelper { - static TAG: string = 'JS'; - - static log(message: string): void { - android.util.Log.v(ConsoleHelper.TAG, message); - } - - static info(message: string): void { - android.util.Log.i(ConsoleHelper.TAG, message); - } - - static error(message: string): void { - android.util.Log.e(ConsoleHelper.TAG, message); - } - - static warn(message: string): void { - android.util.Log.w(ConsoleHelper.TAG, message); - } - - static timeMillis(): number { - // NOTE: we might need to use currentTimeMillis if we have troubles with the long size - return java.lang.System.nanoTime() / 1000000; // 1 ms = 1000000 ns - } -} \ No newline at end of file diff --git a/Console/console.d.ts b/Console/console.d.ts index 33d9da73b..b4166f907 100644 --- a/Console/console.d.ts +++ b/Console/console.d.ts @@ -1,19 +1,50 @@ -export declare class TKConsole implements i.IConsole { +/** +* Encapsulates methods used to report some information to the console. +* Instance of this class is declared in the global JavaScript context and is accessible by directly calling console.[xxx] methods. +*/ +export declare class Console { + /** + * Begins counting a time span for a given name (key). + */ public time(reportName: string): void; - public timeEnd(reportName: string): void; - public assert(test: boolean, message: string, ...optionalParams: any[]): void; - public info(message: any, ...optionalParams: any[]): void; - public warn(message: any, ...optionalParams: any[]): void; - public error(message: any, ...optionalParams: any[]): void; - public log(message: any, ...optionalParams: any[]): void; - public trace(): void; - public dump(obj: any): void; -} -export declare class ConsoleHelper { - static log(message: string): void; - static info(message: string): void; - static error(message: string): void; - static warn(message: string): void; - static timeMillis(): number; + /** + * Ends a previously started time span through the time method. + */ + public timeEnd(reportName: string): void; + + /** + * Asserts a boolean condition and prints a message in case the assert fails. + */ + public assert(test: boolean, message: string, ...optionalParams: any[]): void; + + /** + * Reports some information. + */ + public info(message: any, ...optionalParams: any[]): void; + + /** + * Reports a warning. + */ + public warn(message: any, ...optionalParams: any[]): void; + + /** + * Reports an error. + */ + public error(message: any, ...optionalParams: any[]): void; + + /** + * Verbously logs a message. + */ + public log(message: any, ...optionalParams: any[]): void; + + /** + * Prints the current stack trace in the console. + */ + public trace(): void; + + /** + * Prints the state of the specified object to the console. + */ + public dump(obj: any): void; } \ No newline at end of file diff --git a/Console/console.ios.ts b/Console/console.ios.ts deleted file mode 100644 index a90d11605..000000000 --- a/Console/console.ios.ts +++ /dev/null @@ -1,22 +0,0 @@ -export class ConsoleHelper { - // FIXME: we should use Foundation.NSLog() but it currently does not work - static log(message: string): void { - log('log: ' + message); - } - - static info(message: string): void { - log('info: ' + message); - } - - static error(message: string): void { - log('error: ' + message); - } - - static warn(message: string): void { - log('warning: ' + message); - } - - static timeMillis(): number { - return QuartzCore.CACurrentMediaTime() * 1000; - } -} \ No newline at end of file diff --git a/Console/console_common.ts b/Console/console.ts similarity index 94% rename from Console/console_common.ts rename to Console/console.ts index 7d1402d01..2d53a267c 100644 --- a/Console/console_common.ts +++ b/Console/console.ts @@ -1,12 +1,9 @@ +import helperModule = require("Console/console_helper"); -import native_module = require("Console/console"); - -export class TKConsole { - private _nativeClass: any; +export class Console { private _timers: any; constructor() { - this._nativeClass = native_module.ConsoleHelper; this._timers = {}; } @@ -216,7 +213,7 @@ export class TKConsole { public time(reportName: string): void { var name = reportName ? '__' + reportName : '__internal_console_time__'; if (('undefined' === typeof (this._timers[name])) || (this._timers.hasOwnProperty(name))) { - this._timers[name] = this._nativeClass.timeMillis(); + this._timers[name] = helperModule.timeMillis(); } else { this.warn('invalid name for timer console.time(' + reportName + ')'); @@ -228,7 +225,7 @@ export class TKConsole { if (this._timers.hasOwnProperty(name)) { var val = this._timers[name]; if (val) { - var time = this._nativeClass.timeMillis(); + var time = helperModule.timeMillis(); this.info('console.time(' + reportName + '): %.6f ms', (time - val)); this._timers[name] = undefined; } @@ -241,7 +238,7 @@ export class TKConsole { public assert(test: boolean, message: string, ...optionalParams: any[]): void { if (!test) { Array.prototype.shift.apply(arguments); - this._nativeClass.error(this.formatParams.apply(this, arguments)); + helperModule.error(this.formatParams.apply(this, arguments)); // duplicating trace code here because android version shows only 2 frames and if we call trace() // this would be assert() and trace() which leaves all important stack frames out of our view @@ -269,19 +266,19 @@ export class TKConsole { } public info(message: any, ...optionalParams: any[]): void { - this._nativeClass.info(this.formatParams.apply(this, arguments)); + helperModule.info(this.formatParams.apply(this, arguments)); } public warn(message: any, ...optionalParams: any[]): void { - this._nativeClass.warn(this.formatParams.apply(this, arguments)); + helperModule.warn(this.formatParams.apply(this, arguments)); } public error(message: any, ...optionalParams: any[]): void { - this._nativeClass.error(this.formatParams.apply(this, arguments)); + helperModule.error(this.formatParams.apply(this, arguments)); } public log(message: any, ...optionalParams: any[]): void { - this._nativeClass.log(this.formatParams.apply(this, arguments)); + helperModule.log(this.formatParams.apply(this, arguments)); } public trace(): void { diff --git a/Console/console_helper.android.ts b/Console/console_helper.android.ts new file mode 100644 index 000000000..a44bfa61e --- /dev/null +++ b/Console/console_helper.android.ts @@ -0,0 +1,22 @@ +var TAG = 'JS'; + +export var log = function (message: string) { + android.util.Log.v(TAG, message); +} + +export var info = function (message: string) { + android.util.Log.i(TAG, message); +} + +export var error = function (message: string) { + android.util.Log.e(TAG, message); +} + +export var warn = function (message: string) { + android.util.Log.w(TAG, message); +} + +export var timeMillis = function (): number { + // NOTE: we might need to use currentTimeMillis if we have troubles with the long size + return java.lang.System.nanoTime() / 1000000; // 1 ms = 1000000 ns +} \ No newline at end of file diff --git a/Console/console_helper.d.ts b/Console/console_helper.d.ts new file mode 100644 index 000000000..b72d1ae3c --- /dev/null +++ b/Console/console_helper.d.ts @@ -0,0 +1,5 @@ +export declare var log: (message: string) => void; +export declare var info: (message: string) => void; +export declare var error: (message: string) => void; +export declare var warn: (message: string) => void; +export declare var timeMillis: () => number; \ No newline at end of file diff --git a/Console/console_helper.ios.ts b/Console/console_helper.ios.ts new file mode 100644 index 000000000..016a24ebc --- /dev/null +++ b/Console/console_helper.ios.ts @@ -0,0 +1,22 @@ +// TODO: we should use Foundation.NSLog() but it currently does not work +// TODO: Is there a better way to implement the info/warn/error + +export var log = function (message: string) { + log('log: ' + message); +} + +export var info = function (message: string) { + log('info: ' + message); +} + +export var error = function (message: string) { + log('error: ' + message); +} + +export var warn = function (message: string) { + log('warning: ' + message); +} + +export var timeMillis = function (): number { + return QuartzCore.CACurrentMediaTime() * 1000; +} \ No newline at end of file diff --git a/FileSystem/file_system.ts b/FileSystem/file_system.ts index a32be0f71..41720b90e 100644 --- a/FileSystem/file_system.ts +++ b/FileSystem/file_system.ts @@ -154,7 +154,7 @@ export class FileSystemEntity { */ get lastModified(): Date { var value = this[lastModifiedProperty]; - if (this[lastModifiedProperty] === undefined) { + if (!this[lastModifiedProperty]) { value = this[lastModifiedProperty] = getFileAccess().getLastModified(this.path); } diff --git a/FileSystem/file_system_access.android.ts b/FileSystem/file_system_access.android.ts index d20672f4f..1129e12f4 100644 --- a/FileSystem/file_system_access.android.ts +++ b/FileSystem/file_system_access.android.ts @@ -384,7 +384,7 @@ export class FileSystemAccess { } retVal = callback(info); - if (retVal != undefined && !retVal) { + if (retVal === false) { break; } } diff --git a/FileSystem/file_system_access.ios.ts b/FileSystem/file_system_access.ios.ts index feff76b94..5c7bda2a0 100644 --- a/FileSystem/file_system_access.ios.ts +++ b/FileSystem/file_system_access.ios.ts @@ -334,7 +334,7 @@ export class FileSystemAccess { } retVal = callback(info); - if (retVal != undefined && !retVal) { + if (retVal === false) { // the callback returned false meaning we should stop the iteration break; }