use of com.android.ide.common.rendering.api.RenderResources 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);
}
}
}
}
}
use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by crdroidandroid.
the class CustomBar method getResourceValue.
private ResourceValue getResourceValue(String reference) {
RenderResources res = getContext().getRenderResources();
// find the resource
ResourceValue value = res.findResValue(reference, false);
// resolve it if needed
return res.resolveResValue(value);
}
use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by crdroidandroid.
the class RenderAction method init.
/**
* Initializes and acquires the scene, creating various Android objects such as context,
* inflater, and parser.
*
* @param timeout the time to wait if another rendering is happening.
*
* @return whether the scene was prepared
*
* @see #acquire(long)
* @see #release()
*/
public Result init(long timeout) {
// acquire the lock. if the result is null, lock was just acquired, otherwise, return
// the result.
Result result = acquireLock(timeout);
if (result != null) {
return result;
}
HardwareConfig hardwareConfig = mParams.getHardwareConfig();
// setup the display Metrics.
DisplayMetrics metrics = new DisplayMetrics();
metrics.densityDpi = metrics.noncompatDensityDpi = hardwareConfig.getDensity().getDpiValue();
metrics.density = metrics.noncompatDensity = metrics.densityDpi / (float) DisplayMetrics.DENSITY_DEFAULT;
metrics.scaledDensity = metrics.noncompatScaledDensity = metrics.density;
metrics.widthPixels = metrics.noncompatWidthPixels = hardwareConfig.getScreenWidth();
metrics.heightPixels = metrics.noncompatHeightPixels = hardwareConfig.getScreenHeight();
metrics.xdpi = metrics.noncompatXdpi = hardwareConfig.getXdpi();
metrics.ydpi = metrics.noncompatYdpi = hardwareConfig.getYdpi();
RenderResources resources = mParams.getResources();
// build the context
mContext = new BridgeContext(mParams.getProjectKey(), metrics, resources, mParams.getAssets(), mParams.getLayoutlibCallback(), getConfiguration(mParams), mParams.getTargetSdkVersion(), mParams.isRtlSupported());
setUp();
return SUCCESS.createResult();
}
use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by crdroidandroid.
the class RenderSessionImpl method setActiveToolbar.
/**
* If the root layout is a CoordinatorLayout with an AppBar:
* Set the title of the AppBar to the title of the activity context.
*/
private void setActiveToolbar(View view, BridgeContext context, SessionParams params) {
View coordinatorLayout = findChildView(view, DesignLibUtil.CN_COORDINATOR_LAYOUT);
if (coordinatorLayout == null) {
return;
}
View appBar = findChildView(coordinatorLayout, DesignLibUtil.CN_APPBAR_LAYOUT);
if (appBar == null) {
return;
}
ViewGroup collapsingToolbar = (ViewGroup) findChildView(appBar, DesignLibUtil.CN_COLLAPSING_TOOLBAR_LAYOUT);
if (collapsingToolbar == null) {
return;
}
if (!hasToolbar(collapsingToolbar)) {
return;
}
RenderResources res = context.getRenderResources();
String title = params.getAppLabel();
ResourceValue titleValue = res.findResValue(title, false);
if (titleValue != null && titleValue.getValue() != null) {
title = titleValue.getValue();
}
DesignLibUtil.setTitle(collapsingToolbar, title);
}
Aggregations