List of usage examples for android.view Gravity LEFT
int LEFT
To view the source code for android.view Gravity LEFT.
Click Source Link
From source file:com.hippo.drawerlayout.DrawerLayout.java
@Override protected void onRestoreInstanceState(Parcelable state) { Bundle saved = (Bundle) state;// w w w . j a v a 2 s. co m setDrawerLockMode(saved.getInt(KEY_LEFT_LOCK_MODER, LOCK_MODE_UNLOCKED), Gravity.LEFT); setDrawerLockMode(saved.getInt(KEY_RIGHT_LOCK_MODER, LOCK_MODE_UNLOCKED), Gravity.RIGHT); openDrawer(saved.getInt(KEY_OPENED_DRAWER, Gravity.NO_GRAVITY)); super.onRestoreInstanceState(saved.getParcelable(KEY_SUPER)); }
From source file:android.car.ui.provider.CarDrawerLayout.java
/** * Open the drawer view by animating it into view. *///from w w w . ja v a 2 s . c om public void openDrawer() { ViewGroup drawerView = (ViewGroup) findDrawerView(); mStartedOpen = false; if (hasWindowFocus()) { int left; LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams(); if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) { left = drawerLp.getMarginStart(); } else { left = drawerLp.getMarginStart() + getWidth() - drawerView.getWidth(); } mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop()); dispatchOnDrawerOpening(drawerView); } else { final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); lp.onScreen = 1.f; dispatchOnDrawerOpened(drawerView); } ViewGroup contentView = (ViewGroup) findContentView(); contentView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); drawerView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); View focusable = drawerView.getChildAt(0); if (focusable != null) { focusable.requestFocus(); } invalidate(); }
From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { Log.i(TAG, "drawChild()"); final int height = getHeight(); final boolean drawingContent = isContentView(child); int clipLeft = 0, clipRight = getWidth(); int clipTop = 0, clipBottom = getHeight(); final int restoreCount = canvas.save(); if (drawingContent) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View v = getChildAt(i); if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v) || v.getHeight() < height) { Log.i(TAG, "drawChild() -- 0"); continue; }// www .ja v a 2 s.com switch (getDrawerViewAbsoluteGravity(v)) { case Gravity.LEFT: Log.i(TAG, "drawChild() -- 1"); if (checkDrawerViewAbsoluteGravity(v, Gravity.LEFT)) { final int vright = v.getRight(); if (vright > clipLeft) clipLeft = vright; } break; case Gravity.RIGHT: Log.i(TAG, "drawChild() -- 2"); if (checkDrawerViewAbsoluteGravity(v, Gravity.RIGHT)) { final int vleft = v.getLeft(); if (vleft < clipRight) clipRight = vleft; } break; case Gravity.TOP: Log.i(TAG, "drawChild() -- 3"); if (checkDrawerViewAbsoluteGravity(v, Gravity.TOP)) { final int vbottom = v.getBottom(); if (vbottom > clipTop) { clipTop = vbottom; } } break; case Gravity.BOTTOM: Log.i(TAG, "drawChild() -- 4"); if (checkDrawerViewAbsoluteGravity(v, Gravity.BOTTOM)) { final int vtop = v.getTop(); if (vtop < clipBottom) { clipBottom = vtop; } } break; default: Log.i(TAG, "drawChild() -- 5"); final int vtop = v.getTop(); if (vtop < clipBottom) { clipBottom = vtop; } break; } } canvas.clipRect(clipLeft, clipTop, clipRight, clipBottom); } final boolean result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(restoreCount); if (mScrimOpacity > 0 && drawingContent) { Log.i(TAG, "drawChild() -- drawingContent"); final int baseAlpha = (mScrimColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * mScrimOpacity); final int color = imag << 24 | (mScrimColor & 0xffffff); mScrimPaint.setColor(color); canvas.drawRect(clipLeft, clipTop, clipRight, clipBottom, mScrimPaint); } else if (mShadowLeft != null && checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) { Log.i(TAG, "drawChild() -- LEFT"); final int shadowWidth = mShadowLeft.getIntrinsicWidth(); final int childRight = child.getRight(); final int drawerPeekDistance = mLeftDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f)); mShadowLeft.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom()); mShadowLeft.setAlpha((int) (0xff * alpha)); mShadowLeft.draw(canvas); } else if (mShadowRight != null && checkDrawerViewAbsoluteGravity(child, Gravity.RIGHT)) { Log.i(TAG, "drawChild() -- Gravity.RIGHT"); final int shadowWidth = mShadowRight.getIntrinsicWidth(); final int childLeft = child.getLeft(); final int showing = getWidth() - childLeft; final int drawerPeekDistance = mRightDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f)); mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom()); mShadowRight.setAlpha((int) (0xff * alpha)); mShadowRight.draw(canvas); } else if (mShadowTop != null && checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) { Log.i(TAG, "drawChild() -- Gravity.TOP"); final int shadowHeight = mShadowTop.getIntrinsicHeight(); final int childBottom = child.getBottom(); final int drawerPeekDistance = mTopDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) childBottom / drawerPeekDistance, 1.f)); mShadowTop.setBounds(child.getLeft(), childBottom, child.getRight(), childBottom + shadowHeight); mShadowTop.setAlpha((int) (0xff * alpha)); mShadowTop.draw(canvas); } else if (mShadowBottom != null && checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) { Log.i(TAG, "drawChild() -- Gravity.BOTTOM"); final int shadowHeight = mShadowBottom.getIntrinsicWidth(); final int childTop = child.getTop(); final int showing = getHeight() - childTop; final int drawerPeekDistance = mBottomDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f)); mShadowRight.setBounds(child.getLeft(), childTop - shadowHeight, child.getRight(), childTop); mShadowRight.setAlpha((int) (0xff * alpha)); mShadowRight.draw(canvas); } return result; }
From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java
/** * Open the specified drawer view by animating it into view. * * @param drawerView Drawer view to open *//* w w w . ja v a 2s . c om*/ public void openDrawer(View drawerView) { if (!isDrawerView(drawerView)) { throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer"); } if (mFirstLayout) { final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); lp.onScreen = 1.f; lp.knownOpen = true; } else { if (checkDrawerViewGravity(drawerView, Gravity.LEFT)) { mLeftDragger.smoothSlideViewTo(drawerView, 0, drawerView.getTop()); } else { mRightDragger.smoothSlideViewTo(drawerView, getWidth() - drawerView.getWidth(), drawerView.getTop()); } } invalidate(); }
From source file:com.cyanogenmod.filemanager.ui.widgets.DrawerLayout.java
/** * Open the specified drawer view by animating it into view. * * @param drawerView Drawer view to open *///from w w w .ja va2s . c o m public void openDrawer(View drawerView) { if (!isDrawerView(drawerView)) { throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer"); } if (mFirstLayout) { final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); lp.onScreen = 1.f; lp.knownOpen = true; } else { if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) { mLeftDragger.smoothSlideViewTo(drawerView, 0, drawerView.getTop()); } else { mRightDragger.smoothSlideViewTo(drawerView, getWidth() - drawerView.getWidth(), drawerView.getTop()); } } invalidate(); }
From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java
private void computeInsets(int dx, int dy) { final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: mHorizontalInset = 0;/* w w w . java 2 s . c o m*/ break; case Gravity.RIGHT: mHorizontalInset = dx; break; case Gravity.CENTER_HORIZONTAL: default: mHorizontalInset = dx / 2; break; } switch (absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.TOP: mVerticalInset = 0; break; case Gravity.BOTTOM: mVerticalInset = dy; break; case Gravity.CENTER_VERTICAL: default: mVerticalInset = dy / 2; break; } }
From source file:android.support.design.widget.CoordinatorLayout.java
private void getDesiredAnchoredChildRectWithoutConstraints(View child, int layoutDirection, Rect anchorRect, Rect out, LayoutParams lp, int childWidth, int childHeight) { final int absGravity = GravityCompat.getAbsoluteGravity(resolveAnchoredChildGravity(lp.gravity), layoutDirection);/*from w w w. ja v a 2 s.c o m*/ final int absAnchorGravity = GravityCompat.getAbsoluteGravity(resolveGravity(lp.anchorGravity), layoutDirection); final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK; final int anchorHgrav = absAnchorGravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int anchorVgrav = absAnchorGravity & Gravity.VERTICAL_GRAVITY_MASK; int left; int top; // Align to the anchor. This puts us in an assumed right/bottom child view gravity. // If this is not the case we will subtract out the appropriate portion of // the child size below. switch (anchorHgrav) { default: case Gravity.LEFT: left = anchorRect.left; break; case Gravity.RIGHT: left = anchorRect.right; break; case Gravity.CENTER_HORIZONTAL: left = anchorRect.left + anchorRect.width() / 2; break; } switch (anchorVgrav) { default: case Gravity.TOP: top = anchorRect.top; break; case Gravity.BOTTOM: top = anchorRect.bottom; break; case Gravity.CENTER_VERTICAL: top = anchorRect.top + anchorRect.height() / 2; break; } // Offset by the child view's gravity itself. The above assumed right/bottom gravity. switch (hgrav) { default: case Gravity.LEFT: left -= childWidth; break; case Gravity.RIGHT: // Do nothing, we're already in position. break; case Gravity.CENTER_HORIZONTAL: left -= childWidth / 2; break; } switch (vgrav) { default: case Gravity.TOP: top -= childHeight; break; case Gravity.BOTTOM: // Do nothing, we're already in position. break; case Gravity.CENTER_VERTICAL: top -= childHeight / 2; break; } out.set(left, top, left + childWidth, top + childHeight); }
From source file:com.jecelyin.editor.v2.widget.AnyDrawerLayout.java
/** * Simple gravity to string - only supports LEFT and RIGHT for debugging output. * * @param gravity Absolute gravity value * @return LEFT or RIGHT as appropriate, or a hex string *//*from w w w. j av a 2 s .com*/ static String gravityToString(@EdgeGravity int gravity) { if ((gravity & Gravity.LEFT) == Gravity.LEFT) { return "LEFT"; } if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) { return "RIGHT"; } if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) { return "BOTTOM"; } return Integer.toHexString(gravity); }
From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final int height = getHeight(); final boolean drawingContent = isContentView(child); int clipLeft = 0, clipRight = getWidth(); final int restoreCount = canvas.save(); if (drawingContent) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View v = getChildAt(i); if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v) || v.getHeight() < height) { continue; }/* w ww. ja v a 2s. c o m*/ if (checkDrawerViewAbsoluteGravity(v, Gravity.LEFT)) { final int vright = v.getRight(); if (vright > clipLeft) clipLeft = vright; } else { final int vleft = v.getLeft(); if (vleft < clipRight) clipRight = vleft; } } canvas.clipRect(clipLeft, 0, clipRight, getHeight()); } final boolean result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(restoreCount); if (mScrimOpacity > 0 && drawingContent) { final int baseAlpha = (mScrimColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * mScrimOpacity); final int color = imag << 24 | (mScrimColor & 0xffffff); mScrimPaint.setColor(color); canvas.drawRect(clipLeft, 0, clipRight, getHeight(), mScrimPaint); } else if (mShadowLeft != null && checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) { final int shadowWidth = mShadowLeft.getIntrinsicWidth(); final int childRight = child.getRight(); final int drawerPeekDistance = mLeftDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f)); mShadowLeft.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom()); mShadowLeft.setAlpha((int) (0xff * alpha)); mShadowLeft.draw(canvas); } else if (mShadowRight != null && checkDrawerViewAbsoluteGravity(child, Gravity.RIGHT)) { final int shadowWidth = mShadowRight.getIntrinsicWidth(); final int childLeft = child.getLeft(); final int showing = getWidth() - childLeft; final int drawerPeekDistance = mRightDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f)); mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom()); mShadowRight.setAlpha((int) (0xff * alpha)); mShadowRight.draw(canvas); } return result; }
From source file:android.car.ui.provider.CarDrawerLayout.java
/** * Close the specified drawer view by animating it into view. *///from w w w . ja va 2 s . co m public void closeDrawer() { ViewGroup drawerView = (ViewGroup) findDrawerView(); if (!isDrawerView(drawerView)) { throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer"); } mStartedOpen = true; // Don't trigger the close drawer animation if drawer is not open. if (hasWindowFocus() && isDrawerOpen()) { int left; LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams(); if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) { left = drawerLp.getMarginStart() - drawerView.getWidth(); } else { left = drawerLp.getMarginStart() + getWidth(); } mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop()); dispatchOnDrawerClosing(drawerView); } else { final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); lp.onScreen = 0.f; dispatchOnDrawerClosed(drawerView); } ViewGroup contentView = (ViewGroup) findContentView(); drawerView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); contentView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); if (!isInTouchMode()) { List<View> focusables = contentView.getFocusables(FOCUS_DOWN); if (focusables.size() > 0) { View candidate = focusables.get(0); candidate.requestFocus(); } } invalidate(); }