mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Refactored the Application module (removed namespaces). Updated the UnitTestApp project.
This commit is contained in:
5
Application/Readme.md
Normal file
5
Application/Readme.md
Normal 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]);
|
||||
```
|
||||
@@ -1,138 +1,129 @@
|
||||
import app_common_module = require("Application/application_common");
|
||||
import console_module = require("Console/console_common");
|
||||
var currentApp = app_common_module.Application.current;
|
||||
|
||||
var currentApp = app_common_module.tk.ui.Application.current;
|
||||
// merge the exports of the application_common file with the exports of this file
|
||||
declare var exports;
|
||||
exports.tk = app_common_module.tk;
|
||||
exports.TargetOS = app_common_module.TargetOS;
|
||||
exports.Application = app_common_module.Application;
|
||||
|
||||
export module tk {
|
||||
// TODO: This is tricky, we have a module named android down in the hierarchy and we need to declare it here
|
||||
var callbacks = android.app.Application.ActivityLifecycleCallbacks;
|
||||
var callbacks = android.app.Application.ActivityLifecycleCallbacks;
|
||||
|
||||
export module ui {
|
||||
export module android {
|
||||
var initEvents = function () {
|
||||
var androidApp = <Application>app_common_module.tk.ui.Application.current.android;
|
||||
var initEvents = function () {
|
||||
var androidApp = app_common_module.Application.current.android;
|
||||
var lifecycleCallbacks = new callbacks({
|
||||
onActivityCreated: function (activity: any, bundle: any) {
|
||||
if (!androidApp.startActivity) {
|
||||
androidApp.startActivity = activity;
|
||||
|
||||
var lifecycleCallbacks = new callbacks({
|
||||
onActivityCreated: function (activity: any, bundle: any) {
|
||||
if (!androidApp.startActivity) {
|
||||
androidApp.startActivity = activity;
|
||||
//if (UI.Application.current.onLaunch) {
|
||||
// UI.Application.current.onLaunch();
|
||||
//}
|
||||
|
||||
//if (UI.Application.current.onLaunch) {
|
||||
// UI.Application.current.onLaunch();
|
||||
//}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
export var initApp = function (nativeApp: any) {
|
||||
var app = new Application(nativeApp);
|
||||
currentApp.os = app_common_module.tk.TargetOS.Android;
|
||||
currentApp.android = app;
|
||||
app.init();
|
||||
console = new console_module.TKConsole();
|
||||
//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();
|
||||
// }
|
||||
//}
|
||||
|
||||
class Application {
|
||||
public nativeApp: any;
|
||||
public context: any;
|
||||
public currentActivity: any;
|
||||
public startActivity: any;
|
||||
public packageName: string;
|
||||
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();
|
||||
// }
|
||||
//}
|
||||
|
||||
// TODO: Provide type information once definitions are done - e.g. activity: android.widget.activity
|
||||
public onActivityCreated: (activity: any, bundle: any) => any;
|
||||
public onActivityDestroyed: (activity: any) => any;
|
||||
public onActivityStarted: (activity: any) => any;
|
||||
public onActivityPaused: (activity: any) => any;
|
||||
public onActivityResumed: (activity: any) => any;
|
||||
public onActivityStopped: (activity: any) => any;
|
||||
public onSaveActivityState: (activity: any, bundle: any) => any;
|
||||
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;
|
||||
|
||||
private _eventsToken: any;
|
||||
//if (activity === UI.Application.android.startActivity) {
|
||||
// if (UI.Application.current.onStart) {
|
||||
// UI.Application.current.onStart();
|
||||
// }
|
||||
//}
|
||||
|
||||
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();
|
||||
}
|
||||
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);
|
||||
currentApp.os = app_common_module.TargetOS.Android;
|
||||
currentApp.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();
|
||||
}
|
||||
}
|
||||
76
Application/application.d.ts
vendored
76
Application/application.d.ts
vendored
@@ -1,50 +1,40 @@
|
||||
export declare module tk {
|
||||
export enum TargetOS {
|
||||
iOS,
|
||||
Android,
|
||||
//WP
|
||||
}
|
||||
export declare enum TargetOS {
|
||||
iOS,
|
||||
Android
|
||||
}
|
||||
|
||||
export module ui {
|
||||
export class Application {
|
||||
static current: Application;
|
||||
public os: TargetOS;
|
||||
export declare class Application {
|
||||
static current: Application;
|
||||
public os: TargetOS;
|
||||
|
||||
public onLaunch: () => any;
|
||||
public onSuspend: () => any;
|
||||
public onResume: () => any;
|
||||
public onExit: () => any;
|
||||
public onLowMemory: () => any;
|
||||
public onLaunch: () => any;
|
||||
public onSuspend: () => any;
|
||||
public onResume: () => any;
|
||||
public onExit: () => any;
|
||||
public onLowMemory: () => any;
|
||||
|
||||
public android: android.Application;
|
||||
public ios: ios.Application;
|
||||
}
|
||||
public android: AndroidApplication;
|
||||
public ios: iOSApplication;
|
||||
}
|
||||
|
||||
export module android {
|
||||
export function initApp(nativeApp: any);
|
||||
export class Application {
|
||||
public nativeApp: any; // TODO: android.app
|
||||
public context: any; // TODO: android.context
|
||||
public currentActivity: any; // TODO: android.activity
|
||||
public startActivity: any; // TODO: android.activity
|
||||
public packageName: string;
|
||||
export declare function init(nativeApp: any);
|
||||
|
||||
// TODO: Provide type information once definitions are done - e.g. activity: android.widget.activity
|
||||
public onActivityCreated: (activity: any, bundle: any) => any;
|
||||
public onActivityDestroyed: (activity: any) => any;
|
||||
public onActivityStarted: (activity: any) => any;
|
||||
public onActivityPaused: (activity: any) => any;
|
||||
public onActivityResumed: (activity: any) => any;
|
||||
public onActivityStopped: (activity: any) => any;
|
||||
public onSaveActivityState: (activity: any, bundle: any) => any;
|
||||
}
|
||||
}
|
||||
export declare 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;
|
||||
|
||||
export module ios {
|
||||
export function initApp(nativeApp: any);
|
||||
export class Application {
|
||||
public rootController: any;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
export declare class iOSApplication {
|
||||
public rootController: any;
|
||||
}
|
||||
@@ -21,96 +21,90 @@ log("JavaScript loading ended.");
|
||||
*/
|
||||
|
||||
import app_common_module = require("Application/application_common");
|
||||
import console_module = require("Console/console_common");
|
||||
var currentApp = app_common_module.Application.current;
|
||||
|
||||
var currentApp = app_common_module.tk.ui.Application.current;
|
||||
// merge the exports of the application_common file with the exports of this file
|
||||
declare var exports;
|
||||
exports.tk = app_common_module.tk;
|
||||
exports.TargetOS = app_common_module.TargetOS;
|
||||
exports.Application = app_common_module.Application;
|
||||
|
||||
export module tk {
|
||||
export module ui {
|
||||
export module ios {
|
||||
// TODO: Declarations
|
||||
export var initApp = function (nativeApp: any) {
|
||||
var app = new Application(nativeApp);
|
||||
currentApp.os = app_common_module.tk.TargetOS.iOS;
|
||||
currentApp.ios = app;
|
||||
app.init();
|
||||
console = new console_module.TKConsole();
|
||||
}
|
||||
// TODO: Declarations
|
||||
export var init = function (nativeApp: any) {
|
||||
var app = new iOSApplication(nativeApp);
|
||||
currentApp.os = app_common_module.TargetOS.iOS;
|
||||
currentApp.ios = app;
|
||||
app.init();
|
||||
}
|
||||
|
||||
class Application {
|
||||
public nativeApp: any;
|
||||
public rootController: any;
|
||||
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: "KimeraAppDelegate",
|
||||
}).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();
|
||||
|
||||
var iosApp = <Application>currentApp.ios;
|
||||
|
||||
if (currentApp.onLaunch) {
|
||||
this.window.rootViewController = currentApp.onLaunch();
|
||||
} else {
|
||||
log("Missing TK.UI.Application.current.onLaunch");
|
||||
}
|
||||
|
||||
log("applicationDidFinishLaunchingWithOptions finished.");
|
||||
return true;
|
||||
},
|
||||
|
||||
applicationDidBecomeActive: function (application) {
|
||||
log("applicationDidBecomeActive: " + application);
|
||||
if (currentApp.onResume) {
|
||||
currentApp.onResume();
|
||||
}
|
||||
},
|
||||
|
||||
applicationWillResignActive: function (application) {
|
||||
log("applicationWillResignActive: " + application);
|
||||
},
|
||||
|
||||
applicationDidEnterBackground: function (application) {
|
||||
log("applicationDidEnterBackground: " + application);
|
||||
if (currentApp.onSuspend) {
|
||||
currentApp.onSuspend();
|
||||
}
|
||||
},
|
||||
|
||||
applicationWillEnterForeground: function (application) {
|
||||
log("applicationWillEnterForeground: " + application);
|
||||
},
|
||||
|
||||
applicationWillTerminate: function (application) {
|
||||
log("applicationWillTerminate: " + application);
|
||||
if (currentApp.onExit) {
|
||||
currentApp.onExit();
|
||||
}
|
||||
},
|
||||
|
||||
applicationDidReceiveMemoryWarning: function (application) {
|
||||
log("applicationDidReceiveMemoryWarning: " + application);
|
||||
if (currentApp.onLowMemory) {
|
||||
currentApp.onLowMemory();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
constructor(nativeApp: any) {
|
||||
this.nativeApp = nativeApp;
|
||||
}
|
||||
}
|
||||
|
||||
public init() {
|
||||
UIKit.UIResponder.extends({/*TODO: Empty parameter here, needs API improvement*/}, {
|
||||
name: "KimeraAppDelegate",
|
||||
}).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();
|
||||
|
||||
var iosApp = currentApp.ios;
|
||||
|
||||
if (currentApp.onLaunch) {
|
||||
this.window.rootViewController = currentApp.onLaunch();
|
||||
} else {
|
||||
log("Missing TK.UI.Application.current.onLaunch");
|
||||
}
|
||||
|
||||
log("applicationDidFinishLaunchingWithOptions finished.");
|
||||
return true;
|
||||
},
|
||||
|
||||
applicationDidBecomeActive: function (application) {
|
||||
log("applicationDidBecomeActive: " + application);
|
||||
if (currentApp.onResume) {
|
||||
currentApp.onResume();
|
||||
}
|
||||
},
|
||||
|
||||
applicationWillResignActive: function (application) {
|
||||
log("applicationWillResignActive: " + application);
|
||||
},
|
||||
|
||||
applicationDidEnterBackground: function (application) {
|
||||
log("applicationDidEnterBackground: " + application);
|
||||
if (currentApp.onSuspend) {
|
||||
currentApp.onSuspend();
|
||||
}
|
||||
},
|
||||
|
||||
applicationWillEnterForeground: function (application) {
|
||||
log("applicationWillEnterForeground: " + application);
|
||||
},
|
||||
|
||||
applicationWillTerminate: function (application) {
|
||||
log("applicationWillTerminate: " + application);
|
||||
if (currentApp.onExit) {
|
||||
currentApp.onExit();
|
||||
}
|
||||
},
|
||||
|
||||
applicationDidReceiveMemoryWarning: function (application) {
|
||||
log("applicationDidReceiveMemoryWarning: " + application);
|
||||
if (currentApp.onLowMemory) {
|
||||
currentApp.onLowMemory();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,26 @@
|
||||
export module tk {
|
||||
export enum TargetOS {
|
||||
iOS,
|
||||
Android,
|
||||
//WP
|
||||
import console_module = require("Console/console_common");
|
||||
|
||||
export enum TargetOS {
|
||||
iOS,
|
||||
Android
|
||||
}
|
||||
|
||||
export class Application {
|
||||
public os: TargetOS;
|
||||
|
||||
constructor() {
|
||||
console = new console_module.TKConsole();
|
||||
}
|
||||
|
||||
export module ui {
|
||||
export class Application {
|
||||
public onLaunch: () => any;
|
||||
public onSuspend: () => any;
|
||||
public onResume: () => any;
|
||||
public onExit: () => any;
|
||||
public onLowMemory: () => any;
|
||||
|
||||
public os: TargetOS;
|
||||
public static current: Application = new Application();
|
||||
|
||||
public onLaunch: () => any;
|
||||
public onSuspend: () => any;
|
||||
public onResume: () => any;
|
||||
public onExit: () => any;
|
||||
public onLowMemory: () => any;
|
||||
|
||||
public static current: Application = new Application();
|
||||
|
||||
// TODO: These fields are declared by the application.d.ts file and intellisense will come from there
|
||||
public android: any;
|
||||
public ios: any;
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: These fields are declared by the application.d.ts file and intellisense will come from there
|
||||
public android: any;
|
||||
public ios: any;
|
||||
}
|
||||
@@ -181,6 +181,9 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Location\Readme.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Application\Readme.md" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'iOS'">
|
||||
<TypeScriptModuleKind>commonjs</TypeScriptModuleKind>
|
||||
<TypeScriptRemoveComments>True</TypeScriptRemoveComments>
|
||||
|
||||
@@ -6,7 +6,7 @@ var REQUEST_SELECT_PICTURE: number = 2;
|
||||
export class CameraManager {
|
||||
public takePicture(params: any, onSuccess: (imageData: any) => any, onError?: (error: any) => any) {
|
||||
var takePictureIntent = new android.content.Intent('android.media.action.IMAGE_CAPTURE');
|
||||
var androidApp = app_module.tk.ui.Application.current.android;
|
||||
var androidApp = app_module.Application.current.android;
|
||||
|
||||
if (takePictureIntent.resolveActivity(androidApp.context.getPackageManager()) !== null) {
|
||||
androidApp.currentActivity.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
|
||||
@@ -16,7 +16,7 @@ export class CameraManager {
|
||||
// options { useSavedPhotos: true }
|
||||
public pictureFromLibrary(params: any, onSuccess: (imageData: any) => any, onError?: (error: any) => any) {
|
||||
var readPictureIntent = new android.content.Intent();
|
||||
var androidApp = app_module.tk.ui.Application.current.android;
|
||||
var androidApp = app_module.Application.current.android;
|
||||
|
||||
readPictureIntent.setType('image/*');
|
||||
readPictureIntent.setAction('android.intent.action.GET_CONTENT');
|
||||
|
||||
@@ -222,13 +222,13 @@ export class FileSystemAccess {
|
||||
}
|
||||
|
||||
public getDocumentsFolderPath(): string {
|
||||
var context = app_module.tk.ui.Application.current.android.context;
|
||||
var context = app_module.Application.current.android.context;
|
||||
var dir: java.io.File = context.getFilesDir();
|
||||
return dir.getAbsolutePath();
|
||||
}
|
||||
|
||||
public getTempFolderPath(): string {
|
||||
var context = app_module.tk.ui.Application.current.android.context;
|
||||
var context = app_module.Application.current.android.context;
|
||||
var dir: java.io.File = context.getCacheDir();
|
||||
return dir.getAbsolutePath();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ export class Image {
|
||||
}
|
||||
|
||||
public loadFromResource(name: string): boolean {
|
||||
var androidApp = app_module.tk.ui.Application.current.android;
|
||||
var androidApp = app_module.Application.current.android;
|
||||
var res = androidApp.context.getResources();
|
||||
if (res) {
|
||||
var identifier: number = res.getIdentifier(name, 'drawable', androidApp.packageName);
|
||||
|
||||
@@ -20,7 +20,7 @@ export class LocationManager {
|
||||
public static isLocationEnabled(): boolean {
|
||||
var criteria = new android.location.Criteria();
|
||||
criteria.setAccuracy(1); // low ? fine ? who knows what 1 means (bug in android docs?)
|
||||
var lm = app_module.tk.ui.Application.current.android.context.getSystemService('location');
|
||||
var lm = app_module.Application.current.android.context.getSystemService('location');
|
||||
return (lm.getBestProvider(criteria, true) != null) ? true : false;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ export class LocationManager {
|
||||
this.minimumUpdateTime = 200;
|
||||
this.isStarted = false;
|
||||
|
||||
this.androidLocationManager = app_module.tk.ui.Application.current.android.context.getSystemService('location');
|
||||
this.androidLocationManager = app_module.Application.current.android.context.getSystemService('location');
|
||||
}
|
||||
|
||||
private static locationFromAndroidLocation(androidLocation: android.location.Location): types.Location {
|
||||
|
||||
@@ -5,7 +5,7 @@ export class UserPreferences {
|
||||
private sharedPreferences: any;
|
||||
|
||||
constructor() {
|
||||
this.sharedPreferences = app_module.tk.ui.Application.current.android.context.getSharedPreferences("prefs.db", 0);
|
||||
this.sharedPreferences = app_module.Application.current.android.context.getSharedPreferences("prefs.db", 0);
|
||||
}
|
||||
|
||||
public containsKey(key: string): boolean {
|
||||
|
||||
@@ -43,7 +43,7 @@ export class http {
|
||||
try {
|
||||
var isImage = url.match(/\.(jpeg|jpg|gif|png)$/) != null;
|
||||
|
||||
var context = app_module.tk.ui.Application.current.android.context;
|
||||
var context = app_module.Application.current.android.context;
|
||||
var request = com.koushikdutta.ion.Ion.with(context, url);
|
||||
|
||||
request = isImage ? request.asBitmap() : request.asString();
|
||||
|
||||
Reference in New Issue
Block a user