Ejemplo n.º 1
0
  @SuppressWarnings("NewApi")
  public Path computePath(int radius, int l, int t, int r, int b) {
    final Point o = computeOrigin(l, t, r, b);
    final int ol = o.x - radius;
    final int ot = o.y - radius;
    final int or = o.x + radius;
    final int ob = o.y + radius;

    Path path = new Path();
    path.moveTo(o.x, o.y);
    switch (startAngle) {
      case 0:
        path.lineTo(or, o.y);
        break;
      case 90:
        path.lineTo(o.x, ob);
        break;
      case 180:
        path.lineTo(ol, o.y);
        break;
      case 270:
        path.lineTo(o.x, ot);
        break;
      default:
        throw new UnsupportedOperationException();
    }
    if (Utils.LOLLIPOP_OR_LATER) {
      path.arcTo(ol, ot, or, ob, startAngle, sweepAngle, true);
    } else {
      path.arcTo(new RectF(ol, ot, or, ob), startAngle, sweepAngle, true);
    }
    path.lineTo(o.x, o.y);
    return path;
  }
Ejemplo n.º 2
0
 private Path makeSlice(float start, float end, int outer, int inner, Point center) {
   RectF bb = new RectF(center.x - outer, center.y - outer, center.x + outer, center.y + outer);
   RectF bbi = new RectF(center.x - inner, center.y - inner, center.x + inner, center.y + inner);
   Path path = new Path();
   path.arcTo(bb, start, end - start, true);
   path.arcTo(bbi, end, start - end);
   path.close();
   return path;
 }
Ejemplo n.º 3
0
  private Path getOutline(float scale) {
    RectF outerBB = new RectF(-mOuter * scale, -mOuter * scale, mOuter * scale, mOuter * scale);
    RectF innerBB = new RectF(-mInner * scale, -mInner * scale, mInner * scale, mInner * scale);

    double gamma = (mInner + mOuter) * Math.sin(Math.toRadians(mGap / 2.0f));
    float alphaOuter = (float) Math.toDegrees(Math.asin(gamma / (mOuter * 2.0f)));
    float alphaInner = (float) Math.toDegrees(Math.asin(gamma / (mInner * 2.0f)));

    Path path = new Path();
    path.arcTo(outerBB, mStart + alphaOuter, mSweep - 2 * alphaOuter, true);
    path.arcTo(innerBB, mStart + mSweep - alphaInner, 2 * alphaInner - mSweep);
    path.close();

    return path;
  }
 private void buildShadowCorners() {
   Object obj = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius);
   Object obj1 = new RectF(((RectF) (obj)));
   ((RectF) (obj1)).inset(-mShadowSize, -mShadowSize);
   float f;
   float f1;
   float f2;
   float f3;
   int i;
   int j;
   int k;
   if (mCornerShadowPath == null) {
     mCornerShadowPath = new Path();
   } else {
     mCornerShadowPath.reset();
   }
   mCornerShadowPath.setFillType(android.graphics.Path.FillType.EVEN_ODD);
   mCornerShadowPath.moveTo(-mCornerRadius, 0.0F);
   mCornerShadowPath.rLineTo(-mShadowSize, 0.0F);
   mCornerShadowPath.arcTo(((RectF) (obj1)), 180F, 90F, false);
   mCornerShadowPath.arcTo(((RectF) (obj)), 270F, -90F, false);
   mCornerShadowPath.close();
   f = mCornerRadius / (mCornerRadius + mShadowSize);
   obj = mCornerShadowPaint;
   f1 = mCornerRadius;
   f2 = mShadowSize;
   i = mShadowStartColor;
   j = mShadowStartColor;
   k = mShadowEndColor;
   obj1 = android.graphics.Shader.TileMode.CLAMP;
   ((Paint) (obj))
       .setShader(
           new RadialGradient(
               0.0F,
               0.0F,
               f1 + f2,
               new int[] {i, j, k},
               new float[] {0.0F, f, 1.0F},
               ((android.graphics.Shader.TileMode) (obj1))));
   obj = mEdgeShadowPaint;
   f = -mCornerRadius;
   f1 = mShadowSize;
   f2 = -mCornerRadius;
   f3 = mShadowSize;
   i = mShadowStartColor;
   j = mShadowStartColor;
   k = mShadowEndColor;
   obj1 = android.graphics.Shader.TileMode.CLAMP;
   ((Paint) (obj))
       .setShader(
           new LinearGradient(
               0.0F,
               f + f1,
               0.0F,
               f2 - f3,
               new int[] {i, j, k},
               new float[] {0.0F, 0.5F, 1.0F},
               ((android.graphics.Shader.TileMode) (obj1))));
   mEdgeShadowPaint.setAntiAlias(false);
 }
Ejemplo n.º 5
0
 private void drawIntoBitmap() {
   Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
   if (mAlpha) {
     if (!mBlur) {
       mViewBitmap.eraseColor(Color.TRANSPARENT);
     }
   }
   if (mBlur) {
     if (mAlphaMark) {
       p.setAlpha(mBlurVal);
     } else {
       mAlphaMark = true;
     }
   }
   Canvas c = new Canvas(mViewBitmap);
   c.save();
   Path path = new Path();
   path.moveTo(0, 0);
   path.arcTo(
       new RectF(-mBitmapViewWidth, -mBitmapViewWidth, mBitmapViewWidth, mBitmapViewWidth),
       0,
       mAngle);
   // path.lineTo(0, 1);
   path.close();
   c.clipPath(path);
   // c.drawRGB(0, 0, 0);
   // RectF r = new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight);
   c.drawBitmap(
       mBitmap,
       new Rect(mCurX, mCurY, mRadius + mCurX, mBitmapNewHeight + mCurY),
       new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight),
       p);
 }
Ejemplo n.º 6
0
 private void drawIntoBitmap(int i) {
   Canvas c = new Canvas(mViewBitmap);
   // Paint p = new Paint();
   Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
   if (mBlur) {
     if (mAlphaMark) {
       p.setAlpha(mBlurVal);
     } else {
       mAlphaMark = true;
     }
   }
   // p.setAntiAlias(true);
   c.save();
   Path path = new Path();
   path.moveTo(0, 0);
   path.arcTo(
       new RectF(-mBitmapViewWidth, -mBitmapViewWidth, mBitmapViewWidth, mBitmapViewWidth),
       0,
       mAngle);
   // path.lineTo(0, 1);
   path.close();
   c.clipPath(path);
   // RectF r = new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight);
   c.drawBitmap(
       mBitmap,
       new Rect(mCurX, mCurY, mRadius + mCurX, mBitmapNewHeight + mCurY),
       new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight),
       p);
   // mPaint.setTextSize(28);
   // mPaint.setColor(Color.RED);
   // c.drawText(debugString, 150, 50, mPaint);
 }
    @Override
    public Path newInstance(Rect bounds) {
      Preconditions.checkNotNull(bounds);
      float left = bounds.left + padding;
      float top = bounds.top + padding;
      float right = bounds.right - 2;
      float bottom = bounds.bottom - 1 - padding;

      Path path = new Path();
      path.moveTo(right, bottom);
      path.arcTo(new RectF(left, bottom - round * 2, left + round * 2, bottom), 90, 90);
      path.arcTo(new RectF(left, top, left + round + 2, top + round * 2), 180, 90);
      path.lineTo(right, top);
      path.close();

      return path;
    }
 private void drawRightUp(Canvas canvas) {
   Path path = new Path();
   path.moveTo(getWidth(), roundHeight);
   path.lineTo(getWidth(), 0);
   path.lineTo(getWidth() - roundWidth, 0);
   path.arcTo(new RectF(getWidth() - roundWidth * 2, 0, getWidth(), 0 + roundHeight * 2), -90, 90);
   path.close();
   canvas.drawPath(path, paint);
 }
 private void drawLiftDown(Canvas canvas) {
   Path path = new Path();
   path.moveTo(0, getHeight() - roundHeight);
   path.lineTo(0, getHeight());
   path.lineTo(roundWidth, getHeight());
   path.arcTo(new RectF(0, getHeight() - roundHeight * 2, 0 + roundWidth * 2, getWidth()), 90, 90);
   path.close();
   canvas.drawPath(path, paint);
 }
 private void drawLiftUp(Canvas canvas) {
   Path path = new Path();
   path.moveTo(0, roundHeight);
   path.lineTo(0, 0);
   path.lineTo(roundWidth, 0);
   path.arcTo(new RectF(0, 0, roundWidth * 2, roundHeight * 2), -90, -90);
   path.close();
   canvas.drawPath(path, paint);
 }
Ejemplo n.º 11
0
  private void buildShadowCorners() {
    RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-mShadowSize, -mShadowSize);

    if (mCornerShadowPath == null) {
      mCornerShadowPath = new Path();
    } else {
      mCornerShadowPath.reset();
    }
    mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD);
    mCornerShadowPath.moveTo(-mCornerRadius, 0);
    mCornerShadowPath.rLineTo(-mShadowSize, 0);
    // outer arc
    mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false);
    // inner arc
    mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false);
    mCornerShadowPath.close();

    float startRatio = mCornerRadius / (mCornerRadius + mShadowSize);
    mCornerShadowPaint.setShader(
        new RadialGradient(
            0,
            0,
            mCornerRadius + mShadowSize,
            new int[] {mShadowStartColor, mShadowStartColor, mShadowEndColor},
            new float[] {0f, startRatio, 1f},
            Shader.TileMode.CLAMP));

    // we offset the content shadowSize/2 pixels up to make it more realistic.
    // this is why edge shadow shader has some extra space
    // When drawing bottom edge shadow, we use that extra space.
    mEdgeShadowPaint.setShader(
        new LinearGradient(
            0,
            -mCornerRadius + mShadowSize,
            0,
            -mCornerRadius - mShadowSize,
            new int[] {mShadowStartColor, mShadowStartColor, mShadowEndColor},
            new float[] {0f, .5f, 1f},
            Shader.TileMode.CLAMP));
  }
Ejemplo n.º 12
0
  private void getTrackPath(float x, float y, float radius) {
    float halfStroke = mTrackSize / 2f;

    mTrackPath.reset();

    if (mTrackCap != Paint.Cap.ROUND) {
      mTempRect.set(x - radius + 1f, y - radius + 1f, x + radius - 1f, y + radius - 1f);
      float angle = (float) (Math.asin(halfStroke / (radius - 1f)) / Math.PI * 180);

      if (x - radius > mDrawRect.left) {
        mTrackPath.moveTo(mDrawRect.left, y - halfStroke);
        mTrackPath.arcTo(mTempRect, 180 + angle, -angle * 2);
        mTrackPath.lineTo(mDrawRect.left, y + halfStroke);
        mTrackPath.close();
      }

      if (x + radius < mDrawRect.right) {
        mTrackPath.moveTo(mDrawRect.right, y - halfStroke);
        mTrackPath.arcTo(mTempRect, -angle, angle * 2);
        mTrackPath.lineTo(mDrawRect.right, y + halfStroke);
        mTrackPath.close();
      }
    } else {
      float angle = (float) (Math.asin(halfStroke / (radius - 1f)) / Math.PI * 180);

      if (x - radius > mDrawRect.left) {
        float angle2 =
            (float)
                (Math.acos(Math.max(0f, (mDrawRect.left + halfStroke - x + radius) / halfStroke))
                    / Math.PI
                    * 180);

        mTempRect.set(mDrawRect.left, y - halfStroke, mDrawRect.left + mTrackSize, y + halfStroke);
        mTrackPath.arcTo(mTempRect, 180 - angle2, angle2 * 2);

        mTempRect.set(x - radius + 1f, y - radius + 1f, x + radius - 1f, y + radius - 1f);
        mTrackPath.arcTo(mTempRect, 180 + angle, -angle * 2);
        mTrackPath.close();
      }

      if (x + radius < mDrawRect.right) {
        float angle2 =
            (float)
                Math.acos(Math.max(0f, (x + radius - mDrawRect.right + halfStroke) / halfStroke));
        mTrackPath.moveTo(
            (float) (mDrawRect.right - halfStroke + Math.cos(angle2) * halfStroke),
            (float) (y + Math.sin(angle2) * halfStroke));

        angle2 = (float) (angle2 / Math.PI * 180);
        mTempRect.set(
            mDrawRect.right - mTrackSize, y - halfStroke, mDrawRect.right, y + halfStroke);
        mTrackPath.arcTo(mTempRect, angle2, -angle2 * 2);

        mTempRect.set(x - radius + 1f, y - radius + 1f, x + radius - 1f, y + radius - 1f);
        mTrackPath.arcTo(mTempRect, -angle, angle * 2);
        mTrackPath.close();
      }
    }
  }
Ejemplo n.º 13
0
    public void updateCorner(float radius) {
      mRadius = radius;
      Rect bounds = getBounds();

      mPath.reset();
      if (radius == 0)
        mPath.addRect(bounds.left, bounds.top, bounds.right, bounds.bottom, Path.Direction.CW);
      else {
        RectF rect = new RectF();
        mPath.moveTo(bounds.left, bounds.top - radius);
        rect.set(bounds.left, bounds.top, bounds.left + radius * 2, bounds.top + radius * 2);
        mPath.arcTo(rect, 180, 90, false);
        mPath.lineTo(bounds.right - radius, bounds.top);
        rect.set(bounds.right - radius * 2, bounds.top, bounds.right, bounds.top + radius * 2);
        mPath.arcTo(rect, 270, 90, false);
        mPath.lineTo(bounds.right, bounds.bottom);
        mPath.lineTo(bounds.left, bounds.bottom);
        mPath.close();
      }

      invalidateSelf();
    }
Ejemplo n.º 14
0
  @Override
  protected void onSizeChanged(int width, int height, int oldw, int oldh) {

    int centerX = width / 2;
    int centerY = height / 2;

    innerPadding = (int) (paramInnerPadding * width / 100);
    outerPadding = (int) (paramOuterPadding * width / 100);
    arrowPointerSize = (int) (paramArrowPointerSize * width / 100);
    valueSliderWidth = (int) (paramValueSliderWidth * width / 100);

    outerWheelRadius = width / 2 - outerPadding - arrowPointerSize;
    innerWheelRadius = outerWheelRadius - valueSliderWidth;
    colorWheelRadius = innerWheelRadius - innerPadding;

    outerWheelRect.set(
        centerX - outerWheelRadius,
        centerY - outerWheelRadius,
        centerX + outerWheelRadius,
        centerY + outerWheelRadius);
    innerWheelRect.set(
        centerX - innerWheelRadius,
        centerY - innerWheelRadius,
        centerX + innerWheelRadius,
        centerY + innerWheelRadius);

    colorWheelBitmap = createColorWheelBitmap(colorWheelRadius * 2, colorWheelRadius * 2);

    gradientRotationMatrix = new Matrix();
    gradientRotationMatrix.preRotate(270, width / 2, height / 2);

    colorViewPath.arcTo(outerWheelRect, 270, -180);
    colorViewPath.arcTo(innerWheelRect, 90, 180);

    valueSliderPath.arcTo(outerWheelRect, 270, 180);
    valueSliderPath.arcTo(innerWheelRect, 90, -180);
  }
Ejemplo n.º 15
0
  private void drawIntoBitmap(Bitmap bm, Bitmap initialBitmap, int posX, int posY) {
    int x = bm.getWidth();
    int y = bm.getHeight();
    Canvas c = new Canvas(bm);

    c.save();
    Path path = new Path();
    path.moveTo(0, 0);
    path.arcTo(new RectF(-x, -x, x, x), 0, mAngle);
    // path.lineTo(0, 1);
    path.close();
    c.clipPath(path);
    // RectF r = new RectF(0, 0, x, y);
    c.drawBitmap(
        initialBitmap,
        new Rect(posX, posY, mRadius + posX, mBitmapNewHeight + posY),
        new RectF(0, 0, x, y),
        mPaint);
  }
  private void updatePath(final int w, final int h) {
    final float maxAbsSize = Math.min(w, h) / 2f;
    final float absSize = size < maxSize ? maxAbsSize * size / maxSize : maxAbsSize - 1;

    path.reset();

    if (progress == 0) {
      path.close();
    } else if (progress < maxProgress) {
      final float angle = progress * 360 / maxProgress;
      final float x = w / 2f;
      final float y = h / 2f;

      path.moveTo(x, y);
      path.arcTo(new RectF(x - absSize, y - absSize, x + absSize, y + absSize), 270, angle);
      path.close();
    } else {
      path.addCircle(w / 2f, h / 2f, absSize, Direction.CW);
    }
  }
Ejemplo n.º 17
0
  public void draw(Canvas c) {
    changeState();
    setBounds(xCoord - 50, yCoord - 20, xCoord + 50, yCoord + 20);
    Paint p = new Paint();
    Path path = new Path();
    path.setFillType(Path.FillType.EVEN_ODD);
    path.moveTo(xCoord - 50, yCoord);
    path.arcTo(new RectF(xCoord - 50, yCoord - 20, xCoord + 50, yCoord + 20), 180, 180);
    path.lineTo(xCoord, yCoord + 20);
    path.lineTo(xCoord - 50, yCoord);
    path.close();

    p.setColor(Color.CYAN);
    p.setStyle(Paint.Style.FILL_AND_STROKE);
    c.drawPath(path, p);
    p.setColor(Color.BLACK);
    p.setStyle(Paint.Style.STROKE);
    c.drawPath(path, p);

    if (yCoord < 0) {
      setComplete(true);
    }
  }
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    int height = bottom - top;
    int width = right - left;
    // Log.d(TAG, String.format("Height: %d Width: %d", height, width));

    float sizeMultiplier = 1.0f;
    int forcedPadding = 10;

    // determine the position of the background image first
    // then all other items will depend on this one
    // for now, we will just use simple midpoint adjustment
    int pos_x = 0;
    if (mBackground.getWidth() < width) {
      pos_x = (width - mBackground.getWidth()) / 2;
    } else if (mBackground.getWidth() > width) {
      sizeMultiplier = (float) (width) / (float) mBackground.getWidth();
      mBackground =
          Bitmap.createScaledBitmap(
              mBackground,
              (int) (mBackground.getWidth() * sizeMultiplier),
              (int) (mBackground.getHeight() * sizeMultiplier),
              true);
      pos_x = (width - mBackground.getWidth()) / 2;
    }
    int pos_y = 0;
    if (mBackground.getHeight() < height) {
      pos_y = (height - mBackground.getHeight()) / 2;
    } else if (mBackground.getHeight() > height) {
      sizeMultiplier = (float) (height - forcedPadding) / (float) mBackground.getHeight();
      mBackground =
          Bitmap.createScaledBitmap(
              mBackground,
              (int) (mBackground.getWidth() * sizeMultiplier),
              (int) (mBackground.getHeight() * sizeMultiplier),
              true);
      pos_y = (height - mBackground.getHeight()) / 2;
    }
    mBackgroundPosition = new Point(pos_x, pos_y);

    // determine the position of the color wheel
    pos_y = 0;
    if (sizeMultiplier < 1.0f) {
      mWheel =
          Bitmap.createScaledBitmap(
              mWheel,
              (int) (mWheel.getWidth() * sizeMultiplier) - forcedPadding,
              (int) (mWheel.getHeight() * sizeMultiplier) - forcedPadding,
              true);
    }
    if (mWheel.getHeight() < height) {
      pos_y = (height - mWheel.getHeight()) / 2;
    }
    // put the wheel in the center, taking into account the brightness bar
    pos_x =
        (int)
            (mBackgroundPosition.x
                + (mBackground.getWidth()
                        - mWheel.getWidth()
                        - SPACE_BETWEEN_WHEEL_AND_BAR
                        - ARC_WIDTH)
                    / 2);
    mRadius = mWheel.getWidth() / 2.0;
    mWheelPosition = new Point(pos_x, pos_y);
    mWheelCenter = new Point(mWheelPosition.x + (int) mRadius, mWheelPosition.y + (int) mRadius);

    // make the Path for the arc
    // find the angle for the inner arc
    double angle = Math.acos(mRadius / (mRadius + (double) SPACE_BETWEEN_WHEEL_AND_BAR));
    // change angle to degrees
    angle *= (180.0 / Math.PI);
    // get the complementary angle (which is the one we want)
    angle = 90 - angle;
    // Log.d(TAG, String.format("Angle: %f", angle));
    // make the rects that hold the ovals for the arcs
    // the first (inner) will have a radius equal to the sum of the color wheel radius
    // and the space between the color wheel and the brightness bar
    mInnerArcRect =
        new RectF(
            mWheelPosition.x - SPACE_BETWEEN_WHEEL_AND_BAR,
            mWheelPosition.y - SPACE_BETWEEN_WHEEL_AND_BAR,
            mWheelPosition.x + mWheel.getWidth() + SPACE_BETWEEN_WHEEL_AND_BAR,
            mWheelPosition.y + mWheel.getHeight() + SPACE_BETWEEN_WHEEL_AND_BAR);
    // the second (outer) will have a radius equal to the sum of the inner radius
    // and the width of the brightness bar
    mOuterArcRect =
        new RectF(
            mInnerArcRect.left - ARC_WIDTH,
            mInnerArcRect.top - ARC_WIDTH,
            mInnerArcRect.right + ARC_WIDTH,
            mInnerArcRect.bottom + ARC_WIDTH);
    // create a path to hold the bar drawing
    mArcPath = new Path();
    // add the first arc
    mArcPath.arcTo(mInnerArcRect, (float) (angle * -1.0), (float) (2.0 * angle));
    // find the angle for the outer arc
    angle =
        Math.acos(mRadius / (mRadius + (double) SPACE_BETWEEN_WHEEL_AND_BAR + (double) ARC_WIDTH));
    // change angle to degrees
    angle *= (180.0 / Math.PI);
    // get the complementary angle (which is the one we want)
    angle = 90 - angle;
    // Log.d(TAG, String.format("Angle: %f", angle));
    // add the second arc (a line is added in between the end points of the arcs)
    mArcPath.arcTo(mOuterArcRect, (float) angle, (float) (-2.0 * angle));
    mArcPath.close();
  }
Ejemplo n.º 19
0
 public void draw(Canvas paramCanvas) {
   boolean bool = DialogToastListActivity.f;
   super.draw(paramCanvas);
   Paint localPaint = new Paint();
   localPaint.setAntiAlias(true);
   RectF localRectF = new RectF(getBounds());
   if (this.d != null) {
     int i = (int) (13.333333F * j4.a(App.Mb.getApplicationContext()).d);
     int j = (int) (2.0F * i);
     Path localPath = new Path();
     localPath.moveTo(localRectF.left, localRectF.bottom - j);
     localPath.lineTo(localRectF.right, localRectF.bottom - j);
     localPath.lineTo(localRectF.right, localRectF.bottom - this.a);
     localPath.arcTo(
         new RectF(
             localRectF.right - 2.0F * this.a,
             localRectF.bottom - 2.0F * this.a,
             localRectF.right,
             localRectF.bottom),
         0.0F,
         90.0F);
     localPath.lineTo(localRectF.left + this.a, localRectF.bottom);
     localPath.arcTo(
         new RectF(
             localRectF.left,
             localRectF.bottom - 2.0F * this.a,
             localRectF.left + 2.0F * this.a,
             localRectF.bottom),
         90.0F,
         90.0F);
     localPath.lineTo(localRectF.left, localRectF.bottom - j);
     localPaint.setStyle(Paint.Style.FILL);
     if (this.b == 16842919) {
       localPaint.setColor(-1712291840);
       if (!bool) ;
     } else {
       localPaint.setColor(1073741824);
     }
     paramCanvas.drawPath(localPath, localPaint);
     TextPaint localTextPaint = new TextPaint();
     localTextPaint.setAntiAlias(true);
     localTextPaint.setColor(-1);
     localTextPaint.setTextSize(i);
     localTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
     localTextPaint.setTextAlign(Paint.Align.CENTER);
     paramCanvas.drawText(
         TextUtils.ellipsize(
                 this.d, localTextPaint, localRectF.width() - this.a, TextUtils.TruncateAt.END)
             .toString(),
         localRectF.left + localRectF.width() / 2.0F,
         localRectF.bottom - (j - i) / 2,
         localTextPaint);
   }
   localPaint.setStyle(Paint.Style.STROKE);
   localPaint.setStrokeJoin(Paint.Join.ROUND);
   localPaint.setStrokeCap(Paint.Cap.ROUND);
   localRectF.top = (1.0F + localRectF.top);
   localRectF.bottom = (1.0F + localRectF.bottom);
   localPaint.setStrokeWidth(1.5F);
   localPaint.setColor(-1711276033);
   paramCanvas.drawRoundRect(localRectF, this.a, this.a, localPaint);
   localRectF.top -= 1.0F;
   localRectF.bottom -= 1.0F;
   if (this.b == 16842919) {
     localPaint.setColor(-1015808);
     if (!bool) ;
   } else {
     localPaint.setColor(1711276032);
   }
   paramCanvas.drawRoundRect(localRectF, this.a, this.a, localPaint);
   localPaint.setStrokeWidth(1.0F);
   localPaint.setAntiAlias(false);
   if (this.b == 16842919) {
     localPaint.setColor(871399424);
     if (!bool) ;
   } else {
     localPaint.setColor(855638016);
   }
   paramCanvas.drawRoundRect(localRectF, this.a, this.a, localPaint);
 }
Ejemplo n.º 20
0
  public void onDraw(Canvas canvas) {
    canvas.drawColor(Color.TRANSPARENT);
    paint.reset();
    paint.setAntiAlias(true);
    float midX, midY, radius, innerRadius;
    path.reset();

    float currentAngle = 270;
    float currentSweep;
    int totalValue = 0;
    float padding = 2;

    midX = getWidth() / 2;
    midY = getHeight() / 2;
    if (midX < midY) {
      radius = midX;
    } else {
      radius = midY;
    }
    radius -= padding;
    innerRadius = radius - thickness;

    for (PieSlice slice : slices) {
      totalValue += slice.getValue();
    }

    int count = 0;
    for (PieSlice slice : slices) {
      Path p = new Path();
      paint.setColor(slice.getColor());
      currentSweep = (slice.getValue() / totalValue) * (360);
      p.arcTo(
          new RectF(midX - radius, midY - radius, midX + radius, midY + radius),
          currentAngle + padding,
          currentSweep - padding);
      p.arcTo(
          new RectF(midX - innerRadius, midY - innerRadius, midX + innerRadius, midY + innerRadius),
          (currentAngle + padding) + (currentSweep - padding),
          -(currentSweep - padding));
      p.close();

      slice.setPath(p);
      slice.setRegion(
          new Region(
              (int) (midX - radius),
              (int) (midY - radius),
              (int) (midX + radius),
              (int) (midY + radius)));
      canvas.drawPath(p, paint);

      if (indexSelected == count && listener != null) {
        path.reset();
        paint.setColor(slice.getColor());
        paint.setColor(Color.parseColor("#33B5E5"));
        paint.setAlpha(100);

        if (slices.size() > 1) {
          path.arcTo(
              new RectF(
                  midX - radius - (padding * 2),
                  midY - radius - (padding * 2),
                  midX + radius + (padding * 2),
                  midY + radius + (padding * 2)),
              currentAngle,
              currentSweep + padding);
          path.arcTo(
              new RectF(
                  midX - innerRadius + (padding * 2),
                  midY - innerRadius + (padding * 2),
                  midX + innerRadius - (padding * 2),
                  midY + innerRadius - (padding * 2)),
              currentAngle + currentSweep + padding,
              -(currentSweep + padding));
          path.close();
        } else {
          path.addCircle(midX, midY, radius + padding, Direction.CW);
        }

        canvas.drawPath(path, paint);
        paint.setAlpha(255);
      }

      currentAngle = currentAngle + currentSweep;

      count++;
    }
  }
Ejemplo n.º 21
0
  // draw path 96x96
  public static void calcTurnPath(Path pathForTurn, TurnType turnType, Matrix transform) {
    if (turnType == null) {
      return;
    }
    pathForTurn.reset();

    int c = 48;
    int w = 16;
    pathForTurn.moveTo(c, 94);
    float sarrowL = 30; // side of arrow
    float harrowL = (float) Math.sqrt(2) * sarrowL; // hypotenuse of arrow
    float spartArrowL = (float) ((sarrowL - w / Math.sqrt(2)) / 2);
    float hpartArrowL = (float) (harrowL - w) / 2;

    if (TurnType.C.equals(turnType.getValue())) {
      int h = 65;

      pathForTurn.rMoveTo(w / 2, 0);
      pathForTurn.rLineTo(0, -h);
      pathForTurn.rLineTo(hpartArrowL, 0);
      pathForTurn.rLineTo(-harrowL / 2, -harrowL / 2); // center
      pathForTurn.rLineTo(-harrowL / 2, harrowL / 2);
      pathForTurn.rLineTo(hpartArrowL, 0);
      pathForTurn.rLineTo(0, h);
    } else if (TurnType.TR.equals(turnType.getValue()) || TurnType.TL.equals(turnType.getValue())) {
      int b = TurnType.TR.equals(turnType.getValue()) ? 1 : -1;
      int h = 36;
      float quadShiftX = 22;
      float quadShiftY = 22;

      pathForTurn.rMoveTo(-b * 8, 0);
      pathForTurn.rLineTo(0, -h);
      pathForTurn.rQuadTo(0, -quadShiftY, b * quadShiftX, -quadShiftY);
      pathForTurn.rLineTo(0, hpartArrowL);
      pathForTurn.rLineTo(b * harrowL / 2, -harrowL / 2); // center
      pathForTurn.rLineTo(-b * harrowL / 2, -harrowL / 2);
      pathForTurn.rLineTo(0, hpartArrowL);
      pathForTurn.rQuadTo(-b * (quadShiftX + w), 0, -b * (quadShiftX + w), quadShiftY + w);
      pathForTurn.rLineTo(0, h);
    } else if (TurnType.TSLR.equals(turnType.getValue())
        || TurnType.TSLL.equals(turnType.getValue())) {
      int b = TurnType.TSLR.equals(turnType.getValue()) ? 1 : -1;
      int h = 40;
      int quadShiftY = 22;
      float quadShiftX = (float) (quadShiftY / (1 + Math.sqrt(2)));
      float nQuadShiftX = (sarrowL - 2 * spartArrowL) - quadShiftX - w;
      float nQuadShifty = quadShiftY + (sarrowL - 2 * spartArrowL);

      pathForTurn.rMoveTo(-b * 4, 0);
      pathForTurn.rLineTo(0, -h /* + partArrowL */);
      pathForTurn.rQuadTo(
          0,
          -quadShiftY + quadShiftX /*- partArrowL*/,
          b * quadShiftX,
          -quadShiftY /*- partArrowL*/);
      pathForTurn.rLineTo(b * spartArrowL, spartArrowL);
      pathForTurn.rLineTo(0, -sarrowL); // center
      pathForTurn.rLineTo(-b * sarrowL, 0);
      pathForTurn.rLineTo(b * spartArrowL, spartArrowL);
      pathForTurn.rQuadTo(b * nQuadShiftX, -nQuadShiftX, b * nQuadShiftX, nQuadShifty);
      pathForTurn.rLineTo(0, h);
    } else if (TurnType.TSHR.equals(turnType.getValue())
        || TurnType.TSHL.equals(turnType.getValue())) {
      int b = TurnType.TSHR.equals(turnType.getValue()) ? 1 : -1;
      int h = 45;
      float quadShiftX = 22;
      float quadShiftY = -(float) (quadShiftX / (1 + Math.sqrt(2)));
      float nQuadShiftX = -(sarrowL - 2 * spartArrowL) - quadShiftX - w;
      float nQuadShiftY = -quadShiftY + (sarrowL - 2 * spartArrowL);

      pathForTurn.rMoveTo(-b * 8, 0);
      pathForTurn.rLineTo(0, -h);
      pathForTurn.rQuadTo(0, -(quadShiftX - quadShiftY), b * quadShiftX, quadShiftY);
      pathForTurn.rLineTo(-b * spartArrowL, spartArrowL);
      pathForTurn.rLineTo(b * sarrowL, 0); // center
      pathForTurn.rLineTo(0, -sarrowL);
      pathForTurn.rLineTo(-b * spartArrowL, spartArrowL);
      pathForTurn.rCubicTo(
          b * nQuadShiftX / 2,
          nQuadShiftX / 2,
          b * nQuadShiftX,
          nQuadShiftX / 2,
          b * nQuadShiftX,
          nQuadShiftY);
      pathForTurn.rLineTo(0, h);
    } else if (TurnType.TU.equals(turnType.getValue())) {
      int h = 54;
      float quadShiftX = 13;
      float quadShiftY = 13;

      pathForTurn.rMoveTo(28, 0);
      pathForTurn.rLineTo(0, -h);
      pathForTurn.rQuadTo(0, -(quadShiftY + w), -(quadShiftX + w), -(quadShiftY + w));
      pathForTurn.rQuadTo(-(quadShiftX + w), 0, -(quadShiftX + w), (quadShiftY + w));
      pathForTurn.rLineTo(-hpartArrowL, 0);
      pathForTurn.rLineTo(harrowL / 2, harrowL / 2); // center
      pathForTurn.rLineTo(harrowL / 2, -harrowL / 2);
      pathForTurn.rLineTo(-hpartArrowL, 0);
      pathForTurn.rQuadTo(0, -quadShiftX, quadShiftX, -quadShiftY);
      pathForTurn.rQuadTo(quadShiftX, 0, quadShiftX, quadShiftY);
      pathForTurn.rLineTo(0, h);
    } else if (turnType != null && turnType.isRoundAbout()) {
      float t = turnType.getTurnAngle();
      if (t >= 170 && t < 220) {
        t = 220;
      } else if (t > 160 && t < 170) {
        t = 160;
      }
      float sweepAngle = (t - 360) - 180;
      if (sweepAngle < -360) {
        sweepAngle += 360;
      }
      float r1 = 32f;
      float r2 = 24f;
      float angleToRot = 0.3f;

      pathForTurn.moveTo(48, 48 + r1 + 8);
      pathForTurn.lineTo(48, 48 + r1);
      RectF r = new RectF(48 - r1, 48 - r1, 48 + r1, 48 + r1);
      pathForTurn.arcTo(r, 90, sweepAngle);
      float angleRad = (float) ((180 + sweepAngle) * Math.PI / 180f);

      pathForTurn.lineTo(
          48 + (r1 + 4) * FloatMath.sin(angleRad), 48 - (r1 + 4) * FloatMath.cos(angleRad));
      pathForTurn.lineTo(
          48 + (r1 + 6) * FloatMath.sin(angleRad + angleToRot / 2),
          48 - (r1 + 6) * FloatMath.cos(angleRad + angleToRot / 2));
      pathForTurn.lineTo(
          48 + (r1 + 12) * FloatMath.sin(angleRad - angleToRot / 2),
          48 - (r1 + 12) * FloatMath.cos(angleRad - angleToRot / 2));
      pathForTurn.lineTo(
          48 + (r1 + 6) * FloatMath.sin(angleRad - 3 * angleToRot / 2),
          48 - (r1 + 6) * FloatMath.cos(angleRad - 3 * angleToRot / 2));
      pathForTurn.lineTo(
          48 + (r1 + 4) * FloatMath.sin(angleRad - angleToRot),
          48 - (r1 + 4) * FloatMath.cos(angleRad - angleToRot));
      pathForTurn.lineTo(
          48 + r2 * FloatMath.sin(angleRad - angleToRot),
          48 - r2 * FloatMath.cos(angleRad - angleToRot));

      r.set(48 - r2, 48 - r2, 48 + r2, 48 + r2);
      pathForTurn.arcTo(r, 360 + sweepAngle + 90, -sweepAngle);
      pathForTurn.lineTo(40, 48 + r2);
      pathForTurn.lineTo(40, 48 + r1 + 8);
      pathForTurn.close();
    }
    pathForTurn.close();
    if (transform != null) {
      pathForTurn.transform(transform);
    }
  }
  @Override
  protected void onDraw(Canvas canvas) {
    int selectedIndex = getSelectedIndicatorIndex();

    // Draw the highlight arc if an indicator is selected or being pressed.
    // And skip the zoom control which index is zero.
    if (selectedIndex >= 1) {
      int degree = (int) Math.toDegrees(mChildRadians[selectedIndex]);
      float innerR = (float) mShutterButtonRadius;
      float outerR = (float) (mShutterButtonRadius + mStrokeWidth + EDGE_STROKE_WIDTH * 0.5);

      // Construct the path of the fan-shaped semi-transparent area.
      Path fanPath = new Path();
      mBackgroundRect.set(
          mCenterX - innerR, mCenterY - innerR, mCenterX + innerR, mCenterY + innerR);
      fanPath.arcTo(mBackgroundRect, -degree + HIGHLIGHT_DEGREES / 2, -HIGHLIGHT_DEGREES);
      mBackgroundRect.set(
          mCenterX - outerR, mCenterY - outerR, mCenterX + outerR, mCenterY + outerR);
      fanPath.arcTo(mBackgroundRect, -degree - HIGHLIGHT_DEGREES / 2, HIGHLIGHT_DEGREES);
      fanPath.close();

      mBackgroundPaint.setStrokeWidth(HIGHLIGHT_WIDTH);
      mBackgroundPaint.setStrokeCap(Paint.Cap.SQUARE);
      mBackgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
      mBackgroundPaint.setColor(HIGHLIGHT_FAN_COLOR);
      if (FeatureOption.MTK_THEMEMANAGER_APP) {
        int bgColor = res.getThemeMainColor();
        if (bgColor != 0) {
          bgColor &= 0x3FFFFFFF;
          mBackgroundPaint.setColor(bgColor);
        }
      }
      canvas.drawPath(fanPath, mBackgroundPaint);

      // Draw the highlight edge
      mBackgroundPaint.setStyle(Paint.Style.STROKE);
      mBackgroundPaint.setColor(HIGHLIGHT_COLOR);
      if (FeatureOption.MTK_THEMEMANAGER_APP) {
        int bgColor = res.getThemeMainColor();
        if (bgColor != 0) {
          mBackgroundPaint.setColor(bgColor);
        }
      }
      canvas.drawArc(
          mBackgroundRect,
          -degree - HIGHLIGHT_DEGREES / 2,
          HIGHLIGHT_DEGREES,
          false,
          mBackgroundPaint);
    }

    // Draw arc shaped indicator in time lapse recording.
    if (mTimeLapseInterval != 0) {
      // Setup rectangle and paint.
      mBackgroundRect.set(
          (float) (mCenterX - mShutterButtonRadius),
          (float) (mCenterY - mShutterButtonRadius),
          (float) (mCenterX + mShutterButtonRadius),
          (float) (mCenterY + mShutterButtonRadius));
      mBackgroundRect.inset(3f, 3f);
      mBackgroundPaint.setStrokeWidth(TIME_LAPSE_ARC_WIDTH);
      mBackgroundPaint.setStrokeCap(Paint.Cap.ROUND);
      mBackgroundPaint.setColor(TIME_LAPSE_ARC_COLOR);

      // Compute the start angle and sweep angle.
      long timeDelta = SystemClock.uptimeMillis() - mRecordingStartTime;
      long numberOfFrames = timeDelta / mTimeLapseInterval;
      float sweepAngle;
      if (numberOfFrames > mNumberOfFrames) {
        // The arc just acrosses 0 degree. Draw a full circle so it
        // looks better.
        sweepAngle = 360;
        mNumberOfFrames = numberOfFrames;
      } else {
        sweepAngle = timeDelta % mTimeLapseInterval * 360f / mTimeLapseInterval;
      }

      canvas.drawArc(mBackgroundRect, 0, sweepAngle, false, mBackgroundPaint);
      invalidate();
    }

    super.onDraw(canvas);
  }