Created
August 22, 2013 07:35
-
-
Save FokkeZB/6304139 to your computer and use it in GitHub Desktop.
Android density specific folders
This file contains hidden or 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 logicalDensityFactor = Ti.Platform.displayCaps.logicalDensityFactor, | |
density, | |
orientation = (Ti.Gesture.orientation === Ti.UI.LANDSCAPE_LEFT) ? "land" : "port", | |
width = Ti.Platform.displayCaps.platformWidth, | |
height = Ti.Platform.displayCaps.platformHeihgt, | |
ratio = ((width / height) < ((orientation === "land") ? (320 / 240) : (240 / 320))) ? "long" : "notlong", | |
folders = [], | |
shortnames = { | |
"ldpi": "low", | |
"mdpi": "medium", | |
"hdpi": "high" | |
}; | |
if (logicalDensityFactor <= 0.75) { | |
density = "ldpi"; | |
} else if (logicalDensityFactor <= 1.0) { | |
density = "mdpi"; | |
} else if (logicalDensityFactor <= 1.5) { | |
density = "hdpi"; | |
} else { | |
density = "xhdpi"; | |
} | |
folders.push("res-" + ratio + "-ORIENTATION-" + density); | |
folders.push("res-ORIENTATION-" + density); | |
folders.push("res-" + density); | |
if (shortnames[density]) { | |
folders.push(shortnames[density]); | |
} | |
folders.push("res-mdpi"); | |
Ti.API.info('orientation: ' + orientation); | |
Ti.API.info('density: ' + density); | |
Ti.API.info('ratio: ' + ratio); | |
Ti.API.info('folders: ' + JSON.stringify(folders)); | |
Ti.Gesture.addEventListener("orientationchange", function (e) { | |
orientation = (e.orientation === Ti.UI.LANDSCAPE_LEFT) ? "land" : "port"; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment