Merge change 7783 into donut
* changes: Add "nodpi" density, and expose a bunch of density-related APIs.
This commit is contained in:
222
api/current.xml
222
api/current.xml
@@ -48942,6 +48942,17 @@
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getDensityScale"
|
||||
return="float"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getHeight"
|
||||
return="int"
|
||||
abstract="false"
|
||||
@@ -49015,6 +49026,28 @@
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getScaledHeight"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getScaledWidth"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getWidth"
|
||||
return="int"
|
||||
abstract="false"
|
||||
@@ -49037,6 +49070,17 @@
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="isAutoScalingEnabled"
|
||||
return="boolean"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="isMutable"
|
||||
return="boolean"
|
||||
abstract="false"
|
||||
@@ -49081,6 +49125,32 @@
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="setAutoScalingEnabled"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="autoScalingEnabled" type="boolean">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setDensityScale"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="densityScale" type="float">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setPixel"
|
||||
return="void"
|
||||
abstract="false"
|
||||
@@ -49148,6 +49218,17 @@
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="DENSITY_SCALE_UNKNOWN"
|
||||
type="float"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="-1.0f"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
</class>
|
||||
<class name="Bitmap.CompressFormat"
|
||||
extends="java.lang.Enum"
|
||||
@@ -49367,6 +49448,27 @@
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="res" type="android.content.res.Resources">
|
||||
</parameter>
|
||||
<parameter name="value" type="android.util.TypedValue">
|
||||
</parameter>
|
||||
<parameter name="is" type="java.io.InputStream">
|
||||
</parameter>
|
||||
<parameter name="pad" type="android.graphics.Rect">
|
||||
</parameter>
|
||||
<parameter name="opts" type="android.graphics.BitmapFactory.Options">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="decodeStream"
|
||||
return="android.graphics.Bitmap"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="true"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="is" type="java.io.InputStream">
|
||||
</parameter>
|
||||
<parameter name="outPadding" type="android.graphics.Rect">
|
||||
@@ -49415,6 +49517,16 @@
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<field name="inDensity"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="inDither"
|
||||
type="boolean"
|
||||
transient="false"
|
||||
@@ -49475,6 +49587,16 @@
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="inScaled"
|
||||
type="boolean"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="inTempStorage"
|
||||
type="byte[]"
|
||||
transient="false"
|
||||
@@ -50729,6 +50851,17 @@
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getDensityScale"
|
||||
return="float"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getDrawFilter"
|
||||
return="android.graphics.DrawFilter"
|
||||
abstract="false"
|
||||
@@ -51075,6 +51208,19 @@
|
||||
<parameter name="bitmap" type="android.graphics.Bitmap">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setDensityScale"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="densityScale" type="float">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setDrawFilter"
|
||||
return="void"
|
||||
abstract="false"
|
||||
@@ -132969,6 +133115,50 @@
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<field name="DENSITY_DEFAULT"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="160"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="DENSITY_HIGH"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="240"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="DENSITY_LOW"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="120"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="DENSITY_MEDIUM"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="160"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="density"
|
||||
type="float"
|
||||
transient="false"
|
||||
@@ -135018,6 +135208,28 @@
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="DENSITY_DEFAULT"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="0"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="DENSITY_NONE"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="65535"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="TYPE_ATTRIBUTE"
|
||||
type="int"
|
||||
transient="false"
|
||||
@@ -135246,6 +135458,16 @@
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="density"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="resourceId"
|
||||
type="int"
|
||||
transient="false"
|
||||
|
||||
@@ -32,7 +32,6 @@ import android.content.pm.InstrumentationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ProviderInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.content.pm.PackageParser.Component;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.CompatibilityInfo;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
@@ -114,14 +114,14 @@ public class CompatibilityInfo {
|
||||
packageDensityScale = 1.0f;
|
||||
break;
|
||||
}
|
||||
int tmpDiff = Math.abs(DisplayMetrics.DEVICE_DENSITY - density);
|
||||
int tmpDiff = Math.abs(DisplayMetrics.DENSITY_DEVICE - density);
|
||||
if (tmpDiff == 0) {
|
||||
packageDensityScale = 1.0f;
|
||||
break;
|
||||
}
|
||||
// prefer higher density (appScale>1.0), unless that's only option.
|
||||
if (tmpDiff < minDiff && packageDensityScale < 1.0f) {
|
||||
packageDensityScale = DisplayMetrics.DEVICE_DENSITY / (float) density;
|
||||
packageDensityScale = DisplayMetrics.DENSITY_DEVICE / (float) density;
|
||||
minDiff = tmpDiff;
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class CompatibilityInfo {
|
||||
applicationScale = packageDensityScale;
|
||||
} else {
|
||||
applicationScale =
|
||||
DisplayMetrics.DEVICE_DENSITY / (float) DisplayMetrics.DEFAULT_DENSITY;
|
||||
DisplayMetrics.DENSITY_DEVICE / (float) DisplayMetrics.DENSITY_DEFAULT;
|
||||
}
|
||||
|
||||
applicationInvertedScale = 1.0f / applicationScale;
|
||||
|
||||
@@ -87,7 +87,7 @@ public class Resources {
|
||||
/*package*/ final DisplayMetrics mMetrics = new DisplayMetrics();
|
||||
PluralRules mPluralRule;
|
||||
|
||||
private final CompatibilityInfo mCompatibilityInfo;
|
||||
private CompatibilityInfo mCompatibilityInfo;
|
||||
private Display mDefaultDisplay;
|
||||
|
||||
private static final LongSparseArray<Object> EMPTY_ARRAY = new LongSparseArray<Object>() {
|
||||
@@ -1385,6 +1385,15 @@ public class Resources {
|
||||
return mCompatibilityInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is just for testing.
|
||||
* @hide
|
||||
*/
|
||||
public void setCompatibilityInfo(CompatibilityInfo ci) {
|
||||
mCompatibilityInfo = ci;
|
||||
updateConfiguration(mConfiguration, mMetrics);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a resource identifier for the given resource name. A fully
|
||||
* qualified resource name is of the form "package:type/entry". The first
|
||||
|
||||
@@ -27,17 +27,31 @@ import android.os.*;
|
||||
*/
|
||||
public class DisplayMetrics {
|
||||
/**
|
||||
* The reference density used throughout the system.
|
||||
*
|
||||
* @hide Pending API council approval
|
||||
* Standard quantized DPI for low-density screens.
|
||||
*/
|
||||
public static final int DEFAULT_DENSITY = 160;
|
||||
public static final int DENSITY_LOW = 120;
|
||||
|
||||
/**
|
||||
* Standard quantized DPI for medium-density screens.
|
||||
*/
|
||||
public static final int DENSITY_MEDIUM = 160;
|
||||
|
||||
/**
|
||||
* Standard quantized DPI for high-density screens.
|
||||
*/
|
||||
public static final int DENSITY_HIGH = 240;
|
||||
|
||||
/**
|
||||
* The reference density used throughout the system.
|
||||
*/
|
||||
public static final int DENSITY_DEFAULT = DENSITY_MEDIUM;
|
||||
|
||||
/**
|
||||
* The device's density.
|
||||
* @hide
|
||||
* @hide becase eventually this should be able to change while
|
||||
* running, so shouldn't be a constant.
|
||||
*/
|
||||
public static final int DEVICE_DENSITY = getDeviceDensity();
|
||||
public static final int DENSITY_DEVICE = getDeviceDensity();
|
||||
|
||||
/**
|
||||
* The absolute width of the display in pixels.
|
||||
@@ -62,7 +76,7 @@ public class DisplayMetrics {
|
||||
* 320x480 but the screen size remained 1.5"x2" then the density would be
|
||||
* increased (probably to 1.5).
|
||||
*
|
||||
* @see #DEFAULT_DENSITY
|
||||
* @see #DENSITY_DEFAULT
|
||||
*/
|
||||
public float density;
|
||||
/**
|
||||
@@ -95,10 +109,10 @@ public class DisplayMetrics {
|
||||
public void setToDefaults() {
|
||||
widthPixels = 0;
|
||||
heightPixels = 0;
|
||||
density = DEVICE_DENSITY / (float) DEFAULT_DENSITY;
|
||||
density = DENSITY_DEVICE / (float) DENSITY_DEFAULT;
|
||||
scaledDensity = density;
|
||||
xdpi = DEVICE_DENSITY;
|
||||
ydpi = DEVICE_DENSITY;
|
||||
xdpi = DENSITY_DEVICE;
|
||||
ydpi = DENSITY_DEVICE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,6 +190,6 @@ public class DisplayMetrics {
|
||||
// The reason for this is that ro.sf.lcd_density is write-once and is
|
||||
// set by the init process when it parses build.prop before anything else.
|
||||
return SystemProperties.getInt("qemu.sf.lcd_density",
|
||||
SystemProperties.getInt("ro.sf.lcd_density", DEFAULT_DENSITY));
|
||||
SystemProperties.getInt("ro.sf.lcd_density", DENSITY_DEFAULT));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,12 +140,16 @@ public class TypedValue {
|
||||
|
||||
/**
|
||||
* If {@link #density} is equal to this value, then the density should be
|
||||
* treated as the system's default density value: {@link DisplayMetrics#DEFAULT_DENSITY}.
|
||||
*
|
||||
* @hide Pending API council approval
|
||||
* treated as the system's default density value: {@link DisplayMetrics#DENSITY_DEFAULT}.
|
||||
*/
|
||||
public static final int DENSITY_DEFAULT = 0;
|
||||
|
||||
/**
|
||||
* If {@link #density} is equal to this value, then there is no density
|
||||
* associated with the resource and it should not be scaled.
|
||||
*/
|
||||
public static final int DENSITY_NONE = 0xffff;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
||||
/** The type held by this value, as defined by the constants here.
|
||||
@@ -171,8 +175,6 @@ public class TypedValue {
|
||||
|
||||
/**
|
||||
* If the Value came from a resource, this holds the corresponding pixel density.
|
||||
*
|
||||
* @hide Pending API council approval
|
||||
* */
|
||||
public int density;
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ public final class Bitmap implements Parcelable {
|
||||
*
|
||||
* @see Bitmap#getDensityScale()
|
||||
* @see Bitmap#setDensityScale(float)
|
||||
*
|
||||
* @hide pending API council approval
|
||||
*/
|
||||
public static final float DENSITY_SCALE_UNKNOWN = -1.0f;
|
||||
|
||||
@@ -84,11 +82,9 @@ public final class Bitmap implements Parcelable {
|
||||
* @see #setDensityScale(float)
|
||||
* @see #isAutoScalingEnabled()
|
||||
* @see #setAutoScalingEnabled(boolean)
|
||||
* @see android.util.DisplayMetrics#DEFAULT_DENSITY
|
||||
* @see android.util.DisplayMetrics#DENSITY_DEFAULT
|
||||
* @see android.util.DisplayMetrics#density
|
||||
* @see #DENSITY_SCALE_UNKNOWN
|
||||
*
|
||||
* @hide pending API council approval
|
||||
*/
|
||||
public float getDensityScale() {
|
||||
return mDensityScale;
|
||||
@@ -106,11 +102,9 @@ public final class Bitmap implements Parcelable {
|
||||
* @see #getDensityScale()
|
||||
* @see #isAutoScalingEnabled()
|
||||
* @see #setAutoScalingEnabled(boolean)
|
||||
* @see android.util.DisplayMetrics#DEFAULT_DENSITY
|
||||
* @see android.util.DisplayMetrics#DENSITY_DEFAULT
|
||||
* @see android.util.DisplayMetrics#density
|
||||
* @see #DENSITY_SCALE_UNKNOWN
|
||||
*
|
||||
* @hide pending API council approval
|
||||
*/
|
||||
public void setDensityScale(float densityScale) {
|
||||
mDensityScale = densityScale;
|
||||
@@ -132,8 +126,6 @@ public final class Bitmap implements Parcelable {
|
||||
* @see #setAutoScalingEnabled(boolean)
|
||||
* @see #getDensityScale()
|
||||
* @see #setDensityScale(float)
|
||||
*
|
||||
* @hide pending API council approval
|
||||
*/
|
||||
public boolean isAutoScalingEnabled() {
|
||||
return mAutoScaling;
|
||||
@@ -150,8 +142,6 @@ public final class Bitmap implements Parcelable {
|
||||
* the bitmap will never be automatically scaled at drawing time.</p>
|
||||
*
|
||||
* @param autoScalingEnabled True to scale the bitmap at drawing time, false otherwise.
|
||||
*
|
||||
* @hide pending API council approval
|
||||
*/
|
||||
public void setAutoScalingEnabled(boolean autoScalingEnabled) {
|
||||
mAutoScaling = autoScalingEnabled;
|
||||
@@ -465,8 +455,8 @@ public final class Bitmap implements Parcelable {
|
||||
|
||||
// The new bitmap was created from a known bitmap source so assume that
|
||||
// they use the same density scale
|
||||
bitmap.setDensityScale(source.getDensityScale());
|
||||
bitmap.setAutoScalingEnabled(source.isAutoScalingEnabled());
|
||||
bitmap.mDensityScale = source.mDensityScale;
|
||||
bitmap.mAutoScaling = source.mAutoScaling;
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
@@ -616,11 +606,9 @@ public final class Bitmap implements Parcelable {
|
||||
* by the density scale factor.
|
||||
*
|
||||
* @return The scaled width of this bitmap, according to the density scale factor.
|
||||
*
|
||||
* @hide pending API council approval
|
||||
*/
|
||||
public int getScaledWidth() {
|
||||
final float scale = getDensityScale();
|
||||
final float scale = mDensityScale;
|
||||
return scale == DENSITY_SCALE_UNKNOWN ? getWidth() : (int) (getWidth() / scale);
|
||||
}
|
||||
|
||||
@@ -629,11 +617,9 @@ public final class Bitmap implements Parcelable {
|
||||
* by the density scale factor.
|
||||
*
|
||||
* @return The scaled height of this bitmap, according to the density scale factor.
|
||||
*
|
||||
* @hide pending API council approval
|
||||
*/
|
||||
public int getScaledHeight() {
|
||||
final float scale = getDensityScale();
|
||||
final float scale = mDensityScale;
|
||||
return scale == DENSITY_SCALE_UNKNOWN ? getWidth() : (int) (getHeight() / scale);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,10 +81,8 @@ public class BitmapFactory {
|
||||
/**
|
||||
* The desired pixel density of the bitmap.
|
||||
*
|
||||
* @see android.util.DisplayMetrics#DEFAULT_DENSITY
|
||||
* @see android.util.DisplayMetrics#DENSITY_DEFAULT
|
||||
* @see android.util.DisplayMetrics#density
|
||||
*
|
||||
* @hide pending API council approval
|
||||
*/
|
||||
public int inDensity;
|
||||
|
||||
@@ -97,8 +95,6 @@ public class BitmapFactory {
|
||||
* a non-scaled version of the bitmap. In this case,
|
||||
* {@link android.graphics.Bitmap#setAutoScalingEnabled(boolean)} can be used
|
||||
* to properly scale the bitmap at drawing time.</p>
|
||||
*
|
||||
* @hide pending API council approval
|
||||
*/
|
||||
public boolean inScaled;
|
||||
|
||||
@@ -238,8 +234,6 @@ public class BitmapFactory {
|
||||
/**
|
||||
* Decode a new Bitmap from an InputStream. This InputStream was obtained from
|
||||
* resources, which we pass to be able to scale the bitmap accordingly.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static Bitmap decodeStream(Resources res, TypedValue value, InputStream is,
|
||||
Rect pad, Options opts) {
|
||||
@@ -251,15 +245,19 @@ public class BitmapFactory {
|
||||
Bitmap bm = decodeStream(is, pad, opts);
|
||||
|
||||
if (bm != null && res != null && value != null) {
|
||||
final int density = value.density;
|
||||
if (density == TypedValue.DENSITY_NONE) {
|
||||
return bm;
|
||||
}
|
||||
|
||||
byte[] np = bm.getNinePatchChunk();
|
||||
final boolean isNinePatch = np != null && NinePatch.isNinePatchChunk(np);
|
||||
|
||||
final int density = value.density;
|
||||
if (opts.inDensity == 0) {
|
||||
opts.inDensity = density == TypedValue.DENSITY_DEFAULT ?
|
||||
DisplayMetrics.DEFAULT_DENSITY : density;
|
||||
DisplayMetrics.DENSITY_DEFAULT : density;
|
||||
}
|
||||
float scale = opts.inDensity / (float) DisplayMetrics.DEFAULT_DENSITY;
|
||||
float scale = opts.inDensity / (float) DisplayMetrics.DENSITY_DEFAULT;
|
||||
|
||||
if (opts.inScaled || isNinePatch) {
|
||||
bm.setDensityScale(1.0f);
|
||||
|
||||
@@ -184,8 +184,6 @@ public class Canvas {
|
||||
*
|
||||
* @see #setDensityScale(float)
|
||||
* @see Bitmap#getDensityScale()
|
||||
*
|
||||
* @hide pending API council approval
|
||||
*/
|
||||
public float getDensityScale() {
|
||||
if (mBitmap != null) {
|
||||
@@ -205,8 +203,6 @@ public class Canvas {
|
||||
*
|
||||
* @see #getDensityScale()
|
||||
* @see Bitmap#setDensityScale(float)
|
||||
*
|
||||
* @hide pending API council approval
|
||||
*/
|
||||
public void setDensityScale(float densityScale) {
|
||||
if (mBitmap != null) {
|
||||
|
||||
@@ -825,7 +825,8 @@ struct ResTable_config
|
||||
};
|
||||
|
||||
enum {
|
||||
DENSITY_ANY = 0
|
||||
DENSITY_DEFAULT = 0,
|
||||
DENSITY_NONE = 0xffff
|
||||
};
|
||||
|
||||
union {
|
||||
|
||||
@@ -4007,7 +4007,16 @@ void ResTable::print(bool inclValues) const
|
||||
printf(" NON-INTEGER ResTable_type ADDRESS: %p\n", type);
|
||||
continue;
|
||||
}
|
||||
printf(" config %d lang=%c%c cnt=%c%c orien=%d touch=%d density=%d key=%d infl=%d nav=%d w=%d h=%d lyt=%d\n",
|
||||
char density[16];
|
||||
uint16_t dval = dtohs(type->config.density);
|
||||
if (dval == ResTable_config::DENSITY_DEFAULT) {
|
||||
strcpy(density, "def");
|
||||
} else if (dval == ResTable_config::DENSITY_NONE) {
|
||||
strcpy(density, "non");
|
||||
} else {
|
||||
sprintf(density, "%d", (int)dval);
|
||||
}
|
||||
printf(" config %d lang=%c%c cnt=%c%c orien=%d touch=%d density=%s key=%d infl=%d nav=%d w=%d h=%d lyt=%d\n",
|
||||
(int)configIndex,
|
||||
type->config.language[0] ? type->config.language[0] : '-',
|
||||
type->config.language[1] ? type->config.language[1] : '-',
|
||||
@@ -4015,7 +4024,7 @@ void ResTable::print(bool inclValues) const
|
||||
type->config.country[1] ? type->config.country[1] : '-',
|
||||
type->config.orientation,
|
||||
type->config.touchscreen,
|
||||
dtohs(type->config.density),
|
||||
density,
|
||||
type->config.keyboard,
|
||||
type->config.inputFlags,
|
||||
type->config.navigation,
|
||||
|
||||
@@ -133,7 +133,7 @@ public class ConfigTest extends AndroidTestCase {
|
||||
case DENSITY:
|
||||
// this is the ratio from the standard
|
||||
|
||||
mMetrics.density = (((float)value)/((float)DisplayMetrics.DEFAULT_DENSITY));
|
||||
mMetrics.density = (((float)value)/((float)DisplayMetrics.DENSITY_DEFAULT));
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
|
||||
@@ -19,10 +19,15 @@
|
||||
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="3" />
|
||||
<supports-screens android:smallScreens="true" />
|
||||
<application android:label="DpiTest">
|
||||
<activity android:name="DpiTestActivity" android:label="DpiTest">
|
||||
<activity android:name="DpiTestActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="DpiTestActivityNoCompat" android:label="DpiTestCompat">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
BIN
tests/DpiTest/res/drawable-nodpi/logonodpi120.png
Normal file
BIN
tests/DpiTest/res/drawable-nodpi/logonodpi120.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.1 KiB |
BIN
tests/DpiTest/res/drawable-nodpi/logonodpi160.png
Normal file
BIN
tests/DpiTest/res/drawable-nodpi/logonodpi160.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.9 KiB |
BIN
tests/DpiTest/res/drawable-nodpi/logonodpi240.png
Normal file
BIN
tests/DpiTest/res/drawable-nodpi/logonodpi240.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -28,8 +28,38 @@ import android.widget.TextView;
|
||||
import android.widget.ScrollView;
|
||||
import android.view.View;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.CompatibilityInfo;
|
||||
|
||||
public class DpiTestActivity extends Activity {
|
||||
public DpiTestActivity() {
|
||||
super();
|
||||
init(false);
|
||||
}
|
||||
|
||||
public DpiTestActivity(boolean noCompat) {
|
||||
super();
|
||||
init(noCompat);
|
||||
}
|
||||
|
||||
public void init(boolean noCompat) {
|
||||
try {
|
||||
ApplicationInfo ai = getPackageManager().getApplicationInfo(
|
||||
"com.google.android.test.dpi",
|
||||
PackageManager.GET_SUPPORTS_DENSITIES);
|
||||
if (noCompat) {
|
||||
ai.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS
|
||||
| ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS
|
||||
| ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
|
||||
ai.supportsDensities = new int[] { ApplicationInfo.ANY_DENSITY };
|
||||
}
|
||||
getResources().setCompatibilityInfo(new CompatibilityInfo(ai));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
throw new RuntimeException("ouch", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -73,6 +103,13 @@ public class DpiTestActivity extends Activity {
|
||||
addLabelToRoot(root, "Autoscaled bitmap");
|
||||
addChildToRoot(root, layout);
|
||||
|
||||
layout = new LinearLayout(this);
|
||||
addResourceDrawable(layout, R.drawable.logonodpi120);
|
||||
addResourceDrawable(layout, R.drawable.logonodpi160);
|
||||
addResourceDrawable(layout, R.drawable.logonodpi240);
|
||||
addLabelToRoot(root, "No-dpi resource drawable");
|
||||
addChildToRoot(root, layout);
|
||||
|
||||
setContentView(scrollWrap(root));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed 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 com.google.android.test.dpi;
|
||||
|
||||
public class DpiTestNoCompatActivity extends DpiTestActivity {
|
||||
public DpiTestNoCompatActivity() {
|
||||
super(true);
|
||||
}
|
||||
}
|
||||
@@ -654,9 +654,15 @@ bool AaptGroupEntry::getDensityName(const char* name,
|
||||
ResTable_config* out)
|
||||
{
|
||||
if (strcmp(name, kWildcardName) == 0) {
|
||||
if (out) out->density = 0;
|
||||
if (out) out->density = ResTable_config::DENSITY_DEFAULT;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp(name, "nodpi") == 0) {
|
||||
if (out) out->density = ResTable_config::DENSITY_NONE;
|
||||
return true;
|
||||
}
|
||||
|
||||
char* c = (char*)name;
|
||||
while (*c >= '0' && *c <= '9') {
|
||||
c++;
|
||||
|
||||
@@ -286,8 +286,8 @@ public final class Bridge implements ILayoutBridge {
|
||||
}
|
||||
|
||||
return computeLayout(layoutDescription, projectKey,
|
||||
screenWidth, screenHeight, DisplayMetrics.DEFAULT_DENSITY,
|
||||
DisplayMetrics.DEFAULT_DENSITY, DisplayMetrics.DEFAULT_DENSITY,
|
||||
screenWidth, screenHeight, DisplayMetrics.DENSITY_DEFAULT,
|
||||
DisplayMetrics.DENSITY_DEFAULT, DisplayMetrics.DENSITY_DEFAULT,
|
||||
themeName, isProjectTheme,
|
||||
projectResources, frameworkResources, customViewLoader, logger);
|
||||
}
|
||||
@@ -304,8 +304,8 @@ public final class Bridge implements ILayoutBridge {
|
||||
Map<String, Map<String, IResourceValue>> frameworkResources,
|
||||
IProjectCallback customViewLoader, ILayoutLog logger) {
|
||||
return computeLayout(layoutDescription, projectKey,
|
||||
screenWidth, screenHeight, DisplayMetrics.DEFAULT_DENSITY,
|
||||
DisplayMetrics.DEFAULT_DENSITY, DisplayMetrics.DEFAULT_DENSITY,
|
||||
screenWidth, screenHeight, DisplayMetrics.DENSITY_DEFAULT,
|
||||
DisplayMetrics.DENSITY_DEFAULT, DisplayMetrics.DENSITY_DEFAULT,
|
||||
themeName, isProjectTheme,
|
||||
projectResources, frameworkResources, customViewLoader, logger);
|
||||
}
|
||||
@@ -340,7 +340,7 @@ public final class Bridge implements ILayoutBridge {
|
||||
try {
|
||||
// setup the display Metrics.
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
metrics.density = density / (float) DisplayMetrics.DEFAULT_DENSITY;
|
||||
metrics.density = density / (float) DisplayMetrics.DENSITY_DEFAULT;
|
||||
metrics.scaledDensity = metrics.density;
|
||||
metrics.widthPixels = screenWidth;
|
||||
metrics.heightPixels = screenHeight;
|
||||
|
||||
Reference in New Issue
Block a user