use of com.android.resources.Density in project platform_frameworks_base by android.
the class RenderAction method getConfiguration.
// VisibleForTesting
public static Configuration getConfiguration(RenderParams params) {
Configuration config = new Configuration();
HardwareConfig hardwareConfig = params.getHardwareConfig();
ScreenSize screenSize = hardwareConfig.getScreenSize();
if (screenSize != null) {
switch(screenSize) {
case SMALL:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_SMALL;
break;
case NORMAL:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_NORMAL;
break;
case LARGE:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_LARGE;
break;
case XLARGE:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_XLARGE;
break;
}
}
Density density = hardwareConfig.getDensity();
if (density == null) {
density = Density.MEDIUM;
}
config.screenWidthDp = hardwareConfig.getScreenWidth() / density.getDpiValue();
config.screenHeightDp = hardwareConfig.getScreenHeight() / density.getDpiValue();
if (config.screenHeightDp < config.screenWidthDp) {
//noinspection SuspiciousNameCombination
config.smallestScreenWidthDp = config.screenHeightDp;
} else {
config.smallestScreenWidthDp = config.screenWidthDp;
}
config.densityDpi = density.getDpiValue();
// never run in compat mode:
config.compatScreenWidthDp = config.screenWidthDp;
config.compatScreenHeightDp = config.screenHeightDp;
ScreenOrientation orientation = hardwareConfig.getOrientation();
if (orientation != null) {
switch(orientation) {
case PORTRAIT:
config.orientation = Configuration.ORIENTATION_PORTRAIT;
break;
case LANDSCAPE:
config.orientation = Configuration.ORIENTATION_LANDSCAPE;
break;
case SQUARE:
//noinspection deprecation
config.orientation = Configuration.ORIENTATION_SQUARE;
break;
}
} else {
config.orientation = Configuration.ORIENTATION_UNDEFINED;
}
ScreenRound roundness = hardwareConfig.getScreenRoundness();
if (roundness != null) {
switch(roundness) {
case ROUND:
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
break;
case NOTROUND:
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_NO;
}
} else {
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_UNDEFINED;
}
String locale = params.getLocale();
if (locale != null && !locale.isEmpty())
config.locale = new Locale(locale);
return config;
}
use of com.android.resources.Density in project android_frameworks_base by ParanoidAndroid.
the class ResourceHelper method getDrawable.
/**
* Returns a drawable from the given value.
* @param value The value that contains a path to a 9 patch, a bitmap or a xml based drawable,
* or an hexadecimal color
* @param context the current context
*/
public static Drawable getDrawable(ResourceValue value, BridgeContext context) {
String stringValue = value.getValue();
if (RenderResources.REFERENCE_NULL.equals(stringValue)) {
return null;
}
String lowerCaseValue = stringValue.toLowerCase();
Density density = Density.MEDIUM;
if (value instanceof DensityBasedResourceValue) {
density = ((DensityBasedResourceValue) value).getResourceDensity();
}
if (lowerCaseValue.endsWith(NinePatch.EXTENSION_9PATCH)) {
File file = new File(stringValue);
if (file.isFile()) {
try {
return getNinePatchDrawable(new FileInputStream(file), density, value.isFramework(), stringValue, context);
} catch (IOException e) {
// failed to read the file, we'll return null below.
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, "Failed lot load " + file.getAbsolutePath(), e, null);
}
}
return null;
} else if (lowerCaseValue.endsWith(".xml")) {
// create a block parser for the file
File f = new File(stringValue);
if (f.isFile()) {
try {
// let the framework inflate the Drawable from the XML file.
XmlPullParser parser = ParserFactory.create(f);
BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, context, value.isFramework());
try {
return Drawable.createFromXml(context.getResources(), blockParser);
} finally {
blockParser.ensurePopped();
}
} catch (Exception e) {
// this is an error and not warning since the file existence is checked before
// attempting to parse it.
Bridge.getLog().error(null, "Failed to parse file " + stringValue, e, null);
}
} else {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("File %s does not exist (or is not a file)", stringValue), null);
}
return null;
} else {
File bmpFile = new File(stringValue);
if (bmpFile.isFile()) {
try {
Bitmap bitmap = Bridge.getCachedBitmap(stringValue, value.isFramework() ? null : context.getProjectKey());
if (bitmap == null) {
bitmap = Bitmap_Delegate.createBitmap(bmpFile, false, /*isMutable*/
density);
Bridge.setCachedBitmap(stringValue, bitmap, value.isFramework() ? null : context.getProjectKey());
}
return new BitmapDrawable(context.getResources(), bitmap);
} catch (IOException e) {
// we'll return null below
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, "Failed lot load " + bmpFile.getAbsolutePath(), e, null);
}
} else {
// attempt to get a color from the value
try {
int color = getColor(stringValue);
return new ColorDrawable(color);
} catch (NumberFormatException e) {
// we'll return null below.
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_FORMAT, "Failed to convert " + stringValue + " into a drawable", e, null);
}
}
}
return null;
}
use of com.android.resources.Density in project android_frameworks_base by ParanoidAndroid.
the class RenderAction method getConfiguration.
private Configuration getConfiguration() {
Configuration config = new Configuration();
HardwareConfig hardwareConfig = mParams.getHardwareConfig();
ScreenSize screenSize = hardwareConfig.getScreenSize();
if (screenSize != null) {
switch(screenSize) {
case SMALL:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_SMALL;
break;
case NORMAL:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_NORMAL;
break;
case LARGE:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_LARGE;
break;
case XLARGE:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_XLARGE;
break;
}
}
Density density = hardwareConfig.getDensity();
if (density == null) {
density = Density.MEDIUM;
}
config.screenWidthDp = hardwareConfig.getScreenWidth() / density.getDpiValue();
config.screenHeightDp = hardwareConfig.getScreenHeight() / density.getDpiValue();
if (config.screenHeightDp < config.screenWidthDp) {
config.smallestScreenWidthDp = config.screenHeightDp;
} else {
config.smallestScreenWidthDp = config.screenWidthDp;
}
config.densityDpi = density.getDpiValue();
// never run in compat mode:
config.compatScreenWidthDp = config.screenWidthDp;
config.compatScreenHeightDp = config.screenHeightDp;
ScreenOrientation orientation = hardwareConfig.getOrientation();
if (orientation != null) {
switch(orientation) {
case PORTRAIT:
config.orientation = Configuration.ORIENTATION_PORTRAIT;
break;
case LANDSCAPE:
config.orientation = Configuration.ORIENTATION_LANDSCAPE;
break;
case SQUARE:
config.orientation = Configuration.ORIENTATION_SQUARE;
break;
}
} else {
config.orientation = Configuration.ORIENTATION_UNDEFINED;
}
return config;
}
use of com.android.resources.Density in project android_frameworks_base by AOSPA.
the class RenderAction method getConfiguration.
// VisibleForTesting
public static Configuration getConfiguration(RenderParams params) {
Configuration config = new Configuration();
HardwareConfig hardwareConfig = params.getHardwareConfig();
ScreenSize screenSize = hardwareConfig.getScreenSize();
if (screenSize != null) {
switch(screenSize) {
case SMALL:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_SMALL;
break;
case NORMAL:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_NORMAL;
break;
case LARGE:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_LARGE;
break;
case XLARGE:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_XLARGE;
break;
}
}
Density density = hardwareConfig.getDensity();
if (density == null) {
density = Density.MEDIUM;
}
config.screenWidthDp = hardwareConfig.getScreenWidth() / density.getDpiValue();
config.screenHeightDp = hardwareConfig.getScreenHeight() / density.getDpiValue();
if (config.screenHeightDp < config.screenWidthDp) {
//noinspection SuspiciousNameCombination
config.smallestScreenWidthDp = config.screenHeightDp;
} else {
config.smallestScreenWidthDp = config.screenWidthDp;
}
config.densityDpi = density.getDpiValue();
// never run in compat mode:
config.compatScreenWidthDp = config.screenWidthDp;
config.compatScreenHeightDp = config.screenHeightDp;
ScreenOrientation orientation = hardwareConfig.getOrientation();
if (orientation != null) {
switch(orientation) {
case PORTRAIT:
config.orientation = Configuration.ORIENTATION_PORTRAIT;
break;
case LANDSCAPE:
config.orientation = Configuration.ORIENTATION_LANDSCAPE;
break;
case SQUARE:
//noinspection deprecation
config.orientation = Configuration.ORIENTATION_SQUARE;
break;
}
} else {
config.orientation = Configuration.ORIENTATION_UNDEFINED;
}
ScreenRound roundness = hardwareConfig.getScreenRoundness();
if (roundness != null) {
switch(roundness) {
case ROUND:
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
break;
case NOTROUND:
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_NO;
}
} else {
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_UNDEFINED;
}
String locale = params.getLocale();
if (locale != null && !locale.isEmpty())
config.locale = new Locale(locale);
return config;
}
use of com.android.resources.Density in project android by JetBrains.
the class AvdDisplayList method getResolution.
/**
* @return the resolution of a given AVD as a string of the format [width]x[height] - [density]
* (e.g. 1200x1920 - xhdpi) or "Unknown Resolution" if the AVD does not define a resolution.
*/
@VisibleForTesting
static String getResolution(@NotNull AvdInfo info) {
DeviceManagerConnection deviceManager = DeviceManagerConnection.getDefaultDeviceManagerConnection();
Device device = deviceManager.getDevice(info.getDeviceName(), info.getDeviceManufacturer());
Dimension res = null;
Density density = null;
if (device != null) {
res = device.getScreenSize(device.getDefaultState().getOrientation());
density = device.getDefaultHardware().getScreen().getPixelDensity();
}
String resolution;
String densityString = density == null ? "Unknown Density" : density.getResourceValue();
if (res != null) {
resolution = String.format(Locale.getDefault(), "%1$d × %2$d: %3$s", res.width, res.height, densityString);
} else {
resolution = "Unknown Resolution";
}
return resolution;
}
Aggregations