mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Stabilizing layout tests
This commit is contained in:
committed by
Hristo Hristov
parent
1757eb7092
commit
c2cb4a8f61
@@ -28,6 +28,14 @@ export module layout {
|
||||
return (size & ~MODE_MASK) | (mode & MODE_MASK);
|
||||
}
|
||||
|
||||
export function getDisplayMetrics(): android.util.DisplayMetrics {
|
||||
if (!metrics) {
|
||||
metrics = ad.getApplicationContext().getResources().getDisplayMetrics();
|
||||
}
|
||||
|
||||
return metrics;
|
||||
}
|
||||
|
||||
export function getDisplayDensity(): number {
|
||||
if (density === -1) {
|
||||
density = getDisplayMetrics().density;
|
||||
@@ -36,12 +44,12 @@ export module layout {
|
||||
return density;
|
||||
}
|
||||
|
||||
function getDisplayMetrics(): android.util.DisplayMetrics {
|
||||
if (!metrics) {
|
||||
metrics = ad.getApplicationContext().getResources().getDisplayMetrics();
|
||||
}
|
||||
export function toDevicePixels(value: number): number {
|
||||
return value * getDisplayDensity();
|
||||
}
|
||||
|
||||
return metrics;
|
||||
export function toDeviceIndependentPixels(value: number): number {
|
||||
return value / getDisplayDensity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,8 +82,8 @@ export module ad {
|
||||
}
|
||||
|
||||
export module collections {
|
||||
export function stringArrayToStringSet(str: string[]): any {
|
||||
var hashSet = new java.util.HashSet();
|
||||
export function stringArrayToStringSet(str: string[]): java.util.HashSet<string> {
|
||||
var hashSet = new java.util.HashSet<string>();
|
||||
if ("undefined" !== typeof str) {
|
||||
for (var element in str) {
|
||||
hashSet.add('' + str[element]);
|
||||
|
||||
10
utils/utils.d.ts
vendored
10
utils/utils.d.ts
vendored
@@ -50,6 +50,16 @@
|
||||
* Gets display density for the current device.
|
||||
*/
|
||||
export function getDisplayDensity(): number;
|
||||
/**
|
||||
* Convert value to device pixels.
|
||||
* @param value - The pixel to convert.
|
||||
*/
|
||||
export function toDevicePixels(value: number): number;
|
||||
/**
|
||||
* Convert value to device independent pixels.
|
||||
* @param value - The pixel to convert.
|
||||
*/
|
||||
export function toDeviceIndependentPixels(value: number): number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,24 +18,27 @@ export module layout {
|
||||
export function getDisplayDensity(): number {
|
||||
return 1;
|
||||
}
|
||||
|
||||
export function toDevicePixels(value: number): number {
|
||||
return value * getDisplayDensity();
|
||||
}
|
||||
|
||||
export function toDeviceIndependentPixels(value: number): number {
|
||||
return value / getDisplayDensity();
|
||||
}
|
||||
}
|
||||
|
||||
export module ios {
|
||||
export module collections {
|
||||
export function jsArrayToNSArray(str: string[]): any {
|
||||
var arr = new NSMutableArray();
|
||||
if ("undefined" !== typeof str) {
|
||||
for (var element in str) {
|
||||
arr.addObject(str[element]);
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
export function jsArrayToNSArray(str: string[]): NSArray {
|
||||
return NSArray.arrayWithArray(<any>str);
|
||||
}
|
||||
|
||||
export function nsArrayToJSArray(a: any): string[] {
|
||||
export function nsArrayToJSArray(a: NSArray): Array<Object> {
|
||||
var arr = [];
|
||||
if ("undefined" !== typeof a) {
|
||||
for (var i = 0; i < a.count; i++) {
|
||||
let count = a.count;
|
||||
for (let i = 0; i < count; i++) {
|
||||
arr.push(a.objectAtIndex(i));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user