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.albedinsky.android.ui.widget.SeekBarWidget.java
/** * Draws discrete indicator of this SeekBarWidget at its current position updated by * {@link #updateDiscreteIndicatorPosition(int, int)} according to the current progress. * * @param canvas Canvas on which to draw discrete indicator's drawable. *//* w w w .j a v a 2s.c om*/ private void drawDiscreteIndicator(Canvas canvas) { if (mDiscreteIndicatorHeight == 0) { return; } // todo: draw according to LTR/RTL layout direction. mDiscreteIndicator.draw(canvas); // Draw current progress over indicator's graphics. final Rect indicatorBounds = mDiscreteIndicator.getBounds(); final Paint textPaint = DISCRETE_INDICATOR_TEXT_INFO.paint; textPaint.getTextBounds("0", 0, 1, mRect); final float textSize = mRect.height(); final Rect textPadding = DISCRETE_INDICATOR_TEXT_INFO.padding; final int absoluteTextGravity = WidgetGravity.getAbsoluteGravity(DISCRETE_INDICATOR_TEXT_INFO.gravity, ViewCompat.getLayoutDirection(this)); final float textX, textY; // Resolve horizontal text position according to the requested gravity. switch (absoluteTextGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: textPaint.setTextAlign(Paint.Align.CENTER); textX = indicatorBounds.centerX(); break; case Gravity.RIGHT: textPaint.setTextAlign(Paint.Align.RIGHT); textX = indicatorBounds.right - textPadding.right; break; case Gravity.LEFT: default: textPaint.setTextAlign(Paint.Align.LEFT); textX = indicatorBounds.left + textPadding.left; break; } // Resolve vertical text position according to the requested gravity. switch (absoluteTextGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.CENTER_VERTICAL: textY = indicatorBounds.centerY() + textSize / 2f; break; case Gravity.BOTTOM: textY = indicatorBounds.bottom - textPadding.bottom; break; case Gravity.TOP: default: textY = indicatorBounds.top + textSize + textPadding.top; break; } canvas.drawText(Integer.toString(getProgress()), textX, textY, textPaint); }