/* * (non-Javadoc) * * @see android.view.View#onDraw(android.graphics.Canvas) */ @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int count = 3; if (viewFlow != null) { count = viewFlow.getViewsCount(); } float circleSeparation = 2 * radius + radius; // this is the amount the first circle should be offset to make the entire thing centered float centeringOffset = 0; int leftPadding = getPaddingLeft(); // Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { canvas.drawCircle( leftPadding + radius + (iLoop * circleSeparation) + centeringOffset, getPaddingTop() + radius, radius, mPaintInactive); } float cx = 0; if (flowWidth != 0) { // Draw the filled circle according to the current scroll cx = (currentScroll * (2 * radius + radius)) / flowWidth; } // The flow width has been upadated yet. Draw the default position canvas.drawCircle( leftPadding + radius + cx + centeringOffset, getPaddingTop() + radius, radius, mPaintActive); }
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(); } }
@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); }
@Override public void onDraw(Canvas canvas) { super.onDraw(canvas); int count = mPagesCount; if (count == 0) { return; } float cx = canvas.getWidth() >> 1; float cy = canvas.getHeight() >> 1; int totalCount = 2 * count - 1; int halfCount = totalCount / 2; float itemWithOffset = mIndicatorElementSize + mIndicatorElementSpacing; float halfItemWithOffset = mIndicatorElementSize / 2 + mIndicatorElementSpacing; float halfSize = mIndicatorElementSize / 2f; float halfSpacing = mIndicatorElementSpacing / 2f; float startX = cx - halfCount * (mIndicatorElementSize + mIndicatorElementSpacing); float top = cy - halfSize; float bottom = cy + halfSize; // if we have odd elements - need to set indicators in center if (totalCount % 2 != 0) { startX -= halfSize + halfSpacing; } int i; for (i = 0; i < totalCount; i++) { // skip empty spaces if (i % 2 != 0) { continue; } float left = startX + (mIndicatorElementSize + mIndicatorElementSpacing) * i; float right = left + mIndicatorElementSize; mElementBounds.set(left, top, right, bottom); mRenderer.draw(canvas, mElementBounds, mIndicatorPaint, false); } // multiply on 2 because there are spaces between elements float activeItemOffset = (mSelectedPosition + mScrolledOffset) * 2; float left = startX + (mIndicatorElementSize + mIndicatorElementSpacing) * activeItemOffset; float right = left + mIndicatorElementSize; mElementBounds.set(left, top, right, bottom); canvas.clipRect(mClipBounds); canvas.save(); canvas.rotate(ANGLE_360 * mScrolledOffset, mElementBounds.centerX(), mElementBounds.centerY()); mRenderer.draw(canvas, mElementBounds, mIndicatorSelectedPaint, true); canvas.restore(); if (mIsInfiniteScroll && mSelectedPosition == mPagesCount - 1) { // isInfinite && isEnd activeItemOffset = (1f - mScrolledOffset) * 2; left = mClipBounds.left - itemWithOffset * activeItemOffset + halfItemWithOffset; right = left + mIndicatorElementSize; mElementBounds.set(left, top, right, bottom); canvas.save(); canvas.rotate( ANGLE_360 * mScrolledOffset, mElementBounds.centerX(), mElementBounds.centerY()); mRenderer.draw(canvas, mElementBounds, mIndicatorSelectedPaint, true); canvas.restore(); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (!active) { return; } DownloadService downloadService = DownloadServiceImpl.getInstance(); if (downloadService != null && downloadService.getPlayerState() != PlayerState.STARTED) { return; } if (data == null) { return; } if (points == null || points.length < data.length * 4) { points = new float[data.length * 4]; } int w = getWidth(); int h = getHeight(); for (int i = 0; i < data.length - 1; i++) { points[i * 4] = w * i / (data.length - 1); points[i * 4 + 1] = h / 2 + ((byte) (data[i] + 128)) * (h / 2) / 128; points[i * 4 + 2] = w * (i + 1) / (data.length - 1); points[i * 4 + 3] = h / 2 + ((byte) (data[i + 1] + 128)) * (h / 2) / 128; } canvas.drawLines(points, paint); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final float ratio = calculateRatio(); float radius; // Darkening background canvas.drawColor(Color.argb((int) (200 * calculateRatio()), 0, 0, 0)); if (mRadiusAimed) { // Indicate that target radius is aimed. mPaint.setAlpha(35); radius = (float) Math.sqrt(mRadius / 70) * 70; canvas.drawCircle(mPoint[0], mPoint[1], radius, mPaint); } // Draw unlock circle mPaint.setAlpha((int) (255 * Math.pow(ratio, 0.33f))); radius = (float) Math.sqrt(mRadius / 50) * 50; canvas.drawCircle(mPoint[0], mPoint[1], radius, mPaint); // Draw unlock icon at the center of circle float scale = 0.5f + 0.5f * ratio; canvas.save(); canvas.translate( mPoint[0] - mDrawable.getMinimumWidth() / 2 * scale, mPoint[1] - mDrawable.getMinimumHeight() / 2 * scale); canvas.scale(scale, scale); mDrawable.draw(canvas); canvas.restore(); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(mBackgroundColor); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); }
@Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.GRAY); ballsManager.DrawBalls(canvas); super.onDraw(canvas); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // 计算组件绘制区域的宽高 viewH = getHeight() - getPaddingLeft() - getPaddingRight(); viewW = getWidth() - getPaddingTop() - getPaddingBottom(); int bottom = viewH; // 计算view底部距离 count = viewW / (rectW + 10); // 计算矩形的个数 10位矩形的间距 Rect rectw = new Rect(0, 0, viewW, bottom); // 外边框矩形 canvas.drawRect(rectw, rectK); // 循环绘制矩形 for (int i = 0; i < count; i++) { linearGradient = new LinearGradient( 0, 0, rectW, randomH(), new int[] {Color.BLUE, Color.YELLOW, Color.CYAN, Color.GREEN}, new float[] {0.3f, 0.5f, 0.7f, 0.9f}, Shader.TileMode.CLAMP); rectP.setShader(linearGradient); Rect rect = new Rect( (int) (viewW * 0.03f + i * (rectW + 10)), bottom - randomH(), (int) (viewW * 0.03f + (i) * (rectW + 10) + rectW), bottom); canvas.drawRect(rect, rectP); } canvas.save(); postInvalidateDelayed(300); }
@Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); // canvas canvas.drawLine( canvas.getWidth() / 2 - 200, canvas.getHeight() / 2 + 50, canvas.getWidth(), canvas.getHeight() / 2 + 50, red); // xaxis canvas.drawLine( canvas.getWidth() / 2 - 150, canvas.getHeight() / 2 - 800, canvas.getWidth() / 2 - 150, canvas.getHeight() / 2 + 100, red); // yaxis for (int i = 0; i <= 720; i++) // curve { int x = i + (canvas.getWidth() / 2 - 150); int y = (int) ((canvas.getHeight() / 2 + 50) + ((float) Math.sin(Math.toRadians(2 * i))) * 100); canvas.drawPoint(x, y, blue); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); for (ShapeDrawable shape : shapes) { shape.draw(canvas); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // 获取焦点改变背景色 int height = getHeight(); int width = getWidth(); int singleHeight = height / b.length; // 获取每一个字母的高度 for (int i = 0; i < b.length; i++) { paint.setColor(Color.rgb(33, 65, 98)); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true); paint.setTextSize(20 * (int) (displayMetrics != null ? (displayMetrics.density / 1.5) : 1)); // 选中的状态 if (i == choose) { paint.setColor(Color.parseColor("#3399ff")); paint.setFakeBoldText(true); } // x 坐标等于中间 - 字符串宽度的一半 float xPos = width / 2 - paint.measureText(b[i]) / 2; float yPos = singleHeight * i + singleHeight; canvas.drawText(b[i], xPos, yPos, paint); paint.reset(); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // TODO: consider storing these as member variables to reduce // allocations per draw cycle. int paddingLeft = getPaddingLeft(); int paddingTop = getPaddingTop(); int paddingRight = getPaddingRight(); int paddingBottom = getPaddingBottom(); int contentWidth = getWidth() - paddingLeft - paddingRight; int contentHeight = getHeight() - paddingTop - paddingBottom; // Draw the text. canvas.drawText( mExampleString, paddingLeft + (contentWidth - mTextWidth) / 2, paddingTop + (contentHeight + mTextHeight) / 2, mTextPaint); // Draw the example drawable on top of the text. if (mExampleDrawable != null) { mExampleDrawable.setBounds( paddingLeft, paddingTop, paddingLeft + contentWidth, paddingTop + contentHeight); mExampleDrawable.draw(canvas); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (matrix != null) { canvas.drawBitmap(bmp, matrix, paint); } }
@Override protected void onDraw(Canvas canvas) { for (int i = 0; i < pos_width_num; i++) { canvas.drawLine( startx + i * perL, starty, startx + i * perL, starty + perL * (pos_height_num - 1), paint); } for (int i = 0; i < pos_height_num; i++) { canvas.drawLine( startx, starty + i * perL, startx + perL * (pos_width_num - 1), starty + i * perL, paint); } if (cirX > 0 && cirY > 0) { canvas.drawCircle(cirX, cirY, perL / 2, paint); } if (showText.length() > 0) { canvas.drawText(showText, 60, 1000, paint); } super.onDraw(canvas); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Log.v(LOG_TAG, "Index Bar onDraw called"); drawRect(canvas); drawSections(canvas); }
protected void onDraw(Canvas canvas) { super.onDraw(canvas); // Draw the rim canvas.drawArc(circleBounds, 360, 360, false, rimPaint); // Draw the bar if (isSpinning) { canvas.drawArc(circleBounds, progress - 90, barLength, false, barPaint); } else { canvas.drawArc(circleBounds, -90, progress, false, barPaint); } // Draw the inner circle canvas.drawCircle( (circleBounds.width() / 2) + rimWidth + paddingLeft, (circleBounds.height() / 2) + rimWidth + paddingTop, circleRadius, circlePaint); // Draw the text (attempts to center it horizontally and vertically) int offsetNum = 0; for (String s : splitText) { float offset = textPaint.measureText(s) / 2; canvas.drawText( s, this.getWidth() / 2 - offset, this.getHeight() / 2 + (textSize * (offsetNum)) - ((splitText.length - 1) * (textSize / 2)), textPaint); offsetNum++; } }
protected void onDraw(Canvas canvas) { super.onDraw(canvas); Matrix matrix = new Matrix(); Paint paint = new Paint(); float x = 0; // 根据nowX设置背景,开或者关状态 if (nowX < (bg_on.getWidth() / 2)) { canvas.drawBitmap(bg_off, matrix, paint); // 画出关闭时的背景 } else { canvas.drawBitmap(bg_on, matrix, paint); // 画出打开时的背景 } if (onSlip) { // 是否是在滑动状态, if (nowX >= bg_on.getWidth()) // 是否划出指定范围,不能让滑块跑到外头,必须做这个判断 x = bg_on.getWidth() - slipper_btn.getWidth() / 2; // 减去滑块1/2的长度 else x = nowX - slipper_btn.getWidth() / 2; } else { if (nowStatus) { // 根据当前的状态设置滑块的x值 x = bg_on.getWidth() - slipper_btn.getWidth(); } else { x = 0; } } // 对滑块滑动进行异常处理,不能让滑块出界 if (x < 0) { x = 0; } else if (x > bg_on.getWidth() - slipper_btn.getWidth()) { x = bg_on.getWidth() - slipper_btn.getWidth(); } // 画出滑块 canvas.drawBitmap(slipper_btn, x, 0, paint); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (this.isVisible && this.bitmap != null) { Point tmp = this.mMapViewGroup.getMapView().CoordinatesToPixel(this.Cx, this.Cy); float px = tmp.x + this.OffsetX; float py = tmp.y + this.OffsetY; // Rect rect=new // Rect((int)px-this.buffer,(int)py-this.buffer,(int)px+bitmap.getWidth()+this.buffer,(int)py+bitmap.getHeight()+this.buffer); // Log.d("旋转标注",""+px+";"+py+"___"+this.Cx+";"+this.Cy); // canvas.drawBitmap(bitmap,px,py,null); Paint paint = new Paint(); if (this.Cx > 0 && this.Cy > 0 && this.Cx2 > 0 && this.Cy2 > 0 && (this.Cx != this.Cx2 || this.Cy != this.Cy2)) { this.Degree = (float) (Math.atan2(this.Cx2 - this.Cx, this.Cy2 - this.Cy) * 180 / Math.PI); } matrix.setRotate(this.Degree, 0 - this.OffsetX, 0 - this.OffsetY); // matrix.setTranslate(px, py); // matrix.postRotate(this.Degree, 0-this.OffsetX, 0-this.OffsetY); matrix.postTranslate(px, py); canvas.drawBitmap(bitmap, matrix, paint); } }
@Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); canvas.drawColor(Color.BLACK); Paint textPaint = new Paint(); textPaint.setARGB(50, 254, 100, 45); textPaint.setTextAlign(Align.CENTER); textPaint.setTextSize(50); textPaint.setTypeface(font); canvas.drawText("Ajith is ..", canvas.getWidth() / 2, 200, textPaint); canvas.drawBitmap(star, (canvas.getWidth() / 2), y, null); if (y < canvas.getHeight()) { y += 10; } else { y = 0; } Rect middlRect = new Rect(); middlRect.set(0, 400, canvas.getWidth(), 550); Paint ourBlue = new Paint(); ourBlue.setColor(Color.BLUE); canvas.drawRect(middlRect, ourBlue); invalidate(); }
@Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas); canvas.drawPath(path, fillPaint); canvas.drawPath(path, strokePaint); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return; } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } final int paddingLeft = getPaddingLeft(); final float pageWidth = (getWidth() - paddingLeft - getPaddingRight()) / (1f * count); final float left = paddingLeft + pageWidth * (mCurrentPage + mPositionOffset); final float right = left + pageWidth; final float top = getPaddingTop(); final float bottom = getHeight() - getPaddingBottom(); canvas.drawRect(left, top, right, bottom, mPaint); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); if (IsPaint) canvas.drawPath(mPath, mPaint); else canvas.drawPath(mPath, mEraserPaint); }
protected void onDraw(Canvas canvas) { mCalendar = Calendar.getInstance(); super.onDraw(canvas); int minute = mCalendar.get(Calendar.MINUTE); // 得到当前分钟数 int hour = mCalendar.get(Calendar.HOUR); // 得到当前小时数 int sec = mCalendar.get(Calendar.SECOND); // 得到当前秒数 float minuteDegree = minute / 60f * 360; // 得到分针旋转的角度 canvas.save(); canvas.rotate(minuteDegree, width / 2, height / 2); canvas.drawLine(width / 2, height / 2 - 250, width / 2, height / 2 + 40, mPaintMinute); canvas.restore(); float hourDegree = (hour * 60 + minute) / 12f / 60 * 360; // 得到时钟旋转的角度 canvas.save(); canvas.rotate(hourDegree, width / 2, height / 2); canvas.drawLine(width / 2, height / 2 - 200, width / 2, height / 2 + 30, mPaintHour); canvas.restore(); float secDegree = sec / 60f * 360; // 得到秒针旋转的角度 canvas.save(); canvas.rotate(secDegree, width / 2, height / 2); canvas.drawLine(width / 2, height / 2 - 300, width / 2, height / 2 + 40, mPaintSec); canvas.restore(); }
@Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); Matrix matrix = new Matrix(); Paint paint = new Paint(); float x; if (onSlip) { if (nowX >= bg_on.getWidth()) { x = bg_on.getWidth() - slip_btn.getWidth() / 2; } else { x = nowX - slip_btn.getWidth() / 2; } } else { if (nowChoose) { x = btn_On.left; } else { x = btn_Off.left; } } if (nowX < (bg_on.getWidth() / 2)) { canvas.drawBitmap(bg_off, matrix, paint); } else { canvas.drawBitmap(bg_on, matrix, paint); } if (x < 0) { x = 0; } else if (x > bg_on.getWidth() - slip_btn.getWidth()) { x = bg_on.getWidth() - slip_btn.getWidth(); } canvas.drawBitmap(slip_btn, x, 0, paint); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); for (ExplosionAnimator animator : explosionAnimators) { animator.draw(canvas); } }
/** 重写这个方法 */ @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // 获取焦点改变背景颜色. int height = getHeight(); // 获取对应高度 1596 samsung s4 int width = getWidth(); // 获取对应宽度 int singleHeight = height / b.length; // 获取每一个字母的高度 for (int i = 0; i < b.length; i++) { paint.setColor(Color.rgb(33, 65, 98)); // 右边字母导航条的颜色 // paint.setColor(Color.WHITE); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true); paint.setTextSize(height / 320 * 10); // 根据屏幕分辨率设置字体大小 // 选中的状态 if (i == choose) { paint.setColor(Color.parseColor("#3399ff")); paint.setFakeBoldText(true); } // x坐标等于中间-字符串宽度的一半. float xPos = width / 2 - paint.measureText(b[i]) / 2; float yPos = singleHeight * i + singleHeight; canvas.drawText(b[i], xPos, yPos, paint); paint.reset(); // 重置画笔 } }
/** 这个方法会在初始化后背调用一次,invaildate()的时候会被调用 */ @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint(); // 设置一个笔 paint.setAntiAlias(true); // 设置没有锯齿 paint.setColor(Color.RED); // 设置笔的颜色 canvas.drawCircle(paintX, paintY, radius, paint); // 距离画圆 paint.setColor(Color.BLUE); paint.setStrokeWidth(4); paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.RED); // 设置笔的颜色 paint.setTextSize(50); canvas.drawLines(points1, paint); if (switch_info == true) { canvas.drawText(String.valueOf(ori_acc), 10, 50, paint); canvas.drawText(String.valueOf(orientationA), 300, 50, paint); canvas.drawText(String.valueOf(ori_increment), 600, 50, paint); canvas.drawText(String.valueOf(mean_oriacc), 10, 100, paint); canvas.drawText(String.valueOf(mean_orisensor), 300, 100, paint); canvas.drawText(String.valueOf(Step), 10, 150, paint); canvas.drawText(String.valueOf(distance), 300, 150, paint); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawRect( strokeWidth, strokeWidth, rectSize - strokeWidth, rectSize - strokeWidth, paint); }
@Override protected void onDraw(Canvas canvas) { for (int i = 0; i < mStvorki; i++) { mList.get(i).drawBit(canvas, mValue); } super.onDraw(canvas); }