Resourcespublic class Resources extends Object Class for accessing an application's resources. This sits on top of the
asset manager of the application (accessible through {@link #getAssets}) and
provides a high-level API for getting typed data from the assets.
The Android resource system keeps track of all non-code assets associated with an
application. You can use this class to access your application's resources. You can generally
acquire the {@link android.content.res.Resources} instance associated with your application
with {@link android.content.Context#getResources getResources()}.
The Android SDK tools compile your application's resources into the application binary
at build time. To use a resource, you must install it correctly in the source tree (inside
your project's {@code res/} directory) and build your application. As part of the build
process, the SDK tools generate symbols for each resource, which you can use in your application
code to access the resources.
Using application resources makes it easy to update various characteristics of your
application without modifying code, and—by providing sets of alternative
resources—enables you to optimize your application for a variety of device configurations
(such as for different languages and screen sizes). This is an important aspect of developing
Android applications that are compatible on different types of devices.
For more information about using resources, see the documentation about Application Resources. |
Fields Summary |
---|
static final String | TAG | private static final boolean | DEBUG_LOAD | private static final boolean | DEBUG_CONFIG | private static final boolean | TRACE_FOR_PRELOAD | private static final boolean | TRACE_FOR_MISS_PRELOAD | private static final int | LAYOUT_DIR_CONFIG | private static final int | ID_OTHER | private static final Object | sSync | private static final android.util.LongSparseArray[] | sPreloadedDrawables | private static final android.util.LongSparseArray | sPreloadedColorDrawables | private static final android.util.LongSparseArray | sPreloadedColorStateLists | final android.util.Pools.SynchronizedPool | mTypedArrayPool | static Resources | mSystem | private static boolean | sPreloaded | private static int | sPreloadedDensity | private final Object | mAccessLock | private final Configuration | mTmpConfig | private final android.util.ArrayMap | mDrawableCache | private final android.util.ArrayMap | mColorDrawableCache | private final android.util.LongSparseArray | mColorStateListCache | private final ConfigurationBoundResourceCache | mAnimatorCache | private final ConfigurationBoundResourceCache | mStateListAnimatorCache | private android.util.TypedValue | mTmpValue | private boolean | mPreloading | private TypedArray | mCachedStyledAttributes | private int | mLastCachedXmlBlockIndex | private final int[] | mCachedXmlBlockIds | private final XmlBlock[] | mCachedXmlBlocks | final AssetManager | mAssets | final android.util.DisplayMetrics | mMetrics | private final Configuration | mConfiguration | private libcore.icu.NativePluralRules | mPluralRule | private CompatibilityInfo | mCompatibilityInfo | private WeakReference | mToken |
Constructors Summary |
---|
public Resources(AssetManager assets, android.util.DisplayMetrics metrics, Configuration config)Create a new Resources object on top of an existing set of assets in an
AssetManager.
this(assets, metrics, config, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
| public Resources(AssetManager assets, android.util.DisplayMetrics metrics, Configuration config, CompatibilityInfo compatInfo, android.os.IBinder token)Creates a new Resources object with CompatibilityInfo.
mAssets = assets;
mMetrics.setToDefaults();
if (compatInfo != null) {
mCompatibilityInfo = compatInfo;
}
mToken = new WeakReference<IBinder>(token);
updateConfiguration(config, metrics);
assets.ensureStringBlocks();
| private Resources()
mAssets = AssetManager.getSystem();
// NOTE: Intentionally leaving this uninitialized (all values set
// to zero), so that anyone who tries to do something that requires
// metrics will get a very wrong value.
mConfiguration.setToDefaults();
mMetrics.setToDefaults();
updateConfiguration(null, null);
mAssets.ensureStringBlocks();
|
Methods Summary |
---|
private static java.lang.String | adjustLanguageTag(java.lang.String languageTag){@code Locale.toLanguageTag} will transform the obsolete (and deprecated)
language codes "in", "ji" and "iw" to "id", "yi" and "he" respectively.
All released versions of android prior to "L" used the deprecated language
tags, so we will need to support them for backwards compatibility.
Note that this conversion needs to take place *after* the call to
{@code toLanguageTag} because that will convert all the deprecated codes to
the new ones, even if they're set manually.
final int separator = languageTag.indexOf('-");
final String language;
final String remainder;
if (separator == -1) {
language = languageTag;
remainder = "";
} else {
language = languageTag.substring(0, separator);
remainder = languageTag.substring(separator);
}
return Locale.adjustLanguageCode(language) + remainder;
| private static int | attrForQuantityCode(int quantityCode)
switch (quantityCode) {
case NativePluralRules.ZERO: return 0x01000005;
case NativePluralRules.ONE: return 0x01000006;
case NativePluralRules.TWO: return 0x01000007;
case NativePluralRules.FEW: return 0x01000008;
case NativePluralRules.MANY: return 0x01000009;
default: return ID_OTHER;
}
| private void | cacheDrawable(android.util.TypedValue value, android.content.res.Resources$Theme theme, boolean isColorDrawable, android.util.ArrayMap caches, long key, android.graphics.drawable.Drawable dr)
final ConstantState cs = dr.getConstantState();
if (cs == null) {
return;
}
if (mPreloading) {
// Preloaded drawables never have a theme, but may be themeable.
final int changingConfigs = cs.getChangingConfigurations();
if (isColorDrawable) {
if (verifyPreloadConfig(changingConfigs, 0, value.resourceId, "drawable")) {
sPreloadedColorDrawables.put(key, cs);
}
} else {
if (verifyPreloadConfig(
changingConfigs, LAYOUT_DIR_CONFIG, value.resourceId, "drawable")) {
if ((changingConfigs & LAYOUT_DIR_CONFIG) == 0) {
// If this resource does not vary based on layout direction,
// we can put it in all of the preload maps.
sPreloadedDrawables[0].put(key, cs);
sPreloadedDrawables[1].put(key, cs);
} else {
// Otherwise, only in the layout dir we loaded it for.
sPreloadedDrawables[mConfiguration.getLayoutDirection()].put(key, cs);
}
}
}
} else {
synchronized (mAccessLock) {
final String themeKey = theme == null ? "" : theme.mKey;
LongSparseArray<WeakReference<ConstantState>> themedCache = caches.get(themeKey);
if (themedCache == null) {
themedCache = new LongSparseArray<WeakReference<ConstantState>>(1);
caches.put(themeKey, themedCache);
}
themedCache.put(key, new WeakReference<ConstantState>(cs));
}
}
| private int | calcConfigChanges(Configuration config)Called by ConfigurationBoundResourceCacheTest via reflection.
int configChanges = 0xfffffff;
if (config != null) {
mTmpConfig.setTo(config);
int density = config.densityDpi;
if (density == Configuration.DENSITY_DPI_UNDEFINED) {
density = mMetrics.noncompatDensityDpi;
}
mCompatibilityInfo.applyToConfiguration(density, mTmpConfig);
if (mTmpConfig.locale == null) {
mTmpConfig.locale = Locale.getDefault();
mTmpConfig.setLayoutDirection(mTmpConfig.locale);
}
configChanges = mConfiguration.updateFrom(mTmpConfig);
configChanges = ActivityInfo.activityInfoConfigToNative(configChanges);
}
return configChanges;
| private void | clearDrawableCacheLocked(android.util.LongSparseArray cache, int configChanges)
if (DEBUG_CONFIG) {
Log.d(TAG, "Cleaning up drawables config changes: 0x"
+ Integer.toHexString(configChanges));
}
final int N = cache.size();
for (int i = 0; i < N; i++) {
final WeakReference<ConstantState> ref = cache.valueAt(i);
if (ref != null) {
final ConstantState cs = ref.get();
if (cs != null) {
if (Configuration.needNewResources(
configChanges, cs.getChangingConfigurations())) {
if (DEBUG_CONFIG) {
Log.d(TAG, "FLUSHING #0x"
+ Long.toHexString(cache.keyAt(i))
+ " / " + cs + " with changes: 0x"
+ Integer.toHexString(cs.getChangingConfigurations()));
}
cache.setValueAt(i, null);
} else if (DEBUG_CONFIG) {
Log.d(TAG, "(Keeping #0x"
+ Long.toHexString(cache.keyAt(i))
+ " / " + cs + " with changes: 0x"
+ Integer.toHexString(cs.getChangingConfigurations())
+ ")");
}
}
}
}
| private void | clearDrawableCachesLocked(android.util.ArrayMap caches, int configChanges)
final int N = caches.size();
for (int i = 0; i < N; i++) {
clearDrawableCacheLocked(caches.valueAt(i), configChanges);
}
| public final void | finishPreloading()Called by zygote when it is done preloading resources, to change back
to normal Resources operation.
if (mPreloading) {
mPreloading = false;
flushLayoutCache();
}
| public final void | flushLayoutCache()Call this to remove all cached loaded layout resources from the
Resources object. Only intended for use with performance testing
tools.
synchronized (mCachedXmlBlockIds) {
// First see if this block is in our cache.
final int num = mCachedXmlBlockIds.length;
for (int i=0; i<num; i++) {
mCachedXmlBlockIds[i] = -0;
XmlBlock oldBlock = mCachedXmlBlocks[i];
if (oldBlock != null) {
oldBlock.close();
}
mCachedXmlBlocks[i] = null;
}
}
| public XmlResourceParser | getAnimation(int id)Return an XmlResourceParser through which you can read an animation
description for the given resource ID. This parser has limited
functionality -- in particular, you can't change its input, and only
the high-level events are available.
This function is really a simple wrapper for calling
{@link #getXml} with an animation resource.
return loadXmlResourceParser(id, "anim");
| public ConfigurationBoundResourceCache | getAnimatorCache()Used by AnimatorInflater.
return mAnimatorCache;
| public final AssetManager | getAssets()Retrieve underlying AssetManager storage for these resources.
return mAssets;
| public boolean | getBoolean(int id)Return a boolean associated with a particular resource ID. This can be
used with any integral resource value, and will return true if it is
non-zero.
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
mTmpValue = value = new TypedValue();
}
getValue(id, value, true);
if (value.type >= TypedValue.TYPE_FIRST_INT
&& value.type <= TypedValue.TYPE_LAST_INT) {
return value.data != 0;
}
throw new NotFoundException(
"Resource ID #0x" + Integer.toHexString(id) + " type #0x"
+ Integer.toHexString(value.type) + " is not valid");
}
| private ColorStateList | getCachedColorStateList(long key)
synchronized (mAccessLock) {
WeakReference<ColorStateList> wr = mColorStateListCache.get(key);
if (wr != null) { // we have the key
ColorStateList entry = wr.get();
if (entry != null) {
//Log.i(TAG, "Returning cached color state list @ #" +
// Integer.toHexString(((Integer)key).intValue())
// + " in " + this + ": " + entry);
return entry;
} else { // our entry has been purged
mColorStateListCache.delete(key);
}
}
}
return null;
| private android.graphics.drawable.Drawable | getCachedDrawable(android.util.ArrayMap caches, long key, android.content.res.Resources$Theme theme)
synchronized (mAccessLock) {
final String themeKey = theme != null ? theme.mKey : "";
final LongSparseArray<WeakReference<ConstantState>> themedCache = caches.get(themeKey);
if (themedCache != null) {
final Drawable themedDrawable = getCachedDrawableLocked(themedCache, key);
if (themedDrawable != null) {
return themedDrawable;
}
}
// No cached drawable, we'll need to create a new one.
return null;
}
| private android.graphics.drawable.Drawable | getCachedDrawableLocked(android.util.LongSparseArray drawableCache, long key)
final ConstantState entry = getConstantStateLocked(drawableCache, key);
if (entry != null) {
return entry.newDrawable(this);
}
return null;
| public int | getColor(int id)Return a color integer associated with a particular resource ID.
If the resource holds a complex
{@link android.content.res.ColorStateList}, then the default color from
the set is returned.
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
if (value == null) {
value = new TypedValue();
}
getValue(id, value, true);
if (value.type >= TypedValue.TYPE_FIRST_INT
&& value.type <= TypedValue.TYPE_LAST_INT) {
mTmpValue = value;
return value.data;
} else if (value.type != TypedValue.TYPE_STRING) {
throw new NotFoundException(
"Resource ID #0x" + Integer.toHexString(id) + " type #0x"
+ Integer.toHexString(value.type) + " is not valid");
}
mTmpValue = null;
}
ColorStateList csl = loadColorStateList(value, id);
synchronized (mAccessLock) {
if (mTmpValue == null) {
mTmpValue = value;
}
}
return csl.getDefaultColor();
| public ColorStateList | getColorStateList(int id)Return a color state list associated with a particular resource ID. The
resource may contain either a single raw color value, or a complex
{@link android.content.res.ColorStateList} holding multiple possible colors.
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
if (value == null) {
value = new TypedValue();
} else {
mTmpValue = null;
}
getValue(id, value, true);
}
ColorStateList res = loadColorStateList(value, id);
synchronized (mAccessLock) {
if (mTmpValue == null) {
mTmpValue = value;
}
}
return res;
| public CompatibilityInfo | getCompatibilityInfo()Return the compatibility mode information for the application.
The returned object should be treated as read-only.
return mCompatibilityInfo;
| public Configuration | getConfiguration()Return the current configuration that is in effect for this resource
object. The returned object should be treated as read-only.
return mConfiguration;
| private android.graphics.drawable.Drawable.ConstantState | getConstantStateLocked(android.util.LongSparseArray drawableCache, long key)
final WeakReference<ConstantState> wr = drawableCache.get(key);
if (wr != null) { // we have the key
final ConstantState entry = wr.get();
if (entry != null) {
//Log.i(TAG, "Returning cached drawable @ #" +
// Integer.toHexString(((Integer)key).intValue())
// + " in " + this + ": " + entry);
return entry;
} else { // our entry has been purged
drawableCache.delete(key);
}
}
return null;
| public float | getDimension(int id)Retrieve a dimensional for a particular resource ID. Unit
conversions are based on the current {@link DisplayMetrics} associated
with the resources.
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
mTmpValue = value = new TypedValue();
}
getValue(id, value, true);
if (value.type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimension(value.data, mMetrics);
}
throw new NotFoundException(
"Resource ID #0x" + Integer.toHexString(id) + " type #0x"
+ Integer.toHexString(value.type) + " is not valid");
}
| public int | getDimensionPixelOffset(int id)Retrieve a dimensional for a particular resource ID for use
as an offset in raw pixels. This is the same as
{@link #getDimension}, except the returned value is converted to
integer pixels for you. An offset conversion involves simply
truncating the base value to an integer.
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
mTmpValue = value = new TypedValue();
}
getValue(id, value, true);
if (value.type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelOffset(
value.data, mMetrics);
}
throw new NotFoundException(
"Resource ID #0x" + Integer.toHexString(id) + " type #0x"
+ Integer.toHexString(value.type) + " is not valid");
}
| public int | getDimensionPixelSize(int id)Retrieve a dimensional for a particular resource ID for use
as a size in raw pixels. This is the same as
{@link #getDimension}, except the returned value is converted to
integer pixels for use as a size. A size conversion involves
rounding the base value, and ensuring that a non-zero base value
is at least one pixel in size.
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
mTmpValue = value = new TypedValue();
}
getValue(id, value, true);
if (value.type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelSize(
value.data, mMetrics);
}
throw new NotFoundException(
"Resource ID #0x" + Integer.toHexString(id) + " type #0x"
+ Integer.toHexString(value.type) + " is not valid");
}
| public android.util.DisplayMetrics | getDisplayMetrics()Return the current display metrics that are in effect for this resource
object. The returned object should be treated as read-only.
if (DEBUG_CONFIG) Slog.v(TAG, "Returning DisplayMetrics: " + mMetrics.widthPixels
+ "x" + mMetrics.heightPixels + " " + mMetrics.density);
return mMetrics;
| public android.graphics.drawable.Drawable | getDrawable(int id)Return a drawable object associated with a particular resource ID.
Various types of objects will be returned depending on the underlying
resource -- for example, a solid color, PNG image, scalable image, etc.
The Drawable API hides these implementation details.
Note: Prior to
{@link android.os.Build.VERSION_CODES#JELLY_BEAN}, this function
would not correctly retrieve the final configuration density when
the resource ID passed here is an alias to another Drawable resource.
This means that if the density configuration of the alias resource
is different than the actual resource, the density of the returned
Drawable would be incorrect, resulting in bad scaling. To work
around this, you can instead retrieve the Drawable through
{@link TypedArray#getDrawable TypedArray.getDrawable}. Use
{@link android.content.Context#obtainStyledAttributes(int[])
Context.obtainStyledAttributes} with
an array containing the resource ID of interest to create the TypedArray.
Note: To obtain a themed drawable, use
{@link android.content.Context#getDrawable(int) Context.getDrawable(int)}
or {@link #getDrawable(int, Theme)} passing the desired theme.
final Drawable d = getDrawable(id, null);
if (d != null && d.canApplyTheme()) {
Log.w(TAG, "Drawable " + getResourceName(id) + " has unresolved theme "
+ "attributes! Consider using Resources.getDrawable(int, Theme) or "
+ "Context.getDrawable(int).", new RuntimeException());
}
return d;
| public android.graphics.drawable.Drawable | getDrawable(int id, android.content.res.Resources$Theme theme)Return a drawable object associated with a particular resource ID and
styled for the specified theme. Various types of objects will be
returned depending on the underlying resource -- for example, a solid
color, PNG image, scalable image, etc.
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
if (value == null) {
value = new TypedValue();
} else {
mTmpValue = null;
}
getValue(id, value, true);
}
final Drawable res = loadDrawable(value, id, theme);
synchronized (mAccessLock) {
if (mTmpValue == null) {
mTmpValue = value;
}
}
return res;
| public android.graphics.drawable.Drawable | getDrawableForDensity(int id, int density)Return a drawable object associated with a particular resource ID for the
given screen density in DPI. This will set the drawable's density to be
the device's density multiplied by the ratio of actual drawable density
to requested density. This allows the drawable to be scaled up to the
correct size if needed. Various types of objects will be returned
depending on the underlying resource -- for example, a solid color, PNG
image, scalable image, etc. The Drawable API hides these implementation
details.
Note: To obtain a themed drawable, use
{@link android.content.Context#getDrawable(int) Context.getDrawable(int)}
or {@link #getDrawableForDensity(int, int, Theme)} passing the desired
theme.
return getDrawableForDensity(id, density, null);
| public android.graphics.drawable.Drawable | getDrawableForDensity(int id, int density, android.content.res.Resources$Theme theme)Return a drawable object associated with a particular resource ID for the
given screen density in DPI and styled for the specified theme.
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
if (value == null) {
value = new TypedValue();
} else {
mTmpValue = null;
}
getValueForDensity(id, density, value, true);
/*
* Pretend the requested density is actually the display density. If
* the drawable returned is not the requested density, then force it
* to be scaled later by dividing its density by the ratio of
* requested density to actual device density. Drawables that have
* undefined density or no density don't need to be handled here.
*/
if (value.density > 0 && value.density != TypedValue.DENSITY_NONE) {
if (value.density == density) {
value.density = mMetrics.densityDpi;
} else {
value.density = (value.density * mMetrics.densityDpi) / density;
}
}
}
final Drawable res = loadDrawable(value, id, theme);
synchronized (mAccessLock) {
if (mTmpValue == null) {
mTmpValue = value;
}
}
return res;
| public float | getFloat(int id)Retrieve a floating-point value for a particular resource ID.
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
mTmpValue = value = new TypedValue();
}
getValue(id, value, true);
if (value.type == TypedValue.TYPE_FLOAT) {
return value.getFloat();
}
throw new NotFoundException("Resource ID #0x" + Integer.toHexString(id) + " type #0x"
+ Integer.toHexString(value.type) + " is not valid");
}
| public float | getFraction(int id, int base, int pbase)Retrieve a fractional unit for a particular resource ID.
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
mTmpValue = value = new TypedValue();
}
getValue(id, value, true);
if (value.type == TypedValue.TYPE_FRACTION) {
return TypedValue.complexToFraction(value.data, base, pbase);
}
throw new NotFoundException(
"Resource ID #0x" + Integer.toHexString(id) + " type #0x"
+ Integer.toHexString(value.type) + " is not valid");
}
| public int | getIdentifier(java.lang.String name, java.lang.String defType, java.lang.String defPackage)Return a resource identifier for the given resource name. A fully
qualified resource name is of the form "package:type/entry". The first
two components (package and type) are optional if defType and
defPackage, respectively, are specified here.
Note: use of this function is discouraged. It is much more
efficient to retrieve resources by identifier than by name.
if (name == null) {
throw new NullPointerException("name is null");
}
try {
return Integer.parseInt(name);
} catch (Exception e) {
// Ignore
}
return mAssets.getResourceIdentifier(name, defType, defPackage);
| public int[] | getIntArray(int id)Return the int array associated with a particular resource ID.
int[] res = mAssets.getArrayIntResource(id);
if (res != null) {
return res;
}
throw new NotFoundException("Int array resource ID #0x"
+ Integer.toHexString(id));
| public int | getInteger(int id)Return an integer associated with a particular resource ID.
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
mTmpValue = value = new TypedValue();
}
getValue(id, value, true);
if (value.type >= TypedValue.TYPE_FIRST_INT
&& value.type <= TypedValue.TYPE_LAST_INT) {
return value.data;
}
throw new NotFoundException(
"Resource ID #0x" + Integer.toHexString(id) + " type #0x"
+ Integer.toHexString(value.type) + " is not valid");
}
| public XmlResourceParser | getLayout(int id)Return an XmlResourceParser through which you can read a view layout
description for the given resource ID. This parser has limited
functionality -- in particular, you can't change its input, and only
the high-level events are available.
This function is really a simple wrapper for calling
{@link #getXml} with a layout resource.
return loadXmlResourceParser(id, "layout");
| public android.graphics.Movie | getMovie(int id)Return a movie object associated with the particular resource ID.
InputStream is = openRawResource(id);
Movie movie = Movie.decodeStream(is);
try {
is.close();
}
catch (java.io.IOException e) {
// don't care, since the return value is valid
}
return movie;
| private libcore.icu.NativePluralRules | getPluralRule()
synchronized (sSync) {
if (mPluralRule == null) {
mPluralRule = NativePluralRules.forLocale(mConfiguration.locale);
}
return mPluralRule;
}
| public android.util.LongSparseArray | getPreloadedDrawables()
return sPreloadedDrawables[0];
| public java.lang.String | getQuantityString(int id, int quantity, java.lang.Object formatArgs)Formats the string necessary for grammatically correct pluralization
of the given resource ID for the given quantity, using the given arguments.
Note that the string is selected based solely on grammatical necessity,
and that such rules differ between languages. Do not assume you know which string
will be returned for a given quantity. See
String Resources
for more detail.
Substitution of format arguments works as if using
{@link java.util.Formatter} and {@link java.lang.String#format}.
The resulting string will be stripped of any styled text information.
String raw = getQuantityText(id, quantity).toString();
return String.format(mConfiguration.locale, raw, formatArgs);
| public java.lang.String | getQuantityString(int id, int quantity)Returns the string necessary for grammatically correct pluralization
of the given resource ID for the given quantity.
Note that the string is selected based solely on grammatical necessity,
and that such rules differ between languages. Do not assume you know which string
will be returned for a given quantity. See
String Resources
for more detail.
return getQuantityText(id, quantity).toString();
| public java.lang.CharSequence | getQuantityText(int id, int quantity)Returns the character sequence necessary for grammatically correct pluralization
of the given resource ID for the given quantity.
Note that the character sequence is selected based solely on grammatical necessity,
and that such rules differ between languages. Do not assume you know which string
will be returned for a given quantity. See
String Resources
for more detail.
NativePluralRules rule = getPluralRule();
CharSequence res = mAssets.getResourceBagText(id,
attrForQuantityCode(rule.quantityForInt(quantity)));
if (res != null) {
return res;
}
res = mAssets.getResourceBagText(id, ID_OTHER);
if (res != null) {
return res;
}
throw new NotFoundException("Plural resource ID #0x" + Integer.toHexString(id)
+ " quantity=" + quantity
+ " item=" + stringForQuantityCode(rule.quantityForInt(quantity)));
| public java.lang.String | getResourceEntryName(int resid)Return the entry name for a given resource identifier.
String str = mAssets.getResourceEntryName(resid);
if (str != null) return str;
throw new NotFoundException("Unable to find resource ID #0x"
+ Integer.toHexString(resid));
| public java.lang.String | getResourceName(int resid)Return the full name for a given resource identifier. This name is
a single string of the form "package:type/entry".
String str = mAssets.getResourceName(resid);
if (str != null) return str;
throw new NotFoundException("Unable to find resource ID #0x"
+ Integer.toHexString(resid));
| public java.lang.String | getResourcePackageName(int resid)Return the package name for a given resource identifier.
String str = mAssets.getResourcePackageName(resid);
if (str != null) return str;
throw new NotFoundException("Unable to find resource ID #0x"
+ Integer.toHexString(resid));
| public java.lang.String | getResourceTypeName(int resid)Return the type name for a given resource identifier.
String str = mAssets.getResourceTypeName(resid);
if (str != null) return str;
throw new NotFoundException("Unable to find resource ID #0x"
+ Integer.toHexString(resid));
| public ConfigurationBoundResourceCache | getStateListAnimatorCache()Used by AnimatorInflater.
return mStateListAnimatorCache;
| public java.lang.String | getString(int id)Return the string value associated with a particular resource ID. It
will be stripped of any styled text information.
{@more}
CharSequence res = getText(id);
if (res != null) {
return res.toString();
}
throw new NotFoundException("String resource ID #0x"
+ Integer.toHexString(id));
| public java.lang.String | getString(int id, java.lang.Object formatArgs)Return the string value associated with a particular resource ID,
substituting the format arguments as defined in {@link java.util.Formatter}
and {@link java.lang.String#format}. It will be stripped of any styled text
information.
{@more}
String raw = getString(id);
return String.format(mConfiguration.locale, raw, formatArgs);
| public java.lang.String[] | getStringArray(int id)Return the string array associated with a particular resource ID.
String[] res = mAssets.getResourceStringArray(id);
if (res != null) {
return res;
}
throw new NotFoundException("String array resource ID #0x"
+ Integer.toHexString(id));
| public static android.content.res.Resources | getSystem()Return a global shared Resources object that provides access to only
system resources (no application resources), and is not configured for
the current screen (can not use dimension units, does not change based
on orientation, etc).
synchronized (sSync) {
Resources ret = mSystem;
if (ret == null) {
ret = new Resources();
mSystem = ret;
}
return ret;
}
| public java.lang.CharSequence | getText(int id, java.lang.CharSequence def)Return the string value associated with a particular resource ID. The
returned object will be a String if this is a plain string; it will be
some other type of CharSequence if it is styled.
CharSequence res = id != 0 ? mAssets.getResourceText(id) : null;
return res != null ? res : def;
| public java.lang.CharSequence | getText(int id)Return the string value associated with a particular resource ID. The
returned object will be a String if this is a plain string; it will be
some other type of CharSequence if it is styled.
{@more}
CharSequence res = mAssets.getResourceText(id);
if (res != null) {
return res;
}
throw new NotFoundException("String resource ID #0x"
+ Integer.toHexString(id));
| public java.lang.CharSequence[] | getTextArray(int id)Return the styled text array associated with a particular resource ID.
CharSequence[] res = mAssets.getResourceTextArray(id);
if (res != null) {
return res;
}
throw new NotFoundException("Text array resource ID #0x"
+ Integer.toHexString(id));
| public void | getValue(int id, android.util.TypedValue outValue, boolean resolveRefs)Return the raw data associated with a particular resource ID.
boolean found = mAssets.getResourceValue(id, 0, outValue, resolveRefs);
if (found) {
return;
}
throw new NotFoundException("Resource ID #0x"
+ Integer.toHexString(id));
| public void | getValue(java.lang.String name, android.util.TypedValue outValue, boolean resolveRefs)Return the raw data associated with a particular resource ID.
See getIdentifier() for information on how names are mapped to resource
IDs, and getString(int) for information on how string resources are
retrieved.
Note: use of this function is discouraged. It is much more
efficient to retrieve resources by identifier than by name.
int id = getIdentifier(name, "string", null);
if (id != 0) {
getValue(id, outValue, resolveRefs);
return;
}
throw new NotFoundException("String resource name " + name);
| public void | getValueForDensity(int id, int density, android.util.TypedValue outValue, boolean resolveRefs)Get the raw value associated with a resource with associated density.
boolean found = mAssets.getResourceValue(id, density, outValue, resolveRefs);
if (found) {
return;
}
throw new NotFoundException("Resource ID #0x" + Integer.toHexString(id));
| public XmlResourceParser | getXml(int id)Return an XmlResourceParser through which you can read a generic XML
resource for the given resource ID.
The XmlPullParser implementation returned here has some limited
functionality. In particular, you can't change its input, and only
high-level parsing events are available (since the document was
pre-parsed for you at build time, which involved merging text and
stripping comments).
return loadXmlResourceParser(id, "xml");
| ColorStateList | loadColorStateList(android.util.TypedValue value, int id)
if (TRACE_FOR_PRELOAD) {
// Log only framework resources
if ((id >>> 24) == 0x1) {
final String name = getResourceName(id);
if (name != null) android.util.Log.d("PreloadColorStateList", name);
}
}
final long key = (((long) value.assetCookie) << 32) | value.data;
ColorStateList csl;
if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
csl = sPreloadedColorStateLists.get(key);
if (csl != null) {
return csl;
}
csl = ColorStateList.valueOf(value.data);
if (mPreloading) {
if (verifyPreloadConfig(value.changingConfigurations, 0, value.resourceId,
"color")) {
sPreloadedColorStateLists.put(key, csl);
}
}
return csl;
}
csl = getCachedColorStateList(key);
if (csl != null) {
return csl;
}
csl = sPreloadedColorStateLists.get(key);
if (csl != null) {
return csl;
}
if (value.string == null) {
throw new NotFoundException(
"Resource is not a ColorStateList (color or path): " + value);
}
final String file = value.string.toString();
if (file.endsWith(".xml")) {
Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, file);
try {
final XmlResourceParser rp = loadXmlResourceParser(
file, id, value.assetCookie, "colorstatelist");
csl = ColorStateList.createFromXml(this, rp);
rp.close();
} catch (Exception e) {
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
NotFoundException rnf = new NotFoundException(
"File " + file + " from color state list resource ID #0x"
+ Integer.toHexString(id));
rnf.initCause(e);
throw rnf;
}
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
} else {
throw new NotFoundException(
"File " + file + " from drawable resource ID #0x"
+ Integer.toHexString(id) + ": .xml extension required");
}
if (csl != null) {
if (mPreloading) {
if (verifyPreloadConfig(value.changingConfigurations, 0, value.resourceId,
"color")) {
sPreloadedColorStateLists.put(key, csl);
}
} else {
synchronized (mAccessLock) {
//Log.i(TAG, "Saving cached color state list @ #" +
// Integer.toHexString(key.intValue())
// + " in " + this + ": " + csl);
mColorStateListCache.put(key, new WeakReference<ColorStateList>(csl));
}
}
}
return csl;
| android.graphics.drawable.Drawable | loadDrawable(android.util.TypedValue value, int id, android.content.res.Resources$Theme theme)
if (TRACE_FOR_PRELOAD) {
// Log only framework resources
if ((id >>> 24) == 0x1) {
final String name = getResourceName(id);
if (name != null) {
Log.d("PreloadDrawable", name);
}
}
}
final boolean isColorDrawable;
final ArrayMap<String, LongSparseArray<WeakReference<ConstantState>>> caches;
final long key;
if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT
&& value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
isColorDrawable = true;
caches = mColorDrawableCache;
key = value.data;
} else {
isColorDrawable = false;
caches = mDrawableCache;
key = (((long) value.assetCookie) << 32) | value.data;
}
// First, check whether we have a cached version of this drawable
// that was inflated against the specified theme.
if (!mPreloading) {
final Drawable cachedDrawable = getCachedDrawable(caches, key, theme);
if (cachedDrawable != null) {
return cachedDrawable;
}
}
// Next, check preloaded drawables. These are unthemed but may have
// themeable attributes.
final ConstantState cs;
if (isColorDrawable) {
cs = sPreloadedColorDrawables.get(key);
} else {
cs = sPreloadedDrawables[mConfiguration.getLayoutDirection()].get(key);
}
final Drawable dr;
if (cs != null) {
final Drawable clonedDr = cs.newDrawable(this);
if (theme != null) {
dr = clonedDr.mutate();
dr.applyTheme(theme);
dr.clearMutated();
} else {
dr = clonedDr;
}
} else if (isColorDrawable) {
dr = new ColorDrawable(value.data);
} else {
dr = loadDrawableForCookie(value, id, theme);
}
// If we were able to obtain a drawable, store it in the appropriate
// cache (either preload or themed).
if (dr != null) {
dr.setChangingConfigurations(value.changingConfigurations);
cacheDrawable(value, theme, isColorDrawable, caches, key, dr);
}
return dr;
| private android.graphics.drawable.Drawable | loadDrawableForCookie(android.util.TypedValue value, int id, android.content.res.Resources$Theme theme)Loads a drawable from XML or resources stream.
if (value.string == null) {
throw new NotFoundException("Resource \"" + getResourceName(id) + "\" ("
+ Integer.toHexString(id) + ") is not a Drawable (color or path): " + value);
}
final String file = value.string.toString();
if (TRACE_FOR_MISS_PRELOAD) {
// Log only framework resources
if ((id >>> 24) == 0x1) {
final String name = getResourceName(id);
if (name != null) {
Log.d(TAG, "Loading framework drawable #" + Integer.toHexString(id)
+ ": " + name + " at " + file);
}
}
}
if (DEBUG_LOAD) {
Log.v(TAG, "Loading drawable for cookie " + value.assetCookie + ": " + file);
}
final Drawable dr;
Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, file);
try {
if (file.endsWith(".xml")) {
final XmlResourceParser rp = loadXmlResourceParser(
file, id, value.assetCookie, "drawable");
dr = Drawable.createFromXml(this, rp, theme);
rp.close();
} else {
final InputStream is = mAssets.openNonAsset(
value.assetCookie, file, AssetManager.ACCESS_STREAMING);
dr = Drawable.createFromResourceStream(this, value, is, file, null);
is.close();
}
} catch (Exception e) {
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
final NotFoundException rnf = new NotFoundException(
"File " + file + " from drawable resource ID #0x" + Integer.toHexString(id));
rnf.initCause(e);
throw rnf;
}
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
return dr;
| XmlResourceParser | loadXmlResourceParser(int id, java.lang.String type)
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
mTmpValue = value = new TypedValue();
}
getValue(id, value, true);
if (value.type == TypedValue.TYPE_STRING) {
return loadXmlResourceParser(value.string.toString(), id,
value.assetCookie, type);
}
throw new NotFoundException(
"Resource ID #0x" + Integer.toHexString(id) + " type #0x"
+ Integer.toHexString(value.type) + " is not valid");
}
| XmlResourceParser | loadXmlResourceParser(java.lang.String file, int id, int assetCookie, java.lang.String type)
if (id != 0) {
try {
// These may be compiled...
synchronized (mCachedXmlBlockIds) {
// First see if this block is in our cache.
final int num = mCachedXmlBlockIds.length;
for (int i=0; i<num; i++) {
if (mCachedXmlBlockIds[i] == id) {
//System.out.println("**** REUSING XML BLOCK! id="
// + id + ", index=" + i);
return mCachedXmlBlocks[i].newParser();
}
}
// Not in the cache, create a new block and put it at
// the next slot in the cache.
XmlBlock block = mAssets.openXmlBlockAsset(
assetCookie, file);
if (block != null) {
int pos = mLastCachedXmlBlockIndex+1;
if (pos >= num) pos = 0;
mLastCachedXmlBlockIndex = pos;
XmlBlock oldBlock = mCachedXmlBlocks[pos];
if (oldBlock != null) {
oldBlock.close();
}
mCachedXmlBlockIds[pos] = id;
mCachedXmlBlocks[pos] = block;
//System.out.println("**** CACHING NEW XML BLOCK! id="
// + id + ", index=" + pos);
return block.newParser();
}
}
} catch (Exception e) {
NotFoundException rnf = new NotFoundException(
"File " + file + " from xml type " + type + " resource ID #0x"
+ Integer.toHexString(id));
rnf.initCause(e);
throw rnf;
}
}
throw new NotFoundException(
"File " + file + " from xml type " + type + " resource ID #0x"
+ Integer.toHexString(id));
| public final android.content.res.Resources$Theme | newTheme()Generate a new Theme object for this set of Resources. It initially
starts out empty.
return new Theme();
| public TypedArray | obtainAttributes(android.util.AttributeSet set, int[] attrs)Retrieve a set of basic attribute values from an AttributeSet, not
performing styling of them using a theme and/or style resources.
int len = attrs.length;
TypedArray array = TypedArray.obtain(this, len);
// XXX note that for now we only work with compiled XML files.
// To support generic XML files we will need to manually parse
// out the attributes from the XML file (applying type information
// contained in the resources and such).
XmlBlock.Parser parser = (XmlBlock.Parser)set;
mAssets.retrieveAttributes(parser.mParseState, attrs,
array.mData, array.mIndices);
array.mXml = parser;
return array;
| public TypedArray | obtainTypedArray(int id)Return an array of heterogeneous values.
int len = mAssets.getArraySize(id);
if (len < 0) {
throw new NotFoundException("Array resource ID #0x"
+ Integer.toHexString(id));
}
TypedArray array = TypedArray.obtain(this, len);
array.mLength = mAssets.retrieveArray(id, array.mData);
array.mIndices[0] = 0;
return array;
| public java.io.InputStream | openRawResource(int id)Open a data stream for reading a raw resource. This can only be used
with resources whose value is the name of an asset files -- that is, it can be
used to open drawable, sound, and raw resources; it will fail on string
and color resources.
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
if (value == null) {
value = new TypedValue();
} else {
mTmpValue = null;
}
}
InputStream res = openRawResource(id, value);
synchronized (mAccessLock) {
if (mTmpValue == null) {
mTmpValue = value;
}
}
return res;
| public java.io.InputStream | openRawResource(int id, android.util.TypedValue value)Open a data stream for reading a raw resource. This can only be used
with resources whose value is the name of an asset file -- that is, it can be
used to open drawable, sound, and raw resources; it will fail on string
and color resources.
getValue(id, value, true);
try {
return mAssets.openNonAsset(value.assetCookie, value.string.toString(),
AssetManager.ACCESS_STREAMING);
} catch (Exception e) {
NotFoundException rnf = new NotFoundException("File " + value.string.toString() +
" from drawable resource ID #0x" + Integer.toHexString(id));
rnf.initCause(e);
throw rnf;
}
| public AssetFileDescriptor | openRawResourceFd(int id)Open a file descriptor for reading a raw resource. This can only be used
with resources whose value is the name of an asset files -- that is, it can be
used to open drawable, sound, and raw resources; it will fail on string
and color resources.
This function only works for resources that are stored in the package
as uncompressed data, which typically includes things like mp3 files
and png images.
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
if (value == null) {
value = new TypedValue();
} else {
mTmpValue = null;
}
getValue(id, value, true);
}
try {
return mAssets.openNonAssetFd(
value.assetCookie, value.string.toString());
} catch (Exception e) {
NotFoundException rnf = new NotFoundException(
"File " + value.string.toString()
+ " from drawable resource ID #0x"
+ Integer.toHexString(id));
rnf.initCause(e);
throw rnf;
} finally {
synchronized (mAccessLock) {
if (mTmpValue == null) {
mTmpValue = value;
}
}
}
| public void | parseBundleExtra(java.lang.String tagName, android.util.AttributeSet attrs, android.os.Bundle outBundle)Parse a name/value pair out of an XML tag holding that data. The
AttributeSet must be holding the data defined by
{@link android.R.styleable#Extra}. The following value types are supported:
- {@link TypedValue#TYPE_STRING}:
{@link Bundle#putCharSequence Bundle.putCharSequence()}
- {@link TypedValue#TYPE_INT_BOOLEAN}:
{@link Bundle#putCharSequence Bundle.putBoolean()}
- {@link TypedValue#TYPE_FIRST_INT}-{@link TypedValue#TYPE_LAST_INT}:
{@link Bundle#putCharSequence Bundle.putBoolean()}
- {@link TypedValue#TYPE_FLOAT}:
{@link Bundle#putCharSequence Bundle.putFloat()}
TypedArray sa = obtainAttributes(attrs,
com.android.internal.R.styleable.Extra);
String name = sa.getString(
com.android.internal.R.styleable.Extra_name);
if (name == null) {
sa.recycle();
throw new XmlPullParserException("<" + tagName
+ "> requires an android:name attribute at "
+ attrs.getPositionDescription());
}
TypedValue v = sa.peekValue(
com.android.internal.R.styleable.Extra_value);
if (v != null) {
if (v.type == TypedValue.TYPE_STRING) {
CharSequence cs = v.coerceToString();
outBundle.putCharSequence(name, cs);
} else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
outBundle.putBoolean(name, v.data != 0);
} else if (v.type >= TypedValue.TYPE_FIRST_INT
&& v.type <= TypedValue.TYPE_LAST_INT) {
outBundle.putInt(name, v.data);
} else if (v.type == TypedValue.TYPE_FLOAT) {
outBundle.putFloat(name, v.getFloat());
} else {
sa.recycle();
throw new XmlPullParserException("<" + tagName
+ "> only supports string, integer, float, color, and boolean at "
+ attrs.getPositionDescription());
}
} else {
sa.recycle();
throw new XmlPullParserException("<" + tagName
+ "> requires an android:value or android:resource attribute at "
+ attrs.getPositionDescription());
}
sa.recycle();
| public void | parseBundleExtras(XmlResourceParser parser, android.os.Bundle outBundle)Parse a series of {@link android.R.styleable#Extra <extra>} tags from
an XML file. You call this when you are at the parent tag of the
extra tags, and it will return once all of the child tags have been parsed.
This will call {@link #parseBundleExtra} for each extra tag encountered.
int outerDepth = parser.getDepth();
int type;
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
continue;
}
String nodeName = parser.getName();
if (nodeName.equals("extra")) {
parseBundleExtra("extra", parser, outBundle);
XmlUtils.skipCurrentTag(parser);
} else {
XmlUtils.skipCurrentTag(parser);
}
}
| void | recycleCachedStyledAttributes(TypedArray attrs)
synchronized (mAccessLock) {
final TypedArray cached = mCachedStyledAttributes;
if (cached == null || cached.mData.length < attrs.mData.length) {
mCachedStyledAttributes = attrs;
}
}
| public static boolean | resourceHasPackage(int resid)Return true if given resource identifier includes a package.
return (resid >>> 24) != 0;
| public static int | selectDefaultTheme(int curTheme, int targetSdkVersion)Returns the most appropriate default theme for the specified target SDK version.
- Below API 11: Gingerbread
- APIs 11 thru 14: Holo
- APIs 14 thru XX: Device default dark
- API XX and above: Device default light with dark action bar
sPreloadedDrawables = new LongSparseArray[2];
sPreloadedDrawables[0] = new LongSparseArray<ConstantState>();
sPreloadedDrawables[1] = new LongSparseArray<ConstantState>();
return selectSystemTheme(curTheme, targetSdkVersion,
com.android.internal.R.style.Theme,
com.android.internal.R.style.Theme_Holo,
com.android.internal.R.style.Theme_DeviceDefault,
com.android.internal.R.style.Theme_DeviceDefault_Light_DarkActionBar);
| public static int | selectSystemTheme(int curTheme, int targetSdkVersion, int orig, int holo, int dark, int deviceDefault)
if (curTheme != 0) {
return curTheme;
}
if (targetSdkVersion < Build.VERSION_CODES.HONEYCOMB) {
return orig;
}
if (targetSdkVersion < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
return holo;
}
if (targetSdkVersion < Build.VERSION_CODES.CUR_DEVELOPMENT) {
return dark;
}
return deviceDefault;
| public void | setCompatibilityInfo(CompatibilityInfo ci)This is just for testing.
if (ci != null) {
mCompatibilityInfo = ci;
updateConfiguration(mConfiguration, mMetrics);
}
| public final void | startPreloading()Start preloading of resource data using this Resources object. Only
for use by the zygote process for loading common system resources.
{@hide}
synchronized (sSync) {
if (sPreloaded) {
throw new IllegalStateException("Resources already preloaded");
}
sPreloaded = true;
mPreloading = true;
sPreloadedDensity = DisplayMetrics.DENSITY_DEVICE;
mConfiguration.densityDpi = sPreloadedDensity;
updateConfiguration(null, null);
}
| private static java.lang.String | stringForQuantityCode(int quantityCode)
switch (quantityCode) {
case NativePluralRules.ZERO: return "zero";
case NativePluralRules.ONE: return "one";
case NativePluralRules.TWO: return "two";
case NativePluralRules.FEW: return "few";
case NativePluralRules.MANY: return "many";
default: return "other";
}
| public void | updateConfiguration(Configuration config, android.util.DisplayMetrics metrics)Store the newly updated configuration.
updateConfiguration(config, metrics, null);
| public void | updateConfiguration(Configuration config, android.util.DisplayMetrics metrics, CompatibilityInfo compat)
synchronized (mAccessLock) {
if (false) {
Slog.i(TAG, "**** Updating config of " + this + ": old config is "
+ mConfiguration + " old compat is " + mCompatibilityInfo);
Slog.i(TAG, "**** Updating config of " + this + ": new config is "
+ config + " new compat is " + compat);
}
if (compat != null) {
mCompatibilityInfo = compat;
}
if (metrics != null) {
mMetrics.setTo(metrics);
}
// NOTE: We should re-arrange this code to create a Display
// with the CompatibilityInfo that is used everywhere we deal
// with the display in relation to this app, rather than
// doing the conversion here. This impl should be okay because
// we make sure to return a compatible display in the places
// where there are public APIs to retrieve the display... but
// it would be cleaner and more maintainble to just be
// consistently dealing with a compatible display everywhere in
// the framework.
mCompatibilityInfo.applyToDisplayMetrics(mMetrics);
int configChanges = calcConfigChanges(config);
if (mConfiguration.locale == null) {
mConfiguration.locale = Locale.getDefault();
mConfiguration.setLayoutDirection(mConfiguration.locale);
}
if (mConfiguration.densityDpi != Configuration.DENSITY_DPI_UNDEFINED) {
mMetrics.densityDpi = mConfiguration.densityDpi;
mMetrics.density = mConfiguration.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
}
mMetrics.scaledDensity = mMetrics.density * mConfiguration.fontScale;
String locale = null;
if (mConfiguration.locale != null) {
locale = adjustLanguageTag(mConfiguration.locale.toLanguageTag());
}
int width, height;
if (mMetrics.widthPixels >= mMetrics.heightPixels) {
width = mMetrics.widthPixels;
height = mMetrics.heightPixels;
} else {
//noinspection SuspiciousNameCombination
width = mMetrics.heightPixels;
//noinspection SuspiciousNameCombination
height = mMetrics.widthPixels;
}
int keyboardHidden = mConfiguration.keyboardHidden;
if (keyboardHidden == Configuration.KEYBOARDHIDDEN_NO
&& mConfiguration.hardKeyboardHidden
== Configuration.HARDKEYBOARDHIDDEN_YES) {
keyboardHidden = Configuration.KEYBOARDHIDDEN_SOFT;
}
mAssets.setConfiguration(mConfiguration.mcc, mConfiguration.mnc,
locale, mConfiguration.orientation,
mConfiguration.touchscreen,
mConfiguration.densityDpi, mConfiguration.keyboard,
keyboardHidden, mConfiguration.navigation, width, height,
mConfiguration.smallestScreenWidthDp,
mConfiguration.screenWidthDp, mConfiguration.screenHeightDp,
mConfiguration.screenLayout, mConfiguration.uiMode,
Build.VERSION.RESOURCES_SDK_INT);
if (DEBUG_CONFIG) {
Slog.i(TAG, "**** Updating config of " + this + ": final config is " + mConfiguration
+ " final compat is " + mCompatibilityInfo);
}
clearDrawableCachesLocked(mDrawableCache, configChanges);
clearDrawableCachesLocked(mColorDrawableCache, configChanges);
mAnimatorCache.onConfigurationChange(configChanges);
mStateListAnimatorCache.onConfigurationChange(configChanges);
mColorStateListCache.clear();
flushLayoutCache();
}
synchronized (sSync) {
if (mPluralRule != null) {
mPluralRule = NativePluralRules.forLocale(config.locale);
}
}
| public static void | updateSystemConfiguration(Configuration config, android.util.DisplayMetrics metrics, CompatibilityInfo compat)Update the system resources configuration if they have previously
been initialized.
if (mSystem != null) {
mSystem.updateConfiguration(config, metrics, compat);
//Log.i(TAG, "Updated system resources " + mSystem
// + ": " + mSystem.getConfiguration());
}
| private boolean | verifyPreloadConfig(int changingConfigurations, int allowVarying, int resourceId, java.lang.String name)
// We allow preloading of resources even if they vary by font scale (which
// doesn't impact resource selection) or density (which we handle specially by
// simply turning off all preloading), as well as any other configs specified
// by the caller.
if (((changingConfigurations&~(ActivityInfo.CONFIG_FONT_SCALE |
ActivityInfo.CONFIG_DENSITY)) & ~allowVarying) != 0) {
String resName;
try {
resName = getResourceName(resourceId);
} catch (NotFoundException e) {
resName = "?";
}
// This should never happen in production, so we should log a
// warning even if we're not debugging.
Log.w(TAG, "Preloaded " + name + " resource #0x"
+ Integer.toHexString(resourceId)
+ " (" + resName + ") that varies with configuration!!");
return false;
}
if (TRACE_FOR_PRELOAD) {
String resName;
try {
resName = getResourceName(resourceId);
} catch (NotFoundException e) {
resName = "?";
}
Log.w(TAG, "Preloading " + name + " resource #0x"
+ Integer.toHexString(resourceId)
+ " (" + resName + ")");
}
return true;
|
|