renamed folders with lower cases and renamed user preferences to local settings

This commit is contained in:
Stanimir Karoserov
2014-05-13 17:59:30 +03:00
parent b6313517db
commit ceff7bb368
58 changed files with 227 additions and 225 deletions

5
application/Readme.md Normal file
View File

@@ -0,0 +1,5 @@
To initialize the module put the following code in the main entry point file (app.js):
```js
var appModule = require("Application");
appModule.init([native app instance]);
```

View File

@@ -0,0 +1,122 @@
import appModule = require("application/application_common");
// merge the exports of the application_common file with the exports of this file
declare var exports;
require("utils/module_merge").merge(appModule, exports);
var callbacks = android.app.Application.ActivityLifecycleCallbacks;
var initEvents = function () {
var androidApp = exports.android;
var lifecycleCallbacks = new callbacks({
onActivityCreated: function (activity: any, bundle: any) {
if (!androidApp.startActivity) {
androidApp.startActivity = activity;
if (androidApp.onActivityCreated) {
androidApp.onActivityCreated(activity, bundle);
}
}
},
onActivityDestroyed: function (activity: any) {
// Clear the current activity reference to prevent leak
if (activity === androidApp.currentActivity) {
androidApp.currentActivity = undefined;
}
//if (activity === UI.Application.android.startActivity) {
// UI.Application.android.currentActivity = undefined;
// if (UI.Application.current.onExit) {
// UI.Application.current.onExit();
// }
//}
if (androidApp.onActivityDestroyed) {
androidApp.onActivityDestroyed(activity);
}
},
onActivityPaused: function (activity: any) {
//if (UI.Application.android.currentActivity === activity) {
// if (UI.Application.current.onSuspend) {
// UI.Application.current.onSuspend();
// }
//}
if (androidApp.onActivityPaused) {
androidApp.onActivityPaused(activity);
}
},
onActivityResumed: function (activity: any) {
//if (UI.Application.android.currentActivity === activity) {
// if (UI.Application.current.onResume) {
// UI.Application.current.onResume();
// }
//}
if (androidApp.onActivityResumed) {
androidApp.onActivityResumed(activity);
}
},
onActivitySaveInstanceState: function (activity: any, bundle: any) {
if (androidApp.onSaveActivityState) {
androidApp.onSaveActivityState(activity, bundle);
}
},
onActivityStarted: function (activity: any) {
androidApp.currentActivity = activity;
//if (activity === UI.Application.android.startActivity) {
// if (UI.Application.current.onStart) {
// UI.Application.current.onStart();
// }
//}
if (androidApp.onActivityStarted) {
androidApp.onActivityStarted(activity);
}
},
onActivityStopped: function (activity: any) {
if (androidApp.onActivityStopped) {
androidApp.onActivityStopped(activity);
}
}
});
return lifecycleCallbacks;
}
export var init = function (nativeApp: android.app.Application) {
var app = new AndroidApplication(nativeApp);
exports.android = app;
app.init();
}
class AndroidApplication {
public nativeApp: android.app.Application;
public context: android.content.Context;
public currentActivity: android.app.Activity;
public startActivity: android.app.Activity;
public packageName: string;
public onActivityCreated: (activity: android.app.Activity, bundle: android.os.Bundle) => any;
public onActivityDestroyed: (activity: android.app.Activity) => any;
public onActivityStarted: (activity: android.app.Activity) => any;
public onActivityPaused: (activity: android.app.Activity) => any;
public onActivityResumed: (activity: android.app.Activity) => any;
public onActivityStopped: (activity: android.app.Activity) => any;
public onSaveActivityState: (activity: android.app.Activity, bundle: android.os.Bundle) => any;
private _eventsToken: any;
constructor(nativeApp: any) {
this.nativeApp = nativeApp;
this.packageName = nativeApp.getPackageName();
this.context = nativeApp.getApplicationContext();
}
public init() {
this._eventsToken = initEvents();
this.nativeApp.registerActivityLifecycleCallbacks(this._eventsToken);
this.context = this.nativeApp.getApplicationContext();
}
}

125
application/application.d.ts vendored Normal file
View File

@@ -0,0 +1,125 @@
/**
* The main entry point event. This method is expected to return an instance of the root UI for the application.
* This will be an Activity extends for Android and a RootViewController for iOS.
*/
export declare function onLaunch(): any;
/**
* This method will be called when the Application is suspended.
*/
export declare function onSuspend();
/**
* This method will be called when the Application is resumed after it has been suspended.
*/
export declare function onResume();
/**
* This method will be called when the Application is about to exit.
*/
export declare function onExit();
/**
* This method will be called when there is low memory on the target device.
*/
export declare function onLowMemory();
/**
* This is the Android-specific application object instance.
* Encapsulates methods and properties specific to the Android platform.
* Will be undefined when TargetOS is iOS.
*/
export declare var android: AndroidApplication;
/**
* This is the iOS-specific application object instance.
* Encapsulates methods and properties specific to the iOS platform.
* Will be undefined when TargetOS is Android.
*/
export declare var ios: iOSApplication;
/**
* The abstraction of an Android-specific application object.
*/
export declare class AndroidApplication {
/**
* The android.app.Application object instance provided to the init of the module.
*/
public nativeApp: android.app.Application;
/**
* The application android.content.Context object instance.
*/
public context: android.content.Context;
/**
* The currently active (loaded) android.app.Activity. This property is automatically updated upon Activity events.
*/
public currentActivity: android.app.Activity;
/**
* The main (start) Activity for the application.
*/
public mainActivity: android.app.Activity;
/**
* The name of the application package.
*/
public packageName: string;
/**
* 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.
*/
public getActivity: (intent: android.content.Intent) => any;
/**
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onActivityCreated method.
*/
public onActivityCreated: (activity: android.app.Activity, bundle: android.os.Bundle) => void;
/**
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onActivityDestroyed method.
*/
public onActivityDestroyed: (activity: android.app.Activity) => void;
/**
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onActivityDestroyed method.
*/
public onActivityStarted: (activity: android.app.Activity) => void;
/**
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onActivityPaused method.
*/
public onActivityPaused: (activity: android.app.Activity) => void;
/**
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onActivityResumed method.
*/
public onActivityResumed: (activity: android.app.Activity) => void;
/**
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onActivityStopped method.
*/
public onActivityStopped: (activity: android.app.Activity) => void;
/**
* Direct handler of the android.app.Application.ActivityLifecycleCallbacks.onSaveActivityState method.
*/
public onSaveActivityState: (activity: android.app.Activity, bundle: android.os.Bundle) => void;
}
/**
* The abstraction of an iOS-specific application object.
*/
export declare class iOSApplication {
/**
* The root view controller for the application.
*/
public rootController: UIKit.UIViewController;
}
/**
* Entry point for the module. Initializes the Application singleton and hooks application lifecycle events.
*/
export declare function init(nativeApp: any);

View File

@@ -0,0 +1,105 @@

/*
Current launch sequence for iOS looks like:
var app = require("Application/application");
app.tk.ui.Application.current.onLaunch = function() {
log("tk.ui.Application.current.onLaunch");
var myViewController = new MyViewController();
var navController = new UIKit.UINavigationController(myViewController);
return navController;
}
log("JavaScript loading started.");
app.tk.ui.ios.initApp(null);
log("JavaScript loading ended.");
log("JavaScript loading ended.");
*/
import appModule = require("application/application_common");
// merge the exports of the application_common file with the exports of this file
declare var exports;
require("utils/module_merge").merge(appModule, exports);
// TODO: Declarations
export var init = function (nativeApp: any) {
var app = new iOSApplication(nativeApp);
exports.ios = app;
app.init();
}
class iOSApplication {
public nativeApp: any;
public rootController: any;
constructor(nativeApp: any) {
this.nativeApp = nativeApp;
}
public init() {
UIKit.UIResponder.extends({/*TODO: Empty parameter here, needs API improvement*/}, {
name: "TNSAppDelegate",
}).implements({
protocol: "UIApplicationDelegate",
implementation: {
applicationDidFinishLaunchingWithOptions: function () {
log("Application launched: applicationDidFinishLaunchingWithOptions.");
this.window = new UIKit.UIWindow(UIKit.UIScreen.mainScreen().bounds);
this.window.backgroundColor = UIKit.UIColor.whiteColor();
this.window.makeKeyAndVisible();
if (exports.onLaunch) {
this.window.rootViewController = exports.onLaunch();
} else {
log("Missing Application.onLaunch");
}
log("applicationDidFinishLaunchingWithOptions finished.");
return true;
},
applicationDidBecomeActive: function (application) {
log("applicationDidBecomeActive: " + application);
if (exports.onResume) {
exports.onResume();
}
},
applicationWillResignActive: function (application) {
log("applicationWillResignActive: " + application);
},
applicationDidEnterBackground: function (application) {
log("applicationDidEnterBackground: " + application);
if (exports.onSuspend) {
exports.onSuspend();
}
},
applicationWillEnterForeground: function (application) {
log("applicationWillEnterForeground: " + application);
},
applicationWillTerminate: function (application) {
log("applicationWillTerminate: " + application);
if (exports.onExit) {
exports.onExit();
}
},
applicationDidReceiveMemoryWarning: function (application) {
log("applicationDidReceiveMemoryWarning: " + application);
if (exports.onLowMemory) {
exports.onLowMemory();
}
}
}
});
}
}

View File

@@ -0,0 +1,15 @@
require("globals");
export var onLaunch: () => any = undefined;
export var onSuspend: () => any = undefined;
export var onResume: () => any = undefined;
export var onExit: () => any = undefined;
export var onLowMemory: () => any = undefined;
export var android = undefined;
export var ios = undefined;

2
application/index.ts Normal file
View File

@@ -0,0 +1,2 @@
declare var module, require;
module.exports = require("application/application");