Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10043] Android: Add "physicalSizeCategory" to Ti.Platform.displayCaps

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2012-09-05T23:35:40.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 3.0.0
ComponentsAndroid
Labelscore, module_platform, parity, qe-review, qe-testadded
ReporterTony Lukasavage
AssigneeNeeraj Gupta
Created2012-07-19T14:05:39.000+0000
Updated2012-09-05T23:35:40.000+0000

Description

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.

Comments

  1. Tony Lukasavage 2012-07-19

    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
  2. Tony Lukasavage 2012-07-20

    The functionality is android-specific, much like the existing xdpi and ydpi properties. As far as I can tell from perusing the code, iOS and mobileweb implement neither of these properties and simply return undefined 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.
  3. Tony Lukasavage 2012-07-27

    This has been made into an Android-only property, with corresponding constants and docs, in Ti.Platform.Android. The PR has been updated.
  4. Shyam Bhadauria 2012-08-16

    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
  5. Shyam Bhadauria 2012-09-05

    Re-opening to edit label

JSON Source