Created
October 25, 2013 02:37
-
-
Save jkotchoff/7148669 to your computer and use it in GitHub Desktop.
This is an edit of: http://www.libtronics.com/2013/10/determining-if-device-is-tablet-on.html that can be used to check whether an appcelerator Titanium app should be rendered with a tablet layout.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isTablet(){ | |
if(!Ti.Android){ | |
return Ti.Platform.osname === 'ipad'; | |
} | |
// http://www.libtronics.com/2013/10/determining-if-device-is-tablet-on.html | |
var height = Ti.Platform.displayCaps.platformHeight; | |
var width = Ti.Platform.displayCaps.platformWidth; | |
if (height < width){ | |
var w_inch = height / Ti.Platform.displayCaps.xdpi; | |
var h_inch = width / Ti.Platform.displayCaps.ydpi; | |
}else{ | |
var w_inch = width / Ti.Platform.displayCaps.xdpi; | |
var h_inch = height / Ti.Platform.displayCaps.ydpi; | |
} | |
var disp_size = Math.sqrt(w_inch*w_inch+h_inch*h_inch); | |
// Ti.API.info('Width: '+width+', Height: '+height+', size: '+disp_size); | |
// Ti.API.info('w_inch: '+w_inch+', h_inch: '+h_inch); | |
// The Samsung Galaxy Tablet 1 in our office has a disp_size of: 6.77 and renders titanium apps with tablet layouts nicely | |
return (disp_size > 6.75); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah-ha, just found out that this isn't even neccessary, refer:
http://docs.appcelerator.com/titanium/3.0/#!/api/Alloy-property-isTablet
https://github.com/appcelerator/alloy/blob/7ca0be6f142046f328b6b911b28fa3117501e14d/Alloy/lib/alloy.js#L449