Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nativescript-dna-deviceinfo

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nativescript-dna-deviceinfo - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

utility.d.ts

4

deviceinfo.android.d.ts

@@ -1,2 +0,2 @@

import { Carrier, StorageVolume } from './deviceinfo.interface';
import { Carrier, DisplayMetrics, StorageVolume } from './deviceinfo.interface';
export declare function staticDecorator<T>(): (constructor: T) => void;

@@ -26,2 +26,4 @@ export declare class DeviceInfo {

static wifiSSID(): string;
static displayMetrics(): DisplayMetrics;
static isPortrait(): boolean;
static isTablet(): boolean;

@@ -28,0 +30,0 @@ static is24Hour(): boolean;

@@ -6,2 +6,3 @@ "use strict";

var network_provider_1 = require("./network-provider");
var utility_1 = require("./utility");
function staticDecorator() {

@@ -11,2 +12,3 @@ return function (constructor) { };

exports.staticDecorator = staticDecorator;
var ICE_CREAM_SANDWICH = 14;
var JELLY_BEAN_MR1 = 17;

@@ -279,2 +281,42 @@ var JELLY_BEAN_MR2 = 18;

};
DeviceInfo.displayMetrics = function () {
var ctx = application_1.android.context;
var wm = ctx.getSystemService(Context.WINDOW_SERVICE);
var point = new android.graphics.Point();
if (android.os.Build.VERSION.SDK_INT >= JELLY_BEAN_MR1) {
wm.getDefaultDisplay().getRealSize(point);
}
else if (android.os.Build.VERSION.SDK_INT >= ICE_CREAM_SANDWICH) {
try {
var getRawWidth = android.view.Display.class.getMethod("getRawWidth", []);
point.x = getRawWidth.invoke(wm.getDefaultDisplay(), []);
var getRawHeight = android.view.Display.class.getMethod("getRawHeight", []);
point.y = getRawHeight.invoke(wm.getDefaultDisplay(), []);
}
catch (e) {
wm.getDefaultDisplay().getSize(point);
}
}
else {
wm.getDefaultDisplay().getSize(point);
}
var displayMetrics = new android.util.DisplayMetrics();
wm.getDefaultDisplay().getRealMetrics(displayMetrics);
var horizontal = Math.pow(point.x / displayMetrics.xdpi, 2);
var vertical = Math.pow(point.y / displayMetrics.ydpi, 2);
var diagonalInInches = Math.sqrt(horizontal + vertical);
var pixelPerInch = Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2)) / diagonalInInches;
var dm = {};
dm.scale = utility_1.round(displayMetrics.scaledDensity, 0);
dm.widthInPixels = point.x;
dm.heightInPixels = point.y;
dm.diagonalInInches = utility_1.round(diagonalInInches, 1);
dm.pixelPerInch = utility_1.round(pixelPerInch, 0);
return dm;
};
DeviceInfo.isPortrait = function () {
var Configuration = android.content.res.Configuration;
var ctx = application_1.android.context;
return ctx.getResources().getConfiguration().orientation === Configuration.ORIENTATION_PORTRAIT;
};
DeviceInfo.isTablet = function () {

@@ -281,0 +323,0 @@ var Configuration = android.content.res.Configuration;

@@ -14,2 +14,9 @@ import { RadioAccessTechnology, WCTGeneration } from "./index.d";

}
export interface DisplayMetrics {
scale: number;
pixelPerInch: number;
widthInPixels: number;
heightInPixels: number;
diagonalInInches: number;
}
export interface StorageVolume {

@@ -48,2 +55,4 @@ path: string;

wifiSSID(): string;
displayMetrics(): DisplayMetrics;
isPortrait(): boolean;
isTablet(): boolean;

@@ -50,0 +59,0 @@ is24Hour(): boolean;

@@ -1,2 +0,2 @@

import { Carrier, StorageVolume } from './deviceinfo.interface';
import { Carrier, DisplayMetrics, StorageVolume } from './deviceinfo.interface';
export declare function staticDecorator<T>(): (constructor: T) => void;

@@ -28,2 +28,4 @@ export declare class DeviceInfo {

static wifiSSID(): string;
static displayMetrics(): DisplayMetrics;
static isPortrait(): boolean;
static isTablet(): boolean;

@@ -30,0 +32,0 @@ static is24Hour(): boolean;

@@ -5,2 +5,3 @@ "use strict";

var network_provider_1 = require("./network-provider");
var utility_1 = require("./utility");
function staticDecorator() {

@@ -167,3 +168,3 @@ return function (constructor) { };

var interfaces = CNCopySupportedInterfaces();
if (interfaces.count) {
if (interfaces && interfaces.count) {
var interfaceName = CFArrayGetValueAtIndex(interfaces, 0);

@@ -177,2 +178,29 @@ var dict = CNCopyCurrentNetworkInfo(interfaceName);

};
DeviceInfo.displayMetrics = function () {
var nativeScale = UIScreen.mainScreen.nativeScale;
var pixelPerInch = 0.0;
if (UIDevice.currentDevice.userInterfaceIdiom === 0) {
pixelPerInch = 163 * nativeScale;
}
else if (UIDevice.currentDevice.userInterfaceIdiom === 1) {
pixelPerInch = 132 * nativeScale;
}
else {
pixelPerInch = 160 * nativeScale;
}
var dm = {};
dm.scale = nativeScale;
dm.pixelPerInch = pixelPerInch;
dm.widthInPixels = UIScreen.mainScreen.bounds.size.width * nativeScale;
dm.heightInPixels = UIScreen.mainScreen.bounds.size.height * nativeScale;
var vertical = dm.heightInPixels / pixelPerInch;
var horizontal = dm.widthInPixels / pixelPerInch;
var diagnoalInInches = Math.sqrt(Math.pow(horizontal, 2) + Math.pow(vertical, 2));
dm.diagonalInInches = utility_1.round(diagnoalInInches, 1);
return dm;
};
DeviceInfo.isPortrait = function () {
return UIDevice.currentDevice.orientation === 1 ||
UIDevice.currentDevice.orientation === 2;
};
DeviceInfo.isTablet = function () {

@@ -179,0 +207,0 @@ return UIDevice.currentDevice.userInterfaceIdiom === 1;

@@ -1,2 +0,2 @@

import { Carrier, StorageVolume } from './deviceinfo.interface';
import { Carrier, StorageVolume, DisplayMetrics } from './deviceinfo.interface';

@@ -54,2 +54,4 @@ export const enum RadioAccessTechnology {

static wifiSSID(): string;
static displayMetrics(): DisplayMetrics;
static isPortrait(): boolean;
static isTablet(): boolean;

@@ -56,0 +58,0 @@ static is24Hour(): boolean;

{
"name": "nativescript-dna-deviceinfo",
"version": "2.2.0",
"version": "2.3.0",
"description": "NativeScript plugin to acquire device information.",

@@ -5,0 +5,0 @@ "main": "deviceinfo",

@@ -8,26 +8,5 @@

The plugin offers cross-platform, utility, APIs to retrieve or query device-related information. The utility APIs are available for iOS and Android platforms.
## Features
- Cross-platform APIs for Android and iOS to retrieve or query device related information.
- Offers APIs to obtain device related info.
## Changelogs:
- 1.0.0: First release.
- 1.0.1: Minor document correction.
- 1.1.0: New APIs related to battery charging status and its charge level.
- 1.1.1: Updated document.
- 1.2.0: Added an API to retrieve Network Providers, Carriers, related information.
- 1.2.1: Removed unwanted dependencies.
- 1.3.0: Added externalStoragePaths API. Fixed crashes and compatibility issues with the Android platform.
- 1.4.0: Added storageVolumeInfo API.
- 2.0.0: Changed APIs name for storageVolumes & cellularServiceProviders.
- 2.1.0: Added an API to get service set identifier(SSID) of a wireless local area network (WLAN).
- 2.1.1: The documentation is updated.
- 2.1.2: Added the package nativescript-custom-entitlements to dev dependencies to the demo app.
- 2.1.3: Adjusted the license from Apache-2.0 to MIT.
- 2.2.0: Added an API to get a status of Bluetooth.
## Installation

@@ -239,3 +218,3 @@

Below is **StorageVolume** interface:
Below is the **StorageVolume** interface:

@@ -295,2 +274,32 @@ ```javascript

### - displayMetrics
Returns *DisplayMetrics* of a device.
```javascript
DeviceInfo.displayMetrics();
```
Below is the **DisplayMetrics** interface:
```javascript
export interface DisplayMetrics {
scale: number;
pixelPerInch: number;
widthInPixels: number;
heightInPixels: number;
diagonalInInches: number;
}
```
- Notes for Android users:
* A word of caution: *pixelPerInch* and *diagonalInInches* may be inaccurate and not matches to the device specs.
### - isPortrait
Returns 'true' if a device is in portrait mode, otherwise 'false'.
```javascript
DeviceInfo.isPortrait();
```
### - isTablet

@@ -370,4 +379,6 @@

console.log("Storage paths: ", DeviceInfo.externalStoragePaths());
console.log("Storage Volume Info: ", DeviceInfo.storageVolumes());
console.log("Storage volume info: ", DeviceInfo.storageVolumes());
console.log("WiFi SSID: ", DeviceInfo.wifiSSID());
console.log("Display metrics: ", DeviceInfo.displayMetrics());
console.log("Is portrait orientation: ", DeviceInfo.isPortrait());
console.log("Is tablet: ", DeviceInfo.isTablet());

@@ -395,4 +406,23 @@ console.log("Is 24 hour: ", DeviceInfo.is24Hour());

## Changelogs:
- 1.0.0: First release.
- 1.0.1: Minor document correction.
- 1.1.0: New APIs related to battery charging status and its charge level.
- 1.1.1: Updated document.
- 1.2.0: Added an API to retrieve Network Providers, Carriers, related information.
- 1.2.1: Removed unwanted dependencies.
- 1.3.0: Added externalStoragePaths API. Fixed crashes and compatibility issues with the Android platform.
- 1.4.0: Added storageVolumeInfo API.
- 2.0.0: Changed APIs name for storageVolumes & cellularServiceProviders.
- 2.1.0: Added an API to get service set identifier(SSID) of a wireless local area network (WLAN).
- 2.1.1: The documentation is updated.
- 2.1.2: Added the package nativescript-custom-entitlements to dev dependencies to the demo app.
- 2.1.3: Adjusted the license from Apache-2.0 to MIT.
- 2.2.0: Added an API to get a status of Bluetooth.
- 2.3.0: Added APIs to get device orientation and display metrics.
## License
MIT license (see LICENSE file)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc