{ "id": "169899", "key": "TIMOB-25386", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": null, "resolutiondate": null, "created": "2017-09-26T08:12:01.000+0000", "priority": null, "labels": [], "versions": [], "issuelinks": [], "assignee": null, "updated": "2018-02-28T19:55:27.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "{code:java}\r\nTi.Platform.displayCaps.density: xhigh\r\nTi.Platform.displayCaps.dpi: 320\r\nTi.Platform.displayCaps.platformHeight: 1200\r\n\r\nrequire(\"alloy/measurement\").pxToDP(Ti.Platform.displayCaps.platformHeight) // 400 wrong\r\nTi.Platform.displayCaps.platformHeight / (Ti.Platform.displayCaps.dpi / 160) // 600 right\r\n{code}", "attachment": [], "flagged": false, "summary": "Android: Alloy/Measurement pxToDP returns wrong result", "creator": { "name": "zozo4kin", "key": "zozo4kin", "displayName": "Zakhar Zhuravlev", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "zozo4kin", "key": "zozo4kin", "displayName": "Zakhar Zhuravlev", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "Lg Stylus 3, android 7.0\r\nTi SDK 6.1.1 and 6.2.2", "comment": { "comments": [ { "id": "428525", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "Here is the method implementation:\r\n{code:js}\r\n\r\n/**\r\n * @method pxToDP\r\n * Converts a screen pixel value to density-independent pixels.\r\n * @param {Number} val Value in screen pixels.\r\n * @return {Number} Converted value in density-independent pixels.\r\n */\r\nexports.pxToDP = function (val) {\r\n\tif (OS_ANDROID) {\r\n\t\treturn val / dpi * 160;\r\n\t} else if (OS_IOS) {\r\n\t\tswitch (density) {\r\n\t\t\tcase 'xhigh': return val / 3;\r\n\t\t\tcase 'high': return val / 2;\r\n\t\t\tdefault: return val;\r\n\t\t}\r\n\t} else {\r\n\t\treturn val;\r\n\t}\r\n};\r\n{code}\r\nLooks like it's missing the newer densities? A simple PR against [this file|https://github.com/appcelerator/alloy/blob/master/Alloy/builtins/measurement.js] should fix it.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2017-09-27T15:25:03.000+0000", "updated": "2017-09-27T15:25:03.000+0000" } ], "maxResults": 1, "total": 1, "startAt": 0 } } }