下面列出了android.content.pm.ActivityInfo#activityInfoConfigNativeToJava() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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;
}
// Convert the changing configurations flags populated by native code.
outValue.changingConfigurations = ActivityInfo.activityInfoConfigNativeToJava(
outValue.changingConfigurations);
if (outValue.type == TypedValue.TYPE_STRING) {
return mStringBlocks[block].get(outValue.data);
}
return outValue.coerceToString();
}
}
/**
* Populates {@code outValue} with the data associated a particular
* resource identifier for the current configuration.
*
* @param resId the resource identifier to load
* @param densityDpi the density bucket for which to load the resource
* @param outValue the typed value in which to put the data
* @param resolveRefs {@code true} to resolve references, {@code false}
* to leave them unresolved
* @return {@code true} if the data was loaded into {@code outValue},
* {@code false} otherwise
*/
final boolean getResourceValue(@AnyRes int resId, int densityDpi, @NonNull TypedValue outValue,
boolean resolveRefs) {
synchronized (this) {
final int block = loadResourceValue(resId, (short) densityDpi, outValue, resolveRefs);
if (block < 0) {
return false;
}
// Convert the changing configurations flags populated by native code.
outValue.changingConfigurations = ActivityInfo.activityInfoConfigNativeToJava(
outValue.changingConfigurations);
if (outValue.type == TypedValue.TYPE_STRING) {
outValue.string = mStringBlocks[block].get(outValue.data);
}
return true;
}
}
/**
* Populates {@code outValue} with the data associated with a particular
* resource identifier for the current configuration. Resolves theme
* attributes against the specified theme.
*
* @param theme the native pointer of the theme
* @param resId the resource identifier to load
* @param outValue the typed value in which to put the data
* @param resolveRefs {@code true} to resolve references, {@code false}
* to leave them unresolved
* @return {@code true} if the data was loaded into {@code outValue},
* {@code false} otherwise
*/
final boolean getThemeValue(long theme, @AnyRes int resId, @NonNull TypedValue outValue,
boolean resolveRefs) {
final int block = loadThemeAttributeValue(theme, resId, outValue, resolveRefs);
if (block < 0) {
return false;
}
// Convert the changing configurations flags populated by native code.
outValue.changingConfigurations = ActivityInfo.activityInfoConfigNativeToJava(
outValue.changingConfigurations);
if (outValue.type == TypedValue.TYPE_STRING) {
final StringBlock[] blocks = ensureStringBlocks();
outValue.string = blocks[block].get(outValue.data);
}
return true;
}
/**
* Return a mask of the configuration parameters for which the values in
* this typed array may change.
*
* @return Returns a mask of the changing configuration parameters, as
* defined by {@link android.content.pm.ActivityInfo}.
* @throws RuntimeException if the TypedArray has already been recycled.
* @see android.content.pm.ActivityInfo
*/
public @Config int getChangingConfigurations() {
if (mRecycled) {
throw new RuntimeException("Cannot make calls to a recycled instance!");
}
@Config int changingConfig = 0;
final int[] data = mData;
final int N = length();
for (int i = 0; i < N; i++) {
final int index = i * STYLE_NUM_ENTRIES;
final int type = data[index + STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
continue;
}
changingConfig |= ActivityInfo.activityInfoConfigNativeToJava(
data[index + STYLE_CHANGING_CONFIGURATIONS]);
}
return changingConfig;
}
private boolean getValueAt(int index, TypedValue outValue) {
final int[] data = mData;
final int type = data[index + STYLE_TYPE];
if (type == TypedValue.TYPE_NULL) {
return false;
}
outValue.type = type;
outValue.data = data[index + STYLE_DATA];
outValue.assetCookie = data[index + STYLE_ASSET_COOKIE];
outValue.resourceId = data[index + STYLE_RESOURCE_ID];
outValue.changingConfigurations = ActivityInfo.activityInfoConfigNativeToJava(
data[index + STYLE_CHANGING_CONFIGURATIONS]);
outValue.density = data[index + STYLE_DENSITY];
outValue.string = (type == TypedValue.TYPE_STRING) ? loadStringValueAt(index) : null;
return true;
}
/**
* Populates {@code outValue} with the data associated a particular
* resource identifier for the current configuration.
*
* @param resId the resource identifier to load
* @param densityDpi the density bucket for which to load the resource
* @param outValue the typed value in which to put the data
* @param resolveRefs {@code true} to resolve references, {@code false}
* to leave them unresolved
* @return {@code true} if the data was loaded into {@code outValue},
* {@code false} otherwise
*/
boolean getResourceValue(@AnyRes int resId, int densityDpi, @NonNull TypedValue outValue,
boolean resolveRefs) {
Preconditions.checkNotNull(outValue, "outValue");
synchronized (this) {
ensureValidLocked();
final int cookie = nativeGetResourceValue(
mObject, resId, (short) densityDpi, outValue, resolveRefs);
if (cookie <= 0) {
return false;
}
// Convert the changing configurations flags populated by native code.
outValue.changingConfigurations = ActivityInfo.activityInfoConfigNativeToJava(
outValue.changingConfigurations);
if (outValue.type == TypedValue.TYPE_STRING) {
outValue.string = mApkAssets[cookie - 1].getStringFromPool(outValue.data);
}
return true;
}
}
/**
* Retrieves the string value associated with a particular resource
* identifier for the current configuration.
*
* @param resId the resource identifier to load
* @param bagEntryId the index into the bag to load
* @return the string value, or {@code null}
*/
@Nullable CharSequence getResourceBagText(@StringRes int resId, int bagEntryId) {
synchronized (this) {
ensureValidLocked();
final TypedValue outValue = mValue;
final int cookie = nativeGetResourceBagValue(mObject, resId, bagEntryId, outValue);
if (cookie <= 0) {
return null;
}
// Convert the changing configurations flags populated by native code.
outValue.changingConfigurations = ActivityInfo.activityInfoConfigNativeToJava(
outValue.changingConfigurations);
if (outValue.type == TypedValue.TYPE_STRING) {
return mApkAssets[cookie - 1].getStringFromPool(outValue.data);
}
return outValue.coerceToString();
}
}
/**
* Populates {@code outValue} with the data associated with a particular
* resource identifier for the current configuration. Resolves theme
* attributes against the specified theme.
*
* @param theme the native pointer of the theme
* @param resId the resource identifier to load
* @param outValue the typed value in which to put the data
* @param resolveRefs {@code true} to resolve references, {@code false}
* to leave them unresolved
* @return {@code true} if the data was loaded into {@code outValue},
* {@code false} otherwise
*/
boolean getThemeValue(long theme, @AnyRes int resId, @NonNull TypedValue outValue,
boolean resolveRefs) {
Preconditions.checkNotNull(outValue, "outValue");
synchronized (this) {
ensureValidLocked();
final int cookie = nativeThemeGetAttributeValue(mObject, theme, resId, outValue,
resolveRefs);
if (cookie <= 0) {
return false;
}
// Convert the changing configurations flags populated by native code.
outValue.changingConfigurations = ActivityInfo.activityInfoConfigNativeToJava(
outValue.changingConfigurations);
if (outValue.type == TypedValue.TYPE_STRING) {
outValue.string = mApkAssets[cookie - 1].getStringFromPool(outValue.data);
}
return true;
}
}
/**
* Retrieves the string value for the attribute at <var>index</var> that is
* not allowed to change with the given configurations.
*
* @param index Index of attribute to retrieve.
* @param allowedChangingConfigs Bit mask of configurations from
* {@link Configuration}.NATIVE_CONFIG_* that are allowed to change.
*
* @return String holding string data. Any styling information is removed.
* Returns {@code null} if the attribute is not defined.
* @throws RuntimeException if the TypedArray has already been recycled.
* @hide
*/
public String getNonConfigurationString(@StyleableRes int index,
@Config int allowedChangingConfigs) {
if (mRecycled) {
throw new RuntimeException("Cannot make calls to a recycled instance!");
}
index *= STYLE_NUM_ENTRIES;
final int[] data = mData;
final int type = data[index + STYLE_TYPE];
final @Config int changingConfigs = ActivityInfo.activityInfoConfigNativeToJava(
data[index + STYLE_CHANGING_CONFIGURATIONS]);
if ((changingConfigs & ~allowedChangingConfigs) != 0) {
return null;
}
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("getNonConfigurationString of bad type: 0x"
+ Integer.toHexString(type));
}
@Config int getChangingConfigurations() {
synchronized (mKey) {
final @NativeConfig int nativeChangingConfig =
AssetManager.nativeThemeGetChangingConfigurations(mTheme);
return ActivityInfo.activityInfoConfigNativeToJava(nativeChangingConfig);
}
}