All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scaffold.libs_as.flair.resources.getDimen.as Maven / Gradle / Ivy

package flair.resources
{
	import flair.PhysicalDensity;

	import flair.utils.device.isAndroid;
	import flair.utils.displayMetrics.getDensityScale;

	import feathers.system.DeviceCapabilities;

	/**
	 *
	 */
	public function getDimen( id : String , groupID : String = null ) : Number
	{
		var dim : String = getAssetManager( groupID ).getXml( "values" ).dimen.( @name == id ).toString();
		var value : int = parseInt( dim );
		var matches : Array = dim.match( /^\d+(dp|px|mm|in)/ );

		if( matches && matches.length )
		{
			var unit : String = matches[ 1 ];

			switch( unit )
			{
				case "dp" :
					return value;
				case "px" :
					return value / getDensityScale();
				case "mm" :
				case "in" :

					var dpi : Number = isAndroid() ? PhysicalDensity.dpi : DeviceCapabilities.dpi;
					var inches : Number = value * dpi / getDensityScale();

					if( unit == "in" ) return inches;

					var mm : Number = inches * 0.0393701;

					return mm;
			}
		}

		return NaN;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy