Example usage for android.graphics Canvas drawRect

List of usage examples for android.graphics Canvas drawRect

Introduction

In this page you can find the example usage for android.graphics Canvas drawRect.

Prototype

public void drawRect(@NonNull Rect r, @NonNull Paint paint) 

Source Link

Document

Draw the specified Rect using the specified Paint.

Usage

From source file:com.example.SmartBoard.DrawingView.java

@Override
protected void onDraw(Canvas canvas) {

    drawCanvas.drawPath(drawPath, drawPaint);
    drawCanvas.drawPath(drawPathRecv, drawPaintSender);

    if (rectMode) {
        //draw rectangle
        drawPaint.setXfermode(null);/*from   www  .j  a v a  2 s .c  o  m*/
        onDrawRectangle(canvas);
    } else if (circleMode) {
        drawPaint.setXfermode(null);
        onDrawCircle(canvas);
    } else if (lineMode) {
        drawPaint.setXfermode(null);
        onDrawLine(canvas);
    } else if (textMode) {
        drawPaint.setXfermode(null);
        onDrawText(canvas);
    } else if (dragMode && !dragFinished) {
        drawPaint.setXfermode(null);
        onDragDraw(canvas, dragX, dragY);
    } else if (colorDropperMode) {
        drawPaint.setXfermode(null);
        onDrawColorDropper(canvas, dropperX, dropperY);
    } else if (textSizeMode) {
        drawPaint.setXfermode(null);
    }

    canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint);

    //redraw objects

    Paint tempPaint = new Paint();
    tempPaint.setStyle(Paint.Style.STROKE);

    for (String key : textObjects.keySet()) {
        if (key.compareTo("") == 0) {
            continue;
        }
        JSONObject o = textObjects.get(key);

        tempPaint.setColor(o.optInt("color"));
        tempPaint.setStrokeWidth(o.optInt("size"));

        canvas.drawBitmap(mqtt.stringToBitmap(o.optString("textBitmap")), o.optInt("x"), o.optInt("y"),
                tempPaint);

    }

    for (String key : objectDrawables.keySet()) {
        //hashtable problems no time to explain. But it creates a duplicate of last item I add to the table.
        //So dont print duplicates which have empty string key values
        if (key.compareTo("") == 0) {
            continue;
        }
        JSONObject o = objectDrawables.get(key);

        String objectType = o.optString("type");
        tempPaint.setColor(o.optInt("color"));
        tempPaint.setStrokeWidth(o.optInt("size"));

        if (objectType.compareTo("Circle") == 0) {
            canvas.drawCircle(o.optInt("x"), o.optInt("y"), o.optInt("radius"), tempPaint);

        } else if (objectType.compareTo("Line") == 0) {
            canvas.drawLine(o.optInt("startx"), o.optInt("starty"), o.optInt("stopx"), o.optInt("stopy"),
                    tempPaint);

        } else if (objectType.compareTo("Rectangle") == 0) {
            canvas.drawRect(Rect.unflattenFromString(o.optString("dimens")), tempPaint);
        } else if (objectType.compareTo("Text") == 0) {
            //canvas.drawRect(Rect.unflattenFromString(o.optString("region")), drawPaint);
            canvas.drawBitmap(mqtt.stringToBitmap(o.optString("textBitmap")), o.optInt("x"), o.optInt("y"),
                    tempPaint);

        }
    }

}

From source file:com.viewsforandroid.foundry.sample.indicators.NumericPageIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mViewPager == null) {
        return;//from  w  w  w .jav  a 2s . c om
    }
    final int count = mViewPager.getAdapter().getCount();
    if (count == 0) {
        return;
    }

    // mCurrentPage is -1 on first start and after orientation changed. If
    // so, retrieve the correct index from viewpager.
    if (mCurrentPage == -1 && mViewPager != null) {
        mCurrentPage = mViewPager.getCurrentItem();
    }

    // Handle the first time we draw the view, when onMeasure has not been
    // called yet
    if (mTextFirstPart == null) {
        updateText();
    }

    // Draw the main text (e.g. "Page 1 of 20"). The hardest part is drawing
    // the page
    // number itself, because of the animated effect in which the current
    // page fades
    // out and the next one fades in. In order to implement this effect we
    // are forced to
    // draw the text in four "chunks": the first part ("Page "), the current
    // page
    // number ("1"), the next page number ("2"), and the last part
    // (" of 20").
    // To implement the fade in and fade out animations we simply change the
    // alpha
    // of the page number text, relative to the view pager scroll

    final float currentPageWeight = 1 - mPageOffset;
    final float nextPageWeight = mPageOffset;
    final float firstPartWidth = mPaintText.measureText(mTextFirstPart);
    final String currentPageNumber = Integer.toString(mCurrentPage + 1);
    final String nextPageNumber = Integer.toString(mCurrentPage + 2);
    final float currentPageNumberWidth = mPaintText.measureText(currentPageNumber);
    final float nextPageNumberWidth = mPaintText.measureText(nextPageNumber);
    final float pageNumberWidth = currentPageWeight * currentPageNumberWidth
            + nextPageWeight * nextPageNumberWidth;
    final float lastPartWidth = mPaintText.measureText(mTextLastPart);
    final float totalWidth = firstPartWidth + pageNumberWidth + lastPartWidth;
    float currentX = (getWidth() - totalWidth) / 2;
    canvas.drawText(mTextFirstPart, currentX, mTextBottom, mPaintText);
    currentX += firstPartWidth;
    final float pageNumberCenterX = currentX + pageNumberWidth / 2;

    final int startAlpha = Color.alpha(mColorPageNumberText);
    final int endAlpha = 0;
    final float currentPageNumberAlpha = currentPageWeight * startAlpha + nextPageWeight * endAlpha;

    mPaintPageNumberText.setAlpha((int) currentPageNumberAlpha);
    canvas.drawText(currentPageNumber, pageNumberCenterX - currentPageNumberWidth / 2, mTextBottom,
            mPaintPageNumberText);

    final float nextPageNumberAlpha = nextPageWeight * startAlpha + currentPageWeight * endAlpha;
    mPaintPageNumberText.setAlpha((int) nextPageNumberAlpha);
    canvas.drawText(nextPageNumber, pageNumberCenterX - nextPageNumberWidth / 2, mTextBottom,
            mPaintPageNumberText);

    currentX += pageNumberWidth;
    canvas.drawText(mTextLastPart, currentX, mTextBottom, mPaintText);

    // Draw the "start" and "end" buttons
    if (mShowStartEndButtons) {
        final int textStartAlpha = Color.alpha(mColorText);
        final int textEndAlpha = 0;
        if (mCurrentPage != 0 && mStartDown) {
            canvas.drawRect(mRectStart, mPaintButtonBackground);
        }
        if (mCurrentPage != count - 1 && mEndDown) {
            canvas.drawRect(mRectEnd, mPaintButtonBackground);
        }
        if (mCurrentPage == 0) {
            mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha));
        }
        canvas.drawText(mTextStartButton, mRectStart.centerX() - mWidthStartText / 2, mRectStartText.bottom,
                mPaintText);
        mPaintText.setAlpha(Color.alpha(mColorText));
        if (mCurrentPage < count - 1) {
            if (mCurrentPage == count - 2) {
                mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha));
            }
            canvas.drawText(mTextEndButton, mRectEnd.centerX() - mWidthEndText / 2, mRectEndText.bottom,
                    mPaintText);
            mPaintText.setAlpha(Color.alpha(mColorText));
        }
    }

    // Draw the "next" and "previous" buttons
    if (mShowChangePageButtons) {
        final int textStartAlpha = Color.alpha(mColorText);
        final int textEndAlpha = 0;
        if (mCurrentPage != 0 && mPreviousDown) {
            canvas.drawRect(mRectPrevious, mPaintButtonBackground);
        }
        if (mCurrentPage != count - 1 && mNextDown) {
            canvas.drawRect(mRectNext, mPaintButtonBackground);
        }
        if (mCurrentPage == 0) {
            mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha));
        }
        canvas.drawText(mTextPreviousButton, mRectPrevious.centerX() - mWidthPreviousText / 2,
                mRectPreviousText.bottom, mPaintText);
        mPaintText.setAlpha(Color.alpha(mColorText));
        if (mCurrentPage < count - 1) {
            if (mCurrentPage == count - 2) {
                mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha));
            }
            canvas.drawText(mTextNextButton, mRectNext.centerX() - mWidthNextText / 2, mRectNextText.bottom,
                    mPaintText);
            mPaintText.setAlpha(Color.alpha(mColorText));
        }
    }
}

From source file:com.manuelpeinado.numericpageindicator.NumericPageIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mViewPager == null) {
        return;//  ww w  . ja v a 2  s  . c  o  m
    }
    final int count = mViewPager.getAdapter().getCount();
    if (count == 0) {
        return;
    }

    // mCurrentPage is -1 on first start and after orientation changed. If
    // so, retrieve the correct index from viewpager.
    if (mCurrentPage == -1 && mViewPager != null) {
        mCurrentPage = mViewPager.getCurrentItem();
    }

    // Handle the first time we draw the view, when onMeasure has not been
    // called yet
    if (mTextFirstPart == null) {
        updateText();
    }

    // Draw the main text (e.g. "Page 1 of 20"). The hardest part is drawing
    // the page
    // number itself, because of the animated effect in which the current
    // page fades
    // out and the next one fades in. In order to implement this effect we
    // are forced to
    // draw the text in four "chunks": the first part ("Page "), the current
    // page
    // number ("1"), the next page number ("2"), and the last part
    // (" of 20").
    // To implement the fade in and fade out animations we simply change the
    // alpha
    // of the page number text, relative to the view pager scroll

    final float currentPageWeight = 1 - mPageOffset;
    final float nextPageWeight = mPageOffset;
    final float firstPartWidth = mPaintText.measureText(mTextFirstPart);
    final String currentPageNumber = Integer.toString(mCurrentPage + 1);
    final String nextPageNumber = Integer.toString(mCurrentPage + 2);
    final float currentPageNumberWidth = mPaintText.measureText(currentPageNumber);
    final float nextPageNumberWidth = mPaintText.measureText(nextPageNumber);
    final float pageNumberWidth = currentPageWeight * currentPageNumberWidth
            + nextPageWeight * nextPageNumberWidth;
    final float lastPartWidth = mPaintText.measureText(mTextLastPart);
    final float totalWidth = firstPartWidth + pageNumberWidth + lastPartWidth;
    float currentX = (getWidth() - totalWidth) / 2;
    canvas.drawText(mTextFirstPart, currentX, mTextBottom, mPaintText);
    currentX += firstPartWidth;
    final float pageNumberCenterX = currentX + pageNumberWidth / 2;

    final int startAlpha = Color.alpha(mColorPageNumberText);
    final int endAlpha = 0;
    final float currentPageNumberAlpha = currentPageWeight * startAlpha + nextPageWeight * endAlpha;

    mPaintPageNumberText.setAlpha((int) currentPageNumberAlpha);
    canvas.drawText(currentPageNumber, pageNumberCenterX - currentPageNumberWidth / 2, mTextBottom,
            mPaintPageNumberText);

    final float nextPageNumberAlpha = nextPageWeight * startAlpha + currentPageWeight * endAlpha;
    mPaintPageNumberText.setAlpha((int) nextPageNumberAlpha);
    canvas.drawText(nextPageNumber, pageNumberCenterX - nextPageNumberWidth / 2, mTextBottom,
            mPaintPageNumberText);

    currentX += pageNumberWidth;
    canvas.drawText(mTextLastPart, currentX, mTextBottom, mPaintText);

    // Draw the "start" and "end" buttons
    if (mShowStartEndButtons) {
        final int textStartAlpha = Color.alpha(mColorText);
        final int textEndAlpha = 0;
        if (mCurrentPage != 0 && mStartDown) {
            canvas.drawRect(mRectStart, mPaintButtonBackground);
        }
        if (mCurrentPage != count - 1 && mEndDown) {
            canvas.drawRect(mRectEnd, mPaintButtonBackground);
        }
        if (mCurrentPage == 0) {
            mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha));
        }
        if (!mShowImagesForPageControls) {
            canvas.drawText(mTextStartButton, mRectStart.centerX() - mWidthStartText / 2, mRectStartText.bottom,
                    mPaintText);
        } else if (mStartButtonImage != null) {
            canvas.drawBitmap(mStartButtonImage, mRectStart.centerX() - mStartButtonImage.getWidth() / 2,
                    mRectStart.centerY() - mStartButtonImage.getHeight() / 2, mPaintText);
        }
        mPaintText.setAlpha(Color.alpha(mColorText));
        if (mCurrentPage < count - 1) {
            if (mCurrentPage == count - 2) {
                mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha));
            }
            if (!mShowImagesForPageControls) {
                canvas.drawText(mTextEndButton, mRectEnd.centerX() - mWidthEndText / 2, mRectEndText.bottom,
                        mPaintText);
            } else if (mEndButtonImage != null) {
                canvas.drawBitmap(mEndButtonImage, mRectEnd.centerX() - mEndButtonImage.getWidth() / 2,
                        mRectEnd.centerY() - mEndButtonImage.getHeight() / 2, mPaintText);
            }
            mPaintText.setAlpha(Color.alpha(mColorText));
        }
    }

    // Draw the "next" and "previous" buttons
    if (mShowChangePageButtons) {
        final int textStartAlpha = Color.alpha(mColorText);
        final int textEndAlpha = 0;
        if (mCurrentPage != 0 && mPreviousDown) {
            canvas.drawRect(mRectPrevious, mPaintButtonBackground);
        }
        if (mCurrentPage != count - 1 && mNextDown) {
            canvas.drawRect(mRectNext, mPaintButtonBackground);
        }
        if (mCurrentPage == 0) {
            mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha));
        }
        if (!mShowImagesForPageControls) {
            canvas.drawText(mTextPreviousButton, mRectPrevious.centerX() - mWidthPreviousText / 2,
                    mRectPreviousText.bottom, mPaintText);
        } else if (mPreviousButtonImage != null) {
            canvas.drawBitmap(mPreviousButtonImage,
                    mRectPrevious.centerX() - mPreviousButtonImage.getWidth() / 2,
                    mRectPrevious.centerY() - mPreviousButtonImage.getHeight() / 2, mPaintText);
        }
        mPaintText.setAlpha(Color.alpha(mColorText));
        if (mCurrentPage < count - 1) {
            if (mCurrentPage == count - 2) {
                mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha));
            }
            if (!mShowImagesForPageControls) {
                canvas.drawText(mTextNextButton, mRectNext.centerX() - mWidthNextText / 2, mRectNextText.bottom,
                        mPaintText);
            } else if (mNextButtonImage != null) {
                canvas.drawBitmap(mNextButtonImage, mRectNext.centerX() - mNextButtonImage.getWidth() / 2,
                        mRectNext.centerY() - mNextButtonImage.getHeight() / 2, mPaintText);
            }
            mPaintText.setAlpha(Color.alpha(mColorText));
        }
    }
}

From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java

/**
 * Draws the month days.//from  w ww  .jav a 2  s.c  o m
 */
@SuppressWarnings("ConstantConditions")
private void drawDays(Canvas canvas) {
    final TextPaint p = mDayPaint;
    final int headerHeight = mMonthHeight + mDayOfWeekHeight;
    //final int rowHeight = mDayHeight;
    final float rowHeight = mDayHeight;
    //final int colWidth = mCellWidth;
    final float colWidth = mCellWidth;

    // Text is vertically centered within the row height.
    final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
    //int rowCenter = headerHeight + rowHeight / 2;
    float rowCenter = headerHeight + rowHeight / 2f;

    for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) {
        //final int colCenter = colWidth * col + colWidth / 2;
        final float colCenter = colWidth * col + colWidth / 2f;
        //final int colCenterRtl;
        final float colCenterRtl;
        if (SUtils.isLayoutRtlCompat(this)) {
            colCenterRtl = mPaddedWidth - colCenter;
        } else {
            colCenterRtl = colCenter;
        }

        int stateMask = 0;

        final boolean isDayEnabled = isDayEnabled(day);
        if (isDayEnabled) {
            stateMask |= SUtils.STATE_ENABLED;
        }

        final boolean isDayInActivatedRange = mActivatedDays.isValid() && mActivatedDays.isActivated(day);
        final boolean isSelected = mActivatedDays.isSelected(day);

        if (isSelected) {
            stateMask |= SUtils.STATE_ACTIVATED;
            canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint);
        } else if (isDayInActivatedRange) {
            stateMask |= SUtils.STATE_ACTIVATED;

            int bgShape = DRAW_RECT;

            if (mActivatedDays.isSingleDay()) {
                if (mActivatedDays.isStartOfMonth()) {
                    bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT;
                } else {
                    bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT;
                }
            } else if (mActivatedDays.isStartingDayOfRange(day)) {
                bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT;
            } else if (mActivatedDays.isEndingDayOfRange(day)) {
                bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT;
            }

            // Use height to constrain the protrusion of the arc
            boolean constrainProtrusion = colWidth > (rowHeight - (2 * mPaddingRangeIndicator));
            float horDistFromCenter = constrainProtrusion ? rowHeight / 2f - mPaddingRangeIndicator
                    : colWidth / 2f;

            switch (bgShape) {
            case DRAW_RECT_WITH_CURVE_ON_LEFT:
                int leftRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl - horDistFromCenter) + 1
                        : (int) (colCenterRtl - horDistFromCenter);

                int leftRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl + horDistFromCenter) + 1
                        : (int) (colCenterRtl + horDistFromCenter);

                RectF leftArcRect = new RectF(leftRectArcLeft,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, leftRectArcRight,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator);

                canvas.drawArc(leftArcRect, 90, 180, true, mDayRangeSelectorPaint);

                canvas.drawRect(new RectF(leftArcRect.centerX(),
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            case DRAW_RECT_WITH_CURVE_ON_RIGHT:
                int rightRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl - horDistFromCenter) + 1
                        : (int) (colCenterRtl - horDistFromCenter);

                int rightRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl + horDistFromCenter) + 1
                        : (int) (colCenterRtl + horDistFromCenter);

                RectF rightArcRect = new RectF(rightRectArcLeft,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightRectArcRight,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator);

                canvas.drawArc(rightArcRect, 270, 180, true, mDayRangeSelectorPaint);

                canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightArcRect.centerX(),
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            default:
                canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            }
        }

        if (mTouchedItem == day) {
            stateMask |= SUtils.STATE_PRESSED;

            if (isDayEnabled) {
                canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDayHighlightPaint);
            }
        }

        final boolean isDayToday = mToday == day;
        final int dayTextColor;

        if (isDayToday && !isDayInActivatedRange) {
            dayTextColor = mDaySelectorPaint.getColor();
        } else {
            final int[] stateSet = SUtils.resolveStateSet(stateMask);
            dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
        }
        p.setColor(dayTextColor);

        canvas.drawText(mDayFormatter.format(day), colCenterRtl, rowCenter - halfLineHeight, p);

        col++;

        if (col == DAYS_IN_WEEK) {
            col = 0;
            rowCenter += rowHeight;
        }
    }
}

From source file:com.miuhouse.yourcompany.student.view.widget.date.datepicker.SimpleMonthView.java

/**
 * Draws the month days./*from   w w  w. j a  v a 2  s  .  c  o  m*/
 */
@SuppressWarnings("ConstantConditions")
private void drawDays(Canvas canvas) {
    final TextPaint p = mDayPaint;
    final int headerHeight = mMonthHeight + mDayOfWeekHeight;

    final float rowHeight = mDayHeight;

    final float colWidth = mCellWidth;

    // Text is vertically centered within the row height.
    final float halfLineHeight = (p.ascent() + p.descent()) / 2f;
    //        int rowCenter = headerHeight + rowHeight / 2;
    float rowCenter = headerHeight + rowHeight / 2f;
    //mDaysInMonth303129
    for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) {
        final float colCenter = colWidth * col + colWidth / 2f;
        //final int colCenterRtl;
        final float colCenterRtl;
        if (SUtils.isLayoutRtlCompat(this)) {
            colCenterRtl = mPaddedWidth - colCenter;
        } else {
            colCenterRtl = colCenter;
        }

        int stateMask = 0;

        final boolean isDayEnabled = isDayEnabled(day);
        if (isDayEnabled) {
            stateMask |= SUtils.STATE_ENABLED;
        }

        final boolean isDayInActivatedRange = mActivatedDays.isValid() && mActivatedDays.isActivated(day);
        final boolean isSelected = mActivatedDays.isSelected(day);
        final boolean isSelectedAndTogether = mActivatedDays.isSelectedAndTogether(day);
        if (isSelectedAndTogether) {
            if ((!disable && !isDisable) || isFill) {
                stateMask |= SUtils.STATE_ACTIVATED;
                canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint);
            }
        }
        if (!isSelected && isDayInActivatedRange) {

            stateMask |= SUtils.STATE_ACTIVATED;
            int bgShape = DRAW_RECT;
            if (mActivatedDays.isSingleDay()) {
                if (mActivatedDays.isStartOfMonth()) {
                    bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT;
                } else {
                    bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT;
                }
            } else if (mActivatedDays.isStartingDayOfRange(day)) {
                bgShape = DRAW_RECT_WITH_CURVE_ON_LEFT;
            } else if (mActivatedDays.isEndingDayOfRange(day)) {
                bgShape = DRAW_RECT_WITH_CURVE_ON_RIGHT;
            }

            // Use height to constrain the protrusion of the arc
            boolean constrainProtrusion = colWidth > (rowHeight - (2 * mPaddingRangeIndicator));

            float horDistFromCenter = constrainProtrusion ? rowHeight / 2f - mPaddingRangeIndicator
                    : colWidth / 2f;
            switch (bgShape) {
            case DRAW_RECT_WITH_CURVE_ON_LEFT:

                int leftRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl - horDistFromCenter) + 1
                        : (int) (colCenterRtl - horDistFromCenter);

                int leftRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl + horDistFromCenter) + 1
                        : (int) (colCenterRtl + horDistFromCenter);

                RectF leftArcRect = new RectF(leftRectArcLeft,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, leftRectArcRight,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator);

                canvas.drawArc(leftArcRect, 90, 180, true, mDayRangeSelectorPaint);

                canvas.drawRect(new RectF(leftArcRect.centerX(),
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            case DRAW_RECT_WITH_CURVE_ON_RIGHT:
                int rightRectArcLeft = (int) (colCenterRtl - horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl - horDistFromCenter) + 1
                        : (int) (colCenterRtl - horDistFromCenter);

                int rightRectArcRight = (int) (colCenterRtl + horDistFromCenter) % 2 == 1
                        ? (int) (colCenterRtl + horDistFromCenter) + 1
                        : (int) (colCenterRtl + horDistFromCenter);

                RectF rightArcRect = new RectF(rightRectArcLeft,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightRectArcRight,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator);

                canvas.drawArc(rightArcRect, 270, 180, true, mDayRangeSelectorPaint);

                canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, rightArcRect.centerX(),
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            default:
                canvas.drawRect(new RectF(colCenterRtl - colWidth / 2f,
                        rowCenter - rowHeight / 2f + mPaddingRangeIndicator, colCenterRtl + colWidth / 2f,
                        rowCenter + rowHeight / 2f - mPaddingRangeIndicator), mDayRangeSelectorPaint);
                break;
            }
        }

        final boolean isDayToday = mToday == day;
        final int dayTextColor;
        if (isDayToday) {
            if (mActivatedDays.isClick && isSelected) {
                final int[] stateSet = SUtils.resolveStateSet(stateMask);
                dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
            } else {
                dayTextColor = mDaySelectorPaint.getColor();
            }
        } else {
            final int[] stateSet = SUtils.resolveStateSet(stateMask);
            if (!mActivatedDays.isSingleDay()) {
                if (stateMask == 1) {
                    dayTextColor = mContext.getResources().getColor(R.color.textDarkfour);
                } else {
                    dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
                }
            } else {
                dayTextColor = mDayTextColor.getColorForState(stateSet, 0);
            }
        }
        p.setColor(dayTextColor);

        canvas.drawText(mDayFormatter.format(day), colCenterRtl, rowCenter - halfLineHeight, p);

        col++;

        if (col == DAYS_IN_WEEK) {
            col = 0;
            rowCenter += rowHeight;
        }
        if (mDaysInMonth == day)
            mOnRangeClickListener.onRangeSelected(calendars, position);
    }
}

From source file:xiaofan.llongimageview.view.SubsamplingScaleImageView.java

/**
 * Draw method should not be called until the view has dimensions so the first calls are used as triggers to calculate
 * the scaling and tiling required. Once the view is setup, tiles are displayed as they are loaded.
 *//*  www  . j a  va 2s  . com*/
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    createPaints();

    // If image or view dimensions are not known yet, abort.
    if (sWidth == 0 || sHeight == 0 || decoder == null || getWidth() == 0 || getHeight() == 0) {
        return;
    }

    // On first render with no tile map ready, initialise it and kick off async base image loading.
    if (tileMap == null) {
        initialiseBaseLayer(getMaxBitmapDimensions(canvas));
        return;
    }

    // If waiting to translate to new center position, set translate now
    if (sPendingCenter != null && pendingScale != null) {
        scale = pendingScale;
        vTranslate.x = (getWidth() / 2) - (scale * sPendingCenter.x);
        vTranslate.y = (getHeight() / 2) - (scale * sPendingCenter.y);
        sPendingCenter = null;
        pendingScale = null;
        fitToBounds(true);
        refreshRequiredTiles(true);
    }

    // On first display of base image set up position, and in other cases make sure scale is correct.
    fitToBounds(false);

    // Everything is set up and coordinates are valid. Inform subclasses.
    if (!readySent) {
        readySent = true;
        new Thread(new Runnable() {
            public void run() {
                onImageReady();
            }
        }).start();
    }

    // If animating scale, calculate current scale and center with easing equations
    if (anim != null) {
        long scaleElapsed = System.currentTimeMillis() - anim.time;
        boolean finished = scaleElapsed > anim.duration;
        scaleElapsed = Math.min(scaleElapsed, anim.duration);
        scale = ease(anim.easing, scaleElapsed, anim.scaleStart, anim.scaleEnd - anim.scaleStart,
                anim.duration);

        // Apply required animation to the focal point
        float vFocusNowX = ease(anim.easing, scaleElapsed, anim.vFocusStart.x,
                anim.vFocusEnd.x - anim.vFocusStart.x, anim.duration);
        float vFocusNowY = ease(anim.easing, scaleElapsed, anim.vFocusStart.y,
                anim.vFocusEnd.y - anim.vFocusStart.y, anim.duration);
        // Find out where the focal point is at this scale and adjust its position to follow the animation path
        PointF vFocus = sourceToViewCoord(anim.sCenterEnd);
        vTranslate.x -= vFocus.x - vFocusNowX;
        vTranslate.y -= vFocus.y - vFocusNowY;

        // For translate anims, showing the image non-centered is never allowed, for scaling anims it is during the animation.
        fitToBounds(finished || (anim.scaleStart == anim.scaleEnd));
        refreshRequiredTiles(finished);
        if (finished) {
            anim = null;
        }
        invalidate();
    }

    // Optimum sample size for current scale
    int sampleSize = Math.min(fullImageSampleSize, calculateInSampleSize());

    // First check for missing tiles - if there are any we need the base layer underneath to avoid gaps
    boolean hasMissingTiles = false;
    for (Map.Entry<Integer, List<Tile>> tileMapEntry : tileMap.entrySet()) {
        if (tileMapEntry.getKey() == sampleSize) {
            for (Tile tile : tileMapEntry.getValue()) {
                if (tile.visible && (tile.loading || tile.bitmap == null)) {
                    hasMissingTiles = true;
                }
            }
        }
    }

    // Render all loaded tiles. LinkedHashMap used for bottom up rendering - lower res tiles underneath.
    for (Map.Entry<Integer, List<Tile>> tileMapEntry : tileMap.entrySet()) {
        if (tileMapEntry.getKey() == sampleSize || hasMissingTiles) {
            for (Tile tile : tileMapEntry.getValue()) {
                Rect vRect = convertRect(sourceToViewRect(tile.sRect));
                if (!tile.loading && tile.bitmap != null) {
                    canvas.drawBitmap(tile.bitmap, null, vRect, bitmapPaint);
                    if (debug) {
                        canvas.drawRect(vRect, debugPaint);
                    }
                } else if (tile.loading && debug) {
                    canvas.drawText("LOADING", vRect.left + 5, vRect.top + 35, debugPaint);
                }
                if (tile.visible && debug) {
                    canvas.drawText(
                            "ISS " + tile.sampleSize + " RECT " + tile.sRect.top + "," + tile.sRect.left + ","
                                    + tile.sRect.bottom + "," + tile.sRect.right,
                            vRect.left + 5, vRect.top + 15, debugPaint);
                }
            }
        }
    }

    if (debug) {
        canvas.drawText("Scale: " + String.format("%.2f", scale), 5, 15, debugPaint);
        canvas.drawText(
                "Translate: " + String.format("%.2f", vTranslate.x) + ":" + String.format("%.2f", vTranslate.y),
                5, 35, debugPaint);
        PointF center = getCenter();
        canvas.drawText(
                "Source center: " + String.format("%.2f", center.x) + ":" + String.format("%.2f", center.y), 5,
                55, debugPaint);

        if (anim != null) {
            PointF vCenterStart = sourceToViewCoord(anim.sCenterStart);
            PointF vCenterEndRequested = sourceToViewCoord(anim.sCenterEndRequested);
            PointF vCenterEnd = sourceToViewCoord(anim.sCenterEnd);
            canvas.drawCircle(vCenterStart.x, vCenterStart.y, 10, debugPaint);
            canvas.drawCircle(vCenterEndRequested.x, vCenterEndRequested.y, 20, debugPaint);
            canvas.drawCircle(vCenterEnd.x, vCenterEnd.y, 25, debugPaint);
            canvas.drawCircle(getWidth() / 2, getHeight() / 2, 30, debugPaint);
        }
    }
}

From source file:com.bizcom.vc.widget.cus.SubsamplingScaleImageView.java

/**
 * Draw method should not be called until the view has dimensions so the
 * first calls are used as triggers to calculate the scaling and tiling
 * required. Once the view is setup, tiles are displayed as they are loaded.
 *//*from   w w  w  .j  a va2s .  c o m*/
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    createPaints();

    // If image or view dimensions are not known yet, abort.
    if (sWidth == 0 || sHeight == 0 || decoder == null || getWidth() == 0 || getHeight() == 0) {
        return;
    }

    // On first render with no tile map ready, initialise it and kick off
    // async base image loading.
    if (tileMap == null) {
        initialiseBaseLayer(getMaxBitmapDimensions(canvas));
        return;
    }

    // If waiting to translate to new center position, set translate now
    if (sPendingCenter != null && pendingScale != null) {
        scale = pendingScale;
        vTranslate.x = (getWidth() / 2) - (scale * sPendingCenter.x);
        vTranslate.y = (getHeight() / 2) - (scale * sPendingCenter.y);
        sPendingCenter = null;
        pendingScale = null;
        fitToBounds(true);
        refreshRequiredTiles(true);
    }

    // On first display of base image set up position, and in other cases
    // make sure scale is correct.
    fitToBounds(false);

    // Everything is set up and coordinates are valid. Inform subclasses.
    if (!readySent) {
        readySent = true;
        new Thread(new Runnable() {
            public void run() {
                onImageReady();
            }
        }).start();
    }

    // If animating scale, calculate current scale and center with easing
    // equations
    if (anim != null) {
        long scaleElapsed = System.currentTimeMillis() - anim.time;
        boolean finished = scaleElapsed > anim.duration;
        scaleElapsed = Math.min(scaleElapsed, anim.duration);
        scale = ease(anim.easing, scaleElapsed, anim.scaleStart, anim.scaleEnd - anim.scaleStart,
                anim.duration);

        // Apply required animation to the focal point
        float vFocusNowX = ease(anim.easing, scaleElapsed, anim.vFocusStart.x,
                anim.vFocusEnd.x - anim.vFocusStart.x, anim.duration);
        float vFocusNowY = ease(anim.easing, scaleElapsed, anim.vFocusStart.y,
                anim.vFocusEnd.y - anim.vFocusStart.y, anim.duration);
        // Find out where the focal point is at this scale and adjust its
        // position to follow the animation path
        PointF vFocus = sourceToViewCoord(anim.sCenterEnd);
        vTranslate.x -= vFocus.x - vFocusNowX;
        vTranslate.y -= vFocus.y - vFocusNowY;

        // For translate anims, showing the image non-centered is never
        // allowed, for scaling anims it is during the animation.
        fitToBounds(finished || (anim.scaleStart == anim.scaleEnd));
        refreshRequiredTiles(finished);
        if (finished) {
            anim = null;
        }
        invalidate();
    }

    // Optimum sample size for current scale
    int sampleSize = Math.min(fullImageSampleSize, calculateInSampleSize());

    // First check for missing tiles - if there are any we need the base
    // layer underneath to avoid gaps
    boolean hasMissingTiles = false;
    for (Map.Entry<Integer, List<Tile>> tileMapEntry : tileMap.entrySet()) {
        if (tileMapEntry.getKey() == sampleSize) {
            for (Tile tile : tileMapEntry.getValue()) {
                if (tile.visible && (tile.loading || tile.bitmap == null)) {
                    hasMissingTiles = true;
                }
            }
        }
    }

    // Render all loaded tiles. LinkedHashMap used for bottom up rendering -
    // lower res tiles underneath.
    for (Map.Entry<Integer, List<Tile>> tileMapEntry : tileMap.entrySet()) {
        if (tileMapEntry.getKey() == sampleSize || hasMissingTiles) {
            for (Tile tile : tileMapEntry.getValue()) {
                Rect vRect = convertRect(sourceToViewRect(tile.sRect));
                if (!tile.loading && tile.bitmap != null) {
                    canvas.drawBitmap(tile.bitmap, null, vRect, bitmapPaint);
                    if (debug) {
                        canvas.drawRect(vRect, debugPaint);
                    }
                } else if (tile.loading && debug) {
                    canvas.drawText("LOADING", vRect.left + 5, vRect.top + 35, debugPaint);
                }
                if (tile.visible && debug) {
                    canvas.drawText(
                            "ISS " + tile.sampleSize + " RECT " + tile.sRect.top + "," + tile.sRect.left + ","
                                    + tile.sRect.bottom + "," + tile.sRect.right,
                            vRect.left + 5, vRect.top + 15, debugPaint);
                }
            }
        }
    }

    if (debug) {
        canvas.drawText("Scale: " + String.format("%.2f", scale), 5, 15, debugPaint);
        canvas.drawText(
                "Translate: " + String.format("%.2f", vTranslate.x) + ":" + String.format("%.2f", vTranslate.y),
                5, 35, debugPaint);
        PointF center = getCenter();
        canvas.drawText(
                "Source center: " + String.format("%.2f", center.x) + ":" + String.format("%.2f", center.y), 5,
                55, debugPaint);

        if (anim != null) {
            PointF vCenterStart = sourceToViewCoord(anim.sCenterStart);
            PointF vCenterEndRequested = sourceToViewCoord(anim.sCenterEndRequested);
            PointF vCenterEnd = sourceToViewCoord(anim.sCenterEnd);
            canvas.drawCircle(vCenterStart.x, vCenterStart.y, 10, debugPaint);
            canvas.drawCircle(vCenterEndRequested.x, vCenterEndRequested.y, 20, debugPaint);
            canvas.drawCircle(vCenterEnd.x, vCenterEnd.y, 25, debugPaint);
            canvas.drawCircle(getWidth() / 2, getHeight() / 2, 30, debugPaint);
        }
    }
}

From source file:com.huewu.pla.lib.internal.PLAListView.java

@Override
protected void dispatchDraw(final Canvas canvas) {
    // Draw the dividers
    final int dividerHeight = mDividerHeight;
    final Drawable overscrollHeader = mOverScrollHeader;
    final Drawable overscrollFooter = mOverScrollFooter;
    final boolean drawOverscrollHeader = overscrollHeader != null;
    final boolean drawOverscrollFooter = overscrollFooter != null;
    final boolean drawDividers = dividerHeight > 0 && mDivider != null;

    if (drawDividers || drawOverscrollHeader || drawOverscrollFooter) {
        // Only modify the top and bottom in the loop, we set the left and
        // right here
        final Rect bounds = mTempRect;
        // bounds.left = mPaddingLeft;
        // bounds.right = mRight - mLeft - mPaddingRight;
        bounds.left = getPaddingLeft();//from ww w .j  av a2 s. c om
        bounds.right = getRight() - getLeft() - getPaddingRight();

        final int count = getChildCount();
        final int headerCount = mHeaderViewInfos.size();
        final int itemCount = mItemCount;
        final int footerLimit = itemCount - mFooterViewInfos.size() - 1;
        final boolean headerDividers = mHeaderDividersEnabled;
        final boolean footerDividers = mFooterDividersEnabled;
        final int first = mFirstPosition;
        final boolean areAllItemsSelectable = mAreAllItemsSelectable;
        final ListAdapter adapter = mAdapter;
        // If the list is opaque *and* the background is not, we want to
        // fill a rect where the dividers would be for non-selectable items
        // If the list is opaque and the background is also opaque, we don't
        // need to draw anything since the background will do it for us
        final boolean fillForMissingDividers = drawDividers && isOpaque() && !super.isOpaque();

        if (fillForMissingDividers && mDividerPaint == null && mIsCacheColorOpaque) {
            mDividerPaint = new Paint();
            mDividerPaint.setColor(getCacheColorHint());
        }
        final Paint paint = mDividerPaint;

        // final int listBottom = mBottom - mTop - mListPadding.bottom +
        // mScrollY;
        final int listBottom = getBottom() - getTop() - mListPadding.bottom + getScrollY();
        if (!mStackFromBottom) {
            int bottom = 0;

            // Draw top divider or header for overscroll
            // final int scrollY = mScrollY;
            final int scrollY = getScrollY();
            if (count > 0 && scrollY < 0) {
                if (drawOverscrollHeader) {
                    bounds.bottom = 0;
                    bounds.top = scrollY;
                    drawOverscrollHeader(canvas, overscrollHeader, bounds);
                } else if (drawDividers) {
                    bounds.bottom = 0;
                    bounds.top = -dividerHeight;
                    drawDivider(canvas, bounds, -1);
                }
            }

            for (int i = 0; i < count; i++) {
                if ((headerDividers || first + i >= headerCount)
                        && (footerDividers || first + i < footerLimit)) {
                    final View child = getChildAt(i);
                    bottom = child.getBottom();
                    // Don't draw dividers next to items that are not
                    // enabled
                    if (drawDividers && bottom < listBottom && !(drawOverscrollFooter && i == count - 1)) {
                        if (areAllItemsSelectable || adapter.isEnabled(first + i)
                                && (i == count - 1 || adapter.isEnabled(first + i + 1))) {
                            bounds.top = bottom;
                            bounds.bottom = bottom + dividerHeight;
                            drawDivider(canvas, bounds, i);
                        } else if (fillForMissingDividers) {
                            bounds.top = bottom;
                            bounds.bottom = bottom + dividerHeight;
                            canvas.drawRect(bounds, paint);
                        }
                    }
                }
            }

            // final int overFooterBottom = mBottom + mScrollY;
            final int overFooterBottom = getBottom() + getScrollY();
            if (drawOverscrollFooter && first + count == itemCount && overFooterBottom > bottom) {
                bounds.top = bottom;
                bounds.bottom = overFooterBottom;
                drawOverscrollFooter(canvas, overscrollFooter, bounds);
            }
        } else {
            int top;
            final int listTop = mListPadding.top;

            // final int scrollY = mScrollY;
            final int scrollY = getScrollY();

            if (count > 0 && drawOverscrollHeader) {
                bounds.top = scrollY;
                bounds.bottom = getChildAt(0).getTop();
                drawOverscrollHeader(canvas, overscrollHeader, bounds);
            }

            final int start = drawOverscrollHeader ? 1 : 0;
            for (int i = start; i < count; i++) {
                if ((headerDividers || first + i >= headerCount)
                        && (footerDividers || first + i < footerLimit)) {
                    final View child = getChildAt(i);
                    top = child.getTop();
                    // Don't draw dividers next to items that are not
                    // enabled
                    if (drawDividers && top > listTop) {
                        if (areAllItemsSelectable || adapter.isEnabled(first + i)
                                && (i == count - 1 || adapter.isEnabled(first + i + 1))) {
                            bounds.top = top - dividerHeight;
                            bounds.bottom = top;
                            // Give the method the child ABOVE the divider,
                            // so we
                            // subtract one from our child
                            // position. Give -1 when there is no child
                            // above the
                            // divider.
                            drawDivider(canvas, bounds, i - 1);
                        } else if (fillForMissingDividers) {
                            bounds.top = top - dividerHeight;
                            bounds.bottom = top;
                            canvas.drawRect(bounds, paint);
                        }
                    }
                }
            }

            if (count > 0 && scrollY > 0) {
                if (drawOverscrollFooter) {
                    // final int absListBottom = mBottom;
                    final int absListBottom = getBottom();
                    bounds.top = absListBottom;
                    bounds.bottom = absListBottom + scrollY;
                    drawOverscrollFooter(canvas, overscrollFooter, bounds);
                } else if (drawDividers) {
                    bounds.top = listBottom;
                    bounds.bottom = listBottom + dividerHeight;
                    drawDivider(canvas, bounds, -1);
                }
            }
        }
    }

    // Draw the indicators (these should be drawn above the dividers) and
    // children
    super.dispatchDraw(canvas);
}

From source file:com.huewu.pla.lib.internal.PLA_ListView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    // Draw the dividers
    final int dividerHeight = mDividerHeight;
    final Drawable overscrollHeader = mOverScrollHeader;
    final Drawable overscrollFooter = mOverScrollFooter;
    final boolean drawOverscrollHeader = overscrollHeader != null;
    final boolean drawOverscrollFooter = overscrollFooter != null;
    final boolean drawDividers = dividerHeight > 0 && mDivider != null;

    if (drawDividers || drawOverscrollHeader || drawOverscrollFooter) {
        // Only modify the top and bottom in the loop, we set the left and
        // right here
        final Rect bounds = mTempRect;
        // bounds.left = mPaddingLeft;
        // bounds.right = mRight - mLeft - mPaddingRight;
        bounds.left = getPaddingLeft();/*from  ww w .ja  v  a2  s .c o m*/
        bounds.right = getRight() - getLeft() - getPaddingRight();

        final int count = getChildCount();
        final int headerCount = mHeaderViewInfos.size();
        final int itemCount = mItemCount;
        final int footerLimit = itemCount - mFooterViewInfos.size() - 1;
        final boolean headerDividers = mHeaderDividersEnabled;
        final boolean footerDividers = mFooterDividersEnabled;
        final int first = mFirstPosition;
        final boolean areAllItemsSelectable = mAreAllItemsSelectable;
        final ListAdapter adapter = mAdapter;
        // If the list is opaque *and* the background is not, we want to
        // fill a rect where the dividers would be for non-selectable items
        // If the list is opaque and the background is also opaque, we don't
        // need to draw anything since the background will do it for us
        final boolean fillForMissingDividers = drawDividers && isOpaque() && !super.isOpaque();

        if (fillForMissingDividers && mDividerPaint == null && mIsCacheColorOpaque) {
            mDividerPaint = new Paint();
            mDividerPaint.setColor(getCacheColorHint());
        }
        final Paint paint = mDividerPaint;

        // final int listBottom = mBottom - mTop - mListPadding.bottom +
        // mScrollY;
        final int listBottom = getBottom() - getTop() - mListPadding.bottom + getScrollY();
        if (!mStackFromBottom) {
            int bottom = 0;

            // Draw top divider or header for overscroll
            // final int scrollY = mScrollY;
            final int scrollY = getScrollY();
            if (count > 0 && scrollY < 0) {
                if (drawOverscrollHeader) {
                    bounds.bottom = 0;
                    bounds.top = scrollY;
                    drawOverscrollHeader(canvas, overscrollHeader, bounds);
                } else if (drawDividers) {
                    bounds.bottom = 0;
                    bounds.top = -dividerHeight;
                    drawDivider(canvas, bounds, -1);
                }
            }

            for (int i = 0; i < count; i++) {
                if ((headerDividers || first + i >= headerCount)
                        && (footerDividers || first + i < footerLimit)) {
                    View child = getChildAt(i);
                    bottom = child.getBottom();
                    // Don't draw dividers next to items that are not
                    // enabled
                    if (drawDividers && (bottom < listBottom && !(drawOverscrollFooter && i == count - 1))) {
                        if ((areAllItemsSelectable || (adapter.isEnabled(first + i)
                                && (i == count - 1 || adapter.isEnabled(first + i + 1))))) {
                            bounds.top = bottom;
                            bounds.bottom = bottom + dividerHeight;
                            drawDivider(canvas, bounds, i);
                        } else if (fillForMissingDividers) {
                            bounds.top = bottom;
                            bounds.bottom = bottom + dividerHeight;
                            canvas.drawRect(bounds, paint);
                        }
                    }
                }
            }

            // final int overFooterBottom = mBottom + mScrollY;
            final int overFooterBottom = getBottom() + getScrollY();
            if (drawOverscrollFooter && first + count == itemCount && overFooterBottom > bottom) {
                bounds.top = bottom;
                bounds.bottom = overFooterBottom;
                drawOverscrollFooter(canvas, overscrollFooter, bounds);
            }
        } else {
            int top;
            int listTop = mListPadding.top;

            // final int scrollY = mScrollY;
            final int scrollY = getScrollY();

            if (count > 0 && drawOverscrollHeader) {
                bounds.top = scrollY;
                bounds.bottom = getChildAt(0).getTop();
                drawOverscrollHeader(canvas, overscrollHeader, bounds);
            }

            final int start = drawOverscrollHeader ? 1 : 0;
            for (int i = start; i < count; i++) {
                if ((headerDividers || first + i >= headerCount)
                        && (footerDividers || first + i < footerLimit)) {
                    View child = getChildAt(i);
                    top = child.getTop();
                    // Don't draw dividers next to items that are not
                    // enabled
                    if (drawDividers && top > listTop) {
                        if ((areAllItemsSelectable || (adapter.isEnabled(first + i)
                                && (i == count - 1 || adapter.isEnabled(first + i + 1))))) {
                            bounds.top = top - dividerHeight;
                            bounds.bottom = top;
                            // Give the method the child ABOVE the divider,
                            // so we
                            // subtract one from our child
                            // position. Give -1 when there is no child
                            // above the
                            // divider.
                            drawDivider(canvas, bounds, i - 1);
                        } else if (fillForMissingDividers) {
                            bounds.top = top - dividerHeight;
                            bounds.bottom = top;
                            canvas.drawRect(bounds, paint);
                        }
                    }
                }
            }

            if (count > 0 && scrollY > 0) {
                if (drawOverscrollFooter) {
                    // final int absListBottom = mBottom;
                    final int absListBottom = getBottom();
                    bounds.top = absListBottom;
                    bounds.bottom = absListBottom + scrollY;
                    drawOverscrollFooter(canvas, overscrollFooter, bounds);
                } else if (drawDividers) {
                    bounds.top = listBottom;
                    bounds.bottom = listBottom + dividerHeight;
                    drawDivider(canvas, bounds, -1);
                }
            }
        }
    }

    // Draw the indicators (these should be drawn above the dividers) and
    // children
    super.dispatchDraw(canvas);
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    if (mCachingStarted) {
        mCachingActive = true;//from  w w  w  .  j a va2 s  .  c  om
    }

    // Draw the dividers
    final int dividerWidth = mDividerWidth;
    final Drawable overscrollHeader = mOverScrollHeader;
    final Drawable overscrollFooter = mOverScrollFooter;
    final boolean drawOverscrollHeader = overscrollHeader != null;
    final boolean drawOverscrollFooter = overscrollFooter != null;
    final boolean drawDividers = dividerWidth > 0 && mDivider != null;

    if (drawDividers || drawOverscrollHeader || drawOverscrollFooter) {
        // Only modify the top and bottom in the loop, we set the left and right here
        final Rect bounds = mTempRect;
        bounds.top = getPaddingTop();
        bounds.bottom = getBottom() - getTop() - getPaddingBottom();

        final int count = getChildCount();
        final int headerCount = mHeaderViewInfos.size();
        final int itemCount = mItemCount;
        final int footerLimit = itemCount - mFooterViewInfos.size() - 1;
        final boolean headerDividers = mHeaderDividersEnabled;
        final boolean footerDividers = mFooterDividersEnabled;
        final int first = mFirstPosition;
        final boolean areAllItemsSelectable = mAreAllItemsSelectable;
        final ListAdapter adapter = mAdapter;
        // If the list is opaque *and* the background is not, we want to
        // fill a rect where the dividers would be for non-selectable items
        // If the list is opaque and the background is also opaque, we don't
        // need to draw anything since the background will do it for us
        final boolean fillForMissingDividers = isOpaque() && !super.isOpaque();

        if (fillForMissingDividers && mDividerPaint == null && mIsCacheColorOpaque) {
            mDividerPaint = new Paint();
            mDividerPaint.setColor(getCacheColorHint());
        }
        final Paint paint = mDividerPaint;

        int effectivePaddingLeft = 0;
        int effectivePaddingRight = 0;
        // if ( ( mGroupFlags & CLIP_TO_PADDING_MASK ) == CLIP_TO_PADDING_MASK ) {
        // effectivePaddingTop = mListPadding.top;
        // effectivePaddingBottom = mListPadding.bottom;
        // }

        final int listRight = getRight() - getLeft() - effectivePaddingRight + getScrollX();
        if (!mStackFromRight) {
            int right = 0;

            // Draw top divider or header for overscroll
            final int scrollX = getScrollX();
            if (count > 0 && scrollX < 0) {
                if (drawOverscrollHeader) {
                    bounds.right = 0;
                    bounds.left = scrollX;
                    drawOverscrollHeader(canvas, overscrollHeader, bounds);
                } else if (drawDividers) {
                    bounds.right = 0;
                    bounds.left = -dividerWidth;
                    drawDivider(canvas, bounds, -1);
                }
            }

            for (int i = 0; i < count; i++) {
                if ((headerDividers || first + i >= headerCount)
                        && (footerDividers || first + i < footerLimit)) {
                    View child = getChildAt(i);
                    right = child.getRight();
                    // Don't draw dividers next to items that are not enabled

                    if (drawDividers && (right < listRight && !(drawOverscrollFooter && i == count - 1))) {
                        if ((areAllItemsSelectable || (adapter.isEnabled(first + i)
                                && (i == count - 1 || adapter.isEnabled(first + i + 1))))) {
                            bounds.left = right;
                            bounds.right = right + dividerWidth;
                            drawDivider(canvas, bounds, i);
                        } else if (fillForMissingDividers) {
                            bounds.left = right;
                            bounds.right = right + dividerWidth;
                            canvas.drawRect(bounds, paint);
                        }
                    }
                }
            }

            final int overFooterBottom = getRight() + getScrollX();
            if (drawOverscrollFooter && first + count == itemCount && overFooterBottom > right) {
                bounds.left = right;
                bounds.right = overFooterBottom;
                drawOverscrollFooter(canvas, overscrollFooter, bounds);
            }
        } else {
            int left;

            final int scrollX = getScrollX();

            if (count > 0 && drawOverscrollHeader) {
                bounds.left = scrollX;
                bounds.right = getChildAt(0).getLeft();
                drawOverscrollHeader(canvas, overscrollHeader, bounds);
            }

            final int start = drawOverscrollHeader ? 1 : 0;
            for (int i = start; i < count; i++) {
                if ((headerDividers || first + i >= headerCount)
                        && (footerDividers || first + i < footerLimit)) {
                    View child = getChildAt(i);
                    left = child.getLeft();
                    // Don't draw dividers next to items that are not enabled
                    if (left > effectivePaddingLeft) {
                        if ((areAllItemsSelectable || (adapter.isEnabled(first + i)
                                && (i == count - 1 || adapter.isEnabled(first + i + 1))))) {
                            bounds.left = left - dividerWidth;
                            bounds.right = left;
                            // Give the method the child ABOVE the divider, so we
                            // subtract one from our child
                            // position. Give -1 when there is no child above the
                            // divider.
                            drawDivider(canvas, bounds, i - 1);
                        } else if (fillForMissingDividers) {
                            bounds.left = left - dividerWidth;
                            bounds.right = left;
                            canvas.drawRect(bounds, paint);
                        }
                    }
                }
            }

            if (count > 0 && scrollX > 0) {
                if (drawOverscrollFooter) {
                    final int absListRight = getRight();
                    bounds.left = absListRight;
                    bounds.right = absListRight + scrollX;
                    drawOverscrollFooter(canvas, overscrollFooter, bounds);
                } else if (drawDividers) {
                    bounds.left = listRight;
                    bounds.right = listRight + dividerWidth;
                    drawDivider(canvas, bounds, -1);
                }
            }
        }
    }

    // Draw the indicators (these should be drawn above the dividers) and children
    super.dispatchDraw(canvas);
}