*/
public class Resources {
static final String TAG = "Resources";
+
private static final boolean DEBUG_LOAD = false;
private static final boolean DEBUG_CONFIG = false;
private static final boolean DEBUG_ATTRIBUTES_CACHE = false;
private static final boolean TRACE_FOR_PRELOAD = false;
private static final boolean TRACE_FOR_MISS_PRELOAD = false;
+ private static final int LAYOUT_DIR_CONFIG = ActivityInfo.activityInfoConfigToNative(
+ ActivityInfo.CONFIG_LAYOUT_DIRECTION);
+
private static final int ID_OTHER = 0x01000004;
private static final Object sSync = new Object();
- /*package*/ static Resources mSystem = null;
// Information about preloaded resources. Note that they are not
// protected by a lock, because while preloading in zygote we are all
private static final LongSparseArray<ColorStateList> sPreloadedColorStateLists
= new LongSparseArray<ColorStateList>();
+ private static Resources mSystem = null;
private static boolean sPreloaded;
private static int sPreloadedDensity;
// These are protected by mAccessLock.
- /*package*/ final Object mAccessLock = new Object();
- /*package*/ final Configuration mTmpConfig = new Configuration();
- /*package*/ TypedValue mTmpValue = new TypedValue();
- /*package*/ final LongSparseArray<WeakReference<Drawable.ConstantState> > mDrawableCache
- = new LongSparseArray<WeakReference<Drawable.ConstantState> >(0);
- /*package*/ final LongSparseArray<WeakReference<ColorStateList> > mColorStateListCache
- = new LongSparseArray<WeakReference<ColorStateList> >(0);
- /*package*/ final LongSparseArray<WeakReference<Drawable.ConstantState> > mColorDrawableCache
- = new LongSparseArray<WeakReference<Drawable.ConstantState> >(0);
- /*package*/ boolean mPreloading;
+ private final Object mAccessLock = new Object();
+ private final Configuration mTmpConfig = new Configuration();
+ private final LongSparseArray<WeakReference<Drawable.ConstantState>> mDrawableCache
+ = new LongSparseArray<WeakReference<Drawable.ConstantState>>(0);
+ private final LongSparseArray<WeakReference<ColorStateList>> mColorStateListCache
+ = new LongSparseArray<WeakReference<ColorStateList>>(0);
+ private final LongSparseArray<WeakReference<Drawable.ConstantState>> mColorDrawableCache
+ = new LongSparseArray<WeakReference<Drawable.ConstantState>>(0);
- /*package*/ TypedArray mCachedStyledAttributes = null;
- RuntimeException mLastRetrievedAttrs = null;
+ private TypedValue mTmpValue = new TypedValue();
+ private boolean mPreloading;
+
+ private TypedArray mCachedStyledAttributes = null;
+ private RuntimeException mLastRetrievedAttrs = null;
private int mLastCachedXmlBlockIndex = -1;
private final int[] mCachedXmlBlockIds = { 0, 0, 0, 0 };
private final XmlBlock[] mCachedXmlBlocks = new XmlBlock[4];
- /*package*/ final AssetManager mAssets;
+ private final AssetManager mAssets;
private final Configuration mConfiguration = new Configuration();
- /*package*/ final DisplayMetrics mMetrics = new DisplayMetrics();
+ private final DisplayMetrics mMetrics = new DisplayMetrics();
private NativePluralRules mPluralRule;
private CompatibilityInfo mCompatibilityInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
return true;
}
- static private final int LAYOUT_DIR_CONFIG = ActivityInfo.activityInfoConfigToNative(
- ActivityInfo.CONFIG_LAYOUT_DIRECTION);
-
/*package*/ Drawable loadDrawable(TypedValue value, int id)
throws NotFoundException {
+ Integer.toHexString(id));
}
+ /*package*/ void recycleCachedStyledAttributes(TypedArray attrs) {
+ synchronized (mAccessLock) {
+ final TypedArray cached = mCachedStyledAttributes;
+ if (cached == null || cached.mData.length < attrs.mData.length) {
+ attrs.mXml = null;
+ mCachedStyledAttributes = attrs;
+ }
+ }
+ }
+
private TypedArray getCachedStyledAttributes(int len) {
synchronized (mAccessLock) {
TypedArray attrs = mCachedStyledAttributes;
*/
public class TypedArray {
private final Resources mResources;
+ private final DisplayMetrics mMetrics;
+ private final AssetManager mAssets;
/*package*/ XmlBlock.Parser mXml;
/*package*/ int[] mRsrcs;
/*package*/ int[] mData;
return defValue;
} else if (type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimension(
- data[index+AssetManager.STYLE_DATA], mResources.mMetrics);
+ data[index+AssetManager.STYLE_DATA], mMetrics);
}
throw new UnsupportedOperationException("Can't convert to dimension: type=0x"
return defValue;
} else if (type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelOffset(
- data[index+AssetManager.STYLE_DATA], mResources.mMetrics);
+ data[index+AssetManager.STYLE_DATA], mMetrics);
}
throw new UnsupportedOperationException("Can't convert to dimension: type=0x"
return defValue;
} else if (type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelSize(
- data[index+AssetManager.STYLE_DATA], mResources.mMetrics);
+ data[index+AssetManager.STYLE_DATA], mMetrics);
}
throw new UnsupportedOperationException("Can't convert to dimension: type=0x"
return data[index+AssetManager.STYLE_DATA];
} else if (type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelSize(
- data[index+AssetManager.STYLE_DATA], mResources.mMetrics);
+ data[index+AssetManager.STYLE_DATA], mMetrics);
}
throw new RuntimeException(getPositionDescription()
return data[index+AssetManager.STYLE_DATA];
} else if (type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelSize(
- data[index+AssetManager.STYLE_DATA], mResources.mMetrics);
+ data[index+AssetManager.STYLE_DATA], mMetrics);
}
return defValue;
* Give back a previously retrieved array, for later re-use.
*/
public void recycle() {
- synchronized (mResources.mAccessLock) {
- TypedArray cached = mResources.mCachedStyledAttributes;
- if (cached == null || cached.mData.length < mData.length) {
- mXml = null;
- mResources.mCachedStyledAttributes = this;
- }
- }
+ mResources.recycleCachedStyledAttributes(this);
}
private boolean getValueAt(int index, TypedValue outValue) {
}
return null;
}
- //System.out.println("Getting pooled from: " + v);
- return mResources.mAssets.getPooledString(
- cookie, data[index+AssetManager.STYLE_DATA]);
+ return mAssets.getPooledString(cookie, data[index+AssetManager.STYLE_DATA]);
}
/*package*/ TypedArray(Resources resources, int[] data, int[] indices, int len) {
mResources = resources;
+ mMetrics = mResources.getDisplayMetrics();
+ mAssets = mResources.getAssets();
mData = data;
mIndices = indices;
mLength = len;
}
+ @Override
public String toString() {
return Arrays.toString(mData);
}