Java Code Examples for android.graphics.Canvas#drawPoint()

The following examples show how to use android.graphics.Canvas#drawPoint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CaptureActivity.java    From reacteu-app with MIT License 6 votes vote down vote up
/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of the barcode.
 *
 * @param barcode   A bitmap of the captured image.
 * @param rawResult The decoded results which contains the points to draw.
 */
private void drawResultPoints(Bitmap barcode, Result rawResult) {
  ResultPoint[] points = rawResult.getResultPoints();
  if (points != null && points.length > 0) {
    Canvas canvas = new Canvas(barcode);
    Paint paint = new Paint();
    paint.setColor(getResources().getColor(fakeR.getId("color", "result_points")));
    if (points.length == 2) {
      paint.setStrokeWidth(4.0f);
      drawLine(canvas, paint, points[0], points[1]);
    } else if (points.length == 4 &&
               (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A ||
                rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
      // Hacky special case -- draw two lines, for the barcode and metadata
      drawLine(canvas, paint, points[0], points[1]);
      drawLine(canvas, paint, points[2], points[3]);
    } else {
      paint.setStrokeWidth(10.0f);
      for (ResultPoint point : points) {
        canvas.drawPoint(point.getX(), point.getY(), paint);
      }
    }
  }
}
 
Example 2
Source File: CaptureActivity.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of
 * the barcode.
 * 
 * @param barcode
 *            A bitmap of the captured image.
 * @param scaleFactor
 *            amount by which thumbnail was scaled
 * @param rawResult
 *            The decoded results which contains the points to draw.
 */
private void drawResultPoints(Bitmap barcode, float scaleFactor,
		Result rawResult) {
	ResultPoint[] points = rawResult.getResultPoints();
	if (points != null && points.length > 0) {
		Canvas canvas = new Canvas(barcode);
		Paint paint = new Paint();
		paint.setColor(getResources().getColor(R.color.result_points));
		if (points.length == 2) {
			paint.setStrokeWidth(4.0f);
			drawLine(canvas, paint, points[0], points[1], scaleFactor);
		} else if (points.length == 4
				&& (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A || rawResult
						.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
			// Hacky special case -- draw two lines, for the barcode and
			// metadata
			drawLine(canvas, paint, points[0], points[1], scaleFactor);
			drawLine(canvas, paint, points[2], points[3], scaleFactor);
		} else {
			paint.setStrokeWidth(10.0f);
			for (ResultPoint point : points) {
				if (point != null) {
					canvas.drawPoint(scaleFactor * point.getX(),
							scaleFactor * point.getY(), paint);
				}
			}
		}
	}
}
 
Example 3
Source File: SnowflakesEffect.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void draw(Canvas canvas) {
    switch (type) {
        case 0: {
            particlePaint.setAlpha((int) (255 * alpha));
            canvas.drawPoint(x, y, particlePaint);
            break;
        }
        case 1:
        default: {
            particleThinPaint.setAlpha((int) (255 * alpha));

            float angle = (float) -Math.PI / 2;

            float px = AndroidUtilities.dpf2(2.0f) * 2 * scale;
            float px1 = -AndroidUtilities.dpf2(0.57f) * 2 * scale;
            float py1 = AndroidUtilities.dpf2(1.55f) * 2 * scale;
            for (int a = 0; a < 6; a++) {
                float x1 = (float) Math.cos(angle) * px;
                float y1 = (float) Math.sin(angle) * px;
                float cx = x1 * 0.66f;
                float cy = y1 * 0.66f;
                canvas.drawLine(x, y, x + x1, y + y1, particleThinPaint);

                float angle2 = (float) (angle - Math.PI / 2);
                x1 = (float) (Math.cos(angle2) * px1 - Math.sin(angle2) * py1);
                y1 = (float) (Math.sin(angle2) * px1 + Math.cos(angle2) * py1);
                canvas.drawLine(x + cx, y + cy, x + x1, y + y1, particleThinPaint);

                x1 = (float) (-Math.cos(angle2) * px1 - Math.sin(angle2) * py1);
                y1 = (float) (-Math.sin(angle2) * px1 + Math.cos(angle2) * py1);
                canvas.drawLine(x + cx, y + cy, x + x1, y + y1, particleThinPaint);

                angle += angleDiff;
            }
            break;
        }
    }

}
 
Example 4
Source File: DrawPoint.java    From PaintView with MIT License 5 votes vote down vote up
@Override
public void draw(Canvas canvas, Matrix matrix) {
    //缩放坐标映射
    matrix.getValues(matrixValues);
    x = x * matrixValues[0] + y * matrixValues[1] + matrixValues[2];
    y = x * matrixValues[3] + y * matrixValues[4] + matrixValues[5];

    canvas.drawPoint(x, y, paint.setStrokeWidth());
}
 
Example 5
Source File: RxShineView.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    for (int i = 0; i < shineCount; i++) {
        if (allowRandomColor) {
            paint.setColor(colorRandom[Math.abs(colorCount / 2 - i) >= colorCount ? colorCount - 1 : Math.abs(colorCount / 2 - i)]);
        }
        canvas.drawArc(rectF, 360f / shineCount * i + 1 + ((value - 1) * turnAngle), 0.1f, false, getConfigPaint(paint));
    }

    for (int i = 0; i < shineCount; i++) {
        if (allowRandomColor) {
            paint.setColor(colorRandom[Math.abs(colorCount / 2 - i) >= colorCount ? colorCount - 1 : Math.abs(colorCount / 2 - i)]);
        }
        canvas.drawArc(rectFSmall, 360f / shineCount * i + 1 - smallOffsetAngle + ((value - 1) * turnAngle), 0.1f, false, getConfigPaint(paintSmall));

    }
    paint.setStrokeWidth(btnWidth * (clickValue) * (shineDistanceMultiple - distanceOffset));
    if (clickValue != 0) {
        paint2.setStrokeWidth(btnWidth * (clickValue) * (shineDistanceMultiple - distanceOffset) - 8);
    } else {
        paint2.setStrokeWidth(0);
    }
    canvas.drawPoint(centerAnimX, centerAnimY, paint);
    canvas.drawPoint(centerAnimX, centerAnimY, paint2);
    if (mRxShineAnimator != null && !isRun) {
        isRun = true;
        showAnimation(mRxShineButton);
    }
}
 
Example 6
Source File: ScatterChart.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public void drawLegendShape(Canvas canvas, SimpleSeriesRenderer simpleseriesrenderer, float f, float f1, int i, Paint paint)
{
    if (((XYSeriesRenderer)simpleseriesrenderer).isFillPoints())
    {
        paint.setStyle(android.graphics.Paint.Style.FILL);
    } else
    {
        paint.setStyle(android.graphics.Paint.Style.STROKE);
    }
    switch (b.a[((XYSeriesRenderer)simpleseriesrenderer).getPointStyle().ordinal()])
    {
    default:
        return;

    case 1: // '\001'
        a(canvas, paint, f + 10F, f1);
        return;

    case 2: // '\002'
        b(canvas, paint, f + 10F, f1);
        return;

    case 3: // '\003'
        a(canvas, paint, new float[6], f + 10F, f1);
        return;

    case 4: // '\004'
        c(canvas, paint, f + 10F, f1);
        return;

    case 5: // '\005'
        b(canvas, paint, new float[8], f + 10F, f1);
        return;

    case 6: // '\006'
        canvas.drawPoint(f + 10F, f1, paint);
        break;
    }
}
 
Example 7
Source File: BaseDraw.java    From zone-sdk with MIT License 5 votes vote down vote up
private void drawMe(Canvas canvas) {
    int size=50;
    String dot="dot:";
    String line="line:";
    String lines="lines:";
    Paint p = new Paint();
    p.setColor(Color.BLACK);// 设置红色
    p.setStyle(Paint.Style.FILL);

    p.setTextSize(size);
    canvas.drawText(dot,0,size,p);
    canvas.drawText(line,0,size*2,p);
    canvas.drawText(lines,0,size*3,p);

    p.setStrokeWidth(10);
    //两个字母是一个汉子  记 size
    canvas.drawPoint(size*(float)Math.ceil(dot.toCharArray().length/2),size,p);
    //starX1,startY2,enxX1,endY1  两个字母是一个汉子  记 size
    canvas.drawLine(size*(float)Math.ceil(line.toCharArray().length/2),size*2,size*(float)Math.ceil(line.toCharArray().length/2)+100,size*2,p);
    //starX1,startY2,enxX1,endY1......starXn,startYn,enxXn,endYn
    float[] pts=new float[]{
            size*(float)Math.ceil(lines.toCharArray().length/2),size*3,size*(float)Math.ceil(lines.toCharArray().length/2)+100,size*3,
            size*(float)Math.ceil(lines.toCharArray().length/2)*2,size*3,size*(float)Math.ceil(lines.toCharArray().length/2)*2+100,size*3,
    };
    canvas.drawLines(pts,p);


    int offset=100;
    canvas.drawRect(offset,size*4,size+offset,size*5,p);
    int radius=50;
    canvas.drawCircle(size+offset+radius,size*4,radius,p);

}
 
Example 8
Source File: StrokeView.java    From sinovoice-pathfinder with MIT License 5 votes vote down vote up
/**
 * ���Ʊ�ʽ��Ч��
 * 
 * @param x
 * @param y
 */
private void drawPenScript(int x, int y) {
	int penScriptResult = HWRManager.instance().penScript(x, y);

	Canvas canvas = new Canvas(this.mPenScriptBitmap);
	if (penScriptResult == HciErrorCode.HCI_ERR_NONE) {
		List<HwrPenScriptResultItem> items = HWRManager
				.instance().getPenScriptRetList();
		for (int k = 0; k < items.size(); k++) {

			HwrPenScriptResultItem item = items.get(k);
			short[] pageImg = item.getPageImg();
			long colorL = item.getPenColor();

			// ��unsigned ��ֵ��Ϊ ��ɫֵ
			colorL = colorL & 0xffffffL;
			colorL = colorL | 0xff000000L;
			mBrushPaint.setColor((int) colorL);

			for (int h = 0; h < item.getHeight(); h++) {
				for (int w = 0; w < item.getWidth(); w++) {
					int pos = h * item.getWidth() + w;
					if (pageImg[pos] == 0) {
						canvas.drawPoint(w + item.getX(), h + item.getY(),
								mBrushPaint);
					}
				}
			}
		}
	} else {
		StrokeMgr.instance().isBrush = false;
	}
}
 
Example 9
Source File: SnowflakesEffect.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void draw(Canvas canvas) {
    switch (type) {
        case 0: {
            particlePaint.setAlpha((int) (255 * alpha));
            canvas.drawPoint(x, y, particlePaint);
            break;
        }
        case 1:
        default: {
            particleThinPaint.setAlpha((int) (255 * alpha));

            float angle = (float) -Math.PI / 2;

            float px = AndroidUtilities.dpf2(2.0f) * 2 * scale;
            float px1 = -AndroidUtilities.dpf2(0.57f) * 2 * scale;
            float py1 = AndroidUtilities.dpf2(1.55f) * 2 * scale;
            for (int a = 0; a < 6; a++) {
                float x1 = (float) Math.cos(angle) * px;
                float y1 = (float) Math.sin(angle) * px;
                float cx = x1 * 0.66f;
                float cy = y1 * 0.66f;
                canvas.drawLine(x, y, x + x1, y + y1, particleThinPaint);

                float angle2 = (float) (angle - Math.PI / 2);
                x1 = (float) (Math.cos(angle2) * px1 - Math.sin(angle2) * py1);
                y1 = (float) (Math.sin(angle2) * px1 + Math.cos(angle2) * py1);
                canvas.drawLine(x + cx, y + cy, x + x1, y + y1, particleThinPaint);

                x1 = (float) (-Math.cos(angle2) * px1 - Math.sin(angle2) * py1);
                y1 = (float) (-Math.sin(angle2) * px1 + Math.cos(angle2) * py1);
                canvas.drawLine(x + cx, y + cy, x + x1, y + y1, particleThinPaint);

                angle += angleDiff;
            }
            break;
        }
    }

}
 
Example 10
Source File: DoodleView.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
public void draw(Canvas canvas, Paint paint) {
    paint.setColor(mColor);
    paint.setStrokeWidth(mWidth);
    if (mIsDot) {
        canvas.drawPoint(mStartX, mStartY, paint);
    } else {
        canvas.drawPath(mPath, paint);
    }
}
 
Example 11
Source File: PressView.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    final ArrayList<PointF> points = mPoints;
    final int count = points.size();
    if (count <= 0)
        return;
    if (count == 1) {
        final PointF p = points.get(0);
        canvas.drawPoint(p.x, p.y, mPaint);
        return;
    }
    canvas.drawPath(mPath, mPaint);
}
 
Example 12
Source File: SnowflakesEffect.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void draw(Canvas canvas) {
    switch (type) {
        case 0: {
            particlePaint.setAlpha((int) (255 * alpha));
            canvas.drawPoint(x, y, particlePaint);
            break;
        }
        case 1:
        default: {
            particleThinPaint.setAlpha((int) (255 * alpha));

            float angle = (float) -Math.PI / 2;

            float px = AndroidUtilities.dpf2(2.0f) * 2 * scale;
            float px1 = -AndroidUtilities.dpf2(0.57f) * 2 * scale;
            float py1 = AndroidUtilities.dpf2(1.55f) * 2 * scale;
            for (int a = 0; a < 6; a++) {
                float x1 = (float) Math.cos(angle) * px;
                float y1 = (float) Math.sin(angle) * px;
                float cx = x1 * 0.66f;
                float cy = y1 * 0.66f;
                canvas.drawLine(x, y, x + x1, y + y1, particleThinPaint);

                float angle2 = (float) (angle - Math.PI / 2);
                x1 = (float) (Math.cos(angle2) * px1 - Math.sin(angle2) * py1);
                y1 = (float) (Math.sin(angle2) * px1 + Math.cos(angle2) * py1);
                canvas.drawLine(x + cx, y + cy, x + x1, y + y1, particleThinPaint);

                x1 = (float) (-Math.cos(angle2) * px1 - Math.sin(angle2) * py1);
                y1 = (float) (-Math.sin(angle2) * px1 + Math.cos(angle2) * py1);
                canvas.drawLine(x + cx, y + cy, x + x1, y + y1, particleThinPaint);

                angle += angleDiff;
            }
            break;
        }
    }

}
 
Example 13
Source File: PointView.java    From WidgetCase with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    mPaint.setColor(mColor);
    if (mStyle == Point_Style.CIRCLE) {
        canvas.drawCircle(mPointWH / 2, mPointWH / 2, mPointWH / 2, mPaint);
    } else if (mStyle == Point_Style.SQUARE) {
        mPaint.setStrokeWidth(12);
        canvas.drawPoint(0, mPointWH / 2, mPaint);
    } else {

    }
}
 
Example 14
Source File: NinePointView.java    From ClockView with Apache License 2.0 5 votes vote down vote up
public void drawCyanPoint(Canvas canvas, Point point){
    String s =getKey(point);
    String [] strings =  s.split(":");
    int i= Integer.parseInt(strings[0]);
    int j=Integer.parseInt(strings[1]);
    pointPaint.setColor(Color.CYAN);
    canvas.drawPoint(mSquarewidth * (0.5f + i),mSquarewidth * (0.5f + j),pointPaint);
}
 
Example 15
Source File: ScannerView.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onDraw(final Canvas canvas) {
    if (frame == null)
        return;

    final long now = System.currentTimeMillis();

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

    final float[] point = new float[2];

    // draw mask darkened
    maskPaint.setColor(isResult ? maskResultColor : maskColor);
    canvas.drawRect(0, 0, width, frame.top, maskPaint);
    canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, maskPaint);
    canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, maskPaint);
    canvas.drawRect(0, frame.bottom + 1, width, height, maskPaint);

    if (isResult) {
        laserPaint.setColor(dotResultColor);
        laserPaint.setAlpha(160);

        dotPaint.setColor(dotResultColor);
    } else {
        laserPaint.setColor(laserColor);
        final boolean laserPhase = (now / 600) % 2 == 0;
        laserPaint.setAlpha(laserPhase ? 160 : 255);

        dotPaint.setColor(dotColor);

        // schedule redraw
        postInvalidateDelayed(LASER_ANIMATION_DELAY_MS);
    }

    canvas.drawRect(frame, laserPaint);

    // draw points
    for (final Iterator<Map.Entry<float[], Long>> i = dots.entrySet().iterator(); i.hasNext();) {
        final Map.Entry<float[], Long> entry = i.next();
        final long age = now - entry.getValue();
        if (age < DOT_TTL_MS) {
            dotPaint.setAlpha((int) ((DOT_TTL_MS - age) * 256 / DOT_TTL_MS));

            matrix.mapPoints(point, entry.getKey());
            canvas.drawPoint(point[0], point[1], dotPaint);
        } else {
            i.remove();
        }
    }
}
 
Example 16
Source File: DegreeSeekBar.java    From imsdk-android with MIT License 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.getClipBounds(mCanvasClipBounds);

    int zeroIndex = mPointCount / 2 + (0 - mCurrentDegrees) / 2;
    mPointPaint.setColor(mPointColor);
    for (int i = 0; i < mPointCount; i++) {

        if (i > zeroIndex - Math.abs(mMinReachableDegrees) / 2
                && i < zeroIndex + Math.abs(mMaxReachableDegrees) / 2
                && mScrollStarted) {
            mPointPaint.setAlpha(255);
        } else {
            mPointPaint.setAlpha(100);
        }

        if (i > mPointCount / 2 - 8
                && i < mPointCount / 2 + 8
                && i > zeroIndex - Math.abs(mMinReachableDegrees) / 2
                && i < zeroIndex + Math.abs(mMaxReachableDegrees) / 2) {
            if (mScrollStarted) {
                mPointPaint.setAlpha(Math.abs(mPointCount / 2 - i) * 255 / 8);
            } else {
                mPointPaint.setAlpha(Math.abs(mPointCount / 2 - i) * 100 / 8);
            }
        }

        canvas.drawPoint(mCanvasClipBounds.centerX() + (i - mPointCount / 2) * mPointMargin,
                mCanvasClipBounds.centerY(), mPointPaint);

        if (mCurrentDegrees != 0 && i == zeroIndex) {
            if (mScrollStarted) {
                mTextPaint.setAlpha(255);
            } else {
                mTextPaint.setAlpha(192);
            }
            mPointPaint.setStrokeWidth(4);
            canvas.drawPoint((mCanvasClipBounds.centerX() + (i - mPointCount / 2) * mPointMargin),
                    mCanvasClipBounds.centerY(), mPointPaint);
            mPointPaint.setStrokeWidth(2);
            mTextPaint.setAlpha(100);
        }
    }

    for (int i = -180; i <= 180; i += 15) {
        if (i >= mMinReachableDegrees && i <= mMaxReachableDegrees) {
            drawDegreeText(i, canvas, true);
        } else {
            drawDegreeText(i, canvas, false);
        }
    }

    mTextPaint.setTextSize(28f);
    mTextPaint.setAlpha(255);
    mTextPaint.setColor(mCenterTextColor);

    if (mCurrentDegrees >= 10) {
        canvas.drawText(mCurrentDegrees + suffix, getWidth() / 2 - mTextWidths[0], mBaseLine,
                mTextPaint);
    } else if (mCurrentDegrees <= -10) {
        canvas.drawText(mCurrentDegrees + suffix, getWidth() / 2 - mTextWidths[0] / 2 * 3, mBaseLine,
                mTextPaint);
    } else if (mCurrentDegrees < 0) {
        canvas.drawText(mCurrentDegrees + suffix, getWidth() / 2 - mTextWidths[0], mBaseLine,
                mTextPaint);
    } else {
        canvas.drawText(mCurrentDegrees + suffix, getWidth() / 2 - mTextWidths[0] / 2, mBaseLine,
                mTextPaint);
    }

    mTextPaint.setAlpha(100);
    mTextPaint.setTextSize(24f);
    mTextPaint.setColor(mTextColor);
    //画中心三角
    mCirclePaint.setColor(mCenterTextColor);
    canvas.drawPath(mIndicatorPath, mCirclePaint);
    mCirclePaint.setColor(mCenterTextColor);
}
 
Example 17
Source File: ScannerView.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onDraw(final Canvas canvas) {
	if (frame == null)
		return;

	final long now = System.currentTimeMillis();

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

	// draw mask darkened
	maskPaint.setColor(resultBitmap != null ? resultColor : maskColor);
	canvas.drawRect(0, 0, width, frame.top, maskPaint);
	canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, maskPaint);
	canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1,
			maskPaint);
	canvas.drawRect(0, frame.bottom + 1, width, height, maskPaint);

	if (resultBitmap != null) {
		canvas.drawBitmap(resultBitmap, null, frame, maskPaint);
	} else {
		// draw red "laser scanner" to show decoding is active
		final boolean laserPhase = (now / 600) % 2 == 0;
		laserPaint.setAlpha(laserPhase ? 160 : 255);
		canvas.drawRect(frame, laserPaint);

		// draw points
		final int frameLeft = frame.left;
		final int frameTop = frame.top;
		final float scaleX = frame.width() / (float) framePreview.width();
		final float scaleY = frame.height() / (float) framePreview.height();

		for (final Iterator<Map.Entry<ResultPoint, Long>> i = dots
				.entrySet().iterator(); i.hasNext();) {
			final Map.Entry<ResultPoint, Long> entry = i.next();
			final long age = now - entry.getValue();
			if (age < DOT_TTL_MS) {
				dotPaint.setAlpha((int) ((DOT_TTL_MS - age) * 256 / DOT_TTL_MS));

				final ResultPoint point = entry.getKey();
				canvas.drawPoint(frameLeft + (int) (point.getX() * scaleX),
						frameTop + (int) (point.getY() * scaleY), dotPaint);
			} else {
				i.remove();
			}
		}

		// schedule redraw
		postInvalidateDelayed(LASER_ANIMATION_DELAY_MS);
	}
}
 
Example 18
Source File: SecretMediaViewer.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas) {
    if (currentMessageObject == null || currentMessageObject.messageOwner.destroyTime == 0) {
        return;
    }

    canvas.drawCircle(getMeasuredWidth() - AndroidUtilities.dp(16 + 19), getMeasuredHeight() / 2, AndroidUtilities.dp(16), circlePaint);

    float progress;

    if (useVideoProgress) {
        if (videoPlayer != null) {
            long duration = videoPlayer.getDuration();
            long position = videoPlayer.getCurrentPosition();
            if (duration != C.TIME_UNSET && position != C.TIME_UNSET) {
                progress = 1.0f - (position / (float) duration);
            } else {
                progress = 1;
            }
        } else {
            progress = 1;
        }
    } else {
        long msTime = System.currentTimeMillis() + ConnectionsManager.getInstance(currentAccount).getTimeDifference() * 1000;
        progress = Math.max(0, destroyTime - msTime) / (destroyTtl * 1000.0f);
    }

    int x = getMeasuredWidth() - AndroidUtilities.dp(32 - 11 + 19);
    int y = (getMeasuredHeight() - AndroidUtilities.dp(14)) / 2 - AndroidUtilities.dp(0.5f);
    drawable.setBounds(x, y, x + AndroidUtilities.dp(10), y + AndroidUtilities.dp(14));
    drawable.draw(canvas);
    float radProgress = -360 * progress;
    canvas.drawArc(deleteProgressRect, -90, radProgress, false, afterDeleteProgressPaint);

    int count = particles.size();
    for (int a = 0; a < count; a++) {
        Particle particle = particles.get(a);
        particlePaint.setAlpha((int) (255 * particle.alpha));
        canvas.drawPoint(particle.x, particle.y, particlePaint);
    }

    double vx = Math.sin(Math.PI / 180.0 * (radProgress - 90));
    double vy = -Math.cos(Math.PI / 180.0 * (radProgress - 90));
    int rad = AndroidUtilities.dp(14);
    float cx = (float) (-vy * rad + deleteProgressRect.centerX());
    float cy = (float) (vx * rad + deleteProgressRect.centerY());
    for (int a = 0; a < 1; a++) {
        Particle newParticle;
        if (!freeParticles.isEmpty()) {
            newParticle = freeParticles.get(0);
            freeParticles.remove(0);
        } else {
            newParticle = new Particle();
        }
        newParticle.x = cx;
        newParticle.y = cy;

        double angle = (Math.PI / 180.0) * (Utilities.random.nextInt(140) - 70);
        if (angle < 0) {
            angle = Math.PI * 2 + angle;
        }
        newParticle.vx = (float) (vx * Math.cos(angle) - vy * Math.sin(angle));
        newParticle.vy = (float) (vx * Math.sin(angle) + vy * Math.cos(angle));

        newParticle.alpha = 1.0f;
        newParticle.currentTime = 0;

        newParticle.lifeTime = 400 + Utilities.random.nextInt(100);
        newParticle.velocity = 20.0f + Utilities.random.nextFloat() * 4.0f;
        particles.add(newParticle);
    }

    long newTime = System.currentTimeMillis();
    long dt = (newTime - lastAnimationTime);
    updateParticles(dt);
    lastAnimationTime = newTime;
    invalidate();
}
 
Example 19
Source File: CoordinateView.java    From ClockView with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.translate(getWidth()/2,getHeight()/2);
        canvas.drawPoint(0,0,mPaint);
        canvas.drawPoints(new float[]{getWidth()/2*0.8f,0,
                -getWidth()/2*0.8f,0,
        0,getHeight()/2*0.8f,
        0,-getHeight()/2*0.8f},mPaint);
        mPaint.setColor(Color.GRAY);
        canvas.drawLine(-getWidth()/2*0.8f,0,getWidth()/2*0.8f,0,mPaint);
        canvas.drawLine(0,-getHeight()/2*0.8f,0,getHeight()/2*0.8f,mPaint);
        mPaint.setColor(Color.BLACK);
        //绘制X轴箭头
        canvas.drawLines(new float[]{
                getWidth()/2*0.8f,0,getWidth()/2*0.8f*0.95f,-getWidth()/2*0.8f*0.05f,
                getWidth()/2*0.8f,0,getWidth()/2*0.8f*0.95f,getWidth()/2*0.8f*0.05f
        },mPaint);
//绘制Y轴箭头
        canvas.drawLines(new float[]{
                0,getHeight()/2*0.8f,getWidth()/2*0.8f*0.05f,getHeight()/2*0.8f-getWidth()/2*0.8f*0.05f,
                0,getHeight()/2*0.8f,-getWidth()/2*0.8f*0.05f,getHeight()/2*0.8f-getWidth()/2*0.8f*0.05f,
        },mPaint);
        Path path = new Path();
//        Bitmap bitmap =BitmapFactory.decodeResource(getResources(), R.mipmap.single);
//        Matrix matrix =new Matrix();
//        System.out.println(bitmap.getWidth()+"//"+bitmap.getHeight());
//        matrix.postScale(0.5f,0.5f);
//        Bitmap b = bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
//        path.addCircle(0,0,Math.min(bitmap.getWidth()/4,bitmap.getHeight()/4), Path.Direction.CW);
//        canvas.clipPath(path, Region.Op.INTERSECT);
//        canvas.drawBitmap(b,-bitmap.getWidth()/4,-bitmap.getHeight()/4,mPaint);
        mPaint.setStyle(Paint.Style.FILL);
        Path path1 = new Path();
        Path path2 = new Path();
        path1.moveTo(0,0);
        path1.arcTo(new RectF(-200,-200,200,200),240,60,false);
        path1.lineTo(0,0);
        path2.moveTo(0,0);
        path2.arcTo(new RectF(-300,-300,300,300),240,60,false);
        path2.lineTo(0,0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            path.op(path1,path2, Path.Op.XOR);
        }
        canvas.drawPath(path,mPaint);

    }
 
Example 20
Source File: HorTaperChart.java    From WidgetCase with Apache License 2.0 4 votes vote down vote up
/**
 * 绘制图形
 *
 * @param canvas
 * @param pf         开始绘制的点坐标
 * @param topY       顶部y值
 * @param paintColor 画笔颜色
 * @param xValue     对应的数据值 x
 * @param yValue     对应的数据值 y
 */
private void drawGraph(Canvas canvas, PointF pf, float topY, int paintColor, String xValue, float yValue) {
    // 设置画笔颜色
    mPaint.setColor(paintColor);
    // 直接参与画图的path
    Path path = new Path();
    // 图形中心点x轴值
    float centerX = pf.x + mLabelWidth / 2;

    // 左侧控制点
    PointF pfL = new PointF();
    pfL.x = pf.x + mQuadXSpace;
    pfL.y = pf.y - QUAD_Y_SPACE;

    if (topY >= pfL.y) { // 极端场景处理:数据值的y坐标>=控制点的y坐标
        if (topY >= mCanvasH - mOffBtm) { // 到底了,也就是数据为0的情况
            if (yValue > 0f) { // 总得有点东西显示吧
                // 控制点做调整
                pfL.y = mCanvasH - mOffBtm - QUAD_Y_SPACE / 5;
                topY = pfL.y - QUAD_Y_SPACE / 5;
            } else {
                topY = pfL.y = mCanvasH - mOffBtm;
            }
        } else {
            topY = topY - mOffBtm;
            pfL.y = topY + (mCanvasH - mOffBtm - pfL.y) / 2;
        }
    }

    TaperChartBean bean = new TaperChartBean();
    RectF rectF = new RectF(pf.x, topY, pf.x + mLabelWidth, pf.y);
    bean.setRectF(rectF);
    bean.setxValue(xValue);
    bean.setyValue(yValue);
    mList.add(bean);


    Path pathL = new Path();
    pathL.moveTo(pf.x, pf.y);
    pathL.quadTo(pfL.x, pfL.y, centerX, topY);
    pathL.lineTo(centerX, pf.y);

    PointF pfR = new PointF();
    pfR.x = pf.x + mLabelWidth - mQuadXSpace;
    pfR.y = pfL.y;
    // 右边图形路径
    Path pathR = new Path();
    pathR.moveTo(pf.x + mLabelWidth, pf.y);
    pathR.quadTo(pfR.x, pfR.y, centerX, topY);
    pathR.lineTo(centerX, pf.y);

    // path路径组合
    path.addPath(pathL);
    path.addPath(pathR);
    canvas.drawPath(path, mPaint);


    drawTopValue(canvas, yValue, topY, centerX);


    if (mIsShowDebug) {
        // 左 - 控制点
        canvas.drawPoint(pf.x + mQuadXSpace, pf.y - QUAD_Y_SPACE, mPointPaint);
        // 右 - 控制点
        canvas.drawPoint(pf.x + mLabelWidth - mQuadXSpace, pf.y - QUAD_Y_SPACE, mPointPaint);
        //绘制测量线,便于观察绘制的准确性
        canvas.drawLine(centerX, topY - DensityUtil.dp2px(5), centerX, pf.y, mLinePaint);
        // 绘制高度测量线,便于观察绘制的准确性
        mPaint.setStrokeWidth(1.5f);
        canvas.drawLine(mYMaxStrW + mLeftAxisLabelMargin + mPaint.getStrokeWidth(),
                topY, centerX, topY, mPaint);
    }
}