Search in sources :

Example 11 with NinePatch

use of android.graphics.NinePatch in project android_frameworks_base by crdroidandroid.

the class NinePatchDrawable method computeBitmapSize.

private void computeBitmapSize() {
    final NinePatch ninePatch = mNinePatchState.mNinePatch;
    if (ninePatch == null) {
        return;
    }
    final int sourceDensity = ninePatch.getDensity();
    final int targetDensity = mTargetDensity;
    final Insets sourceOpticalInsets = mNinePatchState.mOpticalInsets;
    if (sourceOpticalInsets != Insets.NONE) {
        final int left = Drawable.scaleFromDensity(sourceOpticalInsets.left, sourceDensity, targetDensity, true);
        final int top = Drawable.scaleFromDensity(sourceOpticalInsets.top, sourceDensity, targetDensity, true);
        final int right = Drawable.scaleFromDensity(sourceOpticalInsets.right, sourceDensity, targetDensity, true);
        final int bottom = Drawable.scaleFromDensity(sourceOpticalInsets.bottom, sourceDensity, targetDensity, true);
        mOpticalInsets = Insets.of(left, top, right, bottom);
    } else {
        mOpticalInsets = Insets.NONE;
    }
    final Rect sourcePadding = mNinePatchState.mPadding;
    if (sourcePadding != null) {
        if (mPadding == null) {
            mPadding = new Rect();
        }
        mPadding.left = Drawable.scaleFromDensity(sourcePadding.left, sourceDensity, targetDensity, false);
        mPadding.top = Drawable.scaleFromDensity(sourcePadding.top, sourceDensity, targetDensity, false);
        mPadding.right = Drawable.scaleFromDensity(sourcePadding.right, sourceDensity, targetDensity, false);
        mPadding.bottom = Drawable.scaleFromDensity(sourcePadding.bottom, sourceDensity, targetDensity, false);
    } else {
        mPadding = null;
    }
    mBitmapHeight = Drawable.scaleFromDensity(ninePatch.getHeight(), sourceDensity, targetDensity, true);
    mBitmapWidth = Drawable.scaleFromDensity(ninePatch.getWidth(), sourceDensity, targetDensity, true);
    final NinePatch.InsetStruct insets = ninePatch.getBitmap().getNinePatchInsets();
    if (insets != null) {
        Rect outlineRect = insets.outlineRect;
        mOutlineInsets = NinePatch.InsetStruct.scaleInsets(outlineRect.left, outlineRect.top, outlineRect.right, outlineRect.bottom, targetDensity / (float) sourceDensity);
        mOutlineRadius = Drawable.scaleFromDensity(insets.outlineRadius, sourceDensity, targetDensity);
    } else {
        mOutlineInsets = null;
    }
}
Also used : Rect(android.graphics.Rect) Insets(android.graphics.Insets) NinePatch(android.graphics.NinePatch) Paint(android.graphics.Paint)

Aggregations

NinePatch (android.graphics.NinePatch)11 Paint (android.graphics.Paint)11 Rect (android.graphics.Rect)11 Bitmap (android.graphics.Bitmap)6 BitmapFactory (android.graphics.BitmapFactory)6 TypedValue (android.util.TypedValue)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 ColorStateList (android.content.res.ColorStateList)5 Resources (android.content.res.Resources)5 Insets (android.graphics.Insets)5 TypedArray (android.content.res.TypedArray)1