Skip to content

Commit

Permalink
Add configurable padding between title text and indicator.
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed Aug 6, 2011
1 parent 925770a commit 99b4f90
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions library/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<enum name="underline" value="2" />
</attr>
<attr name="footerIndicatorHeight" format="dimension" />
<attr name="footerIndicatorPadding" format="dimension" />
<attr name="footerIndicatorUnderlinePadding" format="dimension" />
<attr name="selectedColor" format="color" />
<attr name="selectedBold" format="boolean" />
Expand Down
1 change: 1 addition & 0 deletions library/res/values/defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<dimen name="default_title_indicator_footer_line_height">1px</dimen>
<integer name="default_title_indicator_footer_indicator_style">1</integer>
<dimen name="default_title_indicator_footer_indicator_height">7dp</dimen>
<dimen name="default_title_indicator_footer_indicator_padding">5dp</dimen>
<dimen name="default_title_indicator_footer_indicator_underline_padding">10dp</dimen>
<color name="default_title_indicator_selected_color">#FFFFFFFF</color>
<bool name="default_title_indicator_selected_bold">true</bool>
Expand Down
1 change: 1 addition & 0 deletions library/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<item name="footerLineHeight">@dimen/default_title_indicator_footer_line_height</item>
<item name="footerIndicatorStyle">@integer/default_title_indicator_footer_indicator_style</item>
<item name="footerIndicatorHeight">@dimen/default_title_indicator_footer_indicator_height</item>
<item name="footerIndicatorPadding">@dimen/default_title_indicator_footer_indicator_padding</item>
<item name="footerIndicatorUnderlinePadding">@dimen/default_title_indicator_footer_indicator_underline_padding</item>
<item name="selectedColor">@color/default_title_indicator_selected_color</item>
<item name="selectedBold">@bool/default_title_indicator_selected_bold</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public static IndicatorStyle fromValue(int value) {
private IndicatorStyle mFooterIndicatorStyle;
private final Paint mPaintFooterIndicator;
private float mFooterIndicatorHeight;
private float mFooterIndicatorPadding;
private float mFooterIndicatorUnderlinePadding;
private float mTitlePadding;
/** Left and right side padding for not active view titles. */
Expand All @@ -98,6 +99,7 @@ public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) {
final float defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height);
final int defaultFooterIndicatorStyle = res.getInteger(R.integer.default_title_indicator_footer_indicator_style);
final float defaultFooterIndicatorHeight = res.getDimension(R.dimen.default_title_indicator_footer_indicator_height);
final float defaultFooterIndicatorPadding = res.getDimension(R.dimen.default_title_indicator_footer_indicator_padding);
final float defaultFooterIndicatorUnderlinePadding = res.getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding);
final int defaultSelectedColor = res.getColor(R.color.default_title_indicator_selected_color);
final boolean defaultSelectedBold = res.getBoolean(R.bool.default_title_indicator_selected_bold);
Expand All @@ -113,6 +115,7 @@ public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) {
mFooterLineHeight = a.getDimension(R.styleable.TitlePageIndicator_footerLineHeight, defaultFooterLineHeight);
mFooterIndicatorStyle = IndicatorStyle.fromValue(a.getInteger(R.styleable.TitlePageIndicator_footerIndicatorStyle, defaultFooterIndicatorStyle));
mFooterIndicatorHeight = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorHeight, defaultFooterIndicatorHeight);
mFooterIndicatorPadding = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorPadding, defaultFooterIndicatorPadding);
mFooterIndicatorUnderlinePadding = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding, defaultFooterIndicatorUnderlinePadding);
mTitlePadding = a.getDimension(R.styleable.TitlePageIndicator_titlePadding, defaultTitlePadding);
mClipPadding = a.getDimension(R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding);
Expand Down Expand Up @@ -555,7 +558,7 @@ private int measureWidth(int measureSpec) {
* @return The height of the view, honoring constraints from measureSpec
*/
private int measureHeight(int measureSpec) {
int result = 0;
float result = 0;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);

Expand All @@ -566,12 +569,12 @@ private int measureHeight(int measureSpec) {
//Calculate the text bounds
Rect bounds = new Rect();
bounds.bottom = (int) (mPaintText.descent()-mPaintText.ascent());
result = bounds.bottom - bounds.top + (int)mFooterLineHeight;
result = bounds.bottom - bounds.top + mFooterLineHeight;
if (mFooterIndicatorStyle != IndicatorStyle.None) {
result += (int)mFooterIndicatorHeight;
result += mFooterIndicatorHeight + mFooterIndicatorPadding;
}
}
return result;
return (int)result;
}

@Override
Expand Down

0 comments on commit 99b4f90

Please sign in to comment.