Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2052] Google Nexus 7 tablet returns wrong dpi, density, height and width.

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionNeeds more info
Resolution Date2013-06-04T20:14:22.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
LabelsAndroid, Nexus-7
ReporterVatsal
AssigneeEric Wieber
Created2013-05-07T10:25:04.000+0000
Updated2016-03-08T07:41:00.000+0000

Description

On Google Nexus 7 16GB WiFi, Titanium API returns wrong dpi, density, height and width. Log is pasted below. 05-07 15:24:11.320: I/TiAPI(7320): calculatedDpi : 160 05-07 15:24:11.320: I/TiAPI(7320): Ti.Platform.displayCaps.density : medium 05-07 15:24:11.320: I/TiAPI(7320): platformHeight : 905 05-07 15:24:11.320: I/TiAPI(7320): platformWidth : 601 Nexus 7 has following properties : dpi : 216 density : high height : 1280 width : 800
var win = Ti.UI.createWindow({
    backgroundColor : "#FFF"
 });

win.open();

alert('Ti.Platform.displayCaps.density: ' + Ti.Platform.displayCaps.density);
alert('Ti.Platform.displayCaps.dpi: ' + Ti.Platform.displayCaps.dpi);
alert('Ti.Platform.displayCaps.platformHeight: ' + Ti.Platform.displayCaps.platformHeight);
alert('Ti.Platform.displayCaps.platformWidth: ' + Ti.Platform.displayCaps.platformWidth);
if(Ti.Platform.osname === 'android'){
 alert('Ti.Platform.displayCaps.xdpi: ' + Ti.Platform.displayCaps.xdpi);
  alert('Ti.Platform.displayCaps.ydpi: ' + Ti.Platform.displayCaps.ydpi);
  alert('Ti.Platform.displayCaps.logicalDensityFactor: ' + Ti.Platform.displayCaps.logicalDensityFactor);
}
source : https://play.google.com/store/devices/details?id=nexus_7_16gb&feature=device-featured#?t=W251bGwsMSwxLDIwMiwibnVsbC13ZWJfaG9tZV81MDAwMDA1X25leHVzSU5fZGV2aWNlc19JTl9fNTAwMDAwNV9uZXh1c0lOXzFfcHJvbW9fMTM2NzYyNDkxOTkzMSJd

Comments

  1. Carter Lathrop 2013-06-04

    Hello Vatsal, I have tested the code above on a Galaxy S3 which provided all the correct values for platform height, dpie, width and density. As I do not have a nexus 7 would you do me a favor and run the code provided above in the description and take screenshots to show the actual values? This proves validity to the claim without having me to reproduce the bug myself. Thanks for your cooperation. Regards, Carter
  2. Eric Wieber 2013-12-16

    Hi Vatsal, According to Dianne Hackborn, an Android framework engineer: "They need to be set by the manufacturer (there is no way for the platform to know what they are), and as of today they are just not consistently set correctly across devices, and because nothing in the platform relies on them it is easy for devices to have them set incorrectly." The Titanium DPI calls are just calling the underlying context.getResources().getDisplayMetrics().density. These values look to be set elsewhere. You may be able to get correct values by updating your Android SDK to a higher or to the latest version. Could you please try that? Seeing as we have not heard from you since June I will be closing this ticket, but please feel free to re-open it or to comment here if you have any additional information or questions. Thanks!

JSON Source