diff --git a/apps/tests/layouts/absolute-layout-tests.ts b/apps/tests/layouts/absolute-layout-tests.ts index 44d7eeacc..8c28fb3f6 100644 --- a/apps/tests/layouts/absolute-layout-tests.ts +++ b/apps/tests/layouts/absolute-layout-tests.ts @@ -56,15 +56,15 @@ export class AbsoluteLayoutTest extends testModule.UITest // # DockLayout @@ -37,8 +38,8 @@ export class DockLayoutTest extends testModule.UITest { public create(): DockLayout { let rootLayout = new DockLayout(); - rootLayout.height = 300; - rootLayout.width = 300; + rootLayout.height = layoutHelper.dp(300); + rootLayout.width = layoutHelper.dp(300); return rootLayout; } @@ -62,7 +63,7 @@ export class DockLayoutTest extends testModule.UITest { public test_dock_left() { var testBtn = new helper.MyButton(); - testBtn.width = 20; + testBtn.width = layoutHelper.dp(20); this.testView.stretchLastChild = false; this.testView.addChild(testBtn); @@ -73,7 +74,7 @@ export class DockLayoutTest extends testModule.UITest { public test_dock_right() { var testBtn = new helper.MyButton(); - testBtn.width = 20; + testBtn.width = layoutHelper.dp(20); dockModule.DockLayout.setDock(testBtn, enums.Dock.right); this.testView.stretchLastChild = false; this.testView.addChild(testBtn); @@ -85,7 +86,7 @@ export class DockLayoutTest extends testModule.UITest { public test_dock_top() { var testBtn = new helper.MyButton(); - testBtn.height = 20; + testBtn.height = layoutHelper.dp(20); dockModule.DockLayout.setDock(testBtn, enums.Dock.top); this.testView.stretchLastChild = false; this.testView.addChild(testBtn); @@ -97,7 +98,7 @@ export class DockLayoutTest extends testModule.UITest { public test_dock_button() { var testBtn = new helper.MyButton(); - testBtn.height = 20; + testBtn.height = layoutHelper.dp(20); dockModule.DockLayout.setDock(testBtn, enums.Dock.bottom); this.testView.stretchLastChild = false; this.testView.addChild(testBtn); @@ -118,21 +119,21 @@ export class DockLayoutTest extends testModule.UITest { public test_dock_left_top_righ_bottom_fill() { var testBtnLeft = new helper.MyButton(); - testBtnLeft.width = 20; + testBtnLeft.width = layoutHelper.dp(20); this.testView.addChild(testBtnLeft); var testBtnTop = new helper.MyButton(); - testBtnTop.height = 20; + testBtnTop.height = layoutHelper.dp(20); dockModule.DockLayout.setDock(testBtnTop, enums.Dock.top); this.testView.addChild(testBtnTop); var testBtnRight = new helper.MyButton(); - testBtnRight.width = 20; + testBtnRight.width = layoutHelper.dp(20); dockModule.DockLayout.setDock(testBtnRight, enums.Dock.right); this.testView.addChild(testBtnRight); var testBtnBottom = new helper.MyButton(); - testBtnBottom.height = 20; + testBtnBottom.height = layoutHelper.dp(20); dockModule.DockLayout.setDock(testBtnBottom, enums.Dock.bottom); this.testView.addChild(testBtnBottom); @@ -152,10 +153,10 @@ export class DockLayoutTest extends testModule.UITest { public test_padding() { var testBtn = new helper.MyButton(); this.testView.addChild(testBtn); - this.testView.paddingLeft = 10; - this.testView.paddingTop = 20; - this.testView.paddingRight = 30; - this.testView.paddingBottom = 40; + this.testView.paddingLeft = layoutHelper.dp(10); + this.testView.paddingTop = layoutHelper.dp(20); + this.testView.paddingRight = layoutHelper.dp(30); + this.testView.paddingBottom = layoutHelper.dp(40); this.waitUntilTestElementLayoutIsValid(); diff --git a/apps/tests/layouts/grid-layout-tests.ts b/apps/tests/layouts/grid-layout-tests.ts index bd2fb6a3e..6edc208c2 100644 --- a/apps/tests/layouts/grid-layout-tests.ts +++ b/apps/tests/layouts/grid-layout-tests.ts @@ -9,6 +9,7 @@ import utils = require("utils/utils"); import builder = require("ui/builder"); import enums = require("ui/enums"); import testModule = require("../ui-test"); +import layoutHelper = require("./layout-helper"); var DELTA = 1; @@ -61,12 +62,12 @@ export class GridLayoutTest extends testModule.UITest { this.testView.addRow(new layout.ItemSpec(1, layout.GridUnitType.star)); this.testView.addRow(new layout.ItemSpec(2, layout.GridUnitType.star)); - this.testView.addRow(new layout.ItemSpec(50, layout.GridUnitType.pixel)); + this.testView.addRow(new layout.ItemSpec(layoutHelper.dp(50), layout.GridUnitType.pixel)); this.testView.addRow(new layout.ItemSpec(50, layout.GridUnitType.auto)); this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star)); this.testView.addColumn(new layout.ItemSpec(2, layout.GridUnitType.star)); - this.testView.addColumn(new layout.ItemSpec(50, layout.GridUnitType.pixel)); + this.testView.addColumn(new layout.ItemSpec(layoutHelper.dp(50), layout.GridUnitType.pixel)); this.testView.addColumn(new layout.ItemSpec(50, layout.GridUnitType.auto)); for (var r = 0; r < 4; r++) { @@ -76,19 +77,19 @@ export class GridLayoutTest extends testModule.UITest { layout.GridLayout.setColumn(btn, c); layout.GridLayout.setRow(btn, r); if (c === 3) { - btn.width = 100; // Auto column should take 100px for this test. + btn.width = layoutHelper.dp(100); // Auto column should take 100px for this test. } if (r === 3) { - btn.height = 100; // Auto row should take 100px for this test. + btn.height = layoutHelper.dp(100); // Auto row should take 100px for this test. } this.testView.addChild(btn); } } - this.testView.width = 300; - this.testView.height = 300; + this.testView.width = layoutHelper.dp(300); + this.testView.height = layoutHelper.dp(300); if (wait) { this.waitUntilTestElementLayoutIsValid(); @@ -245,58 +246,55 @@ export class GridLayoutTest extends testModule.UITest { this.waitUntilTestElementLayoutIsValid(); TKUnit.assertTrue(btn.getMeasuredWidth() === this.testView.getMeasuredWidth()); + TKUnit.assertTrue(this.testView.getMeasuredWidth() < 50); } public test_measuredWidth_when_not_stretched_two_columns() { this.testView.horizontalAlignment = enums.HorizontalAlignment.center; - this.testView.addColumn(new layout.ItemSpec(80, layout.GridUnitType.pixel)); + this.testView.addColumn(new layout.ItemSpec(layoutHelper.dp(80), layout.GridUnitType.pixel)); this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star)); let btn = new Button(); btn.text = "A"; - btn.width = 100; + btn.width = layoutHelper.dp(100); MyGridLayout.setColumnSpan(btn, 2); this.testView.addChild(btn); this.waitUntilTestElementLayoutIsValid(); - var density = utils.layout.getDisplayDensity(); - var delta = Math.floor(density) !== density ? 2 : DELTA; var cols = this.testView.getColumns(); - TKUnit.assertAreClose(cols[0].actualLength, 80, delta); - TKUnit.assertAreClose(cols[1].actualLength, 20, delta); - TKUnit.assertAreClose(this.testView.getMeasuredWidth(), 100 * density, delta); + TKUnit.assertAreClose(cols[0].actualLength, 80, DELTA); + TKUnit.assertAreClose(cols[1].actualLength, 20, DELTA); + TKUnit.assertAreClose(this.testView.getMeasuredWidth(), 100, DELTA); } public test_measuredWidth_when_not_stretched_three_columns() { this.testView.horizontalAlignment = enums.HorizontalAlignment.center; - this.testView.addColumn(new layout.ItemSpec(80, layout.GridUnitType.pixel)); + this.testView.addColumn(new layout.ItemSpec(layoutHelper.dp(80), layout.GridUnitType.pixel)); this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star)); this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.auto)); for (let i = 1; i < 4; i++) { let btn = new Button(); btn.text = "A"; - btn.width = i * 20; + btn.width = layoutHelper.dp(i * 20); MyGridLayout.setColumn(btn, i - 1); this.testView.addChild(btn); } let btn = new Button(); btn.text = "B"; - btn.width = 100; + btn.width = layoutHelper.dp(100); MyGridLayout.setColumnSpan(btn, 3); this.testView.addChild(btn); this.waitUntilTestElementLayoutIsValid(); - var density = utils.layout.getDisplayDensity(); - var delta = Math.floor(density) !== density ? 2 : DELTA; var cols = this.testView.getColumns(); - TKUnit.assertAreClose(cols[0].actualLength, 80, delta); - TKUnit.assertAreClose(cols[1].actualLength, 40, delta); - TKUnit.assertAreClose(cols[2].actualLength, 60, delta); - TKUnit.assertAreClose(this.testView.getMeasuredWidth(), 180 * density, delta); + TKUnit.assertAreClose(cols[0].actualLength, 80, DELTA); + TKUnit.assertAreClose(cols[1].actualLength, 40, DELTA); + TKUnit.assertAreClose(cols[2].actualLength, 60, DELTA); + TKUnit.assertAreClose(this.testView.getMeasuredWidth(), 180, DELTA); } public test_getRows_shouldNotReturnNULL() { @@ -405,12 +403,10 @@ export class GridLayoutTest extends testModule.UITest { } } - var delta = 1.1; // Set to an overly high value to avoid failing on some emulators. - let measuredWidth = this.testView.getMeasuredWidth(); let measuredHeight = this.testView.getMeasuredHeight(); - TKUnit.assertAreClose(measuredWidth, maxWidth, delta, "GridLayout incorrect measured width"); - TKUnit.assertAreClose(measuredHeight, maxHeight, delta, "GridLayout incorrect measured height"); + TKUnit.assertAreClose(measuredWidth, maxWidth, DELTA, "GridLayout incorrect measured width"); + TKUnit.assertAreClose(measuredHeight, maxHeight, DELTA, "GridLayout incorrect measured height"); } public test_columnsActualWidth_isCorrect() { @@ -427,10 +423,10 @@ export class GridLayoutTest extends testModule.UITest { this.prepareGridLayout(true); var rows = this.testView.getRows(); - TKUnit.assertEqual(rows[0].actualLength, 50, "Star row should be 50px width"); - TKUnit.assertEqual(rows[1].actualLength, 100, "2*Star row should be 100px width"); - TKUnit.assertEqual(rows[2].actualLength, 50, "Absolute row should be 50px width"); - TKUnit.assertEqual(rows[3].actualLength, 100, "Auto row should be 100px width"); + TKUnit.assertEqual(rows[0].actualLength, layoutHelper.dip(50), "Star row should be 50px width"); + TKUnit.assertEqual(rows[1].actualLength, layoutHelper.dip(100), "2*Star row should be 100px width"); + TKUnit.assertEqual(rows[2].actualLength, layoutHelper.dip(50), "Absolute row should be 50px width"); + TKUnit.assertEqual(rows[3].actualLength, layoutHelper.dip(100), "Auto row should be 100px width"); } public test_Measure_and_Layout_Children_withCorrect_size() { @@ -440,8 +436,6 @@ export class GridLayoutTest extends testModule.UITest { var rows = this.testView.getRows(); var cols = this.testView.getColumns(); var i = 0; - var density = utils.layout.getDisplayDensity(); - var delta = Math.floor(density) !== density ? 1.1 : DELTA; for (var r = 0; r < 4; r++) { @@ -453,31 +447,28 @@ export class GridLayoutTest extends testModule.UITest { var h = r % 2 === 0 ? 50 : 100; var w = c % 2 === 0 ? 50 : 100; - h = Math.round(h * density); - w = Math.round(w * density); - if (row.isAuto) { - TKUnit.assertAreClose(btn.layoutHeight, btn.getMeasuredHeight(), delta, "Auto rows should layout with measured height"); + TKUnit.assertAreClose(btn.layoutHeight, btn.getMeasuredHeight(), DELTA, "Auto rows should layout with measured height"); } else if (row.isAbsolute) { - TKUnit.assertAreClose(btn.measureHeight, h, delta, "Absolute rows should measure with specific height"); - TKUnit.assertAreClose(btn.layoutHeight, h, delta, "Absolute rows should layout with specific height"); + TKUnit.assertAreClose(btn.measureHeight, h, DELTA, "Absolute rows should measure with specific height"); + TKUnit.assertAreClose(btn.layoutHeight, h, DELTA, "Absolute rows should layout with specific height"); } else { - TKUnit.assertAreClose(btn.measureHeight, h, delta, "Star rows should measure with specific height"); - TKUnit.assertAreClose(btn.layoutHeight, h, delta, "Star rows should layout with exact length"); + TKUnit.assertAreClose(btn.measureHeight, h, DELTA, "Star rows should measure with specific height"); + TKUnit.assertAreClose(btn.layoutHeight, h, DELTA, "Star rows should layout with exact length"); } if (col.isAuto) { - TKUnit.assertAreClose(btn.layoutWidth, btn.getMeasuredWidth(), delta, "Auto columns should layout with measured width"); + TKUnit.assertAreClose(btn.layoutWidth, btn.getMeasuredWidth(), DELTA, "Auto columns should layout with measured width"); } else if (col.isAbsolute) { - TKUnit.assertAreClose(btn.measureWidth, w, delta, "Absolute columns should measure with specific width"); - TKUnit.assertAreClose(btn.layoutWidth, w, delta, "Absolute columns should layout with specific width"); + TKUnit.assertAreClose(btn.measureWidth, w, DELTA, "Absolute columns should measure with specific width"); + TKUnit.assertAreClose(btn.layoutWidth, w, DELTA, "Absolute columns should layout with specific width"); } else { - TKUnit.assertAreClose(btn.measureWidth, w, delta, "Star columns should measure with specific width"); - TKUnit.assertAreClose(btn.layoutWidth, w, delta, "Star columns should layout with exact length"); + TKUnit.assertAreClose(btn.measureWidth, w, DELTA, "Star columns should measure with specific width"); + TKUnit.assertAreClose(btn.layoutWidth, w, DELTA, "Star columns should layout with exact length"); } } } @@ -485,7 +476,7 @@ export class GridLayoutTest extends testModule.UITest { public test_ColumnWidth_when_4stars_and_width_110() { - this.testView.width = 110; + this.testView.width = layoutHelper.dp(110); this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star)); this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star)); this.testView.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star)); @@ -495,34 +486,28 @@ export class GridLayoutTest extends testModule.UITest { var cols = this.testView.getColumns(); - var density = utils.layout.getDisplayDensity(); - var delta = Math.floor(density) !== density ? 1.1 : DELTA; - - TKUnit.assertAreClose(cols[0].actualLength, 28, delta, "Column[0] actual length should be 28"); - TKUnit.assertAreClose(cols[1].actualLength, 27, delta, "Column[1] actual length should be 27"); - TKUnit.assertAreClose(cols[2].actualLength, 28, delta, "Column[2] actual length should be 28"); - TKUnit.assertAreClose(cols[3].actualLength, 27, delta, "Column[3] actual length should be 27"); + TKUnit.assertAreClose(cols[0].actualLength, layoutHelper.dip(28), DELTA, "Column[0] actual length should be 28"); + TKUnit.assertAreClose(cols[1].actualLength, layoutHelper.dip(27), DELTA, "Column[1] actual length should be 27"); + TKUnit.assertAreClose(cols[2].actualLength, layoutHelper.dip(28), DELTA, "Column[2] actual length should be 28"); + TKUnit.assertAreClose(cols[3].actualLength, layoutHelper.dip(27), DELTA, "Column[3] actual length should be 27"); } public test_margins_and_verticalAlignment_center() { - this.testView.height = 200; - this.testView.width = 200; + this.testView.height = layoutHelper.dp(200); + this.testView.width = layoutHelper.dp(200); var btn = new helper.MyButton(); btn.text = "btn"; - btn.height = 100; - btn.width = 100; - btn.marginBottom = 50; - btn.marginRight = 50; + btn.height = layoutHelper.dp(100); + btn.width = layoutHelper.dp(100); + btn.marginBottom = layoutHelper.dp(50); + btn.marginRight = layoutHelper.dp(50); this.testView.addChild(btn); this.waitUntilTestElementLayoutIsValid(); - var density = utils.layout.getDisplayDensity(); - var delta = Math.floor(density) !== density ? 1.1 : DELTA; - - TKUnit.assertAreClose(btn.layoutTop, 25 * density, delta, "vertical margins"); - TKUnit.assertAreClose(btn.layoutLeft, 25 * density, delta, "horizontal margins"); + TKUnit.assertAreClose(btn.layoutTop, 25, DELTA, "vertical margins"); + TKUnit.assertAreClose(btn.layoutLeft, 25, DELTA, "horizontal margins"); } public test_set_columns_in_XML() { @@ -564,13 +549,13 @@ export class GridLayoutTest extends testModule.UITest { } public test_padding() { - this.testView.paddingLeft = 10; - this.testView.paddingTop = 20; - this.testView.paddingRight = 30; - this.testView.paddingBottom = 40; + this.testView.paddingLeft = layoutHelper.dp(10); + this.testView.paddingTop = layoutHelper.dp(20); + this.testView.paddingRight = layoutHelper.dp(30); + this.testView.paddingBottom = layoutHelper.dp(40); - this.testView.width = 300; - this.testView.height = 300; + this.testView.width = layoutHelper.dp(300); + this.testView.height = layoutHelper.dp(300); var btn = new helper.MyButton(); this.testView.addChild(btn); diff --git a/apps/tests/layouts/layout-helper.android.ts b/apps/tests/layouts/layout-helper.android.ts index 684d9af55..4611ba825 100644 --- a/apps/tests/layouts/layout-helper.android.ts +++ b/apps/tests/layouts/layout-helper.android.ts @@ -155,28 +155,25 @@ export class MyStackLayout extends StackLayout implements def.MyStackLayout { } export function assertMeasure(btn: MyButton, width: number, height: number, name?: string) { - var density = utils.layout.getDisplayDensity(); - - var delta = Math.floor(density) !== density ? 1.1 : DELTA; name = name ? "[" + name + "]" : ""; - TKUnit.assertAreClose(Math.floor(btn.measureWidth / density), width, delta, name + "width"); - TKUnit.assertAreClose(Math.floor(btn.measureHeight / density), height, delta, name + "height"); + TKUnit.assertAreClose(btn.measureWidth, width, DELTA, name + "width"); + TKUnit.assertAreClose(btn.measureHeight, height, DELTA, name + "height"); } export function assertLayout(btn: MyButton, left: number, top: number, width: number, height: number, name?: string): void { - var density = utils.layout.getDisplayDensity(); - - var delta = Math.floor(density) !== density ? 1.1 : DELTA; name = name ? "[" + name + "]" : ""; - TKUnit.assertAreClose(Math.floor(btn.layoutLeft / density), left, delta, name + "left"); - TKUnit.assertAreClose(Math.floor(btn.layoutTop / density), top, delta, name + "top"); - TKUnit.assertAreClose(Math.floor(btn.layoutWidth / density), width, delta, name + "width"); - TKUnit.assertAreClose(Math.floor(btn.layoutHeight / density), height, delta, name + "height"); + TKUnit.assertAreClose(btn.layoutLeft, left, DELTA, name + "left"); + TKUnit.assertAreClose(btn.layoutTop, top, DELTA, name + "top"); + TKUnit.assertAreClose(btn.layoutWidth, width, DELTA, name + "width"); + TKUnit.assertAreClose(btn.layoutHeight, height, DELTA, name + "height"); +} + +export function dp(value: number): number { + return utils.layout.toDevicePixels(value); } export function dip(value: number): number { - var density = utils.layout.getDisplayDensity(); - return Math.floor(value * density); -} + return utils.layout.toDeviceIndependentPixels(value); +} \ No newline at end of file diff --git a/apps/tests/layouts/layout-helper.d.ts b/apps/tests/layouts/layout-helper.d.ts index 606fe7a95..17ef67905 100644 --- a/apps/tests/layouts/layout-helper.d.ts +++ b/apps/tests/layouts/layout-helper.d.ts @@ -28,4 +28,5 @@ export class MyStackLayout extends StackLayout { export function assertMeasure(btn: MyButton, width: number, height: number, name?: string); export function assertLayout(btn: MyButton, left: number, top: number, width: number, height: number, name?: string): void; -export function dip(value: number): number; \ No newline at end of file +export function dip(value: number): number; +export function dp(value: number): number; \ No newline at end of file diff --git a/apps/tests/layouts/layout-helper.ios.ts b/apps/tests/layouts/layout-helper.ios.ts index 748cc89e5..546683219 100644 --- a/apps/tests/layouts/layout-helper.ios.ts +++ b/apps/tests/layouts/layout-helper.ios.ts @@ -119,7 +119,10 @@ export function assertLayout(btn: MyButton, left: number, top: number, width: nu TKUnit.assertAreClose(Math.floor(btn.layoutHeight / density), height, delta, name + "height"); } +export function dp(value: number): number { + return utils.layout.toDevicePixels(value); +} + export function dip(value: number): number { - var density = utils.layout.getDisplayDensity(); - return Math.floor(value * density); + return utils.layout.toDeviceIndependentPixels(value); } \ No newline at end of file diff --git a/apps/tests/layouts/stack-layout-tests.ts b/apps/tests/layouts/stack-layout-tests.ts index c6092e115..8ec4bab73 100644 --- a/apps/tests/layouts/stack-layout-tests.ts +++ b/apps/tests/layouts/stack-layout-tests.ts @@ -7,6 +7,7 @@ import navHelper = require("../ui/helper"); import enums = require("ui/enums"); import utils = require("utils/utils"); import testModule = require("../ui-test"); +import layoutHelper = require("./layout-helper"); export class StackLayoutTest extends testModule.UITest { @@ -38,7 +39,7 @@ export class StackLayoutTest extends testModule.UITest { this.waitUntilTestElementLayoutIsValid(); var arrangeCount = this.rootLayout.arrangeCount; - TKUnit.assert(this.rootLayout.orientation === enums.Orientation.vertical, "Default orientation should be Vertical."); + TKUnit.assertEqual(this.rootLayout.orientation, enums.Orientation.vertical, "Default orientation should be Vertical."); this.rootLayout.orientation = enums.Orientation.horizontal; this.waitUntilTestElementLayoutIsValid(); @@ -51,8 +52,8 @@ export class StackLayoutTest extends testModule.UITest { this.waitUntilTestElementLayoutIsValid(); TKUnit.assertEqual(this.rootLayout.orientation, enums.Orientation.vertical, "StackLayout should be vertical."); - TKUnit.assert(this.rootLayout.measured, "Layout should be measured."); - TKUnit.assert(this.rootLayout.arranged, "Layout should be arranged."); + TKUnit.assertTrue(this.rootLayout.measured, "Layout should be measured."); + TKUnit.assertTrue(this.rootLayout.arranged, "Layout should be arranged."); var specs = this.btn1._getCurrentMeasureSpecs(); @@ -97,16 +98,16 @@ export class StackLayoutTest extends testModule.UITest { } public test_Padding_Vertical() { - this.rootLayout.width = 300; - this.rootLayout.height = 300; + this.rootLayout.width = layoutHelper.dp(300); + this.rootLayout.height = layoutHelper.dp(300); - this.rootLayout.paddingLeft = 10; - this.rootLayout.paddingTop = 20; - this.rootLayout.paddingRight = 30; - this.rootLayout.paddingBottom = 40; + this.rootLayout.paddingLeft = layoutHelper.dp(10); + this.rootLayout.paddingTop = layoutHelper.dp(20); + this.rootLayout.paddingRight = layoutHelper.dp(30); + this.rootLayout.paddingBottom = layoutHelper.dp(40); - this.btn1.height = 50; - this.btn2.height = 50; + this.btn1.height = layoutHelper.dp(50); + this.btn2.height = layoutHelper.dp(50); this.waitUntilTestElementLayoutIsValid(); @@ -118,17 +119,17 @@ export class StackLayoutTest extends testModule.UITest { } public test_Padding_Horizontal() { - this.rootLayout.width = 300; - this.rootLayout.height = 300; + this.rootLayout.width = layoutHelper.dp(300); + this.rootLayout.height = layoutHelper.dp(300); this.rootLayout.orientation = enums.Orientation.horizontal; - this.rootLayout.paddingLeft = 10; - this.rootLayout.paddingTop = 20; - this.rootLayout.paddingRight = 30; - this.rootLayout.paddingBottom = 40; + this.rootLayout.paddingLeft = layoutHelper.dp(10); + this.rootLayout.paddingTop = layoutHelper.dp(20); + this.rootLayout.paddingRight = layoutHelper.dp(30); + this.rootLayout.paddingBottom = layoutHelper.dp(40); - this.btn1.width = 50; - this.btn2.width = 50; + this.btn1.width = layoutHelper.dp(50); + this.btn2.width = layoutHelper.dp(50); this.waitUntilTestElementLayoutIsValid(); diff --git a/apps/tests/layouts/wrap-layout-tests.ts b/apps/tests/layouts/wrap-layout-tests.ts index b178ee656..23f042e13 100644 --- a/apps/tests/layouts/wrap-layout-tests.ts +++ b/apps/tests/layouts/wrap-layout-tests.ts @@ -41,8 +41,8 @@ export class WrapLayoutTest extends testModule.UITest - wrapLayout.width = 200; - wrapLayout.height = 200; + wrapLayout.width = layoutHelper.dp(200); + wrapLayout.height = layoutHelper.dp(200); var label; var i; @@ -51,8 +51,8 @@ export class WrapLayoutTest extends testModule.UITest { + var hashSet = new java.util.HashSet(); if ("undefined" !== typeof str) { for (var element in str) { hashSet.add('' + str[element]); diff --git a/utils/utils.d.ts b/utils/utils.d.ts index a6b93a2bd..2799cedf6 100644 --- a/utils/utils.d.ts +++ b/utils/utils.d.ts @@ -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; } /** diff --git a/utils/utils.ios.ts b/utils/utils.ios.ts index 3647b372d..8c61ef83c 100644 --- a/utils/utils.ios.ts +++ b/utils/utils.ios.ts @@ -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(str); } - export function nsArrayToJSArray(a: any): string[] { + export function nsArrayToJSArray(a: NSArray): Array { 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)); } }