Skip to content

Instantly share code, notes, and snippets.

@demogar
Created May 2, 2014 16:46
Show Gist options
  • Select an option

  • Save demogar/bd866e1e77243e615ec6 to your computer and use it in GitHub Desktop.

Select an option

Save demogar/bd866e1e77243e615ec6 to your computer and use it in GitHub Desktop.
// Con esta función transformamos de pixeles (o la unidad por default)
// a dp
function pixelToDp(pixel) {
var dpi = Ti.Platform.displayCaps.dpi;
var dp = (pixel / dpi) * 160;
dp = Math.ceil(dp);
return dp;
};
// Esta self-calling-function es la que utilizamos para sobreescribir la funcionalidad de Alloy. Como nuestro aplicativo sólo funciona para iOS y Android hacemos la verificación para esta dos.
Alloy.isTablet = (function() {
var width = Ti.Platform.displayCaps.platformWidth;
var height = Ti.Platform.displayCaps.platformHeight;
var min = Math.min(width, height);
if (OS_IOS) {
return Ti.Platform.osname === 'ipad';
} else {
return pixelToDp(min) >= 500;
}
})();
// Y bueno, isHandheld sería el inverso de isTablet
Alloy.isHandheld = !Alloy.isTablet;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment