Skip to content

Instantly share code, notes, and snippets.

@jkotchoff
Created October 25, 2013 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkotchoff/7148669 to your computer and use it in GitHub Desktop.
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.
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