List of usage examples for android.support.v4.view GravityCompat getAbsoluteGravity
public static int getAbsoluteGravity(int i, int i2)
From source file:org.buffer.android.buffertextinputlayout.util.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom; break;/*from w ww. j a v a 2 s.co m*/ case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset; break; } switch (collapsedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom; break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mExpandedDrawY = mExpandedBounds.centerY() + textOffset; break; } switch (expandedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); // Now reset the text size back to the original setInterpolatedTextSize(currentTextSize); }
From source file:com.aries.ui.view.title.util.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom - mTextPaint.descent(); break;// w ww .jav a 2 s . c o m case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset; break; } switch (collapsedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom - mTextPaint.descent(); break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mExpandedDrawY = mExpandedBounds.centerY() + textOffset; break; } switch (expandedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); // Now reset the text size back to the original setInterpolatedTextSize(currentTextSize); }
From source file:com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayout.java
@Override protected void onFinishInflate() { super.onFinishInflate(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final int absGravity = GravityCompat.getAbsoluteGravity( ((LayoutParams) child.getLayoutParams()).gravity, ViewCompat.getLayoutDirection(child)); if (absGravity == Gravity.NO_GRAVITY) { if (mContentView != null) throw new IllegalStateException("There is more than one content view"); mContentView = child;/*w ww . j av a 2 s .c o m*/ } else if ((absGravity & Gravity.LEFT) == Gravity.LEFT) { if (mLeftDrawer != null) throw new IllegalStateException("There is more than one left menu"); mLeftDrawer = child; } else if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) { if (mRightDrawer != null) throw new IllegalStateException("There is more than one right menu"); mRightDrawer = child; } else { throw new IllegalStateException("Child " + child + " at index " + i + " does not have a valid layout_gravity - must be Gravity.LEFT, " + "Gravity.RIGHT or Gravity.NO_GRAVITY"); } } if (mContentView == null) throw new IllegalStateException("There is no content view"); // Material is solid. // Input events cannot pass through material. if (mLeftDrawer != null) mLeftDrawer.setClickable(true); if (mRightDrawer != null) mRightDrawer.setClickable(true); mShadow = new ShadowView(getContext()); addView(mShadow, 1); }
From source file:com.li.utils.ui.mdbottom.BottomNavigation.java
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); attached = true;/*from w ww . j ava 2s.c o m*/ final CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) getLayoutParams(); this.gravity = GravityCompat.getAbsoluteGravity(params.gravity, ViewCompat.getLayoutDirection(this)); initializeUI(gravity); if (null != pendingMenu) { setItems(pendingMenu); pendingMenu = null; } if (null == mBehavior) { if (CoordinatorLayout.LayoutParams.class.isInstance(params)) { mBehavior = params.getBehavior(); if (isInEditMode()) { return; } if (BottomBehavior.class.isInstance(mBehavior)) { ((BottomBehavior) mBehavior).setLayoutValues(defaultHeight, bottomInset); } else if (TabletBehavior.class.isInstance(mBehavior)) { final Activity activity = MiscUtils.getActivity(getContext()); boolean translucentStatus = MiscUtils.hasTranslucentStatusBar(activity); ((TabletBehavior) mBehavior).setLayoutValues(defaultWidth, topInset, translucentStatus); } } } }
From source file:net.opacapp.multilinecollapsingtoolbar.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); // BEGIN MODIFICATION: set mTextToDrawCollapsed and calculate width using it mTextToDrawCollapsed = mTextToDraw;/*w w w.ja v a 2 s . c o m*/ float width = mTextToDrawCollapsed != null ? mTextPaint.measureText(mTextToDrawCollapsed, 0, mTextToDrawCollapsed.length()) : 0; // END MODIFICATION final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); // BEGIN MODIFICATION: calculate height and Y position using mTextLayout float textHeight = mTextLayout != null ? mTextLayout.getHeight() : 0; switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom - textHeight; break; case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top; break; case Gravity.CENTER_VERTICAL: default: float textOffset = (textHeight / 2); mCollapsedDrawY = mCollapsedBounds.centerY() - textOffset; break; } // END MODIFICATION switch (collapsedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); // BEGIN MODIFICATION: calculate width using mTextLayout based on first line and store that padding width = mTextLayout != null ? mTextLayout.getLineWidth(0) : 0; mExpandedFirstLineDrawX = mTextLayout != null ? mTextLayout.getLineLeft(0) : 0; // END MODIFICATION final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); // BEGIN MODIFICATION: calculate height and Y position using mTextLayout textHeight = mTextLayout != null ? mTextLayout.getHeight() : 0; switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom - textHeight; break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top; break; case Gravity.CENTER_VERTICAL: default: float textOffset = (textHeight / 2); mExpandedDrawY = mExpandedBounds.centerY() - textOffset; break; } // END MODIFICATION switch (expandedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); // Now reset the text size back to the original setInterpolatedTextSize(currentTextSize); }
From source file:com.aidy.bottomdrawerlayout.DrawerLayout.java
/** * Enable or disable interaction with the given drawer. * /* w w w.j a va2s .c om*/ * <p> * This allows the application to restrict the user's ability to open or * close the given drawer. DrawerLayout will still respond to calls to * {@link #openDrawer(int)}, {@link #closeDrawer(int)} and friends if a * drawer is locked. * </p> * * <p> * Locking a drawer open or closed will implicitly open or close that drawer * as appropriate. * </p> * * @param lockMode * The new lock mode for the given drawer. One of * {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} * or {@link #LOCK_MODE_LOCKED_OPEN}. * @param edgeGravity * Gravity.LEFT, RIGHT, START or END. Expresses which drawer to * change the mode for. * * @see #LOCK_MODE_UNLOCKED * @see #LOCK_MODE_LOCKED_CLOSED * @see #LOCK_MODE_LOCKED_OPEN */ public void setDrawerLockMode(int lockMode, int edgeGravity) { final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this)); if (absGravity == Gravity.LEFT) { mLockModeLeft = lockMode; } else if (absGravity == Gravity.RIGHT) { mLockModeRight = lockMode; } if (lockMode != LOCK_MODE_UNLOCKED) { // Cancel interaction in progress final ViewDragHelper helper = absGravity == Gravity.LEFT ? mLeftDragger : mRightDragger; helper.cancel(); } switch (lockMode) { case LOCK_MODE_LOCKED_OPEN: final View toOpen = findDrawerWithGravity(absGravity); if (toOpen != null) { openDrawer(toOpen); } break; case LOCK_MODE_LOCKED_CLOSED: final View toClose = findDrawerWithGravity(absGravity); if (toClose != null) { closeDrawer(toClose); } break; // default: do nothing } }
From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java
/** * Check the lock mode of the drawer with the given gravity. * /*from w w w . j a va 2s . c o m*/ * @param edgeGravity * Gravity of the drawer to check * @return one of {@link #LOCK_MODE_UNLOCKED}, * {@link #LOCK_MODE_LOCKED_CLOSED} or * {@link #LOCK_MODE_LOCKED_OPEN}. */ public int getDrawerLockMode(int edgeGravity) { final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this)); if (absGravity == Gravity.BOTTOM) { return mLockModeBottom; } return LOCK_MODE_UNLOCKED; }
From source file:it.sephiroth.android.library.bottomnavigation.BottomNavigation.java
@Override protected void onAttachedToWindow() { log(TAG, INFO, "onAttachedToWindow"); super.onAttachedToWindow(); attached = true;// ww w. jav a 2s. c o m final CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) getLayoutParams(); this.gravity = GravityCompat.getAbsoluteGravity(params.gravity, ViewCompat.getLayoutDirection(this)); initializeUI(gravity); if (null != pendingMenu) { setItems(pendingMenu); pendingMenu = null; } if (null == mBehavior) { if (CoordinatorLayout.LayoutParams.class.isInstance(params)) { mBehavior = params.getBehavior(); if (isInEditMode()) { return; } if (BottomBehavior.class.isInstance(mBehavior)) { ((BottomBehavior) mBehavior).setLayoutValues(defaultHeight, bottomInset); } else if (TabletBehavior.class.isInstance(mBehavior)) { final Activity activity = MiscUtils.getActivity(getContext()); boolean translucentStatus = MiscUtils.hasTranslucentStatusBar(activity); ((TabletBehavior) mBehavior).setLayoutValues(defaultWidth, topInset, translucentStatus); } } } }
From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java
/** * Enable or disable interaction with the given drawer. * /* ww w . j av a2 s.c om*/ * <p> * This allows the application to restrict the user's ability to open or * close the given drawer. DrawerLayout will still respond to calls to * {@link #openDrawer(int)}, {@link #closeDrawer(int)} and friends if a * drawer is locked. * </p> * * <p> * Locking a drawer open or closed will implicitly open or close that drawer * as appropriate. * </p> * * @param lockMode * The new lock mode for the given drawer. One of * {@link #LOCK_MODE_UNLOCKED}, {@link #LOCK_MODE_LOCKED_CLOSED} * or {@link #LOCK_MODE_LOCKED_OPEN}. * @param edgeGravity * Gravity.LEFT, RIGHT, START or END. * Expresses which drawer to change the mode for. * * @see #LOCK_MODE_UNLOCKED * @see #LOCK_MODE_LOCKED_CLOSED * @see #LOCK_MODE_LOCKED_OPEN */ public void setDrawerLockMode(int lockMode, int edgeGravity) { final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this)); if (absGravity == Gravity.TOP) { mLockModeTop = lockMode; } else if (absGravity == Gravity.BOTTOM) { mLockModeBottom = lockMode; } if (lockMode != LOCK_MODE_UNLOCKED) { // Cancel interaction in progress final ViewDragHelper helper = absGravity == Gravity.TOP ? mTopDragger : mBottomDragger; helper.cancel(); } switch (lockMode) { case LOCK_MODE_LOCKED_OPEN: final View toOpen = findDrawerWithGravity(absGravity); if (toOpen != null) { openDrawer(toOpen); } break; case LOCK_MODE_LOCKED_CLOSED: final View toClose = findDrawerWithGravity(absGravity); if (toClose != null) { closeDrawer(toClose); } break; // default: do nothing } }
From source file:com.hippo.drawerlayout.DrawerLayout.java
@Override protected void onFinishInflate() { super.onFinishInflate(); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final int absGravity = GravityCompat.getAbsoluteGravity( ((LayoutParams) child.getLayoutParams()).gravity, ViewCompat.getLayoutDirection(child)); if (absGravity == Gravity.NO_GRAVITY) { if (mContentView != null) throw new IllegalStateException("There is more than one content view"); mContentView = child;/* w w w . j a v a2s. c o m*/ } else if ((absGravity & Gravity.LEFT) == Gravity.LEFT) { if (mLeftDrawer != null) throw new IllegalStateException("There is more than one left menu"); mLeftDrawer = child; } else if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) { if (mRightDrawer != null) throw new IllegalStateException("There is more than one right menu"); mRightDrawer = child; } else { throw new IllegalStateException("Child " + child + " at index " + i + " does not have a valid layout_gravity - must be Gravity.LEFT, " + "Gravity.RIGHT or Gravity.NO_GRAVITY"); } } if (mContentView == null) { throw new IllegalStateException("There is no content view"); } // Material is solid. // Input events cannot pass through material. if (mLeftDrawer != null) { mLeftDrawer.setClickable(true); } if (mRightDrawer != null) { mRightDrawer.setClickable(true); } mShadow = new ShadowView(getContext()); addView(mShadow, 1); }