Add dividers to action bar navigation. Lighter dividers for holo themes.
Change-Id: I879dbd815a891fe5db20678b674a9cee63a5e1ae
diff --git a/api/current.xml b/api/current.xml
index f60b8fe..57518a7 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -5476,6 +5476,17 @@
visibility="public"
>
</field>
+<field name="itemPadding"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843582"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="itemTextAppearance"
type="int"
transient="false"
diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java
index a09e5c6..fd0e53d 100644
--- a/core/java/android/widget/LinearLayout.java
+++ b/core/java/android/widget/LinearLayout.java
@@ -155,8 +155,8 @@
public LinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- TypedArray a =
- context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.LinearLayout);
+ TypedArray a = context.obtainStyledAttributes(attrs,
+ com.android.internal.R.styleable.LinearLayout, defStyle, 0);
int index = a.getInt(com.android.internal.R.styleable.LinearLayout_orientation, -1);
if (index >= 0) {
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index 07a65fc..931bea9 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -90,6 +90,7 @@
private TextView mTitleView;
private TextView mSubtitleView;
private Spinner mSpinner;
+ private LinearLayout mListNavLayout;
private HorizontalScrollView mTabScrollView;
private LinearLayout mTabLayout;
private View mCustomNavView;
@@ -97,6 +98,7 @@
private ProgressBar mIndeterminateProgressView;
private int mProgressBarPadding;
+ private int mItemPadding;
private int mTitleStyleRes;
private int mSubtitleStyleRes;
@@ -193,6 +195,7 @@
R.styleable.ActionBar_indeterminateProgressStyle, 0);
mProgressBarPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_progressBarPadding, 0);
+ mItemPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_itemPadding, 0);
setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, DISPLAY_DEFAULT));
@@ -419,7 +422,7 @@
switch (oldMode) {
case ActionBar.NAVIGATION_MODE_LIST:
if (mSpinner != null) {
- removeView(mSpinner);
+ removeView(mListNavLayout);
}
break;
case ActionBar.NAVIGATION_MODE_TABS:
@@ -430,11 +433,21 @@
switch (mode) {
case ActionBar.NAVIGATION_MODE_LIST:
- mSpinner = new Spinner(mContext, null,
- com.android.internal.R.attr.actionDropDownStyle);
- mSpinner.setAdapter(mSpinnerAdapter);
+ if (mSpinner == null) {
+ mSpinner = new Spinner(mContext, null,
+ com.android.internal.R.attr.actionDropDownStyle);
+ mListNavLayout = new LinearLayout(mContext, null,
+ com.android.internal.R.attr.actionBarTabBarStyle);
+ LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
+ LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ params.gravity = Gravity.CENTER;
+ mListNavLayout.addView(mSpinner, params);
+ }
+ if (mSpinner.getAdapter() != mSpinnerAdapter) {
+ mSpinner.setAdapter(mSpinnerAdapter);
+ }
mSpinner.setOnItemSelectedListener(mNavItemSelectedListener);
- addView(mSpinner);
+ addView(mListNavLayout);
break;
case ActionBar.NAVIGATION_MODE_TABS:
ensureTabsExist();
@@ -631,24 +644,32 @@
rightOfCenter -= mMenuView.getMeasuredWidth();
}
- if (mTitleLayout != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
+ boolean showTitle = mTitleLayout != null &&
+ (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;
+ if (showTitle) {
availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0);
leftOfCenter -= mTitleLayout.getMeasuredWidth();
}
switch (mNavigationMode) {
case ActionBar.NAVIGATION_MODE_LIST:
- if (mSpinner != null) {
- mSpinner.measure(
+ if (mListNavLayout != null) {
+ final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
+ availableWidth -= itemPaddingSize;
+ leftOfCenter -= itemPaddingSize;
+ mListNavLayout.measure(
MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
- MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
- final int spinnerWidth = mSpinner.getMeasuredWidth();
- availableWidth -= spinnerWidth;
- leftOfCenter -= spinnerWidth;
+ MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
+ final int listNavWidth = mListNavLayout.getMeasuredWidth();
+ availableWidth -= listNavWidth;
+ leftOfCenter -= listNavWidth;
}
break;
case ActionBar.NAVIGATION_MODE_TABS:
if (mTabScrollView != null) {
+ final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
+ availableWidth -= itemPaddingSize;
+ leftOfCenter -= itemPaddingSize;
mTabScrollView.measure(
MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
@@ -755,7 +776,9 @@
x += positionChild(mHomeLayout, x, y, contentHeight);
}
- if (mTitleLayout != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
+ final boolean showTitle = mTitleLayout != null &&
+ (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;
+ if (showTitle) {
x += positionChild(mTitleLayout, x, y, contentHeight);
}
@@ -763,13 +786,15 @@
case ActionBar.NAVIGATION_MODE_STANDARD:
break;
case ActionBar.NAVIGATION_MODE_LIST:
- if (mSpinner != null) {
- x += positionChild(mSpinner, x, y, contentHeight);
+ if (mListNavLayout != null) {
+ if (showTitle) x += mItemPadding;
+ x += positionChild(mListNavLayout, x, y, contentHeight) + mItemPadding;
}
break;
case ActionBar.NAVIGATION_MODE_TABS:
if (mTabScrollView != null) {
- x += positionChild(mTabScrollView, x, y, contentHeight);
+ if (showTitle) x += mItemPadding;
+ x += positionChild(mTabScrollView, x, y, contentHeight) + mItemPadding;
}
break;
}
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 78465cf..4d35b94 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -4542,6 +4542,9 @@
<attr name="indeterminateProgressStyle" format="reference" />
<!-- Specifies the horizontal padding on either end for an embedded progress bar. -->
<attr name="progressBarPadding" format="dimension" />
+ <!-- Specifies padding that should be applied to the left and right sides of
+ system-provided items in the bar. -->
+ <attr name="itemPadding" format="dimension" />
</declare-styleable>
<declare-styleable name="ActionMode">
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 63097c1..5941b52 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1396,6 +1396,7 @@
<public type="attr" name="dividerPadding" />
<public type="attr" name="borderlessButtonStyle" />
<public type="attr" name="dividerHorizontal" />
+ <public type="attr" name="itemPadding" />
<public type="anim" name="animator_fade_in" />
<public type="anim" name="animator_fade_out" />
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index e364418..d13af31 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -1599,6 +1599,9 @@
</style>
<style name="Widget.Holo.ActionBarView_TabBar" parent="Widget.ActionBarView_TabBar">
+ <item name="divider">?android:attr/dividerVertical</item>
+ <item name="showDividers">beginning|end</item>
+ <item name="dividerPadding">8dip</item>
</style>
<style name="Widget.Holo.ActionBarView_TabText" parent="Widget.ActionBarView_TabText">
@@ -1624,6 +1627,7 @@
<item name="android:progressBarStyle">@android:style/Widget.Holo.ProgressBar.Horizontal</item>
<item name="android:indeterminateProgressStyle">@android:style/Widget.Holo.ProgressBar</item>
<item name="android:progressBarPadding">32dip</item>
+ <item name="android:itemPadding">8dip</item>
</style>
<style name="Widget.Holo.CompoundButton.Switch">
diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml
index 9c4e237..a44e8d4 100644
--- a/core/res/res/values/themes.xml
+++ b/core/res/res/values/themes.xml
@@ -900,8 +900,8 @@
<item name="actionBarStyle">@android:style/Widget.Holo.ActionBar</item>
<item name="actionBarSize">56dip</item>
- <item name="dividerVertical">@drawable/divider_vertical_holo_dark</item>
- <item name="dividerHorizontal">@drawable/divider_vertical_holo_dark</item>
+ <item name="dividerVertical">?android:attr/listDivider</item>
+ <item name="dividerHorizontal">?android:attr/listDivider</item>
<item name="buttonGroupStyle">@android:style/Widget.Holo.ButtonGroup</item>
<!-- SearchView attributes -->
@@ -1146,8 +1146,8 @@
<item name="actionBarStyle">@android:style/Widget.Holo.Light.ActionBar</item>
<item name="actionBarSize">56dip</item>
- <item name="dividerVertical">@drawable/divider_vertical_holo_light</item>
- <item name="dividerHorizontal">@drawable/divider_vertical_holo_light</item>
+ <item name="dividerVertical">?android:attr/listDivider</item>
+ <item name="dividerHorizontal">?android:attr/listDivider</item>
<item name="buttonGroupStyle">@android:style/Widget.Holo.Light.ButtonGroup</item>
<!-- SearchView attributes -->