Search in sources :

Example 11 with HardwareConfig

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

the class RenderDrawable method render.

public Result render() {
    checkLock();
    // get the drawable resource value
    DrawableParams params = getParams();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    ResourceValue drawableResource = params.getDrawable();
    // resolve it
    BridgeContext context = getContext();
    drawableResource = context.getRenderResources().resolveResValue(drawableResource);
    if (drawableResource == null) {
        return Status.ERROR_NOT_A_DRAWABLE.createResult();
    }
    ResourceType resourceType = drawableResource.getResourceType();
    if (resourceType != ResourceType.DRAWABLE && resourceType != ResourceType.MIPMAP) {
        return Status.ERROR_NOT_A_DRAWABLE.createResult();
    }
    Drawable d = ResourceHelper.getDrawable(drawableResource, context);
    final Boolean allStates = params.getFlag(RenderParamsFlags.FLAG_KEY_RENDER_ALL_DRAWABLE_STATES);
    if (allStates == Boolean.TRUE) {
        final List<BufferedImage> result;
        if (d instanceof StateListDrawable) {
            result = new ArrayList<BufferedImage>();
            final StateListDrawable stateList = (StateListDrawable) d;
            for (int i = 0; i < stateList.getStateCount(); i++) {
                final Drawable stateDrawable = stateList.getStateDrawable(i);
                result.add(renderImage(hardwareConfig, stateDrawable, context));
            }
        } else {
            result = Collections.singletonList(renderImage(hardwareConfig, d, context));
        }
        return Status.SUCCESS.createResult(result);
    } else {
        BufferedImage image = renderImage(hardwareConfig, d, context);
        return Status.SUCCESS.createResult(image);
    }
}
Also used : HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ResourceType(com.android.resources.ResourceType) StateListDrawable(android.graphics.drawable.StateListDrawable) BufferedImage(java.awt.image.BufferedImage) DrawableParams(com.android.ide.common.rendering.api.DrawableParams)

Example 12 with HardwareConfig

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

the class RenderAction method getConfiguration.

// VisibleForTesting
public static Configuration getConfiguration(RenderParams params) {
    Configuration config = new Configuration();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    ScreenSize screenSize = hardwareConfig.getScreenSize();
    if (screenSize != null) {
        switch(screenSize) {
            case SMALL:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_SMALL;
                break;
            case NORMAL:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_NORMAL;
                break;
            case LARGE:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_LARGE;
                break;
            case XLARGE:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_XLARGE;
                break;
        }
    }
    Density density = hardwareConfig.getDensity();
    if (density == null) {
        density = Density.MEDIUM;
    }
    config.screenWidthDp = hardwareConfig.getScreenWidth() / density.getDpiValue();
    config.screenHeightDp = hardwareConfig.getScreenHeight() / density.getDpiValue();
    if (config.screenHeightDp < config.screenWidthDp) {
        //noinspection SuspiciousNameCombination
        config.smallestScreenWidthDp = config.screenHeightDp;
    } else {
        config.smallestScreenWidthDp = config.screenWidthDp;
    }
    config.densityDpi = density.getDpiValue();
    // never run in compat mode:
    config.compatScreenWidthDp = config.screenWidthDp;
    config.compatScreenHeightDp = config.screenHeightDp;
    ScreenOrientation orientation = hardwareConfig.getOrientation();
    if (orientation != null) {
        switch(orientation) {
            case PORTRAIT:
                config.orientation = Configuration.ORIENTATION_PORTRAIT;
                break;
            case LANDSCAPE:
                config.orientation = Configuration.ORIENTATION_LANDSCAPE;
                break;
            case SQUARE:
                //noinspection deprecation
                config.orientation = Configuration.ORIENTATION_SQUARE;
                break;
        }
    } else {
        config.orientation = Configuration.ORIENTATION_UNDEFINED;
    }
    ScreenRound roundness = hardwareConfig.getScreenRoundness();
    if (roundness != null) {
        switch(roundness) {
            case ROUND:
                config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
                break;
            case NOTROUND:
                config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_NO;
        }
    } else {
        config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_UNDEFINED;
    }
    String locale = params.getLocale();
    if (locale != null && !locale.isEmpty())
        config.locale = new Locale(locale);
    return config;
}
Also used : ScreenOrientation(com.android.resources.ScreenOrientation) Locale(java.util.Locale) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) Configuration(android.content.res.Configuration) ScreenSize(com.android.resources.ScreenSize) Density(com.android.resources.Density) ScreenRound(com.android.resources.ScreenRound)

Example 13 with HardwareConfig

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

the class RenderAction method getConfiguration.

// VisibleForTesting
public static Configuration getConfiguration(RenderParams params) {
    Configuration config = new Configuration();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    ScreenSize screenSize = hardwareConfig.getScreenSize();
    if (screenSize != null) {
        switch(screenSize) {
            case SMALL:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_SMALL;
                break;
            case NORMAL:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_NORMAL;
                break;
            case LARGE:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_LARGE;
                break;
            case XLARGE:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_XLARGE;
                break;
        }
    }
    Density density = hardwareConfig.getDensity();
    if (density == null) {
        density = Density.MEDIUM;
    }
    config.screenWidthDp = hardwareConfig.getScreenWidth() / density.getDpiValue();
    config.screenHeightDp = hardwareConfig.getScreenHeight() / density.getDpiValue();
    if (config.screenHeightDp < config.screenWidthDp) {
        //noinspection SuspiciousNameCombination
        config.smallestScreenWidthDp = config.screenHeightDp;
    } else {
        config.smallestScreenWidthDp = config.screenWidthDp;
    }
    config.densityDpi = density.getDpiValue();
    // never run in compat mode:
    config.compatScreenWidthDp = config.screenWidthDp;
    config.compatScreenHeightDp = config.screenHeightDp;
    ScreenOrientation orientation = hardwareConfig.getOrientation();
    if (orientation != null) {
        switch(orientation) {
            case PORTRAIT:
                config.orientation = Configuration.ORIENTATION_PORTRAIT;
                break;
            case LANDSCAPE:
                config.orientation = Configuration.ORIENTATION_LANDSCAPE;
                break;
            case SQUARE:
                //noinspection deprecation
                config.orientation = Configuration.ORIENTATION_SQUARE;
                break;
        }
    } else {
        config.orientation = Configuration.ORIENTATION_UNDEFINED;
    }
    ScreenRound roundness = hardwareConfig.getScreenRoundness();
    if (roundness != null) {
        switch(roundness) {
            case ROUND:
                config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
                break;
            case NOTROUND:
                config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_NO;
        }
    } else {
        config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_UNDEFINED;
    }
    String locale = params.getLocale();
    if (locale != null && !locale.isEmpty())
        config.locale = new Locale(locale);
    return config;
}
Also used : ScreenOrientation(com.android.resources.ScreenOrientation) Locale(java.util.Locale) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) Configuration(android.content.res.Configuration) ScreenSize(com.android.resources.ScreenSize) Density(com.android.resources.Density) ScreenRound(com.android.resources.ScreenRound)

Example 14 with HardwareConfig

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

the class RenderDrawable method render.

public Result render() {
    checkLock();
    // get the drawable resource value
    DrawableParams params = getParams();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    ResourceValue drawableResource = params.getDrawable();
    // resolve it
    BridgeContext context = getContext();
    drawableResource = context.getRenderResources().resolveResValue(drawableResource);
    if (drawableResource == null) {
        return Status.ERROR_NOT_A_DRAWABLE.createResult();
    }
    ResourceType resourceType = drawableResource.getResourceType();
    if (resourceType != ResourceType.DRAWABLE && resourceType != ResourceType.MIPMAP) {
        return Status.ERROR_NOT_A_DRAWABLE.createResult();
    }
    Drawable d = ResourceHelper.getDrawable(drawableResource, context);
    final Boolean allStates = params.getFlag(RenderParamsFlags.FLAG_KEY_RENDER_ALL_DRAWABLE_STATES);
    if (allStates == Boolean.TRUE) {
        final List<BufferedImage> result;
        if (d instanceof StateListDrawable) {
            result = new ArrayList<BufferedImage>();
            final StateListDrawable stateList = (StateListDrawable) d;
            for (int i = 0; i < stateList.getStateCount(); i++) {
                final Drawable stateDrawable = stateList.getStateDrawable(i);
                result.add(renderImage(hardwareConfig, stateDrawable, context));
            }
        } else {
            result = Collections.singletonList(renderImage(hardwareConfig, d, context));
        }
        return Status.SUCCESS.createResult(result);
    } else {
        BufferedImage image = renderImage(hardwareConfig, d, context);
        return Status.SUCCESS.createResult(image);
    }
}
Also used : HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ResourceType(com.android.resources.ResourceType) StateListDrawable(android.graphics.drawable.StateListDrawable) BufferedImage(java.awt.image.BufferedImage) DrawableParams(com.android.ide.common.rendering.api.DrawableParams)

Example 15 with HardwareConfig

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

the class RenderAction method getConfiguration.

// VisibleForTesting
public static Configuration getConfiguration(RenderParams params) {
    Configuration config = new Configuration();
    HardwareConfig hardwareConfig = params.getHardwareConfig();
    ScreenSize screenSize = hardwareConfig.getScreenSize();
    if (screenSize != null) {
        switch(screenSize) {
            case SMALL:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_SMALL;
                break;
            case NORMAL:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_NORMAL;
                break;
            case LARGE:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_LARGE;
                break;
            case XLARGE:
                config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_XLARGE;
                break;
        }
    }
    Density density = hardwareConfig.getDensity();
    if (density == null) {
        density = Density.MEDIUM;
    }
    config.screenWidthDp = hardwareConfig.getScreenWidth() / density.getDpiValue();
    config.screenHeightDp = hardwareConfig.getScreenHeight() / density.getDpiValue();
    if (config.screenHeightDp < config.screenWidthDp) {
        //noinspection SuspiciousNameCombination
        config.smallestScreenWidthDp = config.screenHeightDp;
    } else {
        config.smallestScreenWidthDp = config.screenWidthDp;
    }
    config.densityDpi = density.getDpiValue();
    // never run in compat mode:
    config.compatScreenWidthDp = config.screenWidthDp;
    config.compatScreenHeightDp = config.screenHeightDp;
    ScreenOrientation orientation = hardwareConfig.getOrientation();
    if (orientation != null) {
        switch(orientation) {
            case PORTRAIT:
                config.orientation = Configuration.ORIENTATION_PORTRAIT;
                break;
            case LANDSCAPE:
                config.orientation = Configuration.ORIENTATION_LANDSCAPE;
                break;
            case SQUARE:
                //noinspection deprecation
                config.orientation = Configuration.ORIENTATION_SQUARE;
                break;
        }
    } else {
        config.orientation = Configuration.ORIENTATION_UNDEFINED;
    }
    ScreenRound roundness = hardwareConfig.getScreenRoundness();
    if (roundness != null) {
        switch(roundness) {
            case ROUND:
                config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
                break;
            case NOTROUND:
                config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_NO;
        }
    } else {
        config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_UNDEFINED;
    }
    String locale = params.getLocale();
    if (locale != null && !locale.isEmpty())
        config.locale = new Locale(locale);
    return config;
}
Also used : ScreenOrientation(com.android.resources.ScreenOrientation) Locale(java.util.Locale) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) Configuration(android.content.res.Configuration) ScreenSize(com.android.resources.ScreenSize) Density(com.android.resources.Density) ScreenRound(com.android.resources.ScreenRound)

Aggregations

HardwareConfig (com.android.ide.common.rendering.api.HardwareConfig)33 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)13 BufferedImage (java.awt.image.BufferedImage)12 Result (com.android.ide.common.rendering.api.Result)11 Bitmap (android.graphics.Bitmap)7 Canvas (android.graphics.Canvas)7 Drawable (android.graphics.drawable.Drawable)7 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)7 SessionParams (com.android.ide.common.rendering.api.SessionParams)7 Configuration (android.content.res.Configuration)6 DisplayMetrics (android.util.DisplayMetrics)6 DrawableParams (com.android.ide.common.rendering.api.DrawableParams)6 RenderResources (com.android.ide.common.rendering.api.RenderResources)6 RenderingMode (com.android.ide.common.rendering.api.SessionParams.RenderingMode)6 Density (com.android.resources.Density)6 ScreenOrientation (com.android.resources.ScreenOrientation)6 ScreenSize (com.android.resources.ScreenSize)6 Color (java.awt.Color)6 Graphics2D (java.awt.Graphics2D)6 StateListDrawable (android.graphics.drawable.StateListDrawable)5