use of android.graphics.drawable.ShapeDrawable in project SublimePicker by vikramkakkar.
the class SUtils method createButtonShape.
// Base button shape
private static Drawable createButtonShape(Context context, int color) {
// Translation of Lollipop's xml button-bg definition to Java
int paddingH = context.getResources().getDimensionPixelSize(R.dimen.button_padding_horizontal_material);
int paddingV = context.getResources().getDimensionPixelSize(R.dimen.button_padding_vertical_material);
int insetH = context.getResources().getDimensionPixelSize(R.dimen.button_inset_horizontal_material);
int insetV = context.getResources().getDimensionPixelSize(R.dimen.button_inset_vertical_material);
float[] outerRadii = new float[8];
Arrays.fill(outerRadii, CORNER_RADIUS);
RoundRectShape r = new RoundRectShape(outerRadii, null, null);
ShapeDrawable shapeDrawable = new ShapeDrawable(r);
shapeDrawable.getPaint().setColor(color);
shapeDrawable.setPadding(paddingH, paddingV, paddingH, paddingV);
return new InsetDrawable(shapeDrawable, insetH, insetV, insetH, insetV);
}
use of android.graphics.drawable.ShapeDrawable in project Ushahidi_Android by ushahidi.
the class IcsProgressBar method tileify.
/**
* Converts a drawable to a tiled version of itself. It will recursively
* traverse layer and state list drawables.
*/
private Drawable tileify(Drawable drawable, boolean clip) {
if (drawable instanceof LayerDrawable) {
LayerDrawable background = (LayerDrawable) drawable;
final int N = background.getNumberOfLayers();
Drawable[] outDrawables = new Drawable[N];
for (int i = 0; i < N; i++) {
int id = background.getId(i);
outDrawables[i] = tileify(background.getDrawable(i), (id == android.R.id.progress || id == android.R.id.secondaryProgress));
}
LayerDrawable newBg = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
newBg.setId(i, background.getId(i));
}
return newBg;
} else /* else if (drawable instanceof StateListDrawable) {
StateListDrawable in = (StateListDrawable) drawable;
StateListDrawable out = new StateListDrawable();
int numStates = in.getStateCount();
for (int i = 0; i < numStates; i++) {
out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
}
return out;
}*/
if (drawable instanceof BitmapDrawable) {
final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
if (mSampleTile == null) {
mSampleTile = tileBitmap;
}
final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
shapeDrawable.getPaint().setShader(bitmapShader);
return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
}
return drawable;
}
use of android.graphics.drawable.ShapeDrawable in project SublimePicker by vikramkakkar.
the class SUtils method createBgDrawable.
// Creates a drawable with the supplied color and corner radii
public static Drawable createBgDrawable(int color, int rTopLeft, int rTopRight, int rBottomRight, int rBottomLeft) {
float[] outerRadii = new float[8];
outerRadii[0] = rTopLeft;
outerRadii[1] = rTopLeft;
outerRadii[2] = rTopRight;
outerRadii[3] = rTopRight;
outerRadii[4] = rBottomRight;
outerRadii[5] = rBottomRight;
outerRadii[6] = rBottomLeft;
outerRadii[7] = rBottomLeft;
RoundRectShape r = new RoundRectShape(outerRadii, null, null);
ShapeDrawable shapeDrawable = new ShapeDrawable(r);
shapeDrawable.getPaint().setColor(color);
return shapeDrawable;
}
use of android.graphics.drawable.ShapeDrawable in project SublimePicker by vikramkakkar.
the class SUtils method createImageViewShape.
// Base icon bg shape
private static Drawable createImageViewShape(int color) {
OvalShape ovalShape = new OvalShape();
ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
shapeDrawable.getPaint().setColor(color);
return shapeDrawable;
}
use of android.graphics.drawable.ShapeDrawable in project android_frameworks_base by ParanoidAndroid.
the class PlaybackGraphs method gatherFrameMetric.
private void gatherFrameMetric(int metricIndex, double[] metricValues, RunData data) {
// create graph out of rectangles, one per frame
int lastBar = 0;
for (int frameIndex = 0; frameIndex < data.frames.length; frameIndex++) {
TileData[] frame = data.frames[frameIndex];
int newBar = (int) ((frame[0].top + frame[0].bottom) * frame[0].scale / 2.0f);
MetricGen s = Metrics[metricIndex];
double absoluteValue = s.getValue(frame);
double relativeValue = absoluteValue / s.getMax();
relativeValue = Math.min(1, relativeValue);
relativeValue = Math.max(0, relativeValue);
int rightPos = (int) (-BAR_WIDTH * metricIndex);
int leftPos = (int) (-BAR_WIDTH * (metricIndex + relativeValue));
ShapeDrawable graphBar = new ShapeDrawable();
graphBar.getPaint().setColor(Color.BLUE);
graphBar.setBounds(leftPos, lastBar, rightPos, newBar);
mShapes.add(graphBar);
metricValues[frameIndex] = absoluteValue;
lastBar = newBar;
}
}
Aggregations