Skip to content

Instantly share code, notes, and snippets.

@FokkeZB
Created August 22, 2013 07:35
Show Gist options
  • Save FokkeZB/6304139 to your computer and use it in GitHub Desktop.
Save FokkeZB/6304139 to your computer and use it in GitHub Desktop.
Android density specific folders
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