List of usage examples for android.view Gravity RIGHT
int RIGHT
To view the source code for android.view Gravity RIGHT.
Click Source Link
From source file:android.support.design.widget.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;/*ww w . j a v a2 s.com*/ 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;//ww w .j ava2s .com 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.facebook.react.views.textinput.ReactTextInputManager.java
@ReactProp(name = ViewProps.TEXT_ALIGN) public void setTextAlign(ReactEditText view, @Nullable String textAlign) { if (textAlign == null || "auto".equals(textAlign)) { view.setGravityHorizontal(Gravity.NO_GRAVITY); } else if ("left".equals(textAlign)) { view.setGravityHorizontal(Gravity.LEFT); } else if ("right".equals(textAlign)) { view.setGravityHorizontal(Gravity.RIGHT); } else if ("center".equals(textAlign)) { view.setGravityHorizontal(Gravity.CENTER_HORIZONTAL); } else if ("justify".equals(textAlign)) { // Fallback gracefully for cross-platform compat instead of error view.setGravityHorizontal(Gravity.LEFT); } else {//from ww w. j av a 2 s . c om throw new JSApplicationIllegalArgumentException("Invalid textAlign: " + textAlign); } }
From source file:android.support.v7.view.menu.CascadingMenuPopup.java
/** * Prepares and shows the specified menu immediately. * * @param menu the menu to show//from ww w.j av a 2s . co m */ private void showMenu(@NonNull MenuBuilder menu) { final LayoutInflater inflater = LayoutInflater.from(mContext); final MenuAdapter adapter = new MenuAdapter(menu, inflater, mOverflowOnly); // Apply "force show icon" setting. There are 3 cases: // (1) This is the top level menu and icon spacing is forced. Add spacing. // (2) This is a submenu. Add spacing if any of the visible menu items has an icon. // (3) This is the top level menu and icon spacing isn't forced. Do not add spacing. if (!isShowing() && mForceShowIcon) { // Case 1 adapter.setForceShowIcon(true); } else if (isShowing()) { // Case 2 adapter.setForceShowIcon(MenuPopup.shouldPreserveIconSpacing(menu)); } // Case 3: Else, don't allow spacing for icons (default behavior; do nothing). final int menuWidth = measureIndividualMenuWidth(adapter, null, mContext, mMenuMaxWidth); final MenuPopupWindow popupWindow = createPopupWindow(); popupWindow.setAdapter(adapter); popupWindow.setWidth(menuWidth); popupWindow.setDropDownGravity(mDropDownGravity); final CascadingMenuInfo parentInfo; final View parentView; if (mShowingMenus.size() > 0) { parentInfo = mShowingMenus.get(mShowingMenus.size() - 1); parentView = findParentViewForSubmenu(parentInfo, menu); } else { parentInfo = null; parentView = null; } if (parentView != null) { // This menu is a cascading submenu anchored to a parent view. popupWindow.setTouchModal(false); popupWindow.setEnterTransition(null); final @HorizPosition int nextMenuPosition = getNextMenuPosition(menuWidth); final boolean showOnRight = nextMenuPosition == HORIZ_POSITION_RIGHT; mLastPosition = nextMenuPosition; final int[] tempLocation = new int[2]; // This popup menu will be positioned relative to the top-left edge // of the view representing its parent menu. parentView.getLocationInWindow(tempLocation); final int parentOffsetLeft = parentInfo.window.getHorizontalOffset() + tempLocation[0]; final int parentOffsetTop = parentInfo.window.getVerticalOffset() + tempLocation[1]; // By now, mDropDownGravity is the resolved absolute gravity, so // this should work in both LTR and RTL. final int x; if ((mDropDownGravity & Gravity.RIGHT) == Gravity.RIGHT) { if (showOnRight) { x = parentOffsetLeft + menuWidth; } else { x = parentOffsetLeft - parentView.getWidth(); } } else { if (showOnRight) { x = parentOffsetLeft + parentView.getWidth(); } else { x = parentOffsetLeft - menuWidth; } } popupWindow.setHorizontalOffset(x); final int y = parentOffsetTop; popupWindow.setVerticalOffset(y); } else { if (mHasXOffset) { popupWindow.setHorizontalOffset(mXOffset); } if (mHasYOffset) { popupWindow.setVerticalOffset(mYOffset); } final Rect epicenterBounds = getEpicenterBounds(); popupWindow.setEpicenterBounds(epicenterBounds); } final CascadingMenuInfo menuInfo = new CascadingMenuInfo(popupWindow, menu, mLastPosition); mShowingMenus.add(menuInfo); popupWindow.show(); // If this is the root menu, show the title if requested. if (parentInfo == null && mShowTitle && menu.getHeaderTitle() != null) { final ListView listView = popupWindow.getListView(); final FrameLayout titleItemView = (FrameLayout) inflater .inflate(R.layout.abc_popup_menu_header_item_layout, listView, false); final TextView titleView = (TextView) titleItemView.findViewById(android.R.id.title); titleItemView.setEnabled(false); titleView.setText(menu.getHeaderTitle()); listView.addHeaderView(titleItemView, null, false); // Show again to update the title. popupWindow.show(); } }
From source file:com.huangj.huangjlibrary.widget.drawerlayout.DrawerLayout.java
public DrawerLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); final float density = getResources().getDisplayMetrics().density; mMinDrawerMargin = (int) (MIN_DRAWER_MARGIN * density + 0.5f); final float minVel = MIN_FLING_VELOCITY * density; mLeftCallback = new ViewDragCallback(Gravity.LEFT); mRightCallback = new ViewDragCallback(Gravity.RIGHT); mLeftDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mLeftCallback); mLeftDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT); mLeftDragger.setMinVelocity(minVel); mLeftCallback.setDragger(mLeftDragger); mRightDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mRightCallback); mRightDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT); mRightDragger.setMinVelocity(minVel); mRightCallback.setDragger(mRightDragger); // So that we can catch the back button setFocusableInTouchMode(true);/* w w w .j a v a 2s .co m*/ ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate()); ViewGroupCompat.setMotionEventSplittingEnabled(this, false); if (ViewCompat.getFitsSystemWindows(this)) { IMPL.configureApplyInsets(this); mStatusBarBackground = IMPL.getDefaultStatusBarBackground(context); } mDrawerElevation = DRAWER_ELEVATION * density; mNonDrawerViews = new ArrayList<View>(); }
From source file:com.org.ccl.practicetwo.camera.Camera2BasicFragment.java
@Override public void onViewCreated(final View view, Bundle savedInstanceState) { mTextureView = view.findViewById(R.id.texture); View rightButtonLayout = view.findViewById(R.id.right_button_layout); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) rightButtonLayout.getLayoutParams(); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT; layoutParams.rightMargin = DensityUtils.dp2px(getActivity(), 5); rightButtonLayout.setLayoutParams(layoutParams); mTvTakePhoto = rightButtonLayout.findViewById(R.id.tv_take_photo); mTvDetermine = rightButtonLayout.findViewById(R.id.tv_determine); mTvCancel = rightButtonLayout.findViewById(R.id.tv_cancel); mTvTakePhoto.setOnClickListener(this); mTvDetermine.setOnClickListener(this); mTvCancel.setOnClickListener(this); }
From source file:com.jecelyin.editor.v2.widget.AnyDrawerLayout.java
public AnyDrawerLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); final float density = getResources().getDisplayMetrics().density; mMinDrawerMargin = (int) (MIN_DRAWER_MARGIN * density + 0.5f); final float minVel = MIN_FLING_VELOCITY * density; mLeftCallback = new ViewDragCallback(Gravity.LEFT); mRightCallback = new ViewDragCallback(Gravity.RIGHT); mBottomCallback = new ViewDragCallback(Gravity.BOTTOM); mLeftDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mLeftCallback); mLeftDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT); mLeftDragger.setMinVelocity(minVel); mLeftCallback.setDragger(mLeftDragger); mRightDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mRightCallback); mRightDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT); mRightDragger.setMinVelocity(minVel); mRightCallback.setDragger(mRightDragger); mBottomDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mBottomCallback); mBottomDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_BOTTOM); mBottomDragger.setMinVelocity(minVel); mBottomCallback.setDragger(mBottomDragger); // So that we can catch the back button setFocusableInTouchMode(true);/*from ww w. ja v a 2s . c om*/ ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate()); ViewGroupCompat.setMotionEventSplittingEnabled(this, false); if (ViewCompat.getFitsSystemWindows(this)) { IMPL.configureApplyInsets(this); mStatusBarBackground = IMPL.getDefaultStatusBarBackground(context); } mDrawerElevation = DRAWER_ELEVATION * density; mNonDrawerViews = new ArrayList<View>(); }
From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java
/** * Enable or disable interaction with all drawers. * * <p>This allows the application to restrict the user's ability to open or close * any drawer within this layout. DrawerLayout will still respond to calls to * {@link #openDrawer(int)}, {@link #closeDrawer(int)} and friends if a drawer is locked.</p> * * <p>Locking drawers open or closed will implicitly open or close * any drawers 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}. *///from w w w .j a v a 2s . c om public void setDrawerLockMode(@LockMode int lockMode) { setDrawerLockMode(lockMode, Gravity.LEFT); setDrawerLockMode(lockMode, Gravity.RIGHT); }
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;//from w w w . j a v a 2 s . c om } 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.cyanogenmod.filemanager.ui.widgets.DrawerLayout.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 w w .j a v a2 s . c om*/ public int getDrawerLockMode(int edgeGravity) { final int absGravity = Gravity.getAbsoluteGravity(edgeGravity, this.getLayoutDirection()); if (absGravity == Gravity.LEFT) { return mLockModeLeft; } else if (absGravity == Gravity.RIGHT) { return mLockModeRight; } return LOCK_MODE_UNLOCKED; }