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.leeon.blank.widget.RangeBarNew.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final int length = mTextArray.length; /*** Draw text marks ***/ mPaint.setTextSize(mTextSize);//from w ww . j av a 2 s .c o m mPaint.setColor(mTextColorNormal); for (int i = 0; i < length; i++) { final String text2draw = mTextArray[i] == -1 ? "" : mTextArray[i] + ""; final float textWidth = mTextWidthArray[i]; float textDrawLeft; // The last text mark's draw location should be adjust. if (i == length - 1) { textDrawLeft = mRangeBarRect.right - textWidth / 2; } else { textDrawLeft = mRangeBarRect.left + i * mPartLength - textWidth / 2; } canvas.drawText(text2draw, textDrawLeft, mRangeBarRect.top - 24 - mMarginBetween, mPaint); //draw lines float lineDrawLeft = mRangeBarRect.left + i * mPartLength; canvas.drawLine(lineDrawLeft, mRangeBarRect.top, lineDrawLeft, mRangeBarRect.top - 24, mPaint); //draw short lines if (i != length - 1) { for (int j = 1; j < 5; j++) { float lineDrawLeft_short = lineDrawLeft + j * mTinyPartLength; canvas.drawLine(lineDrawLeft_short, mRangeBarRect.top, lineDrawLeft_short, mRangeBarRect.top - 18, mPaint); } } } /*** Draw seekBar ***/ final float radius = mRangeBarHeight / 4f; mRangeBarRectSelected.left = mRangeBarRect.left + mTinyPartLength * mLeftCursorIndex; mRangeBarRectSelected.right = mRangeBarRect.left + mTinyPartLength * mRightCursorIndex; // If whole of seekbar is selected, just draw seekbar with selectedcolor. if (mLeftCursorIndex == 0 && mRightCursorIndex == (length - 1) * 5) { mPaint.setColor(mRangeBarColorSelected); canvas.drawRoundRect(mRangeBarRect, radius, radius, mPaint); } else { // Draw background first. mPaint.setColor(mRangeBarColorNormal); canvas.drawRoundRect(mRangeBarRect, radius, radius, mPaint); // Draw selected part. mPaint.setColor(mRangeBarColorSelected); // Can draw rounded rectangle, but original rectangle is enough. // Because edges of selected part will be covered by cursors. canvas.drawRect(mRangeBarRectSelected, mPaint); } /*** Draw cursors ***/ // left cursor first final int leftWidth = mLeftCursorBG.getIntrinsicWidth(); final int leftHeight = mLeftCursorBG.getIntrinsicHeight(); final int leftLeft = (int) (mRangeBarRectSelected.left - leftWidth / 2f); final int leftTop = (int) (mRangeBarRect.bottom + mMarginBetween); mLeftCursorRect.left = leftLeft; mLeftCursorRect.top = leftTop; mLeftCursorRect.right = leftLeft + leftWidth; mLeftCursorRect.bottom = leftTop + leftHeight; mLeftCursorBG.setBounds(mLeftCursorRect); mLeftCursorBG.draw(canvas); // right cursor second final int rightWidth = mRightCursorBG.getIntrinsicWidth(); final int rightHeight = mRightCursorBG.getIntrinsicHeight(); final int rightLeft = (int) (mRangeBarRectSelected.right - rightWidth / 2f); final int rightTop = (int) (mRangeBarRect.bottom + mMarginBetween); mRightCursorRect.left = rightLeft; mRightCursorRect.top = rightTop; mRightCursorRect.right = rightLeft + rightWidth; mRightCursorRect.bottom = rightTop + rightHeight; mRightCursorBG.setBounds(mRightCursorRect); mRightCursorBG.draw(canvas); //Draw indicators final int indicatorWidth = Math.max(indicatorDrawable.getIntrinsicWidth(), (int) mPaint.measureText("888")); if (mLeftHit && mLeftPointerID != -1) { final int indicatorLeft = (int) (mRangeBarRectSelected.left - (float) indicatorWidth / 2); final int indicatorTop = mPaddingRect.top; mLeftIndicatorRect.left = indicatorLeft; mLeftIndicatorRect.top = indicatorTop; mLeftIndicatorRect.right = indicatorLeft + indicatorWidth; mLeftIndicatorRect.bottom = indicatorTop + indicatorHeight; indicatorDrawable.setBounds(mLeftIndicatorRect); indicatorDrawable.draw(canvas); mPaint.setColor(Color.WHITE); mValueLeft = getValueByIndex(mLeftCursorIndex); canvas.drawText(mValueLeft + "", mLeftIndicatorRect.centerX() - mPaint.measureText(mValueLeft + "") / 2, mLeftIndicatorRect.centerY() + mTextSize / 4, mPaint); } if (mRightHit && mRightPointerID != -1) { final int indicatorRightLeft = (int) (mRangeBarRectSelected.right - (float) rightWidth / 2); final int indicatorRightTop = mPaddingRect.top; mRightIndicatorRect.left = indicatorRightLeft; mRightIndicatorRect.top = indicatorRightTop; mRightIndicatorRect.right = indicatorRightLeft + indicatorWidth; mRightIndicatorRect.bottom = indicatorRightTop + indicatorHeight; indicatorDrawable.setBounds(mRightIndicatorRect); indicatorDrawable.draw(canvas); mPaint.setColor(Color.WHITE); mValueRight = getValueByIndex(mRightCursorIndex); if (mValueRight == -1) { canvas.drawText("", mRightIndicatorRect.centerX() - mPaint.measureText("") / 2, mRightIndicatorRect.centerY() + mTextSize / 4, mPaint); } else { canvas.drawText(mValueRight + "", mRightIndicatorRect.centerX() - mPaint.measureText(mValueRight + "") / 2, mRightIndicatorRect.centerY() + mTextSize / 4, mPaint); } } triggerCallback(); }
From source file:com.summer.helper.view.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from ww w.j a v a 2s . c o m } final int height = getHeight(); // 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); rectPaint.setStrokeWidth(tabStrokeWith); canvas.drawLine(lineLeft + mTabWidth, height - 5, lineRight - mTabWidth, height - 5, rectPaint); // draw underline rectPaint.setColor(underlineColor); rectPaint.setStrokeWidth(3); 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); } }
From source file:com.jjoe64.graphview.Viewport.java
/** * will be first called in order to draw * the canvas/*from ww w . ja v a 2 s. c o m*/ * Used to draw the background * * @param c canvas. */ public void drawFirst(Canvas c) { // draw background if (mBackgroundColor != Color.TRANSPARENT) { mPaint.setColor(mBackgroundColor); c.drawRect(mGraphView.getGraphContentLeft(), mGraphView.getGraphContentTop(), mGraphView.getGraphContentLeft() + mGraphView.getGraphContentWidth(), mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), mPaint); } if (mDrawBorder) { Paint p; if (mBorderPaint != null) { p = mBorderPaint; } else { p = mPaint; p.setColor(getBorderColor()); } c.drawLine(mGraphView.getGraphContentLeft(), mGraphView.getGraphContentTop(), mGraphView.getGraphContentLeft(), mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), p); c.drawLine(mGraphView.getGraphContentLeft(), mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), mGraphView.getGraphContentLeft() + mGraphView.getGraphContentWidth(), mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), p); // on the right side if we have second scale if (mGraphView.mSecondScale != null) { c.drawLine(mGraphView.getGraphContentLeft() + mGraphView.getGraphContentWidth(), mGraphView.getGraphContentTop(), mGraphView.getGraphContentLeft() + mGraphView.getGraphContentWidth(), mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), p); } } }
From source file:bigshots.people_helping_people.scroll_iew_lib.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from ww w . j ava 2 s . c o m*/ } final int height = getHeight(); // 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); // draw underline rectPaint.setColor(underlineColor); 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); } updateTextColor(); }
From source file:com.android.screenspeak.contextmenu.RadialMenuView.java
private void drawCancel(Canvas canvas) { final float centerX = mCenter.x; final float centerY = mCenter.y; final float radius = mInnerRadius; final float iconRadius = (radius / 4.0f); final RectF dotBounds = new RectF((centerX - radius), (centerY - radius), (centerX + radius), (centerY + radius));//from ww w . j a v a2s .c o m // Apply the appropriate color filters. final boolean selected = (mFocusedItem == null); mPaint.setStyle(Style.FILL); mPaint.setColor(selected ? mSelectionColor : mCenterFillColor); mPaint.setShadowLayer(mShadowRadius, 0, 0, (selected ? mSelectionShadowColor : mTextShadowColor)); canvas.drawOval(dotBounds, mPaint); mPaint.setShadowLayer(0, 0, 0, 0); mPaint.setStyle(Style.STROKE); mPaint.setColor(selected ? mSelectionTextFillColor : mCenterTextFillColor); mPaint.setStrokeCap(Cap.SQUARE); mPaint.setStrokeWidth(10.0f); canvas.drawLine((centerX - iconRadius), (centerY - iconRadius), (centerX + iconRadius), (centerY + iconRadius), mPaint); canvas.drawLine((centerX + iconRadius), (centerY - iconRadius), (centerX - iconRadius), (centerY + iconRadius), mPaint); }
From source file:com.byagowi.persiancalendar.view.QiblaCompassView.java
public void drawMoon(Canvas canvas) { moonPaint.reset();//w w w . j a va 2s . co m moonPaint.setColor(Color.WHITE); moonPaint.setStyle(Paint.Style.FILL_AND_STROKE); moonPaintB.reset();// moon Paint Black moonPaintB.setColor(Color.BLACK); moonPaintB.setStyle(Paint.Style.FILL_AND_STROKE); moonPaintO.reset();// moon Paint for Oval moonPaintO.setColor(Color.WHITE); moonPaintO.setStyle(Paint.Style.FILL_AND_STROKE); moonPaintD.reset();// moon Paint for Diameter // draw moonPaintD.setColor(Color.GRAY); moonPaintD.setStyle(Paint.Style.STROKE); double moonPhase = sunMoonPosition.getMoonPhase(); if (moonPosition.getElevation() > -5) { canvas.rotate((float) moonPosition.getAzimuth() - 360, px, py); int eOffset = (int) ((moonPosition.getElevation() / 90) * Radius); // elevation Offset 0 for 0 degree; r for 90 degree moonRect.set(px - r, py + eOffset - Radius - r, px + r, py + eOffset - Radius + r); canvas.drawArc(moonRect, 90, 180, false, moonPaint); canvas.drawArc(moonRect, 270, 180, false, moonPaintB); int arcWidth = (int) ((moonPhase - 0.5) * (4 * r)); moonPaintO.setColor(arcWidth < 0 ? Color.BLACK : Color.WHITE); moonOval.set(px - Math.abs(arcWidth) / 2, py + eOffset - Radius - r, px + Math.abs(arcWidth) / 2, py + eOffset - Radius + r); canvas.drawArc(moonOval, 0, 360, false, moonPaintO); canvas.drawArc(moonRect, 0, 360, false, moonPaintD); moonPaintD.setPathEffect(dashPath); canvas.drawLine(px, py - Radius, px, py + Radius, moonPaintD); moonPaintD.setPathEffect(null); canvas.restore(); } }
From source file:com.jumeng.shop.view.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from ww w . ja v a 2 s.c om*/ } final int height = getHeight(); rectPaint.setColor(indicatorColor); 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); // draw underline rectPaint.setColor(underlineColor); 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); } }
From source file:com.samebits.beacon.locator.ui.view.RadarScanView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int center = getWidth() / 2; int radius = center - 8; // Draw the rings final Paint gridPaint = mGridPaint; canvas.drawCircle(center, center, radius, gridPaint); canvas.drawCircle(center, center, radius * 3 / 4, gridPaint); canvas.drawCircle(center, center, radius >> 1, gridPaint); canvas.drawCircle(center, center, radius >> 2, gridPaint); int blipRadius = (int) (mDistanceRatio * radius); final long now = SystemClock.uptimeMillis(); if (mSweepTime > 0) { // Draw the sweep. Radius is determined by how long ago it started long sweepDifference = now - mSweepTime; if (sweepDifference < 512L) { int sweepRadius = (int) (((radius + 6) * sweepDifference) >> 9); canvas.drawCircle(center, center, sweepRadius, mSweepPaint0); canvas.drawCircle(center, center, sweepRadius - 2, mSweepPaint1); canvas.drawCircle(center, center, sweepRadius - 4, mSweepPaint2); // Note when the sweep has passed the blip boolean before = sweepRadius < blipRadius; if (!before && mSweepBefore) { mSweepBefore = false;/*from w ww. j a va2 s .c om*/ mBlipTime = now; } } else { mSweepTime = now + 1000; mSweepBefore = true; } postInvalidate(); } // Draw horizontal and vertical lines canvas.drawLine(center, center - (radius >> 2) + 6, center, center - radius - 6, gridPaint); canvas.drawLine(center, center + (radius >> 2) - 6, center, center + radius + 6, gridPaint); canvas.drawLine(center - (radius >> 2) + 6, center, center - radius - 6, center, gridPaint); canvas.drawLine(center + (radius >> 2) - 6, center, center + radius + 6, center, gridPaint); // Draw X in the center of the screen canvas.drawLine(center - 4, center - 4, center + 4, center + 4, gridPaint); canvas.drawLine(center - 4, center + 4, center + 4, center - 4, gridPaint); if (mHaveDetected) { // Draw the blip. Alpha is based on how long ago the sweep crossed the blip long blipDifference = now - mBlipTime; gridPaint.setAlpha(255 - (int) ((128 * blipDifference) >> 10)); double bearingToTarget = mLast_bearing; double drawingAngle = Math.toRadians(bearingToTarget) - (Math.PI / 2); float cos = (float) Math.cos(drawingAngle); float sin = (float) Math.sin(drawingAngle); addText(canvas, getRatioDistanceText(0.25f), center, center + (radius >> 2)); addText(canvas, getRatioDistanceText(0.5f), center, center + (radius >> 1)); addText(canvas, getRatioDistanceText(0.75f), center, center + radius * 3 / 4); addText(canvas, getRatioDistanceText(1.0f), center, center + radius); for (Map.Entry<String, DetectedBeacon> entry : mBeacons.entrySet()) { //String key = entry.getKey(); DetectedBeacon dBeacon = entry.getValue(); System.out.println("value: " + dBeacon); // drawing the beacon if (((System.currentTimeMillis() - dBeacon.getTimeLastSeen()) / 1000 < 5)) { canvas.drawBitmap(mBlip, center + (cos * distanceToPix(dBeacon.getDistance())) - 8, center + (sin * distanceToPix(dBeacon.getDistance())) - 8, gridPaint); } } gridPaint.setAlpha(255); } }
From source file:net.osmand.plus.views.controls.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from w ww. j a v a 2 s . c o m*/ } final int height = getHeight(); // draw underline if (indicatorBgColor != Color.TRANSPARENT) { rectPaint.setColor(indicatorBgColor); // underlineColor canvas.drawRect(padding, height - indicatorHeight, tabsContainer.getWidth() + padding, height, rectPaint); } // draw indicator line Pair<Float, Float> lines = getIndicatorCoordinates(); rectPaint.setColor(indicatorColor); // indicatorColor canvas.drawRect(lines.first + padding, height - indicatorHeight, lines.second + padding, height, rectPaint); // draw underline rectPaint.setColor(underlineColor); //underlineColor canvas.drawRect(padding, height - underlineHeight, tabsContainer.getWidth() + padding, height, rectPaint); // draw divider if (dividerWidth != 0) { dividerPaint.setStrokeWidth(dividerWidth); 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); } } }
From source file:com.seek.ruler.SimpleRulerView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); /**/*from ww w . j a va 2 s . c o m*/ * here is the start the selected the end * / / / * |||||||||||||||||||||||||||||||||||||||||||||||||| * | | | | | | | | | | | * 0 1 2 * \____mViewScopeSize_____/ * */ int start = mSelectedIndex - mViewScopeSize; int end = mSelectedIndex + mViewScopeSize; start = Math.max(start, -mViewScopeSize * 2); end = Math.min(end, mRulerCount + mViewScopeSize * 2); if (mSelectedIndex == mMaxValue) { end += mViewScopeSize; } else if (mSelectedIndex == mMinValue) { start -= mViewScopeSize; } float x = start * mIntervalDis; float markHeight = mHeight - mTextSize; for (int i = start; i < end; i++) { // draw line int remainderBy2 = i % 2; int remainderBy5 = i % 5; if (i == mSelectedIndex) { mRulerPaint.setColor(mHighlightColor); } else { mRulerPaint.setColor(mRulerColor); } if (remainderBy2 == 0 && remainderBy5 == 0) { canvas.drawLine(x, 0, x, 0 + markHeight, mRulerPaint); } else if (remainderBy2 != 0 && remainderBy5 == 0) { canvas.drawLine(x, 0, x, markHeight * 3 / 4, mRulerPaint); } else { canvas.drawLine(x, 0, x, markHeight / 2, mRulerPaint); } // draw text if (mRulerCount > 0 && i >= 0 && i < mRulerCount) { mTextPaint.setColor(mTextColor); if (mSelectedIndex == i) { mTextPaint.setColor(mHighlightColor); } if (i % 10 == 0) { String text = null; if (mTextList != null && mTextList.size() > 0) { int index = i / 10; if (index < mTextList.size()) { text = mTextList.get(index); } else { text = ""; } } else { text = format(i * mIntervalValue + mMinValue); } canvas.drawText(text, 0, text.length(), x, mHeight, mTextPaint); } } x += mIntervalDis; } }