Search in sources :

Example 1 with RenderResources

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();
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) BridgeInflater(android.view.BridgeInflater) IWindowManager(android.view.IWindowManager) IWindowManagerImpl(android.view.IWindowManagerImpl) RenderResources(com.android.ide.common.rendering.api.RenderResources) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) DisplayMetrics(android.util.DisplayMetrics) BridgeXmlBlockParser(com.android.layoutlib.bridge.android.BridgeXmlBlockParser) Result(com.android.ide.common.rendering.api.Result)

Example 2 with RenderResources

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);
}
Also used : ViewGroup(android.view.ViewGroup) RenderResources(com.android.ide.common.rendering.api.RenderResources) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) MenuView(com.android.internal.view.menu.MenuView) View(android.view.View) AdapterView(android.widget.AdapterView) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListView(android.widget.ListView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) AbsListView(android.widget.AbsListView) ActionMenuView(android.widget.ActionMenuView) ExpandableListView(android.widget.ExpandableListView)

Example 3 with RenderResources

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);
                }
            }
        }
    }
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) RenderResources(com.android.ide.common.rendering.api.RenderResources) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ColorStateList(android.content.res.ColorStateList) TextView(android.widget.TextView) TypedValue(android.util.TypedValue)

Example 4 with RenderResources

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;
}
Also used : RenderResources(com.android.ide.common.rendering.api.RenderResources) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) DisplayMetrics(android.util.DisplayMetrics) TypedValue(android.util.TypedValue)

Example 5 with RenderResources

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());
}
Also used : RenderResources(com.android.ide.common.rendering.api.RenderResources) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Aggregations

RenderResources (com.android.ide.common.rendering.api.RenderResources)64 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)48 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)28 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)24 DisplayMetrics (android.util.DisplayMetrics)12 TypedValue (android.util.TypedValue)11 Result (com.android.ide.common.rendering.api.Result)7 ColorStateList (android.content.res.ColorStateList)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)6 Drawable (android.graphics.drawable.Drawable)6 TextView (android.widget.TextView)6 HardwareConfig (com.android.ide.common.rendering.api.HardwareConfig)6 Nullable (android.annotation.Nullable)5 Context (android.content.Context)5 ContextThemeWrapper (android.view.ContextThemeWrapper)5 View (android.view.View)5 ViewGroup (android.view.ViewGroup)5 AbsListView (android.widget.AbsListView)5 ActionMenuView (android.widget.ActionMenuView)5 AdapterView (android.widget.AdapterView)5