Remove the android.app.Application extend from the core modules. This will enable various scenarios where custom application implementation is needed.

This commit is contained in:
atanasovg
2016-06-03 15:34:30 +03:00
parent 3c265a7c00
commit 36da401684
3 changed files with 112 additions and 80 deletions

View File

@ -147,11 +147,43 @@ export module ad {
view.setSingleLine(value === enums.WhiteSpace.nowrap);
view.setEllipsize(value === enums.WhiteSpace.nowrap ? android.text.TextUtils.TruncateAt.END : null);
}
let nativeApp: android.app.Application;
declare var com;
export function getApplication() {
return <android.app.Application>(<any>com.tns).NativeScriptApplication.getInstance();
if(!nativeApp) {
// check whether the com.tns.NativeScriptApplication type exists
if(com.tns.NativeScriptApplication) {
nativeApp = com.tns.NativeScriptApplication.getInstance();
}
else {
// check whether application.android.init has been explicitly called
let application = require("application");
nativeApp = application.android.nativeApp;
if(!nativeApp) {
// TODO: Should we handle the case when a custom application type is provided and the user has not explicitly initialized the application module?
let clazz = java.lang.Class.forName("android.app.ActivityThread");
if(clazz) {
let method = clazz.getMethod("currentApplication", null);
if(method) {
nativeApp = method.invoke(null, null);
}
}
}
}
if(!nativeApp) {
throw new Error("Failed to retrieve native Android Application object. If you have a custom android.app.Application type implemented make sure that you've called the '<application-module>.android.init' method.")
}
}
return nativeApp;
}
export function getApplicationContext() {
let app = getApplication();
return app.getApplicationContext();
}
export function getApplicationContext() { return <android.content.Context>getApplication().getApplicationContext(); }
var inputMethodManager: android.view.inputmethod.InputMethodManager;
export function getInputMethodManager() {