Example usage for android.graphics.drawable ShapeDrawable setBounds

List of usage examples for android.graphics.drawable ShapeDrawable setBounds

Introduction

In this page you can find the example usage for android.graphics.drawable ShapeDrawable setBounds.

Prototype

public void setBounds(int left, int top, int right, int bottom) 

Source Link

Document

Specify a bounding rectangle for the Drawable.

Usage

From source file:com.richtodd.android.quiltdesign.block.PaperPiecedBlockPiece.java

private Drawable createDrawable(RenderOptions renderOptions) {

    PathShape pathShape = new PathShape(getPath(renderOptions.getWidth(), renderOptions.getHeight()),
            renderOptions.getWidth(), renderOptions.getHeight());

    if (renderOptions.getRenderStyle() == RenderStyles.BlackWhite) {

        ShapeDrawable strokeDrawable = new ShapeDrawable(pathShape);
        strokeDrawable.setBounds(0, 0, renderOptions.getWidth(), renderOptions.getHeight());
        strokeDrawable.getPaint().setColor(Color.BLACK);
        strokeDrawable.getPaint().setStyle(Paint.Style.STROKE);
        strokeDrawable.getPaint().setStrokeWidth(renderOptions.getStrokeWidth());

        ShapeDrawable fillDrawable = new ShapeDrawable(pathShape);
        fillDrawable.setBounds(0, 0, renderOptions.getWidth(), renderOptions.getHeight());
        fillDrawable.getPaint().setColor(Color.WHITE);
        fillDrawable.getPaint().setStyle(Paint.Style.FILL);

        Drawable[] layers = new Drawable[2];
        layers[0] = fillDrawable;//  w w w  .  j  ava 2s  .  c o m
        layers[1] = strokeDrawable;
        LayerDrawable drawable = new LayerDrawable(layers);

        return drawable;

    } else {

        ShapeDrawable drawable = new ShapeDrawable(pathShape);
        drawable.getPaint().setColor(getColor());
        drawable.getPaint().setStyle(Paint.Style.FILL);

        return drawable;
    }
}

From source file:com.vuze.android.remote.activity.LoginActivity.java

@SuppressWarnings("deprecation")
private void setBackgroundGradient() {

    ViewGroup mainLayout = (ViewGroup) findViewById(R.id.main_loginlayout);
    assert mainLayout != null;
    int h = mainLayout.getHeight();
    int w = mainLayout.getWidth();
    View viewCenterOn = findViewById(R.id.login_frog_logo);
    assert viewCenterOn != null;

    RectShape shape = new RectShape();
    ShapeDrawable mDrawable = new ShapeDrawable(shape);
    int color1 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_1);
    int color2 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_2);

    RadialGradient shader;/*w  w w  .  j a  v  a2s. c o m*/
    if (w > h) {
        int left = viewCenterOn.getLeft() + (viewCenterOn.getWidth() / 2);
        int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2);
        int remaining = w - left;
        shader = new RadialGradient(left, top, remaining, new int[] { color1, color2 }, new float[] { 0, 1.0f },
                Shader.TileMode.CLAMP);
    } else {
        int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2);
        shader = new RadialGradient(w / 2, top, w * 2 / 3, color1, color2, Shader.TileMode.CLAMP);
    }
    mDrawable.setBounds(0, 0, w, h);
    mDrawable.getPaint().setShader(shader);
    mDrawable.getPaint().setDither(true);
    mDrawable.getPaint().setAntiAlias(true);
    mDrawable.setDither(true);

    mainLayout.setDrawingCacheEnabled(true);
    mainLayout.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    mainLayout.setAnimationCacheEnabled(false);

    mainLayout.setBackgroundDrawable(mDrawable);
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java

private void initDrawable(ShapeDrawable drawable, Path path, int color, int width, int height) {
    path.moveTo(0, 0);//from w  ww  .  java 2  s . com
    drawable.setShape(new PathShape(path, width, height));
    drawable.getPaint().setStyle(Paint.Style.STROKE);
    drawable.getPaint().setColor(color);
    drawable.setBounds(0, 0, width, height);

    setLayerType(LAYER_TYPE_SOFTWARE, drawable.getPaint());
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java

private void initGridH(ShapeDrawable drawable, Path path, int color, int width, int height) {
    path.rewind();//from  www . j a  va  2s. c om
    float cellHeight = height / NUM_ROWS;
    for (int i = 0; i < NUM_ROWS; ++i) {
        path.moveTo(0, i * cellHeight);
        path.lineTo(width, i * cellHeight);
    }

    float offset = NUM_COLUMNS * 5;
    drawable.setShape(new PathShape(path, width, height));
    drawable.getPaint().setStyle(Paint.Style.STROKE);
    drawable.getPaint().setColor(color);
    drawable.getPaint().setPathEffect(new DashPathEffect(new float[] { 1, (width - offset) / offset }, 0));
    drawable.setBounds(0, 0, width, height);
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.ScopeView.java

private void initGridV(ShapeDrawable drawable, Path path, int color, int width, int height) {
    path.rewind();/*from  ww w.  j av  a 2 s  . c om*/
    float cellWidth = width / NUM_COLUMNS;
    for (int i = 0; i < NUM_COLUMNS; ++i) {
        path.moveTo(i * cellWidth, 0);
        path.lineTo(i * cellWidth, height);
    }

    float offset = NUM_ROWS * 5;
    drawable.setShape(new PathShape(path, width, height));
    drawable.getPaint().setStyle(Paint.Style.STROKE);
    drawable.getPaint().setColor(color);
    drawable.getPaint().setPathEffect(new DashPathEffect(new float[] { 1, (height - offset) / offset }, 0));
    drawable.setBounds(0, 0, width, height);
}