/**
   * Creates an animator that can be used for x and/or y translations. When interrupted, it sets a
   * tag to keep track of the position so that it may be continued from position.
   *
   * @param view The view being moved. This may be in the overlay for onDisappear.
   * @param values The values containing the view in the view hierarchy.
   * @param viewPosX The x screen coordinate of view
   * @param startX The start translation x of view
   * @param endX The end translation x of view
   * @param interpolator The interpolator to use with this animator.
   * @return An animator that moves from (startX, startY) to (endX, endY) unless there was a
   *     previous interruption, in which case it moves from the current position to (endX, endY).
   */
  static Animator createAnimation(
      View view,
      TransitionValues values,
      int viewPosX,
      float startX,
      float endX,
      TimeInterpolator interpolator,
      Transition transition) {
    float terminalX = view.getTranslationX();
    Integer startPosition = (Integer) values.view.getTag(R.id.transitionPosition);
    if (startPosition != null) {
      startX = startPosition - viewPosX + terminalX;
    }
    // Initial position is at translation startX, startY, so position is offset by that
    // amount
    int startPosX = viewPosX + Math.round(startX - terminalX);

    view.setTranslationX(startX);
    if (startX == endX) {
      return null;
    }
    Path path = new Path();
    path.moveTo(startX, 0);
    path.lineTo(endX, 0);
    ObjectAnimator anim =
        ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, path);

    TransitionPositionListener listener =
        new TransitionPositionListener(view, values.view, startPosX, terminalX);
    transition.addListener(listener);
    anim.addListener(listener);
    anim.addPauseListener(listener);
    anim.setInterpolator(interpolator);
    return anim;
  }
 private static Path createCubic(
     float paramFloat1, float paramFloat2, float paramFloat3, float paramFloat4) {
   Path localPath = new Path();
   localPath.moveTo(0.0F, 0.0F);
   localPath.cubicTo(paramFloat1, paramFloat2, paramFloat3, paramFloat4, 1.0F, 1.0F);
   return localPath;
 }
  private void computePath(Rect bounds) {
    final float currentScale = mCurrentScale;
    final Path path = mPath;
    final RectF rect = mRect;
    final Matrix matrix = mMatrix;

    path.reset();
    int totalSize = Math.min(bounds.width(), bounds.height());

    float initial = mClosedStateSize;
    float destination = totalSize;
    float currentSize = initial + (destination - initial) * currentScale;

    float halfSize = currentSize / 2f;
    float inverseScale = 1f - currentScale;
    float cornerSize = halfSize * inverseScale;
    float[] corners =
        new float[] {
          halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize, cornerSize
        };
    rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize);
    path.addRoundRect(rect, corners, Path.Direction.CCW);
    matrix.reset();
    matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize);
    matrix.postTranslate((bounds.width() - currentSize) / 2, 0);
    float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale;
    matrix.postTranslate(0, hDiff);
    path.transform(matrix);
  }
Example #4
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);
 }
    public DrawView(Context context) {
      super(context);

      rect = new Rect(0, 0, 100, 100);
      rect1 = new Rect(0, 0, 500, 200);
      p = new Paint(Paint.ANTI_ALIAS_FLAG);
      picture = new Picture();

      Canvas canvas = picture.beginRecording(300, 300);

      p.setColor(Color.GREEN);
      canvas.drawCircle(150, 100, 80, p);

      p.setColor(Color.BLUE);
      canvas.drawRect(20, 70, 150, 200, p);

      p.setColor(Color.RED);
      path = new Path();
      path.moveTo(170, 80);
      path.lineTo(240, 210);
      path.lineTo(100, 210);
      path.close();
      canvas.drawPath(path, p);

      picture.endRecording();
    }
Example #6
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // TODO Auto-generated method stub
    int action = event.getAction();
    int x = (int) event.getX();
    int y = (int) event.getY();
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mLastX = x;
        mLastY = y;
        mPath.moveTo(mLastX, mLastY);

        break;
      case MotionEvent.ACTION_MOVE:
        int dx = Math.abs(x - mLastX);
        int dy = Math.abs(y - mLastY);
        if (dx > 3 || dy > 3) {
          mPath.lineTo(x, y);
        }
        mLastX = x;
        mLastY = y;
        break;
      case MotionEvent.ACTION_UP:
        new Thread(mRunnable).start();
        break;
      default:
        break;
    }
    invalidate();
    return true;
  }
Example #7
0
  Bitmap getSmile() {

    float x1, y1, x3, y3;
    x1 = 200;
    y1 = 300;
    x3 = 250;
    y3 = 300;

    Paint paint =
        new Paint() {
          {
            setStyle(Paint.Style.STROKE);
            setStrokeCap(Paint.Cap.ROUND);
            setStrokeWidth(3.0f);
            setAntiAlias(true);
          }
        };
    final Path path = new Path();
    path.moveTo(x1, 290);

    final float x2 = (x3 + x1) / 2;
    final float y2 = (y3 + y1) / 2;
    path.cubicTo(x1, y1, x2, y2, x3, y3);
    Bitmap bg = Bitmap.createBitmap(480, 800, Bitmap.Config.ARGB_8888);
    Canvas canvas_smile = new Canvas(bg);
    canvas_smile.drawPath(path, paint);
    return bg;
  }
  protected void draw(Canvas canvas) {
    canvas.save();
    Path path = new Path();
    outlinePaint.setStrokeWidth(outlineWidth);
    if (!hasFocus()) {
      outlinePaint.setColor(Color.BLACK);
      canvas.drawRect(drawRect, outlinePaint);
    } else {
      Rect viewDrawingRect = new Rect();
      viewContext.getDrawingRect(viewDrawingRect);

      path.addRect(new RectF(drawRect), Path.Direction.CW);
      outlinePaint.setColor(highlightColor);

      if (isClipPathSupported(canvas)) {
        canvas.clipPath(path, Region.Op.DIFFERENCE);
        canvas.drawRect(viewDrawingRect, outsidePaint);
      } else {
        drawOutsideFallback(canvas);
      }

      canvas.restore();
      canvas.drawPath(path, outlinePaint);

      if (showThirds) {
        drawThirds(canvas);
      }

      if (handleMode == HandleMode.Always
          || (handleMode == HandleMode.Changing && modifyMode == ModifyMode.Grow)) {
        drawHandles(canvas);
      }
    }
  }
Example #9
0
 private Path getArcPath() {
   Path path = new Path();
   path.addArc(rectF, startAngle, 90);
   path.addArc(rectF, startAngle + 90 + 30, 90);
   path.addArc(rectF, startAngle + 90 + 90 + 30 + 30, 90);
   return path;
 }
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);

    centerX = w / 2;
    centerY = h / 2;

    // Make reference line long enough to cross the bounds diagonally after being rotated.
    referenceLine.reset();
    float radius = (float) Math.hypot(centerX, centerY);
    float delta = radius - centerX;
    referenceLine.moveTo(-delta, centerY);
    referenceLine.lineTo(getWidth() + delta, centerY);
    delta = radius - centerY;
    referenceLine.moveTo(centerX, -delta);
    referenceLine.lineTo(centerX, getHeight() + delta);

    // Set grids inside photo display bounds.
    grids.reset();
    delta = displayBounds.width() / 4.0f;
    for (float x = displayBounds.left + delta; x < displayBounds.right; x += delta) {
      grids.moveTo(x, displayBounds.top);
      grids.lineTo(x, displayBounds.bottom);
    }
    delta = displayBounds.height() / 4.0f;
    for (float y = displayBounds.top + delta; y < displayBounds.bottom; y += delta) {
      grids.moveTo(displayBounds.left, y);
      grids.lineTo(displayBounds.right, y);
    }
  }
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    Path temp = new Path();
    float rx = event.getX();
    float ry = event.getY();
    mNodes =
        mGraph.getShortestPath(
            fromSpin.getSelectedItem().toString(), toSpin.getSelectedItem().toString());
    // temp.rMoveTo(rx, ry);

    float x, y;
    String res = " ";
    for (int i = 0; i < mNodes.size(); i++) {
      x = (float) mNodes.get(i).getX();
      y = (float) mNodes.get(i).getY();
      res += mNodes.get(i).getLabel() + " ";
      if (i != 0) {
        temp.lineTo(x, y);
      }

      temp.moveTo(x, y);
    }
    Log.d("Path", res);
    myMap.setMap(temp, 2, rx, ry);
    return true;
  }
Example #12
0
    public void onDraw(Canvas canvas) {
      // 검정색 배경으로 지운다. 빈 화면이면 지우기만 하고 리턴
      canvas.drawColor(Color.BLACK);
      if (status == BLANK) {
        return;
      }

      // 도형 목록을 순회하면서 도형 정보대로 출력한다.
      int idx;
      for (idx = 0; idx < arShape.size(); idx++) {
        Paint Pnt = new Paint();
        Pnt.setAntiAlias(true);
        Pnt.setColor(arShape.get(idx).color);

        Rect rt = arShape.get(idx).rt;
        switch (arShape.get(idx).what) {
          case Shape.RECT:
            canvas.drawRect(rt, Pnt);
            break;
          case Shape.CIRCLE:
            canvas.drawCircle(
                rt.left + rt.width() / 2, rt.top + rt.height() / 2, rt.width() / 2, Pnt);
            break;
          case Shape.TRIANGLE:
            Path path = new Path();
            path.moveTo(rt.left + rt.width() / 2, rt.top);
            path.lineTo(rt.left, rt.bottom);
            path.lineTo(rt.right, rt.bottom);
            canvas.drawPath(path, Pnt);
            break;
        }
      }
    }
Example #13
0
 public boolean onTouch(View view, MotionEvent event) {
   float x = event.getX();
   float y = event.getY();
   switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
       path.moveTo(x, y);
       return true;
     case MotionEvent.ACTION_UP:
     case MotionEvent.ACTION_MOVE:
       l = x;
       r = x;
       t = y;
       b = y;
       for (int i = 0; i < event.getHistorySize(); i++) {
         float newX = event.getHistoricalX(i);
         float newY = event.getHistoricalY(i);
         path.lineTo(newX, newY);
         l = newX < l ? newX : l;
         t = newY < t ? newY : t;
         r = newX > r ? newX : r;
         b = newY > b ? newY : b;
       }
       rect.set(l, t, r, b);
       Log.d("TAG", rect.toShortString());
       invalidate(
           (int) rect.left - 5, (int) rect.top - 5, (int) rect.right + 5, (int) rect.bottom + 5);
       break;
     default:
   }
   return super.onTouchEvent(event);
 }
Example #14
0
  /**
   * 绘制图网络线
   *
   * @param canvas 画布
   * @param lineData 数据集类
   * @param arrayDataX x坐标
   * @param arrayDataY y坐标
   */
  private void drawDataPath(
      Canvas canvas, RadarData lineData, Float[] arrayDataX, Float[] arrayDataY) {
    float startX = 0.0f, startY = 0.0f;
    float initX = 0.0f, initY = 0.0f;

    Path pathArea = new Path();

    for (int p = 0; p < arrayDataX.length; p++) {
      if (0 == p) {
        initX = startX = arrayDataX[p];
        initY = startY = arrayDataY[p];

        pathArea.moveTo(initX, initY);
      } else {
        pathArea.lineTo(arrayDataX[p], arrayDataY[p]);
        startX = arrayDataX[p];
        startY = arrayDataY[p];
      }
      // 绘制点及对应的标签
      renderDotAndLabel(canvas, lineData, arrayDataX[p], arrayDataY[p], p);
    }
    // 收尾
    pathArea.lineTo(initX, initY);
    pathArea.close();

    lineData.getPlotLine().getLinePaint().setAlpha(mAreaAlpha);
    // lineData.getPlotLine().getLinePaint().setStyle(Style.STROKE);
    canvas.drawPath(pathArea, lineData.getPlotLine().getLinePaint());
  }
Example #15
0
 public void touch_start(float x, float y) {
   mPath.reset();
   mPath.moveTo(x, y);
   mX = x;
   mY = y;
   invalidate();
 }
Example #16
0
 /** 绘制焦点框 */
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   if (Style.RECTANGLE == mStyle) {
     mFocusPath.addRect(mFocusRect, Path.Direction.CCW);
     canvas.save();
     canvas.clipRect(0, 0, getWidth(), getHeight());
     canvas.clipPath(mFocusPath, Region.Op.DIFFERENCE);
     canvas.drawColor(mMaskColor);
     canvas.restore();
   } else if (Style.CIRCLE == mStyle) {
     float radius =
         Math.min(
             (mFocusRect.right - mFocusRect.left) / 2, (mFocusRect.bottom - mFocusRect.top) / 2);
     mFocusPath.addCircle(mFocusMidPoint.x, mFocusMidPoint.y, radius, Path.Direction.CCW);
     canvas.save();
     canvas.clipRect(0, 0, getWidth(), getHeight());
     canvas.clipPath(mFocusPath, Region.Op.DIFFERENCE);
     canvas.drawColor(mMaskColor);
     canvas.restore();
   }
   mBorderPaint.setColor(mBorderColor);
   mBorderPaint.setStyle(Paint.Style.STROKE);
   mBorderPaint.setStrokeWidth(mBorderWidth);
   mBorderPaint.setAntiAlias(true);
   canvas.drawPath(mFocusPath, mBorderPaint);
   mFocusPath.reset();
 }
Example #17
0
  private void drawPointerArrow(Canvas canvas) {

    int centerX = getWidth() / 2;
    int centerY = getHeight() / 2;

    double tipAngle = (colorHSV[2] - 0.5f) * Math.PI;
    double leftAngle = tipAngle + Math.PI / 96;
    double rightAngle = tipAngle - Math.PI / 96;

    double tipAngleX = Math.cos(tipAngle) * outerWheelRadius;
    double tipAngleY = Math.sin(tipAngle) * outerWheelRadius;
    double leftAngleX = Math.cos(leftAngle) * (outerWheelRadius + arrowPointerSize);
    double leftAngleY = Math.sin(leftAngle) * (outerWheelRadius + arrowPointerSize);
    double rightAngleX = Math.cos(rightAngle) * (outerWheelRadius + arrowPointerSize);
    double rightAngleY = Math.sin(rightAngle) * (outerWheelRadius + arrowPointerSize);

    arrowPointerPath.reset();
    arrowPointerPath.moveTo((float) tipAngleX + centerX, (float) tipAngleY + centerY);
    arrowPointerPath.lineTo((float) leftAngleX + centerX, (float) leftAngleY + centerY);
    arrowPointerPath.lineTo((float) rightAngleX + centerX, (float) rightAngleY + centerY);
    arrowPointerPath.lineTo((float) tipAngleX + centerX, (float) tipAngleY + centerY);

    valuePointerArrowPaint.setColor(Color.HSVToColor(colorHSV));
    valuePointerArrowPaint.setStyle(Style.FILL);
    canvas.drawPath(arrowPointerPath, valuePointerArrowPaint);

    valuePointerArrowPaint.setStyle(Style.STROKE);
    valuePointerArrowPaint.setStrokeJoin(Join.ROUND);
    valuePointerArrowPaint.setColor(Color.BLACK);
    canvas.drawPath(arrowPointerPath, valuePointerArrowPaint);
  }
Example #18
0
  @Override
  public void draw(Canvas canvas, MapView mapView, boolean shadow) {

    super.draw(canvas, mapView, shadow);

    if (shadow) {
      return;
    }

    Projection projection = mapView.getProjection();
    Path path = new Path();
    boolean isFirst = true;

    for (int i = 0; i < pointsSize; i++) {
      GeoPoint gPoint = points.get(i);
      Point pixelPoint = pixelPoints[i];

      projection.toPixels(gPoint, pixelPoint);

      if (isFirst) {
        path.moveTo(pixelPoint.x, pixelPoint.y);
        isFirst = false;
      } else {
        path.lineTo(pixelPoint.x, pixelPoint.y);
      }
    }

    canvas.drawPath(path, mPaint);
  }
Example #19
0
 private void touchUp() {
   mPath.lineTo(mX, mY);
   // commit the path to our offscreen
   mCanvas.drawPath(mPath, mPaint);
   // kill this so we don't double draw
   mPath.reset();
 }
Example #20
0
 MyPath(float x, float y, int size, int color) {
   super(color);
   path = new Path();
   this.size = size;
   path.moveTo(x, y);
   path.lineTo(x, y);
 }
  @Override
  public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    if (!this.visible) return;

    // long start = System.currentTimeMillis();

    Projection projection = mapView.getProjection();
    Path p = new Path();
    Paint polygonPaint = new Paint();
    polygonPaint.setStrokeWidth(this.style.width);
    polygonPaint.setColor(this.style.color);
    polygonPaint.setStyle(Paint.Style.STROKE);
    polygonPaint.setAntiAlias(true);

    for (int i = 0; i < path.size(); i++) {
      if (i == path.size() - 1) {
        break;
      }
      Point from = new Point();
      Point to = new Point();
      projection.toPixels(path.get(i), from);
      projection.toPixels(path.get(i + 1), to);
      if (i == 0) {
        p.moveTo(from.x, from.y);
      }
      p.lineTo(to.x, to.y);
    }

    canvas.drawPath(p, polygonPaint);

    // Log.d("Tracker", "Path drawing complete in " + String.valueOf(System.currentTimeMillis() -
    // start) + "ms");
  }
 /*
  * Drawing
  */
 @Override
 public void draw(Canvas canvas) {
   final boolean positionChanged = adapterPositionChanged();
   if (rippleOverlay) {
     if (!positionChanged) {
       rippleBackground.draw(canvas);
     }
     super.draw(canvas);
     if (!positionChanged) {
       if (rippleRoundedCorners != 0) {
         Path clipPath = new Path();
         RectF rect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
         clipPath.addRoundRect(
             rect, rippleRoundedCorners, rippleRoundedCorners, Path.Direction.CW);
         canvas.clipPath(clipPath);
       }
       canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint);
     }
   } else {
     if (!positionChanged) {
       rippleBackground.draw(canvas);
       canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint);
     }
     super.draw(canvas);
   }
 }
Example #23
0
  @Override
  protected void dispatchDraw(Canvas canvas) {
    if (mShowcaseX < 0 || mShowcaseY < 0 || mIsRedundant) {
      super.dispatchDraw(canvas);
      return;
    }

    boolean recalculatedCling = mShowcaseDrawer.calculateShowcaseRect(mShowcaseX, mShowcaseY);
    boolean recalculateText = recalculatedCling || mAlteredText;
    mAlteredText = false;

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB && !mHasNoTarget) {
      Path path = new Path();
      path.addCircle(mShowcaseX, mShowcaseY, mShowcaseRadius, Path.Direction.CW);
      canvas.clipPath(path, Op.DIFFERENCE);
    }

    // Draw background color
    canvas.drawColor(mBackgroundColor);

    // Draw the showcase drawable
    if (!mHasNoTarget) {
      mShowcaseDrawer.drawShowcase(
          canvas, mShowcaseX, mShowcaseY, mScaleMultiplier, mShowcaseRadius);
    }

    // Draw the text on the screen, recalculating its position if necessary
    if (recalculateText) {
      mTextDrawer.calculateTextPosition(canvas.getWidth(), canvas.getHeight(), this);
    }
    mTextDrawer.draw(canvas, recalculateText);

    super.dispatchDraw(canvas);
  }
Example #24
0
 @Override
 public Path computePath(int radius, int l, int t, int r, int b) {
   final Point o = computeOrigin(l, t, r, b);
   final Path path = new Path();
   path.addCircle(o.x, o.y, radius, Path.Direction.CW);
   return path;
 }
  // ==============================================================================
  public final int[] renderGlyph(
      char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) {
    Path p = new Path();
    paint.getTextPath(String.valueOf(glyph), 0, 1, 0.0f, 0.0f, p);

    RectF boundsF = new RectF();
    p.computeBounds(boundsF, true);
    matrix.mapRect(boundsF);

    boundsF.roundOut(bounds);
    bounds.left--;
    bounds.right++;

    final int w = bounds.width();
    final int h = bounds.height();

    Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(bm);
    matrix.postTranslate(-bounds.left, -bounds.top);
    c.setMatrix(matrix);
    c.drawPath(p, paint);

    final int sizeNeeded = w * h;
    if (cachedRenderArray.length < sizeNeeded) cachedRenderArray = new int[sizeNeeded];

    bm.getPixels(cachedRenderArray, 0, w, 0, 0, w, h);
    bm.recycle();
    return cachedRenderArray;
  }
Example #26
0
 private static Path createLightPath(int width, int height) {
   final Path path = new Path();
   path.moveTo(0, height);
   path.lineTo(0, 0);
   path.lineTo(width, 0);
   return path;
 }
Example #27
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);
 }
Example #28
0
 public void paintBitmap(Context context, Canvas c, Rect dest) {
   int color0 = Color.argb(0xFF, 196, 181, 51);
   int color1 = Color.argb(0xFF, 251, 219, 39);
   int color2 = Color.argb(0xFF, 255, 239, 151);
   int border = Color.argb(0xFF, 220, 200, 80);
   Paint p = new Paint();
   p.setAntiAlias(true);
   float width = dest.width() / 20.0f;
   float insideSize = dest.width() - 2 * width;
   RectF inside1 =
       new RectF(
           dest.left + width - 1,
           dest.top + width - 1,
           dest.right - width + 1,
           dest.bottom - width + 1);
   RectF inside =
       new RectF(dest.left + width, dest.top + width, dest.right - width, dest.bottom - width);
   LinearGradient linear =
       new LinearGradient(
           inside1.left,
           inside1.top + insideSize / 3,
           inside1.right,
           inside1.top + 2 * insideSize / 3,
           new int[] {color0, color1, color2},
           null,
           Shader.TileMode.CLAMP);
   p.setShader(linear);
   c.drawRoundRect(inside1, width, width, p);
   p.setShader(null);
   p.setColor(border);
   Path path = new Path();
   path.addRoundRect(inside, width, width, Path.Direction.CCW);
   path.addRect(new RectF(dest), Path.Direction.CW);
   c.drawPath(path, p);
 }
Example #29
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    float touchX = event.getX();
    float touchY = event.getY();

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        drawPath.moveTo(touchX, touchY);
        break;
      case MotionEvent.ACTION_MOVE:
        drawPath.lineTo(touchX, touchY);
        break;
      case MotionEvent.ACTION_UP:
        drawCanvas.drawPath(drawPath, drawPaint);
        drawPath.reset();
        break;
      default:
        return false;
    }

    // send the X & Y coordinates over bluetooth.
    sendPointToBluetooth(touchX, touchY);

    postInvalidate(); // Indicate view should be redrawn
    return true; // Indicate we've consumed the touch
    // detect user touch
  }
Example #30
0
  public void onDraw(Canvas canvas, int measuredWidth, int measuredHeight) {
    if (!visual || text == null) {
      return;
    }

    float actualDistance = distance + height / 2;
    calcOffset(actualDistance, measuredWidth, measuredHeight);

    rectPaint.setColor(backgroundColor);
    if (alpha != 0) {
      rectPaint.setAlpha(alpha);
    }
    rectPaint.setStrokeWidth(height);

    rectPath.reset();
    rectPath.moveTo(startPosX, startPosY);
    rectPath.lineTo(endPosX, endPosY);
    canvas.drawPath(rectPath, rectPaint);

    textPaint.setTextSize(textSize);
    textPaint.setColor(textColor);
    textPaint.getTextBounds(text, 0, text.length(), textBound);

    canvas.drawTextOnPath(
        text,
        rectPath,
        (1.4142135f * actualDistance) / 2 - textBound.width() / 2,
        textBound.height() / 2,
        textPaint);
  }