Search in sources :

Example 36 with RenderResources

use of com.android.ide.common.rendering.api.RenderResources in project android by JetBrains.

the class ResourceHelperTest method testResolveEmptyStatelist.

public void testResolveEmptyStatelist() {
    VirtualFile file = myFixture.copyFileToProject("resourceHelper/empty_state_list.xml", "res/color/empty_state_list.xml");
    RenderResources rr = myFacet.getConfigurationManager().getConfiguration(file).getResourceResolver();
    assertNotNull(rr);
    ResourceValue rv = rr.getProjectResource(ResourceType.COLOR, "empty_state_list");
    assertNotNull(rv);
    assertNull(resolveColor(rr, rv, myModule.getProject()));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RenderResources(com.android.ide.common.rendering.api.RenderResources) ResourceValue(com.android.ide.common.rendering.api.ResourceValue)

Example 37 with RenderResources

use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by AOSPA.

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 38 with RenderResources

use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by AOSPA.

the class CustomBar method getResourceValue.

private ResourceValue getResourceValue(String reference) {
    RenderResources res = getContext().getRenderResources();
    // find the resource
    ResourceValue value = res.findResValue(reference, false);
    // resolve it if needed
    return res.resolveResValue(value);
}
Also used : RenderResources(com.android.ide.common.rendering.api.RenderResources) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue)

Example 39 with RenderResources

use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by AOSPA.

the class CustomBar method getBarColor.

/**
     * Find the background color for this bar from the theme attributes. Only relevant to StatusBar
     * and NavigationBar.
     * <p/>
     * Returns 0 if not found.
     *
     * @param colorAttrName the attribute name for the background color
     * @param translucentAttrName the attribute name for the translucency property of the bar.
     *
     * @throws NumberFormatException if color resolved to an invalid string.
     */
protected int getBarColor(@NonNull String colorAttrName, @NonNull String translucentAttrName) {
    if (!Config.isGreaterOrEqual(mSimulatedPlatformVersion, LOLLIPOP)) {
        return 0;
    }
    RenderResources renderResources = getContext().getRenderResources();
    // First check if the bar is translucent.
    boolean translucent = ResourceHelper.getBooleanThemeValue(renderResources, translucentAttrName, true, false);
    if (translucent) {
        // 40% black.
        return 0x66000000;
    }
    boolean transparent = ResourceHelper.getBooleanThemeValue(renderResources, "windowDrawsSystemBarBackgrounds", true, false);
    if (transparent) {
        return getColor(renderResources, colorAttrName);
    }
    return 0;
}
Also used : RenderResources(com.android.ide.common.rendering.api.RenderResources)

Example 40 with RenderResources

use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by AOSPA.

the class AppCompatActionBar method getDrawable.

// TODO: this is duplicated from FrameworkActionBarWrapper$WindowActionBarWrapper
@Nullable
private Drawable getDrawable(@NonNull String name, boolean isFramework) {
    RenderResources res = mBridgeContext.getRenderResources();
    ResourceValue value = res.findResValue(name, isFramework);
    value = res.resolveResValue(value);
    if (value != null) {
        return ResourceHelper.getDrawable(value, mBridgeContext);
    }
    return null;
}
Also used : RenderResources(com.android.ide.common.rendering.api.RenderResources) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) Nullable(android.annotation.Nullable)

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