Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Detect a tablet (solution)

$
0
0

Hi I refined the way to detect a tablet a litte bit (based on the app-templates). The basic change is that I calculate the screen size and take this as an additional test (tablets have at least 6 inches screen diagonal size.

I hope it helps someone!

var osname          = Ti.Platform.osname,
        version         = Ti.Platform.version,
        height          = Ti.Platform.displayCaps.platformHeight,
        width           = Ti.Platform.displayCaps.platformWidth,
        screenWidthInch = Titanium.Platform.displayCaps.platformWidth / Titanium.Platform.displayCaps.dpi,
        screenHeightInch= Titanium.Platform.displayCaps.platformHeight / Titanium.Platform.displayCaps.dpi;
 
var screenSizeInch      = Math.sqrt( Math.pow(screenWidthInch, 2) + Math.pow(screenHeightInch, 2) );
 
var isTablet = osname === 'ipad' || (osname === 'android' && screenSizeInch >=6 && (width > 899 || height > 899) );
Another tip: switch the unit for android to dip in your tiapp.xml - That makes a lot easier:
<property name="ti.ui.defaultunit" type="string">dip</property>
So You can use integers on android like on iOS as values for positioning, sizes etc.

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>