Java Code Examples for android.graphics.Canvas#getHeight()
The following examples show how to use
android.graphics.Canvas#getHeight() .
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: LiveWallpaperService.java From Mysplash with GNU Lesser General Public License v3.0 | 6 votes |
private void ensureSrcRect(Bitmap bitmap, Rect src, Canvas canvas) { if (1.0 * bitmap.getWidth() / bitmap.getHeight() > 1.0 * canvas.getWidth() / canvas.getHeight()) { // landscape. src.set(0, 0, (int) (bitmap.getHeight() * 1.0 * canvas.getWidth() / canvas.getHeight()), bitmap.getHeight()); src.right = Math.min(src.right, bitmap.getWidth()); src.offset((bitmap.getWidth() - src.width()) / 2, 0); src.offset((int) ((bitmap.getWidth() - src.width()) / 2 * horizontalOffset), 0); } else { // portrait. src.set(0, 0, bitmap.getWidth(), (int) (bitmap.getWidth() * 1.0 * canvas.getHeight() / canvas.getWidth())); src.bottom = Math.min(src.bottom, bitmap.getHeight()); src.offset(0, (bitmap.getHeight() - src.height()) / 2); } }
Example 2
Source File: PopupZoomer.java From 365browser with Apache License 2.0 | 6 votes |
/** * Sets the bitmap to be used for the zoomed view. */ public void setBitmap(Bitmap bitmap) { if (mZoomedBitmap != null) { mZoomedBitmap.recycle(); mZoomedBitmap = null; } mZoomedBitmap = bitmap; // Round the corners of the bitmap so it doesn't stick out around the overlay. Canvas canvas = new Canvas(mZoomedBitmap); Path path = new Path(); RectF canvasRect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight()); float overlayCornerRadius = getOverlayCornerRadius(getContext()); path.addRoundRect(canvasRect, overlayCornerRadius, overlayCornerRadius, Direction.CCW); canvas.clipPath(path, Op.XOR); Paint clearPaint = new Paint(); clearPaint.setXfermode(new PorterDuffXfermode(Mode.SRC)); clearPaint.setColor(Color.TRANSPARENT); canvas.drawPaint(clearPaint); }
Example 3
Source File: FileBackend.java From Pix-Art-Messenger with GNU General Public License v3.0 | 6 votes |
public void drawOverlay(final Bitmap bitmap, final int resource, final float factor, final boolean corner) { Bitmap overlay = BitmapFactory.decodeResource(mXmppConnectionService.getResources(), resource); Canvas canvas = new Canvas(bitmap); float targetSize = Math.min(canvas.getWidth(), canvas.getHeight()) * factor; Log.d(Config.LOGTAG, "target size overlay: " + targetSize + " overlay bitmap size was " + overlay.getHeight()); float left; float top; if (corner) { left = canvas.getWidth() - targetSize; top = canvas.getHeight() - targetSize; } else { left = (canvas.getWidth() - targetSize) / 2.0f; top = (canvas.getHeight() - targetSize) / 2.0f; } RectF dst = new RectF(left, top, left + targetSize - 1, top + targetSize - 1); canvas.drawBitmap(overlay, null, dst, createAntiAliasingPaint()); }
Example 4
Source File: RectProgress.java From IOS11RectProgress with Apache License 2.0 | 6 votes |
@Override protected void onDraw(Canvas canvas) { int canvasWidth = canvas.getWidth(); int canvasHeight = canvas.getHeight(); int layerId = canvas.saveLayer(0, 0, canvasWidth, canvasHeight, null, Canvas.ALL_SAVE_FLAG); { bgPaint.setColor(bgColor); // draw the background of progress canvas.drawRoundRect(bgRect, rectRadius, rectRadius, bgPaint); // draw progress canvas.drawRect(progressRect, progressPaint); bgPaint.setXfermode(null); if (bitmap != null) { //draw icon canvas.drawBitmap(bitmap, srcRect, dstRect, bgPaint); } } canvas.restoreToCount(layerId); // TODO: 弄明白为什么在xml预览中,canvas.restoreToCount // TODO: 会导致后续的canvas对象为空 但canvas.restore方法则不会导致这个问题 // canvas.restore(); // canvas.save(); }
Example 5
Source File: DrawingHelper.java From CommonUtils with Apache License 2.0 | 6 votes |
public void draw(@NonNull String letters, boolean circle, Canvas canvas) { int cx = canvas.getWidth() / 2; int cy = canvas.getHeight() / 2; int r = Math.min(cx, cy); float reduce; Paint lettersPaint; if (circle) { reduce = REDUCE_FACTOR_CIRCLE; r = r - SHADOW_RADIUS; canvas.drawCircle(cx, cy, r, shapePaint); lettersPaint = lettersPaintWithCircle; } else { reduce = REDUCE_FACTOR_NO_CIRCLE; lettersPaint = lettersPaintNoCircle; } lettersPaint.getTextBounds(letters, 0, letters.length(), lettersBounds); float factor = hypotenuse(lettersBounds.width() / 2, lettersBounds.height() / 2) / lettersPaint.getTextSize(); lettersPaint.setTextSize(r / factor * reduce); lettersPaint.getTextBounds(letters, 0, letters.length(), lettersBounds); canvas.drawText(letters, cx - lettersBounds.exactCenterX(), cy - lettersBounds.exactCenterY(), lettersPaint); }
Example 6
Source File: RippleLayout.java From fingerpoetry-android with Apache License 2.0 | 6 votes |
@Override public void draw(Canvas canvas) { final boolean positionChanged = adapterPositionChanged(); if (rippleOverlay) { if (!positionChanged) { rippleBackground.draw(canvas); } super.draw(canvas); if (!positionChanged) { if (rippleRoundedCorners != 0) { Path clipPath = new Path(); RectF rect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight()); clipPath.addRoundRect(rect, rippleRoundedCorners, rippleRoundedCorners, Path.Direction.CW); canvas.clipPath(clipPath); } canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint); } } else { if (!positionChanged) { rippleBackground.draw(canvas); canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint); } super.draw(canvas); } }
Example 7
Source File: DataSourcePointOverlay.java From geoar-app with Apache License 2.0 | 5 votes |
@Override protected void drawOverlayBitmap(Canvas canvas, android.graphics.Point drawPosition, Projection projection, byte zoom) { android.graphics.Point pointOverlayPosition = new android.graphics.Point(); int index = 0; visiblePointOverlays.clear(); for (PointOverlayType pot : pointOverlays) { if (zoom != pot.cachedZoomLevel) { pot.cachedMapPosition = projection.toPoint(pot.getPoint(), pot.cachedMapPosition, zoom); pot.cachedZoomLevel = zoom; } pointOverlayPosition.x = pot.cachedMapPosition.x - drawPosition.x; pointOverlayPosition.y = pot.cachedMapPosition.y - drawPosition.y; Rect markerBounds = pot.marker.copyBounds(); this.left = pointOverlayPosition.x + markerBounds.left; this.right = pointOverlayPosition.x + markerBounds.right; this.top = pointOverlayPosition.y + markerBounds.top; this.bottom = pointOverlayPosition.y + markerBounds.bottom; // check boundingbox marker interesects with canvas if (this.right >= 0 && this.left <= canvas.getWidth() && this.bottom >= 0 && this.top <= canvas.getHeight()) { pot.marker.setBounds(left, top, right, bottom); pot.marker.draw(canvas); pot.marker.setBounds(markerBounds); this.visiblePointOverlays.add(index); } index++; } }
Example 8
Source File: SVG.java From starcor.xul with GNU Lesser General Public License v3.0 | 5 votes |
/** * Renders this SVG document to a Canvas object. * * @param canvas the canvas to which the document should be rendered. * @param viewPort the bounds of the area on the canvas you want the SVG rendered, or null for the whole canvas. */ public void renderToCanvas(Canvas canvas, RectF viewPort) { Box svgViewPort; if (viewPort != null) { svgViewPort = Box.fromLimits(viewPort.left, viewPort.top, viewPort.right, viewPort.bottom); } else { svgViewPort = new Box(0f, 0f, (float) canvas.getWidth(), (float) canvas.getHeight()); } SVGAndroidRenderer renderer = new SVGAndroidRenderer(canvas, svgViewPort, this.renderDPI); renderer.renderDocument(this, null, null, true); }
Example 9
Source File: SVG.java From XDroidAnimation with Apache License 2.0 | 5 votes |
/** * Renders this SVG document to a Canvas using the specified view defined in the document. * <p/> * A View is an special element in a SVG documents that describes a rectangular area in the document. * Calling this method with a {@code viewId} will result in the specified view being positioned and scaled * to the viewport. In other words, use {@link #renderToPicture()} to render the whole document, or use this * method instead to render just a part of it. * <p/> * If the {@code <view>} could not be found, nothing will be drawn. * * @param viewId the id of a view element in the document that defines which section of the document is to be * visible. * @param canvas the canvas to which the document should be rendered. * @param viewPort the bounds of the area on the canvas you want the SVG rendered, or null for the whole canvas. */ public void renderViewToCanvas(String viewId, Canvas canvas, RectF viewPort) { SvgObject obj = this.getElementById(viewId); if (obj == null) return; if (!(obj instanceof SVG.View)) return; SVG.View view = (SVG.View) obj; if (view.viewBox == null) { Log.w(TAG, "View element is missing a viewBox attribute."); return; } Box svgViewPort; if (viewPort != null) { svgViewPort = Box.fromLimits(viewPort.left, viewPort.top, viewPort.right, viewPort.bottom); } else { svgViewPort = new Box(0f, 0f, (float) canvas.getWidth(), (float) canvas.getHeight()); } SVGAndroidRenderer renderer = new SVGAndroidRenderer(canvas, svgViewPort, this.renderDPI); renderer.renderDocument(this, view.viewBox, view.preserveAspectRatio, true); }
Example 10
Source File: SVG.java From starcor.xul with GNU Lesser General Public License v3.0 | 5 votes |
/** * Renders this SVG document to a Canvas using the specified view defined in the document. * <p> * A View is an special element in a SVG documents that describes a rectangular area in the document. * Calling this method with a {@code viewId} will result in the specified view being positioned and scaled * to the viewport. In other words, use {@link #renderToPicture()} to render the whole document, or use this * method instead to render just a part of it. * <p> * If the {@code <view>} could not be found, nothing will be drawn. * * @param viewId the id of a view element in the document that defines which section of the document is to be visible. * @param canvas the canvas to which the document should be rendered. * @param viewPort the bounds of the area on the canvas you want the SVG rendered, or null for the whole canvas. */ public void renderViewToCanvas(String viewId, Canvas canvas, RectF viewPort) { SvgObject obj = this.getElementById(viewId); if (obj == null) return; if (!(obj instanceof SVG.View)) return; SVG.View view = (SVG.View) obj; if (view.viewBox == null) { Log.w(TAG, "View element is missing a viewBox attribute."); return; } Box svgViewPort; if (viewPort != null) { svgViewPort = Box.fromLimits(viewPort.left, viewPort.top, viewPort.right, viewPort.bottom); } else { svgViewPort = new Box(0f, 0f, (float) canvas.getWidth(), (float) canvas.getHeight()); } SVGAndroidRenderer renderer = new SVGAndroidRenderer(canvas, svgViewPort, this.renderDPI); renderer.renderDocument(this, view.viewBox, view.preserveAspectRatio, true); }
Example 11
Source File: WXSvgAbsComponent.java From Svg-for-Apache-Weex with Apache License 2.0 | 5 votes |
protected void setupDimensions(Canvas canvas) { Rect mCanvasClipBounds = canvas.getClipBounds(); mCanvasX = mCanvasClipBounds.left; mCanvasY = mCanvasClipBounds.top; mCanvasWidth = canvas.getWidth(); mCanvasHeight = canvas.getHeight(); }
Example 12
Source File: CompositeDrawable.java From materialize with GNU General Public License v3.0 | 5 votes |
public void drawTo(Canvas canvas, boolean antiAliasing) { Rect bounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); RectF foregroundBounds = new RectF(bounds); applyForegroundBounds(foregroundBounds); Rect backgroundBounds = new Rect(bounds); applyBackgroundBounds(backgroundBounds); Rect scoreBounds = new Rect(bounds); applyScoreBounds(scoreBounds); drawInternal(canvas, antiAliasing, bounds, foregroundBounds, backgroundBounds, scoreBounds); }
Example 13
Source File: Utils.java From JumpGo with Mozilla Public License 2.0 | 5 votes |
/** * Draws the trapezoid background for the horizontal tabs on a canvas object using * the specified color. * * @param canvas the canvas to draw upon * @param color the color to use to draw the tab */ public static void drawTrapezoid(@NonNull Canvas canvas, int color, boolean withShader) { Paint paint = new Paint(); paint.setColor(color); paint.setStyle(Paint.Style.FILL); // paint.setFilterBitmap(true); paint.setAntiAlias(true); paint.setDither(true); if (withShader) { paint.setShader(new LinearGradient(0, 0.9f * canvas.getHeight(), 0, canvas.getHeight(), color, mixTwoColors(Color.BLACK, color, 0.5f), Shader.TileMode.CLAMP)); } else { paint.setShader(null); } int width = canvas.getWidth(); int height = canvas.getHeight(); double radians = Math.PI / 3; int base = (int) (height / Math.tan(radians)); Path wallpath = new Path(); wallpath.reset(); wallpath.moveTo(0, height); wallpath.lineTo(width, height); wallpath.lineTo(width - base, 0); wallpath.lineTo(base, 0); wallpath.close(); canvas.drawPath(wallpath, paint); }
Example 14
Source File: EmojiView.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public void customOnDraw(Canvas canvas, int position) { if (position == 6 && !DataQuery.getInstance(currentAccount).getUnreadStickerSets().isEmpty() && dotPaint != null) { int x = canvas.getWidth() / 2 + AndroidUtilities.dp(4 + 5); int y = canvas.getHeight() / 2 - AndroidUtilities.dp(13 - 5); canvas.drawCircle(x, y, AndroidUtilities.dp(5), dotPaint); } }
Example 15
Source File: SquareProgressView.java From UltimateAndroid with Apache License 2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { this.canvas = canvas; super.onDraw(canvas); strokewidth = CalculationUtil.convertDpToPx(widthInDp, getContext()); float scope = canvas.getWidth() + canvas.getHeight() + canvas.getHeight() + canvas.getWidth(); float percent = (scope / 100) * Float.valueOf(String.valueOf(progress)); float halfOfTheImage = canvas.getWidth() / 2; if (outline) { drawOutline(); } if (isStartline()) { drawStartline(); } if (showProgress) { drawPercent(percentSettings); } if (clearOnHundred && progress == 100.0) { return; } Path path = new Path(); if (percent > halfOfTheImage) { paintFirstHalfOfTheTop(canvas); float second = percent - halfOfTheImage; if (second > canvas.getHeight()) { paintRightSide(canvas); float third = second - canvas.getHeight(); if (third > canvas.getWidth()) { paintBottomSide(canvas); float forth = third - canvas.getWidth(); if (forth > canvas.getHeight()) { paintLeftSide(canvas); float fifth = forth - canvas.getHeight(); if (fifth == halfOfTheImage) { paintSecondHalfOfTheTop(canvas); } else { path.moveTo(strokewidth, (strokewidth / 2)); path.lineTo(strokewidth + fifth, (strokewidth / 2)); canvas.drawPath(path, progressBarPaint); } } else { path.moveTo((strokewidth / 2), canvas.getHeight() - strokewidth); path.lineTo((strokewidth / 2), canvas.getHeight() - forth); canvas.drawPath(path, progressBarPaint); } } else { path.moveTo(canvas.getWidth() - strokewidth, canvas.getHeight() - (strokewidth / 2)); path.lineTo(canvas.getWidth() - third, canvas.getHeight() - (strokewidth / 2)); canvas.drawPath(path, progressBarPaint); } } else { path.moveTo(canvas.getWidth() - (strokewidth / 2), strokewidth); path.lineTo(canvas.getWidth() - (strokewidth / 2), strokewidth + second); canvas.drawPath(path, progressBarPaint); } } else { path.moveTo(halfOfTheImage, strokewidth / 2); path.lineTo(halfOfTheImage + percent, strokewidth / 2); canvas.drawPath(path, progressBarPaint); } }
Example 16
Source File: WaveView.java From WaveView with Apache License 2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { canvas.drawColor(backgroundColor); // Prepare common values float xAxisPosition = canvas.getHeight() * xAxisPositionMultiplier; float width = canvas.getWidth(); float mid = canvas.getWidth() / 2; for (int i = 0; i < numberOfWaves; i++) { // Prepare variables for this wave paint.setStrokeWidth(i == 0 ? primaryWaveLineWidth : secondaryWaveLineWidth); float progress = 1.0f - (float) i / this.numberOfWaves; float normedAmplitude = (1.5f * progress - 0.5f) * this.amplitude; // Prepare path for this wave path.reset(); float x; for (x = 0; x < width + density; x += density) { // We use a parable to scale the sinus wave, that has its peak in the middle of // the view. float scaling = (float) (-Math.pow(1 / mid * (x - mid), 2) + 1); float y = (float) (scaling * amplitude * normedAmplitude * Math.sin(2 * Math.PI * (x / width) * frequency + phase * (i + 1)) + xAxisPosition); if (x == 0) { path.moveTo(x, y); } else { path.lineTo(x, y); } } path.lineTo(x, canvas.getHeight()); path.lineTo(0, canvas.getHeight()); path.close(); // Set opacity for this wave fill paint.setAlpha(i == 0 ? 255 : 255 / (i + 1)); // Draw wave canvas.drawPath(path, paint); } if (isPlaying.get()) { this.phase += phaseShift; } invalidate(); }
Example 17
Source File: CirclePicker.java From CircleTimePicker with MIT License | 4 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // 圆心坐标 mCenterX = canvas.getWidth() / 2; mCenterY = canvas.getHeight() / 2; // 默认的圆环进度条的半径 mWheelRadius = (mMinViewSize - mBtnSize) / 2; canvas.drawCircle(mCenterX, mCenterY, mWheelRadius, mCirclePaint); canvas.drawBitmap(mClockBg, mCenterX - mClockSize / 2, mCenterY - mClockSize / 2, mDefaultPaint); // 画选中区域 float begin = 0; //圆弧的起点位置 float sweep = 0; if (mStartBtnAngle > 180 && mStartBtnAngle > mEndBtnAngle) { //180 -- 360 begin = -Math.abs(mStartBtnAngle - 360) - 90; sweep = Math.abs(Math.abs(mStartBtnAngle - 360) + mEndBtnAngle); } else if (mStartBtnAngle > mEndBtnAngle) { begin = mStartBtnAngle - 90; sweep = 360 - (mStartBtnAngle - mEndBtnAngle); } else { begin = mStartBtnAngle - 90; sweep = Math.abs(mStartBtnAngle - mEndBtnAngle); } mProgressPaint.setShader(new LinearGradient(mStartBtnCurX, mStartBtnCurY, mEndBtnCurX, mEndBtnCurY, mStartBtnColor, mEndBtnColor, Shader.TileMode.CLAMP)); canvas.drawArc(new RectF(mCenterX - mWheelRadius, mCenterY - mWheelRadius, mCenterX + mWheelRadius, mCenterY + mWheelRadius), begin, sweep, false, mProgressPaint); // 结束按钮 canvas.drawCircle(mEndBtnCurX, mEndBtnCurY, mBtnSize / 2, mEndBtnPaint); canvas.drawBitmap(mEndBtnBg, mEndBtnCurX - mBtnImgSize / 2, mEndBtnCurY - mBtnImgSize / 2, mDefaultPaint); // 开始按钮 canvas.drawCircle(mStartBtnCurX, mStartBtnCurY, mBtnSize / 2, mStartBtnPaint); canvas.drawBitmap(mStartBtnBg, mStartBtnCurX - mBtnImgSize / 2, mStartBtnCurY - mBtnImgSize / 2, mDefaultPaint); }
Example 18
Source File: LayoutHelper.java From DanDanPlayForAndroid with MIT License | 4 votes |
public void dispatchRoundBorderDraw(Canvas canvas) { View owner = mOwner.get(); if (owner == null) { return; } if (mBorderColor == 0 && (mRadius == 0 || mOuterNormalColor == 0)) { return; } if (mIsShowBorderOnlyBeforeL && useFeature() && mShadowElevation != 0) { return; } int width = canvas.getWidth(), height = canvas.getHeight(); // react if (mIsOutlineExcludePadding) { mBorderRect.set(1 + owner.getPaddingLeft(), 1 + owner.getPaddingTop(), width - 1 - owner.getPaddingRight(), height - 1 - owner.getPaddingBottom()); } else { mBorderRect.set(1, 1, width - 1, height - 1); } if (mRadius == 0 || (!useFeature() && mOuterNormalColor == 0)) { mClipPaint.setStyle(Paint.Style.STROKE); canvas.drawRect(mBorderRect, mClipPaint); return; } // 圆角矩形 if (!useFeature()) { int layerId = canvas.saveLayer(0, 0, width, height, null, Canvas.ALL_SAVE_FLAG); canvas.drawColor(mOuterNormalColor); mClipPaint.setColor(mOuterNormalColor); mClipPaint.setStyle(Paint.Style.FILL); mClipPaint.setXfermode(mMode); if (mRadiusArray == null) { canvas.drawRoundRect(mBorderRect, mRadius, mRadius, mClipPaint); } else { drawRoundRect(canvas, mBorderRect, mRadiusArray, mClipPaint); } mClipPaint.setXfermode(null); canvas.restoreToCount(layerId); } mClipPaint.setColor(mBorderColor); mClipPaint.setStrokeWidth(mBorderWidth); mClipPaint.setStyle(Paint.Style.STROKE); if (mRadiusArray == null) { canvas.drawRoundRect(mBorderRect, mRadius, mRadius, mClipPaint); } else { drawRoundRect(canvas, mBorderRect, mRadiusArray, mClipPaint); } }
Example 19
Source File: ProcessFramesView.java From Camdroid with Apache License 2.0 | 4 votes |
@Override public void drawBitmap(Bitmap bitmap) { if (this.mHolder == null) { return; } Canvas canvas = null; try { synchronized (this.mHolder) { mBitmap = bitmap; canvas = this.mHolder.lockCanvas(); int bmpWidth = bitmap.getWidth(); int bmpHeight = bitmap.getHeight(); int canvasWidth = canvas.getWidth(); int canvasHeight = canvas.getHeight(); if (this.mScale != 0) { canvas.drawBitmap(bitmap, new Rect(0, 0, bmpWidth, bmpHeight), new Rect((int) ((canvasWidth - this.mScale * bmpWidth) / 2), (int) ((canvasHeight - this.mScale * bmpHeight) / 2), (int) ((canvasWidth - this.mScale * bmpWidth) / 2 + this.mScale * bmpWidth), (int) ((canvasHeight - this.mScale * bmpHeight) / 2 + this.mScale * bmpHeight)), null); } else { canvas.drawBitmap(bitmap, new Rect(0, 0, bmpWidth, bmpHeight), new Rect((canvasWidth - bmpWidth) / 2, (canvasHeight - bmpHeight) / 2, (canvasWidth - bmpWidth) / 2 + bmpWidth, (canvasHeight - bmpHeight) / 2 + bmpHeight), null); } String fps = this.fpsMeter.measure(); canvas.drawText(fps, 12, canvasHeight - 6, this.fpsPaint); } } finally { if (canvas != null) { this.mHolder.unlockCanvasAndPost(canvas); } } }
Example 20
Source File: GridLabelRenderer.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 4 votes |
/** * draws the horizontal steps * vertical lines and horizontal labels * * @param canvas canvas */ protected void drawHorizontalSteps(Canvas canvas) { // draw horizontal steps (vertical lines and horizontal labels) mPaintLabel.setColor(getHorizontalLabelsColor()); int i = 0; for (Map.Entry<Integer, Double> e : mStepsHorizontal.entrySet()) { // draw line if (mStyles.highlightZeroLines) { if (e.getValue() == 0d) { mPaintLine.setStrokeWidth(5); } else { mPaintLine.setStrokeWidth(0); } } if (mStyles.gridStyle.drawVertical()) { // dont draw if it is right of visible screen if (e.getKey() <= mGraphView.getGraphContentWidth()) { canvas.drawLine(mGraphView.getGraphContentLeft()+e.getKey(), mGraphView.getGraphContentTop(), mGraphView.getGraphContentLeft()+e.getKey(), mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), mPaintLine); } } // draw label if (isHorizontalLabelsVisible()) { if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) { if (mStyles.horizontalLabelsAngle < 90f) { mPaintLabel.setTextAlign((Paint.Align.RIGHT)); } else if (mStyles.horizontalLabelsAngle <= 180f) { mPaintLabel.setTextAlign((Paint.Align.LEFT)); } } else { mPaintLabel.setTextAlign(Paint.Align.CENTER); if (i == mStepsHorizontal.size() - 1) mPaintLabel.setTextAlign(Paint.Align.RIGHT); if (i == 0) mPaintLabel.setTextAlign(Paint.Align.LEFT); } // multiline labels String label = mLabelFormatter.formatLabel(e.getValue(), true); if (label == null) { label = ""; } String[] lines = label.split("\n"); // If labels are angled, calculate adjustment to line them up with the grid int labelWidthAdj = 0; if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) { Rect textBounds = new Rect(); mPaintLabel.getTextBounds(lines[0], 0, lines[0].length(), textBounds); labelWidthAdj = (int) Math.abs(textBounds.width()* Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle))); } for (int li = 0; li < lines.length; li++) { // for the last line y = height float y = (canvas.getHeight() - mStyles.padding - getHorizontalAxisTitleHeight()) - (lines.length - li - 1) * getTextSize() * 1.1f + mStyles.labelsSpace; float x = mGraphView.getGraphContentLeft()+e.getKey(); if (mStyles.horizontalLabelsAngle > 0 && mStyles.horizontalLabelsAngle < 90f) { canvas.save(); canvas.rotate(mStyles.horizontalLabelsAngle, x + labelWidthAdj, y); canvas.drawText(lines[li], x + labelWidthAdj, y, mPaintLabel); canvas.restore(); } else if (mStyles.horizontalLabelsAngle > 0 && mStyles.horizontalLabelsAngle <= 180f) { canvas.save(); canvas.rotate(mStyles.horizontalLabelsAngle - 180f, x - labelWidthAdj, y); canvas.drawText(lines[li], x - labelWidthAdj, y, mPaintLabel); canvas.restore(); } else { canvas.drawText(lines[li], x, y, mPaintLabel); } } } i++; } }