am b0bed09a: am 469b5da8: Merge "Ensure first load for bitmap and nine-patch gets correct density" into mnc-dev

* commit 'b0bed09a0b4295c0fe4f0e20ecefa9be4ae0cf7b':
  Ensure first load for bitmap and nine-patch gets correct density
This commit is contained in:
Alan Viverette
2015-06-16 22:54:46 +00:00
committed by Android Git Automerger
3 changed files with 12 additions and 9 deletions

View File

@@ -815,6 +815,9 @@ public class BitmapDrawable extends Drawable {
if (tileModeY != TILE_MODE_UNDEFINED) { if (tileModeY != TILE_MODE_UNDEFINED) {
setTileModeY(parseTileMode(tileModeY)); setTileModeY(parseTileMode(tileModeY));
} }
final int densityDpi = r.getDisplayMetrics().densityDpi;
state.mTargetDensity = densityDpi == 0 ? DisplayMetrics.DENSITY_DEFAULT : densityDpi;
} }
@Override @Override
@@ -977,7 +980,8 @@ public class BitmapDrawable extends Drawable {
*/ */
private void updateLocalState(Resources res) { private void updateLocalState(Resources res) {
if (res != null) { if (res != null) {
mTargetDensity = res.getDisplayMetrics().densityDpi; final int densityDpi = res.getDisplayMetrics().densityDpi;
mTargetDensity = densityDpi == 0 ? DisplayMetrics.DENSITY_DEFAULT : densityDpi;
} else { } else {
mTargetDensity = mBitmapState.mTargetDensity; mTargetDensity = mBitmapState.mTargetDensity;
} }

View File

@@ -1147,6 +1147,7 @@ public abstract class Drawable {
* document, tries to create a Drawable from that tag. Returns {@code null} * document, tries to create a Drawable from that tag. Returns {@code null}
* if the tag is not a valid drawable. * if the tag is not a valid drawable.
*/ */
@SuppressWarnings("deprecation")
public static Drawable createFromXmlInner(Resources r, XmlPullParser parser, AttributeSet attrs, public static Drawable createFromXmlInner(Resources r, XmlPullParser parser, AttributeSet attrs,
Theme theme) throws XmlPullParserException, IOException { Theme theme) throws XmlPullParserException, IOException {
final Drawable drawable; final Drawable drawable;
@@ -1202,16 +1203,10 @@ public abstract class Drawable {
drawable = new InsetDrawable(); drawable = new InsetDrawable();
break; break;
case "bitmap": case "bitmap":
drawable = new BitmapDrawable(r); drawable = new BitmapDrawable();
if (r != null) {
((BitmapDrawable) drawable).setTargetDensity(r.getDisplayMetrics());
}
break; break;
case "nine-patch": case "nine-patch":
drawable = new NinePatchDrawable(); drawable = new NinePatchDrawable();
if (r != null) {
((NinePatchDrawable) drawable).setTargetDensity(r.getDisplayMetrics());
}
break; break;
default: default:
throw new XmlPullParserException(parser.getPositionDescription() + throw new XmlPullParserException(parser.getPositionDescription() +

View File

@@ -482,6 +482,9 @@ public class NinePatchDrawable extends Drawable {
if (tint != null) { if (tint != null) {
state.mTint = tint; state.mTint = tint;
} }
final int densityDpi = r.getDisplayMetrics().densityDpi;
state.mTargetDensity = densityDpi == 0 ? DisplayMetrics.DENSITY_DEFAULT : densityDpi;
} }
@Override @Override
@@ -713,7 +716,8 @@ public class NinePatchDrawable extends Drawable {
final NinePatchState state = mNinePatchState; final NinePatchState state = mNinePatchState;
if (res != null) { if (res != null) {
mTargetDensity = res.getDisplayMetrics().densityDpi; final int densityDpi = res.getDisplayMetrics().densityDpi;
mTargetDensity = densityDpi == 0 ? DisplayMetrics.DENSITY_DEFAULT : densityDpi;
} else { } else {
mTargetDensity = state.mTargetDensity; mTargetDensity = state.mTargetDensity;
} }