Merge pull request #400 from NativeScript/android-events

Fixed wrong event names in application.d.ts + added constants for the…
This commit is contained in:
Rossen Hristov
2015-07-07 13:32:58 +03:00
5 changed files with 93 additions and 43 deletions

View File

@ -9,16 +9,11 @@ var events = new observable.Observable();
require("utils/module-merge").merge(events, exports);
export var launchEvent = "launch";
export var uncaughtErrorEvent = "uncaughtError";
export var suspendEvent = "suspend";
export var resumeEvent = "resume";
export var exitEvent = "exit";
export var lowMemoryEvent = "lowMemory";
export var uncaughtErrorEvent = "uncaughtError";
export var cssFile: string = "app.css"

View File

@ -136,7 +136,17 @@ app.init({
}
});
class AndroidApplication extends observable.Observable implements dts.AndroidApplication {
export class AndroidApplication extends observable.Observable implements dts.AndroidApplication {
public static activityCreatedEvent = "activityCreated";
public static activityDestroyedEvent = "activityDestroyed";
public static activityStartedEvent = "activityStarted";
public static activityPausedEvent = "activityPaused";
public static activityResumedEvent = "activityResumed";
public static activityStoppedEvent = "activityStopped";
public static saveActivityStateEvent = "saveActivityState";
public static activityResultEvent = "activityResult";
public static activityBackPressedEvent = "activityBackPressed";
public nativeApp: android.app.Application;
public context: android.content.Context;
public currentContext: android.content.Context;

View File

@ -161,32 +161,32 @@ declare module "application" {
/**
* This event is raised on application launchEvent.
*/
export function on(event: "onLaunch", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when an uncaught error occurs while the application is running.
*/
export function on(event: "onUncaughtError", callback: (args: ApplicationEventData) => void, thisArg?: any);
export function on(event: "launch", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when the Application is suspended.
*/
export function on(event: "onSuspend", callback: (args: ApplicationEventData) => void, thisArg?: any);
export function on(event: "suspend", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when the Application is resumed after it has been suspended.
*/
export function on(event: "onResume", callback: (args: ApplicationEventData) => void, thisArg?: any);
export function on(event: "resume", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when the Application is about to exitEvent.
*/
export function on(event: "onExit", callback: (args: ApplicationEventData) => void, thisArg?: any);
export function on(event: "exit", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when there is low memory on the target device.
*/
export function on(event: "onLowMemory", callback: (args: ApplicationEventData) => void, thisArg?: any);
export function on(event: "lowMemory", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This event is raised when an uncaught error occurs while the application is running.
*/
export function on(event: "uncaughtError", callback: (args: ApplicationEventData) => void, thisArg?: any);
/**
* This is the Android-specific application object instance.
@ -395,6 +395,51 @@ declare module "application" {
* This event is raised on the back button is pressed in an android application.
*/
on(event: "activityBackPressed", callback: (args: AndroidActivityBackPressedEventData) => void, thisArg?: any);
/**
* String value used when hooking to activityCreated event.
*/
public static activityCreatedEvent: string;
/**
* String value used when hooking to activityDestroyed event.
*/
public static activityDestroyedEvent: string;
/**
* String value used when hooking to activityStarted event.
*/
public static activityStartedEvent: string;
/**
* String value used when hooking to activityPaused event.
*/
public static activityPausedEvent: string;
/**
* String value used when hooking to activityResumed event.
*/
public static activityResumedEvent: string;
/**
* String value used when hooking to activityStopped event.
*/
public static activityStoppedEvent: string;
/**
* String value used when hooking to saveActivityState event.
*/
public static saveActivityStateEvent: string;
/**
* String value used when hooking to activityResult event.
*/
public static activityResultEvent: string;
/**
* String value used when hooking to activityBackPressed event.
*/
public static activityBackPressedEvent: string;
}
/* tslint:disable */

View File

@ -1,5 +1,4 @@
import platform = require("platform");
import application = require("application");
import application = require("application");
application.mainModule = "app/mainPage";
@ -64,43 +63,44 @@ application.on(application.uncaughtErrorEvent, function (args: application.Appli
}
});
if (platform.device.os === platform.platformNames.android) {
// Android activity events
application.android.on("activityCreated", function (args: application.AndroidActivityBundleEventData) {
// Android activity events
if (application.android) {
application.android.on(application.AndroidApplication.activityCreatedEvent, function (args: application.AndroidActivityBundleEventData) {
console.log("Event: " + args.eventName + ", Activity: " + args.activity + ", Bundle: " + args.bundle);
});
application.android.on("activityDestroyed", function (args: application.AndroidActivityEventData) {
application.android.on(application.AndroidApplication.activityDestroyedEvent, function (args: application.AndroidActivityEventData) {
console.log("Event: " + args.eventName + ", Activity: " + args.activity);
});
application.android.on("activityPaused", function (args: application.AndroidActivityEventData) {
application.android.on(application.AndroidApplication.activityStartedEvent, function (args: application.AndroidActivityEventData) {
console.log("Event: " + args.eventName + ", Activity: " + args.activity);
});
application.android.on("activityResult", function (args: application.AndroidActivityResultEventData) {
application.android.on(application.AndroidApplication.activityPausedEvent, function (args: application.AndroidActivityEventData) {
console.log("Event: " + args.eventName + ", Activity: " + args.activity);
});
application.android.on(application.AndroidApplication.activityResumedEvent, function (args: application.AndroidActivityEventData) {
console.log("Event: " + args.eventName + ", Activity: " + args.activity);
});
application.android.on(application.AndroidApplication.activityStoppedEvent, function (args: application.AndroidActivityEventData) {
console.log("Event: " + args.eventName + ", Activity: " + args.activity);
});
application.android.on(application.AndroidApplication.saveActivityStateEvent, function (args: application.AndroidActivityBundleEventData) {
console.log("Event: " + args.eventName + ", Activity: " + args.activity + ", Bundle: " + args.bundle);
});
application.android.on(application.AndroidApplication.activityResultEvent, function (args: application.AndroidActivityResultEventData) {
console.log("Event: " + args.eventName + ", Activity: " + args.activity +
", requestCode: " + args.requestCode + ", resultCode: " + args.resultCode + ", Intent: " + args.intent);
});
application.android.on("activityResumed", function (args: application.AndroidActivityEventData) {
console.log("Event: " + args.eventName + ", Activity: " + args.activity);
});
application.android.on("activityStarted", function (args: application.AndroidActivityEventData) {
console.log("Event: " + args.eventName + ", Activity: " + args.activity);
});
application.android.on("activityStopped", function (args: application.AndroidActivityEventData) {
console.log("Event: " + args.eventName + ", Activity: " + args.activity);
});
application.android.on("saveActivityState", function (args: application.AndroidActivityBundleEventData) {
console.log("Event: " + args.eventName + ", Activity: " + args.activity + ", Bundle: " + args.bundle);
});
application.android.on("activityBackPressed", function (args: application.AndroidActivityBackPressedEventData) {
application.android.on(application.AndroidApplication.activityBackPressedEvent, function (args: application.AndroidActivityBackPressedEventData) {
console.log("Event: " + args.eventName + ", Activity: " + args.activity);
// Set args.cancel = true to cancel back navigation and do something custom.
});
}

View File

@ -34,7 +34,7 @@ declare module "ui/styling/background" {
public withPosition(value: string): Background;
public withSize(value: string): Background;;
public withSize(value: string): Background;
public getDrawParams(width: number, height: number): BackgroundDrawParams;