List of usage examples for android.support.v4.view GravityCompat getAbsoluteGravity
public static int getAbsoluteGravity(int i, int i2)
From source file:android.support.v7.internal.widget.SpinnerCompat.java
/** * Creates and positions all views for this Spinner. * * @param delta Change in the selected position. +1 means selection is moving to the right, so * views are scrolling to the left. -1 means selection is moving to the left. *//*from w w w. j av a 2s . c o m*/ @Override void layout(int delta, boolean animate) { int childrenLeft = mSpinnerPadding.left; int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right; if (mDataChanged) { handleDataChanged(); } // Handle the empty set by removing all views if (mItemCount == 0) { resetList(); return; } if (mNextSelectedPosition >= 0) { setSelectedPositionInt(mNextSelectedPosition); } recycleAllViews(); // Clear out old views removeAllViewsInLayout(); // Make selected view and position it mFirstPosition = mSelectedPosition; if (mAdapter != null) { View sel = makeView(mSelectedPosition, true); int width = sel.getMeasuredWidth(); int selectedOffset = childrenLeft; final int layoutDirection = ViewCompat.getLayoutDirection(this); final int absoluteGravity = GravityCompat.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2); break; case Gravity.RIGHT: selectedOffset = childrenLeft + childrenWidth - width; break; } sel.offsetLeftAndRight(selectedOffset); } // Flush any cached views that did not get reused above mRecycler.clear(); invalidate(); checkSelectionChanged(); mDataChanged = false; mNeedSync = false; setNextSelectedPositionInt(mSelectedPosition); }
From source file:com.muzakki.ahmad.widget.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); calculateUsingSubSize(mCollapsedSubSize); float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2); if (mSub != null) { float subHeight = mSubPaint.descent() - mSubPaint.ascent(); float subOffset = (subHeight / 2) - mSubPaint.descent(); float offset = ((mCollapsedBounds.height() - (textHeight + subHeight)) / 3); mCollapsedDrawY = mCollapsedBounds.top + offset - mTextPaint.ascent(); mCollapsedSubY = mCollapsedBounds.top + (offset * 2) + textHeight - mSubPaint.ascent(); } else { // title only mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset; }//from w w w . j a v a2s.co m float width = mText != null ? mTextPaint.measureText(mText, 0, mText.length()) : 0; float subWidth = mSub != null ? mSubPaint.measureText(mSub, 0, mSub.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); mCollapsedDrawSubX = mCollapsedBounds.centerX() - (subWidth / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; mCollapsedDrawSubX = mCollapsedBounds.right - subWidth; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; mCollapsedDrawSubX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); calculateUsingSubSize(mExpandedSubSize); textHeight = mTextPaint.descent() - mTextPaint.ascent(); textOffset = (textHeight / 2); if (mSub != null) { float subHeight = mSubPaint.descent() - mSubPaint.ascent(); float subOffset = (subHeight / 2); mExpandedDrawY = mExpandedBounds.centerY() + textOffset; mExpandedSubY = mExpandedDrawY + subOffset - mSubPaint.ascent(); } else { // title only mExpandedDrawY = mExpandedBounds.centerY() + textOffset; } width = mText != null ? mTextPaint.measureText(mText, 0, mText.length()) : 0; subWidth = mSub != null ? mSubPaint.measureText(mSub, 0, mSub.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); mExpandedDrawSubX = mExpandedBounds.centerX() - (subWidth / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; mExpandedDrawSubX = mExpandedBounds.right - subWidth; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; mExpandedDrawSubX = 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.AllDrawerLayout.java
/** * Check the lock mode of the drawer with the given gravity. * //from ww w .jav a 2 s . c om * @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)); switch (absGravity) { case Gravity.LEFT: return mLockModeLeft; case Gravity.RIGHT: return mLockModeRight; case Gravity.TOP: return mLockModeTop; case Gravity.BOTTOM: return mLockModeBottom; default: return LOCK_MODE_UNLOCKED; } }
From source file:com.dk.view.FolderDrawerLayout.java
/** * Sets the title of the drawer with the given gravity. * <p>/*w w w.j a v a 2 s . co m*/ * When accessibility is turned on, this is the title that will be used to * identify the drawer to the active accessibility service. * * @param edgeGravity * Gravity.LEFT, RIGHT, START or END. Expresses which drawer to * set the title for. * @param title * The title for the drawer. */ public void setDrawerTitle(int edgeGravity, CharSequence title) { final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this)); if (absGravity == Gravity.LEFT) { mTitleLeft = title; } else if (absGravity == Gravity.RIGHT) { mTitleRight = title; } }
From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java
/** * Sets the title of the drawer with the given gravity. * <p>//from w w w. j a va 2 s .co m * When accessibility is turned on, this is the title that will be used to * identify the drawer to the active accessibility service. * * @param edgeGravity * Gravity.LEFT, RIGHT, START or END. Expresses which * drawer to set the title for. * @param title * The title for the drawer. */ public void setDrawerTitle(int edgeGravity, CharSequence title) { final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this)); if (absGravity == Gravity.TOP) { mTitleTop = title; } else if (absGravity == Gravity.BOTTOM) { mTitleBottom = title; } }
From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java
/** * @param gravity// w ww. ja v a 2 s. c o m * the gravity of the child to return. If specified as a relative * value, it will be resolved according to the current layout * direction. * @return the drawer with the specified gravity */ View findDrawerWithGravity(int gravity) { final int absVerticalGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this)) & Gravity.VERTICAL_GRAVITY_MASK; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final int childAbsGravity = getDrawerViewAbsoluteGravity(child); if ((childAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) == absVerticalGravity) { return child; } } return null; }
From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java
/** * Check the lock mode of the drawer with the given gravity. * * @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}. *//*from w ww . jav a2s . co m*/ @LockMode public int getDrawerLockMode(@EdgeGravity int edgeGravity) { final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this)); if (absGravity == Gravity.LEFT) { return mLockModeLeft; } else if (absGravity == Gravity.RIGHT) { return mLockModeRight; } return LOCK_MODE_UNLOCKED; }
From source file:com.dk.view.FolderDrawerLayout.java
/** * Returns the title of the drawer with the given gravity. * //from w w w .j a v a2 s. c o m * @param edgeGravity * Gravity.LEFT, RIGHT, START or END. Expresses which drawer to * return the title for. * @return The title of the drawer, or null if none set. * @see #setDrawerTitle(int, CharSequence) */ public CharSequence getDrawerTitle(int edgeGravity) { final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this)); if (absGravity == Gravity.LEFT) { return mTitleLeft; } else if (absGravity == Gravity.RIGHT) { return mTitleRight; } return null; }
From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java
/** * Returns the title of the drawer with the given gravity. * /*from w w w . jav a2 s .co m*/ * @param edgeGravity * Gravity.LEFT, RIGHT, START or END. Expresses which * drawer to return the title for. * @return The title of the drawer, or null if none set. * @see #setDrawerTitle(int, CharSequence) */ public CharSequence getDrawerTitle(int edgeGravity) { final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this)); if (absGravity == Gravity.TOP) { return mTitleTop; } else if (absGravity == Gravity.BOTTOM) { return mTitleBottom; } return null; }
From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java
int getDrawerViewGravity(View drawerView) { final int gravity = ((LayoutParams) drawerView.getLayoutParams()).gravity; return GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(drawerView)); }