use of android.graphics.drawable.PaintDrawable in project platform_frameworks_base by android.
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);
}
use of android.graphics.drawable.PaintDrawable in project Douya by DreaminginCodeZH.
the class DrawableUtils method makeScrimDrawable.
// From Muzei, Copyright 2014 Google Inc.
public static Drawable makeScrimDrawable(int baseColor, int numStops, int gravity) {
numStops = Math.max(numStops, 2);
PaintDrawable paintDrawable = new PaintDrawable();
paintDrawable.setShape(new RectShape());
final int[] stopColors = new int[numStops];
int red = Color.red(baseColor);
int green = Color.green(baseColor);
int blue = Color.blue(baseColor);
int alpha = Color.alpha(baseColor);
for (int i = 0; i < numStops; i++) {
float x = i * 1f / (numStops - 1);
float opacity = MathUtils.clamp((float) Math.pow(x, 3), 0, 1);
stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
}
final float x0, x1, y0, y1;
switch(gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.LEFT:
x0 = 1;
x1 = 0;
break;
case Gravity.RIGHT:
x0 = 0;
x1 = 1;
break;
default:
x0 = 0;
x1 = 0;
break;
}
switch(gravity & Gravity.VERTICAL_GRAVITY_MASK) {
case Gravity.TOP:
y0 = 1;
y1 = 0;
break;
case Gravity.BOTTOM:
y0 = 0;
y1 = 1;
break;
default:
y0 = 0;
y1 = 0;
break;
}
paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
@Override
public Shader resize(int width, int height) {
return new LinearGradient(width * x0, height * y0, width * x1, height * y1, stopColors, null, Shader.TileMode.CLAMP);
}
});
paintDrawable.setAlpha(Math.round(0.4f * 255));
return paintDrawable;
}
use of android.graphics.drawable.PaintDrawable in project android_frameworks_base by AOSPA.
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);
}
use of android.graphics.drawable.PaintDrawable in project android_frameworks_base by ResurrectionRemix.
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);
}
use of android.graphics.drawable.PaintDrawable in project android_frameworks_base by crdroidandroid.
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;
}
Aggregations