Created
October 13, 2013 21:57
-
-
Save otger/6967852 to your computer and use it in GitHub Desktop.
Code for "Determining if a device is a tablet on Titanium Appcelerator" blog post: http://www.libtronics.com/2013/10/determining-if-device-is-tablet-on.html
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
var osname = Ti.Platform.osname; | |
var version = Ti.Platform.version; | |
var dpi = Ti.Platform.displayCaps.dpi; | |
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); | |
var is7inch = (disp_size > 6.99)? true: false; | |
//Ti.API.info('Width: '+width+', Height: '+height+', size: '+disp_size); | |
//Ti.API.info('w_inch: '+w_inch+', h_inch: '+h_inch); | |
var isTablet = osname === 'ipad' || (osname === 'android' && is7inch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment