use of android.annotation.Nullable in project android_frameworks_base by DirtyUnicorns.
the class ResourcesImpl method loadComplexColor.
@Nullable
ComplexColor loadComplexColor(Resources wrapper, @NonNull TypedValue value, int id, Resources.Theme theme) {
if (TRACE_FOR_PRELOAD) {
// Log only framework resources
if ((id >>> 24) == 0x1) {
final String name = getResourceName(id);
if (name != null)
android.util.Log.d("loadComplexColor", name);
}
}
final long key = (((long) value.assetCookie) << 32) | value.data;
// Handle inline color definitions.
if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
return getColorStateListFromInt(value, key);
}
final String file = value.string.toString();
ComplexColor complexColor;
if (file.endsWith(".xml")) {
try {
complexColor = loadComplexColorFromName(wrapper, theme, value, id);
} catch (Exception e) {
final NotFoundException rnf = new NotFoundException("File " + file + " from complex color resource ID #0x" + Integer.toHexString(id));
rnf.initCause(e);
throw rnf;
}
} else {
throw new NotFoundException("File " + file + " from drawable resource ID #0x" + Integer.toHexString(id) + ": .xml extension required");
}
return complexColor;
}
use of android.annotation.Nullable in project android_frameworks_base by DirtyUnicorns.
the class AssetManager method getResourceBagText.
/**
* Retrieves the string value associated with a particular resource
* identifier for the current configuration.
*
* @param resId the resource identifier to load
* @param bagEntryId
* @return the string value, or {@code null}
*/
@Nullable
final CharSequence getResourceBagText(@StringRes int resId, int bagEntryId) {
synchronized (this) {
final TypedValue outValue = mValue;
final int block = loadResourceBagValue(resId, bagEntryId, outValue, true);
if (block < 0) {
return null;
}
if (outValue.type == TypedValue.TYPE_STRING) {
return mStringBlocks[block].get(outValue.data);
}
return outValue.coerceToString();
}
}
use of android.annotation.Nullable in project android_frameworks_base by DirtyUnicorns.
the class ResourcesImpl method loadDrawable.
@Nullable
Drawable loadDrawable(Resources wrapper, TypedValue value, int id, Resources.Theme theme, boolean useCache) throws NotFoundException {
try {
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 DrawableCache 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;
}
// we're currently preloading or we're not using the cache.
if (!mPreloading && useCache) {
final Drawable cachedDrawable = caches.getInstance(key, wrapper, theme);
if (cachedDrawable != null) {
return cachedDrawable;
}
}
// Next, check preloaded drawables. Preloaded drawables may contain
// unresolved theme attributes.
final Drawable.ConstantState cs;
if (isColorDrawable) {
cs = sPreloadedColorDrawables.get(key);
} else {
cs = sPreloadedDrawables[mConfiguration.getLayoutDirection()].get(key);
}
Drawable dr;
if (cs != null) {
dr = cs.newDrawable(wrapper);
} else if (isColorDrawable) {
dr = new ColorDrawable(value.data);
} else {
dr = loadDrawableForCookie(wrapper, value, id, null);
}
// Determine if the drawable has unresolved theme attributes. If it
// does, we'll need to apply a theme and store it in a theme-specific
// cache.
final boolean canApplyTheme = dr != null && dr.canApplyTheme();
if (canApplyTheme && theme != null) {
dr = dr.mutate();
dr.applyTheme(theme);
dr.clearMutated();
}
// pollute the cache with drawables loaded from a foreign density.
if (dr != null && useCache) {
dr.setChangingConfigurations(value.changingConfigurations);
cacheDrawable(value, isColorDrawable, caches, theme, canApplyTheme, key, dr);
}
return dr;
} catch (Exception e) {
String name;
try {
name = getResourceName(id);
} catch (NotFoundException e2) {
name = "(missing name)";
}
// The target drawable might fail to load for any number of
// reasons, but we always want to include the resource name.
// Since the client already expects this method to throw a
// NotFoundException, just throw one of those.
final NotFoundException nfe = new NotFoundException("Drawable " + name + " with resource ID #0x" + Integer.toHexString(id), e);
nfe.setStackTrace(new StackTraceElement[0]);
throw nfe;
}
}
use of android.annotation.Nullable in project android_frameworks_base by DirtyUnicorns.
the class ThemedResourceCache method getThemedLocked.
/**
* Returns the cached data for the specified theme, optionally creating a
* new entry if one does not already exist.
*
* @param t the theme for which to return cached data
* @param create {@code true} to create an entry if one does not already
* exist, {@code false} otherwise
* @return the cached data for the theme, or {@code null} if the cache is
* empty and {@code create} was {@code false}
*/
@Nullable
private LongSparseArray<WeakReference<T>> getThemedLocked(@Nullable Theme t, boolean create) {
if (t == null) {
if (mNullThemedEntries == null && create) {
mNullThemedEntries = new LongSparseArray<>(1);
}
return mNullThemedEntries;
}
if (mThemedEntries == null) {
if (create) {
mThemedEntries = new ArrayMap<>(1);
} else {
return null;
}
}
final ThemeKey key = t.getKey();
LongSparseArray<WeakReference<T>> cache = mThemedEntries.get(key);
if (cache == null && create) {
cache = new LongSparseArray<>(1);
final ThemeKey keyClone = key.clone();
mThemedEntries.put(keyClone, cache);
}
return cache;
}
use of android.annotation.Nullable in project android_frameworks_base by DirtyUnicorns.
the class TypedArray method getString.
/**
* Retrieves the string value for the attribute at <var>index</var>.
* <p>
* If the attribute is not a string, this method will attempt to coerce
* it to a string.
*
* @param index Index of attribute to retrieve.
*
* @return String holding string data. Any styling information is removed.
* Returns {@code null} if the attribute is not defined or could
* not be coerced to a string.
* @throws RuntimeException if the TypedArray has already been recycled.
*/
@Nullable
public String getString(@StyleableRes int index) {
if (mRecycled) {
throw new RuntimeException("Cannot make calls to a recycled instance!");
}
index *= AssetManager.STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index + AssetManager.STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return null;
} else if (type == TypedValue.TYPE_STRING) {
return loadStringValueAt(index).toString();
}
final TypedValue v = mValue;
if (getValueAt(index, v)) {
final CharSequence cs = v.coerceToString();
return cs != null ? cs.toString() : null;
}
// We already checked for TYPE_NULL. This should never happen.
throw new RuntimeException("getString of bad type: 0x" + Integer.toHexString(type));
}
Aggregations