refactor: Application modules to classes

This commit is contained in:
Igor Randjelovic
2023-05-10 22:08:01 +02:00
parent 7650cdd890
commit fc01f8e79f
50 changed files with 5438 additions and 2985 deletions

View File

@ -1,4 +1,4 @@
import { getNativeApplication, android as androidApp } from '../../application';
import { Application } from '../../application';
import { Trace } from '../../trace';
let application: android.app.Application;
@ -14,14 +14,14 @@ export function getApplicationContext() {
return applicationContext;
}
export function getCurrentActivity() {
if (!androidApp) {
if (!Application) {
return null;
}
return androidApp.foregroundActivity || androidApp.startActivity;
return Application.android.foregroundActivity || Application.android.startActivity;
}
export function getApplication() {
if (!application) {
application = <android.app.Application>getNativeApplication();
application = Application.android.getNativeApplication();
}
return application;
@ -44,7 +44,11 @@ function getPackageName() {
let inputMethodManager: android.view.inputmethod.InputMethodManager;
export function getInputMethodManager(): android.view.inputmethod.InputMethodManager {
if (!inputMethodManager) {
inputMethodManager = <android.view.inputmethod.InputMethodManager>getApplicationContext().getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
inputMethodManager = <android.view.inputmethod.InputMethodManager>(
getApplicationContext().getSystemService(
android.content.Context.INPUT_METHOD_SERVICE
)
);
}
return inputMethodManager;
@ -53,7 +57,10 @@ export function getInputMethodManager(): android.view.inputmethod.InputMethodMan
export function showSoftInput(nativeView: android.view.View): void {
const inputManager = getInputMethodManager();
if (inputManager && nativeView instanceof android.view.View) {
inputManager.showSoftInput(nativeView, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT);
inputManager.showSoftInput(
nativeView,
android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT
);
}
}
@ -129,10 +136,16 @@ export namespace resources {
export function getResource(name: string, type?: string): number {
return getResources().getIdentifier(name, type, getPackageName());
}
export function getPalleteColor(name: string, context: android.content.Context): number {
export function getPalleteColor(
name: string,
context: android.content.Context
): number {
return getPaletteColor(name, context);
}
export function getPaletteColor(name: string, context: android.content.Context): number {
export function getPaletteColor(
name: string,
context: android.content.Context
): number {
if (attrCache.has(name)) {
return attrCache.get(name);
}
@ -155,7 +168,11 @@ export namespace resources {
result = typedValue.data;
}
} catch (ex) {
Trace.write('Cannot get pallete color: ' + name, Trace.categories.Error, Trace.messageType.error);
Trace.write(
'Cannot get pallete color: ' + name,
Trace.categories.Error,
Trace.messageType.error
);
}
attrCache.set(name, result);
@ -167,5 +184,8 @@ export namespace resources {
export function isRealDevice(): boolean {
const fingerprint = android.os.Build.FINGERPRINT;
return fingerprint != null && (fingerprint.indexOf('vbox') > -1 || fingerprint.indexOf('generic') > -1);
return (
fingerprint != null &&
(fingerprint.indexOf('vbox') > -1 || fingerprint.indexOf('generic') > -1)
);
}