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(float left, float top, float right, float bottom, @NonNull Paint paint) 

Source Link

Document

Draw the specified Rect using the specified paint.

Usage

From source file:cn.edu.qzu.face.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*from w  ww  .  jav a2 s.  c o  m*/
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    for (int i = 0; i < tabsContainer.getChildCount(); ++i) {
        View tab = tabsContainer.getChildAt(i);
        tab.setSelected(i == selectedPosition);
    }

    // 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);

    //Indicator
    /*View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();
    if (currentTab instanceof TextView) {
       TextView textView = (TextView) currentTab;
    bound.setEmpty();
       Paint textPaint = textView.getPaint();
       textPaint.getTextBounds(textView.getText().toString(), 0, textView.getText().length(), bound);
       int padding = (textView.getWidth() - bound.width()) / 2;
       lineLeft = lineLeft + padding;
       lineRight = lineRight - padding;
    }
            
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {
            
       View nextTab = tabsContainer.getChildAt(currentPosition + 1);
       float nextTabLeft = nextTab.getLeft();
       float nextTabRight = nextTab.getRight();
       if (nextTab instanceof TextView) {
    TextView textView = (TextView) nextTab;
    Rect bound = new Rect();
    Paint textPaint = textView.getPaint();
    textPaint.getTextBounds(textView.getText().toString(), 0, textView.getText().length(), bound);
    int padding = (textView.getWidth() - bound.width()) / 2;
    nextTabLeft = nextTabLeft + padding;
    nextTabRight = nextTabRight - padding;
       }
            
       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.lt.adamlee.aagame.GameView.java

public void help(Canvas c) {
    String x = "";
    float textsize = F.hf(19.0f);
    Paint p4 = new Paint();
    Paint p5 = new Paint();
    Paint p6 = new Paint();
    String text = ctx.getString(R.string.helptext);
    p4.setColor(getResources().getColor(R.color.bright_foreground_inverse_material_light));
    p4.setFlags(1);//from   w  w w.  j  a  v  a2s .c o  m
    p5.setTypeface(tf);
    p5.setTextSize(F.hf(30.0f));
    p6.setTextSize(textsize);
    p5.setColor(ViewCompat.MEASURED_STATE_MASK);
    c.drawRect(0.0f, 0.0f, (float) screenW, (float) screenH, p4);
    c.drawText(ctx.getString(R.string.help),
            ((float) (screenW / 2)) - (p5.measureText(ctx.getString(R.string.help)) / 2.0f),
            (float) (screenH / 8), p5);
    int i = 0;
    int xv1 = 0;
    int yv1 = (int) textsize;
    while (i < ctx.getString(R.string.helptext).length()) {
        if (text.charAt(i) != '$') {
            c.drawText("  " + ctx.getString(R.string.helptext).charAt(i), (float) xv1,
                    ((float) ((screenH / 8) + yv1)) + (4.0f * textsize), p6);
            xv1 = (int) (((float) xv1)
                    + p6.measureText(Character.toString(ctx.getString(R.string.helptext).charAt(i))));
        }
        if (ctx.getString(R.string.helptext).charAt(i) == '$') {
            i++;
            x = " ";
            yv1 = (int) (((float) yv1) + textsize);
            xv1 = 0;
        }
        i++;
    }
}

From source file:com.cplatform.xhxw.ui.ui.base.view.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*from  w  w w  .  jav a 2  s. co 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 + 20, (int) (height * 0.8), lineRight - 20,
    //            (int) (height * 0.8) + indicatorHeight, 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.zxly.o2o.viewpagerindicator.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0 || !isNeedToDoDraw) {
        return;/*from  w  w  w  .  j  a  v a 2s .  c o m*/
    }

    final int height = getHeight();

    // draw underline
    //        rectPaint.setColor(underlineColor);
    //        canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // 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
            - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, AppController.displayMetrics),
            height - indicatorHeight, lineRight + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                    2, AppController.displayMetrics),
            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.ninexiu.sixninexiu.lib.indicator.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//w  w w. j ava2  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 (indicatorWidth > 0) {
        float differ = (lineRight - lineLeft - indicatorWidth) / 2;
        lineLeft = lineLeft + differ;
        lineRight = lineRight - differ;
    }
    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 + indicatorPadding, height - indicatorHeight, lineRight - indicatorPadding, 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.tbse.mywearapplication.WatchFaceDrawer.java

void onDraw(Context context, IWatchFaceConfig config, Canvas canvas, Rect bounds) {
    final Calendar calendar = config.getCalendar();
    final boolean isAmbient = config.isAmbient();
    final boolean isRound = config.isRound();
    final boolean useLightTheme = !isAmbient && config.isLightTheme();

    mBackgroundPaint.setColor(ContextCompat.getColor(context,
            useLightTheme ? R.color.watchface_background_light : R.color.watchface_background));

    /////////////////////////////////////////////////////////////////////
    // Draw your watch face here, using the provided canvas and bounds //
    /////////////////////////////////////////////////////////////////////

    final int width = bounds.width();
    final int height = bounds.height();

    // Find the center. Ignore the window insets so that, on round
    // watches with a "chin", the watch face is centered on the entire
    // screen, not just the usable portion.
    final float centerX = width / 2f;
    final float centerY = height / 2f;

    // Draw the background.
    if (mIsMobilePreview) {
        if (isRound) {
            canvas.drawCircle(centerX, centerY, centerX, mPreviewBorderPaint);
        } else {/*w w  w .ja va2  s  . c  o m*/
            final float radius = mPreviewSquareRadius;
            final RectF rectF = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
            canvas.drawRoundRect(rectF, radius, radius, mPreviewBorderPaint);
        }

        final float translateXY = width * 0.05f;
        canvas.translate(translateXY, translateXY);
        canvas.scale(0.9f, 0.9f);

        if (isRound) {
            canvas.drawCircle(centerX, centerY, centerX, mBackgroundPaint);
        } else {
            canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint);
        }
    } else {
        canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint);
    }

    // Draw weather icon
    if (image != null) {
        Matrix matrix = new Matrix();
        matrix.setTranslate(50, 90);
        matrix.preScale(0.2f, 0.2f);
        canvas.drawBitmap(image, matrix, null);
    }

    final float secRot = calendar.get(Calendar.SECOND) / 30f * (float) Math.PI;
    final int minutes = calendar.get(Calendar.MINUTE);
    final float minRot = minutes / 30f * (float) Math.PI;
    final float hrRot = ((calendar.get(Calendar.HOUR) + (minutes / 60f)) / 6f) * (float) Math.PI;

    final float secLength = centerX - mSecondOuterOffset;
    final float minLength = centerX - mMinuteOuterOffset;
    final float hrLength = centerX - mHourOuterOffset;

    if (!isAmbient) {
        final float secX = (float) Math.sin(secRot) * secLength;
        final float secY = (float) -Math.cos(secRot) * secLength;
        canvas.drawLine(centerX, centerY, centerX + secX, centerY + secY, mSecondHandPaint);
    }

    final float minX = (float) Math.sin(minRot) * minLength;
    final float minY = (float) -Math.cos(minRot) * minLength;
    canvas.drawLine(centerX, centerY, centerX + minX, centerY + minY, mMinuteHandPaint);

    final float hrX = (float) Math.sin(hrRot) * hrLength;
    final float hrY = (float) -Math.cos(hrRot) * hrLength;
    canvas.drawLine(centerX, centerY, centerX + hrX, centerY + hrY, mHourHandPaint);

    // Draw weather text
    canvas.drawText(day, 50, 50, isAmbient ? ambientTextPaint : textPaint);
    canvas.drawText(low, 50, 65, isAmbient ? ambientTextPaint : textPaint);
    canvas.drawText(high, 80, 65, isAmbient ? ambientTextPaint : textPaint);
    canvas.drawText(weatherDescription, 50, 80, isAmbient ? ambientTextPaint : textPaint);

}

From source file:com.microsoft.mimickeralarm.appcore.AlarmListItemTouchHelperCallback.java

@Override
public void onChildDraw(Canvas canvas, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX,
        float dY, int actionState, boolean isCurrentlyActive) {

    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {

        View itemView = viewHolder.itemView;
        Resources resources = AlarmApplication.getAppContext().getResources();
        Bitmap icon = BitmapFactory.decodeResource(resources, R.drawable.delete_trash_can);
        int iconPadding = resources.getDimensionPixelOffset(R.dimen.alarm_list_delete_icon_padding);
        int maxDrawWidth = (iconPadding * 2) + icon.getWidth();

        Paint paint = new Paint();
        paint.setColor(ContextCompat.getColor(AlarmApplication.getAppContext(), R.color.red));

        int x = Math.round(Math.abs(dX));

        // Reset the dismiss flag if the view resets to its default position
        if (x == 0) {
            mCanDismiss = false;//from  w ww.  jav  a2  s. c  o  m
        }

        // If we have travelled beyond the icon area via direct user interaction
        // we will dismiss when we get a swipe callback.  We do this to try to avoid
        // unwanted swipe dismissal
        if ((x > maxDrawWidth) && isCurrentlyActive) {
            mCanDismiss = true;
        }

        int drawWidth = Math.min(x, maxDrawWidth);
        // Cap the height of the drawable area to the selectable area - this improves the visual
        // for the first taller item in the alarm list
        int itemTop = itemView.getBottom() - resources.getDimensionPixelSize(R.dimen.alarm_list_item_height);

        if (dX > 0) {
            // Handle swiping to the right
            // Draw red background in area that we vacate up to maxDrawWidth
            canvas.drawRect((float) itemView.getLeft(), (float) itemTop, drawWidth,
                    (float) itemView.getBottom(), paint);

            // Only draw icon when we've past the padding threshold
            if (x > iconPadding) {

                Rect destRect = new Rect();
                destRect.left = itemView.getLeft() + iconPadding;
                destRect.top = itemTop + (itemView.getBottom() - itemTop - icon.getHeight()) / 2;
                int maxRight = destRect.left + icon.getWidth();
                destRect.right = Math.min(x, maxRight);
                destRect.bottom = destRect.top + icon.getHeight();

                // Only draw the appropriate parts of the bitmap as it is revealed
                Rect srcRect = null;
                if (x < maxRight) {
                    srcRect = new Rect();
                    srcRect.top = 0;
                    srcRect.left = 0;
                    srcRect.bottom = icon.getHeight();
                    srcRect.right = x - iconPadding;
                }

                canvas.drawBitmap(icon, srcRect, destRect, paint);
            }

        } else {
            // Handle swiping to the left
            // Draw red background in area that we vacate  up to maxDrawWidth
            canvas.drawRect((float) itemView.getRight() - drawWidth, (float) itemTop,
                    (float) itemView.getRight(), (float) itemView.getBottom(), paint);

            // Only draw icon when we've past the padding threshold
            if (x > iconPadding) {
                int fromLeftX = itemView.getRight() - x;
                Rect destRect = new Rect();
                destRect.right = itemView.getRight() - iconPadding;
                destRect.top = itemTop + (itemView.getBottom() - itemTop - icon.getHeight()) / 2;
                int maxFromLeft = destRect.right - icon.getWidth();
                destRect.left = Math.max(fromLeftX, maxFromLeft);
                destRect.bottom = destRect.top + icon.getHeight();

                // Only draw the appropriate parts of the bitmap as it is revealed
                Rect srcRect = null;
                if (fromLeftX > maxFromLeft) {
                    srcRect = new Rect();
                    srcRect.top = 0;
                    srcRect.right = icon.getWidth();
                    srcRect.bottom = icon.getHeight();
                    srcRect.left = srcRect.right - (x - iconPadding);
                }

                canvas.drawBitmap(icon, srcRect, destRect, paint);
            }
        }

        // Fade out the item as we swipe it
        float alpha = 1.0f - Math.abs(dX) / (float) itemView.getWidth();
        itemView.setAlpha(alpha);
        itemView.setTranslationX(dX);
    } else {
        super.onChildDraw(canvas, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
}

From source file:com.zxly.o2o.viewpagerindicator.MPagerSlidingTab.java

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

    if (isInEditMode() || tabCount == 0 || !isNeedToDoDraw) {
        return;//from   w w  w.  j  a v  a2s .  c  o m
    }

    final int height = getHeight();

    // draw underline
    //        rectPaint.setColor(underlineColor);
    //        canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // 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(getLeft(),height - indicatorHeight/2, getRight(), height, botLine);

    canvas.drawRect(lineLeft
            - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, AppController.displayMetrics),
            height - indicatorHeight, lineRight + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                    2, AppController.displayMetrics),
            height, rectPaint);

    //        draw divider

    Log.d("getInfo", " left :" + (lineLeft
            - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, AppController.displayMetrics))
            + "   top :" + (height - indicatorHeight) + "  right :" + (lineRight + (int) TypedValue
                    .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, AppController.displayMetrics))
            + "  bot:" + height);

    Log.d("getInfo", " left :" + getLeft() + "   right :" + getRight() + "  x :" + getX() + "  y:" + getY());
    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.zxly.o2o.view.MPagerSlidingTab.java

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

    if (isInEditMode() || tabCount == 0 || !isNeedToDoDraw) {
        return;/*  w  w w . j a  va 2 s. c  om*/
    }

    final int height = getHeight();

    // draw underline
    //        rectPaint.setColor(underlineColor);
    //        canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // 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(0,height - indicatorHeight/2, Config.displayMetrics.widthPixels, height, botLine);

    canvas.drawRect(lineLeft
            - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, AppController.displayMetrics),
            height - indicatorHeight, lineRight + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                    2, AppController.displayMetrics),
            height, rectPaint);

    //        draw divider
    //
    //        Log.d("getInfo", " left :" + (lineLeft - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, AppController.displayMetrics))
    //                + "   top :" + (height - indicatorHeight)
    //                + "  right :" + (lineRight + (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, AppController.displayMetrics))
    //                +"  bot:"+height);

    //     Log.d("getInfo", " left :"+getLeft() +"   right :"+getRight() + "  x :"+getX()  +"  y:"+getY());
    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.supermonkey.lifeassistant.view.pager.PagerSlidingTabStrip.java

/**
 * ?onDraw// ww  w . j a va  2  s  .c o  m
 */
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // isEditMode()?
    if (isInEditMode() || tabCount == 0) {
        return;
    }
    // 
    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
    // currentPosition0
    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);
    */
    // 
    canvas.drawRect(0, 0, tabsContainer.getWidth(), underlineHeight, 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);
    }
}