/** Draws the main menu */ public void drawMainMenu() { background(157, 184, 51); // "tetris" int tetrisR = (int) (255.0 * Math.sin(System.currentTimeMillis() / 50.0) + 255); int tetrisG = (int) (255.0 * Math.cos(System.currentTimeMillis() / 50.0) + 255); int tetrisB = (int) (100 + 100.0 * Math.cos(System.currentTimeMillis() / 50)); fill(tetrisR, tetrisG, tetrisB); paint.setColor(Color.WHITE); paint.setTextSize(36); currCanvas.drawText("Delaze", 135.0f / 400 * width / 2, 180.0f / 400 * height, paint); currCanvas.drawText( "Delaze", 135.0f / 400 * width / 2 + width / 2.0f, 180.0f / 400 * height, paint); // Regular mode fill(255, 213, 0); currCanvas.drawRect( 114.0f / 400 * width / 2, 167.0f / 400 * height, (114 + 182) / 400.0f * width / 2, (167 + 41) / 400.0f * height, paint); currCanvas.drawRect( 114.0f / 400 * width / 2 + width / 2.0f, 167 / 400 * height, (114 + 182) / 400.0f * width / 2 + width / 2.0f, (167 + 41) / 400.0f * height, paint); paint.setTextSize(24); paint.setColor(Color.CYAN); currCanvas.drawText("Click to begin", 127.0f / 400 * width / 2, 220.0f / 400 * height, paint); currCanvas.drawText( "Click to begin", 127.0f / 400 * width / 2 + width / 2.0f, 220.0f / 400 * height, paint); }
/** * @param bitmap * @return */ public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) { final int reflectionGap = 4; int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1); Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, h / 2, w, h / 2, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(w, (h + h / 2), Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(bitmap, 0, 0, null); Paint deafalutPaint = new Paint(); canvas.drawRect(0, h, w, h + reflectionGap, deafalutPaint); canvas.drawBitmap(reflectionImage, 0, h + reflectionGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient( 0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); paint.setShader(shader); // Set the Transfer mode to be porter duff and destination in paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); // Draw a rectangle using the paint with our linear gradient canvas.drawRect(0, h, w, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; }
@Override public void onDraw(Canvas canvas, Rect bounds) { is24Hour = df.is24HourFormat(context); seconds = getSeconds(); cal = Calendar.getInstance(); width = bounds.width() / 2; height = bounds.height() / 2; canvas.drawRect(0, 0, width * 2, height * 2, mBackgroundPaint); if (!ambientMode) { canvas.drawRect(0, height + 45, width * 2, height * 2, mTilePaint); if (seconds - 447 > -620) { canvas.drawBitmap(scale, seconds - 447, height + 60, mScalePaint); } else { canvas.drawBitmap(scale, seconds + 753, height + 60, mScalePaint); } canvas.drawBitmap(scale, seconds + 153, height + 60, mScalePaint); canvas.rotate(45, width, height); canvas.drawRect(width + 15, height + 15, width + 45, height + 45, mArrowPaint); canvas.rotate(-45, width, height); canvas.drawRect(width - 30, height + 15, width + 30, height + 45, mBorderPaint); } canvas.drawText(getHours(), HOUR_X, HOUR_MINUTE_Y, mHourPaint); canvas.drawText(getMinutes(), MINUTE_X, HOUR_MINUTE_Y, mMinutePaint); canvas.drawText(getDate(), width - mDatePaint.getStrokeWidth() / 2, DATE_Y, mDatePaint); canvas.drawText(getAmPm(), TIME_X, TIME_Y, mTimePaint); if (battery) { canvas.drawText(batteryLevel, BATTERY_X, TIME_Y, mBatteryPaint); } }
/** 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.range_seekbar_track)); 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.range_seekbar_limits_color)); 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); }
private void drawBackground(Canvas canvas, Rect bitmapRect) { final float left = Edge.LEFT.getCoordinate(); final float top = Edge.TOP.getCoordinate(); final float right = Edge.RIGHT.getCoordinate(); final float bottom = Edge.BOTTOM.getCoordinate(); /*- ------------------------------------- | top | ------------------------------------- | | | | | | | | | left | | right | | | | | | | | | ------------------------------------- | bottom | ------------------------------------- */ // Draw "top", "bottom", "left", then "right" quadrants. canvas.drawRect(bitmapRect.left, bitmapRect.top, bitmapRect.right, top, mBackgroundPaint); canvas.drawRect(bitmapRect.left, bottom, bitmapRect.right, bitmapRect.bottom, mBackgroundPaint); canvas.drawRect(bitmapRect.left, top, left, bottom, mBackgroundPaint); canvas.drawRect(right, top, bitmapRect.right, bottom, mBackgroundPaint); }
@Override protected void onDraw(Canvas canvas) { int i = 1; if (percentList != null && !percentList.isEmpty()) { for (Float f : percentList) { rect.set( BAR_SIDE_MARGIN * i + barWidth * (i - 1), topMargin, (BAR_SIDE_MARGIN + barWidth) * i, getHeight() - bottomTextHeight - TEXT_TOP_MARGIN); canvas.drawRect(rect, bgPaint); rect.set( BAR_SIDE_MARGIN * i + barWidth * (i - 1), topMargin + (int) ((getHeight() - topMargin) * percentList.get(i - 1)), (BAR_SIDE_MARGIN + barWidth) * i, getHeight() - bottomTextHeight - TEXT_TOP_MARGIN); canvas.drawRect(rect, fgPaint); i++; } } if (bottomTextList != null && !bottomTextList.isEmpty()) { i = 1; for (String s : bottomTextList) { canvas.drawText( s, BAR_SIDE_MARGIN * i + barWidth * (i - 1) + barWidth / 2, getHeight() - bottomTextDescent, textPaint); i++; } } }
private void drawTail(Canvas canvas, long timeDiff, long currentTime) { final int step = 255 / tail.length; int alpha = 255; for (Rect tailPoint : tail) { fillPaint.setAlpha(alpha); canvas.drawRect(bounds, fillPaint); canvas.drawRect(tailPoint, fillPaint); alpha -= step; } fillPaint.setAlpha(255); taleUpdateTime = 0; Rect first = tail[tail.length - 1]; System.arraycopy(tail, 0, tail, 1, tail.length - 1); tail[0] = first; tail[0].offsetTo(bounds.left, bounds.top); // if (taleUpdateTime > 50) { // taleUpdateTime = 0; // Rect first = tail[tail.length - 1]; // System.arraycopy(tail, 0, tail, 1, tail.length - 1); // tail[0] = first; // tail[0].offsetTo(bounds.left, bounds.top); // } else { // taleUpdateTime += timeDiff; // } }
protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mapView == null || mapView.isClickable()) { return; } if (doMeasureMode) { int cWidth = canvas.getWidth(); canvas.drawPath(measurePath, measurePaint); int upper = 70; int delta = 5; measureTextPaint.getTextBounds(distanceString, 0, distanceString.length(), rect); int textWidth = rect.width(); int textHeight = rect.height(); int x = cWidth / 2 - textWidth / 2; canvas.drawText(distanceString, x, upper, measureTextPaint); String distanceText = String.valueOf((int) measuredDistance); // String distanceText = distanceText((int) measuredDistance, imperial, nautical); measureTextPaint.getTextBounds(distanceText, 0, distanceText.length(), rect); textWidth = rect.width(); x = cWidth / 2 - textWidth / 2; canvas.drawText(distanceText, x, upper + delta + textHeight, measureTextPaint); if (GPLog.LOG_HEAVY) GPLog.addLogEntry(this, "Drawing measure path text: " + upper); // $NON-NLS-1$ } else if (doInfoMode) { canvas.drawRect(rect, infoRectPaintFill); canvas.drawRect(rect, infoRectPaintStroke); } }
@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); }
/** * 生成带镜面倒影的bitmap * * @param originBitmap * @return bitmapWithReflection * @author 考虑到体验的流畅感,以及Gallery的加载机制缺陷,不推荐使用此方法。 仅保留此代码段作备用和记录 by Felix */ public Bitmap getReflection(Bitmap image) { final int reflectionGap = 4; Bitmap originalImage = image; int width = originalImage.getWidth(); int height = originalImage.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1); Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height / 2, width, height / 2, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(originalImage, 0, 0, null); Paint deafaultPaint = new Paint(); canvas.drawRect(0, height, width, height + reflectionGap, deafaultPaint); canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient( 0, originalImage.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x80ffffff, 0x00ffffff, TileMode.CLAMP); paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; }
public static Bitmap capture( View view, float width, float height, boolean scroll, Bitmap.Config config) { if (!view.isDrawingCacheEnabled()) view.setDrawingCacheEnabled(true); Bitmap bitmap = Bitmap.createBitmap((int) width, (int) height, config); bitmap.eraseColor(Color.WHITE); Canvas canvas = new Canvas(bitmap); int left = view.getLeft(); int top = view.getTop(); if (scroll) { left = view.getScrollX(); top = view.getScrollY(); } int status = canvas.save(); canvas.translate(-left, -top); float scale = width / view.getWidth(); canvas.scale(scale, scale, left, top); view.draw(canvas); canvas.restoreToCount(status); Paint alphaPaint = new Paint(); alphaPaint.setColor(Color.TRANSPARENT); canvas.drawRect(0f, 0f, 1f, height, alphaPaint); canvas.drawRect(width - 1f, 0f, width, height, alphaPaint); canvas.drawRect(0f, 0f, width, 1f, alphaPaint); canvas.drawRect(0f, height - 1f, width, height, alphaPaint); canvas.setBitmap(null); return bitmap; }
public void drawBoardObjects(Canvas canvas) { for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { // blocks if (boardStatus[i][j] == -1) { paint.setColor(Color.DKGRAY); canvas.drawRect(gridPoints[i][j], paint); } // colored grids if (boardStatus[i][j] > 0) { paint.setColor(ColorList.getColor(boardStatus[i][j], 0)); paint.setAlpha(150); canvas.drawRect(gridPoints[i][j], paint); } // balls if (balls.containsKey(new Point(i, j)) && !isMoving) { paint.setColor(ColorList.getColor(balls.get(new Point(i, j)), 0)); canvas.drawCircle( gridPoints[i][j].centerX(), gridPoints[i][j].centerY(), gridSize / 3, paint); } } } }
protected void onDraw(Canvas canvas) { this; JVM INSTR monitorenter ; c.set(getThumbOffset(), getHeight() / 2 - f / 4, getWidth() - getThumbOffset(), getHeight() / 2 + f / 4); d.setColor(0xff888888); canvas.drawRect(c, d); int i = getWidth(); int j = getHeight(); canvas.drawBitmap(e, i / 2 - e.getWidth() / 2, j / 2 - e.getHeight() / 2, null); if (getProgress() > 500) { c.set(getWidth() / 2, getHeight() / 2 - f / 2, (getWidth() / 2 + (getWidth() * (getProgress() - 500)) / 1000) - ((getProgress() - 500) * getThumbOffset()) / 500, getHeight() / 2 + f / 2); d.setColor(g.getResources().getColor(0x7f0f0007)); canvas.drawRect(c, d); } if (getProgress() < 500) { c.set((getWidth() / 2 - (getWidth() * (500 - getProgress())) / 1000) + ((500 - getProgress()) * getThumbOffset()) / 500, getHeight() / 2 - f / 2, getWidth() / 2, getHeight() / 2 + f / 2); d.setColor(g.getResources().getColor(0x7f0f0007)); canvas.drawRect(c, d); } super.onDraw(canvas); this; JVM INSTR monitorexit ; return; canvas; throw canvas; }
@Override public void draw(Canvas canvas) { super.draw(canvas); // draw progress bars canvas.drawRect(progressBar, progressPaint); canvas.drawRect(playedBar, playedPaint); // draw scrubber and timers if (showScrubber) { canvas.drawBitmap(scrubber, scrubberLeft, scrubberTop, null); } if (showTimes) { canvas.drawText( stringForTime(currentTime), timeBounds.width() / 2 + getPaddingLeft(), timeBounds.height() + vPaddingInPx / 2 + scrubberPadding + 1, timeTextPaint); canvas.drawText( stringForTime(totalTime), getWidth() - getPaddingRight() - timeBounds.width() / 2, timeBounds.height() + vPaddingInPx / 2 + scrubberPadding + 1, timeTextPaint); } }
/** * Draw the old and new swatches. * * @param canvas */ private void drawSwatches(Canvas canvas) { float[] hsv = new float[3]; mText.setTextSize(16); // Draw the original swatch canvas.drawRect(mOldSwatchRect, mSwatchOld); Color.colorToHSV(mOriginalColor, hsv); // if (UberColorPickerDialog.isGray(mColor)) //Don't need this right here, but imp't to note // hsv[1] = 0; if (hsv[2] > .5) mText.setColor(Color.BLACK); canvas.drawText( "Revert", mOldSwatchRect.left + SWATCH_WIDTH / 2 - mText.measureText("Revert") / 2, mOldSwatchRect.top + 16, mText); mText.setColor(Color.WHITE); // Draw the new swatch canvas.drawRect(mNewSwatchRect, mSwatchNew); if (mHSV[2] > .5) mText.setColor(Color.BLACK); canvas.drawText( "Accept", mNewSwatchRect.left + SWATCH_WIDTH / 2 - mText.measureText("Accept") / 2, mNewSwatchRect.top + 16, mText); mText.setColor(Color.WHITE); mText.setTextSize(TEXT_SIZE); }
@Override protected void onDraw(Canvas canvas) { final int height = getHeight(); final int childCount = getChildCount(); final SlidingTabLayout.TabColorizer tabColorizer = mCustomTabColorizer != null ? mCustomTabColorizer : mDefaultTabColorizer; // Thick colored underline below the current selection if (childCount > 0) { View selectedTitle = getChildAt(mSelectedPosition); int left = selectedTitle.getLeft(); int right = selectedTitle.getRight(); int color = tabColorizer.getIndicatorColor(mSelectedPosition); if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) { int nextColor = tabColorizer.getIndicatorColor(mSelectedPosition + 1); if (color != nextColor) { color = blendColors(nextColor, color, mSelectionOffset); } // Draw the selection partway between the tabs View nextTitle = getChildAt(mSelectedPosition + 1); left = (int) (mSelectionOffset * nextTitle.getLeft() + (1.0f - mSelectionOffset) * left); right = (int) (mSelectionOffset * nextTitle.getRight() + (1.0f - mSelectionOffset) * right); } mSelectedIndicatorPaint.setColor(color); canvas.drawRect( left, height - mSelectedIndicatorThickness, right, height, mSelectedIndicatorPaint); } // Thin underline along the entire bottom edge canvas.drawRect(0, height - mBottomBorderThickness, getWidth(), height, mBottomBorderPaint); }
/** * Draw debug information on the Canvas * * @param c Canvas to draw to */ private void drawDebugInfo(Canvas c) { paint.setColor(Color.WHITE); paint.setTextSize(10); // Draw FPS c.drawText("FPS: " + dispFps, screenDims.x - 40, 10, paint); // Draw last touch c.drawText("Last touch: " + lastTouch.x + "," + lastTouch.y, screenDims.x - 95, 25, paint); // Draw worker/renderer ratio bar if (renderTime != 0) { paint.setColor(resources.getColor(android.R.color.holo_green_dark)); ratioBarOuter.set(screenDims.x - 300, 30, screenDims.x, 40); c.drawRect(ratioBarOuter, paint); float percentage = ((float) updateTime / (float) renderTime); percentage *= 100.0F; int workerBarWidth = (int) percentage; workerBarWidth *= 3; // For 100px on a 300px bar // report("drawDebugInfo()", "W/R: " + (updateTime) + "/" + (renderTime) + " = " + // percentage + " for " + workerBarWidth + " px width"); paint.setColor(resources.getColor(android.R.color.holo_green_light)); ratioBarWorker.set(screenDims.x - 300, 30, (screenDims.x - 300) + workerBarWidth, 40); c.drawRect(ratioBarWorker, paint); } // Draw log console if (console == null) console = new Console(); console.draw(c); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return; } final int height = getHeight(); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates between current and // next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } // draw indicator line rectPaint.setColor(indicatorColor); canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); }
@Override protected void drawBackground(Canvas canvas) { int i = 0; int offset = 0; r.top = DAY_SEPARATOR_INNER_WIDTH; r.bottom = mHeight; if (mShowWeekNum) { i++; offset++; } if (!mOddMonth[i]) { while (++i < mOddMonth.length && !mOddMonth[i]) ; r.right = computeDayLeftPosition(i - offset); r.left = 0; p.setColor(mMonthBGOtherColor); canvas.drawRect(r, p); // compute left edge for i, set up r, draw } else if (!mOddMonth[(i = mOddMonth.length - 1)]) { while (--i >= offset && !mOddMonth[i]) ; i++; // compute left edge for i, set up r, draw r.right = mWidth; r.left = computeDayLeftPosition(i - offset); p.setColor(mMonthBGOtherColor); canvas.drawRect(r, p); } if (mHasToday) { p.setColor(mMonthBGTodayColor); r.left = computeDayLeftPosition(mTodayIndex); r.right = computeDayLeftPosition(mTodayIndex + 1); canvas.drawRect(r, p); } }
private void drawPitch(Canvas canvas) { int step = 40; // Pixels per 5 degree step canvas.translate(0, (int) (pitch * (step / 5))); canvas.rotate(-(int) roll); // Draw the background box - FIXME, doesn't yet work - WTF // groundGradient.setBounds(-width, 0, width, 2 * height); // groundGradient.draw(canvas); canvas.drawRect(-width, 0, width, 5 * height /* Go plenty low */, ground); canvas.drawRect(-width, -5 * height /* Go plenty high */, width, 0, sky); canvas.drawRect(-width, -20, width, 20, whitebar); // Draw the vertical grid canvas.drawLine(-width, 0, width, 0, white); // canvas.f for (int i = -step * 20; i < step * 20; i += step) { if (i != 0) { if (i % (2 * step) == 0) { canvas.drawLine(-50, i, 50, i, white); canvas.drawText((5 * i / -step) + "", -90, i + 5, white); } else canvas.drawLine(-20, i, 20, i, white); } } }
@Override public void onDraw(Canvas canvas) { super.onDraw(canvas); if (mService.isScrimSrcModeEnabled()) { // We need to ensure that our window is always drawn fully even when we have paddings, // since we simulate it to be opaque. int paddedBottom = getHeight() - getPaddingBottom(); int paddedRight = getWidth() - getPaddingRight(); if (getPaddingTop() != 0) { canvas.drawRect(0, 0, getWidth(), getPaddingTop(), mTransparentSrcPaint); } if (getPaddingBottom() != 0) { canvas.drawRect(0, paddedBottom, getWidth(), getHeight(), mTransparentSrcPaint); } if (getPaddingLeft() != 0) { canvas.drawRect(0, getPaddingTop(), getPaddingLeft(), paddedBottom, mTransparentSrcPaint); } if (getPaddingRight() != 0) { canvas.drawRect( paddedRight, getPaddingTop(), getWidth(), paddedBottom, mTransparentSrcPaint); } } if (DEBUG) { Paint pt = new Paint(); pt.setColor(0x80FFFF00); pt.setStrokeWidth(12.0f); pt.setStyle(Paint.Style.STROKE); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // draw progress bars canvas.drawRect(mProgressBar, mProgressPaint); mSecondaryProgressExt.draw(canvas, mProgressBar); canvas.drawRect(mPlayedBar, mPlayedPaint); // draw scrubber and timers if (mShowScrubber) { canvas.drawBitmap(mScrubber, mScrubberLeft, mScrubberTop, null); } if (mShowTimes) { canvas.drawText( stringForTime(mCurrentTime), mTimeBounds.width() / 2 + getPaddingLeft(), mTimeBounds.height() + mVPaddingInPx / 2 + mScrubberPadding + 1 + mLayoutExt.getTimeOffset(), mTimeTextPaint); canvas.drawText( stringForTime(mTotalTime), getWidth() - getPaddingRight() - mTimeBounds.width() / 2, mTimeBounds.height() + mVPaddingInPx / 2 + mScrubberPadding + 1 + mLayoutExt.getTimeOffset(), mTimeTextPaint); } mInfoExt.draw(canvas, mLayoutExt.getInfoBounds(this, mTimeBounds)); }
@Override protected synchronized void onDraw(Canvas canvas) { super.onDraw(canvas); float width = getLayoutParams().width - (thumb.getWidth() / 2); float height = getLayoutParams().height; float line = 2 * (height / 4); float fourty = height / 4; // int step = Math.round(width/diriv); Paint p = new Paint(); Paint e = new Paint(); p.setColor(dis); e.setColor(en); canvas.drawRect(0, line - 1, width, line + 1, p); canvas.drawRect(0, line - 1, offset, line + 1, e); /* if(isScroll) { int ii = offsetToTime(0,Math.round(offset)); if (!isUp && ii>=480) minus -= 1; else if (!isUp && offset == 0 && minus < 0) minus += 1; } */ boolean isSmall = true; int beg = 1; if (minus < 0) beg = minus; if (thumb != null) { if (offset > width) offset = width; if (offset < 0) offset = 0; canvas.drawBitmap(thumb, offset, (height / 2) - fourty, e); } int offtime = offsetToTime(minus, Math.round(offset)); Log.i("onDraw", "" + offtime + " offset:" + offset + " minus:" + minus); if (onChange != null) onChange.onTimeChanged(offtime); invalidate(); }
public static Bitmap drawTextToBitmap(Context mContext, Bitmap bitmap, Location location) { Resources resources = mContext.getResources(); float scale = resources.getDisplayMetrics().density; Bitmap.Config bitmapConfig = bitmap.getConfig(); if (bitmapConfig == null) { bitmapConfig = Bitmap.Config.ARGB_8888; } bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(mContext.getResources().getColor(R.color.white)); paint.setTextSize((int) 13); paint.setStyle(Paint.Style.FILL_AND_STROKE); Paint paint1 = new Paint(Paint.ANTI_ALIAS_FLAG); paint1.setColor(mContext.getResources().getColor(R.color.green)); String text = getText(location); Paint.FontMetrics fm = new Paint.FontMetrics(); paint1.setTextAlign(Paint.Align.CENTER); paint1.getFontMetrics(fm); int width = bitmap.getWidth(); int height = bitmap.getHeight(); if (height > width) { canvas.drawRect(0, height - 40, height - 40, height, paint1); canvas.drawText(text, 5, height - 10, paint); } else { canvas.drawRect(0, 0, width, 40, paint1); canvas.drawText(text, 5, 25, paint); } Log.i(LOGTAG, "Check: Text drawn on bitmap"); return bitmap; }
protected void draw(Canvas canvas) { canvas.save(); Path path = new Path(); outlinePaint.setStrokeWidth(outlineWidth); if (!hasFocus()) { outlinePaint.setColor(Color.BLACK); canvas.drawRect(drawRect, outlinePaint); } else { Rect viewDrawingRect = new Rect(); viewContext.getDrawingRect(viewDrawingRect); path.addRect(new RectF(drawRect), Path.Direction.CW); outlinePaint.setColor(highlightColor); if (isClipPathSupported(canvas)) { canvas.clipPath(path, Region.Op.DIFFERENCE); canvas.drawRect(viewDrawingRect, outsidePaint); } else { drawOutsideFallback(canvas); } canvas.restore(); canvas.drawPath(path, outlinePaint); if (showThirds) { drawThirds(canvas); } if (handleMode == HandleMode.Always || (handleMode == HandleMode.Changing && modifyMode == ModifyMode.Grow)) { drawHandles(canvas); } } }
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; }
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); }
protected void onDraw(Canvas canvas) { canvas.drawRGB(255, 255, 255); paint.setColor(Color.RED); canvas.drawLine(0, 0, canvas.getWidth() - 1, canvas.getHeight() - 1, paint); paint.setStyle(Style.STROKE); paint.setColor(0xff00ff00); canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, 40, paint); paint.setStyle(Style.FILL); paint.setColor(0x770000ff); canvas.drawRect( canvas.getWidth() / 4, canvas.getHeight() / 4, (canvas.getWidth() / 4) + 100, (canvas.getHeight() / 4) + 50, paint); paint.setStyle(Style.FILL_AND_STROKE); paint.setColor(0x55ff0000); canvas.drawRect( 3 * (canvas.getWidth() / 4), 3 * (canvas.getHeight() / 4), 3 * (canvas.getWidth() / 4) + 50, 3 * (canvas.getHeight() / 4) + 25, paint); invalidate(); }
@Override protected void onDraw(Canvas canvas) { int translatedHue = 255 - (int) (mCurrentHue * 255 / 360); // Display all the colors of the hue bar with lines for (int x = 0; x < 256; x++) { // If this is not the current selected hue, display the actual color if (translatedHue != x) { mPaint.setColor(mHueBarColors[x]); mPaint.setStrokeWidth(1); } else // else display a slightly larger black line { mPaint.setColor(Color.BLACK); mPaint.setStrokeWidth(3); } canvas.drawLine(x + 10, 0, x + 10, 40, mPaint); } // Display the main field colors using LinearGradient for (int x = 0; x < 256; x++) { int[] colors = new int[2]; colors[0] = mMainColors[x]; colors[1] = Color.BLACK; Shader shader = new LinearGradient(0, 50, 0, 306, colors, null, Shader.TileMode.REPEAT); mPaint.setShader(shader); canvas.drawLine(x + 10, 50, x + 10, 306, mPaint); } mPaint.setShader(null); // Display the circle around the currently selected color in the main field if (mCurrentX != 0 && mCurrentY != 0) { mPaint.setStyle(Paint.Style.STROKE); mPaint.setColor(Color.BLACK); canvas.drawCircle(mCurrentX, mCurrentY, 10, mPaint); } // Draw a 'button' with the currently selected color mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(mCurrentColor); canvas.drawRect(10, 316, 138, 356, mPaint); // Set the text color according to the brightness of the color if (Color.red(mCurrentColor) + Color.green(mCurrentColor) + Color.blue(mCurrentColor) < 384) mPaint.setColor(Color.WHITE); else mPaint.setColor(Color.BLACK); // canvas.drawText(getResources().getString(R.string.settings_bg_color_confirm), 74, 340, // mPaint); // Draw a 'button' with the default color mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(mDefaultColor); canvas.drawRect(138, 316, 266, 356, mPaint); // Set the text color according to the brightness of the color if (Color.red(mDefaultColor) + Color.green(mDefaultColor) + Color.blue(mDefaultColor) < 384) mPaint.setColor(Color.WHITE); else mPaint.setColor(Color.BLACK); // canvas.drawText(getResources().getString(R.string.settings_default_color_confirm), 202, // 340, mPaint); }
public void drawBox(RectF box, int color, boolean isSelected, Canvas canvas) { if (isSelected) mPaint.setColor(getResources().getColor(R.color.SelectedColor)); else mPaint.setColor(getResources().getColor(R.color.White)); canvas.drawRect(box, mPaint); mPaint.setColor(color); canvas.drawRect( (box.left + 2.5f), (box.top + 2.5f), (box.right - 2.5f), (box.bottom - 2.5f), mPaint); }