summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2010-06-17 12:51:21 -0700
committerAdam Powell <adamp@google.com>2010-06-18 10:12:20 -0700
commit7ade1be822ed05a143b059319dccd5e9f623b56d (patch)
treefb7feaafe62f5e04256935c690b750e7b8c68ddc
parent831c6cc7c1cfcf1271c75dc960948ab6ce720b67 (diff)
downloadframeworks_base-7ade1be822ed05a143b059319dccd5e9f623b56d.zip
frameworks_base-7ade1be822ed05a143b059319dccd5e9f623b56d.tar.gz
frameworks_base-7ade1be822ed05a143b059319dccd5e9f623b56d.tar.bz2
Action bar button layout changes.
Theme attribute added for spacing between action buttons. Action buttons are now allowed to fill up to half of the total action bar's width. Change-Id: Iabbc67e695684529dfae9681d4d9580cd30839d0
-rw-r--r--api/current.xml11
-rw-r--r--core/java/android/view/ActionBarView.java13
-rw-r--r--core/java/com/android/internal/view/menu/ActionMenuView.java54
-rwxr-xr-xcore/res/res/values/attrs.xml7
-rw-r--r--core/res/res/values/dimens.xml3
-rw-r--r--core/res/res/values/public.xml1
-rw-r--r--core/res/res/values/themes.xml3
7 files changed, 83 insertions, 9 deletions
diff --git a/api/current.xml b/api/current.xml
index 966154a..851e9c2 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -2088,6 +2088,17 @@
visibility="public"
>
</field>
+<field name="actionButtonPadding"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843547"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="actionButtonStyle"
type="int"
transient="false"
diff --git a/core/java/android/view/ActionBarView.java b/core/java/android/view/ActionBarView.java
index 3966847..5142c50 100644
--- a/core/java/android/view/ActionBarView.java
+++ b/core/java/android/view/ActionBarView.java
@@ -19,6 +19,7 @@ package android.view;
import com.android.internal.R;
import com.android.internal.view.menu.ActionMenu;
import com.android.internal.view.menu.ActionMenuItem;
+import com.android.internal.view.menu.ActionMenuView;
import com.android.internal.view.menu.MenuBuilder;
import android.app.ActionBar;
@@ -85,7 +86,7 @@ public class ActionBarView extends ViewGroup {
private boolean mShowMenu;
private MenuBuilder mOptionsMenu;
- private View mMenuView;
+ private ActionMenuView mMenuView;
private ActionMenuItem mLogoNavItem;
@@ -186,7 +187,9 @@ public class ActionBarView extends ViewGroup {
if (mMenuView != null) {
removeView(mMenuView);
}
- final View menuView = builder.getMenuView(MenuBuilder.TYPE_ACTION_BUTTON, null);
+ final ActionMenuView menuView = (ActionMenuView) builder.getMenuView(
+ MenuBuilder.TYPE_ACTION_BUTTON, null);
+ mActionSpacing = menuView.getItemMargin();
final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.MATCH_PARENT);
menuView.setLayoutParams(layoutParams);
@@ -426,7 +429,7 @@ public class ActionBarView extends ViewGroup {
if (mMenuView != null) {
availableWidth = measureChildView(mMenuView, availableWidth,
- childSpecHeight, mActionSpacing);
+ childSpecHeight, 0);
}
switch (mNavigationMode) {
@@ -497,9 +500,9 @@ public class ActionBarView extends ViewGroup {
x = r - l - getPaddingRight();
-
if (mMenuView != null) {
- x -= positionChildInverse(mMenuView, x, y, contentHeight) + mActionSpacing;
+ x -= positionChildInverse(mMenuView, x + mActionSpacing, y, contentHeight)
+ - mActionSpacing;
}
}
diff --git a/core/java/com/android/internal/view/menu/ActionMenuView.java b/core/java/com/android/internal/view/menu/ActionMenuView.java
index 596e3de..97d27ac 100644
--- a/core/java/com/android/internal/view/menu/ActionMenuView.java
+++ b/core/java/com/android/internal/view/menu/ActionMenuView.java
@@ -16,7 +16,10 @@
package com.android.internal.view.menu;
import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
import android.util.AttributeSet;
+import android.view.ViewGroup;
import android.widget.LinearLayout;
import java.util.ArrayList;
@@ -27,10 +30,11 @@ import java.util.ArrayList;
public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvoker, MenuView {
private static final String TAG = "ActionMenuView";
- // TODO: Make this a ViewConfiguration constant.
- private static final int MAX_ACTION_ITEMS = 3;
-
private MenuBuilder mMenu;
+
+ private int mItemPadding;
+ private int mItemMargin;
+ private int mMaxItems;
public ActionMenuView(Context context) {
this(context, null);
@@ -38,6 +42,48 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
public ActionMenuView(Context context, AttributeSet attrs) {
super(context, attrs);
+
+ TypedArray a = context.obtainStyledAttributes(attrs,
+ com.android.internal.R.styleable.Theme);
+ mItemPadding = a.getDimensionPixelOffset(
+ com.android.internal.R.styleable.Theme_actionButtonPadding, 0);
+ mItemMargin = mItemPadding / 2;
+ a.recycle();
+
+ final Resources res = getResources();
+ final int size = res.getDimensionPixelSize(com.android.internal.R.dimen.action_icon_size);
+ final int spaceAvailable = res.getDisplayMetrics().widthPixels / 2;
+ final int itemSpace = size + mItemPadding;
+
+ mMaxItems = spaceAvailable / (itemSpace > 0 ? itemSpace : 1);
+ }
+
+ @Override
+ protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
+ if (p instanceof LayoutParams) {
+ LayoutParams lp = (LayoutParams) p;
+ return lp.leftMargin == mItemMargin && lp.rightMargin == mItemMargin &&
+ lp.width == LayoutParams.WRAP_CONTENT && lp.height == LayoutParams.WRAP_CONTENT;
+ }
+ return false;
+ }
+
+ @Override
+ protected LayoutParams generateDefaultLayoutParams() {
+ LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
+ LayoutParams.WRAP_CONTENT);
+ params.leftMargin = mItemMargin;
+ params.rightMargin = mItemMargin;
+ return params;
+ }
+
+ @Override
+ protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
+ return generateDefaultLayoutParams();
+ }
+
+ public int getItemMargin() {
+ return mItemMargin;
}
public boolean invokeItem(MenuItemImpl item) {
@@ -49,7 +95,7 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
}
public void initialize(MenuBuilder menu, int menuType) {
- menu.setMaxActionItems(MAX_ACTION_ITEMS);
+ menu.setMaxActionItems(mMaxItems);
mMenu = menu;
updateChildren(true);
}
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index d984575..3d31c27 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -439,6 +439,13 @@
<attr name="quickContactBadgeStyleSmallWindowLarge" format="reference" />
<!-- =================== -->
+ <!-- Action bar styles -->
+ <!-- =================== -->
+ <eat-comment />
+ <!-- Default amount of padding to use between action buttons. -->
+ <attr name="actionButtonPadding" format="dimension" />
+
+ <!-- =================== -->
<!-- Preference styles -->
<!-- =================== -->
<eat-comment />
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index 8a92757..656471c 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -25,6 +25,9 @@
<!-- The standard size (both width and height) of an application icon that
will be displayed in the app launcher and elsewhere. -->
<dimen name="app_icon_size">48dip</dimen>
+ <!-- The standard size (both width and height) of an action icon that will
+ be displayed in application action bars. -->
+ <dimen name="action_icon_size">48dip</dimen>
<dimen name="toast_y_offset">64dip</dimen>
<!-- Height of the status bar -->
<dimen name="status_bar_height">25dip</dimen>
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 3dba1a0..3d2db39 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1298,6 +1298,7 @@
<public type="attr" name="actionDropDownStyle" />
<public type="attr" name="actionButtonStyle" />
<public type="attr" name="showAsAction" />
+ <public type="attr" name="actionButtonPadding" />
<public type="id" name="home" />
diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml
index 1f9f136..76bba4b 100644
--- a/core/res/res/values/themes.xml
+++ b/core/res/res/values/themes.xml
@@ -203,6 +203,9 @@
<!-- Search widget styles -->
<item name="searchWidgetCorpusItemBackground">@android:color/search_widget_corpus_item_background</item>
+
+ <!-- Action bar styles -->
+ <item name="actionButtonPadding">12dip</item>
</style>
<!-- Variant of the default (dark) theme with no title bar -->