use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by ParanoidAndroid.
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() == false) {
return result;
}
SessionParams params = getParams();
BridgeContext context = getContext();
RenderResources resources = getParams().getResources();
DisplayMetrics metrics = getContext().getMetrics();
// use default of true in case it's not found to use alpha by default
mIsAlphaChannelImage = getBooleanThemeValue(resources, "windowIsFloating", true);
mWindowIsFloating = getBooleanThemeValue(resources, "windowIsFloating", true);
findBackground(resources);
findStatusBar(resources, metrics);
findActionBar(resources, metrics);
findNavigationBar(resources, metrics);
// FIXME: find those out, and possibly add them to the render params
boolean hasSystemNavBar = true;
boolean hasNavigationBar = true;
IWindowManager iwm = new IWindowManagerImpl(getContext().getConfiguration(), metrics, Surface.ROTATION_0, hasSystemNavBar, hasNavigationBar);
WindowManagerGlobal_Delegate.setWindowManagerService(iwm);
// build the inflater and parser.
mInflater = new BridgeInflater(context, params.getProjectCallback());
context.setBridgeInflater(mInflater);
mBlockParser = new BridgeXmlBlockParser(params.getLayoutDescription(), context, false);
return SUCCESS.createResult();
}
use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by ResurrectionRemix.
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);
}
use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
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 ResurrectionRemix.
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