List of usage examples for android.view Gravity TOP
int TOP
To view the source code for android.view Gravity TOP.
Click Source Link
From source file:com.b44t.ui.ActionBar.BottomSheet.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Window window = getWindow();//from w ww.ja v a 2 s .c o m window.setWindowAnimations(R.style.DialogNoAnimation); setContentView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); if (containerView == null) { containerView = new FrameLayout(getContext()) { @Override public boolean hasOverlappingRendering() { return false; } }; containerView.setBackgroundDrawable(shadowDrawable); containerView.setPadding(backgroundPaddingLeft, (applyTopPadding ? AndroidUtilities.dp(8) : 0) + backgroundPaddingTop, backgroundPaddingLeft, (applyBottomPadding ? AndroidUtilities.dp(8) : 0)); } if (Build.VERSION.SDK_INT >= 21) { containerView.setFitsSystemWindows(true); } containerView.setVisibility(View.INVISIBLE); container.addView(containerView, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM)); if (customView != null) { if (customView.getParent() != null) { ViewGroup viewGroup = (ViewGroup) customView.getParent(); viewGroup.removeView(customView); } containerView.addView(customView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP)); } else { int topOffset = 0; if (title != null) { TextView titleView = new TextView(getContext()); titleView.setLines(1); titleView.setSingleLine(true); titleView.setText(title); titleView.setTextColor(0xff757575); titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE); titleView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), AndroidUtilities.dp(8)); titleView.setGravity(Gravity.CENTER_VERTICAL); containerView.addView(titleView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48)); titleView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); topOffset += 48; } if (items != null) { FrameLayout rowLayout = null; int lastRowLayoutNum = 0; for (int a = 0; a < items.length; a++) { BottomSheetCell cell = new BottomSheetCell(getContext(), 0); cell.setTextAndIcon(items[a], itemIcons != null ? itemIcons[a] : 0); containerView.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP, 0, topOffset, 0, 0)); topOffset += 48; cell.setTag(a); cell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismissWithButtonClick((Integer) v.getTag()); } }); itemViews.add(cell); } } } WindowManager.LayoutParams params = window.getAttributes(); params.width = ViewGroup.LayoutParams.MATCH_PARENT; params.gravity = Gravity.TOP | Gravity.LEFT; params.dimAmount = 0; params.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND; if (!focusable) { params.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; } params.height = ViewGroup.LayoutParams.MATCH_PARENT; window.setAttributes(params); }
From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java
void moveDrawerToOffset(View drawerView, float slideOffset) { Log.i(TAG, "BottomDrawerLayout -- moveDrawerToOffset() -- slideOffset = " + slideOffset); final int absGravity = getDrawerViewAbsoluteGravity(drawerView); final float oldOffset = getDrawerViewOffset(drawerView); final int width = drawerView.getWidth(); final int height = drawerView.getHeight(); final int xoldPos = (int) (width * oldOffset); final int xnewPos = (int) (width * slideOffset); final int yoldPos = (int) (height * oldOffset); final int ynewPos = (int) (height * slideOffset); int dx = xnewPos - xoldPos; int dy = ynewPos - yoldPos; if (absGravity == Gravity.LEFT || absGravity == Gravity.RIGHT) { drawerView.offsetLeftAndRight(checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT) ? dx : -dx); }/*from w ww.j a v a 2s .com*/ if (absGravity == Gravity.TOP || absGravity == Gravity.BOTTOM) { drawerView.offsetTopAndBottom(checkDrawerViewAbsoluteGravity(drawerView, Gravity.TOP) ? dy : -dy); } setDrawerViewOffset(drawerView, slideOffset); }
From source file:android.support.wear.widget.drawer.WearableDrawerLayout.java
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (mShouldPeekBottomDrawerAfterLayout || mShouldPeekTopDrawerAfterLayout || mShouldOpenTopDrawerAfterLayout || mShouldOpenBottomDrawerAfterLayout) { getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override/*from w w w. jav a 2 s. c o m*/ public void onGlobalLayout() { getViewTreeObserver().removeOnGlobalLayoutListener(this); if (mShouldOpenBottomDrawerAfterLayout) { openDrawerWithoutAnimation(mBottomDrawerView); mShouldOpenBottomDrawerAfterLayout = false; } else if (mShouldPeekBottomDrawerAfterLayout) { peekDrawer(Gravity.BOTTOM); mShouldPeekBottomDrawerAfterLayout = false; } if (mShouldOpenTopDrawerAfterLayout) { openDrawerWithoutAnimation(mTopDrawerView); mShouldOpenTopDrawerAfterLayout = false; } else if (mShouldPeekTopDrawerAfterLayout) { peekDrawer(Gravity.TOP); mShouldPeekTopDrawerAfterLayout = false; } } }); } }
From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java
/** * Simple gravity to string - only supports LEFT and RIGHT for debugging * output.//from ww w .ja va 2 s .co m * * @param gravity * Absolute gravity value * @return LEFT or RIGHT as appropriate, or a hex string */ static String gravityToString(int gravity) { if ((gravity & Gravity.LEFT) == Gravity.LEFT) { return "LEFT"; } if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) { return "RIGHT"; } if ((gravity & Gravity.TOP) == Gravity.TOP) { return "TOP"; } if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) { return "BOTTOM"; } return Integer.toHexString(gravity); }
From source file:com.edible.ocr.CaptureActivity.java
/** Called when the shutter button is pressed in continuous mode. */ void onShutterButtonPressContinuous() { isPaused = true;//from ww w . j a v a2 s . c o m handler.stop(); beepManager.playBeepSoundAndVibrate(); if (lastResult != null) { handleOcrDecode(lastResult); } else { Toast toast = Toast.makeText(this, "OCR failed. Please try again.", Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); resumeContinuousDecoding(); } }
From source file:com.androidhuman.circlerefreshlayout.SwipeRefreshLayout.java
public boolean canPull() { return Gravity.TOP == mPullPosition ? canChildScrollUp() : canChildScrollDown(); }
From source file:android.support.wear.widget.drawer.WearableDrawerLayout.java
@Override public void onFlingComplete(View view) { boolean canTopPeek = mTopDrawerView != null && mTopDrawerView.isAutoPeekEnabled(); boolean canBottomPeek = mBottomDrawerView != null && mBottomDrawerView.isAutoPeekEnabled(); boolean canScrollUp = view.canScrollVertically(UP); boolean canScrollDown = view.canScrollVertically(DOWN); if (canTopPeek && !canScrollUp && !mTopDrawerView.isPeeking()) { peekDrawer(Gravity.TOP); }//from ww w . j a v a 2 s . c om if (canBottomPeek && (!canScrollUp || !canScrollDown) && !mBottomDrawerView.isPeeking()) { peekDrawer(Gravity.BOTTOM); } }
From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;//from w w w . j a va2 s. co m final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (isContentView(child)) { child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight()); } else { // Drawer, if it wasn't onMeasure would have thrown an exception. final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childTop; if (checkDrawerViewGravity(child, Gravity.TOP)) { childTop = -childHeight + (int) (childHeight * lp.onScreen); } else { // Bottom; onMeasure checked for us. childTop = b - t - (int) (childHeight * lp.onScreen); } final int vgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.LEFT: { child.layout(lp.leftMargin, childTop, childWidth, childTop + childHeight); break; } case Gravity.RIGHT: { final int width = r - l; child.layout(width - lp.rightMargin - child.getMeasuredWidth(), childTop, width - lp.rightMargin, childTop + childHeight); break; } case Gravity.CENTER_HORIZONTAL: { final int width = r - l; int childLeft = (width - childWidth) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childLeft < lp.leftMargin) { childLeft = lp.leftMargin; } else if (childLeft + childWidth > width - lp.rightMargin) { childLeft = width - lp.rightMargin - childWidth; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); break; } } if (lp.onScreen == 0) { child.setVisibility(INVISIBLE); } } } mInLayout = false; mFirstLayout = false; }
From source file:android.support.v7.app.AppCompatDelegateImplV7.java
@Override ActionMode startSupportActionModeFromWindow(ActionMode.Callback callback) { if (mActionMode != null) { mActionMode.finish();//from w w w. j ava 2s . c o m } final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapper(callback); final Context context = getActionBarThemedContext(); if (mActionModeView == null) { if (mIsFloating) { mActionModeView = new ActionBarContextView(context); mActionModePopup = new PopupWindow(context, null, R.attr.actionModePopupWindowStyle); mActionModePopup.setContentView(mActionModeView); mActionModePopup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); TypedValue heightValue = new TypedValue(); mContext.getTheme().resolveAttribute(R.attr.actionBarSize, heightValue, true); final int height = TypedValue.complexToDimensionPixelSize(heightValue.data, mContext.getResources().getDisplayMetrics()); mActionModeView.setContentHeight(height); mActionModePopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); mShowActionModePopup = new Runnable() { public void run() { mActionModePopup.showAtLocation(mActionModeView, Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0); } }; } else { ViewStubCompat stub = (ViewStubCompat) mSubDecor.findViewById(R.id.action_mode_bar_stub); if (stub != null) { // Set the layout inflater so that it is inflated with the action bar's context stub.setLayoutInflater(LayoutInflater.from(context)); mActionModeView = (ActionBarContextView) stub.inflate(); } } } if (mActionModeView != null) { mActionModeView.killMode(); ActionMode mode = new StandaloneActionMode(context, mActionModeView, wrappedCallback, mActionModePopup == null); if (callback.onCreateActionMode(mode, mode.getMenu())) { mode.invalidate(); mActionModeView.initForMode(mode); mActionModeView.setVisibility(View.VISIBLE); mActionMode = mode; if (mActionModePopup != null) { mWindow.getDecorView().post(mShowActionModePopup); } mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); if (mActionModeView.getParent() != null) { ViewCompat.requestApplyInsets((View) mActionModeView.getParent()); } } else { mActionMode = null; } } if (mActionMode != null && mAppCompatCallback != null) { mAppCompatCallback.onSupportActionModeStarted(mActionMode); } return mActionMode; }
From source file:com.actionbarsherlock.custom.widget.ContentDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;// w ww .j a v a 2 s . c o m final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (isContentView(child)) { child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight()); } else { // Drawer, if it wasn't onMeasure would have thrown an exception. final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childLeft; if (checkDrawerViewGravity(child, Gravity.LEFT)) { childLeft = -childWidth + (int) (childWidth * lp.onScreen); } else { // Right; onMeasure checked for us. childLeft = r - l - (int) (childWidth * lp.onScreen); } final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.TOP: { child.layout(childLeft, lp.topMargin, childLeft + childWidth, childHeight); break; } case Gravity.BOTTOM: { final int height = b - t; child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(), childLeft + childWidth, height - lp.bottomMargin); break; } case Gravity.CENTER_VERTICAL: { final int height = b - t; int childTop = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop < lp.topMargin) { childTop = lp.topMargin; } else if (childTop + childHeight > height - lp.bottomMargin) { childTop = height - lp.bottomMargin - childHeight; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); break; } } if (lp.onScreen == 0) { child.setVisibility(INVISIBLE); } } } mInLayout = false; mFirstLayout = false; }