description
In order to reliably determine the physical size of an Android device, it would be beneficial to use Android's own assessment of the device. To do so, we should expose the screen layout size of an Android device via a simple comparison on Android's
Configuration.screenLayout
property. This property and getter method should be added to
Ti.Platform.displayCaps
and return the various possible Android screen layout size, currently:
* small
* normal
* large
* xlarge
It should be noted that
xlarge
was actually added at API level 9, so its constant value with be entered manually.
test app
Just pop this into a default titanium mobile project and test on android.
var size = Ti.Platform.Android.physicalSizeCategory;
var str = '';
switch(size) {
case Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_SMALL:
str = 'small';
break;
case Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_NORMAL:
str = 'normal';
break;
case Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_LARGE:
str = 'large';
break;
case Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_XLARGE:
str = 'xlarge';
break;
case Ti.Platform.Android.PHYSICAL_SIZE_CATEGORY_SMALL:
str = 'undefined';
break;
}
alert(
'width: ' + Ti.Platform.displayCaps.platformWidth + '\n' +
'height: ' + Ti.Platform.displayCaps.platformHeight + '\n' +
'dpi: ' + Ti.Platform.displayCaps.dpi + '\n' +
'den: ' + Ti.Platform.displayCaps.density + '\n' +
'ldf: ' + Ti.Platform.displayCaps.logicalDensityFactor + '\n' +
'xdpi: ' + Ti.Platform.displayCaps.xdpi + '\n' +
'ydpi: ' + Ti.Platform.displayCaps.ydpi + '\n' +
'SIZE: ' + str
);
concerns
Parity tickets may need to be raised for Mobileweb and iOS.
PR submitted: https://github.com/appcelerator/titanium_mobile/pull/2610 While far from a comprehensive test, I ran this against the following devices and emulators, all of which returned the correct values: * Transformer Prime: xlarge * Galaxy Nexus: normal * Galaxy Tab (emulator): large
The functionality is android-specific, much like the existing
xdpi
andydpi
properties. As far as I can tell from perusing the code, iOS and mobileweb implement neither of these properties and simply returnundefined
when they are accessed in Titanium at runtime. I was following those examples when implementing this property. I have no aversion to attaching this new property to an Android-specific namespace if you think that will help. Let me know how you'd like me to proceed and I can adjust the corresponding PR.This has been made into an Android-only property, with corresponding constants and docs, in
Ti.Platform.Android
. The PR has been updated.Environment used for verification - Tested with Titanium SDK: 2.2.0.v20120816212512 Tested with Titanium Studio: 2.1.1.201207271312 Device - Samsung GALAXY Note Android 2.3.6,Samung GALAXY Tab 620 Android 3.2 Machine OS - MAC 10.8
Re-opening to edit label