Search in sources :

Example 41 with RenderResources

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

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

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

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

use of com.android.ide.common.rendering.api.RenderResources 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 44 with RenderResources

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

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)

Example 45 with RenderResources

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

the class BridgeActionBar method setTitle.

private void setTitle() {
    RenderResources res = mBridgeContext.getRenderResources();
    String title = mParams.getAppLabel();
    ResourceValue titleValue = res.findResValue(title, false);
    if (titleValue != null && titleValue.getValue() != null) {
        setTitle(titleValue.getValue());
    } else {
        setTitle(title);
    }
}
Also used : RenderResources(com.android.ide.common.rendering.api.RenderResources) ResourceValue(com.android.ide.common.rendering.api.ResourceValue)

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