Exemplo n.º 1
3
Arquivo: n.java Projeto: KilFer/miband
 protected final void draw(Canvas paramCanvas, RectF paramRectF, float paramFloat) {
   paramCanvas.save();
   RectF localRectF = new RectF(paramRectF);
   paramRectF.right -= this.mPaddingRight;
   paramCanvas.clipRect(localRectF);
   Rect localRect = new Rect();
   while (true) {
     synchronized (StatisticChartOld.a(this.b)) {
       Iterator localIterator = StatisticChartOld.a(this.b).iterator();
       if (!localIterator.hasNext()) {
         paramCanvas.restore();
         return;
       }
       StatisticChartOld.DateItem localDateItem =
           (StatisticChartOld.DateItem) localIterator.next();
       if ((localDateItem.a > 1 + this.offset) || (localDateItem.a < -8 + this.offset)) continue;
       float f1 =
           paramRectF.right
               - this.mPaddingRight
               + (-1 + localDateItem.a) * StatisticChartOld.a()
               + this.mScroll;
       float f2 = paramRectF.top;
       if (f1 <= this.mRect.right - this.mPaddingRight - 2.0F * StatisticChartOld.a()) {
         this.a.setTextSize(8.0F * this.mDensity);
         this.a.getTextBounds(localDateItem.b, 0, localDateItem.b.length(), localRect);
         float f3 = f1 + (StatisticChartOld.a() - localRect.width()) / 2.0F;
         float f4 = f2 + (this.stroke + localRect.height()) / 2.0F;
         paramCanvas.drawText(localDateItem.b, f3, f4, this.a);
       }
     }
     this.a.setTextSize(10.0F * this.mDensity);
   }
 }
Exemplo n.º 2
0
  @Override
  public void draw(Canvas canvas) {
    super.draw(canvas);
    int totalW = getWidth();
    int totalH = getHeight();
    // rotate canvas first
    canvas.rotate(45, totalW / 2, totalH / 2);

    totalW /= 1.2;
    totalH /= 1.4;
    mMaxLeftRectWidth = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;

    RectF leftRect = new RectF();
    if (mLeftRectGrowMode) {
      leftRect.left = 0;
      leftRect.right = leftRect.left + mLeftRectWidth;
      leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2;
      leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT;
    } else {
      leftRect.right = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;
      leftRect.left = leftRect.right - mLeftRectWidth;
      leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2;
      leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT;
    }

    canvas.drawRoundRect(leftRect, CONST_RADIUS, CONST_RADIUS, mPaint);

    RectF rightRect = new RectF();
    rightRect.bottom = (totalH + CONST_RIGHT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;
    rightRect.left = (totalW + CONST_LEFT_RECT_W) / 2;
    rightRect.right = rightRect.left + CONST_RECT_WEIGHT;
    rightRect.top = rightRect.bottom - mRightRectWidth;
    canvas.drawRoundRect(rightRect, CONST_RADIUS, CONST_RADIUS, mPaint);
  }
Exemplo n.º 3
0
  /** Recalculates page rectangles. */
  private void updatePageRects() {
    if (mViewRect.width() == 0 || mViewRect.height() == 0) {
      return;
    } else if (mViewMode == SHOW_ONE_PAGE) {
      mPageRectRight.set(mViewRect);
      mPageRectRight.left += mViewRect.width() * mMargins.left;
      mPageRectRight.right -= mViewRect.width() * mMargins.right;
      mPageRectRight.top += mViewRect.height() * mMargins.top;
      mPageRectRight.bottom -= mViewRect.height() * mMargins.bottom;

      mPageRectLeft.set(mPageRectRight);
      mPageRectLeft.offset(-mPageRectRight.width(), 0);

      int bitmapW = (int) ((mPageRectRight.width() * mViewportWidth) / mViewRect.width());
      int bitmapH = (int) ((mPageRectRight.height() * mViewportHeight) / mViewRect.height());
      mObserver.onPageSizeChanged(bitmapW, bitmapH);
    } else if (mViewMode == SHOW_TWO_PAGES) {
      mPageRectRight.set(mViewRect);
      mPageRectRight.left += mViewRect.width() * mMargins.left;
      mPageRectRight.right -= mViewRect.width() * mMargins.right;
      mPageRectRight.top += mViewRect.height() * mMargins.top;
      mPageRectRight.bottom -= mViewRect.height() * mMargins.bottom;

      mPageRectLeft.set(mPageRectRight);
      mPageRectLeft.right = (mPageRectLeft.right + mPageRectLeft.left) / 2;
      mPageRectRight.left = mPageRectLeft.right;

      int bitmapW = (int) ((mPageRectRight.width() * mViewportWidth) / mViewRect.width());
      int bitmapH = (int) ((mPageRectRight.height() * mViewportHeight) / mViewRect.height());
      mObserver.onPageSizeChanged(bitmapW, bitmapH);
    }
  }
Exemplo n.º 4
0
 public static RectF translate(float x, float y, RectF rect) {
   rect.left += x;
   rect.top += y;
   rect.right += x;
   rect.bottom += y;
   return rect;
 }
Exemplo n.º 5
0
  /** Draws the widget on the given canvas. */
  @Override
  protected synchronized void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // draw seek bar background line
    final RectF rect =
        new RectF(
            padding,
            0.5f * (getHeight() - lineHeight),
            getWidth() - padding,
            0.5f * (getHeight() + lineHeight));
    /*paint.setStyle(Style.FILL);
    paint.setColor(getResources().getColor(R.color.notification_baf_color));
    paint.setAntiAlias(true);
    canvas.drawRect(rect, paint);*/

    // draw seek bar active range line
    rect.left = normalizedToScreen(normalizedMinValue);
    rect.right = normalizedToScreen(normalizedMaxValue);

    // orange color
    paint.setColor(getResources().getColor(R.color.white));
    canvas.drawRect(rect, paint);

    // draw minimum thumb
    drawThumb(normalizedToScreen(normalizedMinValue), Thumb.MIN.equals(pressedThumb), canvas);

    // draw maximum thumb
    drawThumb(normalizedToScreen(normalizedMaxValue), Thumb.MAX.equals(pressedThumb), canvas);
  }
Exemplo n.º 6
0
 /**
  * Set margins or padding. Note: margins are proportional. Meaning a value of .1f will produce a
  * 10% margin.
  */
 public synchronized void setMargins(float left, float top, float right, float bottom) {
   mMargins.left = left;
   mMargins.top = top;
   mMargins.right = right;
   mMargins.bottom = bottom;
   updatePageRects();
 }
Exemplo n.º 7
0
  private void computeRect(final RectF r, View view) {
    // compute current rectangle according to matrix transformation
    final float w = view.getWidth();
    final float h = view.getHeight();

    // use a rectangle at 0,0 to make sure we don't run into issues with scaling
    r.set(0, 0, w, h);

    final Matrix m = mTempMatrix;
    m.reset();
    transformMatrix(m, view);
    mTempMatrix.mapRect(r);

    r.offset(view.getLeft(), view.getTop());

    // Straighten coords if rotations flipped them
    if (r.right < r.left) {
      final float f = r.right;
      r.right = r.left;
      r.left = f;
    }
    if (r.bottom < r.top) {
      final float f = r.top;
      r.top = r.bottom;
      r.bottom = f;
    }
  }
Exemplo n.º 8
0
  private void getEdgesHelper(RectF edgesOut) {
    final float width = getWidth();
    final float height = getHeight();
    final float[] imageDims = getImageDims();
    final float imageWidth = imageDims[0];
    final float imageHeight = imageDims[1];

    float initialCenterX = mRenderer.source.getImageWidth() / 2f;
    float initialCenterY = mRenderer.source.getImageHeight() / 2f;

    float[] rendererCenter = mTempRendererCenter;
    rendererCenter[0] = mCenterX - initialCenterX;
    rendererCenter[1] = mCenterY - initialCenterY;
    mRotateMatrix.mapPoints(rendererCenter);
    rendererCenter[0] += imageWidth / 2;
    rendererCenter[1] += imageHeight / 2;

    final float scale = mRenderer.scale;
    float centerX =
        (width / 2f - rendererCenter[0] + (imageWidth - width) / 2f) * scale + width / 2f;
    float centerY =
        (height / 2f - rendererCenter[1] + (imageHeight - height) / 2f) * scale + height / 2f;
    float leftEdge = centerX - imageWidth / 2f * scale;
    float rightEdge = centerX + imageWidth / 2f * scale;
    float topEdge = centerY - imageHeight / 2f * scale;
    float bottomEdge = centerY + imageHeight / 2f * scale;

    edgesOut.left = leftEdge;
    edgesOut.right = rightEdge;
    edgesOut.top = topEdge;
    edgesOut.bottom = bottomEdge;
  }
  @Override
  public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    if (mPositionDataList == null || mPositionDataList.isEmpty()) {
      return;
    }

    // 计算锚点位置
    int currentPosition = Math.min(mPositionDataList.size() - 1, position);
    int nextPosition = Math.min(mPositionDataList.size() - 1, position + 1);
    PositionData current = mPositionDataList.get(currentPosition);
    PositionData next = mPositionDataList.get(nextPosition);

    mRect.left =
        current.mContentLeft
            - mHorizontalPadding
            + (next.mContentLeft - current.mContentLeft)
                * mEndInterpolator.getInterpolation(positionOffset);
    mRect.top = current.mContentTop - mVerticalPadding;
    mRect.right =
        current.mContentRight
            + mHorizontalPadding
            + (next.mContentRight - current.mContentRight)
                * mStartInterpolator.getInterpolation(positionOffset);
    mRect.bottom = current.mContentBottom + mVerticalPadding;

    if (!mRoundRadiusSet) {
      mRoundRadius = mRect.height() / 2;
    }

    invalidate();
  }
Exemplo n.º 10
0
 public RectF BoudingRecTF() {
   BoudingRecTF.left = Dest.left + (SquidAnimMap.getHeight() * 0.25f);
   BoudingRecTF.top = Dest.top + (SquidAnimMap.getHeight() * 0.45f);
   BoudingRecTF.right = (Dest.left + SquidAnimMap.getHeight()) - SquidAnimMap.getHeight() * 0.30f;
   BoudingRecTF.bottom = Dest.top + (SquidAnimMap.getHeight()) - SquidAnimMap.getHeight() * 0.20f;
   return BoudingRecTF;
 }
Exemplo n.º 11
0
 private void RandomPosition() {
   top = random.nextInt(CanvasHeight - water.FoamTop) + water.FoamBottom;
   Dest.left = CanvasWidth;
   Dest.top = top;
   Dest.right = CanvasWidth + SquidAnimMap.getHeight();
   Dest.bottom = top + SquidAnimMap.getHeight();
 }
 public Bitmap createCodeBitmap() {
   Bitmap mBitmap = Bitmap.createBitmap(mBitmapWidth, mBitmapHeight, Config.ARGB_8888);
   Canvas mCanvas = new Canvas(mBitmap);
   Paint mPaint = new Paint();
   RectF rect = new RectF();
   rect.left = 0;
   rect.right = mBitmapWidth;
   rect.top = mBitmapHeight;
   rect.bottom = 0;
   mCanvas.drawRoundRect(rect, 10, 10, mPaint);
   mRandomCode = CreateCodeSting(); // 获得随机的验证码字符串.
   mCanvas.drawColor(Color.GRAY);
   mPaint.setTextSize(mFontSize);
   for (int i = 0; i < mRandomCode.length(); i++) {
     randomCodeTextStyle(mPaint);
     randomPadding();
     mCanvas.drawText(mRandomCode.charAt(i) + "", mPaddingLeft, mPaddingTop, mPaint);
   }
   for (int j = 0; j < mLineNumber; j++) {
     drawRandomLine(mCanvas, mPaint);
   }
   mCanvas.save(Canvas.ALL_SAVE_FLAG);
   mCanvas.restore();
   return mBitmap;
 }
 @Implementation
 public void offset(float dx, float dy) {
   real.left += dx;
   real.top += dy;
   real.right += dx;
   real.bottom += dy;
 }
Exemplo n.º 14
0
 public final void a(PointF pointf) {
   q = pointf;
   i.left = pointf.x - (float) b;
   i.right = pointf.x + (float) b;
   i.top = pointf.y - (float) b;
   i.bottom = pointf.y + (float) b;
 }
Exemplo n.º 15
0
 /**
  * Calculate the bounds for a view's title
  *
  * @param index
  * @param paint
  * @return
  */
 private RectF calcBounds(int index, Paint paint) {
   // Calculate the text bounds
   RectF bounds = new RectF();
   bounds.right = paint.measureText(mTitleProvider.getTitle(index));
   bounds.bottom = paint.descent() - paint.ascent();
   return bounds;
 }
 @Implementation
 public void set(RectF src) {
   real.left = src.left;
   real.top = src.top;
   real.right = src.right;
   real.bottom = src.bottom;
 }
 public static Bitmap createDefaultBitmap(int rectWidth) {
   Bitmap bitmap = Bitmap.createBitmap(rectWidth, rectWidth, Config.ARGB_8888);
   Canvas canvas = new Canvas(bitmap);
   Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
   canvas.drawColor(0xffCCFEBF);
   float rect = rectWidth / 3;
   RectF f = new RectF();
   f.bottom = rect;
   f.left = 0;
   f.top = 0;
   f.right = rect;
   canvas.save();
   paint.setColor(Color.BLACK);
   canvas.drawRect(f, paint);
   canvas.translate(2 * rect, 0);
   paint.setColor(Color.BLUE);
   canvas.drawRect(f, paint);
   canvas.restore();
   canvas.translate(0, 2 * rect);
   paint.setColor(Color.CYAN);
   canvas.drawRect(f, paint);
   canvas.translate(2 * rect, 0);
   paint.setColor(Color.GRAY);
   canvas.drawRect(f, paint);
   return bitmap;
 }
Exemplo n.º 18
0
    @Override
    public void onDraw(final Canvas c) {
      // Draw the alpha pattern
      mAlphaPattern.draw(c);

      // Draw the shader that shows how transparent a colors looks at a given alpha on top of the
      // alpha pattern
      shaderPaint.setShader(
          new LinearGradient(
              borderSize, 0, this.getWidth() - borderSize, 0, 0, color, TileMode.CLAMP));
      c.drawRect(
          borderSize,
          borderSize,
          this.getWidth() - borderSize,
          this.getHeight() - borderSize,
          shaderPaint);

      // Draw the transparency label on top of that stuff
      c.drawText(
          "Transparency",
          this.getWidth() / 2,
          this.getHeight() / 2 + labelPaint.getTextSize() / 2.0f,
          labelPaint);

      // Draw the alpha tracker on top of everything else
      final float xPos = alphaToXPos(alpha);
      final float rectWidth = 2 * mDensity;
      final RectF r = new RectF();
      r.left = xPos - rectWidth;
      r.right = xPos + rectWidth;
      r.top = 0;
      r.bottom = this.getHeight();
      c.drawRoundRect(r, rectWidth, rectWidth, trackerPaint);
    }
Exemplo n.º 19
0
  protected void drawCenterText(Canvas c) {

    SpannableString centerText = mChart.getCenterText();

    if (mChart.isDrawCenterTextEnabled() && centerText != null) {

      PointF center = mChart.getCenterCircleBox();

      float innerRadius =
          mChart.isDrawHoleEnabled() && mChart.isHoleTransparent()
              ? mChart.getRadius() * (mChart.getHoleRadius() / 100f)
              : mChart.getRadius();

      RectF holeRect = mRectBuffer[0];
      holeRect.left = center.x - innerRadius;
      holeRect.top = center.y - innerRadius;
      holeRect.right = center.x + innerRadius;
      holeRect.bottom = center.y + innerRadius;
      RectF boundingRect = mRectBuffer[1];
      boundingRect.set(holeRect);

      float radiusPercent = mChart.getCenterTextRadiusPercent();
      if (radiusPercent > 0.0) {
        boundingRect.inset(
            (boundingRect.width() - boundingRect.width() * radiusPercent) / 2.f,
            (boundingRect.height() - boundingRect.height() * radiusPercent) / 2.f);
      }

      if (!centerText.equals(mCenterTextLastValue) || !boundingRect.equals(mCenterTextLastBounds)) {

        // Next time we won't recalculate StaticLayout...
        mCenterTextLastBounds.set(boundingRect);
        mCenterTextLastValue = centerText;

        float width = mCenterTextLastBounds.width();

        // If width is 0, it will crash. Always have a minimum of 1
        mCenterTextLayout =
            new StaticLayout(
                centerText,
                0,
                centerText.length(),
                mCenterTextPaint,
                (int) Math.max(Math.ceil(width), 1.f),
                Layout.Alignment.ALIGN_CENTER,
                1.f,
                0.f,
                false);
      }

      float layoutHeight = mCenterTextLayout.getHeight();

      c.save();
      c.translate(
          boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2.f);
      mCenterTextLayout.draw(c);
      c.restore();
    }
  }
 @Override
 protected void onBoundsChange(Rect bounds) {
   super.onBoundsChange(bounds);
   fBounds.left = bounds.left + mBorderWidth / 2f + .5f;
   fBounds.right = bounds.right - mBorderWidth / 2f - .5f;
   fBounds.top = bounds.top + mBorderWidth / 2f + .5f;
   fBounds.bottom = bounds.bottom - mBorderWidth / 2f - .5f;
 }
Exemplo n.º 21
0
  private void resetDirtyRect(float eventX, float eventY) {

    // The mLastTouchX and mLastTouchY were set when the ACTION_DOWN motion event occurred.
    mDirtyRect.left = Math.min(mLastTouchX, eventX);
    mDirtyRect.right = Math.max(mLastTouchX, eventX);
    mDirtyRect.top = Math.min(mLastTouchY, eventY);
    mDirtyRect.bottom = Math.max(mLastTouchY, eventY);
  }
  private Bitmap createShadowBitmap(
      int shadowWidth,
      int shadowHeight,
      float cornerRadius,
      float shadowRadius,
      float dx,
      float dy,
      int shadowColor) {

    Bitmap output = Bitmap.createBitmap(shadowWidth, shadowHeight, Bitmap.Config.ALPHA_8);
    Canvas canvas = new Canvas(output);

    RectF shadowRect =
        new RectF(
            shadowRadius, shadowRadius, shadowWidth - shadowRadius, shadowHeight - shadowRadius);

    if (dy > 0) {
      shadowRect.top += dy;
      shadowRect.bottom -= dy;
    } else if (dy < 0) {
      shadowRect.top += Math.abs(dy);
      shadowRect.bottom -= Math.abs(dy);
    }

    if (dx > 0) {
      shadowRect.left += dx;
      shadowRect.right -= dx;
    } else if (dx < 0) {
      shadowRect.left += Math.abs(dx);
      shadowRect.right -= Math.abs(dx);
    }

    Paint shadowPaint = new Paint();
    shadowPaint.setAntiAlias(true);
    shadowPaint.setColor(shadowColor);
    shadowPaint.setStyle(Paint.Style.FILL);

    if (!isInEditMode()) {
      shadowPaint.setShadowLayer(shadowRadius, dx, dy, shadowColor);
    }

    canvas.drawRoundRect(shadowRect, cornerRadius, cornerRadius, shadowPaint);

    return output;
  }
  /**
   * Transform a rectangle with all matrices with potential animation phases.
   *
   * @param r
   * @param phaseY
   */
  public void rectValueToPixelHorizontal(RectF r, float phaseY) {

    // multiply the height of the rect with the phase
    if (r.left > 0) r.left *= phaseY;
    else r.right *= phaseY;

    mMatrixValueToPx.mapRect(r);
    mViewPortHandler.getMatrixTouch().mapRect(r);
    mMatrixOffset.mapRect(r);
  }
 private RectF getRectF() {
   if (backgroundRectF == null) {
     backgroundRectF = new RectF();
     backgroundRectF.left = mPadding;
     backgroundRectF.top = mPadding;
     backgroundRectF.right = getWidth() - mPadding;
     backgroundRectF.bottom = getHeight() - mPadding;
   }
   return backgroundRectF;
 }
Exemplo n.º 25
0
  /** 更新当前删除、缩放按钮绘制位置 */
  private void updateBtnDrawRect() {
    // 计算删除按钮绘制位置
    mDelDrawPoint[0] = mDelPoint[0];
    mDelDrawPoint[1] = mDelPoint[1];
    mViewMatrix.mapPoints(mDelDrawPoint);
    mDelDrawRectF.left = mDelDrawPoint[0] - (mDelBitmap.getWidth() >> 1);
    mDelDrawRectF.top = mDelDrawPoint[1] - (mDelBitmap.getHeight() >> 1);
    mDelDrawRectF.right = mDelDrawPoint[0] + (mDelBitmap.getWidth() >> 1);
    mDelDrawRectF.bottom = mDelDrawPoint[1] + (mDelBitmap.getHeight() >> 1);

    // 计算缩放按钮绘制位置
    mDragDrawPoint[0] = mDragPoint[0];
    mDragDrawPoint[1] = mDragPoint[1];
    mViewMatrix.mapPoints(mDragDrawPoint);
    mDragDrawRectF.left = mDragDrawPoint[0] - (mDelBitmap.getWidth() >> 1);
    mDragDrawRectF.top = mDragDrawPoint[1] - (mDelBitmap.getHeight() >> 1);
    mDragDrawRectF.right = mDragDrawPoint[0] + (mDelBitmap.getWidth() >> 1);
    mDragDrawRectF.bottom = mDragDrawPoint[1] + (mDelBitmap.getHeight() >> 1);
  }
Exemplo n.º 26
0
  private void drawRoundRect(
      float left, float top, float right, float bottom, float radius, Canvas canvas, Paint paint) {

    tempForRoundRect.left = left;
    tempForRoundRect.top = top;
    tempForRoundRect.right = right;
    tempForRoundRect.bottom = bottom;

    canvas.drawRoundRect(tempForRoundRect, radius, radius, paint);
  }
Exemplo n.º 27
0
  // 网络连接成功后的画图效果
  private void drawOnSuccessfulConnect(Canvas canvas, boolean isRun) {
    int width = this.getWidth();
    int height = this.getHeight();

    if (width != height) {
      int min = Math.min(width, height);
      width = min;
      height = min;
    }

    paint.setAntiAlias(true); // 设置画笔为抗锯齿
    paint.setColor(Color.WHITE); // 设置画笔颜色
    canvas.drawColor(Color.TRANSPARENT); // 白色背景
    // 这里绘制未完成的进度
    paint.setStrokeWidth(progressStrokeWidth); // 线宽
    paint.setStyle(Style.STROKE);

    oval.left = progressStrokeWidth / 2; // 左上角x
    oval.top = progressStrokeWidth / 2; // 左上角y
    oval.right = width - progressStrokeWidth / 2; // 左下角x
    oval.bottom = height - progressStrokeWidth / 2; // 右下角y
    paint.setColor(Color.rgb(59, 175, 218));
    canvas.drawArc(oval, -90, 360, false, paint); // 绘制白色圆圈,即进度条背景
    // 这里绘制已经完成的进度
    oval.left = progressStrokeWidth / 2 + finishProgressStrokeWidth; // 左上角x
    oval.top = progressStrokeWidth / 2 + finishProgressStrokeWidth; // 左上角y
    oval.right = width - progressStrokeWidth / 2 - finishProgressStrokeWidth; // 左下角x
    oval.bottom = height - progressStrokeWidth / 2 - finishProgressStrokeWidth; // 右下角y
    paint.setColor(Color.rgb(59, 175, 218));
    paint.setStrokeWidth(progressStrokeWidth + finishProgressStrokeWidth); // 已完成线宽
    canvas.drawArc(oval, -90, (progress / maxProgress) * 360, false, paint); // 绘制进度圆弧,这里是蓝色
    // 绘制正方形
    paint.setStyle(Style.FILL); // 设置填满
    if (!isRun) {
      // 暂停
      canvas.drawRect(width / 3, height / 3, width / 3 + pauseThePitch, height / 3 * 2, paint); //
      canvas.drawRect(
          width / 3 * 2 - pauseThePitch, height / 3, width / 3 * 2, height / 3 * 2, paint); //
    } else {
      // 正方形
      canvas.drawRect(width / 3, height / 3, width / 3 * 2, height / 3 * 2, paint); //
    }
  }
Exemplo n.º 28
0
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public int onTestSize(int suggestedSize, RectF availableSPace) {
          mPaint.setTextSize(suggestedSize);
          String text = getText().toString();
          boolean singleline = getMaxLines() == 1;
          if (singleline) {
            mTextRect.bottom = mPaint.getFontSpacing();
            mTextRect.right = mPaint.measureText(text);
          } else {
            StaticLayout layout =
                new StaticLayout(
                    text,
                    mPaint,
                    mWidthLimit,
                    Alignment.ALIGN_NORMAL,
                    mSpacingMult,
                    mSpacingAdd,
                    true);
            // return early if we have more lines
            if (getMaxLines() != NO_LINE_LIMIT && layout.getLineCount() > getMaxLines()) {
              return 1;
            }
            mTextRect.bottom = layout.getHeight();
            int maxWidth = -1;
            for (int i = 0; i < layout.getLineCount(); i++) {
              if (maxWidth < layout.getLineWidth(i)) {
                maxWidth = (int) layout.getLineWidth(i);
              }
            }
            mTextRect.right = maxWidth;
          }

          mTextRect.offsetTo(0, 0);
          if (availableSPace.contains(mTextRect)) {
            // may be too small, don't worry we will find the best match
            return -1;
          } else {
            // too big
            return 1;
          }
        }
Exemplo n.º 29
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    width = MeasureSpec.getSize(widthMeasureSpec);
    height = MeasureSpec.getSize(heightMeasureSpec);

    // make sure widget remain in a good appearance
    if ((float) height / (float) width < 0.33333F) {
      height = (int) ((float) width * 0.33333F);

      widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.getMode(widthMeasureSpec));
      heightMeasureSpec =
          MeasureSpec.makeMeasureSpec(height, MeasureSpec.getMode(heightMeasureSpec));

      super.setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
    }

    centerX = width / 2;
    centerY = height / 2;

    cornerRadius = centerY - shadowSpace;

    innerContentBound.left = outerStrokeWidth + shadowSpace;
    innerContentBound.top = outerStrokeWidth + shadowSpace;
    innerContentBound.right = width - outerStrokeWidth - shadowSpace;
    innerContentBound.bottom = height - outerStrokeWidth - shadowSpace;

    intrinsicInnerWidth = innerContentBound.width();
    intrinsicInnerHeight = innerContentBound.height();

    knobBound.left = outerStrokeWidth + shadowSpace;
    knobBound.top = outerStrokeWidth + shadowSpace;
    knobBound.right = height - outerStrokeWidth - shadowSpace;
    knobBound.bottom = height - outerStrokeWidth - shadowSpace;

    intrinsicKnobWidth = knobBound.height();
    knobMaxExpandWidth = (float) width * 0.7F;
    if (knobMaxExpandWidth > knobBound.width() * 1.25F) {
      knobMaxExpandWidth = knobBound.width() * 1.25F;
    }
  }
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);

    padding = Math.max(w, h) * 0.1f;

    rect.left = padding;
    rect.right = w - padding;
    rect.top = padding;
    rect.bottom = h - padding;
  }