예제 #1
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);
  }
예제 #2
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();
   }
 }
예제 #3
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();
    }
  @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;
  }
  @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();
  }
예제 #6
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();
        }
      }
    }
  }