Search in sources :

Example 61 with StyleResourceValue

use of com.android.ide.common.rendering.api.StyleResourceValue in project android_frameworks_base by ResurrectionRemix.

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);
}
Also used : Context(android.content.Context) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ContextThemeWrapper(android.view.ContextThemeWrapper) RenderResources(com.android.ide.common.rendering.api.RenderResources) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue)

Example 62 with StyleResourceValue

use of com.android.ide.common.rendering.api.StyleResourceValue in project android_frameworks_base by ResurrectionRemix.

the class BridgeContext method resolveThemeAttribute.

public boolean resolveThemeAttribute(int resId, TypedValue outValue, boolean resolveRefs) {
    Pair<ResourceType, String> resourceInfo = Bridge.resolveResourceId(resId);
    boolean isFrameworkRes = true;
    if (resourceInfo == null) {
        resourceInfo = mLayoutlibCallback.resolveResourceId(resId);
        isFrameworkRes = false;
    }
    if (resourceInfo == null) {
        return false;
    }
    ResourceValue value = mRenderResources.findItemInTheme(resourceInfo.getSecond(), isFrameworkRes);
    if (resolveRefs) {
        value = mRenderResources.resolveResValue(value);
    }
    if (value == null) {
        // unable to find the attribute.
        return false;
    }
    // check if this is a style resource
    if (value instanceof StyleResourceValue) {
        // get the id that will represent this style.
        outValue.resourceId = getDynamicIdByStyle((StyleResourceValue) value);
        return true;
    }
    int a;
    // if this is a framework value.
    if (value.isFramework()) {
        // look for idName in the android R classes.
        // use 0 a default res value as it's not a valid id value.
        a = getFrameworkResourceValue(value.getResourceType(), value.getName(), 0);
    } else {
        // look for idName in the project R class.
        // use 0 a default res value as it's not a valid id value.
        a = getProjectResourceValue(value.getResourceType(), value.getName(), 0);
    }
    if (a != 0) {
        outValue.resourceId = a;
        return true;
    }
    return false;
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ResourceType(com.android.resources.ResourceType)

Example 63 with StyleResourceValue

use of com.android.ide.common.rendering.api.StyleResourceValue in project android_frameworks_base by ResurrectionRemix.

the class Resources_Theme_Delegate method resolveStyle.

@Nullable
private static StyleResourceValue resolveStyle(int nativeResid) {
    if (nativeResid == 0) {
        return null;
    }
    BridgeContext context = RenderSessionImpl.getCurrentContext();
    ResourceReference theme = context.resolveId(nativeResid);
    if (theme.isFramework()) {
        return (StyleResourceValue) context.getRenderResources().getFrameworkResource(ResourceType.STYLE, theme.getName());
    } else {
        return (StyleResourceValue) context.getRenderResources().getProjectResource(ResourceType.STYLE, theme.getName());
    }
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) Nullable(android.annotation.Nullable)

Example 64 with StyleResourceValue

use of com.android.ide.common.rendering.api.StyleResourceValue in project android_frameworks_base by crdroidandroid.

the class Resources_Theme_Delegate method resolveStyle.

@Nullable
private static StyleResourceValue resolveStyle(int nativeResid) {
    if (nativeResid == 0) {
        return null;
    }
    BridgeContext context = RenderSessionImpl.getCurrentContext();
    ResourceReference theme = context.resolveId(nativeResid);
    if (theme.isFramework()) {
        return (StyleResourceValue) context.getRenderResources().getFrameworkResource(ResourceType.STYLE, theme.getName());
    } else {
        return (StyleResourceValue) context.getRenderResources().getProjectResource(ResourceType.STYLE, theme.getName());
    }
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) Nullable(android.annotation.Nullable)

Example 65 with StyleResourceValue

use of com.android.ide.common.rendering.api.StyleResourceValue in project android_frameworks_base by crdroidandroid.

the class Resources_Theme_Delegate method setupResources.

// ---- private helper methods ----
private static boolean setupResources(Theme thisTheme) {
    // Key is a space-separated list of theme ids applied that have been merged into the
    // BridgeContext's theme to make thisTheme.
    final ThemeKey key = thisTheme.getKey();
    final int[] resId = key.mResId;
    final boolean[] force = key.mForce;
    boolean changed = false;
    for (int i = 0, N = key.mCount; i < N; i++) {
        StyleResourceValue style = resolveStyle(resId[i]);
        if (style != null) {
            RenderSessionImpl.getCurrentContext().getRenderResources().applyStyle(style, force[i]);
            changed = true;
        }
    }
    return changed;
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ThemeKey(android.content.res.Resources.ThemeKey)

Aggregations

StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)69 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)41 BridgeTypedArray (android.content.res.BridgeTypedArray)18 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)15 PropertiesMap (com.android.util.PropertiesMap)15 Pair (com.android.util.Pair)12 RenderResources (com.android.ide.common.rendering.api.RenderResources)11 Property (com.android.util.PropertiesMap.Property)10 ResourceReference (com.android.ide.common.rendering.api.ResourceReference)9 ResourceItem (com.android.ide.common.res2.ResourceItem)7 ColorStateList (android.content.res.ColorStateList)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)6 Drawable (android.graphics.drawable.Drawable)6 TypedValue (android.util.TypedValue)6 TextView (android.widget.TextView)6 ResourceType (com.android.resources.ResourceType)6 FileNotFoundException (java.io.FileNotFoundException)6 NotNull (org.jetbrains.annotations.NotNull)6 Context (android.content.Context)5 ContextThemeWrapper (android.view.ContextThemeWrapper)5