Example usage for android.view Gravity VERTICAL_GRAVITY_MASK

List of usage examples for android.view Gravity VERTICAL_GRAVITY_MASK

Introduction

In this page you can find the example usage for android.view Gravity VERTICAL_GRAVITY_MASK.

Prototype

int VERTICAL_GRAVITY_MASK

To view the source code for android.view Gravity VERTICAL_GRAVITY_MASK.

Click Source Link

Document

Binary mask to get the vertical gravity of a gravity.

Usage

From source file:nevet.me.wcviewpager.WrapContentViewPager.java

/**
 * Allows to redraw the view size to wrap the content of the bigger child.
 *
 * @param widthMeasureSpec  with measured
 * @param heightMeasureSpec height measured
 *///ww  w  .j  a  v  a 2s  . co m
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    widthMeasuredSpec = widthMeasureSpec;
    int mode = MeasureSpec.getMode(heightMeasureSpec);

    if (mode == MeasureSpec.UNSPECIFIED || mode == MeasureSpec.AT_MOST) {
        if (height == 0) {
            // measure vertical decor (i.e. PagerTitleStrip) based on ViewPager implementation
            decorHeight = 0;
            for (int i = 0; i < getChildCount(); i++) {
                View child = getChildAt(i);
                LayoutParams lp = (LayoutParams) child.getLayoutParams();
                if (lp != null && lp.isDecor) {
                    int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                    boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
                    if (consumeVertical) {
                        decorHeight += child.getMeasuredHeight();
                    }
                }
            }

            // make sure that we have an height (not sure if this is necessary because it seems that onPageScrolled is called right after
            int position = getCurrentItem();
            View child = getViewAtPosition(position);
            if (child != null) {
                height = measureViewHeight(child);
            }
            Log.d(TAG, "onMeasure height:" + height + " decor:" + decorHeight);

        }
        int totalHeight = height + decorHeight + getPaddingBottom() + getPaddingTop();
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(totalHeight, MeasureSpec.EXACTLY);
        Log.d(TAG, "onMeasure total height:" + totalHeight);
    }

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:id.co.datascrip.dtswarehousesystem.custom.StepPagerStrip.java

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

    if (mPageCount == 0) {
        return;// w w  w  .j a  v a2s .  c o  m
    }

    float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing;
    float totalLeft;
    boolean fillHorizontal = false;

    switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        totalLeft = (getWidth() - totalWidth) / 2;
        break;
    case Gravity.END:
        totalLeft = getWidth() - getPaddingRight() - totalWidth;
        break;
    case Gravity.FILL_HORIZONTAL:
        totalLeft = getPaddingLeft();
        fillHorizontal = true;
        break;
    default:
        totalLeft = getPaddingLeft();
    }

    switch (mGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.CENTER_VERTICAL:
        mTempRectF.top = (int) (getHeight() - mTabHeight) / 2;
        break;
    case Gravity.BOTTOM:
        mTempRectF.top = getHeight() - getPaddingBottom() - mTabHeight;
        break;
    default:
        mTempRectF.top = getPaddingTop();
    }

    mTempRectF.bottom = mTempRectF.top + mTabHeight;

    float tabWidth = mTabWidth;
    if (fillHorizontal) {
        tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (mPageCount - 1) * mTabSpacing)
                / mPageCount;
    }

    for (int i = 0; i < mPageCount; i++) {
        mTempRectF.left = totalLeft + (i * (tabWidth + mTabSpacing));
        mTempRectF.right = mTempRectF.left + tabWidth;
        canvas.drawRect(mTempRectF,
                i < mCurrentPage ? mPrevTabPaint
                        : (i > mCurrentPage ? mNextTabPaint
                                : (i == mPageCount - 1 ? mSelectedLastTabPaint : mSelectedTabPaint)));
    }
}

From source file:com.culinars.culinars.WrapContentViewPager.java

/**
 * Allows to redraw the view size to wrap the content of the bigger child.
 *
 * @param widthMeasureSpec  with measured
 * @param heightMeasureSpec height measured
 *///w  w  w  .ja  va 2 s.  com
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    widthMeasuredSpec = widthMeasureSpec;
    int mode = MeasureSpec.getMode(heightMeasureSpec);

    if (mode == MeasureSpec.UNSPECIFIED || mode == MeasureSpec.AT_MOST) {
        if (height == 0) {
            // measure vertical decor (i.e. PagerTitleStrip) based on ViewPager implementation
            decorHeight = 0;
            for (int i = 0; i < getChildCount(); i++) {
                View child = getChildAt(i);
                LayoutParams lp = (LayoutParams) child.getLayoutParams();
                if (lp != null && lp.isDecor) {
                    int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                    boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
                    if (consumeVertical) {
                        decorHeight += child.getMeasuredHeight();
                    }
                }
            }

            // make sure that we have an height (not sure if this is necessary because it seems that onPageScrolled is called right after
            int position = getCurrentItem();
            View child = getViewAtPosition(position);
            if (child != null) {
                height = measureViewHeight(child);
            }
            Log.d(TAG, "onMeasure height:" + height + " decor:" + decorHeight);

        }
        int totalHeight = height + decorHeight + getPaddingBottom() + getPaddingTop();
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(totalHeight, MeasureSpec.EXACTLY);
        Log.d(TAG, "onMeasure total height:" + totalHeight);
    }

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:com.tmall.ultraviewpager.UltraViewPagerIndicator.java

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

    if (viewPager == null || viewPager.getAdapter() == null)
        return;/*from   w  ww . jav a  2s.c  o  m*/

    final int count = ((UltraViewPagerAdapter) viewPager.getAdapter()).getRealCount();
    if (count == 0)
        return;

    int longSize;
    int shortSize;

    int longPaddingBefore;
    int longPaddingAfter;
    int shortPaddingBefore;
    int shortPaddingAfter;
    if (orientation == UltraViewPager.Orientation.HORIZONTAL) {
        longSize = viewPager.getWidth();
        shortSize = viewPager.getHeight();
        longPaddingBefore = getPaddingLeft() + marginLeft;
        longPaddingAfter = getPaddingRight() + marginRight;
        shortPaddingBefore = getPaddingTop() + marginTop;
        shortPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom;
    } else {
        longSize = viewPager.getHeight();
        shortSize = viewPager.getWidth();
        longPaddingBefore = getPaddingTop() + marginTop;
        longPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom;
        shortPaddingBefore = getPaddingLeft() + marginLeft;
        shortPaddingAfter = getPaddingRight() + marginRight;
    }

    final float itemWidth = getItemWidth();
    final int widthRatio = isDrawResIndicator() ? 1 : 2; //bitmap resource X1 : circle  X2
    if (indicatorPadding == 0) {
        indicatorPadding = (int) itemWidth;
    }

    float shortOffset = shortPaddingBefore;
    float longOffset = longPaddingBefore;

    final float indicatorLength = (count - 1) * (itemWidth * widthRatio + indicatorPadding);

    final int horizontalGravityMask = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int verticalGravityMask = gravity & Gravity.VERTICAL_GRAVITY_MASK;
    switch (horizontalGravityMask) {
    case Gravity.CENTER_HORIZONTAL:
        longOffset = (longSize - longPaddingBefore - longPaddingAfter - indicatorLength) / 2.0f;
        break;
    case Gravity.RIGHT:
        if (orientation == UltraViewPager.Orientation.HORIZONTAL) {
            longOffset = longSize - longPaddingAfter - indicatorLength - itemWidth;
        }
        if (orientation == UltraViewPager.Orientation.VERTICAL) {
            shortOffset = shortSize - shortPaddingAfter - itemWidth;
        }
        break;
    case Gravity.LEFT:
        longOffset += itemWidth;
    default:
        break;
    }

    switch (verticalGravityMask) {
    case Gravity.CENTER_VERTICAL:
        shortOffset = (shortSize - shortPaddingAfter - shortPaddingBefore - itemWidth) / 2;
        break;
    case Gravity.BOTTOM:
        if (orientation == UltraViewPager.Orientation.HORIZONTAL) {
            shortOffset = shortSize - shortPaddingAfter - getItemHeight();
        }
        if (orientation == UltraViewPager.Orientation.VERTICAL) {
            longOffset = longSize - longPaddingAfter - indicatorLength;
        }
        break;
    case Gravity.TOP:
        shortOffset += itemWidth;
    default:
        break;
    }

    if (horizontalGravityMask == Gravity.CENTER_HORIZONTAL && verticalGravityMask == Gravity.CENTER_VERTICAL) {
        shortOffset = (shortSize - shortPaddingAfter - shortPaddingBefore - itemWidth) / 2;
    }

    float dX;
    float dY;

    float pageFillRadius = radius;
    if (paintStroke.getStrokeWidth() > 0) {
        pageFillRadius -= paintStroke.getStrokeWidth() / 2.0f; //TODO may not/2
    }

    //Draw stroked circles
    for (int iLoop = 0; iLoop < count; iLoop++) {
        float drawLong = longOffset + (iLoop * (itemWidth * widthRatio + indicatorPadding));

        if (orientation == UltraViewPager.Orientation.HORIZONTAL) {
            dX = drawLong;
            dY = shortOffset;
        } else {
            dX = shortOffset;
            dY = drawLong;
        }

        if (isDrawResIndicator()) {
            if (iLoop == viewPager.getCurrentItem())
                continue;
            canvas.drawBitmap(normalBitmap, dX, dY, paintFill);
        } else {
            // Only paint fill if not completely transparent
            if (paintFill.getAlpha() > 0) {
                paintFill.setColor(normalColor);
                canvas.drawCircle(dX, dY, pageFillRadius, paintFill);
            }

            // Only paint stroke if a stroke width was non-zero
            if (pageFillRadius != radius) {
                canvas.drawCircle(dX, dY, radius, paintStroke);
            }
        }
    }

    //Draw the filled circle according to the current scroll
    float cx = (viewPager.getCurrentItem()) * (itemWidth * widthRatio + indicatorPadding);
    if (animateIndicator)
        cx += pageOffset * itemWidth;
    if (orientation == UltraViewPager.Orientation.HORIZONTAL) {
        dX = longOffset + cx;
        dY = shortOffset;
    } else {
        dX = shortOffset;
        dY = longOffset + cx;
    }

    if (isDrawResIndicator()) {
        canvas.drawBitmap(focusBitmap, dX, dY, paintStroke);
    } else {
        paintFill.setColor(focusColor);
        canvas.drawCircle(dX, dY, radius, paintFill);
    }
}

From source file:com.qs.qswlw.view.Mypager.UltraViewPagerIndicator.java

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

    if (viewPager == null || viewPager.getAdapter() == null)
        return;/*from w w w . j ava  2  s.  c o  m*/

    final int count = ((UltraViewPagerAdapter) viewPager.getAdapter()).getRealCount();
    if (count == 0)
        return;

    int longSize;
    int shortSize;

    int longPaddingBefore;
    int longPaddingAfter;
    int shortPaddingBefore;
    int shortPaddingAfter;
    if (orientation == UltraViewPager.Orientation.HORIZONTAL) {
        longSize = viewPager.getWidth();
        shortSize = viewPager.getHeight();
        longPaddingBefore = (int) (getItemWidth() + getPaddingLeft() + marginLeft);
        longPaddingAfter = getPaddingRight() + marginRight;
        shortPaddingBefore = (int) (getItemWidth() + getPaddingTop() + marginTop);
        shortPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom;
    } else {
        longSize = viewPager.getHeight();
        shortSize = viewPager.getWidth();
        longPaddingBefore = (int) (getItemWidth() + getPaddingTop() + marginTop);
        longPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom;
        shortPaddingBefore = (int) (getItemWidth() + getPaddingLeft() + marginLeft);
        shortPaddingAfter = getPaddingRight() + marginRight;
    }

    final float itemWidth = getItemWidth();
    final int widthRatio = isDrawResIndicator() ? 1 : 2; //bitmap resource X1 : circle  X2
    if (indicatorPadding == 0) {
        indicatorPadding = (int) itemWidth;
    }

    float shortOffset = shortPaddingBefore;
    float longOffset = longPaddingBefore;

    final float indicatorLength = count * itemWidth * widthRatio + (count - 1) * indicatorPadding;

    final int horizontalGravityMask = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int verticalGravityMask = gravity & Gravity.VERTICAL_GRAVITY_MASK;
    switch (horizontalGravityMask) {
    case Gravity.CENTER_HORIZONTAL:
        longOffset = (longSize - longPaddingBefore - longPaddingAfter - indicatorLength) / 2.0f;
        break;
    case Gravity.RIGHT:
        if (orientation == UltraViewPager.Orientation.HORIZONTAL) {
            longOffset = longSize - longPaddingAfter - indicatorLength;
        }
        if (orientation == UltraViewPager.Orientation.VERTICAL) {
            shortOffset = shortSize - shortPaddingAfter - itemWidth;
        }
        break;
    case Gravity.LEFT:
    default:
        break;
    }

    switch (verticalGravityMask) {
    case Gravity.CENTER_VERTICAL:
        shortOffset = (shortSize - shortPaddingAfter - shortPaddingBefore - itemWidth) / 2;
        break;
    case Gravity.BOTTOM:
        if (orientation == UltraViewPager.Orientation.HORIZONTAL) {
            shortOffset = shortSize - shortPaddingAfter - getItemHeight();
        }
        if (orientation == UltraViewPager.Orientation.VERTICAL) {
            longOffset = longSize - longPaddingAfter - indicatorLength;
        }
        break;
    case Gravity.TOP:
    default:
        break;
    }

    if (horizontalGravityMask == Gravity.CENTER_HORIZONTAL && verticalGravityMask == Gravity.CENTER_VERTICAL) {
        shortOffset = (shortSize - shortPaddingAfter - shortPaddingBefore - itemWidth) / 2;
    }

    float dX;
    float dY;

    float pageFillRadius = radius;
    if (paintStroke.getStrokeWidth() > 0) {
        pageFillRadius -= paintStroke.getStrokeWidth() / 2.0f; //TODO may not/2
    }

    //Draw stroked circles
    for (int iLoop = 0; iLoop < count; iLoop++) {
        float drawLong = longOffset + (iLoop * (itemWidth * widthRatio + indicatorPadding));
        if (orientation == UltraViewPager.Orientation.HORIZONTAL) {
            dX = drawLong;
            dY = shortOffset;
        } else {
            dX = shortOffset;
            dY = drawLong;
        }

        if (isDrawResIndicator()) {
            if (iLoop == viewPager.getCurrentItem())
                continue;
            canvas.drawBitmap(normalBitmap, dX, dY, paintFill);
        } else {
            // Only paint fill if not completely transparent
            if (paintFill.getAlpha() > 0) {
                paintFill.setColor(normalColor);
                canvas.drawCircle(dX, dY, pageFillRadius, paintFill);
            }

            // Only paint stroke if a stroke width was non-zero
            if (pageFillRadius != radius) {
                canvas.drawCircle(dX, dY, radius, paintStroke);
            }
        }
    }

    //Draw the filled circle according to the current scroll
    float cx = (viewPager.getCurrentItem()) * (itemWidth * widthRatio + indicatorPadding);
    if (animateIndicator)
        cx += pageOffset * itemWidth;
    if (orientation == UltraViewPager.Orientation.HORIZONTAL) {
        dX = longOffset + cx;
        dY = shortOffset;
    } else {
        dX = shortOffset;
        dY = longOffset + cx;
    }

    if (isDrawResIndicator()) {
        canvas.drawBitmap(focusBitmap, dX, dY, paintStroke);
    } else {
        paintFill.setColor(focusColor);
        canvas.drawCircle(dX, dY, radius, paintFill);
    }
}

From source file:com.manuelpeinado.imagelayout.ImageLayout.java

public void setGravity(int newValue) {
    if (fitter != null && gravity == newValue) {
        return;/*  w  ww .j  a v  a 2 s  .  c  o  m*/
    }
    if ((newValue & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) {
        newValue |= Gravity.CENTER_HORIZONTAL;
    }
    if ((newValue & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
        newValue |= Gravity.CENTER_VERTICAL;
    }
    gravity = newValue;
    rebuildFitter();
}

From source file:com.kyo.fitssystemwindows.FitsSystemWindowsFrameLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final boolean applyInsets = lastInsets != null && ViewCompat.getFitsSystemWindows(this);
    final int layoutDirection = ViewCompat.getLayoutDirection(this);
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }//from w  w w  . j  av  a  2s . c  om

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (lp.gravity == -1) {
            lp.gravity = DEFAULT_CHILD_GRAVITY;
        }

        if (applyInsets) {
            int cgrav = GravityCompat.getAbsoluteGravity(lp.gravity, layoutDirection);

            if (cgrav == -1) {
                cgrav = DEFAULT_CHILD_GRAVITY;
            } else {
                if ((cgrav & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
                    cgrav = cgrav | Gravity.TOP;
                }
                if ((cgrav & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) {
                    cgrav = cgrav | (layoutDirection == LAYOUT_DIRECTION_LTR ? Gravity.LEFT : Gravity.RIGHT);
                }
            }

            if (ViewCompat.getFitsSystemWindows(child)) {
                final int l = child.getPaddingLeft();
                final int t = child.getPaddingTop();
                final int r = child.getPaddingRight();
                final int b = child.getPaddingBottom();
                IMPL.dispatchChildInsets(child, lp, cgrav, lastInsets);
                child.setPadding(l, t, r, b);
            } else {
                IMPL.applyMarginInsets(lp, cgrav, lastInsets);
                lp.leftMargin += lp.leftMargin2;
                lp.topMargin += lp.topMargin2;
                lp.rightMargin += lp.rightMargin2;
                lp.bottomMargin += lp.bottomMargin2;
            }
        }
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == GONE || ViewCompat.getFitsSystemWindows(child)) {
            continue;
        }
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        lp.leftMargin -= lp.leftMargin2;
        lp.topMargin -= lp.topMargin2;
        lp.rightMargin -= lp.rightMargin2;
        lp.bottomMargin -= lp.bottomMargin2;
    }
}

From source file:com.oshi.librcalendarwidget.views.WrapContentHeightViewPager.java

/**
 * Allows to redraw the view size to wrap the content of the bigger child.
 *
 * @param widthMeasureSpec  with measured
 * @param heightMeasureSpec height measured
 *///from w  w w  . jav a 2  s  .c  om
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    widthMeasuredSpec = widthMeasureSpec;
    int mode = MeasureSpec.getMode(heightMeasureSpec);

    if (mode == MeasureSpec.UNSPECIFIED || mode == MeasureSpec.AT_MOST) {
        if(height == 0) {
            // measure vertical decor (i.e. PagerTitleStrip) based on ViewPager implementation
            decorHeight = 0;
            for (int i = 0; i < getChildCount(); i++) {
                View child = getChildAt(i);
                LayoutParams lp = (LayoutParams) child.getLayoutParams();
                if(lp != null && lp.isDecor) {
                    int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                    boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
                    if(consumeVertical) {
                        decorHeight += child.getMeasuredHeight() ;
                    }
                }
            }

            // make sure that we have an height (not sure if this is necessary because it seems that onPageScrolled is called right after
            int position = getCurrentItem();
            View child = getViewAtPosition(position);
            if (child != null) {
                height = measureViewHeight(child);
            }
            Log.d(TAG, "onMeasure height:" + height + " decor:" + decorHeight);

        }
        int totalHeight = height + decorHeight + getPaddingBottom() + getPaddingTop();
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(totalHeight, MeasureSpec.EXACTLY);
        Log.d(TAG, "onMeasure total height:" + totalHeight);
    }

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:io.plaidapp.ui.widget.FabOverlapTextView.java

private void recompute(int width) {
    if (text != null) {
        // work out the top padding and line height to align text to a 4dp grid
        float fourDip = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4,
                getResources().getDisplayMetrics());

        // Ensure that the first line's baselines sits on 4dp grid by setting the top padding
        Paint.FontMetricsInt fm = paint.getFontMetricsInt();
        int gridAlignedTopPadding = (int) (fourDip
                * (float) Math.ceil((topPaddingHint + Math.abs(fm.ascent)) / fourDip)
                - Math.ceil(Math.abs(fm.ascent)));
        setPadding(getPaddingLeft(), gridAlignedTopPadding, getPaddingRight(), getPaddingBottom());

        // Ensures line height is a multiple of 4dp
        int fontHeight = Math.abs(fm.ascent - fm.descent) + fm.leading;
        int baselineAlignedLineHeight = (int) (fourDip * (float) Math.ceil(lineHeightHint / fourDip));

        // before we can workout indents we need to know how many lines of text there are;
        // so we need to create a temporary layout :(
        layout = StaticLayout.Builder.obtain(text, 0, text.length(), paint, width)
                .setLineSpacing(baselineAlignedLineHeight - fontHeight, 1f).setBreakStrategy(breakStrategy)
                .build();//w w  w . jav a  2s  .  com
        int preIndentedLineCount = layout.getLineCount();

        // now we can calculate the indents required for the given fab gravity
        boolean gravityTop = (fabGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP;
        boolean gravityLeft = (fabGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.LEFT;
        // we want to iterate forward/backward over the lines depending on whether the fab
        // overlap vertical gravity is top/bottom
        int currentLine = gravityTop ? 0 : preIndentedLineCount - 1;
        int remainingHeightOverlap = fabOverlapHeight - (gravityTop ? getPaddingTop() : getPaddingBottom());
        int[] leftIndents = new int[preIndentedLineCount];
        int[] rightIndents = new int[preIndentedLineCount];
        do {
            if (remainingHeightOverlap > 0) {
                // still have overlap height to consume, set the appropriate indent
                leftIndents[currentLine] = gravityLeft ? fabOverlapWidth : 0;
                rightIndents[currentLine] = gravityLeft ? 0 : fabOverlapWidth;
                remainingHeightOverlap -= baselineAlignedLineHeight;
            } else {
                // have consumed the overlap height: no indent
                leftIndents[currentLine] = 0;
                rightIndents[currentLine] = 0;
            }
            if (gravityTop) { // iterate forward over the lines
                currentLine++;
            } else { // iterate backward over the lines
                currentLine--;
            }
        } while (gravityTop ? currentLine < preIndentedLineCount : currentLine >= 0);

        // now that we know the indents, create the actual layout
        layout = StaticLayout.Builder.obtain(text, 0, text.length(), paint, width)
                .setLineSpacing(baselineAlignedLineHeight - fontHeight, 1f)
                .setIndents(leftIndents, rightIndents).setBreakStrategy(breakStrategy).build();
    }
}

From source file:android.support.wear.widget.drawer.WearableDrawerView.java

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    // The peek view has a layout gravity of bottom for the top drawer, and a layout gravity
    // of top for the bottom drawer. This is required so that the peek view shows. On the top
    // drawer, the bottom peeks from the top, and on the bottom drawer, the top peeks.
    // LayoutParams are not guaranteed to return a non-null value until a child is attached to
    // the window.
    LayoutParams peekParams = (LayoutParams) mPeekContainer.getLayoutParams();
    if (!Gravity.isVertical(peekParams.gravity)) {
        final boolean isTopDrawer = (((LayoutParams) getLayoutParams()).gravity
                & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP;
        if (isTopDrawer) {
            peekParams.gravity = Gravity.BOTTOM;
            mPeekIcon.setImageResource(R.drawable.ws_ic_more_horiz_24dp_wht);
        } else {/* w  w w . j  av  a 2  s.c  om*/
            peekParams.gravity = Gravity.TOP;
            mPeekIcon.setImageResource(R.drawable.ws_ic_more_vert_24dp_wht);
        }
        mPeekContainer.setLayoutParams(peekParams);
    }
}