Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7953] Android: Device is returning platformWidth and platformHeight values in dp

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionWon't Fix
Resolution Date2012-03-13T09:56:32.000+0000
Affected Version/sRelease 1.8.1, Release 1.8.2
Fix Version/sn/a
ComponentsAndroid
LabelsParity
ReporterNikhil Sharma
AssigneeHieu Pham
Created2012-03-09T17:42:26.000+0000
Updated2017-03-30T20:41:27.000+0000

Description

After setting the resolution of the Android Virtual Device to 480x800, the emulator is returning incorrect platformHeight and platformWidth.

Expected Results : 320x533

The value that its returning is 480x800

Repro Steps

1. Launch the Android AVD Manager by clicking its icon in the Titanium Studio toolbar 2. Select the emulator. 3. Click the 'Start' button. It opens the 'Launch Options' dialog 4. Check the 'Scale display to real size' checkbox. It enables the 'Screen Size' and 'Monitor dpi' options in the middle 5. Click the '?' button right to the 'Monitor dpi' field. It pops up the 'Monitor Density' dialog and enter dpi value 240. 6. Set your current resolution as 480x800. Then click 'OK' button. 7. Launch the emulator from the AVD Manager 8. Go back to Titanium Studio and 'Launch' your app again. It will load into the running emulator. 9. Run the below code and check the values in the console. Log file is also attached.

In android device

Repro Steps

1. Run the below code. 2. In the console the resolution of the screen (pixels) is returned but it should return the values in dp.
var win = Ti.UI.createWindow({ 
	backgroundColor: '#fff'});
	Ti.API.info (Ti.Platform.displayCaps.platformWidth);
	Ti.API.info(Ti.Platform.displayCaps.platformHeight);
win.open();

Attachments

FileDateSize
log.txt2012-03-09T17:42:26.000+0000760

Comments

  1. Hieu Pham 2012-03-12

    This looks like expected behavior given sample code...
  2. Hieu Pham 2012-03-12

    This is expected behavior. getWidth()/Height() will return pixels, not dp. You can use the formula px = dp * (dpi / 160) to convert to dp. DisplayCaps.getDpi() will give you dpi of device/emulator. Closing as invalid.
  3. Hieu Pham 2012-03-13

    Had a brief discussion regarding the behavior. This is expected, as DIP is the system unit on iOS and PX is the system unit on Android. platformWidth/platformHeight should be seen as system units. Closing as won't fix.
  4. Jason Priebe 2012-03-16

    I have spent a couple of months coding in Ti, and I've been reading a LOT of documentation. I never *once* have seen that iOS and Android have different system units. Please document this thoroughly, both in the guides and the API docs. This is a *fundamental* issue for building mobile UIs. A less determined developer than I would have given up and dropped Ti entirely with such a poorly documented API. In fact, if I had wrestled with these UI issues earlier in my proof-of-concept, I would probably not be a paying customer of Appcelerator.
  5. Shawn Lipscomb 2012-03-21

    I agree that this should be documented better, but the results of platformWidth and platformHeight are correct. On Android, they return the actual dimensions of the screen. By using dpi, one can calculate the effective dp units, and handle conversions both ways. On iPhone, while I disagree with the fact that both normal and retina-display devices return 320x480, I understand why that's being done. You can check if (Ti.Platform.displayCaps.density == 'high') on the iPhone and know that you have to multiply the results of platformWidth and platformHeight by 2 to get the actual screen dimensions. Sometimes you need the actual number of retina pixels, and sometimes you don't.
  6. Lee Morris 2017-03-30

    Closing ticket as "Won't Fix". There has been no update for a number of years. If there is any problem, please open a new ticket.

JSON Source