Search in sources :

Example 21 with RenderResources

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

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

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

the class RenderAction 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()
     */
public Result init(long timeout) {
    // acquire the lock. if the result is null, lock was just acquired, otherwise, return
    // the result.
    Result result = acquireLock(timeout);
    if (result != null) {
        return result;
    }
    HardwareConfig hardwareConfig = mParams.getHardwareConfig();
    // setup the display Metrics.
    DisplayMetrics metrics = new DisplayMetrics();
    metrics.densityDpi = metrics.noncompatDensityDpi = hardwareConfig.getDensity().getDpiValue();
    metrics.density = metrics.noncompatDensity = metrics.densityDpi / (float) DisplayMetrics.DENSITY_DEFAULT;
    metrics.scaledDensity = metrics.noncompatScaledDensity = metrics.density;
    metrics.widthPixels = metrics.noncompatWidthPixels = hardwareConfig.getScreenWidth();
    metrics.heightPixels = metrics.noncompatHeightPixels = hardwareConfig.getScreenHeight();
    metrics.xdpi = metrics.noncompatXdpi = hardwareConfig.getXdpi();
    metrics.ydpi = metrics.noncompatYdpi = hardwareConfig.getYdpi();
    RenderResources resources = mParams.getResources();
    // build the context
    mContext = new BridgeContext(mParams.getProjectKey(), metrics, resources, mParams.getAssets(), mParams.getLayoutlibCallback(), getConfiguration(mParams), mParams.getTargetSdkVersion(), mParams.isRtlSupported());
    setUp();
    return SUCCESS.createResult();
}
Also used : HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) RenderResources(com.android.ide.common.rendering.api.RenderResources) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) DisplayMetrics(android.util.DisplayMetrics) Result(com.android.ide.common.rendering.api.Result)

Example 23 with RenderResources

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

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)

Example 24 with RenderResources

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

the class RenderAction 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()
     */
public Result init(long timeout) {
    // acquire the lock. if the result is null, lock was just acquired, otherwise, return
    // the result.
    Result result = acquireLock(timeout);
    if (result != null) {
        return result;
    }
    HardwareConfig hardwareConfig = mParams.getHardwareConfig();
    // setup the display Metrics.
    DisplayMetrics metrics = new DisplayMetrics();
    metrics.densityDpi = metrics.noncompatDensityDpi = hardwareConfig.getDensity().getDpiValue();
    metrics.density = metrics.noncompatDensity = metrics.densityDpi / (float) DisplayMetrics.DENSITY_DEFAULT;
    metrics.scaledDensity = metrics.noncompatScaledDensity = metrics.density;
    metrics.widthPixels = metrics.noncompatWidthPixels = hardwareConfig.getScreenWidth();
    metrics.heightPixels = metrics.noncompatHeightPixels = hardwareConfig.getScreenHeight();
    metrics.xdpi = metrics.noncompatXdpi = hardwareConfig.getXdpi();
    metrics.ydpi = metrics.noncompatYdpi = hardwareConfig.getYdpi();
    RenderResources resources = mParams.getResources();
    // build the context
    mContext = new BridgeContext(mParams.getProjectKey(), metrics, resources, mParams.getAssets(), mParams.getLayoutlibCallback(), getConfiguration(mParams), mParams.getTargetSdkVersion(), mParams.isRtlSupported());
    setUp();
    return SUCCESS.createResult();
}
Also used : HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) RenderResources(com.android.ide.common.rendering.api.RenderResources) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) DisplayMetrics(android.util.DisplayMetrics) Result(com.android.ide.common.rendering.api.Result)

Example 25 with RenderResources

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

the class BridgeTypedArray method getInt.

/**
     * Retrieve the integer value for the attribute at <var>index</var>.
     *
     * @param index Index of attribute to retrieve.
     * @param defValue Value to return if the attribute is not defined.
     *
     * @return Attribute int value, or defValue if not defined.
     */
@Override
public int getInt(int index, int defValue) {
    if (index < 0 || index >= mResourceData.length) {
        return defValue;
    }
    if (mResourceData[index] == null) {
        return defValue;
    }
    String s = mResourceData[index].getValue();
    if (RenderResources.REFERENCE_NULL.equals(s)) {
        return defValue;
    }
    if (s == null || s.length() == 0) {
        return defValue;
    }
    try {
        return XmlUtils.convertValueToInt(s, defValue);
    } catch (NumberFormatException e) {
    // pass
    }
    // Field is not null and is not an integer.
    // Check for possible constants and try to find them.
    // Get the map of attribute-constant -> IntegerValue
    Map<String, Integer> map = null;
    if (mIsFramework[index]) {
        map = Bridge.getEnumValues(mNames[index]);
    } else {
        // get the styleable matching the resolved name
        RenderResources res = mContext.getRenderResources();
        ResourceValue attr = res.getProjectResource(ResourceType.ATTR, mNames[index]);
        if (attr instanceof AttrResourceValue) {
            map = ((AttrResourceValue) attr).getAttributeValues();
        }
    }
    if (map != null) {
        // accumulator to store the value of the 1+ constants.
        int result = 0;
        // split the value in case this is a mix of several flags.
        String[] keywords = s.split("\\|");
        for (String keyword : keywords) {
            Integer i = map.get(keyword.trim());
            if (i != null) {
                result |= i.intValue();
            } else {
                Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT, String.format("\"%s\" in attribute \"%2$s\" is not a valid value", keyword, mNames[index]), null);
            }
        }
        return result;
    }
    return defValue;
}
Also used : AttrResourceValue(com.android.ide.common.rendering.api.AttrResourceValue) RenderResources(com.android.ide.common.rendering.api.RenderResources) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) AttrResourceValue(com.android.ide.common.rendering.api.AttrResourceValue) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue)

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