use of com.android.resources.Density in project android_frameworks_base by ParanoidAndroid.
the class BitmapFactory_Delegate method nativeDecodeStream.
@LayoutlibDelegate
static /*package*/
Bitmap nativeDecodeStream(InputStream is, byte[] storage, Rect padding, Options opts, boolean applyScale, float scale) {
Bitmap bm = null;
//TODO support rescaling
Density density = Density.MEDIUM;
if (opts != null) {
density = Density.getEnum(opts.inDensity);
}
try {
if (is instanceof NinePatchInputStream) {
NinePatchInputStream npis = (NinePatchInputStream) is;
npis.disableFakeMarkSupport();
// load the bitmap as a nine patch
com.android.ninepatch.NinePatch ninePatch = com.android.ninepatch.NinePatch.load(npis, true, /*is9Patch*/
false);
// get the bitmap and chunk objects.
bm = Bitmap_Delegate.createBitmap(ninePatch.getImage(), true, /*isMutable*/
density);
NinePatchChunk chunk = ninePatch.getChunk();
// put the chunk in the bitmap
bm.setNinePatchChunk(NinePatch_Delegate.serialize(chunk));
// read the padding
int[] paddingarray = chunk.getPadding();
padding.left = paddingarray[0];
padding.top = paddingarray[1];
padding.right = paddingarray[2];
padding.bottom = paddingarray[3];
} else {
// load the bitmap directly.
bm = Bitmap_Delegate.createBitmap(is, true, density);
}
} catch (IOException e) {
Bridge.getLog().error(null, "Failed to load image", e, null);
}
return bm;
}
use of com.android.resources.Density in project android_frameworks_base by ParanoidAndroid.
the class CustomBar method getIcon.
private InputStream getIcon(String iconName, Density[] densityInOut, String[] pathOut, boolean tryOtherDensities) {
// current density
Density density = densityInOut[0];
// bitmap url relative to this class
pathOut[0] = "/bars/" + density.getResourceValue() + "/" + iconName;
InputStream stream = getClass().getResourceAsStream(pathOut[0]);
if (stream == null && tryOtherDensities) {
for (Density d : Density.values()) {
if (d != density) {
densityInOut[0] = d;
stream = getIcon(iconName, densityInOut, pathOut, false);
if (stream != null) {
return stream;
}
}
}
}
return stream;
}
use of com.android.resources.Density in project android_frameworks_base by ParanoidAndroid.
the class CustomBar method loadIcon.
protected void loadIcon(int index, String iconName, Density density) {
View child = getChildAt(index);
if (child instanceof ImageView) {
ImageView imageView = (ImageView) child;
String[] pathOut = new String[1];
Density[] densityInOut = new Density[] { density };
InputStream stream = getIcon(iconName, densityInOut, pathOut, true);
density = densityInOut[0];
if (stream != null) {
// look for a cached bitmap
Bitmap bitmap = Bridge.getCachedBitmap(pathOut[0], true);
if (bitmap == null) {
try {
bitmap = Bitmap_Delegate.createBitmap(stream, false, /*isMutable*/
density);
Bridge.setCachedBitmap(pathOut[0], bitmap, true);
} catch (IOException e) {
return;
}
}
if (bitmap != null) {
BitmapDrawable drawable = new BitmapDrawable(getContext().getResources(), bitmap);
imageView.setImageDrawable(drawable);
}
}
}
}
use of com.android.resources.Density in project android_frameworks_base by ResurrectionRemix.
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 DirtyUnicorns.
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;
}
Aggregations