Search in sources :

Example 61 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project platform_frameworks_base by android.

the class RenderSessionImpl method getViewKey.

/* (non-Javadoc)
     * The cookie for menu items are stored in menu item and not in the map from View stored in
     * BridgeContext.
     */
@Nullable
private Object getViewKey(View view) {
    BridgeContext context = getContext();
    if (!(view instanceof MenuView.ItemView)) {
        return context.getViewKey(view);
    }
    MenuItemImpl menuItem;
    if (view instanceof ActionMenuItemView) {
        menuItem = ((ActionMenuItemView) view).getItemData();
    } else if (view instanceof ListMenuItemView) {
        menuItem = ((ListMenuItemView) view).getItemData();
    } else if (view instanceof IconMenuItemView) {
        menuItem = ((IconMenuItemView) view).getItemData();
    } else {
        menuItem = null;
    }
    if (menuItem instanceof BridgeMenuItemImpl) {
        return ((BridgeMenuItemImpl) menuItem).getViewCookie();
    }
    return null;
}
Also used : BridgeMenuItemImpl(com.android.internal.view.menu.BridgeMenuItemImpl) MenuItemImpl(com.android.internal.view.menu.MenuItemImpl) BridgeMenuItemImpl(com.android.internal.view.menu.BridgeMenuItemImpl) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) Nullable(android.annotation.Nullable)

Example 62 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project platform_frameworks_base by android.

the class Main method testGetResourceNameVariants.

@Test
public void testGetResourceNameVariants() throws Exception {
    // Setup
    SessionParams params = createSessionParams("", ConfigGenerator.NEXUS_4);
    AssetManager assetManager = AssetManager.getSystem();
    DisplayMetrics metrics = new DisplayMetrics();
    Configuration configuration = RenderAction.getConfiguration(params);
    Resources resources = new Resources(assetManager, metrics, configuration);
    resources.mLayoutlibCallback = params.getLayoutlibCallback();
    resources.mContext = new BridgeContext(params.getProjectKey(), metrics, params.getResources(), params.getAssets(), params.getLayoutlibCallback(), configuration, params.getTargetSdkVersion(), params.isRtlSupported());
    // Test
    assertEquals("android:style/ButtonBar", resources.getResourceName(android.R.style.ButtonBar));
    assertEquals("android", resources.getResourcePackageName(android.R.style.ButtonBar));
    assertEquals("ButtonBar", resources.getResourceEntryName(android.R.style.ButtonBar));
    assertEquals("style", resources.getResourceTypeName(android.R.style.ButtonBar));
    int id = resources.mLayoutlibCallback.getResourceId(ResourceType.STRING, "app_name");
    assertEquals("com.android.layoutlib.test.myapplication:string/app_name", resources.getResourceName(id));
    assertEquals("com.android.layoutlib.test.myapplication", resources.getResourcePackageName(id));
    assertEquals("string", resources.getResourceTypeName(id));
    assertEquals("app_name", resources.getResourceEntryName(id));
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) AssetManager(android.content.res.AssetManager) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(android.content.res.Configuration) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) FrameworkResources(com.android.ide.common.resources.FrameworkResources) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics) Test(org.junit.Test)

Example 63 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project platform_frameworks_base by android.

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 64 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by ParanoidAndroid.

the class CustomBar method loadIcon.

protected Drawable loadIcon(int index, ResourceType type, String name) {
    BridgeContext bridgeContext = (BridgeContext) mContext;
    RenderResources res = bridgeContext.getRenderResources();
    // find the resource
    ResourceValue value = res.getFrameworkResource(type, name);
    // resolve it if needed
    value = res.resolveResValue(value);
    return loadIcon(index, 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) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext)

Example 65 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by ParanoidAndroid.

the class CustomBar method setStyle.

protected void setStyle(String themeEntryName) {
    BridgeContext bridgeContext = (BridgeContext) mContext;
    RenderResources res = bridgeContext.getRenderResources();
    ResourceValue value = res.findItemInTheme(themeEntryName, true);
    value = res.resolveResValue(value);
    if (value instanceof StyleResourceValue == false) {
        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(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)

Aggregations

BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)112 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)40 Context (android.content.Context)31 View (android.view.View)24 AdapterView (android.widget.AdapterView)24 RenderResources (com.android.ide.common.rendering.api.RenderResources)24 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)24 SessionParams (com.android.ide.common.rendering.api.SessionParams)23 ActionMenuItemView (com.android.internal.view.menu.ActionMenuItemView)20 IconMenuItemView (com.android.internal.view.menu.IconMenuItemView)20 ListMenuItemView (com.android.internal.view.menu.ListMenuItemView)20 AbsListView (android.widget.AbsListView)18 ExpandableListView (android.widget.ExpandableListView)18 ListView (android.widget.ListView)18 Result (com.android.ide.common.rendering.api.Result)18 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)17 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)16 ActionMenuView (android.widget.ActionMenuView)15 MenuView (com.android.internal.view.menu.MenuView)15 Drawable (android.graphics.drawable.Drawable)13