List of usage examples for android.view Gravity HORIZONTAL_GRAVITY_MASK
int HORIZONTAL_GRAVITY_MASK
To view the source code for android.view Gravity HORIZONTAL_GRAVITY_MASK.
Click Source Link
From source file:com.brookmanholmes.bma.wizard.ui.StepPagerStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (pageCount == 0) { return;// ww w . j av a2 s . c o m } float totalWidth = pageCount * (tabWidth + indicatorSpacing) - indicatorSpacing; float totalcx; float cy; boolean fillHorizontal = false; switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: totalcx = (getWidth() - totalWidth) / 2; break; case Gravity.RIGHT: totalcx = getWidth() - getPaddingRight() - totalWidth; break; case Gravity.FILL_HORIZONTAL: totalcx = getPaddingLeft(); fillHorizontal = true; break; default: totalcx = getPaddingLeft(); } switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.CENTER_VERTICAL: cy = (int) (getHeight() - tabHeight) / 2; break; case Gravity.BOTTOM: cy = getHeight() - getPaddingBottom() - tabHeight; break; default: cy = getPaddingTop(); } float center = cy + tabHeight / 2; float tabWidth = this.tabWidth; if (fillHorizontal) { tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (pageCount - 1) * indicatorSpacing) / pageCount; } for (int i = 0; i < pageCount; i++) { float cx = totalcx + (i * (tabWidth + indicatorSpacing)); Paint tempPaint; if (i < currentPage) tempPaint = prevTabPaint; else if (i > currentPage) tempPaint = nextTabPaint; else tempPaint = selectedTabPaint; canvas.drawCircle(cx, center, i == currentPage ? radius : nonCurrentRadius, tempPaint); } }
From source file:id.co.datascrip.dtswarehousesystem.custom.StepPagerStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mPageCount == 0) { return;/*from www. j ava2 s . c o m*/ } float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing; float totalLeft; boolean fillHorizontal = false; switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: totalLeft = (getWidth() - totalWidth) / 2; break; case Gravity.END: totalLeft = getWidth() - getPaddingRight() - totalWidth; break; case Gravity.FILL_HORIZONTAL: totalLeft = getPaddingLeft(); fillHorizontal = true; break; default: totalLeft = getPaddingLeft(); } switch (mGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.CENTER_VERTICAL: mTempRectF.top = (int) (getHeight() - mTabHeight) / 2; break; case Gravity.BOTTOM: mTempRectF.top = getHeight() - getPaddingBottom() - mTabHeight; break; default: mTempRectF.top = getPaddingTop(); } mTempRectF.bottom = mTempRectF.top + mTabHeight; float tabWidth = mTabWidth; if (fillHorizontal) { tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (mPageCount - 1) * mTabSpacing) / mPageCount; } for (int i = 0; i < mPageCount; i++) { mTempRectF.left = totalLeft + (i * (tabWidth + mTabSpacing)); mTempRectF.right = mTempRectF.left + tabWidth; canvas.drawRect(mTempRectF, i < mCurrentPage ? mPrevTabPaint : (i > mCurrentPage ? mNextTabPaint : (i == mPageCount - 1 ? mSelectedLastTabPaint : mSelectedTabPaint))); } }
From source file:com.example.android.supportv7.app.ToolbarDisplayOptions.java
@Override public void onClick(View v) { final ActionBar bar = getSupportActionBar(); int flags = 0; switch (v.getId()) { case R.id.toggle_home_as_up: flags = ActionBar.DISPLAY_HOME_AS_UP; break;//from ww w. j a v a 2s . c o m case R.id.toggle_show_home: flags = ActionBar.DISPLAY_SHOW_HOME; break; case R.id.toggle_use_logo: flags = ActionBar.DISPLAY_USE_LOGO; getSupportActionBar().setLogo(R.drawable.ic_media_play); break; case R.id.toggle_show_title: flags = ActionBar.DISPLAY_SHOW_TITLE; break; case R.id.toggle_show_custom: flags = ActionBar.DISPLAY_SHOW_CUSTOM; break; case R.id.cycle_custom_gravity: { ActionBar.LayoutParams lp = mCustomViewLayoutParams; int newGravity = 0; switch (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: newGravity = Gravity.CENTER_HORIZONTAL; break; case Gravity.CENTER_HORIZONTAL: newGravity = Gravity.RIGHT; break; case Gravity.RIGHT: newGravity = Gravity.LEFT; break; } lp.gravity = lp.gravity & ~Gravity.HORIZONTAL_GRAVITY_MASK | newGravity; bar.setCustomView(mCustomView, lp); return; } case R.id.toggle_visibility: if (bar.isShowing()) { bar.hide(); } else { bar.show(); } return; } int change = bar.getDisplayOptions() ^ flags; bar.setDisplayOptions(change, flags); }
From source file:com.example.android.supportv7.app.ActionBarDisplayOptions.java
@Override public void onClick(View v) { final ActionBar bar = getSupportActionBar(); int flags = 0; switch (v.getId()) { case R.id.toggle_home_as_up: flags = ActionBar.DISPLAY_HOME_AS_UP; break;/*from ww w.ja va 2s . c o m*/ case R.id.toggle_show_home: flags = ActionBar.DISPLAY_SHOW_HOME; break; case R.id.toggle_use_logo: flags = ActionBar.DISPLAY_USE_LOGO; break; case R.id.toggle_show_title: flags = ActionBar.DISPLAY_SHOW_TITLE; break; case R.id.toggle_show_custom: flags = ActionBar.DISPLAY_SHOW_CUSTOM; break; case R.id.toggle_navigation: bar.setNavigationMode( bar.getNavigationMode() == ActionBar.NAVIGATION_MODE_STANDARD ? ActionBar.NAVIGATION_MODE_TABS : ActionBar.NAVIGATION_MODE_STANDARD); return; case R.id.cycle_custom_gravity: { ActionBar.LayoutParams lp = mCustomViewLayoutParams; int newGravity = 0; switch (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: newGravity = Gravity.CENTER_HORIZONTAL; break; case Gravity.CENTER_HORIZONTAL: newGravity = Gravity.RIGHT; break; case Gravity.RIGHT: newGravity = Gravity.LEFT; break; } lp.gravity = lp.gravity & ~Gravity.HORIZONTAL_GRAVITY_MASK | newGravity; bar.setCustomView(mCustomView, lp); return; } case R.id.toggle_visibility: if (bar.isShowing()) { bar.hide(); } else { bar.show(); } return; } int change = bar.getDisplayOptions() ^ flags; bar.setDisplayOptions(change, flags); }
From source file:li.barter.widgets.FullWidthDrawerLayout.java
@Override protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { final int widthMode = MeasureSpec.getMode(widthMeasureSpec); final int heightMode = MeasureSpec.getMode(heightMeasureSpec); final int widthSize = MeasureSpec.getSize(widthMeasureSpec); final int heightSize = MeasureSpec.getSize(heightMeasureSpec); if ((widthMode != MeasureSpec.EXACTLY) || (heightMode != MeasureSpec.EXACTLY)) { throw new IllegalArgumentException("DrawerLayout must be measured with MeasureSpec.EXACTLY."); }//ww w . j a v a2 s .c o m setMeasuredDimension(widthSize, heightSize); // Gravity value for each drawer we've seen. Only one of each permitted. final int foundDrawers = 0; 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 (isChildAContentView(child)) { // Content views get measured at exactly the layout's size. final int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY); final int contentHeightSpec = MeasureSpec .makeMeasureSpec(heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY); child.measure(contentWidthSpec, contentHeightSpec); } else if (isChildADrawerView(child)) { final int childGravity = getDrawerViewGravity(child) & Gravity.HORIZONTAL_GRAVITY_MASK; if ((foundDrawers & childGravity) != 0) { throw new IllegalStateException( "Child drawer has absolute gravity " + gravityToString(childGravity) + " but this already has a " + "drawer view along that edge"); } final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec, lp.leftMargin + lp.rightMargin, lp.width); final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec, lp.topMargin + lp.bottomMargin, lp.height); child.measure(drawerWidthSpec, drawerHeightSpec); } 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"); } } }
From source file:com.tmall.ultraviewpager.UltraViewPagerIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (viewPager == null || viewPager.getAdapter() == null) return;//from w w w . j a v a 2 s.c o m final int count = ((UltraViewPagerAdapter) viewPager.getAdapter()).getRealCount(); if (count == 0) return; int longSize; int shortSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; int shortPaddingAfter; if (orientation == UltraViewPager.Orientation.HORIZONTAL) { longSize = viewPager.getWidth(); shortSize = viewPager.getHeight(); longPaddingBefore = getPaddingLeft() + marginLeft; longPaddingAfter = getPaddingRight() + marginRight; shortPaddingBefore = getPaddingTop() + marginTop; shortPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom; } else { longSize = viewPager.getHeight(); shortSize = viewPager.getWidth(); longPaddingBefore = getPaddingTop() + marginTop; longPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom; shortPaddingBefore = getPaddingLeft() + marginLeft; shortPaddingAfter = getPaddingRight() + marginRight; } final float itemWidth = getItemWidth(); final int widthRatio = isDrawResIndicator() ? 1 : 2; //bitmap resource X1 : circle X2 if (indicatorPadding == 0) { indicatorPadding = (int) itemWidth; } float shortOffset = shortPaddingBefore; float longOffset = longPaddingBefore; final float indicatorLength = (count - 1) * (itemWidth * widthRatio + indicatorPadding); final int horizontalGravityMask = gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int verticalGravityMask = gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (horizontalGravityMask) { case Gravity.CENTER_HORIZONTAL: longOffset = (longSize - longPaddingBefore - longPaddingAfter - indicatorLength) / 2.0f; break; case Gravity.RIGHT: if (orientation == UltraViewPager.Orientation.HORIZONTAL) { longOffset = longSize - longPaddingAfter - indicatorLength - itemWidth; } if (orientation == UltraViewPager.Orientation.VERTICAL) { shortOffset = shortSize - shortPaddingAfter - itemWidth; } break; case Gravity.LEFT: longOffset += itemWidth; default: break; } switch (verticalGravityMask) { case Gravity.CENTER_VERTICAL: shortOffset = (shortSize - shortPaddingAfter - shortPaddingBefore - itemWidth) / 2; break; case Gravity.BOTTOM: if (orientation == UltraViewPager.Orientation.HORIZONTAL) { shortOffset = shortSize - shortPaddingAfter - getItemHeight(); } if (orientation == UltraViewPager.Orientation.VERTICAL) { longOffset = longSize - longPaddingAfter - indicatorLength; } break; case Gravity.TOP: shortOffset += itemWidth; default: break; } if (horizontalGravityMask == Gravity.CENTER_HORIZONTAL && verticalGravityMask == Gravity.CENTER_VERTICAL) { shortOffset = (shortSize - shortPaddingAfter - shortPaddingBefore - itemWidth) / 2; } float dX; float dY; float pageFillRadius = radius; if (paintStroke.getStrokeWidth() > 0) { pageFillRadius -= paintStroke.getStrokeWidth() / 2.0f; //TODO may not/2 } //Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * (itemWidth * widthRatio + indicatorPadding)); if (orientation == UltraViewPager.Orientation.HORIZONTAL) { dX = drawLong; dY = shortOffset; } else { dX = shortOffset; dY = drawLong; } if (isDrawResIndicator()) { if (iLoop == viewPager.getCurrentItem()) continue; canvas.drawBitmap(normalBitmap, dX, dY, paintFill); } else { // Only paint fill if not completely transparent if (paintFill.getAlpha() > 0) { paintFill.setColor(normalColor); canvas.drawCircle(dX, dY, pageFillRadius, paintFill); } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != radius) { canvas.drawCircle(dX, dY, radius, paintStroke); } } } //Draw the filled circle according to the current scroll float cx = (viewPager.getCurrentItem()) * (itemWidth * widthRatio + indicatorPadding); if (animateIndicator) cx += pageOffset * itemWidth; if (orientation == UltraViewPager.Orientation.HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } if (isDrawResIndicator()) { canvas.drawBitmap(focusBitmap, dX, dY, paintStroke); } else { paintFill.setColor(focusColor); canvas.drawCircle(dX, dY, radius, paintFill); } }
From source file:com.qs.qswlw.view.Mypager.UltraViewPagerIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (viewPager == null || viewPager.getAdapter() == null) return;/*from w w w .ja v a2 s . c o m*/ final int count = ((UltraViewPagerAdapter) viewPager.getAdapter()).getRealCount(); if (count == 0) return; int longSize; int shortSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; int shortPaddingAfter; if (orientation == UltraViewPager.Orientation.HORIZONTAL) { longSize = viewPager.getWidth(); shortSize = viewPager.getHeight(); longPaddingBefore = (int) (getItemWidth() + getPaddingLeft() + marginLeft); longPaddingAfter = getPaddingRight() + marginRight; shortPaddingBefore = (int) (getItemWidth() + getPaddingTop() + marginTop); shortPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom; } else { longSize = viewPager.getHeight(); shortSize = viewPager.getWidth(); longPaddingBefore = (int) (getItemWidth() + getPaddingTop() + marginTop); longPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom; shortPaddingBefore = (int) (getItemWidth() + getPaddingLeft() + marginLeft); shortPaddingAfter = getPaddingRight() + marginRight; } final float itemWidth = getItemWidth(); final int widthRatio = isDrawResIndicator() ? 1 : 2; //bitmap resource X1 : circle X2 if (indicatorPadding == 0) { indicatorPadding = (int) itemWidth; } float shortOffset = shortPaddingBefore; float longOffset = longPaddingBefore; final float indicatorLength = count * itemWidth * widthRatio + (count - 1) * indicatorPadding; final int horizontalGravityMask = gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int verticalGravityMask = gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (horizontalGravityMask) { case Gravity.CENTER_HORIZONTAL: longOffset = (longSize - longPaddingBefore - longPaddingAfter - indicatorLength) / 2.0f; break; case Gravity.RIGHT: if (orientation == UltraViewPager.Orientation.HORIZONTAL) { longOffset = longSize - longPaddingAfter - indicatorLength; } if (orientation == UltraViewPager.Orientation.VERTICAL) { shortOffset = shortSize - shortPaddingAfter - itemWidth; } break; case Gravity.LEFT: default: break; } switch (verticalGravityMask) { case Gravity.CENTER_VERTICAL: shortOffset = (shortSize - shortPaddingAfter - shortPaddingBefore - itemWidth) / 2; break; case Gravity.BOTTOM: if (orientation == UltraViewPager.Orientation.HORIZONTAL) { shortOffset = shortSize - shortPaddingAfter - getItemHeight(); } if (orientation == UltraViewPager.Orientation.VERTICAL) { longOffset = longSize - longPaddingAfter - indicatorLength; } break; case Gravity.TOP: default: break; } if (horizontalGravityMask == Gravity.CENTER_HORIZONTAL && verticalGravityMask == Gravity.CENTER_VERTICAL) { shortOffset = (shortSize - shortPaddingAfter - shortPaddingBefore - itemWidth) / 2; } float dX; float dY; float pageFillRadius = radius; if (paintStroke.getStrokeWidth() > 0) { pageFillRadius -= paintStroke.getStrokeWidth() / 2.0f; //TODO may not/2 } //Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * (itemWidth * widthRatio + indicatorPadding)); if (orientation == UltraViewPager.Orientation.HORIZONTAL) { dX = drawLong; dY = shortOffset; } else { dX = shortOffset; dY = drawLong; } if (isDrawResIndicator()) { if (iLoop == viewPager.getCurrentItem()) continue; canvas.drawBitmap(normalBitmap, dX, dY, paintFill); } else { // Only paint fill if not completely transparent if (paintFill.getAlpha() > 0) { paintFill.setColor(normalColor); canvas.drawCircle(dX, dY, pageFillRadius, paintFill); } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != radius) { canvas.drawCircle(dX, dY, radius, paintStroke); } } } //Draw the filled circle according to the current scroll float cx = (viewPager.getCurrentItem()) * (itemWidth * widthRatio + indicatorPadding); if (animateIndicator) cx += pageOffset * itemWidth; if (orientation == UltraViewPager.Orientation.HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } if (isDrawResIndicator()) { canvas.drawBitmap(focusBitmap, dX, dY, paintStroke); } else { paintFill.setColor(focusColor); canvas.drawCircle(dX, dY, radius, paintFill); } }
From source file:com.manuelpeinado.imagelayout.ImageLayout.java
public void setGravity(int newValue) { if (fitter != null && gravity == newValue) { return;/*from w w w. j a v a2 s.c o m*/ } if ((newValue & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) { newValue |= Gravity.CENTER_HORIZONTAL; } if ((newValue & Gravity.VERTICAL_GRAVITY_MASK) == 0) { newValue |= Gravity.CENTER_VERTICAL; } gravity = newValue; rebuildFitter(); }
From source file:com.brookmanholmes.bma.wizard.ui.StepPagerStrip.java
private int hitTest(float x) { if (pageCount == 0) { return -1; }/* w w w .ja va 2s. c o m*/ float totalWidth = pageCount * (tabWidth + indicatorSpacing) - indicatorSpacing; float totalLeft; boolean fillHorizontal = false; switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: totalLeft = (getWidth() - totalWidth) / 2; break; case Gravity.RIGHT: totalLeft = getWidth() - getPaddingRight() - totalWidth; break; case Gravity.FILL_HORIZONTAL: totalLeft = getPaddingLeft(); fillHorizontal = true; break; default: totalLeft = getPaddingLeft(); } float tabWidth = this.tabWidth; if (fillHorizontal) { tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (pageCount - 1) * indicatorSpacing) / pageCount; } float totalRight = totalLeft + (pageCount * (tabWidth + indicatorSpacing)); if (x >= totalLeft && x <= totalRight && totalRight > totalLeft) { return (int) (((x - totalLeft) / (totalRight - totalLeft)) * pageCount); } else { return -1; } }
From source file:id.co.datascrip.dtswarehousesystem.custom.StepPagerStrip.java
private int hitTest(float x) { if (mPageCount == 0) { return -1; }// ww w . j av a 2s.c o m float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing; float totalLeft; boolean fillHorizontal = false; switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: totalLeft = (getWidth() - totalWidth) / 2; break; case Gravity.RIGHT: totalLeft = getWidth() - getPaddingRight() - totalWidth; break; case Gravity.FILL_HORIZONTAL: totalLeft = getPaddingLeft(); fillHorizontal = true; break; default: totalLeft = getPaddingLeft(); } float tabWidth = mTabWidth; if (fillHorizontal) { tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (mPageCount - 1) * mTabSpacing) / mPageCount; } float totalRight = totalLeft + (mPageCount * (tabWidth + mTabSpacing)); if (x >= totalLeft && x <= totalRight && totalRight > totalLeft) { return (int) (((x - totalLeft) / (totalRight - totalLeft)) * mPageCount); } else { return -1; } }