List of usage examples for android.graphics Canvas drawRect
public void drawRect(float left, float top, float right, float bottom, @NonNull Paint paint)
From source file:com.summer.helper.view.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;// w w w . j a v a2s . 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:am.widget.indicatortabstrip.IndicatorTabStrip.java
/** * ??// w ww . jav a 2s .c om * * @param canvas * @param position ??? * @param itemWidth ? * @param itemHeight ? */ protected void drawItemGradient(Canvas canvas, int position, int itemWidth, int itemHeight) { if (mGradient == null || !mGradient.isStateful()) return; final int normalColor = mGradient.getDefaultColor(); final int selectedColor = mGradient.getColorForState(SELECTED_STATE_SET, normalColor); if (position == mNextPager) { mTextPaint.setColor(getColor(normalColor, selectedColor, mOffset)); } else if (position == mCurrentPager) { mTextPaint.setColor(getColor(normalColor, selectedColor, 1 - mOffset)); } else { mTextPaint.setColor(normalColor); } final float moveX = ViewCompat.getPaddingStart(this) + (itemWidth + getIntervalWidth()) * position; final float moveY = getPaddingTop(); final int restWidth = position == getItemCount() - 1 ? getLastItemWidth() : itemWidth; canvas.save(); canvas.translate(moveX, moveY); canvas.drawRect(0, 0, restWidth, itemHeight, mTextPaint); canvas.restore(); }
From source file:com.android.customviewpagerindicator.viewpagerindicator.UnderlinePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;//from w w w. j a v a 2s .co m } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } /* 1. //?CustomUnderlinePageIndicator paddingLeft?paddingRight //paddingLeft?paddingRight????? final int paddingLeft = getPaddingLeft(); //?title?? 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();*/ // 2.?CustomUnderlinePageIndicator paddingLeft?paddingRight //paddingLeft?paddingRight???????? final int paddingLeft = getPaddingLeft(); final int paddingRight = getPaddingRight(); // ?title?? final float pageWidth = (getWidth()) / (1f * count); final float left = paddingLeft + pageWidth * (mCurrentPage + mPositionOffset); final float right = left + pageWidth - paddingLeft - paddingRight; final float top = getPaddingTop(); final float bottom = getHeight() - getPaddingBottom(); canvas.drawRect(left, top, right, bottom, mPaint); }
From source file:net.droidsolutions.droidcharts.core.renderer.xy.AbstractXYItemRenderer.java
/** * Fills a band between two values on the range axis. This can be used to * color bands between the grid lines.// w w w .j a v a 2 s . c om * * @param g2 the graphics device. * @param plot the plot. * @param axis the range axis. * @param dataArea the data area. * @param start the start value. * @param end the end value. */ public void fillRangeGridBand(Canvas g2, XYPlot plot, ValueAxis axis, Rectangle2D dataArea, double start, double end) { double y1 = axis.valueToJava2D(start, dataArea, plot.getRangeAxisEdge()); double y2 = axis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge()); Rectangle2D band; if (plot.getOrientation() == PlotOrientation.VERTICAL) { band = new Rectangle2D.Double(dataArea.getMinX(), Math.min(y1, y2), dataArea.getWidth(), Math.abs(y2 - y1)); } else { band = new Rectangle2D.Double(Math.min(y1, y2), dataArea.getMinY(), Math.abs(y2 - y1), dataArea.getHeight()); } Paint paint = plot.getRangeTickBandPaint(); if (paint != null) { paint.setStyle(Paint.Style.FILL); g2.drawRect((float) band.getMinX(), (float) band.getMinY(), (float) band.getMaxX(), (float) band.getMaxY(), paint); } }
From source file:net.droidsolutions.droidcharts.core.renderer.xy.AbstractXYItemRenderer.java
/** * Fills a band between two values on the axis. This can be used to color * bands between the grid lines./*from w w w .j av a2 s .c o m*/ * * @param g2 the graphics device. * @param plot the plot. * @param axis the domain axis. * @param dataArea the data area. * @param start the start value. * @param end the end value. */ public void fillDomainGridBand(Canvas g2, XYPlot plot, ValueAxis axis, Rectangle2D dataArea, double start, double end) { double x1 = axis.valueToJava2D(start, dataArea, plot.getDomainAxisEdge()); double x2 = axis.valueToJava2D(end, dataArea, plot.getDomainAxisEdge()); Rectangle2D band; if (plot.getOrientation() == PlotOrientation.VERTICAL) { band = new Rectangle2D.Double(Math.min(x1, x2), dataArea.getMinY(), Math.abs(x2 - x1), dataArea.getWidth()); } else { band = new Rectangle2D.Double(dataArea.getMinX(), Math.min(x1, x2), dataArea.getWidth(), Math.abs(x2 - x1)); } Paint paint = plot.getDomainTickBandPaint(); if (paint != null) { paint.setStyle(Paint.Style.FILL); g2.drawRect((float) band.getMinX(), (float) band.getMinY(), (float) band.getMaxX(), (float) band.getMaxY(), paint); } }
From source file:com.vnp.myvinaphone.util.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); //get screen//from w ww.j av a2 s.c o m // int h = getHeight(); // int w = getWidth(); // if (isInEditMode() || tabCount == 0) { return; } final int height = getHeight(); final int width = getWidth(); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); // float lineLeft = currentTab.getLeft(); // float lineRight = currentTab.getRight(); float lineLeft = currentPosition * width / tabCount; float lineRight = (currentPosition + 1) * width / tabCount; // 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 nextTabLeft = (currentPosition + 1) * width / tabCount; // final float nextTabRight = nextTab.getRight(); final float nextTabRight = (currentPosition + 2) * width / tabCount; ; // 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); // canvas.drawLine( (i+1)*width/tabCount, dividerPadding, (i+1)*width/tabCount, height - dividerPadding, dividerPaint); // } }
From source file:com.dashihui.afford.ui.widget.WdtPagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//from w w w .j a v a 2 s . c o m } final int height = getHeight(); // draw indicator line //tab rectPaint.setColor(getResources().getColor(R.color.btfontBlue)); // 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) { //?tab? View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); if (lineLeft != nextTabLeft && yesBoolean < 3) { //??tab //? // Log.i(TAG, "??===TTT==nextTabLeft=====>"+nextTabLeft); // Log.i(TAG, "??===TTT==lineLeft=====>"+lineLeft); yesBoolean++; } else { lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); yesBoolean++; } } 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.blestep.sportsbracelet.view.TimelineChartView.java
private void drawBarItems(Canvas c, SparseArray<Object[]> data, double maxValue) { final float halfItemBarWidth = mBarItemWidth / 2; final float height = mGraphArea.height(); final Paint seriesBgPaint; final Paint highlightSeriesBgPaint; synchronized (mLock) { seriesBgPaint = mBarItemBgPaint; highlightSeriesBgPaint = mHighlightBarItemBgPaint; }/*from w ww. j a v a 2s . c o m*/ // Apply zoom animation final float graphCenterX = mGraphArea.left + (mGraphArea.width() / 2); final int size = data.size() - 1; for (int i = mItemsOnScreen[1]; i >= mItemsOnScreen[0] && i <= data.size(); i--) { final float barCenterX = graphCenterX + mCurrentOffset - (mBarWidth * (size - i)); // ? double value = (double) data.valueAt(i)[1]; float barTop = (float) (height - ((height * ((value * 100) / maxValue)) / 100)) + mTopSpaceHeight; float barBottom = height; float barLeft = barCenterX - halfItemBarWidth; float barRight = barCenterX + halfItemBarWidth; final Paint paint; // ? paint = barLeft < graphCenterX && barRight > graphCenterX && (mLastPosition == mCurrentPosition || (mState != STATE_SCROLLING)) ? highlightSeriesBgPaint : seriesBgPaint; // c.drawRect(barLeft, mGraphArea.top + barTop, barRight, mGraphArea.top + barBottom, paint); } }
From source file:com.next.PagerSlidingTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*w w w .j a v a 2s . co m*/ } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); updateTabColor(tabsContainer.getChildAt(currentPosition), 1.0f); // 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); /* if(currentPositionOffset > 0.5) { updateTabColor(currentTab, tabTextColorNormal); updateTabColor(nextTab, tabTextColor); } else { updateTabColor(currentTab, tabTextColor); updateTabColor(nextTab, tabTextColorNormal); } */ updateTabColor(currentTab, 1 - currentPositionOffset); updateTabColor(nextTab, currentPositionOffset); } 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.dashihui.afford.ui.widget.WdtPagerTabServerTime.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;/*from w w w .j av a2 s . co m*/ } final int height = getHeight(); // draw indicator line //tab rectPaint.setColor(getResources().getColor(R.color.btfontBlue)); // 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) { //?tab? View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); if (lineLeft != nextTabLeft && yesBoolean < 2) { //??tab //? // Log.i(TAG, "??===TTT==nextTabLeft=====>"+nextTabLeft); // Log.i(TAG, "??===TTT==lineLeft=====>"+lineLeft); yesBoolean++; } else { lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); yesBoolean++; } } 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); } }