List of usage examples for android.graphics Canvas drawLine
public void drawLine(float startX, float startY, float stopX, float stopY, @NonNull Paint paint)
From source file:com.yibu.headmaster.lib.PagerSliding.PagerSlidingTab.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from www . ja v a 2 s .c om*/ } final int height = getHeight(); // draw underline rectPaint.setColor(underlineColor); canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint); // canvas.drawRect(0, height - underlineHeight, // tabsContainer.getWidth(), // height, rectPaint); // draw divider dividerPaint.setColor(dividerColor); for (int i = 0; i < tabCount - 1; i++) { View tab = tabsContainer.getChildAt(i); canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint); } // draw indicator line rectPaint.setColor(indicatorColor); // 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); } canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); }
From source file:ir.hatamiarash.calendar.view.QiblaCompassView.java
public void drawDial(Canvas canvas) { // over here/* w w w . j a v a 2 s . c om*/ circlePaint.reset(); circlePaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color)); circlePaint.setStrokeWidth(1); circlePaint.setStyle(Paint.Style.STROKE); // Sadece Cember ciziyor. int textHeight = (int) textPaint.measureText("yY"); markerPaint.reset(); markerPaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color)); // Draw the background canvas.drawCircle(px, py, Radius, circlePaint); canvas.drawCircle(px, py, Radius - 20, circlePaint); // Rotate our perspective so that the "top" is // facing the current bearing. int textWidth = (int) textPaint.measureText("W"); int cardinalX = px - textWidth / 2; int cardinalY = py - Radius + textHeight; // Draw the marker every 15 degrees and text every 45. for (int i = 0; i < 24; i++) { // Draw a marker. canvas.drawLine(px, py - Radius, px, py - Radius + 10, markerPaint); canvas.save(); canvas.translate(0, textHeight); // Draw the cardinal points if (i % 6 == 0) { String dirString = ""; switch (i) { case (0): { dirString = northString; break; } case (6): dirString = eastString; break; case (12): dirString = southString; break; case (18): dirString = westString; break; } canvas.drawText(dirString, cardinalX, cardinalY, textPaint); } else if (i % 3 == 0) { // Draw the text every alternate 45deg String angle = String.valueOf(i * 15); float angleTextWidth = textPaint.measureText(angle); int angleTextX = (int) (px - angleTextWidth / 2); int angleTextY = py - Radius + textHeight; canvas.drawText(angle, angleTextX, angleTextY, textPaint); } canvas.restore(); canvas.rotate(15, px, py); } }
From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java
public void drawDial(Canvas canvas) { // over here//from w ww .j a va 2s . c o m circlePaint.reset(); circlePaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color)); circlePaint.setStrokeWidth(1); circlePaint.setStyle(Paint.Style.STROKE); // Sadece Cember ciziyor. int textHeight = (int) textPaint.measureText("yY"); markerPaint.reset(); markerPaint.setColor(ContextCompat.getColor(getContext(), R.color.qibla_color)); // Draw the background canvas.drawCircle(px, py, Radius, circlePaint); canvas.drawCircle(px, py, Radius - 20, circlePaint); // Rotate our perspective so that the "top" is // facing the current bearing. int textWidth = (int) textPaint.measureText("W"); int cardinalX = px - textWidth / 2; int cardinalY = py - Radius + textHeight; // Draw the marker every 15 degrees and text every 45. for (int i = 0; i < 24; i++) { // Draw a marker. canvas.drawLine(px, py - Radius, px, py - Radius + 10, markerPaint); canvas.save(); canvas.translate(0, textHeight); // Draw the cardinal points if (i % 6 == 0) { String dirString = ""; switch (i) { case (0): { dirString = northString; break; } case (6): dirString = eastString; break; case (12): dirString = southString; break; case (18): dirString = westString; break; } canvas.drawText(dirString, cardinalX, cardinalY, textPaint); } else if (i % 3 == 0) { // Draw the text every alternate 45deg String angle = String.valueOf(i * 15); float angleTextWidth = textPaint.measureText(angle); int angleTextX = (int) (px - angleTextWidth / 2); int angleTextY = py - Radius + textHeight; canvas.drawText(angle, angleTextX, angleTextY, textPaint); } canvas.restore(); canvas.rotate(15, px, py); } }
From source file:com.mukesh.OtpView.java
private void drawCursor(Canvas canvas) { if (drawCursor) { float cx = itemCenterPoint.x; float cy = itemCenterPoint.y; float y = cy - cursorHeight / 2; int color = paint.getColor(); float width = paint.getStrokeWidth(); paint.setColor(cursorColor);// ww w. j a v a2 s . com paint.setStrokeWidth(cursorWidth); canvas.drawLine(cx, y, cx, y + cursorHeight, paint); paint.setColor(color); paint.setStrokeWidth(width); } }
From source file:com.youqu.piclbs.util.SlidingTabLayout.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || mTabCount <= 0) { return;//from ww w .j a v a2s . co m } int height = getHeight(); int paddingLeft = getPaddingLeft(); // draw divider if (mDividerWidth > 0) { mDividerPaint.setStrokeWidth(mDividerWidth); mDividerPaint.setColor(mDividerColor); for (int i = 0; i < mTabCount - 1; i++) { View tab = mTabsContainer.getChildAt(i); canvas.drawLine(paddingLeft + tab.getRight(), mDividerPadding, paddingLeft + tab.getRight(), height - mDividerPadding, mDividerPaint); } } // draw underline if (mUnderlineHeight > 0) { mRectPaint.setColor(mUnderlineColor); if (mUnderlineGravity == Gravity.BOTTOM) { canvas.drawRect(paddingLeft, height - mUnderlineHeight, mTabsContainer.getWidth() + paddingLeft, height, mRectPaint); } else { canvas.drawRect(paddingLeft, 0, mTabsContainer.getWidth() + paddingLeft, mUnderlineHeight, mRectPaint); } } //draw indicator line calcIndicatorRect(); if (mIndicatorStyle == STYLE_TRIANGLE) { if (mIndicatorHeight > 0) { mTrianglePaint.setColor(mIndicatorColor); mTrianglePath.reset(); mTrianglePath.moveTo(paddingLeft + mIndicatorRect.left, height); mTrianglePath.lineTo(paddingLeft + mIndicatorRect.left / 2 + mIndicatorRect.right / 2, height - mIndicatorHeight); mTrianglePath.lineTo(paddingLeft + mIndicatorRect.right, height); mTrianglePath.close(); canvas.drawPath(mTrianglePath, mTrianglePaint); } } else if (mIndicatorStyle == STYLE_BLOCK) { if (mIndicatorHeight < 0) { mIndicatorHeight = height - mIndicatorMarginTop - mIndicatorMarginBottom; } else { } if (mIndicatorHeight > 0) { if (mIndicatorCornerRadius < 0 || mIndicatorCornerRadius > mIndicatorHeight / 2) { mIndicatorCornerRadius = mIndicatorHeight / 2; } mIndicatorDrawable.setColor(mIndicatorColor); mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left, (int) mIndicatorMarginTop, (int) (paddingLeft + mIndicatorRect.right - mIndicatorMarginRight), (int) (mIndicatorMarginTop + mIndicatorHeight)); mIndicatorDrawable.setCornerRadius(mIndicatorCornerRadius); mIndicatorDrawable.draw(canvas); } } else { /* mRectPaint.setColor(mIndicatorColor); calcIndicatorRect(); canvas.drawRect(getPaddingLeft() + mIndicatorRect.left, getHeight() - mIndicatorHeight, mIndicatorRect.right + getPaddingLeft(), getHeight(), mRectPaint);*/ if (mIndicatorHeight > 0) { mIndicatorDrawable.setColor(mIndicatorColor); if (mIndicatorGravity == Gravity.BOTTOM) { mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left, height - (int) mIndicatorHeight - (int) mIndicatorMarginBottom, paddingLeft + mIndicatorRect.right - (int) mIndicatorMarginRight, height - (int) mIndicatorMarginBottom); } else { mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left, (int) mIndicatorMarginTop, paddingLeft + mIndicatorRect.right - (int) mIndicatorMarginRight, (int) mIndicatorHeight + (int) mIndicatorMarginTop); } mIndicatorDrawable.setCornerRadius(mIndicatorCornerRadius); mIndicatorDrawable.draw(canvas); } } }
From source file:com.nextgis.maplibui.overlay.EditLayerOverlay.java
protected void drawCross(Canvas canvas) { if (mMode != MODE_EDIT) { return;//w w w. jav a2 s .c o m } mCanvasCenterX = canvas.getWidth() / 2; mCanvasCenterY = canvas.getHeight() / 2; canvas.drawLine(mCanvasCenterX - mTolerancePX, mCanvasCenterY, mCanvasCenterX + mTolerancePX, mCanvasCenterY, mPaint); canvas.drawLine(mCanvasCenterX, mCanvasCenterY - mTolerancePX, mCanvasCenterX, mCanvasCenterY + mTolerancePX, mPaint); }
From source file:info.bartowski.easteregg.LLand.java
@Override public void onDraw(Canvas c) { super.onDraw(c); if (!DEBUG_DRAW) return;//from w ww.j a v a 2 s.c o m final Paint pt = new Paint(); pt.setColor(0xFFFFFFFF); final int L = mDroid.corners.length; final int N = L / 2; for (int i = 0; i < N; i++) { final int x = (int) mDroid.corners[i * 2]; final int y = (int) mDroid.corners[i * 2 + 1]; c.drawCircle(x, y, 4, pt); c.drawLine(x, y, mDroid.corners[(i * 2 + 2) % L], mDroid.corners[(i * 2 + 3) % L], pt); } pt.setStyle(Paint.Style.STROKE); pt.setStrokeWidth(getResources().getDisplayMetrics().density); final int M = getChildCount(); pt.setColor(0x8000FF00); for (int i = 0; i < M; i++) { final View v = getChildAt(i); if (v == mDroid) continue; if (!(v instanceof GameView)) continue; if (v instanceof Pop) { final Pop p = (Pop) v; c.drawCircle(p.cx, p.cy, p.r, pt); } else { final Rect r = new Rect(); v.getHitRect(r); c.drawRect(r, pt); } } pt.setColor(Color.BLACK); final StringBuilder sb = new StringBuilder("obstacles: "); for (Obstacle ob : mObstaclesInPlay) { sb.append(ob.hitRect.toShortString()); sb.append(" "); } pt.setTextSize(20f); c.drawText(sb.toString(), 20, 100, pt); }
From source file:com.baiiu.autoloopviewpager.indicator.LinePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/*from www .j ava 2s.c o m*/ } final int count = getRealCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } final float lineWidthAndGap = mLineWidth + mGapWidth; final float indicatorWidth = (count * lineWidthAndGap) - mGapWidth; final float paddingTop = getPaddingTop(); final float paddingLeft = getPaddingLeft(); final float paddingRight = getPaddingRight(); float verticalOffset = paddingTop + ((getHeight() - paddingTop - getPaddingBottom()) / 2.0f); float horizontalOffset = paddingLeft; if (mCentered) { horizontalOffset += ((getWidth() - paddingLeft - paddingRight) / 2.0f) - (indicatorWidth / 2.0f); } //Draw stroked circles for (int i = 0; i < count; i++) { float dx1 = horizontalOffset + (i * lineWidthAndGap); float dx2 = dx1 + mLineWidth; canvas.drawLine(dx1, verticalOffset, dx2, verticalOffset, (i == mCurrentPage) ? mPaintSelected : mPaintUnselected); } }
From source file:com.blestep.sportsbracelet.view.TimelineChartViewSleep.java
/** * {@inheritDoc}//from w w w .jav a 2s . c o m */ @Override protected void onDraw(Canvas c) { // c.clipRect(mViewArea); mViewAreaBgShader = new LinearGradient(0, 0, 0, mViewArea.height(), ContextCompat.getColor(getContext(), R.color.tlcSleepGraphBgColorStart), ContextCompat.getColor(getContext(), R.color.tlcSleepGraphBgColorEnd), Shader.TileMode.CLAMP); mViewAreaBgPaint.setShader(mViewAreaBgShader); // c.drawRect(mViewArea, mViewAreaBgPaint); c.drawRect(mGraphArea, mGraphAreaBgPaint); c.drawRect(mFooterArea, mFooterAreaBgPaint); // c.drawLine(0, mGraphArea.height(), mGraphArea.width(), mGraphArea.height(), mGraphBottomLinePaint); final SparseArray<Object[]> data; final double maxValue; synchronized (mLock) { data = mData; maxValue = mMaxValue; } boolean hasData = data.size() > 0; if (hasData) { // ??? computeItemsOnScreen(data.size()); // drawBarItems(c, data, maxValue); // drawTickLabels(c, data); } }
From source file:com.blestep.sportsbracelet.view.TimelineChartView.java
/** * {@inheritDoc}// w w w .j a v a 2 s.c om */ @Override protected void onDraw(Canvas c) { // c.clipRect(mViewArea); mViewAreaBgShader = new LinearGradient(0, 0, 0, mViewArea.height(), ContextCompat.getColor(getContext(), R.color.tlcStepsGraphBgColorStart), ContextCompat.getColor(getContext(), R.color.tlcStepsGraphBgColorEnd), Shader.TileMode.CLAMP); mViewAreaBgPaint.setShader(mViewAreaBgShader); // c.drawRect(mViewArea, mViewAreaBgPaint); c.drawRect(mGraphArea, mGraphAreaBgPaint); c.drawRect(mFooterArea, mFooterAreaBgPaint); // c.drawLine(0, mGraphArea.height(), mGraphArea.width(), mGraphArea.height(), mGraphBottomLinePaint); final SparseArray<Object[]> data; final double maxValue; synchronized (mLock) { data = mData; if (mIsShowTargetDashedLine && mTargetValue > mMaxValue) { maxValue = mTargetValue; } else { maxValue = mMaxValue; } } boolean hasData = data.size() > 0; if (hasData) { // ??? computeItemsOnScreen(data.size()); // drawTargetLine(c); // drawBarItems(c, data, maxValue); // drawTickLabels(c, data); } }