Search in sources :

Example 11 with PaintDrawable

use of android.graphics.drawable.PaintDrawable in project hubroid by EddieRingle.

the class OcticonView method initialize.

protected void initialize(AttributeSet attrs) {
    if (OCTICON_TYPE == null) {
        OCTICON_TYPE = Typeface.createFromAsset(getContext().getAssets(), OCTICON_FONT);
    }
    mPaintDrawable = new PaintDrawable(Color.TRANSPARENT);
    mPaintDrawable.setCornerRadius(OCTICON_CORNER_RADIUS);
    setBackgroundDrawable(mPaintDrawable);
    mTextView = new TextView(getContext());
    mTextView.setBackgroundDrawable(null);
    mTextView.setTypeface(OCTICON_TYPE);
    mTextView.setTextColor(Color.WHITE);
    LayoutParams textViewParams = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    textViewParams.addRule(CENTER_IN_PARENT);
    addView(mTextView, textViewParams);
    LayoutParams layoutParams = (LayoutParams) getLayoutParams();
    if (layoutParams == null) {
        layoutParams = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    }
    setLayoutParams(layoutParams);
    if (attrs != null) {
        int[] handledAttrs = { android.R.attr.textSize, android.R.attr.textColor };
        final TypedArray attrArray = getContext().obtainStyledAttributes(attrs, handledAttrs);
        setGlyphSize(attrArray.getDimension(0, 24));
        mTextView.setTextColor(attrArray.getColor(1, Color.WHITE));
    }
    setId(getId());
}
Also used : TypedArray(android.content.res.TypedArray) PaintDrawable(android.graphics.drawable.PaintDrawable) TextView(android.widget.TextView)

Example 12 with PaintDrawable

use of android.graphics.drawable.PaintDrawable in project android_frameworks_base by DirtyUnicorns.

the class IconUtilities method createIconBitmap.

/**
     * Returns a bitmap suitable for the all apps view.  The bitmap will be a power
     * of two sized ARGB_8888 bitmap that can be used as a gl texture.
     */
public Bitmap createIconBitmap(Drawable icon) {
    int width = mIconWidth;
    int height = mIconHeight;
    if (icon instanceof PaintDrawable) {
        PaintDrawable painter = (PaintDrawable) icon;
        painter.setIntrinsicWidth(width);
        painter.setIntrinsicHeight(height);
    } else if (icon instanceof BitmapDrawable) {
        // Ensure the bitmap has a density.
        BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
        Bitmap bitmap = bitmapDrawable.getBitmap();
        if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
            bitmapDrawable.setTargetDensity(mDisplayMetrics);
        }
    }
    int sourceWidth = icon.getIntrinsicWidth();
    int sourceHeight = icon.getIntrinsicHeight();
    if (sourceWidth > 0 && sourceHeight > 0) {
        // There are intrinsic sizes.
        if (width < sourceWidth || height < sourceHeight) {
            // It's too big, scale it down.
            final float ratio = (float) sourceWidth / sourceHeight;
            if (sourceWidth > sourceHeight) {
                height = (int) (width / ratio);
            } else if (sourceHeight > sourceWidth) {
                width = (int) (height * ratio);
            }
        } else if (sourceWidth < width && sourceHeight < height) {
            // It's small, use the size they gave us.
            width = sourceWidth;
            height = sourceHeight;
        }
    }
    // no intrinsic size --> use default size
    int textureWidth = mIconTextureWidth;
    int textureHeight = mIconTextureHeight;
    final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888);
    final Canvas canvas = mCanvas;
    canvas.setBitmap(bitmap);
    final int left = (textureWidth - width) / 2;
    final int top = (textureHeight - height) / 2;
    if (false) {
        // draw a big box for the icon for debugging
        canvas.drawColor(sColors[mColorIndex]);
        if (++mColorIndex >= sColors.length)
            mColorIndex = 0;
        Paint debugPaint = new Paint();
        debugPaint.setColor(0xffcccc00);
        canvas.drawRect(left, top, left + width, top + height, debugPaint);
    }
    mOldBounds.set(icon.getBounds());
    icon.setBounds(left, top, left + width, top + height);
    icon.draw(canvas);
    icon.setBounds(mOldBounds);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) PaintDrawable(android.graphics.drawable.PaintDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 13 with PaintDrawable

use of android.graphics.drawable.PaintDrawable in project android_frameworks_base by DirtyUnicorns.

the class GridSimple method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    getGridView().setSelector(new PaintDrawable(0xFFFF0000));
    getGridView().setPadding(0, 0, 0, 0);
    getGridView().setFadingEdgeLength(64);
    getGridView().setVerticalFadingEdgeEnabled(true);
    getGridView().setBackgroundColor(0xFFC0C0C0);
}
Also used : PaintDrawable(android.graphics.drawable.PaintDrawable)

Example 14 with PaintDrawable

use of android.graphics.drawable.PaintDrawable in project android_frameworks_base by ResurrectionRemix.

the class IconUtilities method createIconBitmap.

/**
     * Returns a bitmap suitable for the all apps view.  The bitmap will be a power
     * of two sized ARGB_8888 bitmap that can be used as a gl texture.
     */
public Bitmap createIconBitmap(Drawable icon) {
    int width = mIconWidth;
    int height = mIconHeight;
    if (icon instanceof PaintDrawable) {
        PaintDrawable painter = (PaintDrawable) icon;
        painter.setIntrinsicWidth(width);
        painter.setIntrinsicHeight(height);
    } else if (icon instanceof BitmapDrawable) {
        // Ensure the bitmap has a density.
        BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
        Bitmap bitmap = bitmapDrawable.getBitmap();
        if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
            bitmapDrawable.setTargetDensity(mDisplayMetrics);
        }
    }
    int sourceWidth = icon.getIntrinsicWidth();
    int sourceHeight = icon.getIntrinsicHeight();
    if (sourceWidth > 0 && sourceHeight > 0) {
        // There are intrinsic sizes.
        if (width < sourceWidth || height < sourceHeight) {
            // It's too big, scale it down.
            final float ratio = (float) sourceWidth / sourceHeight;
            if (sourceWidth > sourceHeight) {
                height = (int) (width / ratio);
            } else if (sourceHeight > sourceWidth) {
                width = (int) (height * ratio);
            }
        } else if (sourceWidth < width && sourceHeight < height) {
            // It's small, use the size they gave us.
            width = sourceWidth;
            height = sourceHeight;
        }
    }
    // no intrinsic size --> use default size
    int textureWidth = mIconTextureWidth;
    int textureHeight = mIconTextureHeight;
    final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888);
    final Canvas canvas = mCanvas;
    canvas.setBitmap(bitmap);
    final int left = (textureWidth - width) / 2;
    final int top = (textureHeight - height) / 2;
    if (false) {
        // draw a big box for the icon for debugging
        canvas.drawColor(sColors[mColorIndex]);
        if (++mColorIndex >= sColors.length)
            mColorIndex = 0;
        Paint debugPaint = new Paint();
        debugPaint.setColor(0xffcccc00);
        canvas.drawRect(left, top, left + width, top + height, debugPaint);
    }
    mOldBounds.set(icon.getBounds());
    icon.setBounds(left, top, left + width, top + height);
    icon.draw(canvas);
    icon.setBounds(mOldBounds);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) PaintDrawable(android.graphics.drawable.PaintDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 15 with PaintDrawable

use of android.graphics.drawable.PaintDrawable in project android_packages_apps_Launcher2 by CyanogenMod.

the class Utilities method createIconBitmap.

/**
     * Returns a bitmap suitable for the all apps view.
     */
static Bitmap createIconBitmap(Drawable icon, Context context) {
    synchronized (sCanvas) {
        // we share the statics :-(
        if (sIconWidth == -1) {
            initStatics(context);
        }
        int width = sIconWidth;
        int height = sIconHeight;
        if (icon instanceof PaintDrawable) {
            PaintDrawable painter = (PaintDrawable) icon;
            painter.setIntrinsicWidth(width);
            painter.setIntrinsicHeight(height);
        } else if (icon instanceof BitmapDrawable) {
            // Ensure the bitmap has a density.
            BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
                bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
            }
        }
        int sourceWidth = icon.getIntrinsicWidth();
        int sourceHeight = icon.getIntrinsicHeight();
        if (sourceWidth > 0 && sourceHeight > 0) {
            // There are intrinsic sizes.
            if (width < sourceWidth || height < sourceHeight) {
                // It's too big, scale it down.
                final float ratio = (float) sourceWidth / sourceHeight;
                if (sourceWidth > sourceHeight) {
                    height = (int) (width / ratio);
                } else if (sourceHeight > sourceWidth) {
                    width = (int) (height * ratio);
                }
            } else if (sourceWidth < width && sourceHeight < height) {
                // Don't scale up the icon
                width = sourceWidth;
                height = sourceHeight;
            }
        }
        // no intrinsic size --> use default size
        int textureWidth = sIconTextureWidth;
        int textureHeight = sIconTextureHeight;
        final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888);
        final Canvas canvas = sCanvas;
        canvas.setBitmap(bitmap);
        final int left = (textureWidth - width) / 2;
        final int top = (textureHeight - height) / 2;
        // suppress dead code warning
        @SuppressWarnings("all") final boolean debug = false;
        if (debug) {
            // draw a big box for the icon for debugging
            canvas.drawColor(sColors[sColorIndex]);
            if (++sColorIndex >= sColors.length)
                sColorIndex = 0;
            Paint debugPaint = new Paint();
            debugPaint.setColor(0xffcccc00);
            canvas.drawRect(left, top, left + width, top + height, debugPaint);
        }
        sOldBounds.set(icon.getBounds());
        icon.setBounds(left, top, left + width, top + height);
        icon.draw(canvas);
        icon.setBounds(sOldBounds);
        canvas.setBitmap(null);
        return bitmap;
    }
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) PaintDrawable(android.graphics.drawable.PaintDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Aggregations

PaintDrawable (android.graphics.drawable.PaintDrawable)26 Bitmap (android.graphics.Bitmap)10 Canvas (android.graphics.Canvas)10 Paint (android.graphics.Paint)10 BitmapDrawable (android.graphics.drawable.BitmapDrawable)10 LinearGradient (android.graphics.LinearGradient)5 Shader (android.graphics.Shader)5 Drawable (android.graphics.drawable.Drawable)5 ShapeDrawable (android.graphics.drawable.ShapeDrawable)5 RectShape (android.graphics.drawable.shapes.RectShape)5 TypedArray (android.content.res.TypedArray)4 LayerDrawable (android.graphics.drawable.LayerDrawable)4 Attributes (com.cengalabs.flatui.Attributes)3 Typeface (android.graphics.Typeface)2 GradientDrawable (android.graphics.drawable.GradientDrawable)2 InsetDrawable (android.graphics.drawable.InsetDrawable)2 StateListDrawable (android.graphics.drawable.StateListDrawable)2 TextPaint (android.text.TextPaint)2 Resources (android.content.res.Resources)1 ClipDrawable (android.graphics.drawable.ClipDrawable)1