Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function setupConfigListener() {
nsApp.off(nsApp.launchEvent, setupConfigListener);
const context = nsApp.android && (nsApp.android.context as android.content.Context);
if (!context) {
nsApp.on(nsApp.launchEvent, setupConfigListener);
return;
}
useAndroidFontScale();
let configChangedCallback = new android.content.ComponentCallbacks2({
onLowMemory() {
// Dummy
},
onTrimMemory() {
// Dummy
},
private platformExtension() {
// 'mp3'
return `${app.android ? 'm4a' : 'caf'}`;
}
function printDeviceInfoAndroid() {
console.log("android.os.Build.DEVICE = " + android.os.Build.DEVICE); //android.os.Build.DEVICE = hammerhead
console.log("android.os.Build.VERSION.SDK = " + android.os.Build.VERSION.SDK); //android.os.Build.VERSION.SDK = 19
console.log("android.os.Build.VERSION.SDK_INT = " + android.os.Build.VERSION.SDK_INT); //android.os.Build.VERSION.SDK_INT = 19
console.log("android.os.Build.VERSION.CODENAME = " + android.os.Build.VERSION.CODENAME); //android.os.Build.VERSION.CODENAME = REL
console.log("android.os.Build.VERSION.RELEASE = " + android.os.Build.VERSION.RELEASE); //android.os.Build.VERSION.RELEASE = 4.4.4
var metrics: android.util.DisplayMetrics = app.android.context.getResources().getDisplayMetrics();
console.log("metrics.density = " + metrics.density); //metrics.density = 3
console.log("metrics.scaledDensity = " + metrics.scaledDensity); //metrics.scaledDensity = 3
console.log("metrics.densityDpi = " + metrics.densityDpi); //metrics.densityDpi = 480
console.log("metrics.xdpi = " + metrics.xdpi); //metrics.xdpi = 442.45098876953125
console.log("metrics.yxdpi = " + metrics.ydpi); //metrics.yxdpi = 443.3450012207031
console.log("metrics.widthPixels = " + metrics.widthPixels); //metrics.widthPixels = 1080
console.log("metrics.heightPixels = " + metrics.heightPixels); //metrics.heightPixels = 1776
var config = app.android.context.getResources().getConfiguration();
console.log("config.screenWidthDp = " + config.screenWidthDp);
console.log("config.screenHeightDp = " + config.screenHeightDp);
console.log("config.smallestScreenWidthDp = " + config.smallestScreenWidthDp);
console.log("config.orientation = " + (config.orientation === android.content.res.Configuration.ORIENTATION_PORTRAIT ? "portrait" : "ladscape"));
}
export function testNativeFields() {
const img = ImageSource.fromFileSync(imagePath);
if (app.android) {
TKUnit.assert(img.android != null, "Image.android not updated.");
} else if (app.ios) {
TKUnit.assert(img.ios != null, "Image.ios not updated.");
}
}
const fullAndroidPng = "iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAA3NCSVQICAjb4U/gAAAAFUlEQVQImWP8z4AAjAz/kTnIPGQAAG86AwGcuMlCAAAAAElFTkSuQmCC";
export function test_platform() {
let expectedPlatform;
if (app.android) {
expectedPlatform = "Android";
} else {
expectedPlatform = "iOS";
}
TKUnit.assertEqual(platformModule.device.os, expectedPlatform);
}
function print() {
if (app.android) {
printDeviceInfoAndroid();
}
else {
printDeviceInfoIOS();
}
printTNSInfo();
}
//print();
function getId(id: string) {
const context: android.content.Context = application.android.context;
return context.getResources().getIdentifier(id, 'id', context.getPackageName());
}
function useAndroidFontScale() {
fontScaleChanged(Number(nsApp.android.context.getResources().getConfiguration().fontScale));
}