use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by DirtyUnicorns.
the class Resources_Delegate method getResourceValue.
private static Pair<String, ResourceValue> getResourceValue(Resources resources, int id, boolean[] platformResFlag_out) {
Pair<ResourceType, String> resourceInfo = getResourceInfo(resources, id, platformResFlag_out);
if (resourceInfo != null) {
String attributeName = resourceInfo.getSecond();
RenderResources renderResources = resources.mContext.getRenderResources();
return Pair.of(attributeName, platformResFlag_out[0] ? renderResources.getFrameworkResource(resourceInfo.getFirst(), attributeName) : renderResources.getProjectResource(resourceInfo.getFirst(), attributeName));
}
return null;
}
use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by DirtyUnicorns.
the class AppCompatActionBar method getDrawable.
// TODO: this is duplicated from FrameworkActionBarWrapper$WindowActionBarWrapper
@Nullable
private Drawable getDrawable(@NonNull String name, boolean isFramework) {
RenderResources res = mBridgeContext.getRenderResources();
ResourceValue value = res.findResValue(name, isFramework);
value = res.resolveResValue(value);
if (value != null) {
return ResourceHelper.getDrawable(value, mBridgeContext);
}
return null;
}
use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by DirtyUnicorns.
the class FrameworkActionBar method getActionBarHeight.
// TODO: This is duplicated from RenderSessionImpl.
private int getActionBarHeight() {
RenderResources resources = mBridgeContext.getRenderResources();
DisplayMetrics metrics = mBridgeContext.getMetrics();
ResourceValue value = resources.findItemInTheme("actionBarSize", true);
// resolve it
value = resources.resolveResValue(value);
if (value != null) {
// get the numerical value, if available
TypedValue typedValue = ResourceHelper.getValue("actionBarSize", value.getValue(), true);
if (typedValue != null) {
// compute the pixel value based on the display metrics
return (int) typedValue.getDimension(metrics);
}
}
return 0;
}
use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by DirtyUnicorns.
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);
}
}
}
}
}
use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by DirtyUnicorns.
the class CustomBar method getBarColor.
/**
* Find the background color for this bar from the theme attributes. Only relevant to StatusBar
* and NavigationBar.
* <p/>
* Returns 0 if not found.
*
* @param colorAttrName the attribute name for the background color
* @param translucentAttrName the attribute name for the translucency property of the bar.
*
* @throws NumberFormatException if color resolved to an invalid string.
*/
protected int getBarColor(@NonNull String colorAttrName, @NonNull String translucentAttrName) {
if (!Config.isGreaterOrEqual(mSimulatedPlatformVersion, LOLLIPOP)) {
return 0;
}
RenderResources renderResources = getContext().getRenderResources();
// First check if the bar is translucent.
boolean translucent = ResourceHelper.getBooleanThemeValue(renderResources, translucentAttrName, true, false);
if (translucent) {
// 40% black.
return 0x66000000;
}
boolean transparent = ResourceHelper.getBooleanThemeValue(renderResources, "windowDrawsSystemBarBackgrounds", true, false);
if (transparent) {
return getColor(renderResources, colorAttrName);
}
return 0;
}
Aggregations