예제 #1
0
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);

    // Account for padding
    float xpad = (float) (getPaddingLeft() + getPaddingRight());
    float ypad = (float) (getPaddingTop() + getPaddingBottom());

    float ww = (float) w - xpad;
    float hh = (float) h - ypad;
    float size = Math.min(ww, hh);

    // Figure out how big we can make the pie.
    backBound =
        new RectF(
            0.0f, 0.0f, size - coverPaint.getStrokeWidth(), size - coverPaint.getStrokeWidth());
    backBound.offsetTo(
        getPaddingLeft() + coverPaint.getStrokeWidth() / 2,
        getPaddingTop() + coverPaint.getStrokeWidth() / 2);

    coverBound =
        new RectF(
            0.0f, 0.0f, size - coverPaint.getStrokeWidth(), size - coverPaint.getStrokeWidth());
    coverBound.offsetTo(
        getPaddingLeft() + coverPaint.getStrokeWidth() / 2,
        getPaddingTop() + coverPaint.getStrokeWidth() / 2);
  }
예제 #2
0
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);

    float xpad = (float) (getPaddingLeft() + getPaddingRight());
    float ypad = (float) (getPaddingTop() + getPaddingBottom());

    float ww = (float) w - xpad - axisYSpacing;
    float hh = (float) h - ypad - axisXSpacing;

    // Figure out how big we can make the pie.
    mPlotBounds = new RectF(0f, 0f, ww, hh);
    mPlotBounds.offsetTo(getPaddingLeft() + axisYSpacing, getPaddingTop());

    onDataChanged();
  }
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public int onTestSize(int suggestedSize, RectF availableSPace) {
          mPaint.setTextSize(suggestedSize);
          String text = getText().toString();
          boolean singleline = getMaxLines() == 1;
          if (singleline) {
            mTextRect.bottom = mPaint.getFontSpacing();
            mTextRect.right = mPaint.measureText(text);
          } else {
            StaticLayout layout =
                new StaticLayout(
                    text,
                    mPaint,
                    mWidthLimit,
                    Alignment.ALIGN_NORMAL,
                    mSpacingMult,
                    mSpacingAdd,
                    true);
            // return early if we have more lines
            if (getMaxLines() != NO_LINE_LIMIT && layout.getLineCount() > getMaxLines()) {
              return 1;
            }
            mTextRect.bottom = layout.getHeight();
            int maxWidth = -1;
            for (int i = 0; i < layout.getLineCount(); i++) {
              if (maxWidth < layout.getLineWidth(i)) {
                maxWidth = (int) layout.getLineWidth(i);
              }
            }
            mTextRect.right = maxWidth;
          }

          mTextRect.offsetTo(0, 0);
          if (availableSPace.contains(mTextRect)) {
            // may be too small, don't worry we will find the best match
            return -1;
          } else {
            // too big
            return 1;
          }
        }
예제 #4
0
  public Bitmap getRoundedCornerBitmap1(Bitmap bitmap, int row, int column, float radius) {
    float[] radii = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    int bmsIndex = 0;

    {
      bmsIndex = 4;
      if (column == 0) {
        bmsIndex = 3;
      }
      if (column == mNumColumns - 1) {
        bmsIndex = 5;
      }
    }
    if (row == 0) {
      bmsIndex = 1;
      if (column == 0) {
        bmsIndex = 0;
        radii[0] = radii[1] = radius;
      }
      if (column == mNumColumns - 1) {
        bmsIndex = 2;
        radii[2] = radii[3] = radius;
      }
    }
    if (row == mNumRows - 1) {
      bmsIndex = 7;
      if (column == 0) {
        bmsIndex = 6;
        radii[6] = radii[7] = radius;
      }
      if (column == mNumColumns - 1) {
        bmsIndex = 8;
        radii[4] = radii[5] = radius;
      }
    }

    if (bms[bmsIndex] != null) return bms[bmsIndex];

    bms[bmsIndex] = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    Bitmap output = bms[bmsIndex];
    // Bitmap output = Bitmap.createBitmap(w,h, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    // We have to make sure our rounded corners have an alpha channel in most cases
    // color is arbitrary. This could be any color that was fully opaque (alpha = 255)
    int color = 0xff429242;

    // We're just reusing xferPaint to paint a normal looking rounded box,
    // the roundPx is the amount we're rounding by.
    final Paint paint = new Paint();
    int x1 = 0, y1 = 0, x2 = w, y2 = h;

    paint.setAntiAlias(true);
    paint.setStrokeWidth(1);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);

    /*
    if (row==0) {
    	if (column==0)
    	    radii[0] = radii[1]= radius;
        if (column==mNumColumns-1)
    	    radii[2] = radii[3]= radius;
    }


    if (row==mNumRows-1) {
    	if (column==0)
    	    radii[6] = radii[7]= radius;
        if (column==mNumColumns-1)
    	    radii[4] = radii[5]= radius;
       }
       */

    if (row == 0) y1 = MARGIN;
    if (column == mNumColumns - 1) x2 = w - MARGIN;
    if (column == 0) x1 = MARGIN;
    if (row == mNumRows - 1) y2 = h - MARGIN;

    Rect rect = new Rect(x1, y1, x2, y2);
    RectF rectF = new RectF(rect);
    Path path = new Path();
    path.addRoundRect(rectF, radii, Path.Direction.CW);
    canvas.drawPath(path, paint);

    // We're going to apply this paint using a porter-duff xfer mode.
    // This will allow us to only overwrite certain pixels.
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    paint.setTextSize(32);
    canvas.drawBitmap(bitmap, rect, rect, paint);

    paint.setColor(0xFFBBBBFF);
    canvas.drawText("Slate-" + row + "," + column, w / 4, h / 4, paint);
    canvas.drawText("Slate-" + row + "," + column, w / 2, h / 4, paint);
    canvas.drawText("Slate-" + row + "," + column, w / 4, h / 2, paint);
    canvas.drawText("Slate-" + row + "," + column, w / 2, h / 2, paint);
    paint.setColor(color);

    path.rewind();

    final RectF cornerRect = new RectF(MARGIN, MARGIN, radius * 2 + MARGIN, radius * 2 + MARGIN);
    if (row == 0) {
      if (column == 0) {
        path.addArc(cornerRect, 180.0f, 90.0f);
      }
      if ((column == mNumColumns - 1)) {
        cornerRect.offsetTo(w - 2 * radius - MARGIN, MARGIN);
        path.addArc(cornerRect, 270.0f, 90.0f);
      }
    }
    if (row == mNumRows - 1) {
      if (column == mNumColumns - 1) {
        cornerRect.offsetTo(w - 2 * radius - MARGIN, h - 2 * radius - MARGIN);
        path.addArc(cornerRect, 0.0f, 90.0f);
      }
      if (column == 0) {
        cornerRect.offsetTo(MARGIN, h - radius * 2 - MARGIN);
        path.addArc(cornerRect, 90.0f, 90.0f);
      }
    }
    if (row == 0) {
      if ((column >= 0) && (column < mNumColumns - 1)) {
        path.moveTo(radius + MARGIN, MARGIN);
        path.rLineTo(w - 2 * radius - MARGIN, 0);
        path.rLineTo(radius, 0);
      }
      if ((column > 0) && (column <= mNumColumns - 1)) {
        path.moveTo(0, MARGIN);
        path.rLineTo(radius, 0);
        path.rLineTo(w - 2 * radius - MARGIN, 0);
      }
    }
    if (column == mNumColumns - 1) {
      if ((row >= 0) && (row < mNumRows - 1)) {
        path.moveTo(w - MARGIN, radius + MARGIN);
        path.rLineTo(0, h - 2 * radius - MARGIN);
        path.rLineTo(0, radius);
      }
      if ((row > 0) && (row <= mNumColumns - 1)) {
        path.moveTo(w - MARGIN, 0);
        path.rLineTo(0, radius);
        path.rLineTo(0, h - 2 * radius - MARGIN);
      }
    }
    if (column == 0) {
      if ((row >= 0) && (row < mNumRows - 1)) {
        path.moveTo(MARGIN, radius + MARGIN);
        path.rLineTo(0, h - 2 * radius - MARGIN);
        path.rLineTo(0, radius);
      }
      if ((row > 0) && (row <= mNumRows - 1)) {
        path.moveTo(MARGIN, 0);
        path.rLineTo(0, radius);
        path.rLineTo(0, h - 2 * radius - MARGIN);
      }
    }
    if (row == mNumRows - 1) {
      if ((column >= 0) && (column < mNumColumns - 1)) {
        path.moveTo(radius + MARGIN, h - MARGIN);
        path.rLineTo(w - 2 * radius - MARGIN, 0);
        path.rLineTo(radius, 0);
      }
      if ((column > 0) && (column <= mNumColumns - 1)) {
        path.moveTo(0, h - MARGIN);
        path.rLineTo(radius, 0);
        path.rLineTo(w - 2 * radius - MARGIN, 0);
      }
    }

    color = 0xff444444;
    final Paint paint1 = new Paint();
    paint1.setAntiAlias(true);
    paint1.setColor(color);
    paint1.setStyle(Style.STROKE);
    paint1.setStrokeWidth(4);
    paint1.setShadowLayer(10, 4, 4, R.color.magic_flame);
    canvas.drawPath(path, paint1);

    return output;
  }
예제 #5
0
 public void setPosition(float newLeft, float newTop) {
   dstRect.offsetTo(newLeft, newTop);
 }
예제 #6
0
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    Log.d(TAG, "Slice Count: " + mData.size());
    if (mData.size() > 0) {
      //
      // Set dimensions for text, pie chart, etc
      //
      // Account for padding
      float xpad = (float) (getPaddingLeft() + getPaddingRight());
      float ypad = (float) (getPaddingTop() + getPaddingBottom());

      // Account for the label
      if (mShowText) xpad += mTextWidth;

      float ww = (float) w - xpad;
      float hh = (float) h - ypad;

      // Figure out how big we can make the pie.
      float diameter = Math.min(ww, hh);
      mPieBounds = new RectF(0.0f, 0.0f, diameter, diameter);
      mPieBounds.offsetTo(getPaddingLeft(), getPaddingTop());
      //	        Log.d(TAG, "mPieBounds>> "+mPieBounds);

      mPointerY = mTextY - (mTextHeight / 2.0f);
      float pointerOffset = mPieBounds.centerY() - mPointerY;

      // Make adjustments based on text position
      if (mTextPos == TEXTPOS_LEFT) {
        mTextPaint.setTextAlign(Paint.Align.RIGHT);
        if (mShowText) mPieBounds.offset(mTextWidth, 0.0f);
        mTextX = mPieBounds.left;

        if (pointerOffset < 0) {
          pointerOffset = -pointerOffset;
          mCurrentItemAngle = 225;
        } else {
          mCurrentItemAngle = 135;
        }
        mPointerX = mPieBounds.centerX() - pointerOffset;
      } else {
        mTextPaint.setTextAlign(Paint.Align.LEFT);
        mTextX = mPieBounds.right;

        if (pointerOffset < 0) {
          pointerOffset = -pointerOffset;
          mCurrentItemAngle = 315;
        } else {
          mCurrentItemAngle = 45;
        }
        mPointerX = mPieBounds.centerX() + pointerOffset;
      }

      mShadowBounds =
          new RectF(
              mPieBounds.left + 10,
              mPieBounds.bottom + 10,
              mPieBounds.right - 10,
              mPieBounds.bottom + 20);

      // Lay out the child view that actually draws the pie.
      mPieView.layout(
          (int) mPieBounds.left,
          (int) mPieBounds.top,
          (int) mPieBounds.right,
          (int) mPieBounds.bottom);
      mPieView.setPivot(mPieBounds.width() / 2, mPieBounds.height() / 2);

      mPointerView.layout(0, 0, w, h);
      onDataChanged();
    }
  }