Example usage for android.graphics.drawable Drawable draw

List of usage examples for android.graphics.drawable Drawable draw

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable draw.

Prototype

public abstract void draw(@NonNull Canvas canvas);

Source Link

Document

Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).

Usage

From source file:cc.flydev.launcher.Workspace.java

/**
 * Draw the View v into the given Canvas.
 *
 * @param v the view to draw/*w  w  w  .  j a  v a2s  . c o  m*/
 * @param destCanvas the canvas to draw on
 * @param padding the horizontal and vertical padding to use when drawing
 */
private void drawDragView(View v, Canvas destCanvas, int padding, boolean pruneToDrawable) {
    final Rect clipRect = mTempRect;
    v.getDrawingRect(clipRect);

    boolean textVisible = false;

    destCanvas.save();
    if (v instanceof TextView && pruneToDrawable) {
        Drawable d = ((TextView) v).getCompoundDrawables()[1];
        clipRect.set(0, 0, d.getIntrinsicWidth() + padding, d.getIntrinsicHeight() + padding);
        destCanvas.translate(padding / 2, padding / 2);
        d.draw(destCanvas);
    } else {
        if (v instanceof FolderIcon) {
            // For FolderIcons the text can bleed into the icon area, and so we need to
            // hide the text completely (which can't be achieved by clipping).
            if (((FolderIcon) v).getTextVisible()) {
                ((FolderIcon) v).setTextVisible(false);
                textVisible = true;
            }
        } else if (v instanceof BubbleTextView) {
            final BubbleTextView tv = (BubbleTextView) v;
            clipRect.bottom = tv.getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V
                    + tv.getLayout().getLineTop(0);
        } else if (v instanceof TextView) {
            final TextView tv = (TextView) v;
            clipRect.bottom = tv.getExtendedPaddingTop() - tv.getCompoundDrawablePadding()
                    + tv.getLayout().getLineTop(0);
        }
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);

        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) v).setTextVisible(true);
        }
    }
    destCanvas.restore();
}

From source file:com.aidy.launcher3.ui.workspace.Workspace.java

/**
 * Draw the View v into the given Canvas.
 * // www  . java2s .  c om
 * @param v
 *            the view to draw
 * @param destCanvas
 *            the canvas to draw on
 * @param padding
 *            the horizontal and vertical padding to use when drawing
 */
private void drawDragView(View v, Canvas destCanvas, int padding, boolean pruneToDrawable) {
    final Rect clipRect = mTempRect;
    v.getDrawingRect(clipRect);

    boolean textVisible = false;

    destCanvas.save();
    if (v instanceof TextView && pruneToDrawable) {
        Drawable d = ((TextView) v).getCompoundDrawables()[1];
        clipRect.set(0, 0, d.getIntrinsicWidth() + padding, d.getIntrinsicHeight() + padding);
        destCanvas.translate(padding / 2, padding / 2);
        d.draw(destCanvas);
    } else {
        if (v instanceof FolderIcon) {
            // For FolderIcons the text can bleed into the icon area, and so
            // we need to
            // hide the text completely (which can't be achieved by
            // clipping).
            if (((FolderIcon) v).getTextVisible()) {
                ((FolderIcon) v).setTextVisible(false);
                textVisible = true;
            }
        } else if (v instanceof BubbleTextView) {
            final BubbleTextView tv = (BubbleTextView) v;
            clipRect.bottom = tv.getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V
                    + tv.getLayout().getLineTop(0);
        } else if (v instanceof TextView) {
            final TextView tv = (TextView) v;
            clipRect.bottom = tv.getExtendedPaddingTop() - tv.getCompoundDrawablePadding()
                    + tv.getLayout().getLineTop(0);
        }
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);

        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) v).setTextVisible(true);
        }
    }
    destCanvas.restore();
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java

private void onBufferDraw(Canvas canvas) {
    if (mKeyboardChanged) {
        invalidateAllKeys();//from  w  w  w. ja  v a  2  s.  com
        mKeyboardChanged = false;
    }

    canvas.getClipBounds(mDirtyRect);

    if (mKeyboard == null)
        return;

    final boolean drawKeyboardNameText = (mKeyboardNameTextSize > 1f)
            && AnyApplication.getConfig().getShowKeyboardNameText();

    final boolean drawHintText = (mHintTextSize > 1) && AnyApplication.getConfig().getShowHintTextOnKeys();
    // TODO: calls to AnyApplication.getConfig().getXXXXX() functions are
    // not yet implemented,
    // but need to when allowing preferences to override theme settings of
    // these values
    // right now just using what should be the default values for these
    // unimplemented preferences

    final boolean useCustomKeyTextColor = false;
    // TODO: final boolean useCustomKeyTextColor =
    // AnyApplication.getConfig().getUseCustomTextColorOnKeys();
    final ColorStateList keyTextColor = useCustomKeyTextColor
            ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFF6666FF })
            : mKeyTextColor;
    // TODO: ? AnyApplication.getConfig().getCustomKeyTextColorOnKeys() :
    // mKeyTextColor;

    final boolean useCustomHintColor = drawHintText && false;
    // TODO: final boolean useCustomHintColor = drawHintText &&
    // AnyApplication.getConfig().getUseCustomHintColorOnKeys();
    final ColorStateList hintColor = useCustomHintColor
            ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFFFF6666 })
            : mHintTextColor;
    // TODO: ? AnyApplication.getConfig().getCustomHintColorOnKeys() :
    // mHintTextColor;

    // allow preferences to override theme settings for hint text position
    final boolean useCustomHintAlign = drawHintText && AnyApplication.getConfig().getUseCustomHintAlign();
    final int hintAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintAlign()
            : mHintLabelAlign;
    final int hintVAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintVAlign()
            : mHintLabelVAlign;

    final Paint paint = mPaint;
    final Drawable keyBackground = mKeyBackground;
    final Rect clipRegion = mClipRegion;
    final int kbdPaddingLeft = getPaddingLeft();
    final int kbdPaddingTop = getPaddingTop();
    final Key[] keys = mKeys;
    final Key invalidKey = mInvalidatedKey;

    boolean drawSingleKey = false;
    if (invalidKey != null && canvas.getClipBounds(clipRegion)) {
        // TODO we should use Rect.inset and Rect.contains here.
        // Is clipRegion completely contained within the invalidated key?
        if (invalidKey.x + kbdPaddingLeft - 1 <= clipRegion.left
                && invalidKey.y + kbdPaddingTop - 1 <= clipRegion.top
                && invalidKey.x + invalidKey.width + kbdPaddingLeft + 1 >= clipRegion.right
                && invalidKey.y + invalidKey.height + kbdPaddingTop + 1 >= clipRegion.bottom) {
            drawSingleKey = true;
        }
    }
    final int keyCount = keys.length;
    for (int i = 0; i < keyCount; i++) {
        final AnyKey key = (AnyKey) keys[i];
        final boolean keyIsSpace = isSpaceKey(key);

        if (drawSingleKey && (invalidKey != key)) {
            continue;
        }
        if (!mDirtyRect.intersects(key.x + kbdPaddingLeft, key.y + kbdPaddingTop,
                key.x + key.width + kbdPaddingLeft, key.y + key.height + kbdPaddingTop)) {
            continue;
        }
        int[] drawableState = key.getCurrentDrawableState(mDrawableStatesProvider);

        if (keyIsSpace)
            paint.setColor(mKeyboardNameTextColor.getColorForState(drawableState, 0xFF000000));
        else
            paint.setColor(keyTextColor.getColorForState(drawableState, 0xFF000000));
        keyBackground.setState(drawableState);

        // Switch the character to uppercase if shift is pressed
        CharSequence label = key.label == null ? null : adjustCase(key).toString();

        final Rect bounds = keyBackground.getBounds();
        if ((key.width != bounds.right) || (key.height != bounds.bottom)) {
            keyBackground.setBounds(0, 0, key.width, key.height);
        }
        canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop);
        keyBackground.draw(canvas);

        if (TextUtils.isEmpty(label)) {
            Drawable iconToDraw = getIconToDrawForKey(key, false);
            if (iconToDraw != null/* && shouldDrawIcon */) {
                //http://developer.android.com/reference/android/graphics/drawable/Drawable.html#getCurrent()
                //http://stackoverflow.com/a/103600/1324235
                final boolean is9Patch = iconToDraw.getCurrent() instanceof NinePatchDrawable;

                // Special handing for the upper-right number hint icons
                final int drawableWidth;
                final int drawableHeight;
                final int drawableX;
                final int drawableY;

                drawableWidth = is9Patch ? key.width : iconToDraw.getIntrinsicWidth();
                drawableHeight = is9Patch ? key.height : iconToDraw.getIntrinsicHeight();
                drawableX = (key.width + mKeyBackgroundPadding.left - mKeyBackgroundPadding.right
                        - drawableWidth) / 2;
                drawableY = (key.height + mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom
                        - drawableHeight) / 2;

                canvas.translate(drawableX, drawableY);
                iconToDraw.setBounds(0, 0, drawableWidth, drawableHeight);
                iconToDraw.draw(canvas);
                canvas.translate(-drawableX, -drawableY);
                if (keyIsSpace && drawKeyboardNameText) {
                    // now a little hack, I'll set the label now, so it get
                    // drawn.
                    label = mKeyboardName;
                }
            } else {
                // ho... no icon.
                // I'll try to guess the text
                label = guessLabelForKey(key.codes[0]);
                if (TextUtils.isEmpty(label)) {
                    Log.w(TAG, "That's unfortunate, for key " + key.codes[0] + " at (" + key.x + ", " + key.y
                            + ") there is no icon nor label. Action ID is " + mKeyboardActionType);
                }
            }
        }

        if (label != null) {
            // For characters, use large font. For labels like "Done", use
            // small font.
            final FontMetrics fm;
            if (keyIsSpace) {
                paint.setTextSize(mKeyboardNameTextSize);
                paint.setTypeface(Typeface.DEFAULT_BOLD);
                if (mKeyboardNameFM == null)
                    mKeyboardNameFM = paint.getFontMetrics();
                fm = mKeyboardNameFM;
            } else if (label.length() > 1 && key.codes.length < 2) {
                paint.setTextSize(mLabelTextSize);
                paint.setTypeface(Typeface.DEFAULT_BOLD);
                if (mLabelFM == null)
                    mLabelFM = paint.getFontMetrics();
                fm = mLabelFM;
            } else {
                fm = setPaintToKeyText(paint);
            }

            final float labelHeight = -fm.top;
            // Draw a drop shadow for the text
            paint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mShadowColor);

            // (+)This is the trick to get RTL/LTR text correct
            // no matter what: StaticLayout
            // this should be in the top left corner of the key
            float textWidth = paint.measureText(label, 0, label.length());
            // I'm going to try something if the key is too small for the
            // text:
            // 1) divide the text size by 1.5
            // 2) if still too large, divide by 2.5
            // 3) show no text
            if (textWidth > key.width) {
                Log.d(TAG, "Label '" + label + "' is too large for the key. Reducing by 1.5.");
                paint.setTextSize(mKeyTextSize / 1.5f);
                textWidth = paint.measureText(label, 0, label.length());
                if (textWidth > key.width) {
                    Log.d(TAG, "Label '" + label + "' is too large for the key. Reducing by 2.5.");
                    paint.setTextSize(mKeyTextSize / 2.5f);
                    textWidth = paint.measureText(label, 0, label.length());
                    if (textWidth > key.width) {
                        Log.d(TAG, "Label '" + label + "' is too large for the key. Showing no text.");
                        paint.setTextSize(0f);
                        textWidth = paint.measureText(label, 0, label.length());
                    }
                }
            }

            // the center of the drawable space, which is value used
            // previously for vertically
            // positioning the key label
            final float centerY = mKeyBackgroundPadding.top
                    + ((key.height - mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom)
                            / (keyIsSpace ? 3 : 2));// the label on the space is a bit higher

            // the X coordinate for the center of the main label text is
            // unaffected by the hints
            final float centerX = mKeyBackgroundPadding.left
                    + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2;

            final float textX = centerX;
            final float textY;
            // Some devices (mostly pre-Honeycomb, have issues with RTL text
            // drawing.
            // Of course, there is no issue with a single character :)
            // so, we'll use the RTL secured drawing (via StaticLayout) for
            // labels.
            if (label.length() > 1 && !AnyApplication.getConfig().workaround_alwaysUseDrawText()) {
                // calculate Y coordinate of top of text based on center
                // location
                textY = centerY - ((labelHeight - paint.descent()) / 2);
                canvas.translate(textX, textY);
                Log.d(TAG, "Using RTL fix for key draw '" + label + "'");
                // RTL fix. But it costs, let do it when in need (more than
                // 1 character)
                StaticLayout labelText = new StaticLayout(label, new TextPaint(paint), (int) textWidth,
                        Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
                labelText.draw(canvas);
            } else {
                // to get Y coordinate of baseline from center of text,
                // first add half the height (to get to
                // bottom of text), then subtract the part below the
                // baseline. Note that fm.top is negative.
                textY = centerY + ((labelHeight - paint.descent()) / 2);
                canvas.translate(textX, textY);
                canvas.drawText(label, 0, label.length(), 0, 0, paint);
            }
            canvas.translate(-textX, -textY);
            // (-)

            // Turn off drop shadow
            paint.setShadowLayer(0, 0, 0, 0);
        }

        if (drawHintText) {
            if ((key.popupCharacters != null && key.popupCharacters.length() > 0) || (key.popupResId != 0)
                    || (key.longPressCode != 0)) {
                Paint.Align oldAlign = paint.getTextAlign();

                String hintText = null;

                if (key.hintLabel != null && key.hintLabel.length() > 0) {
                    hintText = key.hintLabel.toString();
                    // it is the responsibility of the keyboard layout
                    // designer to ensure that they do
                    // not put too many characters in the hint label...
                } else if (key.longPressCode != 0) {
                    if (Character.isLetterOrDigit(key.longPressCode))
                        hintText = Character.toString((char) key.longPressCode);
                } else if (key.popupCharacters != null) {
                    final String hintString = key.popupCharacters.toString();
                    final int hintLength = hintString.length();
                    if (hintLength <= 3)
                        hintText = hintString;
                }

                // if hintText is still null, it means it didn't fit one of
                // the above
                // cases, so we should provide the hint using the default
                if (hintText == null) {
                    if (mHintOverflowLabel != null)
                        hintText = mHintOverflowLabel.toString();
                    else {
                        // theme does not provide a defaultHintLabel
                        // use  if hints are above, ... if hints are
                        // below
                        // (to avoid being too close to main label/icon)
                        if (hintVAlign == Gravity.TOP)
                            hintText = "";
                        else
                            hintText = "...";
                    }
                }

                if (mKeyboard.isShifted())
                    hintText = hintText.toUpperCase();

                // now draw hint
                paint.setTypeface(Typeface.DEFAULT);
                paint.setColor(hintColor.getColorForState(drawableState, 0xFF000000));
                paint.setTextSize(mHintTextSize);
                // get the hint text font metrics so that we know the size
                // of the hint when
                // we try to position the main label (to try to make sure
                // they don't overlap)
                if (mHintTextFM == null) {
                    mHintTextFM = paint.getFontMetrics();
                }

                final float hintX;
                final float hintY;

                // the (float) 0.5 value is added or subtracted to just give
                // a little more room
                // in case the theme designer didn't account for the hint
                // label location
                if (hintAlign == Gravity.LEFT) {
                    // left
                    paint.setTextAlign(Paint.Align.LEFT);
                    hintX = mKeyBackgroundPadding.left + (float) 0.5;
                } else if (hintAlign == Gravity.CENTER) {
                    // center
                    paint.setTextAlign(Paint.Align.CENTER);
                    hintX = mKeyBackgroundPadding.left
                            + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2;
                } else {
                    // right
                    paint.setTextAlign(Paint.Align.RIGHT);
                    hintX = key.width - mKeyBackgroundPadding.right - (float) 0.5;
                }

                if (hintVAlign == Gravity.TOP) {
                    // above
                    hintY = mKeyBackgroundPadding.top - mHintTextFM.top + (float) 0.5;
                } else {
                    // below
                    hintY = key.height - mKeyBackgroundPadding.bottom - mHintTextFM.bottom - (float) 0.5;
                }

                canvas.drawText(hintText, hintX, hintY, paint);
                paint.setTextAlign(oldAlign);
            }
        }

        canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop);
    }
    mInvalidatedKey = null;
    // Overlay a dark rectangle to dim the keyboard
    if (mMiniKeyboard != null && mMiniKeyboardVisible) {
        paint.setColor((int) (mBackgroundDimAmount * 0xFF) << 24);
        canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
    }

    if (FeaturesSet.DEBUG_LOG) {
        if (mShowTouchPoints) {
            for (PointerTracker tracker : mPointerTrackers) {
                int startX = tracker.getStartX();
                int startY = tracker.getStartY();
                int lastX = tracker.getLastX();
                int lastY = tracker.getLastY();
                paint.setAlpha(128);
                paint.setColor(0xFFFF0000);
                canvas.drawCircle(startX, startY, 3, paint);
                canvas.drawLine(startX, startY, lastX, lastY, paint);
                paint.setColor(0xFF0000FF);
                canvas.drawCircle(lastX, lastY, 3, paint);
                paint.setColor(0xFF00FF00);
                canvas.drawCircle((startX + lastX) / 2, (startY + lastY) / 2, 2, paint);
            }
        }
    }

    mDrawPending = false;
    mDirtyRect.setEmpty();
}

From source file:com.am.pagergradienttab.view.PagerGradientTabStrip.java

/**
 * //w  w w.  j a  v  a 2 s .  c o m
 * 
 * @param canvas
 */
private void drawTag(Canvas canvas) {
    // TODO
    if (mTagAdapter != null) {
        canvas.save();
        float canvasOffset = 0;
        int x = getPaddingLeft();
        int y = getPaddingTop();
        float textTop = 0;
        mTextPaint.setColor(Color.WHITE);
        mTextPaint.setTextAlign(Align.LEFT);
        for (int position = 0; position < tabs.size(); position++) {
            canvas.translate(canvasOffset, 0);
            canvasOffset = itemWidth + intervalWidth;
            canvas.save();
            if (mTagAdapter.isEnable(position)) {
                int textWidth;
                int textHeight;
                mTextPaint.setTextSize(mTagAdapter.getTextSize(position));
                String tag = mTagAdapter.getTag(position) == null ? "" : mTagAdapter.getTag(position);
                textWidth = (int) Math.ceil(mTextPaint.measureText(tag));
                FontMetrics fontMetrics = mTextPaint.getFontMetrics();
                textHeight = (int) Math.ceil(fontMetrics.descent - fontMetrics.ascent);
                textTop = textHeight - (-fontMetrics.ascent - fontMetrics.descent
                        + (fontMetrics.bottom - fontMetrics.descent) * density);
                textHeight += textTop;
                if ("".equals(tag)) {
                    textHeight = 0;
                }
                final Drawable drawable = mTagAdapter.getBackground(position);
                int drawableWidth = drawable == null ? 0 : drawable.getMinimumWidth();
                int drawableHeight = drawable == null ? 0 : drawable.getMinimumHeight();
                float offsetX = Math.max(textWidth + mTagAdapter.getPaddingLeft(position)
                        + mTagAdapter.getPaddingRight(position), drawableWidth);
                float offsetTextX = (offsetX - (textWidth + mTagAdapter.getPaddingLeft(position)
                        + mTagAdapter.getPaddingRight(position))) * 0.5f;
                float offsetY = Math.max(textHeight + mTagAdapter.getPaddingBottom(position)
                        + mTagAdapter.getPaddingTop(position), drawableHeight);
                float offsetTextY = (offsetY - (textHeight + mTagAdapter.getPaddingBottom(position)
                        + mTagAdapter.getPaddingTop(position))) * 0.5f;

                mTextPaint.setTextSize(showTextScale ? textSize * (1 + magnification) : textSize);
                float myTextWidth = mTextPaint.measureText(tabs.get(position));
                TagAlign ta = mTagAdapter.getTagAlign(position);
                switch (ta) {
                default:
                case LEFTTOP:
                    canvas.translate(mTagAdapter.getMarginLeft(position), mTagAdapter.getMarginTop(position));
                    break;
                case LEFTCENTER:
                    canvas.translate(mTagAdapter.getMarginLeft(position),
                            (getHeight() - underLineHeight - offsetY) / 2);
                    break;
                case LEFTBOTTOM:
                    canvas.translate(mTagAdapter.getMarginLeft(position),
                            getHeight() - offsetY - underLineHeight - mTagAdapter.getMarginBottom(position));
                    break;
                case RIGHTTOP:
                    canvas.translate(itemWidth - offsetX - mTagAdapter.getMarginRight(position),
                            mTagAdapter.getMarginTop(position));
                    break;
                case RIGHTCENTER:
                    canvas.translate(itemWidth - offsetX - mTagAdapter.getMarginRight(position),
                            (getHeight() - underLineHeight - offsetY) / 2);
                    break;
                case RIGHTBOTTOM:
                    canvas.translate(itemWidth - offsetX - mTagAdapter.getMarginRight(position),
                            getHeight() - offsetY - underLineHeight - mTagAdapter.getMarginBottom(position));
                    break;
                case LEFTTOPTEXT:
                    canvas.translate(
                            (itemWidth - myTextWidth) / 2 - offsetX - mTagAdapter.getMarginRight(position),
                            mTagAdapter.getMarginTop(position));
                    break;
                case LEFTCENTERTEXT:
                    canvas.translate(
                            (itemWidth - myTextWidth) / 2 - offsetX - mTagAdapter.getMarginRight(position),
                            (getHeight() - underLineHeight - offsetY) / 2);
                    break;
                case LEFTBOTTOMTEXT:
                    canvas.translate(
                            (itemWidth - myTextWidth) / 2 - offsetX - mTagAdapter.getMarginRight(position),
                            getHeight() - offsetY - underLineHeight - mTagAdapter.getMarginBottom(position));
                    break;
                case RIGHTTOPTEXT:
                    canvas.translate((itemWidth + myTextWidth) / 2 + mTagAdapter.getMarginLeft(position),
                            mTagAdapter.getMarginTop(position));
                    break;
                case RIGHTCENTERTEXT:
                    canvas.translate((itemWidth + myTextWidth) / 2 + mTagAdapter.getMarginLeft(position),
                            (getHeight() - underLineHeight - offsetY) / 2);
                    break;

                case RIGHTBOTTOMTEXT:
                    canvas.translate((itemWidth + myTextWidth) / 2 + mTagAdapter.getMarginLeft(position),
                            getHeight() - offsetY - underLineHeight - mTagAdapter.getMarginBottom(position));
                    break;

                }
                mTextPaint.setTextSize(mTagAdapter.getTextSize(position));
                if (drawable != null) {
                    drawable.setBounds(x, y, (int) (x + offsetX), (int) (y + offsetY));
                    drawable.draw(canvas);
                }
                canvas.drawText(tag, x + offsetTextX + mTagAdapter.getPaddingLeft(position),
                        y + offsetY - textTop - offsetTextY - mTagAdapter.getPaddingTop(position), mTextPaint);
            }
            canvas.restore();
        }
        canvas.restore();
    }
}

From source file:g7.bluesky.launcher3.Launcher.java

public void loadIconPack(List<ShortcutInfo> shortcuts) {
    //theming vars-----------------------------------------------
    PackageManager pm = getPackageManager();
    final int ICONSIZE = Tools.numtodp(128, Launcher.this);
    Resources themeRes = null;/*w  w w . j  a v  a  2s  . co m*/
    String resPacName = defaultSharedPref.getString(SettingConstants.ICON_THEME_PREF_KEY, "");
    String iconResource = null;
    int intres = 0;
    int intresiconback = 0;
    int intresiconfront = 0;
    int intresiconmask = 0;
    float scaleFactor = 1.0f;

    Paint p = new Paint(Paint.FILTER_BITMAP_FLAG);
    p.setAntiAlias(true);

    Paint origP = new Paint(Paint.FILTER_BITMAP_FLAG);
    origP.setAntiAlias(true);

    Paint maskp = new Paint(Paint.FILTER_BITMAP_FLAG);
    maskp.setAntiAlias(true);
    maskp.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));

    if (resPacName.compareTo("") != 0) {
        try {
            themeRes = pm.getResourcesForApplication(resPacName);
        } catch (Exception e) {
        }
        ;
        if (themeRes != null) {
            String[] backAndMaskAndFront = ThemeTools.getIconBackAndMaskResourceName(themeRes, resPacName);
            if (backAndMaskAndFront[0] != null)
                intresiconback = themeRes.getIdentifier(backAndMaskAndFront[0], "drawable", resPacName);
            if (backAndMaskAndFront[1] != null)
                intresiconmask = themeRes.getIdentifier(backAndMaskAndFront[1], "drawable", resPacName);
            if (backAndMaskAndFront[2] != null)
                intresiconfront = themeRes.getIdentifier(backAndMaskAndFront[2], "drawable", resPacName);
        }
    }

    BitmapFactory.Options uniformOptions = new BitmapFactory.Options();
    uniformOptions.inScaled = false;
    uniformOptions.inDither = false;
    uniformOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;

    Canvas origCanv;
    Canvas canvas;
    scaleFactor = ThemeTools.getScaleFactor(themeRes, resPacName);
    Bitmap back = null;
    Bitmap mask = null;
    Bitmap front = null;
    Bitmap scaledBitmap = null;
    Bitmap scaledOrig = null;
    Bitmap orig = null;

    if (resPacName.compareTo("") != 0 && themeRes != null) {
        try {
            if (intresiconback != 0)
                back = BitmapFactory.decodeResource(themeRes, intresiconback, uniformOptions);
        } catch (Exception e) {
        }
        try {
            if (intresiconmask != 0)
                mask = BitmapFactory.decodeResource(themeRes, intresiconmask, uniformOptions);
        } catch (Exception e) {
        }
        try {
            if (intresiconfront != 0)
                front = BitmapFactory.decodeResource(themeRes, intresiconfront, uniformOptions);
        } catch (Exception e) {
        }
    }
    //theming vars-----------------------------------------------
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;
    options.inPreferredConfig = Bitmap.Config.RGB_565;
    options.inDither = true;

    for (int i = 0; i < shortcuts.size(); i++) {
        if (themeRes != null) {
            iconResource = null;
            intres = 0;
            iconResource = ThemeTools.getResourceName(themeRes, resPacName,
                    shortcuts.get(i).getTargetComponent().toString());
            if (iconResource != null) {
                intres = themeRes.getIdentifier(iconResource, "drawable", resPacName);
            }

            if (intres != 0) {//has single drawable for app
                shortcuts.get(i).setIcon(BitmapFactory.decodeResource(themeRes, intres, uniformOptions));
            } else {

                Drawable drawable = Utilities.createIconDrawable(shortcuts.get(i).getIcon(mIconCache));
                orig = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                        Bitmap.Config.ARGB_8888);
                drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
                drawable.draw(new Canvas(orig));

                scaledOrig = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888);
                scaledBitmap = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888);
                canvas = new Canvas(scaledBitmap);
                if (back != null) {
                    canvas.drawBitmap(back, Tools.getResizedMatrix(back, ICONSIZE, ICONSIZE), p);
                }

                origCanv = new Canvas(scaledOrig);
                orig = Tools.getResizedBitmap(orig, ((int) (ICONSIZE * scaleFactor)),
                        ((int) (ICONSIZE * scaleFactor)));
                origCanv.drawBitmap(orig,
                        scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2,
                        scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, origP);

                if (mask != null) {
                    origCanv.drawBitmap(mask, Tools.getResizedMatrix(mask, ICONSIZE, ICONSIZE), maskp);
                }

                if (back != null) {
                    canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p);
                } else
                    canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p);

                if (front != null)
                    canvas.drawBitmap(front, Tools.getResizedMatrix(front, ICONSIZE, ICONSIZE), p);

                shortcuts.get(i).setIcon(scaledBitmap);
            }
        }
    }
}

From source file:g7.bluesky.launcher3.Launcher.java

public void loadIconPack() {
    //theming vars-----------------------------------------------
    PackageManager pm = getPackageManager();
    final int ICONSIZE = Tools.numtodp(64, Launcher.this);
    Resources themeRes = null;/*from   w  w w  . ja  va  2  s.  co m*/
    String resPacName = defaultSharedPref.getString(SettingConstants.ICON_THEME_PREF_KEY, "");
    String iconResource = null;
    int intres = 0;
    int intresiconback = 0;
    int intresiconfront = 0;
    int intresiconmask = 0;
    float scaleFactor = 1.0f;

    Paint p = new Paint(Paint.FILTER_BITMAP_FLAG);
    p.setAntiAlias(true);

    Paint origP = new Paint(Paint.FILTER_BITMAP_FLAG);
    origP.setAntiAlias(true);

    Paint maskp = new Paint(Paint.FILTER_BITMAP_FLAG);
    maskp.setAntiAlias(true);
    maskp.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));

    if (resPacName.compareTo("") != 0) {
        try {
            themeRes = pm.getResourcesForApplication(resPacName);
        } catch (Exception e) {
        }
        ;
        if (themeRes != null) {
            String[] backAndMaskAndFront = ThemeTools.getIconBackAndMaskResourceName(themeRes, resPacName);
            if (backAndMaskAndFront[0] != null)
                intresiconback = themeRes.getIdentifier(backAndMaskAndFront[0], "drawable", resPacName);
            if (backAndMaskAndFront[1] != null)
                intresiconmask = themeRes.getIdentifier(backAndMaskAndFront[1], "drawable", resPacName);
            if (backAndMaskAndFront[2] != null)
                intresiconfront = themeRes.getIdentifier(backAndMaskAndFront[2], "drawable", resPacName);
        }
    }

    BitmapFactory.Options uniformOptions = new BitmapFactory.Options();
    uniformOptions.inScaled = false;
    uniformOptions.inDither = false;
    uniformOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;

    Canvas origCanv;
    Canvas canvas;
    scaleFactor = ThemeTools.getScaleFactor(themeRes, resPacName);
    Bitmap back = null;
    Bitmap mask = null;
    Bitmap front = null;
    Bitmap scaledBitmap = null;
    Bitmap scaledOrig = null;
    Bitmap orig = null;

    if (resPacName.compareTo("") != 0 && themeRes != null) {
        try {
            if (intresiconback != 0)
                back = BitmapFactory.decodeResource(themeRes, intresiconback, uniformOptions);
        } catch (Exception e) {
        }
        try {
            if (intresiconmask != 0)
                mask = BitmapFactory.decodeResource(themeRes, intresiconmask, uniformOptions);
        } catch (Exception e) {
        }
        try {
            if (intresiconfront != 0)
                front = BitmapFactory.decodeResource(themeRes, intresiconfront, uniformOptions);
        } catch (Exception e) {
        }
    }
    //theming vars-----------------------------------------------
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;
    options.inPreferredConfig = Bitmap.Config.RGB_565;
    options.inDither = true;

    for (int i = 0; i < listApps.size(); i++) {
        if (themeRes != null) {
            iconResource = null;
            intres = 0;
            iconResource = ThemeTools.getResourceName(themeRes, resPacName,
                    listApps.get(i).getComponentName().toString());
            if (iconResource != null) {
                intres = themeRes.getIdentifier(iconResource, "drawable", resPacName);
            }

            if (intres != 0) {//has single drawable for app
                listApps.get(i).setIconBitmap(BitmapFactory.decodeResource(themeRes, intres, uniformOptions));
            } else {
                Drawable drawable = listApps.get(i).getIconDrawable();
                if (drawable == null) {
                    drawable = Utilities.createIconDrawable(listApps.get(i).getIconBitmap());
                }
                orig = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                        Bitmap.Config.ARGB_8888);
                drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
                drawable.draw(new Canvas(orig));

                scaledOrig = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888);
                scaledBitmap = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888);
                canvas = new Canvas(scaledBitmap);
                if (back != null) {
                    canvas.drawBitmap(back, Tools.getResizedMatrix(back, ICONSIZE, ICONSIZE), p);
                }

                origCanv = new Canvas(scaledOrig);
                orig = Tools.getResizedBitmap(orig, ((int) (ICONSIZE * scaleFactor)),
                        ((int) (ICONSIZE * scaleFactor)));
                origCanv.drawBitmap(orig,
                        scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2,
                        scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, origP);

                if (mask != null) {
                    origCanv.drawBitmap(mask, Tools.getResizedMatrix(mask, ICONSIZE, ICONSIZE), maskp);
                }

                if (back != null) {
                    canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p);
                } else
                    canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p);

                if (front != null)
                    canvas.drawBitmap(front, Tools.getResizedMatrix(front, ICONSIZE, ICONSIZE), p);

                listApps.get(i).setIconBitmap(scaledBitmap);
            }
        }
    }
}

From source file:com.aliasapps.seq.scroller.TwoWayView.java

private void drawSelector(Canvas canvas) {
    if (!mSelectorRect.isEmpty()) {
        final Drawable selector = mSelector;
        selector.setBounds(mSelectorRect);
        selector.draw(canvas);
    }/*  w ww . j  av a 2  s . com*/
}

From source file:org.onebusaway.android.map.googlemapsv2.StopOverlay.java

/**
 * Creates a bus stop icon with the given direction arrow, or without a direction arrow if
 * the direction is NO_DIRECTION//from   w  w w .  j  a  v  a 2 s .  c  o m
 *
 * @param direction Bus stop direction, obtained from ObaStop.getDirection() and defined in
 *                  constants in this class, or NO_DIRECTION if the stop icon shouldn't have a
 *                  direction arrow
 * @return a bus stop icon bitmap with the arrow pointing the given direction, or with no arrow
 * if direction is NO_DIRECTION
 */
private static Bitmap createBusStopIcon(String direction) throws NullPointerException {
    if (direction == null) {
        throw new IllegalArgumentException(direction);
    }

    Resources r = Application.get().getResources();
    Context context = Application.get();

    Float directionAngle = null; // 0-360 degrees
    Bitmap bm;
    Canvas c;
    Drawable shape;
    Float rotationX = null, rotationY = null; // Point around which to rotate the arrow

    Paint arrowPaintFill = new Paint();
    arrowPaintFill.setStyle(Paint.Style.FILL);
    arrowPaintFill.setAntiAlias(true);

    if (direction.equals(NO_DIRECTION)) {
        // Don't draw the arrow
        bm = Bitmap.createBitmap(mPx, mPx, Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, bm.getWidth(), bm.getHeight());
    } else if (direction.equals(NORTH)) {
        directionAngle = 0f;
        bm = Bitmap.createBitmap(mPx, (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, (int) mBuffer, mPx, bm.getHeight());
        // Shade with darkest color at tip of arrow
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth() / 2, 0, bm.getWidth() / 2, mArrowHeightPx,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // For NORTH, no rotation occurs - use center of image anyway so we have some value
        rotationX = bm.getWidth() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(NORTH_WEST)) {
        directionAngle = 315f; // Arrow is drawn N, rotate 315 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds((int) mBuffer, (int) mBuffer, bm.getWidth(), bm.getHeight());
        // Shade with darkest color at tip of arrow
        arrowPaintFill.setShader(new LinearGradient(0, 0, mBuffer, mBuffer, r.getColor(R.color.theme_primary),
                r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // Rotate around below coordinates (trial and error)
        rotationX = mPx / 2f + mBuffer / 2f;
        rotationY = bm.getHeight() / 2f - mBuffer / 2f;
    } else if (direction.equals(WEST)) {
        directionAngle = 0f; // Arrow is drawn pointing West, so no rotation
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), mPx, Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds((int) mBuffer, 0, bm.getWidth(), bm.getHeight());
        arrowPaintFill.setShader(new LinearGradient(0, bm.getHeight() / 2, mArrowHeightPx, bm.getHeight() / 2,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // For WEST
        rotationX = bm.getHeight() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(SOUTH_WEST)) {
        directionAngle = 225f; // Arrow is drawn N, rotate 225 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds((int) mBuffer, 0, bm.getWidth(), mPx);
        arrowPaintFill.setShader(new LinearGradient(0, bm.getHeight(), mBuffer, bm.getHeight() - mBuffer,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // Rotate around below coordinates (trial and error)
        rotationX = bm.getWidth() / 2f - mBuffer / 4f;
        rotationY = mPx / 2f + mBuffer / 4f;
    } else if (direction.equals(SOUTH)) {
        directionAngle = 180f; // Arrow is drawn N, rotate 180 degrees
        bm = Bitmap.createBitmap(mPx, (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, bm.getWidth(), (int) (bm.getHeight() - mBuffer));
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth() / 2, bm.getHeight(), bm.getWidth() / 2,
                bm.getHeight() - mArrowHeightPx, r.getColor(R.color.theme_primary),
                r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        rotationX = bm.getWidth() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(SOUTH_EAST)) {
        directionAngle = 135f; // Arrow is drawn N, rotate 135 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, mPx, mPx);
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), bm.getHeight(), bm.getWidth() - mBuffer,
                bm.getHeight() - mBuffer, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent),
                Shader.TileMode.MIRROR));
        // Rotate around below coordinates (trial and error)
        rotationX = (mPx + mBuffer / 2) / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(EAST)) {
        directionAngle = 180f; // Arrow is drawn pointing West, so rotate 180
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), mPx, Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, mPx, bm.getHeight());
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), bm.getHeight() / 2,
                bm.getWidth() - mArrowHeightPx, bm.getHeight() / 2, r.getColor(R.color.theme_primary),
                r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        rotationX = bm.getWidth() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(NORTH_EAST)) {
        directionAngle = 45f; // Arrow is drawn pointing N, so rotate 45 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, (int) mBuffer, mPx, bm.getHeight());
        // Shade with darkest color at tip of arrow
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), 0, bm.getWidth() - mBuffer, mBuffer,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // Rotate around middle of circle
        rotationX = (float) mPx / 2;
        rotationY = bm.getHeight() - (float) mPx / 2;
    } else {
        throw new IllegalArgumentException(direction);
    }

    shape.draw(c);

    if (direction.equals(NO_DIRECTION)) {
        // Everything after this point is for drawing the arrow image, so return the bitmap as-is for no arrow
        return bm;
    }

    /**
     * Draw the arrow - all dimensions should be relative to px so the arrow is drawn the same
     * size for all orientations
     */
    // Height of the cutout in the bottom of the triangle that makes it an arrow (0=triangle)
    final float CUTOUT_HEIGHT = mPx / 12;
    Path path = new Path();
    float x1 = 0, y1 = 0; // Tip of arrow
    float x2 = 0, y2 = 0; // lower left
    float x3 = 0, y3 = 0; // cutout in arrow bottom
    float x4 = 0, y4 = 0; // lower right

    if (direction.equals(NORTH) || direction.equals(SOUTH) || direction.equals(NORTH_EAST)
            || direction.equals(SOUTH_EAST) || direction.equals(NORTH_WEST) || direction.equals(SOUTH_WEST)) {
        // Arrow is drawn pointing NORTH
        // Tip of arrow
        x1 = mPx / 2;
        y1 = 0;

        // lower left
        x2 = (mPx / 2) - (mArrowWidthPx / 2);
        y2 = mArrowHeightPx;

        // cutout in arrow bottom
        x3 = mPx / 2;
        y3 = mArrowHeightPx - CUTOUT_HEIGHT;

        // lower right
        x4 = (mPx / 2) + (mArrowWidthPx / 2);
        y4 = mArrowHeightPx;
    } else if (direction.equals(EAST) || direction.equals(WEST)) {
        // Arrow is drawn pointing WEST
        // Tip of arrow
        x1 = 0;
        y1 = mPx / 2;

        // lower left
        x2 = mArrowHeightPx;
        y2 = (mPx / 2) - (mArrowWidthPx / 2);

        // cutout in arrow bottom
        x3 = mArrowHeightPx - CUTOUT_HEIGHT;
        y3 = mPx / 2;

        // lower right
        x4 = mArrowHeightPx;
        y4 = (mPx / 2) + (mArrowWidthPx / 2);
    }

    path.setFillType(Path.FillType.EVEN_ODD);
    path.moveTo(x1, y1);
    path.lineTo(x2, y2);
    path.lineTo(x3, y3);
    path.lineTo(x4, y4);
    path.lineTo(x1, y1);
    path.close();

    // Rotate arrow around (rotationX, rotationY) point
    Matrix matrix = new Matrix();
    matrix.postRotate(directionAngle, rotationX, rotationY);
    path.transform(matrix);

    c.drawPath(path, arrowPaintFill);
    c.drawPath(path, mArrowPaintStroke);

    return bm;
}

From source file:com.fondesa.recyclerviewdivider.RecyclerViewDivider.java

@SuppressWarnings("ConstantConditions")
@Override/*from  w w w.  j  a v a  2  s .  c  om*/
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    final RecyclerView.Adapter adapter = parent.getAdapter();
    final int listSize;

    // if the divider isn't a simple space, it will be drawn
    if (mType == TYPE_SPACE || adapter == null || (listSize = adapter.getItemCount()) == 0)
        return;

    int left;
    int top;
    int right;
    int bottom;

    final int orientation = RecyclerViewDividerUtils.getOrientation(parent);
    final int spanCount = RecyclerViewDividerUtils.getSpanCount(parent);
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        int itemPosition = parent.getChildAdapterPosition(child);
        final int groupIndex = RecyclerViewDividerUtils.getGroupIndex(parent, itemPosition);
        final int groupCount = RecyclerViewDividerUtils.getGroupCount(parent, listSize);

        Drawable divider = mDrawableFactory.drawableForItem(groupCount, groupIndex);
        @VisibilityFactory.Show
        int showDivider = mVisibilityFactory.displayDividerForItem(groupCount, groupIndex);

        if (divider == null || showDivider == VisibilityFactory.SHOW_NONE)
            continue;

        final int spanSize = RecyclerViewDividerUtils.getSpanSize(parent, itemPosition);

        int lineAccumulatedSpan = RecyclerViewDividerUtils.getAccumulatedSpanInLine(parent, spanSize,
                itemPosition, groupIndex);

        final int margin = mMarginFactory.marginSizeForItem(groupCount, groupIndex);
        int size = mSizeFactory.sizeForItem(divider, orientation, groupCount, groupIndex);
        if (mTintFactory != null) {
            final int tint = mTintFactory.tintForItem(groupCount, groupIndex);
            Drawable wrappedDrawable = DrawableCompat.wrap(divider);
            DrawableCompat.setTint(wrappedDrawable, tint);
            divider = wrappedDrawable;
        }

        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

        int halfSize = size < 2 ? size : size / 2;

        size = showDivider == VisibilityFactory.SHOW_ITEMS_ONLY ? 0 : size;
        halfSize = showDivider == VisibilityFactory.SHOW_GROUP_ONLY ? 0 : halfSize;

        final int childBottom = child.getBottom();
        final int childTop = child.getTop();
        final int childRight = child.getRight();
        final int childLeft = child.getLeft();

        // if the last element in the span doesn't complete the span count, its size will be full, not the half
        // halfSize * 2 is used instead of size to handle the case Show.ITEMS_ONLY in which size will be == 0
        final int lastElementInSpanSize = itemPosition == listSize - 1 ? halfSize * 2 : halfSize;

        final boolean useCellMargin = margin == 0;

        int marginToAddBefore, marginToAddAfter;
        marginToAddBefore = marginToAddAfter = 0;

        if (orientation == RecyclerView.VERTICAL) {
            if (spanCount > 1 && spanSize < spanCount) {
                top = childTop + margin;
                // size is added to draw filling point between horizontal and vertical dividers
                bottom = childBottom - margin;

                if (useCellMargin) {
                    if (groupIndex > 0) {
                        top -= params.topMargin;
                    }
                    if (groupIndex < groupCount - 1 || size > 0) {
                        bottom += params.bottomMargin;
                    }
                    bottom += size;
                }

                if (lineAccumulatedSpan == spanSize) {
                    // first element in the group
                    left = childRight + margin + params.rightMargin;
                    right = left + lastElementInSpanSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    if (useCellMargin) {
                        marginToAddAfter = params.rightMargin;
                    }
                } else if (lineAccumulatedSpan == spanCount) {
                    // last element in the group
                    right = childLeft - margin - params.leftMargin;
                    left = right - halfSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    if (useCellMargin) {
                        marginToAddBefore = params.leftMargin;
                    }
                } else {
                    // element in the middle
                    // left half divider
                    right = childLeft - margin - params.leftMargin;
                    left = right - halfSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    // right half divider
                    left = childRight + margin + params.rightMargin;
                    right = left + lastElementInSpanSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    if (useCellMargin) {
                        marginToAddAfter = params.rightMargin;
                        marginToAddBefore = params.leftMargin;
                    }
                }
            }

            // draw bottom divider
            top = childBottom + params.bottomMargin;
            bottom = top + size;
            left = childLeft + margin - marginToAddBefore;
            right = childRight - margin + marginToAddAfter;

            setBoundsAndDraw(divider, c, left, top, right, bottom);

        } else {
            if (spanCount > 1 && spanSize < spanCount) {
                left = childLeft + margin;
                // size is added to draw filling point between horizontal and vertical dividers
                right = childRight - margin;
                if (useCellMargin) {
                    if (groupIndex > 0) {
                        left -= params.leftMargin;
                    }
                    if (groupIndex < groupCount - 1 || size > 0) {
                        right += params.rightMargin;
                    }
                    right += size;
                }

                if (lineAccumulatedSpan == spanSize) {
                    // first element in the group
                    top = childBottom + margin + params.bottomMargin;
                    bottom = top + lastElementInSpanSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    if (useCellMargin) {
                        marginToAddAfter = params.bottomMargin;
                    }
                } else if (lineAccumulatedSpan == spanCount) {
                    // last element in the group
                    bottom = childTop - margin - params.topMargin;
                    top = bottom - halfSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    if (useCellMargin) {
                        marginToAddBefore = params.topMargin;
                    }
                } else {
                    // element in the middle
                    // top half divider
                    bottom = childTop - margin - params.topMargin;
                    top = bottom - halfSize;

                    divider.setBounds(left, top, right, bottom);
                    divider.draw(c);

                    // bottom half divider
                    top = childBottom + margin + params.bottomMargin;
                    bottom = top + lastElementInSpanSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    if (useCellMargin) {
                        marginToAddAfter = params.bottomMargin;
                        marginToAddBefore = params.topMargin;
                    }
                }
            }

            // draw right divider
            bottom = childBottom - margin + marginToAddAfter;
            top = childTop + margin - marginToAddBefore;
            left = childRight + params.rightMargin;
            right = left + size;

            setBoundsAndDraw(divider, c, left, top, right, bottom);
        }
    }
}