Added Application module comments. Modified Console module + comments. Changed the package name of the UnitTestApp for Android.

This commit is contained in:
atanasovg
2014-05-08 14:47:12 +03:00
parent 1531c206e6
commit 298bf0977a
14 changed files with 121 additions and 93 deletions

View File

@ -13,10 +13,6 @@ var initEvents = function () {
if (!androidApp.startActivity) { if (!androidApp.startActivity) {
androidApp.startActivity = activity; androidApp.startActivity = activity;
//if (UI.Application.current.onLaunch) {
// UI.Application.current.onLaunch();
//}
if (androidApp.onActivityCreated) { if (androidApp.onActivityCreated) {
androidApp.onActivityCreated(activity, bundle); androidApp.onActivityCreated(activity, bundle);
} }

View File

@ -90,7 +90,6 @@ export declare class AndroidApplication {
* This method is called by the JavaScript Bridge when navigation to a new activity is triggered. * 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. * 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; public getActivity: (intent: android.content.Intent) => any;
/** /**

View File

@ -1,4 +1,4 @@
import console_module = require("Console/console_common"); import consoleModule = require("Console/console");
export enum TargetOS { export enum TargetOS {
iOS, iOS,
@ -9,7 +9,8 @@ export class Application {
public os: TargetOS; public os: TargetOS;
constructor() { 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; public onLaunch: () => any;

View File

@ -77,6 +77,16 @@
<TypeScriptCompile Include="Application\application.ios.ts"> <TypeScriptCompile Include="Application\application.ios.ts">
<DependentUpon>application.d.ts</DependentUpon> <DependentUpon>application.d.ts</DependentUpon>
</TypeScriptCompile> </TypeScriptCompile>
<TypeScriptCompile Include="Console\console.ts">
<DependentUpon>console.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="Console\console_helper.android.ts">
<DependentUpon>console_helper.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="Console\console_helper.d.ts" />
<TypeScriptCompile Include="Console\console_helper.ios.ts">
<DependentUpon>console_helper.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="declarations.d.ts" /> <TypeScriptCompile Include="declarations.d.ts" />
<TypeScriptCompile Include="declarations.android.d.ts"> <TypeScriptCompile Include="declarations.android.d.ts">
<DependentUpon>declarations.d.ts</DependentUpon> <DependentUpon>declarations.d.ts</DependentUpon>
@ -160,16 +170,7 @@
<TypeScriptCompile Include="http\http.ts" /> <TypeScriptCompile Include="http\http.ts" />
<TypeScriptCompile Include="ios7.d.ts" /> <TypeScriptCompile Include="ios7.d.ts" />
<Content Include="_references.ts" /> <Content Include="_references.ts" />
<TypeScriptCompile Include="Console\console.android.ts">
<DependentUpon>console.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="Console\console.d.ts" /> <TypeScriptCompile Include="Console\console.d.ts" />
<TypeScriptCompile Include="Console\console.ios.ts">
<DependentUpon>console.d.ts</DependentUpon>
</TypeScriptCompile>
<TypeScriptCompile Include="Console\console_common.ts">
<DependentUpon>console.d.ts</DependentUpon>
</TypeScriptCompile>
<Content Include="Image\Readme.md" /> <Content Include="Image\Readme.md" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -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
}
}

49
Console/console.d.ts vendored
View File

@ -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 time(reportName: string): void;
/**
* Ends a previously started time span through the time method.
*/
public timeEnd(reportName: string): void; 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; public assert(test: boolean, message: string, ...optionalParams: any[]): void;
/**
* Reports some information.
*/
public info(message: any, ...optionalParams: any[]): void; public info(message: any, ...optionalParams: any[]): void;
/**
* Reports a warning.
*/
public warn(message: any, ...optionalParams: any[]): void; public warn(message: any, ...optionalParams: any[]): void;
/**
* Reports an error.
*/
public error(message: any, ...optionalParams: any[]): void; public error(message: any, ...optionalParams: any[]): void;
/**
* Verbously logs a message.
*/
public log(message: any, ...optionalParams: any[]): void; public log(message: any, ...optionalParams: any[]): void;
/**
* Prints the current stack trace in the console.
*/
public trace(): void; public trace(): void;
/**
* Prints the state of the specified object to the console.
*/
public dump(obj: any): 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;
}

View File

@ -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;
}
}

View File

@ -1,12 +1,9 @@
import helperModule = require("Console/console_helper");
import native_module = require("Console/console"); export class Console {
export class TKConsole {
private _nativeClass: any;
private _timers: any; private _timers: any;
constructor() { constructor() {
this._nativeClass = native_module.ConsoleHelper;
this._timers = {}; this._timers = {};
} }
@ -216,7 +213,7 @@ export class TKConsole {
public time(reportName: string): void { public time(reportName: string): void {
var name = reportName ? '__' + reportName : '__internal_console_time__'; var name = reportName ? '__' + reportName : '__internal_console_time__';
if (('undefined' === typeof (this._timers[name])) || (this._timers.hasOwnProperty(name))) { if (('undefined' === typeof (this._timers[name])) || (this._timers.hasOwnProperty(name))) {
this._timers[name] = this._nativeClass.timeMillis(); this._timers[name] = helperModule.timeMillis();
} }
else { else {
this.warn('invalid name for timer console.time(' + reportName + ')'); this.warn('invalid name for timer console.time(' + reportName + ')');
@ -228,7 +225,7 @@ export class TKConsole {
if (this._timers.hasOwnProperty(name)) { if (this._timers.hasOwnProperty(name)) {
var val = this._timers[name]; var val = this._timers[name];
if (val) { if (val) {
var time = this._nativeClass.timeMillis(); var time = helperModule.timeMillis();
this.info('console.time(' + reportName + '): %.6f ms', (time - val)); this.info('console.time(' + reportName + '): %.6f ms', (time - val));
this._timers[name] = undefined; this._timers[name] = undefined;
} }
@ -241,7 +238,7 @@ export class TKConsole {
public assert(test: boolean, message: string, ...optionalParams: any[]): void { public assert(test: boolean, message: string, ...optionalParams: any[]): void {
if (!test) { if (!test) {
Array.prototype.shift.apply(arguments); 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() // 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 // 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 { 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 { 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 { 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 { 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 { public trace(): void {

View File

@ -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
}

5
Console/console_helper.d.ts vendored Normal file
View File

@ -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;

View File

@ -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;
}

View File

@ -154,7 +154,7 @@ export class FileSystemEntity {
*/ */
get lastModified(): Date { get lastModified(): Date {
var value = this[lastModifiedProperty]; var value = this[lastModifiedProperty];
if (this[lastModifiedProperty] === undefined) { if (!this[lastModifiedProperty]) {
value = this[lastModifiedProperty] = getFileAccess().getLastModified(this.path); value = this[lastModifiedProperty] = getFileAccess().getLastModified(this.path);
} }

View File

@ -384,7 +384,7 @@ export class FileSystemAccess {
} }
retVal = callback(info); retVal = callback(info);
if (retVal != undefined && !retVal) { if (retVal === false) {
break; break;
} }
} }

View File

@ -334,7 +334,7 @@ export class FileSystemAccess {
} }
retVal = callback(info); retVal = callback(info);
if (retVal != undefined && !retVal) { if (retVal === false) {
// the callback returned false meaning we should stop the iteration // the callback returned false meaning we should stop the iteration
break; break;
} }