//////////////////////////////////////////////////////////////////////////////// // // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// package mx.core { import flash.system.Capabilities; import mx.core.mx_internal; use namespace mx_internal; /** * The RuntimeDPIProvider class provides the default mapping of * similar device DPI values into predefined DPI classes. * An Application may have its runtimeDPIProvider property set to a * subclass of RuntimeDPIProvider to override Flex's default mappings. * Overriding Flex's default mappings will cause changes in the Application's * automatic scaling behavior. * *
Overriding Flex's default mappings is usually only necessary for devices * that incorrectly report their screenDPI and for devices that may scale better * in a different DPI class.
* *Flex's default mappings are: *
160 DPI | <200 DPI |
240 DPI | >=200 DPI and <280 DPI |
320 DPI | >=280 DPI |
Subclasses of RuntimeDPIProvider should only depend on runtime APIs
* and should not depend on any classes specific to the Flex framework except
* mx.core.DPIClassification
.
flash.system.Capabilities.screenDPI
to one of several DPI
* values in mx.core.DPIClassification
.
*
* A number of devices can have slightly different DPI values and Flex maps these
* into the several DPI classes.
*
* Flex uses this method to calculate the current DPI value when an Application
* authored for a specific DPI is adapted to the current one through scaling.
*
* @param dpi The DPI value.
* @return The corresponding DPIClassification
value.
*
* @see flash.system.Capabilities
* @see mx.core.DPIClassification
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
public function get runtimeDPI():Number
{
return classifyDPI(Capabilities.screenDPI);
}
/**
* @private
* Matches the specified DPI to a DPIClassification
value.
* A number of devices can have slightly different DPI values and classifyDPI
* maps these into the several DPI classes.
*
* This method is specifically kept for Design View. Flex uses RuntimeDPIProvider
* to calculate DPI classes.
*
* @param dpi The DPI value.
* @return The corresponding DPIClassification
value.
*/
mx_internal static function classifyDPI(dpi:Number):Number
{
if (dpi < 200)
return DPIClassification.DPI_160;
if (dpi <= 280)
return DPIClassification.DPI_240;
return DPIClassification.DPI_320;
}
}
}