Search in sources :

Example 11 with Rect

use of android.graphics.Rect in project cw-omnibus by commonsguy.

the class IcsProgressBar method invalidateDrawable.

@Override
public void invalidateDrawable(Drawable dr) {
    if (!mInDrawing) {
        if (verifyDrawable(dr)) {
            final Rect dirty = dr.getBounds();
            final int scrollX = getScrollX() + getPaddingLeft();
            final int scrollY = getScrollY() + getPaddingTop();
            invalidate(dirty.left + scrollX, dirty.top + scrollY, dirty.right + scrollX, dirty.bottom + scrollY);
        } else {
            super.invalidateDrawable(dr);
        }
    }
}
Also used : Rect(android.graphics.Rect)

Example 12 with Rect

use of android.graphics.Rect in project cw-omnibus by commonsguy.

the class TitlePageIndicator method onDraw.

/*
     * (non-Javadoc)
     *
     * @see android.view.View#onDraw(android.graphics.Canvas)
     */
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mViewPager == null) {
        return;
    }
    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();
    //Calculate views bounds
    ArrayList<Rect> bounds = calculateAllBounds(mPaintText);
    final int boundsSize = bounds.size();
    //Make sure we're on a page that still exists
    if (mCurrentPage >= boundsSize) {
        setCurrentItem(boundsSize - 1);
        return;
    }
    final int countMinusOne = count - 1;
    final float halfWidth = getWidth() / 2f;
    final int left = getLeft();
    final float leftClip = left + mClipPadding;
    final int width = getWidth();
    final int height = getHeight();
    final int right = left + width;
    final float rightClip = right - mClipPadding;
    int page = mCurrentPage;
    float offsetPercent;
    if (mPageOffset <= 0.5) {
        offsetPercent = mPageOffset;
    } else {
        page += 1;
        offsetPercent = 1 - mPageOffset;
    }
    final boolean currentSelected = (offsetPercent <= SELECTION_FADE_PERCENTAGE);
    final boolean currentBold = (offsetPercent <= BOLD_FADE_PERCENTAGE);
    final float selectedPercent = (SELECTION_FADE_PERCENTAGE - offsetPercent) / SELECTION_FADE_PERCENTAGE;
    //Verify if the current view must be clipped to the screen
    Rect curPageBound = bounds.get(mCurrentPage);
    float curPageWidth = curPageBound.right - curPageBound.left;
    if (curPageBound.left < leftClip) {
        //Try to clip to the screen (left side)
        clipViewOnTheLeft(curPageBound, curPageWidth, left);
    }
    if (curPageBound.right > rightClip) {
        //Try to clip to the screen (right side)
        clipViewOnTheRight(curPageBound, curPageWidth, right);
    }
    //Left views starting from the current position
    if (mCurrentPage > 0) {
        for (int i = mCurrentPage - 1; i >= 0; i--) {
            Rect bound = bounds.get(i);
            //Is left side is outside the screen
            if (bound.left < leftClip) {
                int w = bound.right - bound.left;
                //Try to clip to the screen (left side)
                clipViewOnTheLeft(bound, w, left);
                //Except if there's an intersection with the right view
                Rect rightBound = bounds.get(i + 1);
                //Intersection
                if (bound.right + mTitlePadding > rightBound.left) {
                    bound.left = (int) (rightBound.left - w - mTitlePadding);
                    bound.right = bound.left + w;
                }
            }
        }
    }
    //Right views starting from the current position
    if (mCurrentPage < countMinusOne) {
        for (int i = mCurrentPage + 1; i < count; i++) {
            Rect bound = bounds.get(i);
            //If right side is outside the screen
            if (bound.right > rightClip) {
                int w = bound.right - bound.left;
                //Try to clip to the screen (right side)
                clipViewOnTheRight(bound, w, right);
                //Except if there's an intersection with the left view
                Rect leftBound = bounds.get(i - 1);
                //Intersection
                if (bound.left - mTitlePadding < leftBound.right) {
                    bound.left = (int) (leftBound.right + mTitlePadding);
                    bound.right = bound.left + w;
                }
            }
        }
    }
    //Now draw views
    int colorTextAlpha = mColorText >>> 24;
    for (int i = 0; i < count; i++) {
        //Get the title
        Rect bound = bounds.get(i);
        //Only if one side is visible
        if ((bound.left > left && bound.left < right) || (bound.right > left && bound.right < right)) {
            final boolean currentPage = (i == page);
            final CharSequence pageTitle = getTitle(i);
            //Only set bold if we are within bounds
            mPaintText.setFakeBoldText(currentPage && currentBold && mBoldText);
            //Draw text as unselected
            mPaintText.setColor(mColorText);
            if (currentPage && currentSelected) {
                //Fade out/in unselected text as the selected text fades in/out
                mPaintText.setAlpha(colorTextAlpha - (int) (colorTextAlpha * selectedPercent));
            }
            canvas.drawText(pageTitle, 0, pageTitle.length(), bound.left, bound.bottom + mTopPadding, mPaintText);
            //If we are within the selected bounds draw the selected text
            if (currentPage && currentSelected) {
                mPaintText.setColor(mColorSelected);
                mPaintText.setAlpha((int) ((mColorSelected >>> 24) * selectedPercent));
                canvas.drawText(pageTitle, 0, pageTitle.length(), bound.left, bound.bottom + mTopPadding, mPaintText);
            }
        }
    }
    //Draw the footer line
    mPath.reset();
    mPath.moveTo(0, height - mFooterLineHeight / 2f);
    mPath.lineTo(width, height - mFooterLineHeight / 2f);
    mPath.close();
    canvas.drawPath(mPath, mPaintFooterLine);
    switch(mFooterIndicatorStyle) {
        case Triangle:
            mPath.reset();
            mPath.moveTo(halfWidth, height - mFooterLineHeight - mFooterIndicatorHeight);
            mPath.lineTo(halfWidth + mFooterIndicatorHeight, height - mFooterLineHeight);
            mPath.lineTo(halfWidth - mFooterIndicatorHeight, height - mFooterLineHeight);
            mPath.close();
            canvas.drawPath(mPath, mPaintFooterIndicator);
            break;
        case Underline:
            if (!currentSelected || page >= boundsSize) {
                break;
            }
            Rect underlineBounds = bounds.get(page);
            mPath.reset();
            mPath.moveTo(underlineBounds.left - mFooterIndicatorUnderlinePadding, height - mFooterLineHeight);
            mPath.lineTo(underlineBounds.right + mFooterIndicatorUnderlinePadding, height - mFooterLineHeight);
            mPath.lineTo(underlineBounds.right + mFooterIndicatorUnderlinePadding, height - mFooterLineHeight - mFooterIndicatorHeight);
            mPath.lineTo(underlineBounds.left - mFooterIndicatorUnderlinePadding, height - mFooterLineHeight - mFooterIndicatorHeight);
            mPath.close();
            mPaintFooterIndicator.setAlpha((int) (0xFF * selectedPercent));
            canvas.drawPath(mPath, mPaintFooterIndicator);
            mPaintFooterIndicator.setAlpha(0xFF);
            break;
    }
}
Also used : Rect(android.graphics.Rect) Paint(android.graphics.Paint)

Example 13 with Rect

use of android.graphics.Rect in project philm by chrisbanes.

the class ForegroundLinearLayout method setForeground.

/**
     * Supply a Drawable that is to be rendered on top of all of the child
     * views in the frame layout.  Any padding in the Drawable will be taken
     * into account by ensuring that the children are inset to be placed
     * inside of the padding area.
     *
     * @param drawable The Drawable to be drawn on top of the children.
     */
public void setForeground(Drawable drawable) {
    if (mForeground != drawable) {
        if (mForeground != null) {
            mForeground.setCallback(null);
            unscheduleDrawable(mForeground);
        }
        mForeground = drawable;
        if (drawable != null) {
            setWillNotDraw(false);
            drawable.setCallback(this);
            if (drawable.isStateful()) {
                drawable.setState(getDrawableState());
            }
            if (mForegroundGravity == Gravity.FILL) {
                Rect padding = new Rect();
                drawable.getPadding(padding);
            }
        } else {
            setWillNotDraw(true);
        }
        requestLayout();
        invalidate();
    }
}
Also used : Rect(android.graphics.Rect)

Example 14 with Rect

use of android.graphics.Rect in project philm by chrisbanes.

the class ForegroundLinearLayout method setForegroundGravity.

/**
     * Describes how the foreground is positioned. Defaults to START and TOP.
     *
     * @param foregroundGravity See {@link android.view.Gravity}
     *
     * @see #getForegroundGravity()
     */
public void setForegroundGravity(int foregroundGravity) {
    if (mForegroundGravity != foregroundGravity) {
        if ((foregroundGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
            foregroundGravity |= Gravity.START;
        }
        if ((foregroundGravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
            foregroundGravity |= Gravity.TOP;
        }
        mForegroundGravity = foregroundGravity;
        if (mForegroundGravity == Gravity.FILL && mForeground != null) {
            Rect padding = new Rect();
            mForeground.getPadding(padding);
        }
        requestLayout();
    }
}
Also used : Rect(android.graphics.Rect)

Example 15 with Rect

use of android.graphics.Rect in project material-icon-lib by code-mc.

the class SetBoundsTest method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    Paint p = new Paint();
    p.setColor(Color.BLACK);
    Rect bounds = new Rect(0, 100, getMeasuredHeight(), getMeasuredHeight());
    canvas.drawRect(bounds, p);
    mDrawable.setBounds(bounds);
    mDrawable.draw(canvas);
}
Also used : Rect(android.graphics.Rect) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Aggregations

Rect (android.graphics.Rect)3823 Paint (android.graphics.Paint)791 View (android.view.View)533 Point (android.graphics.Point)470 Bitmap (android.graphics.Bitmap)333 Canvas (android.graphics.Canvas)255 Drawable (android.graphics.drawable.Drawable)203 RectF (android.graphics.RectF)176 Resources (android.content.res.Resources)101 Matrix (android.graphics.Matrix)99 SmallTest (android.test.suitebuilder.annotation.SmallTest)94 TextPaint (android.text.TextPaint)94 RemoteException (android.os.RemoteException)93 ViewGroup (android.view.ViewGroup)89 TextView (android.widget.TextView)87 ArrayList (java.util.ArrayList)87 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)84 BitmapDrawable (android.graphics.drawable.BitmapDrawable)82 SuppressLint (android.annotation.SuppressLint)77 ImageView (android.widget.ImageView)70