Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18305] Android: Default unit not respected in all cases

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
LabelsAndroid, dafaultunit
ReporterIvan Skugor
AssigneeUnknown
Created2014-11-06T15:37:19.000+0000
Updated2018-02-28T19:54:48.000+0000

Description

Hi there. When setting default value in tiapp.xml to density independent units (which you want to use because it makes calculations easier):
<property name="ti.ui.defaultunit" type="string">dip</property>
Titanium doesn't respect that value in all cases. I've noticed 2 cases, but there may be more:
var win = Ti.UI.createWindow();

Ti.API.info('Platform width & height');
Ti.API.info(Ti.Platform.displayCaps.platformWidth);
Ti.API.info(Ti.Platform.displayCaps.platformWidth / Ti.Platform.displayCaps.logicalDensityFactor);
Ti.API.info(Ti.Platform.displayCaps.platformHeight);
Ti.API.info(Ti.Platform.displayCaps.platformHeight / Ti.Platform.displayCaps.logicalDensityFactor);

var view = Ti.UI.createView({
	height: Ti.UI.SIZE,
	layout: "vertical"
});

view.add(Ti.UI.createView({ height: 50, backgroundColor: "#f00" }));
view.add(Ti.UI.createView({ height: 50, backgroundColor: "#0f0" }));
view.add(Ti.UI.createView({ height: 50, backgroundColor: "#00f" }));

view.addEventListener("click", function(e) {
	Ti.API.info("on click");
	Ti.API.info(e.y);
	Ti.API.info(Math.round(e.y / Ti.Platform.displayCaps.logicalDensityFactor));
});

win.add(view);

win.open();
Run this code after you've set default unit in tiapp.xml. Firstly, you'll see that to get correct platform width and height, you need to divide values with "logicalDensityFactor". Same thing happens if you want to get coordinates in "click" event. For example, if you click on bottom of red view, you'll see that you'll get x values greater than 50, which is obviously wrong (please note that value should be rounded with 1 decimal point to make this identical to iOS). I'm not sure are there more cases, so please update test case if there are.

Comments

  1. Fokke Zandbergen 2015-01-05

    Any progress on fixing the last few API's not respecting the default unit? Apart from this case I know the same is at least true for events passing x/y coordinates.
  2. Ivan Skugor 2015-01-05

    I covered events too :)
  3. Fokke Zandbergen 2015-01-05

    I should read better, sorry :)

JSON Source