private void drawTriangle(Canvas c, float startAngle, float sweepAngle, Rect bounds) {
      if (mShowArrow) {
        if (mArrow == null) {
          mArrow = new Path();
          mArrow.setFillType(Path.FillType.EVEN_ODD);
        } else {
          mArrow.reset();
        }

        // Adjust the position of the triangle so that it is inset as
        // much as the arc, but also centered on the arc.
        float inset = (int) mStrokeInset / 2 * mArrowScale;
        float x = (float) (mRingCenterRadius * Math.cos(0) + bounds.exactCenterX());
        float y = (float) (mRingCenterRadius * Math.sin(0) + bounds.exactCenterY());

        // Update the path each time. This works around an issue in SKIA
        // where concatenating a rotation matrix to a scale matrix
        // ignored a starting negative rotation. This appears to have
        // been fixed as of API 21.
        mArrow.moveTo(0, 0);
        mArrow.lineTo(mArrowWidth * mArrowScale, 0);
        mArrow.lineTo((mArrowWidth * mArrowScale / 2), (mArrowHeight * mArrowScale));
        mArrow.offset(x - inset, y);
        mArrow.close();
        // draw a triangle
        mArrowPaint.setColor(mColors[mColorIndex]);
        c.rotate(
            startAngle + sweepAngle - ARROW_OFFSET_ANGLE,
            bounds.exactCenterX(),
            bounds.exactCenterY());
        c.drawPath(mArrow, mArrowPaint);
      }
    }
  @Override
  protected boolean onStateChange(int[] state) {
    boolean pressed = ViewUtil.hasState(state, android.R.attr.state_pressed);

    if (mPressed != pressed) {
      mPressed = pressed;

      if (mPressed) {
        Rect bounds = getBounds();

        if (mState == STATE_OUT || mState == STATE_RELEASE) {
          if (mRippleType == TYPE_WAVE || mRippleType == TYPE_TOUCH_MATCH_VIEW)
            mMaxRippleRadius = getMaxRippleRadius(bounds.exactCenterX(), bounds.exactCenterY());

          setRippleEffect(bounds.exactCenterX(), bounds.exactCenterY(), 0);
          setRippleState(STATE_PRESS);
        } else if (mRippleType == TYPE_TOUCH)
          setRippleEffect(bounds.exactCenterX(), bounds.exactCenterY(), mRippleRadius);
      } else {
        if (mState != STATE_OUT) {
          if (mState == STATE_HOVER) {
            if (mRippleType == TYPE_WAVE || mRippleType == TYPE_TOUCH_MATCH_VIEW)
              setRippleEffect(mRipplePoint.x, mRipplePoint.y, 0);

            setRippleState(STATE_RELEASE);
          } else setRippleState(STATE_RELEASE_ON_HOLD);
        }
      }

      return true;
    }

    return false;
  }
 @Override
 protected void onBoundsChange(Rect bounds) {
   mBoxRect.set(
       bounds.exactCenterX() - mBoxSize / 2,
       bounds.exactCenterY() - mBoxSize / 2,
       bounds.exactCenterX() + mBoxSize / 2,
       bounds.exactCenterY() + mBoxSize / 2);
 }
 public final void draw(Canvas paramCanvas) {
   Rect localRect = getBounds();
   int i = paramCanvas.save();
   paramCanvas.rotate(this.mRotation, localRect.exactCenterX(), localRect.exactCenterY());
   Ring localRing = this.mRing;
   RectF localRectF = localRing.mTempBounds;
   localRectF.set(localRect);
   localRectF.inset(localRing.mStrokeInset, localRing.mStrokeInset);
   float f1 = 360.0F * (localRing.mStartTrim + localRing.mRotation);
   float f2 = 360.0F * (localRing.mEndTrim + localRing.mRotation) - f1;
   localRing.mPaint.setColor(localRing.mCurrentColor);
   paramCanvas.drawArc(localRectF, f1, f2, false, localRing.mPaint);
   if (localRing.mShowArrow) {
     if (localRing.mArrow != null) {
       break label427;
     }
     localRing.mArrow = new Path();
     localRing.mArrow.setFillType(Path.FillType.EVEN_ODD);
   }
   for (; ; ) {
     float f3 = (int) localRing.mStrokeInset / 2 * localRing.mArrowScale;
     float f4 = (float) (localRing.mRingCenterRadius * Math.cos(0.0D) + localRect.exactCenterX());
     float f5 = (float) (localRing.mRingCenterRadius * Math.sin(0.0D) + localRect.exactCenterY());
     localRing.mArrow.moveTo(0.0F, 0.0F);
     localRing.mArrow.lineTo(localRing.mArrowWidth * localRing.mArrowScale, 0.0F);
     localRing.mArrow.lineTo(
         localRing.mArrowWidth * localRing.mArrowScale / 2.0F,
         localRing.mArrowHeight * localRing.mArrowScale);
     localRing.mArrow.offset(f4 - f3, f5);
     localRing.mArrow.close();
     localRing.mArrowPaint.setColor(localRing.mCurrentColor);
     paramCanvas.rotate(f1 + f2 - 5.0F, localRect.exactCenterX(), localRect.exactCenterY());
     paramCanvas.drawPath(localRing.mArrow, localRing.mArrowPaint);
     if (localRing.mAlpha < 255) {
       localRing.mCirclePaint.setColor(localRing.mBackgroundColor);
       localRing.mCirclePaint.setAlpha(255 - localRing.mAlpha);
       paramCanvas.drawCircle(
           localRect.exactCenterX(),
           localRect.exactCenterY(),
           localRect.width() / 2,
           localRing.mCirclePaint);
     }
     paramCanvas.restoreToCount(i);
     return;
     label427:
     localRing.mArrow.reset();
   }
 }
  private void updatePath() {
    float radius = getWidth() / 20;
    float arrowHeight = getHeight() / 4;

    Rect rect = new Rect(2, 2, this.getWidth() - 4, this.getHeight() - 4);

    mPath = new Path();
    mPath.moveTo(rect.left + radius, rect.top);
    mPath.lineTo(rect.right, rect.top);
    mPath.lineTo(rect.right, rect.bottom - arrowHeight);
    mPath.lineTo(rect.exactCenterX(), rect.bottom);
    mPath.lineTo(rect.left, rect.bottom - arrowHeight);
    mPath.lineTo(rect.left, rect.top);
    mPath.close();

    int color = this.getContext().getResources().getColor(R.color.tag_unselected_outline);
    if (mIsActive) color = this.getContext().getResources().getColor(R.color.tag_selected_outline);

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setColor(color);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setStrokeWidth(0);
    mPaint.setStrokeJoin(Paint.Join.ROUND); // set the join to round you
    // want
    mPaint.setStrokeCap(Paint.Cap.ROUND); // set the paint cap to round too
    mPaint.setPathEffect(new CornerPathEffect(radius)); // set the path
    // effect when they

    color = this.getContext().getResources().getColor(R.color.tag_unselected);
    if (mIsActive) color = this.getContext().getResources().getColor(R.color.tag_selected);
    mShader = new LinearGradient(0, 0, 0, getHeight(), color, color, Shader.TileMode.CLAMP);
  }
 @Override
 public void draw(Canvas canvas) {
   canvas.save();
   canvas.rotate(rotation, drawableArea.exactCenterX(), drawableArea.exactCenterY());
   canvas.drawPath(glyphPath, glyphPaint);
   canvas.restore();
 }
  /**
   * Shrink the {@code shrinkTarget} rectangle to snugly fit inside of {@code reference}; the aspect
   * ratio of {@code shrinkTarget} will change to be the same aspect ratio as {@code reference}.
   *
   * <p>At most a single dimension will scale (down). Both dimensions will never be scaled.
   *
   * @param reference the rectangle whose aspect ratio will be used as the new aspect ratio
   * @param shrinkTarget the rectangle which will be scaled down to have a new aspect ratio
   * @return a new rectangle, a subset of {@code shrinkTarget}, whose aspect ratio will match that
   *     of {@code reference}
   */
  private static Rect shrinkToSameAspectRatioCentered(Rect reference, Rect shrinkTarget) {
    float aspectRatioReference = reference.width() * 1.0f / reference.height();
    float aspectRatioShrinkTarget = shrinkTarget.width() * 1.0f / shrinkTarget.height();

    float cropH, cropW;
    if (aspectRatioShrinkTarget < aspectRatioReference) {
      // The new width must be smaller than the height, so scale the width by AR
      cropH = reference.height();
      cropW = cropH * aspectRatioShrinkTarget;
    } else {
      // The new height must be smaller (or equal) than the width, so scale the height by AR
      cropW = reference.width();
      cropH = cropW / aspectRatioShrinkTarget;
    }

    Matrix translateMatrix = new Matrix();
    RectF shrunkRect = new RectF(shrinkTarget);

    // Scale the rectangle down, but keep its center in the same place as before
    translateMatrix.setScale(
        cropW / reference.width(),
        cropH / reference.height(),
        shrinkTarget.exactCenterX(),
        shrinkTarget.exactCenterY());

    translateMatrix.mapRect(/*inout*/ shrunkRect);

    return ParamsUtils.createRect(shrunkRect);
  }
  private void init() {
    if (mPaint == null) {
      mPaint = new Paint();
      mPaint.setColor(Color.WHITE);
      mPaint.setAntiAlias(true);
      mPaint.setStyle(Paint.Style.FILL);
    }

    int count = (mPoints - 1) * 4;
    posX = new float[count];
    posY = new float[count];

    Rect bounds = new Rect();
    bounds.set(getBounds());
    bounds.inset(mPadding, mPadding);

    // circumference
    float circ = (float) (Math.PI * (float) Math.min(bounds.width(), bounds.height()));
    float arcLength = circ / count;

    mSize = (float) ((arcLength) / (2 * Math.PI));

    double degrees = Math.toRadians((float) 360 / (float) count);
    for (int i = 0; i < count; i++) {
      posX[i] = (float) (bounds.exactCenterX() - (bounds.width() / 2) * Math.sin(degrees * i));
      posY[i] = (float) (bounds.exactCenterY() + (bounds.height() / 2) * Math.cos(degrees * i));
    }
  }
 public void draw(Canvas paramCanvas)
 {
   Rect localRect = getBounds();
   int i = paramCanvas.save();
   paramCanvas.rotate(mRotation, localRect.exactCenterX(), localRect.exactCenterY());
   mRing.draw(paramCanvas, localRect);
   paramCanvas.restoreToCount(i);
 }
示例#10
0
 @Override
 public void draw(Canvas c) {
   final Rect bounds = getBounds();
   final int saveCount = c.save();
   c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
   mRing.draw(c, bounds);
   c.restoreToCount(saveCount);
 }
示例#11
0
 @Override
 protected void onPostDraw(Canvas canvas, Rect rect) {
   paintStroke.setColor(DARK_GRAY);
   final float size = recalc(rect, 23.783f);
   paintStroke.setStrokeWidth(8 * rect.width() / 1000f);
   canvas.drawLine(
       rect.exactCenterX() - size,
       rect.exactCenterY() - size,
       rect.exactCenterX() + size,
       rect.exactCenterY() + size,
       paintStroke);
   canvas.drawLine(
       rect.exactCenterX() - size,
       rect.exactCenterY() + size,
       rect.exactCenterX() + size,
       rect.exactCenterY() - size,
       paintStroke);
 }
 @Override
 protected void onDraw(Canvas canvas) {
   final int saveCount = canvas.save();
   Rect rect = mDrawable.getBounds();
   int l = getPaddingLeft() + (getMeasuredWidth() - mDrawable.getIntrinsicWidth()) / 2;
   canvas.translate(l, getPaddingTop());
   canvas.scale(mScale, mScale, rect.exactCenterX(), rect.exactCenterY());
   mDrawable.draw(canvas);
   canvas.restoreToCount(saveCount);
 }
示例#13
0
  @Override
  protected void onDraw(Canvas canvas) {
    try {
      int height = getHeight() / 10;
      Bitmap state =
          State == 7
              ? StateSplash4
              : State == 6
                  ? StateSplash3
                  : State == 5
                      ? StateSplash2
                      : State == 4
                          ? StateSplash1
                          : State == 3
                              ? StateLand
                              : State == 2 ? StateFly : State == 1 ? StateJump : StateSit;

      if (Position == null) {
        X = (int) GameStat.RoseStart.exactCenterX();
        Y = (int) GameStat.RoseStart.exactCenterY();

        Y -= height;
        X -= height / 2;

        Position = new Rect(X, Y, X + height, Y + height);
      }

      if (Charge > 0 && State == 0) {

        int si = Charge + 5;
        Drop.setStrokeWidth(Position.width() / 2);
        Drop.setPathEffect(
            new DashPathEffect(new float[] {Position.width() / 8, Position.width()}, 0));

        Path p = new Path();
        p.moveTo(Position.exactCenterX(), Position.exactCenterY());
        p.lineTo(MovePoint.x, MovePoint.y);

        canvas.drawPath(p, Drop);
      }
      Scorer.setTextSize(getHeight() / 8);
      Scorer.setFakeBoldText(true);
      // Scorer.setShadowLayer(10, 10, 10, Color.DKGRAY);

      canvas.drawText(
          String.valueOf(Score),
          FontHelper.drawTextX(String.valueOf(Score), Scorer, getWidth() / 2),
          0 + getHeight() / 8,
          Scorer);

      BitmapHelper.drawIn(canvas, Position, state);
    } catch (Exception e) {
    }
  }
示例#14
0
 @Override
 public void draw(Canvas canvas) {
   if (mBitmap != null) {
     Rect bounds = getBounds();
     float x = bounds.exactCenterX();
     float y = bounds.exactCenterY();
     float radius = bounds.height() / 2f;
     mPaint.setShader(mBitmapShader);
     canvas.drawCircle(x, y, radius, mPaint);
   }
 }
示例#15
0
 public static Bitmap getRoundBitmap(Bitmap bitmap) {
   int width = bitmap.getWidth();
   int height = bitmap.getHeight();
   Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
   Canvas canvas = new Canvas(output);
   final int color = 0xff424242;
   final Paint paint = new Paint();
   final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
   paint.setAntiAlias(true);
   canvas.drawARGB(0, 0, 0, 0);
   paint.setColor(color);
   if (width <= height) {
     canvas.drawCircle(rect.exactCenterX(), rect.exactCenterY(), (rect.width() / 2) - 3, paint);
   } else {
     canvas.drawCircle(rect.exactCenterX(), rect.exactCenterY(), (rect.height() / 2) - 3, paint);
   }
   paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
   canvas.drawBitmap(bitmap, rect, rect, paint);
   return output;
 }
示例#16
0
  @Override
  protected void onDraw(Canvas canvas) {
    if (userLocation == null || !userLocation.hasAccuracy() || displayState == null) {
      return;
    }
    // Figure out distance from user location to screen center point
    float[] mapLonLat = displayState.getScreenCenterGeoLocation();
    screenCenterLocation.setLatitude(mapLonLat[1]);
    screenCenterLocation.setLongitude(mapLonLat[0]);
    int distanceM = Math.round(userLocation.distanceTo(screenCenterLocation));
    int accuracyM = Math.round(userLocation.getAccuracy());

    // Don't draw if centered
    if (distanceM == 0) {
      return;
    }

    // Format the distance and accuracy nicely
    String distanceStr;
    if (PreferenceStore.instance(getContext()).isMetric()) {
      distanceStr = getMetricDistanceString(distanceM, accuracyM);
    } else {
      distanceStr = getEnglishDistanceString(distanceM, accuracyM);
    }

    // Compute the pixel size of the distanceStr
    // -- set font size based on canvas density (dpi)
    textPaint.setTextSize(ptsToPixels(textSizePt, canvas));
    Rect distanceBox = new Rect();
    textPaint.getTextBounds(distanceStr, 0, distanceStr.length(), distanceBox);
    distanceBox.offsetTo(0, 0);
    int padding = Math.round(ptsToPixels(paddingPt, canvas));
    distanceBox.right += 2 * padding;
    distanceBox.bottom += 2 * padding;
    distanceBox.offset((getWidth() - distanceBox.width()) / 2, getHeight() - distanceBox.height());
    float baseline = distanceBox.bottom - padding;
    backgroundPaint.setAlpha(192);
    backgroundPaint.setStyle(Paint.Style.FILL);
    textPaint.setStrokeWidth(1f);
    textPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    canvas.drawRoundRect(new RectF(distanceBox), padding, padding, backgroundPaint);
    canvas.drawText(distanceStr, distanceBox.exactCenterX(), baseline, textPaint);

    // Draw center circles
    int x = getWidth() / 2;
    int y = getHeight() / 2;
    backgroundPaint.setAlpha(255);
    backgroundPaint.setStyle(Paint.Style.STROKE);
    textPaint.setStrokeWidth(2f);
    textPaint.setStyle(Paint.Style.STROKE);
    canvas.drawCircle(x, y, 5, backgroundPaint);
    canvas.drawCircle(x, y, 5, textPaint);
  }
 @Override
 public void draw(Canvas c) {
   Rect bounds = getBounds();
   final int saveCount = c.save();
   c.translate(0, mTop);
   mCircle.draw(c);
   // c.scale((float)mWidth / bounds.width(), (float)mHeight /
   // bounds.height());
   c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
   mRing.draw(c, bounds);
   c.restoreToCount(saveCount);
 }
示例#18
0
  @Override
  protected void onDraw(Canvas canvas) {
    canvasNew = canvas;

    // one time function
    if (firstDrawBallRect) {
      canvasHeight = canvas.getHeight();
      canvasWidth = canvas.getWidth();
      // dim = canvasWidth/5;
      ballRectX = canvasWidth / 2 - dim / 2;
      ballRectY = canvasHeight - dim;
      ballRect =
          new Rect(
              canvasWidth / 2 - dim / 2,
              canvasHeight - dim,
              canvasWidth / 2 + dim / 2,
              canvasHeight);
      firstDrawBallRect = false;
    }

    // drawing the paths and connectors
    paint.setColor(pathPaint);
    rect =
        new Rect(
            canvasWidth / 2 - dim / 2 - 10,
            canvasHeight / 2,
            canvasWidth / 2 + dim / 2 + 10,
            canvasHeight);
    canvas.drawRect(rect, paint);

    conRect = new Rect(rect.left, rect.top - dim, rect.right, rect.top + dim);
    canvas.drawRect(conRect, paint);

    rect2 = new Rect(conRect.left, rect.top - rect.width(), canvasWidth - 200, rect.top);
    canvas.drawRect(rect2, paint);

    // drawing the goal
    paint.setColor(Color.CYAN);
    goal = new Rect(rect2.right - 110, rect2.top + 10, rect2.right - 10, rect2.bottom - 10);
    canvas.drawRect(goal, paint);

    // drawing the ball
    paint.setColor(ballPaint);
    canvas.drawRect(ballRect, paint);

    // drawing the text
    paint.setColor(textPaint);
    paint.setTextSize(40);
    canvas.drawText(
        "Ball at (" + ballRect.exactCenterX() + "," + ballRect.exactCenterY() + ")", 30, 50, paint);

    invalidate();
  }
  @Override
  public void draw(Canvas c) {
    if (mShadow != null) {
      mShadow.getPaint().setColor(mBackgroundColor);
      mShadow.draw(c);
    }

    final Rect bounds = getBounds();
    final int saveCount = c.save();
    c.rotate(mRotation, bounds.exactCenterX(), bounds.exactCenterY());
    mRing.draw(c, bounds);
    c.restoreToCount(saveCount);
  }
示例#20
0
    private void updateMatrix() {
      if (mBitmap == null) return;

      Rect bounds = getBounds();
      if (bounds.width() == 0 || bounds.height() == 0) return;

      mMatrix.reset();
      float scale = bounds.height() / (float) Math.min(mBitmap.getWidth(), mBitmap.getHeight());
      mMatrix.setScale(scale, scale, 0, 0);
      mMatrix.postTranslate(
          bounds.exactCenterX() - mBitmap.getWidth() * scale / 2,
          bounds.exactCenterY() - mBitmap.getHeight() * scale / 2);

      mBitmapShader.setLocalMatrix(mMatrix);
    }
示例#21
0
  private void applyZoomToCurrentRect(float animationProgress) {
    if (mSourceRect == null) return;
    if (mCurrentRect == null) mCurrentRect = new Rect();

    mCurrentRect.set(
        mSourceRect.left + (((int) (mCurrentZoom * mSourceRect.width()) / 2)),
        mSourceRect.top + (((int) (mCurrentZoom * mSourceRect.height()) / 2)),
        mSourceRect.right - (((int) (mCurrentZoom * mSourceRect.width()) / 2)),
        mSourceRect.bottom - (((int) (mCurrentZoom * mSourceRect.height()) / 2)));

    if (mFocalPoint != null)
      mCurrentRect.offset(
          ((int) ((mFocalPoint.x - mSourceRect.exactCenterX()) * animationProgress)),
          ((int) ((mFocalPoint.y - mSourceRect.exactCenterY()) * animationProgress)));

    fixCurrentRectBounds();
  }
示例#22
0
  /**
   * Emulates a tap event positioned at the center of the selected view. No-op if no view is
   * selected.
   */
  private void tapSelectedView() {
    if (mSelectedView == null) {
      return;
    }

    final float centerX = mSelectedRect.exactCenterX();
    final float centerY = mSelectedRect.exactCenterY();
    final long currTime = SystemClock.uptimeMillis();

    MotionEvent down =
        MotionEvent.obtain(currTime, currTime, MotionEvent.ACTION_DOWN, centerX, centerY, 0);
    MotionEvent up =
        MotionEvent.obtain(currTime, currTime, MotionEvent.ACTION_UP, centerX, centerY, 0);

    super.dispatchTouchEvent(down);
    super.dispatchTouchEvent(up);
  }
    /** Draw the progress spinner */
    public void draw(Canvas c, Rect bounds) {

      mCirclePaint.setColor(mBackgroundColor);
      mCirclePaint.setAlpha(mAlpha);

      c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2, mCirclePaint);

      final RectF arcBounds = mTempBounds;
      arcBounds.set(bounds);
      arcBounds.inset(mStrokeInset, mStrokeInset);
      final float startAngle = (mStartTrim + mRotation) * 360;
      final float endAngle = (mEndTrim + mRotation) * 360;
      float sweepAngle = endAngle - startAngle;
      mArcPaint.setColor(mColors[mColorIndex]);
      mArcPaint.setAlpha(mAlpha);
      c.drawArc(arcBounds, startAngle, sweepAngle, false, mArcPaint);
      drawTriangle(c, startAngle, sweepAngle, bounds);
    }
 private void drawLetter(Canvas canvas, float cx, float cy) {
   mLetterPaint.setColor(mLetterColor);
   mLetterPaint.setTextSize(spToPx(mLetterSize, context.getResources()));
   if (mInitials) {
     mLetterPaint.getTextBounds(
         mLetter,
         0,
         mInitialsNumber > mLetter.length() ? mLetter.length() : mInitialsNumber,
         textBounds);
   } else {
     mLetterPaint.getTextBounds(
         mLetter,
         0,
         mLettersNumber > mLetter.length() ? mLetter.length() : mLettersNumber,
         textBounds);
   }
   canvas.drawText(
       mLetter, cx - textBounds.exactCenterX(), cy - textBounds.exactCenterY(), mLetterPaint);
 }
  @Override
  public void draw(Canvas canvas) {
    final Rect r = new Rect(getBounds());
    if (canvas.getClipBounds(sTempRect) && !Rect.intersects(sTempRect, r)) {
      // The draw region has been clipped.
      return;
    }
    if (mIndicatorRectDirty) {
      initIndicatorRect();
    }
    final float iconScale;

    if ((mAnimationProgress >= ANIMATION_PROGRESS_STARTED)
        && (mAnimationProgress < ANIMATION_PROGRESS_COMPLETED)) {
      mPaint.setAlpha((int) ((1 - mAnimationProgress) * 255));
      mBgDrawable.setAlpha(mPaint.getAlpha());
      mBgDrawable.draw(canvas);
      canvas.drawOval(mIndicatorRect, mPaint);

      iconScale = ICON_SCALE_FACTOR + (1 - ICON_SCALE_FACTOR) * mAnimationProgress;
    } else if (mAnimationProgress == ANIMATION_PROGRESS_STOPPED) {
      mPaint.setAlpha(255);
      iconScale = ICON_SCALE_FACTOR;
      mBgDrawable.setAlpha(255);
      mBgDrawable.draw(canvas);

      if (mProgress >= 100) {
        canvas.drawOval(mIndicatorRect, mPaint);
      } else if (mProgress > 0) {
        canvas.drawArc(mIndicatorRect, -90, mProgress * 3.6f, false, mPaint);
      }
    } else {
      iconScale = 1;
    }

    canvas.save();
    canvas.scale(iconScale, iconScale, r.exactCenterX(), r.exactCenterY());
    mIcon.draw(canvas);
    canvas.restore();
  }
  /**
   * Get the available 'crop' (zoom) rectangles for this camera.
   *
   * <p>When zoom is supported, this will return a list of {@code 1 + #getMaxZoom} size, where each
   * crop rectangle corresponds to a zoom ratio (and is centered at the middle).
   *
   * <p>Each crop rectangle is changed to have the same aspect ratio as {@code streamSize}, by
   * shrinking the rectangle if necessary.
   *
   * <p>To get the reported crop region when applying a zoom to the sensor, use {@code streamSize} =
   * {@code activeArray size}.
   *
   * @param params non-{@code null} camera api1 parameters
   * @param activeArray active array dimensions, in sensor space
   * @param streamSize stream size dimensions, in pixels
   * @return a list of available zoom rectangles, sorted from least zoomed to most zoomed
   */
  private static List<Rect> getAvailableCropRectangles(
      Camera.Parameters params, Rect activeArray, Size streamSize) {
    checkNotNull(params, "params must not be null");
    checkNotNull(activeArray, "activeArray must not be null");
    checkNotNull(streamSize, "streamSize must not be null");

    // TODO: change all uses of Rect activeArray to Size activeArray,
    // since we want the crop to be active-array relative, not pixel-array relative

    Rect unzoomedStreamCrop = getPreviewCropRectangleUnzoomed(activeArray, streamSize);

    if (!params.isZoomSupported()) {
      // Trivial case: No zoom -> only support the full size as the crop region
      return new ArrayList<>(Arrays.asList(unzoomedStreamCrop));
    }

    List<Rect> zoomCropRectangles = new ArrayList<>(params.getMaxZoom() + 1);
    Matrix scaleMatrix = new Matrix();
    RectF scaledRect = new RectF();

    for (int zoom : params.getZoomRatios()) {
      float shrinkRatio = ZOOM_RATIO_MULTIPLIER * 1.0f / zoom; // normalize to 1.0 and smaller

      // set scaledRect to unzoomedStreamCrop
      ParamsUtils.convertRectF(unzoomedStreamCrop, /*out*/ scaledRect);

      scaleMatrix.setScale(
          shrinkRatio, shrinkRatio, activeArray.exactCenterX(), activeArray.exactCenterY());

      scaleMatrix.mapRect(scaledRect);

      Rect intRect = ParamsUtils.createRect(scaledRect);

      // Round the rect corners towards the nearest integer values
      zoomCropRectangles.add(intRect);
    }

    return zoomCropRectangles;
  }
  /**
   * Calculate the effective crop rectangle for this preview viewport; assumes the preview is
   * centered to the sensor and scaled to fit across one of the dimensions without skewing.
   *
   * <p>The preview size must be a subset of the active array size; the resulting rectangle will
   * also be a subset of the active array rectangle.
   *
   * <p>The unzoomed crop rectangle is calculated only.
   *
   * @param activeArray active array dimensions, in sensor space
   * @param previewSize size of the preview buffer render target, in pixels (not in sensor space)
   * @return a rectangle which serves as the preview stream's effective crop region (unzoomed), in
   *     sensor space
   * @throws NullPointerException if any of the args were {@code null}
   * @throws IllegalArgumentException if {@code previewSize} is wider or taller than {@code
   *     activeArray}
   */
  private static Rect getPreviewCropRectangleUnzoomed(Rect activeArray, Size previewSize) {
    if (previewSize.getWidth() > activeArray.width()) {
      throw new IllegalArgumentException("previewSize must not be wider than activeArray");
    } else if (previewSize.getHeight() > activeArray.height()) {
      throw new IllegalArgumentException("previewSize must not be taller than activeArray");
    }

    float aspectRatioArray = activeArray.width() * 1.0f / activeArray.height();
    float aspectRatioPreview = previewSize.getWidth() * 1.0f / previewSize.getHeight();

    float cropH, cropW;
    if (Math.abs(aspectRatioPreview - aspectRatioArray) < ASPECT_RATIO_TOLERANCE) {
      cropH = activeArray.height();
      cropW = activeArray.width();
    } else if (aspectRatioPreview < aspectRatioArray) {
      // The new width must be smaller than the height, so scale the width by AR
      cropH = activeArray.height();
      cropW = cropH * aspectRatioPreview;
    } else {
      // The new height must be smaller (or equal) than the width, so scale the height by AR
      cropW = activeArray.width();
      cropH = cropW / aspectRatioPreview;
    }

    Matrix translateMatrix = new Matrix();
    RectF cropRect = new RectF(/*left*/ 0, /*top*/ 0, cropW, cropH);

    // Now center the crop rectangle so its center is in the center of the active array
    translateMatrix.setTranslate(activeArray.exactCenterX(), activeArray.exactCenterY());
    translateMatrix.postTranslate(-cropRect.centerX(), -cropRect.centerY());

    translateMatrix.mapRect(/*inout*/ cropRect);

    // Round the rect corners towards the nearest integer values
    return ParamsUtils.createRect(cropRect);
  }
 @Override
 protected void onBoundsChange(Rect bounds) {
   mX = bounds.exactCenterX();
   mY = bounds.exactCenterY();
   mRadius = Math.min(bounds.width(), bounds.height()) / 2f;
 }
  private Intent createShortcutIntent(int position) {
    String url = getUrl(position);
    String title = getBookmarkTitle(position);
    Bitmap touchIcon = getTouchIcon(position);

    final Intent i = new Intent();
    final Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    long urlHash = url.hashCode();
    long uniqueId = (urlHash << 32) | shortcutIntent.hashCode();
    shortcutIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
    i.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    i.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    // Use the apple-touch-icon if available
    if (touchIcon != null) {
      // Make a copy so we can modify the pixels.  We can't use
      // createScaledBitmap or copy since they will preserve the config
      // and lose the ability to add alpha.
      Bitmap bm = Bitmap.createBitmap(mIconSize, mIconSize, Bitmap.Config.ARGB_8888);
      Canvas canvas = new Canvas(bm);
      Rect src = new Rect(0, 0, touchIcon.getWidth(), touchIcon.getHeight());
      Rect dest = new Rect(0, 0, bm.getWidth(), bm.getHeight());

      // Paint used for scaling the bitmap and drawing the rounded rect.
      Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
      paint.setFilterBitmap(true);
      canvas.drawBitmap(touchIcon, src, dest, paint);

      // Construct a path from a round rect. This will allow drawing with
      // an inverse fill so we can punch a hole using the round rect.
      Path path = new Path();
      path.setFillType(Path.FillType.INVERSE_WINDING);
      RectF rect = new RectF(0, 0, bm.getWidth(), bm.getHeight());
      rect.inset(1, 1);
      path.addRoundRect(rect, 8f, 8f, Path.Direction.CW);

      // Reuse the paint and clear the outside of the rectangle.
      paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
      canvas.drawPath(path, paint);

      i.putExtra(Intent.EXTRA_SHORTCUT_ICON, bm);
    } else {
      Bitmap favicon = getFavicon(position);
      if (favicon == null) {
        i.putExtra(
            Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(
                BrowserBookmarksPage.this, R.drawable.ic_launcher_shortcut_browser_bookmark));
      } else {
        Bitmap icon =
            BitmapFactory.decodeResource(
                getResources(), R.drawable.ic_launcher_shortcut_browser_bookmark_icon);

        // Make a copy of the regular icon so we can modify the pixels.
        Bitmap copy = icon.copy(Bitmap.Config.ARGB_8888, true);
        Canvas canvas = new Canvas(copy);

        // Make a Paint for the white background rectangle and for
        // filtering the favicon.
        Paint p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
        p.setStyle(Paint.Style.FILL_AND_STROKE);
        p.setColor(Color.WHITE);

        final float density = getResources().getDisplayMetrics().density;
        // Create a rectangle that is slightly wider than the favicon
        final float iconSize = 16 * density; // 16x16 favicon
        final float padding = 2 * density; // white padding around icon
        final float rectSize = iconSize + 2 * padding;

        final Rect iconBounds = new Rect(0, 0, icon.getWidth(), icon.getHeight());
        final float x = iconBounds.exactCenterX() - (rectSize / 2);
        // Note: Subtract 2 dip from the y position since the box is
        // slightly higher than center. Use padding since it is already
        // 2 * density.
        final float y = iconBounds.exactCenterY() - (rectSize / 2) - padding;
        RectF r = new RectF(x, y, x + rectSize, y + rectSize);

        // Draw a white rounded rectangle behind the favicon
        canvas.drawRoundRect(r, 2, 2, p);

        // Draw the favicon in the same rectangle as the rounded
        // rectangle but inset by the padding
        // (results in a 16x16 favicon).
        r.inset(padding, padding);
        canvas.drawBitmap(favicon, null, r, p);
        i.putExtra(Intent.EXTRA_SHORTCUT_ICON, copy);
      }
    }
    // Do not allow duplicate items
    i.putExtra("duplicate", false);
    return i;
  }
示例#30
0
  @Override
  protected void onDraw(Canvas canvas) {
    Bitmap sweet = BitmapFactory.decodeResource(getResources(), R.drawable.sq);
    canvas.drawColor(color.black);
    canvas.drawBitmap(sweet, 0, 0, null);

    Paint paint = new Paint();

    // draw a red circle
    paint.setColor(Color.RED);
    canvas.drawCircle(20, 50, 25, paint);

    // a blue circle with antialiasing turned on
    paint.setAntiAlias(true);
    paint.setColor(Color.BLUE);
    canvas.drawCircle(60, 50, 25, paint);

    // Now we wiil create some triangles.Create a Path object to store
    // out triangle's segments. Use.offset to draw in many locations.
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setStrokeWidth(2);
    paint.setColor(Color.GREEN);
    Path path = new Path();
    path.moveTo(4, -10);
    path.lineTo(20, 0);
    path.lineTo(-9, 0);
    path.close();
    path.offset(60, 40);
    canvas.drawPath(path, paint);
    path.offset(90, 100);
    canvas.drawPath(path, paint);
    path.offset(80, 150);
    canvas.drawPath(path, paint);

    // Now draw a text using FILL style:
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);
    paint.setTextSize(20);
    canvas.drawText("Hello Android! Fill...", 50, 230, paint);

    // rotate the text, and you can draw it where you want:
    int x = 75;
    int y = 185;
    paint.setColor(Color.GRAY);
    paint.setTextSize(25);
    String rotatedtext = "Rotated hellowandroid:)";

    // draw bounding rect befor rotating text:
    Rect rect = new Rect();
    paint.getTextBounds(rotatedtext, 0, rotatedtext.length(), rect);
    canvas.translate(x, y);
    paint.setStyle(Paint.Style.FILL);

    canvas.drawText("Rotated helloandroid :)", 0, 0, paint);
    paint.setStyle(Paint.Style.STROKE);
    canvas.drawRect(rect, paint);

    canvas.translate(-x, -y);

    paint.setColor(Color.RED);
    canvas.rotate(-45, x + rect.exactCenterX(), y + rect.exactCenterY());
    paint.setStyle(Paint.Style.FILL);
    canvas.drawText(rotatedtext, x, y, paint);

    // draw a draw a thick dashed line in angle
    DashPathEffect dashPath = new DashPathEffect(new float[] {10, 40}, 1);
    paint.setPathEffect(dashPath);
    paint.setStrokeWidth(8);
    canvas.drawLine(0, 60, 320, 300, paint);
  }