use of com.android.ide.common.rendering.api.StyleResourceValue in project android_frameworks_base by crdroidandroid.
the class BridgeContext method resolveThemeAttribute.
public boolean resolveThemeAttribute(int resId, TypedValue outValue, boolean resolveRefs) {
Pair<ResourceType, String> resourceInfo = Bridge.resolveResourceId(resId);
boolean isFrameworkRes = true;
if (resourceInfo == null) {
resourceInfo = mLayoutlibCallback.resolveResourceId(resId);
isFrameworkRes = false;
}
if (resourceInfo == null) {
return false;
}
ResourceValue value = mRenderResources.findItemInTheme(resourceInfo.getSecond(), isFrameworkRes);
if (resolveRefs) {
value = mRenderResources.resolveResValue(value);
}
if (value == null) {
// unable to find the attribute.
return false;
}
// check if this is a style resource
if (value instanceof StyleResourceValue) {
// get the id that will represent this style.
outValue.resourceId = getDynamicIdByStyle((StyleResourceValue) value);
return true;
}
int a;
// if this is a framework value.
if (value.isFramework()) {
// look for idName in the android R classes.
// use 0 a default res value as it's not a valid id value.
a = getFrameworkResourceValue(value.getResourceType(), value.getName(), 0);
} else {
// look for idName in the project R class.
// use 0 a default res value as it's not a valid id value.
a = getProjectResourceValue(value.getResourceType(), value.getName(), 0);
}
if (a != 0) {
outValue.resourceId = a;
return true;
}
return false;
}
use of com.android.ide.common.rendering.api.StyleResourceValue in project android_frameworks_base by crdroidandroid.
the class BridgeContext method createStyleBasedTypedArray.
// ------------- private new methods
/**
* Creates a {@link BridgeTypedArray} by filling the values defined by the int[] with the
* values found in the given style. If no style is specified, the default theme, along with the
* styles applied to it are used.
*
* @see #obtainStyledAttributes(int, int[])
*/
private Pair<BridgeTypedArray, PropertiesMap> createStyleBasedTypedArray(@Nullable StyleResourceValue style, int[] attrs) throws Resources.NotFoundException {
List<Pair<String, Boolean>> attributes = searchAttrs(attrs);
BridgeTypedArray ta = Resources_Delegate.newTypeArray(mSystemResources, attrs.length, false);
PropertiesMap defaultPropMap = new PropertiesMap();
// for each attribute, get its name so that we can search it in the style
for (int i = 0; i < attrs.length; i++) {
Pair<String, Boolean> attribute = attributes.get(i);
if (attribute != null) {
// look for the value in the given style
ResourceValue resValue;
String attrName = attribute.getFirst();
boolean frameworkAttr = attribute.getSecond();
if (style != null) {
resValue = mRenderResources.findItemInStyle(style, attrName, frameworkAttr);
} else {
resValue = mRenderResources.findItemInTheme(attrName, frameworkAttr);
}
if (resValue != null) {
// Add it to defaultPropMap before resolving
String preResolve = resValue.getValue();
// resolve it to make sure there are no references left.
resValue = mRenderResources.resolveResValue(resValue);
ta.bridgeSetValue(i, attrName, frameworkAttr, resValue);
defaultPropMap.put(frameworkAttr ? SdkConstants.ANDROID_PREFIX + attrName : attrName, new Property(preResolve, resValue.getValue()));
}
}
}
ta.sealArray();
return Pair.of(ta, defaultPropMap);
}
use of com.android.ide.common.rendering.api.StyleResourceValue in project android_frameworks_base by crdroidandroid.
the class AppCompatActionBar method getInflater.
@Override
protected LayoutInflater getInflater(BridgeContext context) {
// Other than the resource resolution part, the code has been taken from the support
// library. see code from line 269 onwards in
// https://android.googlesource.com/platform/frameworks/support/+/android-5.1.0_r1/v7/appcompat/src/android/support/v7/app/ActionBarActivityDelegateBase.java
Context themedContext = context;
RenderResources resources = context.getRenderResources();
ResourceValue actionBarTheme = resources.findItemInTheme("actionBarTheme", false);
if (actionBarTheme != null) {
// resolve it, if needed.
actionBarTheme = resources.resolveResValue(actionBarTheme);
}
if (actionBarTheme instanceof StyleResourceValue) {
int styleId = context.getDynamicIdByStyle(((StyleResourceValue) actionBarTheme));
if (styleId != 0) {
themedContext = new ContextThemeWrapper(context, styleId);
}
}
return LayoutInflater.from(themedContext);
}
use of com.android.ide.common.rendering.api.StyleResourceValue in project android_frameworks_base by crdroidandroid.
the class CustomBar method setStyle.
protected void setStyle(String themeEntryName) {
BridgeContext bridgeContext = getContext();
RenderResources res = bridgeContext.getRenderResources();
ResourceValue value = res.findItemInTheme(themeEntryName, true);
value = res.resolveResValue(value);
if (!(value instanceof StyleResourceValue)) {
return;
}
StyleResourceValue style = (StyleResourceValue) value;
// get the background
ResourceValue backgroundValue = res.findItemInStyle(style, "background", true);
backgroundValue = res.resolveResValue(backgroundValue);
if (backgroundValue != null) {
Drawable d = ResourceHelper.getDrawable(backgroundValue, bridgeContext);
if (d != null) {
setBackground(d);
}
}
TextView textView = getStyleableTextView();
if (textView != null) {
// get the text style
ResourceValue textStyleValue = res.findItemInStyle(style, "titleTextStyle", true);
textStyleValue = res.resolveResValue(textStyleValue);
if (textStyleValue instanceof StyleResourceValue) {
StyleResourceValue textStyle = (StyleResourceValue) textStyleValue;
ResourceValue textSize = res.findItemInStyle(textStyle, "textSize", true);
textSize = res.resolveResValue(textSize);
if (textSize != null) {
TypedValue out = new TypedValue();
if (ResourceHelper.parseFloatAttribute("textSize", textSize.getValue(), out, true)) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, out.getDimension(bridgeContext.getResources().getDisplayMetrics()));
}
}
ResourceValue textColor = res.findItemInStyle(textStyle, "textColor", true);
textColor = res.resolveResValue(textColor);
if (textColor != null) {
ColorStateList stateList = ResourceHelper.getColorStateList(textColor, bridgeContext);
if (stateList != null) {
textView.setTextColor(stateList);
}
}
}
}
}
Aggregations