How to use the @nativescript/core/application.android function in @nativescript/core

To help you get started, we’ve selected a few @nativescript/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Notalib / nativescript-accessibility-ext / src / utils / FontScaleObservable.android.ts View on Github external
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
    },
github nstudio / nativescript-audio / demo / app / main-view-model.ts View on Github external
private platformExtension() {
    // 'mp3'
    return `${app.android ? 'm4a' : 'caf'}`;
  }
github NativeScript / NativeScript / tests / app / pages / page5.ts View on Github external
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"));
}
github NativeScript / NativeScript / tests / app / image-source / image-source-tests.ts View on Github external
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";
github NativeScript / NativeScript / tests / app / platform / platform-tests.ts View on Github external
export function test_platform() {
    let expectedPlatform;
    if (app.android) {
        expectedPlatform = "Android";
    } else {
        expectedPlatform = "iOS";
    }
    TKUnit.assertEqual(platformModule.device.os, expectedPlatform);
}
github NativeScript / NativeScript / tests / app / pages / page5.ts View on Github external
function print() {
    if (app.android) {
        printDeviceInfoAndroid();
    }
    else {
        printDeviceInfoIOS();
    }
    printTNSInfo();
}
//print();
github Akylas / nativescript-material-components / src / page / page.android.ts View on Github external
function getId(id: string) {
    const context: android.content.Context = application.android.context;
    return context.getResources().getIdentifier(id, 'id', context.getPackageName());
}
github Notalib / nativescript-accessibility-ext / src / utils / FontScaleObservable.android.ts View on Github external
function useAndroidFontScale() {
  fontScaleChanged(Number(nsApp.android.context.getResources().getConfiguration().fontScale));
}