コード例 #1
0
  private void computeGlyphPath() {
    drawableArea.set(getBounds());
    drawableArea.inset(padding, padding);
    glyphPaint.getTextPath(glyph, 0, 1, 0, 0, glyphPath);
    // Add an extra path point to fix the icon remaining blank on a Galaxy Note 2 running 4.1.2.
    glyphPath.computeBounds(glyphPathBounds, false);
    final float centerX = glyphPathBounds.centerX();
    final float centerY = glyphPathBounds.centerY();
    glyphPath.moveTo(centerX, centerY);
    glyphPath.lineTo(centerX + 0.001f, centerY + 0.001f);
    final float areaWidthF = (float) drawableArea.width();
    final float areaHeightF = (float) drawableArea.height();
    final float scaleX = areaWidthF / glyphPathBounds.width();
    final float scaleY = areaHeightF / glyphPathBounds.height();
    final float scaleFactor = Math.min(scaleX, scaleY);
    glyphPathTransform.setScale(scaleFactor, scaleFactor);
    glyphPath.transform(glyphPathTransform);

    // TODO this two pass calculation irks me.
    // It has to be possible to push this into a single Matrix transform; what makes it hard is
    // that the origin of Text is not top-left, but baseline-left so need to account for that.
    glyphPath.computeBounds(glyphPathBounds, false);
    final float areaLeftF = (float) drawableArea.left;
    final float areaTopF = (float) drawableArea.top;
    float transX = areaLeftF - glyphPathBounds.left;
    transX += 0.5f * Math.abs(areaWidthF - glyphPathBounds.width());
    float transY = areaTopF - glyphPathBounds.top;
    transY += 0.5f * Math.abs(areaHeightF - glyphPathBounds.height());
    glyphPath.offset(transX, transY);

    invalidateSelf();
  }
コード例 #2
0
 public synchronized void addPath(Path aPath, float aStrokeWidth) {
   if (fBounds == null) {
     fBounds = new RectF();
     aPath.computeBounds(fBounds, true);
   } else {
     aPath.computeBounds(fBoundsTemp, true);
     fBounds.union(fBoundsTemp);
   }
   fPaths.add(new Pair<Path, Float>(aPath, aStrokeWidth));
 }
コード例 #3
0
  // ==============================================================================
  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;
  }
コード例 #4
0
 @Override
 public Bitmap getDetailTexture(int n) {
   Bitmap bitmap =
       Bitmap.createBitmap(DETAIL_TEXTURE_WIDTH, DETAIL_TEXTURE_HEIGHT, Bitmap.Config.ARGB_8888);
   Canvas canvas = new Canvas(bitmap);
   canvas.drawARGB(32, 10, 10, 10);
   mPaint.setTextSize(15.0f);
   mPaint.setAntiAlias(true);
   OpenPath mPath = mPathItems[n];
   if (mPath == null)
     canvas.drawText("Detail text for card " + n, 0, DETAIL_TEXTURE_HEIGHT / 2, mPaint);
   else {
     Path p = new Path();
     RectF bounds = new RectF();
     String s = mPath.getName();
     int y = (int) mPaint.getTextSize() + 2;
     while (s != "") {
       mPaint.getTextPath(s, 0, s.length(), 0, 0, p);
       p.computeBounds(bounds, true);
       float lines = Math.max(1, bounds.right / DETAIL_TEXTURE_WIDTH);
       int chars = (int) (s.length() / lines);
       canvas.drawText(s, 0, chars, 0, y, mPaint);
       if (chars >= s.length()) break;
       y += bounds.height() + 2;
       s = s.substring(chars).trim();
     }
   }
   return bitmap;
 }
コード例 #5
0
  /**
   * fill a path with the paint, and record the dirty area.
   *
   * @param state the current graphics state
   * @param g the graphics into which to draw
   * @param s the path to fill
   */
  public RectF fill(final PDFRenderer state, final Canvas g, final Path s) {
    g.drawPath(s, mainPaint);

    final RectF bounds = new RectF();
    final RectF result = new RectF();
    s.computeBounds(bounds, false);
    g.getMatrix().mapRect(result, bounds);
    return bounds;
  }
コード例 #6
0
ファイル: TileView.java プロジェクト: peterLaurence/TileView
 /**
  * Register a HotSpot that should fire a listener when a touch event occurs that intersects the
  * Region defined by the HotSpot.
  *
  * <p>The HotSpot virtually moves and scales with the TileView.
  *
  * @param positions (List<double[]>) List of paired doubles that represents the region.
  * @return HotSpot the hotspot created with this method.
  */
 public HotSpot addHotSpot(List<double[]> positions, HotSpot.HotSpotTapListener listener) {
   Path path = mCoordinateTranslater.pathFromPositions(positions, true);
   RectF bounds = new RectF();
   path.computeBounds(bounds, true);
   Rect rect = new Rect();
   bounds.round(rect);
   Region clip = new Region(rect);
   HotSpot hotSpot = new HotSpot();
   hotSpot.setPath(path, clip);
   hotSpot.setHotSpotTapListener(listener);
   return addHotSpot(hotSpot);
 }
コード例 #7
0
 public void a(Path path) {
   d = path;
   path = new RectF();
   d.computeBounds(path, true);
   e = new Region();
   e.setPath(
       d,
       new Region(
           (int) ((RectF) (path)).left,
           (int) ((RectF) (path)).top,
           (int) ((RectF) (path)).right,
           (int) ((RectF) (path)).bottom));
 }
コード例 #8
0
  @Override
  public void draw(Canvas canvas) {
    String file = getEnvObject().getCurrentRepresentation().getIcon();
    Path objectPath =
        DrawingUtils.freedomPolygonToPath(
            (FreedomPolygon) getEnvObject().getCurrentRepresentation().getShape());
    RectF box = new RectF();
    objectPath.computeBounds(box, true);
    System.out.print("GPT box: box widht:" + box.width() + " box heigh" + box.height());
    drawingMatrix = new Matrix();
    float rotation = (float) getEnvObject().getCurrentRepresentation().getRotation();
    drawingMatrix.postRotate(rotation);
    drawingMatrix.postTranslate(
        getEnvObject().getCurrentRepresentation().getOffset().getX(),
        getEnvObject().getCurrentRepresentation().getOffset().getY());
    Bitmap bmp = null;
    if (file != null) { // TODO: Asign the bmp in the setEnvObject
      bmp = BitmapUtils.getImage(file, (int) box.width(), (int) box.height());
    }
    if (bmp != null) {
      ghostBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.ARGB_8888);
      canvas.drawBitmap(bmp, drawingMatrix, null);

    } else {
      // TODO: Cache path
      Paint paint = new Paint();
      paint.setStyle(Style.FILL);

      ghostPath = new Path();
      objectPath.transform(drawingMatrix, ghostPath);
      int fillColor = -1;
      try {
        fillColor = Color.parseColor(getEnvObject().getCurrentRepresentation().getFillColor());
        paint.setColor(fillColor);
        canvas.drawPath(ghostPath, paint);
      } catch (IllegalArgumentException ex) {
        System.out.println("ParseColor exception in fill");
      }
      int borderColor = -1;
      try {
        borderColor = Color.parseColor(getEnvObject().getCurrentRepresentation().getBorderColor());
        paint.setColor(borderColor);
        paint.setStyle(Style.STROKE);
        canvas.drawPath(ghostPath, paint);
      } catch (IllegalArgumentException ex) {
        System.out.println("ParseColor exception in border");
      }
    }
  }
コード例 #9
0
    public final void a(SelectionShapeType selectionshapetype)
    {
        d.reset();
        final class _cls1
        {

            static final int a[];

            static 
            {
                a = new int[SelectionShapeType.values().length];
                try
                {
                    a[SelectionShapeType.RECTANGLE.ordinal()] = 1;
                }
                catch (NoSuchFieldError nosuchfielderror1) { }
                try
                {
                    a[SelectionShapeType.CIRCLE.ordinal()] = 2;
                }
                catch (NoSuchFieldError nosuchfielderror)
                {
                    return;
                }
            }
        }

        _cls1.a[selectionshapetype.ordinal()];
        JVM INSTR tableswitch 1 2: default 36
    //                   1 59
    //                   2 78;
           goto _L1 _L2 _L3
_L1:
        d.computeBounds(q, true);
        e = null;
        s = selectionshapetype;
        return;
_L2:
        d.addRect(0.0F, 0.0F, 50F, 50F, android.graphics.Path.Direction.CW);
        continue; /* Loop/switch isn't completed */
_L3:
        d.addCircle(50F, 50F, 50F, android.graphics.Path.Direction.CW);
        if (true) goto _L1; else goto _L4
コード例 #10
0
 private void doLimits(Path path) {
   path.computeBounds(rect, false);
   doLimits(rect.left, rect.top);
   doLimits(rect.right, rect.bottom);
 }
  /**
   * Erase any existing {@link Path} and generate series outline based on currently bound {@link
   * NetworkStatsHistory} data.
   */
  private void generatePath() {
    if (LOGD) Log.d(TAG, "generatePath()");

    mMax = 0;
    mPathStroke.reset();
    mPathFill.reset();
    mPathEstimate.reset();
    mPathValid = true;

    // bail when not enough stats to render
    if (mStats == null || mStats.size() < 2) {
      return;
    }

    final int width = getWidth();
    final int height = getHeight();

    boolean started = false;
    float lastX = 0;
    float lastY = height;
    long lastTime = mHoriz.convertToValue(lastX);

    // move into starting position
    mPathStroke.moveTo(lastX, lastY);
    mPathFill.moveTo(lastX, lastY);

    // TODO: count fractional data from first bucket crossing start;
    // currently it only accepts first full bucket.

    long totalData = 0;

    NetworkStatsHistory.Entry entry = null;

    final int start = mStats.getIndexBefore(mStart);
    final int end = mStats.getIndexAfter(mEnd);
    for (int i = start; i <= end; i++) {
      entry = mStats.getValues(i, entry);

      final long startTime = entry.bucketStart;
      final long endTime = startTime + entry.bucketDuration;

      final float startX = mHoriz.convertToPoint(startTime);
      final float endX = mHoriz.convertToPoint(endTime);

      // skip until we find first stats on screen
      if (endX < 0) continue;

      // increment by current bucket total
      totalData += entry.rxBytes + entry.txBytes;

      final float startY = lastY;
      final float endY = mVert.convertToPoint(totalData);

      if (lastTime != startTime) {
        // gap in buckets; line to start of current bucket
        mPathStroke.lineTo(startX, startY);
        mPathFill.lineTo(startX, startY);
      }

      // always draw to end of current bucket
      mPathStroke.lineTo(endX, endY);
      mPathFill.lineTo(endX, endY);

      lastX = endX;
      lastY = endY;
      lastTime = endTime;
    }

    // when data falls short, extend to requested end time
    if (lastTime < mEndTime) {
      lastX = mHoriz.convertToPoint(mEndTime);

      mPathStroke.lineTo(lastX, lastY);
      mPathFill.lineTo(lastX, lastY);
    }

    if (LOGD) {
      final RectF bounds = new RectF();
      mPathFill.computeBounds(bounds, true);
      Log.d(
          TAG,
          "onLayout() rendered with bounds=" + bounds.toString() + " and totalData=" + totalData);
    }

    // drop to bottom of graph from current location
    mPathFill.lineTo(lastX, height);
    mPathFill.lineTo(0, height);

    mMax = totalData;

    // build estimated data
    mPathEstimate.moveTo(lastX, lastY);

    final long now = System.currentTimeMillis();
    final long bucketDuration = mStats.getBucketDuration();

    // long window is average over two weeks
    entry = mStats.getValues(lastTime - WEEK_IN_MILLIS * 2, lastTime, now, entry);
    final long longWindow = (entry.rxBytes + entry.txBytes) * bucketDuration / entry.bucketDuration;

    long futureTime = 0;
    while (lastX < width) {
      futureTime += bucketDuration;

      // short window is day average last week
      final long lastWeekTime = lastTime - WEEK_IN_MILLIS + (futureTime % WEEK_IN_MILLIS);
      entry = mStats.getValues(lastWeekTime - DAY_IN_MILLIS, lastWeekTime, now, entry);
      final long shortWindow =
          (entry.rxBytes + entry.txBytes) * bucketDuration / entry.bucketDuration;

      totalData += (longWindow * 7 + shortWindow * 3) / 10;

      lastX = mHoriz.convertToPoint(lastTime + futureTime);
      lastY = mVert.convertToPoint(totalData);

      mPathEstimate.lineTo(lastX, lastY);
    }

    mMaxEstimate = totalData;

    invalidate();
  }