use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by DirtyUnicorns.
the class RenderSessionImpl 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()
*/
@Override
public Result init(long timeout) {
Result result = super.init(timeout);
if (!result.isSuccess()) {
return result;
}
SessionParams params = getParams();
BridgeContext context = getContext();
// use default of true in case it's not found to use alpha by default
mIsAlphaChannelImage = ResourceHelper.getBooleanThemeValue(params.getResources(), "windowIsFloating", true, true);
mLayoutBuilder = new Layout.Builder(params, context);
// FIXME: find those out, and possibly add them to the render params
boolean hasNavigationBar = true;
//noinspection ConstantConditions
IWindowManager iwm = new IWindowManagerImpl(getContext().getConfiguration(), context.getMetrics(), Surface.ROTATION_0, hasNavigationBar);
WindowManagerGlobal_Delegate.setWindowManagerService(iwm);
// build the inflater and parser.
mInflater = new BridgeInflater(context, params.getLayoutlibCallback());
context.setBridgeInflater(mInflater);
mBlockParser = new BridgeXmlBlockParser(params.getLayoutDescription(), context, false);
return SUCCESS.createResult();
}
use of com.android.layoutlib.bridge.android.BridgeContext 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.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.
the class BridgeInflater method setupViewInContext.
private void setupViewInContext(View view, AttributeSet attrs) {
Context context = getContext();
context = getBaseContext(context);
if (context instanceof BridgeContext) {
BridgeContext bc = (BridgeContext) context;
// get the view key
Object viewKey = getViewKeyFromParser(attrs, bc, mResourceReference, mIsInMerge);
if (viewKey != null) {
bc.addViewKey(view, viewKey);
}
String scrollPosX = attrs.getAttributeValue(BridgeConstants.NS_RESOURCES, "scrollX");
if (scrollPosX != null && scrollPosX.endsWith("px")) {
int value = Integer.parseInt(scrollPosX.substring(0, scrollPosX.length() - 2));
bc.setScrollXPos(view, value);
}
String scrollPosY = attrs.getAttributeValue(BridgeConstants.NS_RESOURCES, "scrollY");
if (scrollPosY != null && scrollPosY.endsWith("px")) {
int value = Integer.parseInt(scrollPosY.substring(0, scrollPosY.length() - 2));
bc.setScrollYPos(view, value);
}
if (ReflectionUtils.isInstanceOf(view, RecyclerViewUtil.CN_RECYCLER_VIEW)) {
Integer resourceId = null;
String attrVal = attrs.getAttributeValue(BridgeConstants.NS_TOOLS_URI, BridgeConstants.ATTR_LIST_ITEM);
if (attrVal != null && !attrVal.isEmpty()) {
ResourceValue resValue = bc.getRenderResources().findResValue(attrVal, false);
if (resValue.isFramework()) {
resourceId = Bridge.getResourceId(resValue.getResourceType(), resValue.getName());
} else {
resourceId = mLayoutlibCallback.getResourceId(resValue.getResourceType(), resValue.getName());
}
}
if (resourceId == null) {
resourceId = 0;
}
RecyclerViewUtil.setAdapter(view, bc, mLayoutlibCallback, resourceId);
} else if (ReflectionUtils.isInstanceOf(view, DrawerLayoutUtil.CN_DRAWER_LAYOUT)) {
String attrVal = attrs.getAttributeValue(BridgeConstants.NS_TOOLS_URI, BridgeConstants.ATTR_OPEN_DRAWER);
if (attrVal != null) {
getDrawerLayoutMap().put(view, attrVal);
}
}
}
}
use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.
the class MenuInflater_Delegate method registerMenu.
@LayoutlibDelegate
static /*package*/
void registerMenu(MenuInflater thisInflater, MenuItem menuItem, AttributeSet attrs) {
if (menuItem instanceof BridgeMenuItemImpl) {
Context context = thisInflater.getContext();
context = BridgeContext.getBaseContext(context);
if (context instanceof BridgeContext) {
Object viewKey = BridgeInflater.getViewKeyFromParser(attrs, ((BridgeContext) context), null, false);
((BridgeMenuItemImpl) menuItem).setViewCookie(viewKey);
return;
}
}
// This means that Bridge did not take over the instantiation of some object properly.
// This is most likely a bug in the LayoutLib code.
Bridge.getLog().warning(LayoutLog.TAG_BROKEN, "Action Bar Menu rendering may be incorrect.", null);
}
use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.
the class BridgePreferenceInflater method onCreateItem.
@Override
protected Preference onCreateItem(String name, AttributeSet attrs) throws ClassNotFoundException {
Object viewKey = null;
BridgeContext bc = null;
Context context = getContext();
if (context instanceof BridgeContext) {
bc = (BridgeContext) context;
}
if (attrs instanceof BridgeXmlBlockParser) {
viewKey = ((BridgeXmlBlockParser) attrs).getViewCookie();
}
Preference preference = super.onCreateItem(name, attrs);
if (viewKey != null && bc != null) {
bc.addCookie(preference, viewKey);
}
return preference;
}
Aggregations