Search in sources :

Example 1 with Density

use of com.android.resources.Density in project android_frameworks_base by ParanoidAndroid.

the class BitmapFactory_Delegate method nativeDecodeStream.

@LayoutlibDelegate
static /*package*/
Bitmap nativeDecodeStream(InputStream is, byte[] storage, Rect padding, Options opts, boolean applyScale, float scale) {
    Bitmap bm = null;
    //TODO support rescaling
    Density density = Density.MEDIUM;
    if (opts != null) {
        density = Density.getEnum(opts.inDensity);
    }
    try {
        if (is instanceof NinePatchInputStream) {
            NinePatchInputStream npis = (NinePatchInputStream) is;
            npis.disableFakeMarkSupport();
            // load the bitmap as a nine patch
            com.android.ninepatch.NinePatch ninePatch = com.android.ninepatch.NinePatch.load(npis, true, /*is9Patch*/
            false);
            // get the bitmap and chunk objects.
            bm = Bitmap_Delegate.createBitmap(ninePatch.getImage(), true, /*isMutable*/
            density);
            NinePatchChunk chunk = ninePatch.getChunk();
            // put the chunk in the bitmap
            bm.setNinePatchChunk(NinePatch_Delegate.serialize(chunk));
            // read the padding
            int[] paddingarray = chunk.getPadding();
            padding.left = paddingarray[0];
            padding.top = paddingarray[1];
            padding.right = paddingarray[2];
            padding.bottom = paddingarray[3];
        } else {
            // load the bitmap directly.
            bm = Bitmap_Delegate.createBitmap(is, true, density);
        }
    } catch (IOException e) {
        Bridge.getLog().error(null, "Failed to load image", e, null);
    }
    return bm;
}
Also used : NinePatchInputStream(android.content.res.BridgeResources.NinePatchInputStream) NinePatchChunk(com.android.ninepatch.NinePatchChunk) IOException(java.io.IOException) Density(com.android.resources.Density) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 2 with Density

use of com.android.resources.Density in project android_frameworks_base by ParanoidAndroid.

the class CustomBar method getIcon.

private InputStream getIcon(String iconName, Density[] densityInOut, String[] pathOut, boolean tryOtherDensities) {
    // current density
    Density density = densityInOut[0];
    // bitmap url relative to this class
    pathOut[0] = "/bars/" + density.getResourceValue() + "/" + iconName;
    InputStream stream = getClass().getResourceAsStream(pathOut[0]);
    if (stream == null && tryOtherDensities) {
        for (Density d : Density.values()) {
            if (d != density) {
                densityInOut[0] = d;
                stream = getIcon(iconName, densityInOut, pathOut, false);
                if (stream != null) {
                    return stream;
                }
            }
        }
    }
    return stream;
}
Also used : InputStream(java.io.InputStream) Density(com.android.resources.Density)

Example 3 with Density

use of com.android.resources.Density in project android_frameworks_base by ParanoidAndroid.

the class CustomBar method loadIcon.

protected void loadIcon(int index, String iconName, Density density) {
    View child = getChildAt(index);
    if (child instanceof ImageView) {
        ImageView imageView = (ImageView) child;
        String[] pathOut = new String[1];
        Density[] densityInOut = new Density[] { density };
        InputStream stream = getIcon(iconName, densityInOut, pathOut, true);
        density = densityInOut[0];
        if (stream != null) {
            // look for a cached bitmap
            Bitmap bitmap = Bridge.getCachedBitmap(pathOut[0], true);
            if (bitmap == null) {
                try {
                    bitmap = Bitmap_Delegate.createBitmap(stream, false, /*isMutable*/
                    density);
                    Bridge.setCachedBitmap(pathOut[0], bitmap, true);
                } catch (IOException e) {
                    return;
                }
            }
            if (bitmap != null) {
                BitmapDrawable drawable = new BitmapDrawable(getContext().getResources(), bitmap);
                imageView.setImageDrawable(drawable);
            }
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) ImageView(android.widget.ImageView) IOException(java.io.IOException) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Density(com.android.resources.Density)

Example 4 with Density

use of com.android.resources.Density 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 5 with Density

use of com.android.resources.Density in project android_frameworks_base by DirtyUnicorns.

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

Density (com.android.resources.Density)34 IOException (java.io.IOException)12 File (java.io.File)10 ScreenSize (com.android.resources.ScreenSize)8 Bitmap (android.graphics.Bitmap)7 BitmapDrawable (android.graphics.drawable.BitmapDrawable)7 Configuration (android.content.res.Configuration)6 ColorDrawable (android.graphics.drawable.ColorDrawable)6 DensityBasedResourceValue (com.android.ide.common.rendering.api.DensityBasedResourceValue)6 HardwareConfig (com.android.ide.common.rendering.api.HardwareConfig)6 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)6 ScreenOrientation (com.android.resources.ScreenOrientation)6 FileInputStream (java.io.FileInputStream)6 MalformedURLException (java.net.MalformedURLException)6 XmlPullParser (org.xmlpull.v1.XmlPullParser)6 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 NinePatchChunk (com.android.ninepatch.NinePatchChunk)5 ScreenRound (com.android.resources.ScreenRound)5 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)5 FileNotFoundException (java.io.FileNotFoundException)5