void initWith(@NonNull IndicatorOptions indicatorOptions, int pagesCount) {
    mIndicatorPaint.setAntiAlias(true);
    int elementColor;
    if (indicatorOptions.getElementColor() != NO_COLOR) {
      elementColor = indicatorOptions.getElementColor();
    } else {
      elementColor = TutorialPageIndicator.DEFAULT_ELEMENT_COLOR;
    }
    mIndicatorPaint.setColor(elementColor);

    mIndicatorSelectedPaint.setAntiAlias(true);
    int selectedElementColor;
    if (indicatorOptions.getSelectedElementColor() != NO_COLOR) {
      selectedElementColor = indicatorOptions.getSelectedElementColor();
    } else {
      selectedElementColor = TutorialPageIndicator.DEFAULT_SELECTED_ELEMENT_COLOR;
    }
    mIndicatorSelectedPaint.setColor(selectedElementColor);

    if (indicatorOptions.getElementSize() != NO_VALUE) {
      mIndicatorElementSize = indicatorOptions.getElementSize();
    }

    if (indicatorOptions.getElementSpacing() != NO_VALUE) {
      mIndicatorElementSpacing = indicatorOptions.getElementSpacing();
    }

    if (indicatorOptions.getRenderer() != null) {
      mRenderer = indicatorOptions.getRenderer();
    } else {
      mRenderer = Renderer.Factory.newCircleRenderer();
    }

    mPagesCount = pagesCount;
  }
 private void drawRecentBg(Canvas paramCanvas) {
   Paint localPaint = new Paint();
   localPaint.setStyle(Paint.Style.FILL);
   localPaint.setColor(-1513237);
   paramCanvas.drawRect(
       0.0F, 0.0F, this.recentItemLayout.width, this.recentItemLayout.height, localPaint);
 }
  /**
   * 将图片转化为圆形头像 @Title: toRoundBitmap
   *
   * @throws
   */
  public static Bitmap toRoundBitmap(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    float roundPx;
    float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom;
    if (width <= height) {
      roundPx = width / 2;

      left = 0;
      top = 0;
      right = width;
      bottom = width;

      height = width;

      dst_left = 0;
      dst_top = 0;
      dst_right = width;
      dst_bottom = width;
    } else {
      roundPx = height / 2;

      float clip = (width - height) / 2;

      left = clip;
      right = width - clip;
      top = 0;
      bottom = height;
      width = height;

      dst_left = 0;
      dst_top = 0;
      dst_right = height;
      dst_bottom = height;
    }

    Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect src = new Rect((int) left, (int) top, (int) right, (int) bottom);
    final Rect dst = new Rect((int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom);
    final RectF rectF = new RectF(dst);

    paint.setAntiAlias(true); // 设置画笔无锯齿

    canvas.drawARGB(0, 0, 0, 0); // 填充整个Canvas

    // 以下有两种方法画圆,drawRounRect和drawCircle
    canvas.drawRoundRect(
        rectF, roundPx, roundPx, paint); // 画圆角矩形,第一个参数为图形显示区域,第二个参数和第三个参数分别是水平圆角半径和垂直圆角半径。
    // canvas.drawCircle(roundPx, roundPx, roundPx, paint);

    paint.setXfermode(
        new PorterDuffXfermode(
            Mode.SRC_IN)); // 设置两张图片相交时的模式,参考http://trylovecatch.iteye.com/blog/1189452
    canvas.drawBitmap(bitmap, src, dst, paint); // 以Mode.SRC_IN模式合并bitmap和已经draw了的Circle

    return output;
  }
Exemple #4
0
 protected void onDraw(Canvas paramCanvas) {
   Drawable localDrawable = getDrawable();
   if (localDrawable == null) return;
   try {
     if (this.paint == null) {
       Paint localPaint1 = new Paint();
       this.paint = localPaint1;
       this.paint.setFilterBitmap(false);
       Paint localPaint2 = this.paint;
       Xfermode localXfermode1 = MASK_XFERMODE;
       @SuppressWarnings("unused")
       Xfermode localXfermode2 = localPaint2.setXfermode(localXfermode1);
     }
     float f1 = getWidth();
     float f2 = getHeight();
     int i = paramCanvas.saveLayer(0.0F, 0.0F, f1, f2, null, 31);
     int j = getWidth();
     int k = getHeight();
     localDrawable.setBounds(0, 0, j, k);
     localDrawable.draw(paramCanvas);
     if ((this.mask == null) || (this.mask.isRecycled())) {
       Bitmap localBitmap1 = createMask();
       this.mask = localBitmap1;
     }
     Bitmap localBitmap2 = this.mask;
     Paint localPaint3 = this.paint;
     paramCanvas.drawBitmap(localBitmap2, 0.0F, 0.0F, localPaint3);
     paramCanvas.restoreToCount(i);
     return;
   } catch (Exception localException) {
     StringBuilder localStringBuilder =
         new StringBuilder().append("Attempting to draw with recycled bitmap. View ID = ");
     System.out.println("localStringBuilder==" + localStringBuilder);
   }
 }
  @Override
  protected void onDraw(Canvas canvas) {
    // avoids drawing too much
    canvas.drawBitmap(mBitmap, xoffset, yoffset, mBitmapPaint);
    Paint paintBlue = new Paint();
    paintBlue.setStyle(Paint.Style.STROKE);
    paintBlue.setStrokeWidth(3);
    paintBlue.setTextSize(ROW_HEIGHT);
    paintBlue.setColor(Color.WHITE);
    canvas.drawText("X:" + x0, 10, VERTICAL_MARGIN, paintBlue);
    canvas.drawText("Y:" + y0, 10, VERTICAL_MARGIN + 32, paintBlue);
    canvas.drawText("scale:" + scale, 10, VERTICAL_MARGIN + 32 * 2, paintBlue);

    if (mode == ZOOM) {
      float w = width / scaleFactor;
      float h = height / scaleFactor;
      Paint paint = new Paint();
      paint.setStyle(Paint.Style.STROKE);
      paint.setStrokeWidth(3);
      paint.setTextSize(ROW_HEIGHT);
      paint.setColor(Color.RED);
      canvas.drawCircle(mid.x, mid.y, Math.min(w, h), paint);
      canvas.drawCircle(mid.x, mid.y, 5, paint);
      canvas.drawText("Scale:" + scale * scaleFactor, width / 2, height * 0.95f, paint);
      canvas.drawText("Mid:" + mid.x + "," + mid.y, width / 2, height * 0.95f + ROW_HEIGHT, paint);
    }
    // stops only after drawing a last time
    invalidate();
  }
Exemple #6
0
 private void drawIntoBitmap() {
   Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
   if (mAlpha) {
     if (!mBlur) {
       mViewBitmap.eraseColor(Color.TRANSPARENT);
     }
   }
   if (mBlur) {
     if (mAlphaMark) {
       p.setAlpha(mBlurVal);
     } else {
       mAlphaMark = true;
     }
   }
   Canvas c = new Canvas(mViewBitmap);
   c.save();
   Path path = new Path();
   path.moveTo(0, 0);
   path.arcTo(
       new RectF(-mBitmapViewWidth, -mBitmapViewWidth, mBitmapViewWidth, mBitmapViewWidth),
       0,
       mAngle);
   // path.lineTo(0, 1);
   path.close();
   c.clipPath(path);
   // c.drawRGB(0, 0, 0);
   // RectF r = new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight);
   c.drawBitmap(
       mBitmap,
       new Rect(mCurX, mCurY, mRadius + mCurX, mBitmapNewHeight + mCurY),
       new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight),
       p);
 }
Exemple #7
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);
    }
 public static Paint redPaint() {
   Paint p = new Paint();
   p.setStrokeWidth(strokeWidth);
   p.setStyle(Style.FILL);
   p.setColor(Color.RED);
   return p;
 }
 public static Paint greenPaint() {
   Paint p = new Paint();
   p.setStrokeWidth(strokeWidth);
   p.setStyle(Style.FILL);
   p.setColor(Color.GREEN);
   return p;
 }
Exemple #10
0
  public static Shadow generateShadow(View view, float elevation) {
    if (!software && renderScript == null) {
      try {
        renderScript = RenderScript.create(view.getContext());
        blurShader = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
      } catch (RSRuntimeException ignore) {
        software = true;
      }
    }

    CornerView cornerView = (CornerView) view;

    int e = (int) Math.ceil(elevation);
    int c = Math.max(e, cornerView.getCornerRadius());

    Bitmap bitmap;
    bitmap = Bitmap.createBitmap(e * 2 + 2 * c + 1, e * 2 + 2 * c + 1, Bitmap.Config.ARGB_8888);

    Canvas shadowCanvas = new Canvas(bitmap);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(0xff000000);

    roundRect.set(e, e, bitmap.getWidth() - e, bitmap.getHeight() - e);
    shadowCanvas.drawRoundRect(roundRect, c, c, paint);

    blur(bitmap, elevation / 2);

    return new NinePatchShadow(bitmap, elevation, c);
  }
  public VisualizerView(Context context) {
    super(context);

    paint.setStrokeWidth(2f);
    paint.setAntiAlias(true);
    paint.setColor(Color.rgb(129, 201, 54));
  }
Exemple #12
0
    public void chooseHeight(
        CharSequence text,
        int start,
        int end,
        int spanstartv,
        int v,
        Paint.FontMetricsInt fm,
        TextPaint paint) {
      int size = mSize;
      if (paint != null) {
        size *= paint.density;
      }

      if (fm.bottom - fm.top < size) {
        fm.top = fm.bottom - size;
        fm.ascent = fm.ascent - size;
      } else {
        if (sProportion == 0) {
          /*
           * Calculate what fraction of the nominal ascent the height
           * of a capital letter actually is, so that we won't reduce
           * the ascent to less than that unless we absolutely have
           * to.
           */

          Paint p = new Paint();
          p.setTextSize(100);
          Rect r = new Rect();
          p.getTextBounds("ABCDEFG", 0, 7, r);

          sProportion = (r.top) / p.ascent();
        }

        int need = (int) Math.ceil(-fm.top * sProportion);

        if (size - fm.descent >= need) {
          /*
           * It is safe to shrink the ascent this much.
           */

          fm.top = fm.bottom - size;
          fm.ascent = fm.descent - size;
        } else if (size >= need) {
          /*
           * We can't show all the descent, but we can at least show
           * all the ascent.
           */

          fm.top = fm.ascent = -need;
          fm.bottom = fm.descent = fm.top + size;
        } else {
          /*
           * Show as much of the ascent as we can, and no descent.
           */

          fm.top = fm.ascent = -size;
          fm.bottom = fm.descent = 0;
        }
      }
    }
  @Override
  public void onDraw(Canvas c) {
    mRect.setView(this);

    if (colors.getBkgColor() != Color.TRANSPARENT) {
      paint.setColor(colors.getBkgColor());
      mRect.drawRounded(c, paint);
    }

    paint.setColor(colors.getSndColor());
    mRect.drawRimRounded(c, paint);
    mRect.drawStripesX(c, mn, paint);

    for (int i = 0; i < pressCount; i++) {
      PointF f = mActivePointers.get(i);
      if (f != null) {
        paint.setColor(palette[i]);
        mRect.drawCross(c, f.x, f.y, paint);
        int mSelected = ViewUtils.getCell(mn, f.x);
        paint.setColor(colors.getSndColor());
        mRect.drawSelectedStripesX(c, mn, mSelected, paint);
      }
    }

    if (!mLabels.isEmpty()) {
      paint.setColor(textColor);
      mRect.drawStripesXText(c, mn, paint, mLabels);
    }
  }
    public DrawView(Context context) {
      super(context);

      rect = new Rect(0, 0, 100, 100);
      rect1 = new Rect(0, 0, 500, 200);
      p = new Paint(Paint.ANTI_ALIAS_FLAG);
      picture = new Picture();

      Canvas canvas = picture.beginRecording(300, 300);

      p.setColor(Color.GREEN);
      canvas.drawCircle(150, 100, 80, p);

      p.setColor(Color.BLUE);
      canvas.drawRect(20, 70, 150, 200, p);

      p.setColor(Color.RED);
      path = new Path();
      path.moveTo(170, 80);
      path.lineTo(240, 210);
      path.lineTo(100, 210);
      path.close();
      canvas.drawPath(path, p);

      picture.endRecording();
    }
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // Draw the inner circle
    canvas.drawArc(innerCircleBounds, 360, 360, false, circlePaint);
    // Draw the rim
    canvas.drawArc(circleBounds, 360, 360, false, rimPaint);
    canvas.drawArc(circleOuterContour, 360, 360, false, contourPaint);
    // canvas.drawArc(circleInnerContour, 360, 360, false, contourPaint);
    // Draw the bar
    if (isSpinning) {
      canvas.drawArc(circleBounds, progress - 90, barLength, false, barPaint);
    } else {
      canvas.drawArc(circleBounds, -90, progress, false, barPaint);
    }
    // Draw the text (attempts to center it horizontally and vertically)
    float textHeight = textPaint.descent() - textPaint.ascent();
    float verticalTextOffset = (textHeight / 2) - textPaint.descent();

    for (String line : splitText) {
      float horizontalTextOffset = textPaint.measureText(line) / 2;
      canvas.drawText(
          line,
          this.getWidth() / 2 - horizontalTextOffset,
          this.getHeight() / 2 + verticalTextOffset,
          textPaint);
    }
    if (isSpinning) {
      scheduleRedraw();
    }
  }
 public static Paint bluePaint() {
   Paint p = new Paint();
   p.setStrokeWidth(strokeWidth);
   p.setStyle(Style.FILL);
   p.setColor(Color.BLUE);
   return p;
 }
  public static Bitmap doHighlightImage(Bitmap src) {
    // create new bitmap, which will be painted and becomes result image
    Bitmap bmOut =
        Bitmap.createBitmap(src.getWidth() + 96, src.getHeight() + 96, Bitmap.Config.ARGB_8888);
    // setup canvas for painting
    Canvas canvas = new Canvas(bmOut);
    // setup default color
    canvas.drawColor(0, PorterDuff.Mode.CLEAR);

    // create a blur paint for capturing alpha
    Paint ptBlur = new Paint();
    ptBlur.setMaskFilter(new BlurMaskFilter(15, BlurMaskFilter.Blur.NORMAL));
    int[] offsetXY = new int[2];
    // capture alpha into a bitmap
    Bitmap bmAlpha = src.extractAlpha(ptBlur, offsetXY);
    // create a color paint
    Paint ptAlphaColor = new Paint();
    ptAlphaColor.setColor(0xFFFFFFFF);
    // paint color for captured alpha region (bitmap)
    canvas.drawBitmap(bmAlpha, offsetXY[0], offsetXY[1], ptAlphaColor);
    // free memory
    bmAlpha.recycle();

    // paint the image source
    canvas.drawBitmap(src, 0, 0, null);

    // return out final image
    return bmOut;
  }
 public static Paint transparentBluePaint() {
   Paint p = new Paint();
   p.setStrokeWidth(strokeWidth);
   p.setStyle(Style.STROKE);
   p.setColor(Color.BLUE);
   return p;
 }
Exemple #19
0
 private void drawIntoBitmap(int i) {
   Canvas c = new Canvas(mViewBitmap);
   // Paint p = new Paint();
   Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
   if (mBlur) {
     if (mAlphaMark) {
       p.setAlpha(mBlurVal);
     } else {
       mAlphaMark = true;
     }
   }
   // p.setAntiAlias(true);
   c.save();
   Path path = new Path();
   path.moveTo(0, 0);
   path.arcTo(
       new RectF(-mBitmapViewWidth, -mBitmapViewWidth, mBitmapViewWidth, mBitmapViewWidth),
       0,
       mAngle);
   // path.lineTo(0, 1);
   path.close();
   c.clipPath(path);
   // RectF r = new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight);
   c.drawBitmap(
       mBitmap,
       new Rect(mCurX, mCurY, mRadius + mCurX, mBitmapNewHeight + mCurY),
       new RectF(0, 0, mBitmapViewWidth, mBitmapViewHeight),
       p);
   // mPaint.setTextSize(28);
   // mPaint.setColor(Color.RED);
   // c.drawText(debugString, 150, 50, mPaint);
 }
 public static Paint myPaint(int strokeWidth, int color) {
   Paint p = new Paint();
   p.setStrokeWidth(strokeWidth);
   p.setStyle(Style.FILL);
   p.setColor(color);
   return p;
 }
Exemple #21
0
  /**
   * The graphical representation of a series.
   *
   * @param canvas the canvas to paint to
   * @param paint the paint to be used for drawing
   * @param points the array of points to be used for drawing the series
   * @param seriesRenderer the series renderer
   * @param yAxisValue the minimum value of the y axis
   * @param seriesIndex the index of the series currently being drawn
   * @param startIndex the start index of the rendering points
   */
  @Override
  public void drawSeries(
      Canvas canvas,
      Paint paint,
      List<Float> points,
      XYSeriesRenderer seriesRenderer,
      float yAxisValue,
      int seriesIndex,
      int startIndex) {
    int seriesNr = mDataset.getSeriesCount();
    int length = points.size();
    paint.setColor(seriesRenderer.getColor());
    paint.setStyle(Style.FILL);
    float halfDiffX = getHalfDiffX(points, length, seriesNr);
    for (int i = 0; i < length; i += 2) {
      float x = points.get(i);
      float y = points.get(i + 1);

      if (mType == Type.HEAPED && seriesIndex > 0) {
        float lastY = mPreviousSeriesPoints.get(i + 1);
        y = y + (lastY - yAxisValue);
        points.set(i + 1, y);
        drawBar(canvas, x, lastY, x, y, halfDiffX, seriesNr, seriesIndex, paint);
      } else {
        drawBar(canvas, x, yAxisValue, x, y, halfDiffX, seriesNr, seriesIndex, paint);
      }
    }
    paint.setColor(seriesRenderer.getColor());
    mPreviousSeriesPoints = points;
  }
Exemple #22
0
  public void drawHealthBar(Canvas canvas, boolean serverDraw) {
    if (isDead()) return;

    tempPaint.set(paint);
    paint.setStyle(Style.FILL);

    float radius = getRadius();
    float border = 1f;

    float left = getX() - radius;
    float top = (serverDraw) ? getY() + (radius * 2f) : getY() - (radius * 2f);
    float right = left + 2f * radius;
    float bottom = top + radius / 2f;

    paint.setColor(Color.WHITE);
    canvas.drawRect(left - border, top - border, right + border, bottom + border, paint);

    paint.setColor(Color.RED);
    canvas.drawRect(left, top, right, bottom, paint);

    paint.setColor(Color.GREEN);
    float greenStopX = MathUtils.scale(0f, getStartingHealth(), left, right, getHealth(), true);
    canvas.drawRect(left, top, greenStopX, bottom, paint);

    paint.set(tempPaint);
  }
 public ArtifactDrawable(Context context, Kind kind, String text) {
   this.context = context;
   if (kind == Kind.IMAGE) {
     this.kind = Kind.OPERATION;
     this.text = "\u273f";
   } else {
     this.kind = kind;
     this.text = text;
   }
   if (kind == Kind.MODULE
       || kind == Kind.OPERATION
       || kind == Kind.SOUND
       || kind == Kind.CONTINUOUS_OPERATION
       || kind == Kind.IMAGE) {
     rect = new RectF();
   }
   if (kind == Kind.PROPERTY || kind == Kind.TUTORIAL || kind == Kind.SOUND) {
     path = new Path();
   }
   if (kind == Kind.CLASSIFIER) {
     paint.setTypeface(Typeface.DEFAULT_BOLD);
   }
   paint.setTextAlign(Paint.Align.CENTER);
   paint.setAntiAlias(true);
   setEnabled(true);
 }
Exemple #24
0
  /**
   * Set the bar color. <br>
   * <br>
   * Its discouraged to use this method.
   *
   * @param color
   */
  public void setColor(int color) {
    int x1, y1;
    if (mOrientation == ORIENTATION_HORIZONTAL) {
      x1 = (mBarLength + mBarPointerHaloRadius);
      y1 = mBarThickness;
    } else {
      x1 = mBarThickness;
      y1 = (mBarLength + mBarPointerHaloRadius);
    }

    Color.colorToHSV(color, mHSVColor);
    shader =
        new LinearGradient(
            mBarPointerHaloRadius,
            0,
            x1,
            y1,
            new int[] {Color.HSVToColor(0x00, mHSVColor), color},
            null,
            Shader.TileMode.CLAMP);
    mBarPaint.setShader(shader);
    calculateColor(mBarPointerPosition);
    mBarPointerPaint.setColor(mColor);
    if (mPicker != null) {
      mPicker.setNewCenterColor(mColor);
    }
    invalidate();
  }
  /** @param paint */
  private void initWhiteLinePaint(Paint paint) {
    paint.setARGB(105, 178, 172, 160);
    paint.setStrokeWidth(getResources().getDimension(R.dimen.pwd_line_size));

    paint.setAntiAlias(true);
    paint.setStrokeCap(Cap.ROUND);
  }
  @Override
  public void draw(Canvas canvas, Paint paint) {
    float circleSpacing = 12;
    float x = getWidth() / 2;
    float y = getHeight() / 2;

    // draw fill circle
    canvas.save();
    canvas.translate(x, y);
    canvas.scale(scaleFloat1, scaleFloat1);
    paint.setStyle(Paint.Style.FILL);
    canvas.drawCircle(0, 0, x / 2.5f, paint);

    canvas.restore();

    canvas.translate(x, y);
    canvas.scale(scaleFloat2, scaleFloat2);
    canvas.rotate(degrees);

    paint.setStrokeWidth(3);
    paint.setStyle(Paint.Style.STROKE);

    // draw two arc
    float[] startAngles = new float[] {225, 45};
    for (int i = 0; i < 2; i++) {
      RectF rectF =
          new RectF(-x + circleSpacing, -y + circleSpacing, x - circleSpacing, y - circleSpacing);
      canvas.drawArc(rectF, startAngles[i], 90, false, paint);
    }
  }
Exemple #27
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
    int previewWidth = metrics.widthPixels;
    int previewHeight = metrics.heightPixels;
    int borderHeight = (previewHeight - previewWidth) / 2;

    Paint mPaintbrush = new Paint(Paint.ANTI_ALIAS_FLAG);

    int xStart = 0;
    int xFinish = previewWidth;

    int yStart1 = 0;
    int yEnd1 = borderHeight;

    int yStart2 = previewHeight - borderHeight;
    int yEnd2 = previewHeight;

    //        mPaintbrush.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintbrush.setColor(Color.BLACK);
    mPaintbrush.setStrokeWidth(10);

    this.setBackgroundColor(Color.TRANSPARENT);
    this.bringToFront();
    canvas.drawRect(previewWidth / 3, 0, previewWidth / 3, previewWidth, mPaintbrush);
  }
 private void displayFps(Canvas canvas, String fps) {
   if (canvas != null && fps != null) {
     Paint paint = new Paint();
     paint.setARGB(255, 255, 255, 255);
     canvas.drawText(fps, this.getWidth() - 50, 20, paint);
   }
 }
  private void blur(Bitmap bg, View view) {
    long startMs = System.currentTimeMillis();

    float radius = 20;
    Bitmap overlay =
        Bitmap.createBitmap(
            view.getMeasuredWidth() / scaleFactor,
            view.getMeasuredHeight() / scaleFactor,
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
    // scale参数为float类型
    canvas.scale(1.0f / scaleFactor, 1.0f / scaleFactor);
    // 开启双缓冲
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);

    canvas.drawBitmap(bg, 0, 0, paint);
    // Bitmap result = blurBitmap(overlay, 2);
    Bitmap result = blurBitmapStack(overlay, 2);
    view.setBackground(new BitmapDrawable(result));
    long endMs = System.currentTimeMillis();
    String time = (endMs - startMs) + "ms";
    Toast.makeText(this, time, Toast.LENGTH_SHORT).show();
  }
 private void refresh(Canvas canvas, Paint p) {
   String s = sharedPrefs.getString("list", "-1");
   if ((s.equals("2")) && (ColorTheme.isLightTheme)) {
     ColorTheme.setDarkTheme();
   } else if ((s.equals("1") && (ColorTheme.isDarkTheme))) {
     ColorTheme.setLightTheme();
   }
   if (!coordinateSystemCreated) {
     setSystemInformation();
     coordinateSystem = new CoordinateSystem();
     coordinateSystemCreated = true;
   }
   canvas.drawColor(ColorTheme.DARK_COLOR);
   paint.setStrokeWidth(4);
   for (ShapeList shape : shapes) {
     shape.draw(canvas, p);
     if (paint.getStrokeWidth() == 4) {
       paint.setStrokeWidth(1);
     }
   }
   if (shapes.size() != 0) {
     paint.setStrokeWidth(4);
     shapes.get(FIRST_SHAPE_IN_LIST).draw(canvas, paint);
   }
   if (shapes.size() > 0) {
     canvas.drawText(shapes.get(FIRST_SHAPE_IN_LIST).toString(), 30, 15, p);
   }
   if (sharedPrefs.getBoolean("checkBox", false)) {
     coordinateSystem.draw(canvas);
   }
 }