use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
the class BridgeInflater method inflate.
@Override
public View inflate(int resource, ViewGroup root) {
Context context = getContext();
context = getBaseContext(context);
if (context instanceof BridgeContext) {
BridgeContext bridgeContext = (BridgeContext) context;
ResourceValue value = null;
@SuppressWarnings("deprecation") Pair<ResourceType, String> layoutInfo = Bridge.resolveResourceId(resource);
if (layoutInfo != null) {
value = bridgeContext.getRenderResources().getFrameworkResource(ResourceType.LAYOUT, layoutInfo.getSecond());
} else {
layoutInfo = mLayoutlibCallback.resolveResourceId(resource);
if (layoutInfo != null) {
value = bridgeContext.getRenderResources().getProjectResource(ResourceType.LAYOUT, layoutInfo.getSecond());
}
}
if (value != null) {
File f = new File(value.getValue());
if (f.isFile()) {
try {
XmlPullParser parser = ParserFactory.create(f, true);
BridgeXmlBlockParser bridgeParser = new BridgeXmlBlockParser(parser, bridgeContext, value.isFramework());
return inflate(bridgeParser, root);
} catch (Exception e) {
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, "Failed to parse file " + f.getAbsolutePath(), e, null);
return null;
}
}
}
}
return null;
}
use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by ResurrectionRemix.
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.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
the class Resources_Theme_Delegate method resolveStyle.
@Nullable
private static StyleResourceValue resolveStyle(int nativeResid) {
if (nativeResid == 0) {
return null;
}
BridgeContext context = RenderSessionImpl.getCurrentContext();
ResourceReference theme = context.resolveId(nativeResid);
if (theme.isFramework()) {
return (StyleResourceValue) context.getRenderResources().getFrameworkResource(ResourceType.STYLE, theme.getName());
} else {
return (StyleResourceValue) context.getRenderResources().getProjectResource(ResourceType.STYLE, theme.getName());
}
}
Aggregations