Java Code Examples for android.graphics.Canvas#drawPoints()
The following examples show how to use
android.graphics.Canvas#drawPoints() .
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: PrimitiveDrawer.java From Building-Android-UIs-with-Custom-Views with MIT License | 7 votes |
@Override protected void onDraw(Canvas canvas) { canvas.drawColor(BACKGROUND_COLOR); if (points == null) { points = new float[POINTS * 2]; for(int i = 0; i < POINTS; i++) { points[i * 2 ] = (float) Math.random() * getWidth(); points[i * 2 + 1] = (float) Math.random() * getHeight(); } } paint.setColor(0xffa0a0a0); paint.setStrokeWidth(4.f); paint.setStrokeCap(Paint.Cap.BUTT); canvas.drawLines(points, paint); paint.setColor(0xffffffff); paint.setStrokeWidth(10.f); paint.setStrokeCap(Paint.Cap.ROUND); canvas.drawPoints(points, paint); }
Example 2
Source File: BaseSlider.java From material-components-android with Apache License 2.0 | 6 votes |
private void drawTicks(@NonNull Canvas canvas) { float[] activeRange = getActiveRange(); int leftPivotIndex = pivotIndex(ticksCoordinates, activeRange[0]); int rightPivotIndex = pivotIndex(ticksCoordinates, activeRange[1]); // Draw inactive ticks to the left of the smallest thumb. canvas.drawPoints(ticksCoordinates, 0, leftPivotIndex * 2, inactiveTicksPaint); // Draw active ticks between the thumbs. canvas.drawPoints( ticksCoordinates, leftPivotIndex * 2, rightPivotIndex * 2 - leftPivotIndex * 2, activeTicksPaint); // Draw inactive ticks to the right of the largest thumb. canvas.drawPoints( ticksCoordinates, rightPivotIndex * 2, ticksCoordinates.length - rightPivotIndex * 2, inactiveTicksPaint); }
Example 3
Source File: RandomPointView.java From bither-android with Apache License 2.0 | 6 votes |
@Override public void draw(Canvas canvas) { removeCallbacks(redraw); canvas.drawARGB(0, 0, 0, 0); if (hasDots) { hasDots = false; postDelayed(redraw, DotsAppearInterval); } else { hasDots = true; int width = getWidth(); int height = getHeight(); float[] points = new float[PointCount * 2]; for (int i = 0; i < PointCount; i++) { points[i * 2] = random.nextFloat() * width; points[i * 2 + 1] = random.nextFloat() * height; } canvas.drawPoints(points, paint); postDelayed(redraw, DotsRemainTime); } super.draw(canvas); }
Example 4
Source File: CoordinateView.java From ClockView with Apache License 2.0 | 4 votes |
@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); }