Example #1
0
    @Override
    public void onDraw(final Canvas c) {
      // Draw the alpha pattern
      mAlphaPattern.draw(c);

      // Draw the shader that shows how transparent a colors looks at a given alpha on top of the
      // alpha pattern
      shaderPaint.setShader(
          new LinearGradient(
              borderSize, 0, this.getWidth() - borderSize, 0, 0, color, TileMode.CLAMP));
      c.drawRect(
          borderSize,
          borderSize,
          this.getWidth() - borderSize,
          this.getHeight() - borderSize,
          shaderPaint);

      // Draw the transparency label on top of that stuff
      c.drawText(
          "Transparency",
          this.getWidth() / 2,
          this.getHeight() / 2 + labelPaint.getTextSize() / 2.0f,
          labelPaint);

      // Draw the alpha tracker on top of everything else
      final float xPos = alphaToXPos(alpha);
      final float rectWidth = 2 * mDensity;
      final RectF r = new RectF();
      r.left = xPos - rectWidth;
      r.right = xPos + rectWidth;
      r.top = 0;
      r.bottom = this.getHeight();
      c.drawRoundRect(r, rectWidth, rectWidth, trackerPaint);
    }
Example #2
0
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
      super.onSizeChanged(w, h, oldw, oldh);

      mAlphaPattern = new AlphaPatternDrawable((int) (5 * mDensity));
      mAlphaPattern.setBounds(
          borderSize, borderSize, this.getWidth() - borderSize, this.getHeight() - borderSize);
    }
  @Override
  protected void onDraw(Canvas canvas) {

    final RectF rect = mColorRect;

    if (BORDER_WIDTH_PX > 0) {
      mBorderPaint.setColor(mBorderColor);
      canvas.drawRect(mDrawingRect, mBorderPaint);
    }

    if (mAlphaPattern != null) {
      mAlphaPattern.draw(canvas);
    }

    mColorPaint.setColor(mColor);

    canvas.drawRect(rect, mColorPaint);
  }
  private void setUpColorRect() {
    final RectF dRect = mDrawingRect;

    float left = dRect.left + BORDER_WIDTH_PX;
    float top = dRect.top + BORDER_WIDTH_PX;
    float bottom = dRect.bottom - BORDER_WIDTH_PX;
    float right = dRect.right - BORDER_WIDTH_PX;

    mColorRect = new RectF(left, top, right, bottom);

    mAlphaPattern = new AlphaPatternDrawable((int) (5 * mDensity));

    mAlphaPattern.setBounds(
        Math.round(mColorRect.left),
        Math.round(mColorRect.top),
        Math.round(mColorRect.right),
        Math.round(mColorRect.bottom));
  }