use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.
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 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 AOSPA.
the class Preference_Delegate method getView.
@LayoutlibDelegate
static /*package*/
View getView(Preference pref, View convertView, ViewGroup parent) {
Context context = pref.getContext();
BridgeContext bc = context instanceof BridgeContext ? ((BridgeContext) context) : null;
convertView = pref.getView_Original(convertView, parent);
if (bc != null) {
Object cookie = bc.getCookie(pref);
if (cookie != null) {
bc.addViewKey(convertView, cookie);
}
}
return convertView;
}
use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by crdroidandroid.
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;
}
use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by crdroidandroid.
the class Bitmap_Delegate method createBitmap.
/**
* Creates and returns a {@link Bitmap} initialized with the given file content.
*
* @param input the file from which to read the bitmap content
* @param density the density associated with the bitmap
*
* @see Bitmap#isPremultiplied()
* @see Bitmap#isMutable()
* @see Bitmap#getDensity()
*/
private static Bitmap createBitmap(File input, Set<BitmapCreateFlags> createFlags, Density density) throws IOException {
// create a delegate with the content of the file.
BufferedImage image = ImageIO.read(input);
if (image == null && input.exists()) {
// There was a problem decoding the image, or the decoder isn't registered. Webp maybe.
// Replace with a broken image icon.
BridgeContext currentContext = RenderAction.getCurrentContext();
if (currentContext != null) {
RenderResources resources = currentContext.getRenderResources();
ResourceValue broken = resources.getFrameworkResource(ResourceType.DRAWABLE, "ic_menu_report_image");
File brokenFile = new File(broken.getValue());
if (brokenFile.exists()) {
image = ImageIO.read(brokenFile);
}
}
}
Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.ARGB_8888);
return createBitmap(delegate, createFlags, density.getDpiValue());
}
Aggregations