private void drawFlippingHalf(Canvas canvas) {
    canvas.save();
    mCamera.save();

    final float degreesFlipped = getDegreesFlipped();

    if (degreesFlipped > 90) {
      canvas.clipRect(isFlippingVertically() ? mTopRect : mLeftRect);
      if (mIsFlippingVertically) {
        mCamera.rotateX(degreesFlipped - 180);
      } else {
        mCamera.rotateY(180 - degreesFlipped);
      }
    } else {
      canvas.clipRect(isFlippingVertically() ? mBottomRect : mRightRect);
      if (mIsFlippingVertically) {
        mCamera.rotateX(degreesFlipped);
      } else {
        mCamera.rotateY(-degreesFlipped);
      }
    }

    mCamera.getMatrix(mMatrix);

    positionMatrix();
    canvas.concat(mMatrix);

    setDrawWithLayer(mCurrentPage.v, true);
    drawChild(canvas, mCurrentPage.v, 0);

    drawFlippingShadeShine(canvas);

    mCamera.restore();
    canvas.restore();
  }
 @Override
 public void drawTo(Canvas drawCanvas, float left, float top, Paint paint, boolean onlyDirty) {
   final Rect src = new Rect(0, 0, mTileSize, mTileSize);
   final Rect dst = new Rect(0, 0, mTileSize, mTileSize);
   drawCanvas.save();
   drawCanvas.translate(-left, -top);
   drawCanvas.clipRect(0, 0, mWidth, mHeight);
   for (int j = 0; j < mTilesY; j++) {
     for (int i = 0; i < mTilesX; i++) {
       dst.offsetTo(i * mTileSize, j * mTileSize);
       final int p = j * mTilesX + i;
       final Tile tile = mTiles[p];
       if (!onlyDirty || tile.dirty) {
         drawCanvas.drawBitmap(tile.getBitmap(), src, dst, paint);
         tile.dirty = false;
         if (mDebug) {
           mDrawCount++;
           dbgPaint.setColor(DEBUG_COLORS[tile.top % DEBUG_COLORS.length]);
           // drawCanvas.drawRect(dst, (mDrawCount % 2 == 0) ? dbgPaint1 : dbgPaint2);
           drawCanvas.drawRect(dst, dbgPaint);
           // drawCanvas.drawRect(dst, dbgStroke);
           drawCanvas.drawText(
               String.format("%d,%d v%d", tile.x, tile.y, tile.top),
               dst.left + 4,
               dst.bottom - 4,
               dbgTextPaint);
         }
       }
     }
   }
   drawCanvas.restore();
 }
Exemplo n.º 3
0
 public void draw(Canvas canvas) {
   int i = 1;
   copyBounds(mTmpRect);
   canvas.save();
   float f;
   float f1;
   float f2;
   boolean flag;
   int j;
   if (ViewCompat.getLayoutDirection(mActivity.getWindow().getDecorView()) == 1) {
     flag = true;
   } else {
     flag = false;
   }
   if (flag) {
     i = -1;
   }
   j = mTmpRect.width();
   f = -mOffset;
   f1 = j;
   f2 = mPosition;
   canvas.translate((float) i * (f * f1 * f2), 0.0F);
   if (flag && !mHasMirroring) {
     canvas.translate(j, 0.0F);
     canvas.scale(-1F, 1.0F);
   }
   super.draw(canvas);
   canvas.restore();
 }
 private void pushTransform(Attributes atts) {
   final String transform = getStringAttr("transform", atts);
   canvas.save();
   if (transform != null) {
     final Matrix matrix = parseTransform(transform);
     canvas.concat(matrix);
   }
 }
Exemplo n.º 5
0
 @Override
 public Surface drawLine(float x0, float y0, float x1, float y1, float width) {
   canvas.save();
   canvas.setStrokeWidth(width);
   canvas.drawLine(x0, y0, x1, y1);
   canvas.restore();
   return this;
 }
Exemplo n.º 6
0
  @Override
  protected void dispatchDraw(Canvas canvas) {
    if (showcaseX < 0 || showcaseY < 0 || isRedundant) {
      super.dispatchDraw(canvas);
      return;
    }

    // Draw the semi-transparent background
    canvas.drawColor(backColor);

    // Draw to the scale specified
    Matrix mm = new Matrix();
    mm.postScale(scaleMultiplier, scaleMultiplier, showcaseX, showcaseY);
    canvas.setMatrix(mm);

    // Erase the area for the ring
    canvas.drawCircle(showcaseX, showcaseY, showcaseRadius, mEraser);

    boolean recalculateText = makeVoidedRect() || mAlteredText;
    mAlteredText = false;

    showcase.setBounds(voidedArea);
    showcase.draw(canvas);

    canvas.setMatrix(new Matrix());

    if (!TextUtils.isEmpty(mTitleText) || !TextUtils.isEmpty(mSubText)) {
      if (recalculateText)
        mBestTextPosition = getBestTextPosition(canvas.getWidth(), canvas.getHeight());

      if (!TextUtils.isEmpty(mTitleText)) {
        // TODO: use a dynamic detail layout
        canvas.drawText(mTitleText, mBestTextPosition[0], mBestTextPosition[1], mPaintTitle);
      }

      if (!TextUtils.isEmpty(mSubText)) {
        canvas.save();
        if (recalculateText)
          mDynamicDetailLayout =
              new DynamicLayout(
                  mSubText,
                  mPaintDetail,
                  ((Number) mBestTextPosition[2]).intValue(),
                  Layout.Alignment.ALIGN_NORMAL,
                  1.2f,
                  1.0f,
                  true);
        canvas.translate(mBestTextPosition[0], mBestTextPosition[1] + 12 * metricScale);
        mDynamicDetailLayout.draw(canvas);
        canvas.restore();
      }
    }

    super.dispatchDraw(canvas);
  }
Exemplo n.º 7
0
 /**
  * ************************************************************** put text in figure coordinates
  * (0,0) is bottom left side. **************************************************************
  */
 private void textFigure(String txt, float x, float y, float deg, Canvas canvas) {
   mPlotPaint.setStrokeWidth(0);
   if (deg != 0) {
     canvas.save();
     canvas.rotate(deg, x, y);
   }
   canvas.drawText(txt, x, y, mPlotPaint);
   if (deg != 0) {
     canvas.restore();
   }
 }
  @Override
  public void draw(Canvas canvas) {
    final int saveCount = canvas.save();
    canvas.translate(0, mTotalDragDistance - mTop);

    drawSky(canvas);
    drawSun(canvas);
    drawTown(canvas);

    canvas.restoreToCount(saveCount);
  }
Exemplo n.º 9
0
  public void draw(Canvas canvas) throws PlotRenderException {
    if (isVisible()) {
      if (backgroundPaint != null) {
        drawBackground(canvas, widgetDimensions.canvasRect);
      }
      canvas.save();
      final RectF paddedRect = applyRotation(canvas, widgetDimensions.paddedRect);
      doOnDraw(canvas, paddedRect);
      canvas.restore();

      if (borderPaint != null) {
        drawBorder(canvas, paddedRect);
      }
    }
  }
  /**
   * draw bottom/right half
   *
   * @param canvas
   */
  private void drawNextHalf(Canvas canvas) {
    canvas.save();
    canvas.clipRect(isFlippingVertically() ? mBottomRect : mRightRect);

    final float degreesFlipped = getDegreesFlipped();
    final Page p = degreesFlipped > 90 ? mCurrentPage : mNextPage;

    // if the view does not exist, skip drawing it
    if (p.valid) {
      setDrawWithLayer(p.v, true);
      drawChild(canvas, p.v, 0);
    }

    drawNextShadow(canvas);
    canvas.restore();
  }
Exemplo n.º 11
0
    @Override
    protected void onDraw(Canvas canvas) {

      mDrawable.setBounds(mRect);

      float r = 16;

      canvas.save();
      canvas.translate(10, 10);
      mDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
      setCornerRadii(mDrawable, r, r, 0, 0);
      mDrawable.draw(canvas);
      canvas.restore();

      canvas.save();
      canvas.translate(10 + mRect.width() + 10, 10);
      mDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
      setCornerRadii(mDrawable, 0, 0, r, r);
      mDrawable.draw(canvas);
      canvas.restore();

      canvas.translate(0, mRect.height() + 10);

      canvas.save();
      canvas.translate(10, 10);
      mDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
      setCornerRadii(mDrawable, 0, r, r, 0);
      mDrawable.draw(canvas);
      canvas.restore();

      canvas.save();
      canvas.translate(10 + mRect.width() + 10, 10);
      mDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
      setCornerRadii(mDrawable, r, 0, 0, r);
      mDrawable.draw(canvas);
      canvas.restore();

      canvas.translate(0, mRect.height() + 10);

      canvas.save();
      canvas.translate(10, 10);
      mDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
      setCornerRadii(mDrawable, r, 0, r, 0);
      mDrawable.draw(canvas);
      canvas.restore();

      canvas.save();
      canvas.translate(10 + mRect.width() + 10, 10);
      mDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
      setCornerRadii(mDrawable, 0, r, 0, r);
      mDrawable.draw(canvas);
      canvas.restore();
    }
Exemplo n.º 12
0
  @Override
  public void draw(Canvas canvas) {
    Rect r = getBounds();
    Paint paint = mShapeState.mPaint;

    int prevAlpha = paint.getAlpha();
    paint.setAlpha(modulateAlpha(prevAlpha, mShapeState.mAlpha));

    if (mShapeState.mShape != null) {
      // need the save both for the translate, and for the (unknown) Shape
      int count = canvas.save();
      canvas.translate(r.left, r.top);
      onDraw(mShapeState.mShape, canvas, paint);
      canvas.restoreToCount(count);
    } else {
      canvas.drawRect(r, paint);
    }

    // restore
    paint.setAlpha(prevAlpha);
  }
Exemplo n.º 13
0
  @Override
  public void onDraw(Canvas canvas) {
    if (layoutInfo == null) layoutInfo = layout();

    float width = containerView.getWidth();
    float margin = 10f;

    canvas.save();
    canvas.translate(width - layoutInfo.frame.width() - margin, margin);
    // draw background
    canvas.drawRect(layoutInfo.frame, backgroundPaint);
    canvas.drawRect(layoutInfo.frame, borderPaint);

    // draw markers
    float x = layoutInfo.getMarkerX();
    float lineLeft = layoutInfo.getMarkerLineLeft();
    float lineRight = layoutInfo.getMarkerLineRight();
    for (int i = 0; i < entryList.size(); i++) {
      Entry entry = entryList.get(i);
      float y = layoutInfo.margin + (layoutInfo.labelHeight + layoutInfo.labelSpacing) * (0.5f + i);
      canvas.drawLine(lineLeft, y, lineRight, y, entry.getPainter().getDrawConfig().getLinePaint());
      tempPoint.set(x, y);
      IPointRenderer pointRenderer = entry.painter.getPointRenderer();
      pointRenderer.drawPoint(canvas, tempPoint, entry.painter.getDrawConfig());
    }

    // draw labels
    x = layoutInfo.getLabelStartX();
    for (int i = 0; i < entryList.size(); i++) {
      Entry entry = entryList.get(i);
      float y =
          layoutInfo.margin
              + (layoutInfo.labelHeight + layoutInfo.labelSpacing) * i
              + layoutInfo.labelHeight;
      canvas.drawText(entry.getLabel(), x, y, labelPaint);
    }

    canvas.restore();
  }
Exemplo n.º 14
0
  @Override
  public void draw(Canvas canvas) {
    super.draw(canvas);
    Rect r = getBounds();

    // draw border
    if (borderThickness > 0) {
      drawBorder(canvas);
    }

    int count = canvas.save();
    canvas.translate(r.left, r.top);

    // draw text
    int width = this.width < 0 ? r.width() : this.width;
    int height = this.height < 0 ? r.height() : this.height;
    int fontSize = this.fontSize < 0 ? (Math.min(width, height) / 2) : this.fontSize;
    textPaint.setTextSize(fontSize);
    canvas.drawText(
        text, width / 2, height / 2 - ((textPaint.descent() + textPaint.ascent()) / 2), textPaint);

    canvas.restoreToCount(count);
  }
  @Override
  protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final boolean ret;

    final Integer row = (Integer) child.getTag(R.id.tag_row);
    final Integer column = (Integer) child.getTag(R.id.tag_column);
    // row == null => Shadow view
    if (row == null || (row == -1 && column == -1)) {
      ret = super.drawChild(canvas, child, drawingTime);
    } else {
      canvas.save();
      if (row == -1) {
        canvas.clipRect(widths[0], 0, canvas.getWidth(), canvas.getHeight());
      } else if (column == -1) {
        canvas.clipRect(0, heights[0], canvas.getWidth(), canvas.getHeight());
      } else {
        canvas.clipRect(widths[0], heights[0], canvas.getWidth(), canvas.getHeight());
      }

      ret = super.drawChild(canvas, child, drawingTime);
      canvas.restore();
    }
    return ret;
  }
Exemplo n.º 16
0
 @Override
 public Surface save() {
   canvas.save();
   return this;
 }
Exemplo n.º 17
0
  protected void draw(Canvas canvas) {

    if (mHidden) {
      return;
    }

    Path path = new Path();
    if (!hasFocus()) {
      mOutlinePaint.setColor(0xFF000000);
      canvas.drawRect(mDrawRect, mOutlinePaint);
    } else {
      Rect viewDrawingRect = new Rect();
      mContext.getDrawingRect(viewDrawingRect);
      if (mCircle) {

        canvas.save();

        float width = mDrawRect.width();
        float height = mDrawRect.height();
        path.addCircle(
            mDrawRect.left + (width / 2),
            mDrawRect.top + (height / 2),
            width / 2,
            Path.Direction.CW);
        mOutlinePaint.setColor(0xFFEF04D6);
        mOutlinePaint.setColor(0x0a83fe);

        canvas.clipPath(path, Region.Op.DIFFERENCE);
        canvas.drawRect(viewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint);

        canvas.restore();

      } else {

        Rect topRect =
            new Rect(
                viewDrawingRect.left, viewDrawingRect.top, viewDrawingRect.right, mDrawRect.top);
        if (topRect.width() > 0 && topRect.height() > 0) {
          canvas.drawRect(topRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
        }
        Rect bottomRect =
            new Rect(
                viewDrawingRect.left,
                mDrawRect.bottom,
                viewDrawingRect.right,
                viewDrawingRect.bottom);
        if (bottomRect.width() > 0 && bottomRect.height() > 0) {
          canvas.drawRect(bottomRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
        }
        Rect leftRect =
            new Rect(viewDrawingRect.left, topRect.bottom, mDrawRect.left, bottomRect.top);
        if (leftRect.width() > 0 && leftRect.height() > 0) {
          canvas.drawRect(leftRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
        }
        Rect rightRect =
            new Rect(mDrawRect.right, topRect.bottom, viewDrawingRect.right, bottomRect.top);
        if (rightRect.width() > 0 && rightRect.height() > 0) {
          canvas.drawRect(rightRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
        }

        path.addRect(new RectF(mDrawRect), Path.Direction.CW);

        mOutlinePaint.setColor(Color.parseColor("#0a83fe"));
      }

      canvas.drawPath(path, mOutlinePaint);

      if (mMode == ModifyMode.Grow) {
        if (mCircle) {
          int width = mResizeDrawableDiagonal.getIntrinsicWidth();
          int height = mResizeDrawableDiagonal.getIntrinsicHeight();

          int d = (int) Math.round(Math.cos(/* 45deg */ Math.PI / 4D) * (mDrawRect.width() / 2D));
          int x = mDrawRect.left + (mDrawRect.width() / 2) + d - width / 2;
          int y = mDrawRect.top + (mDrawRect.height() / 2) - d - height / 2;
          mResizeDrawableDiagonal.setBounds(
              x,
              y,
              x + mResizeDrawableDiagonal.getIntrinsicWidth(),
              y + mResizeDrawableDiagonal.getIntrinsicHeight());
          mResizeDrawableDiagonal.draw(canvas);
        } else {
          int left = mDrawRect.left + 1;
          int right = mDrawRect.right + 1;
          int top = mDrawRect.top + 4;
          int bottom = mDrawRect.bottom + 3;

          int widthWidth = mResizeDrawableWidth.getIntrinsicWidth() / 2;
          int widthHeight = mResizeDrawableWidth.getIntrinsicHeight() / 2;
          int heightHeight = mResizeDrawableHeight.getIntrinsicHeight() / 2;
          int heightWidth = mResizeDrawableHeight.getIntrinsicWidth() / 2;

          int xMiddle = mDrawRect.left + ((mDrawRect.right - mDrawRect.left) / 2);
          int yMiddle = mDrawRect.top + ((mDrawRect.bottom - mDrawRect.top) / 2);

          mResizeDrawableWidth.setBounds(
              left - widthWidth, yMiddle - widthHeight, left + widthWidth, yMiddle + widthHeight);
          mResizeDrawableWidth.draw(canvas);

          mResizeDrawableWidth.setBounds(
              right - widthWidth, yMiddle - widthHeight, right + widthWidth, yMiddle + widthHeight);
          mResizeDrawableWidth.draw(canvas);

          mResizeDrawableHeight.setBounds(
              xMiddle - heightWidth, top - heightHeight, xMiddle + heightWidth, top + heightHeight);
          mResizeDrawableHeight.draw(canvas);

          mResizeDrawableHeight.setBounds(
              xMiddle - heightWidth,
              bottom - heightHeight,
              xMiddle + heightWidth,
              bottom + heightHeight);
          mResizeDrawableHeight.draw(canvas);
        }
      }
    }
  }
  @Override
  protected void onDraw(Canvas canvas) {
    float ringWidth = textHeight + 4;
    int height = getMeasuredHeight();
    int width = getMeasuredWidth();

    int px = width / 2;
    int py = height / 2;
    Point center = new Point(px, py);

    int radius = Math.min(px, py) - 2;

    RectF boundingBox =
        new RectF(center.x - radius, center.y - radius, center.x + radius, center.y + radius);

    RectF innerBoundingBox =
        new RectF(
            center.x - radius + ringWidth,
            center.y - radius + ringWidth,
            center.x + radius - ringWidth,
            center.y + radius - ringWidth);

    float innerRadius = innerBoundingBox.height() / 2;
    RadialGradient borderGradient =
        new RadialGradient(
            px, py, radius, borderGradientColors, borderGradientPositions, TileMode.CLAMP);

    Paint pgb = new Paint();
    pgb.setShader(borderGradient);

    Path outerRingPath = new Path();
    outerRingPath.addOval(boundingBox, Direction.CW);

    canvas.drawPath(outerRingPath, pgb);
    LinearGradient skyShader =
        new LinearGradient(
            center.x,
            innerBoundingBox.top,
            center.x,
            innerBoundingBox.bottom,
            skyHorizonColorFrom,
            skyHorizonColorTo,
            TileMode.CLAMP);

    Paint skyPaint = new Paint();
    skyPaint.setShader(skyShader);

    LinearGradient groundShader =
        new LinearGradient(
            center.x,
            innerBoundingBox.top,
            center.x,
            innerBoundingBox.bottom,
            groundHorizonColorFrom,
            groundHorizonColorTo,
            TileMode.CLAMP);

    Paint groundPaint = new Paint();
    groundPaint.setShader(groundShader);
    float tiltDegree = pitch;
    while (tiltDegree > 90 || tiltDegree < -90) {
      if (tiltDegree > 90) tiltDegree = -90 + (tiltDegree - 90);
      if (tiltDegree < -90) tiltDegree = 90 - (tiltDegree + 90);
    }

    float rollDegree = roll;
    while (rollDegree > 180 || rollDegree < -180) {
      if (rollDegree > 180) rollDegree = -180 + (rollDegree - 180);
      if (rollDegree < -180) rollDegree = 180 - (rollDegree + 180);
    }
    Path skyPath = new Path();
    skyPath.addArc(innerBoundingBox, -rollDegree, (180 + (2 * rollDegree)));
    canvas.rotate(-tiltDegree, px, py);
    canvas.drawOval(innerBoundingBox, groundPaint);
    canvas.drawPath(skyPath, skyPaint);
    canvas.drawPath(skyPath, markerPaint);
    int markWidth = radius / 3;
    int startX = center.x - markWidth;
    int endX = center.x + markWidth;

    Log.d("PAARV ", "Roll " + String.valueOf(rollDegree));
    Log.d("PAARV ", "Pitch " + String.valueOf(tiltDegree));

    double h = innerRadius * Math.cos(Math.toRadians(90 - tiltDegree));
    double justTiltX = center.x - h;

    float pxPerDegree = (innerBoundingBox.height() / 2) / 45f;
    for (int i = 90; i >= -90; i -= 10) {
      double ypos = justTiltX + i * pxPerDegree;

      if ((ypos < (innerBoundingBox.top + textHeight))
          || (ypos > innerBoundingBox.bottom - textHeight)) continue;

      canvas.drawLine(startX, (float) ypos, endX, (float) ypos, markerPaint);
      int displayPos = (int) (tiltDegree - i);
      String displayString = String.valueOf(displayPos);
      float stringSizeWidth = textPaint.measureText(displayString);
      canvas.drawText(
          displayString, (int) (center.x - stringSizeWidth / 2), (int) (ypos) + 1, textPaint);
    }
    markerPaint.setStrokeWidth(2);
    canvas.drawLine(
        center.x - radius / 2,
        (float) justTiltX,
        center.x + radius / 2,
        (float) justTiltX,
        markerPaint);
    markerPaint.setStrokeWidth(1);

    Path rollArrow = new Path();
    rollArrow.moveTo(center.x - 3, (int) innerBoundingBox.top + 14);
    rollArrow.lineTo(center.x, (int) innerBoundingBox.top + 10);
    rollArrow.moveTo(center.x + 3, innerBoundingBox.top + 14);
    rollArrow.lineTo(center.x, innerBoundingBox.top + 10);
    canvas.drawPath(rollArrow, markerPaint);
    String rollText = String.valueOf(rollDegree);
    double rollTextWidth = textPaint.measureText(rollText);
    canvas.drawText(
        rollText,
        (float) (center.x - rollTextWidth / 2),
        innerBoundingBox.top + textHeight + 2,
        textPaint);
    canvas.restore();

    canvas.save();
    canvas.rotate(180, center.x, center.y);
    for (int i = -180; i < 180; i += 10) {
      if (i % 30 == 0) {
        String rollString = String.valueOf(i * -1);
        float rollStringWidth = textPaint.measureText(rollString);
        PointF rollStringCenter =
            new PointF(center.x - rollStringWidth / 2, innerBoundingBox.top + 1 + textHeight);
        canvas.drawText(rollString, rollStringCenter.x, rollStringCenter.y, textPaint);
      } else {
        canvas.drawLine(
            center.x,
            (int) innerBoundingBox.top,
            center.x,
            (int) innerBoundingBox.top + 5,
            markerPaint);
      }

      canvas.rotate(10, center.x, center.y);
    }
    canvas.restore();
    canvas.save();
    canvas.rotate(-1 * (bearing), px, py);

    double increment = 22.5;

    for (double i = 0; i < 360; i += increment) {
      CompassDirection cd = CompassDirection.values()[(int) (i / 22.5)];
      String headString = cd.toString();

      float headStringWidth = textPaint.measureText(headString);
      PointF headStringCenter =
          new PointF(center.x - headStringWidth / 2, boundingBox.top + 1 + textHeight);

      if (i % increment == 0)
        canvas.drawText(headString, headStringCenter.x, headStringCenter.y, textPaint);
      else
        canvas.drawLine(
            center.x, (int) boundingBox.top, center.x, (int) boundingBox.top + 3, markerPaint);

      canvas.rotate((int) increment, center.x, center.y);
    }
    canvas.restore();
    RadialGradient glassShader =
        new RadialGradient(
            px, py, (int) innerRadius, glassGradientColors, glassGradientPositions, TileMode.CLAMP);
    Paint glassPaint = new Paint();
    glassPaint.setShader(glassShader);

    canvas.drawOval(innerBoundingBox, glassPaint);
    canvas.drawOval(boundingBox, circlePaint);

    circlePaint.setStrokeWidth(2);
    canvas.drawOval(innerBoundingBox, circlePaint);

    canvas.restore();
  }
Exemplo n.º 19
0
  @Override
  protected void onDraw(Canvas canvas) {

    if (layout == null) {
      requestLayout();
      return;
    }

    if (description == null) {
      return;
    }

    if (needNewUpdateTyping) {
      updateTyping();
    }

    if (layout.isEncrypted) {
      bounds(secureIcon, layout.layoutEncryptedLeft, layout.layoutEncryptedTop);
      secureIcon.draw(canvas);
    }

    if (layout.titleLayout != null) {
      canvas.save();
      canvas.translate(layout.layoutTitleLeft, layout.layoutTitleLayoutTop);
      layout.titleLayout.draw(canvas);
      canvas.restore();
    } else if (layout.titleString != null) {
      TextPaint paint =
          layout.isEncrypted
              ? titleEncryptedPaint
              : (layout.isHighlighted ? titleHighlightPaint : titlePaint);
      canvas.drawText(layout.titleString, layout.layoutTitleLeft, layout.layoutTitleTop, paint);
    }

    if (state != MessageState.FAILURE && description.getSenderId() == currentUserUid) {
      switch (state) {
        default:
        case MessageState.PENDING:
          bound(statePending, layout.layoutClockLeft, layout.layoutClockTop);
          statePending.draw(canvas);
          break;
        case MessageState.SENT:
          bound(stateSent, layout.layoutStateLeft, layout.layoutStateTop);
          stateSent.draw(canvas);
          break;
        case MessageState.READED:
          bound(stateSent, layout.layoutStateLeftDouble, layout.layoutStateTop);
          stateSent.draw(canvas);
          bound(stateHalfCheck, layout.layoutStateLeft, layout.layoutStateTop);
          stateHalfCheck.draw(canvas);
          break;
      }
    }

    TextPaint timePaint =
        HIGHLIGHT_UNDEAD ? (layout.isUnreadIn ? unreadClockPaint : readClockPaint) : readClockPaint;
    canvas.drawText(layout.time, layout.layoutTimeLeft, layout.layoutTimeTop, timePaint);

    if (typingLayout != null) {
      canvas.save();
      canvas.translate(layout.layoutMainLeft, layout.layoutMainContentTop);
      typingLayout.draw(canvas);
      canvas.restore();
    } else if (layout.bodyLayout != null) {
      canvas.save();
      canvas.translate(layout.layoutMainLeft, layout.layoutMainContentTop);
      layout.bodyLayout.draw(canvas);
      canvas.restore();
    } else if (layout.bodyString != null) {
      //            canvas.save();
      //            canvas.translate(layout.layoutMainLeft, layout.layoutMainTop);
      //            layout.bodyLayout.draw(canvas);
      //            canvas.restore();
      canvas.drawText(layout.bodyString, layout.layoutMainLeft, layout.layoutMainTop, bodyPaint);
    }

    if (avatarHolder != null) {
      long time = SystemClock.uptimeMillis() - avatarAppearTime;
      if (time > AVATAR_FADE_TIME || !AVATAR_FADE) {
        avatarPaint.setAlpha(255);
        canvas.drawBitmap(
            avatarHolder.getBitmap(), layout.layoutAvatarLeft, layout.layoutAvatarTop, avatarPaint);
      } else {
        drawPlaceHolder(canvas);

        float alpha = time / (float) AVATAR_FADE_TIME;
        avatarPaint.setAlpha((int) (255 * alpha));
        canvas.drawBitmap(
            avatarHolder.getBitmap(), layout.layoutAvatarLeft, layout.layoutAvatarTop, avatarPaint);

        inavalidateForAnimation();
      }
    } else {
      drawPlaceHolder(canvas);
    }

    if (description.isErrorState()
        || (state == MessageState.FAILURE && description.getSenderId() == currentUserUid)) {
      bound(stateFailure, layout.layoutMarkLeft, layout.layoutMarkTop);
      stateFailure.draw(canvas);
    } else if (description.getUnreadCount() > 0) {
      canvas.drawRoundRect(
          layout.layoutMarkRect, layout.layoutMarkRadius, layout.layoutMarkRadius, counterPaint);
      canvas.drawText(
          layout.unreadCountText,
          layout.layoutMarkLeft + layout.layoutMarkTextLeft,
          layout.layoutMarkTextTop,
          counterTitlePaint);
    }
  }
Exemplo n.º 20
0
  private void stroke(Seria s, Canvas canvas) {
    mPlotPaint.setStyle(Paint.Style.STROKE);
    // draw line
    if (s.mWidth > 0) {
      // create the path
      mPath.reset();
      mPath.moveTo(calcX(s.x[0]), calcY(s.y[0]));
      for (int i = 1; i < s.sz(); i++) {
        mPath.lineTo(calcX(s.x[i]), calcY(s.y[i]));
      }
      // draw the path
      mPlotPaint.setColor(s.mColor);
      mPlotPaint.setStrokeWidth(s.mWidth);
      mPlotPaint.setPathEffect(s.mEffect);
      canvas.drawPath(mPath, mPlotPaint);
    }

    // draw images seria
    if (s.bms != null) {
      for (int i = 0; i < s.sz(); i++) {
        Bitmap bm;
        if (s.bms.length > 1) {
          bm = s.bms[i];
        } else {
          bm = s.bms[0];
        }
        float left = calcX(s.x[i]);
        float top = calcY(s.y[i]);
        if (s.hAlign == HALIGN.CENTER) {
          left -= bm.getWidth() / 2;
        } else if (s.hAlign == HALIGN.RIGHT) {
          left -= bm.getWidth();
        }
        if (s.vAlign == VALIGN.CENTER) {
          top -= bm.getHeight() / 2;
        } else if (s.vAlign == VALIGN.BOTTOM) {
          top -= bm.getHeight();
        }
        canvas.drawBitmap(s.bms[i], left, top, mPlotPaint);
      }
    }
    if (s.texts != null) {
      Align align = Align.CENTER;
      switch (s.hAlign) {
        case LEFT:
          align = Align.RIGHT;
        case RIGHT:
          align = Align.LEFT;
      }

      mPlotPaint.setTextAlign(align);
      mPlotPaint.setStrokeWidth(0);
      mPlotPaint.setColor(s.mColor);
      for (int i = 0; i < s.sz(); i++) {
        float x = calcX(s.x[i]);
        float y = calcY(s.y[i]);
        switch (s.vAlign) {
          case TOP:
            y -= mPlotPaint.getTextSize();
          case CENTER:
            y -= 0.5 * mPlotPaint.getTextSize();
        }
        if (s.deg != 0) {
          canvas.save();
          canvas.rotate(s.deg, x, y);
        }
        canvas.drawText(s.texts[i], x, y, mPlotPaint);
        if (s.deg != 0) {
          canvas.restore();
        }
      }
    }
  }
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   int radius = 0;
   int shadowColor = changeColorAlpha(mShadowColor, MIN_SHADOW_COLOR_ALPHA);
   long elapsed = System.currentTimeMillis() - mStartTime;
   switch (mState) {
     case StateNormal:
       shadowColor = changeColorAlpha(mShadowColor, MIN_SHADOW_COLOR_ALPHA);
       break;
     case StateTouchDown:
       ripplePaint.setAlpha(255);
       if (elapsed < ANIMATION_DURATION) {
         radius = Math.round(elapsed * getWidth() / 2 / ANIMATION_DURATION);
         float shadowAlpha =
             (MAX_SHADOW_COLOR_ALPHA - MIN_SHADOW_COLOR_ALPHA) * elapsed / ANIMATION_DURATION
                 + MIN_SHADOW_COLOR_ALPHA;
         shadowColor = changeColorAlpha(mShadowColor, shadowAlpha);
       } else {
         radius = getWidth() / 2;
         shadowColor = changeColorAlpha(mShadowColor, MAX_SHADOW_COLOR_ALPHA);
       }
       postInvalidate();
       break;
     case StateTouchUp:
       if (elapsed < ANIMATION_DURATION) {
         int alpha = Math.round((ANIMATION_DURATION - elapsed) * 255 / ANIMATION_DURATION);
         ripplePaint.setAlpha(alpha);
         radius = getWidth() / 2 + Math.round(elapsed * getWidth() / 2 / ANIMATION_DURATION);
         float shadowAlpha =
             (MAX_SHADOW_COLOR_ALPHA - MIN_SHADOW_COLOR_ALPHA)
                     * (ANIMATION_DURATION - elapsed)
                     / ANIMATION_DURATION
                 + MIN_SHADOW_COLOR_ALPHA;
         shadowColor = changeColorAlpha(mShadowColor, shadowAlpha);
       } else {
         mState = StateNormal;
         radius = 0;
         ripplePaint.setAlpha(0);
         shadowColor = changeColorAlpha(mShadowColor, MIN_SHADOW_COLOR_ALPHA);
       }
       postInvalidate();
       break;
   }
   backgroundPaint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, shadowColor);
   canvas.drawRoundRect(getRectF(), mCornerRadius, mCornerRadius, backgroundPaint);
   canvas.save();
   if (mState == StateTouchDown || mState == StateTouchUp) {
     if (rippleClipPath == null) {
       rippleClipPath = new Path();
       rippleClipPath.addRoundRect(getRectF(), mCornerRadius, mCornerRadius, Path.Direction.CW);
     }
     canvas.clipPath(rippleClipPath);
   }
   canvas.drawCircle(mTouchPoint.x, mTouchPoint.y, radius, ripplePaint);
   canvas.restore();
   if (mText != null && mText.length() > 0) {
     int y = (int) (getHeight() / 2 - ((textPaint.descent() + textPaint.ascent()) / 2));
     canvas.drawText(mText.toString(), getWidth() / 2, y, textPaint);
   }
 }
Exemplo n.º 22
0
  @Override
  protected boolean drawBubble(Canvas canvas) {
    if (messageLayout == null) {
      requestLayout();
      return false;
    }

    boolean isAnimated = false;

    if (messageLayout.isForwarded) {
      canvas.drawText("Forwarded message", 0, getPx(16), messageLayout.forwardingPaint);
      canvas.drawText("From", 0, getPx(35), messageLayout.forwardingPaint);
      canvas.drawText(
          messageLayout.forwarderNameMeasured,
          messageLayout.forwardOffset,
          getPx(35),
          messageLayout.senderPaint);
      canvas.save();
      canvas.translate(0, getPx(19) * 2);
      messageLayout.layout.draw(canvas);
      canvas.restore();
    } else {
      if (!messageLayout.isOut & messageLayout.isGroup) {
        canvas.drawText(messageLayout.senderNameMeasured, 0, getPx(16), messageLayout.senderPaint);
        canvas.save();
        canvas.translate(0, getPx(19));
        messageLayout.layout.draw(canvas);
        canvas.restore();
      } else {
        messageLayout.layout.draw(canvas);
      }
    }

    if (messageLayout.showState) {
      if (state == MessageState.PENDING) {
        canvas.save();
        canvas.translate(
            messageLayout.layoutRealWidth - getPx(12),
            messageLayout.layoutHeight - getPx(12) - getPx(3));
        canvas.drawCircle(getPx(6), getPx(6), getPx(6), clockIconPaint);
        double time = (System.currentTimeMillis() / 15.0) % (12 * 60);
        double angle = (time / (6 * 60)) * Math.PI;

        int x = (int) (Math.sin(-angle) * getPx(4));
        int y = (int) (Math.cos(-angle) * getPx(4));
        canvas.drawLine(getPx(6), getPx(6), getPx(6) + x, getPx(6) + y, clockIconPaint);

        x = (int) (Math.sin(-angle * 12) * getPx(5));
        y = (int) (Math.cos(-angle * 12) * getPx(5));
        canvas.drawLine(getPx(6), getPx(6), getPx(6) + x, getPx(6) + y, clockIconPaint);

        canvas.restore();

        clockOutPaint.setColor(COLOR_NORMAL);

        isAnimated = true;
      } else if (state == MessageState.READED
          && prevState == MessageState.SENT
          && (SystemClock.uptimeMillis() - stateChangeTime < STATE_ANIMATION_TIME)) {
        long animationTime = SystemClock.uptimeMillis() - stateChangeTime;
        float progress = easeStateFade(animationTime / (float) STATE_ANIMATION_TIME);
        int offset = (int) (getPx(5) * progress);
        int alphaNew = (int) (progress * 255);

        bounds(
            stateSent,
            messageLayout.layoutRealWidth - stateSent.getIntrinsicWidth() - offset,
            messageLayout.layoutHeight - stateSent.getIntrinsicHeight() - getPx(3));
        stateSent.setAlpha(255);
        stateSent.draw(canvas);

        bounds(
            stateHalfCheck,
            messageLayout.layoutRealWidth - stateHalfCheck.getIntrinsicWidth() + getPx(5) - offset,
            messageLayout.layoutHeight - stateHalfCheck.getIntrinsicHeight() - getPx(3));
        stateHalfCheck.setAlpha(alphaNew);
        stateHalfCheck.draw(canvas);

        clockOutPaint.setColor(COLOR_NORMAL);

        isAnimated = true;
      } else {
        Drawable stateDrawable = getStateDrawable(state);

        bounds(
            stateDrawable,
            messageLayout.layoutRealWidth - stateDrawable.getIntrinsicWidth(),
            messageLayout.layoutHeight - stateDrawable.getIntrinsicHeight() - getPx(3));
        stateDrawable.setAlpha(255);
        stateDrawable.draw(canvas);

        if (state == MessageState.READED) {
          bounds(
              stateSent,
              messageLayout.layoutRealWidth - stateSent.getIntrinsicWidth() - getPx(5),
              messageLayout.layoutHeight - stateDrawable.getIntrinsicHeight() - getPx(3));
          stateSent.setAlpha(255);
          stateSent.draw(canvas);
        }

        if (state == MessageState.FAILURE) {
          clockOutPaint.setColor(COLOR_ERROR);
        } else {
          clockOutPaint.setColor(COLOR_NORMAL);
        }
      }
    } else {
      clockOutPaint.setColor(COLOR_IN);
    }
    canvas.drawText(
        wireframe.date,
        messageLayout.layoutRealWidth - messageLayout.timeWidth + getPx(6),
        messageLayout.layoutHeight - getPx(4),
        clockOutPaint);
    return isAnimated;
  }