summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2010-10-29 15:43:05 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-10-29 15:43:05 -0700
commit2308628a2059122f86168f5569274cbcca3ee93b (patch)
tree9e86d08b5b590437ba7111d6562206b026799ccf
parent723aa7088f3822b3b8205f0c9b85516ab88d053f (diff)
parent9ab978713ce86fdaefed2407f4f3c998ab0e3178 (diff)
downloadframeworks_base-2308628a2059122f86168f5569274cbcca3ee93b.zip
frameworks_base-2308628a2059122f86168f5569274cbcca3ee93b.tar.gz
frameworks_base-2308628a2059122f86168f5569274cbcca3ee93b.tar.bz2
Merge "Action bar API updates - new display options"
-rw-r--r--api/current.xml284
-rw-r--r--core/java/android/app/ActionBar.java262
-rw-r--r--core/java/com/android/internal/app/ActionBarImpl.java101
-rw-r--r--core/java/com/android/internal/view/menu/ActionMenuView.java6
-rw-r--r--core/java/com/android/internal/widget/ActionBarContextView.java3
-rw-r--r--core/java/com/android/internal/widget/ActionBarView.java438
-rw-r--r--core/res/res/drawable-hdpi/ic_ab_back_holo_dark.pngbin0 -> 644 bytes
-rw-r--r--core/res/res/drawable-hdpi/ic_ab_back_holo_light.pngbin0 -> 657 bytes
-rw-r--r--core/res/res/drawable-mdpi/ic_ab_back_holo_dark.pngbin0 -> 500 bytes
-rw-r--r--core/res/res/drawable-mdpi/ic_ab_back_holo_light.pngbin0 -> 507 bytes
-rwxr-xr-xcore/res/res/values/attrs.xml25
-rw-r--r--core/res/res/values/public.xml1
-rw-r--r--core/res/res/values/styles.xml4
13 files changed, 898 insertions, 226 deletions
diff --git a/api/current.xml b/api/current.xml
index 4c7df55..5d5f8ac 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -1894,7 +1894,7 @@
type="int"
transient="false"
volatile="false"
- value="16843549"
+ value="16843550"
static="true"
final="true"
deprecated="not deprecated"
@@ -1905,7 +1905,7 @@
type="int"
transient="false"
volatile="false"
- value="16843548"
+ value="16843549"
static="true"
final="true"
deprecated="not deprecated"
@@ -1916,7 +1916,7 @@
type="int"
transient="false"
volatile="false"
- value="16843550"
+ value="16843551"
static="true"
final="true"
deprecated="not deprecated"
@@ -4717,6 +4717,17 @@
visibility="public"
>
</field>
+<field name="homeAsUpIndicator"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843548"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="horizontalDivider"
type="int"
transient="false"
@@ -9286,7 +9297,7 @@
type="int"
transient="false"
volatile="false"
- value="16843552"
+ value="16843553"
static="true"
final="true"
deprecated="not deprecated"
@@ -9297,7 +9308,7 @@
type="int"
transient="false"
volatile="false"
- value="16843551"
+ value="16843552"
static="true"
final="true"
deprecated="not deprecated"
@@ -19449,6 +19460,17 @@
visibility="public"
>
</method>
+<method name="getNavigationItemCount"
+ return="int"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
<method name="getNavigationMode"
return="int"
abstract="true"
@@ -19460,7 +19482,7 @@
visibility="public"
>
</method>
-<method name="getSelectedNavigationItem"
+<method name="getSelectedNavigationIndex"
return="int"
abstract="true"
native="false"
@@ -19471,6 +19493,17 @@
visibility="public"
>
</method>
+<method name="getSelectedNavigationItem"
+ return="int"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="deprecated"
+ visibility="public"
+>
+</method>
<method name="getSelectedTab"
return="android.app.ActionBar.Tab"
abstract="true"
@@ -19493,6 +19526,19 @@
visibility="public"
>
</method>
+<method name="getTabAt"
+ return="android.app.ActionBar.Tab"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="index" type="int">
+</parameter>
+</method>
<method name="getTitle"
return="java.lang.CharSequence"
abstract="true"
@@ -19537,6 +19583,17 @@
visibility="public"
>
</method>
+<method name="removeAllTabs"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
<method name="removeTab"
return="void"
abstract="true"
@@ -19596,11 +19653,39 @@
synchronized="false"
static="false"
final="false"
+ deprecated="deprecated"
+ visibility="public"
+>
+<parameter name="view" type="android.view.View">
+</parameter>
+</method>
+<method name="setCustomView"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="view" type="android.view.View">
+</parameter>
+</method>
+<method name="setCustomView"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="view" type="android.view.View">
</parameter>
+<parameter name="layoutParams" type="android.app.ActionBar.LayoutParams">
+</parameter>
</method>
<method name="setDisplayOptions"
return="void"
@@ -19637,7 +19722,7 @@
synchronized="false"
static="false"
final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
visibility="public"
>
<parameter name="adapter" type="android.widget.SpinnerAdapter">
@@ -19652,7 +19737,7 @@
synchronized="false"
static="false"
final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
visibility="public"
>
<parameter name="adapter" type="android.widget.SpinnerAdapter">
@@ -19662,6 +19747,34 @@
<parameter name="defaultSelectedPosition" type="int">
</parameter>
</method>
+<method name="setListNavigationCallbacks"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="adapter" type="android.widget.SpinnerAdapter">
+</parameter>
+<parameter name="callback" type="android.app.ActionBar.NavigationCallback">
+</parameter>
+</method>
+<method name="setNavigationMode"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="mode" type="int">
+</parameter>
+</method>
<method name="setSelectedNavigationItem"
return="void"
abstract="true"
@@ -19682,7 +19795,7 @@
synchronized="false"
static="false"
final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
visibility="public"
>
</method>
@@ -19719,7 +19832,7 @@
synchronized="false"
static="false"
final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
visibility="public"
>
</method>
@@ -19764,6 +19877,39 @@
type="int"
transient="false"
volatile="false"
+ value="4096"
+ static="true"
+ final="true"
+ deprecated="deprecated"
+ visibility="public"
+>
+</field>
+<field name="DISPLAY_HOME_AS_UP"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="4"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="DISPLAY_SHOW_CUSTOM"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="DISPLAY_SHOW_HOME"
+ type="int"
+ transient="false"
+ volatile="false"
value="2"
static="true"
final="true"
@@ -19771,22 +19917,22 @@
visibility="public"
>
</field>
-<field name="DISPLAY_USE_LOGO"
+<field name="DISPLAY_SHOW_TITLE"
type="int"
transient="false"
volatile="false"
- value="1"
+ value="8"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
-<field name="NAVIGATION_MODE_CUSTOM"
+<field name="DISPLAY_USE_LOGO"
type="int"
transient="false"
volatile="false"
- value="3"
+ value="1"
static="true"
final="true"
deprecated="not deprecated"
@@ -19800,6 +19946,17 @@
value="1"
static="true"
final="true"
+ deprecated="deprecated"
+ visibility="public"
+>
+</field>
+<field name="NAVIGATION_MODE_LIST"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="1"
+ static="true"
+ final="true"
deprecated="not deprecated"
visibility="public"
>
@@ -19827,6 +19984,93 @@
>
</field>
</class>
+<class name="ActionBar.LayoutParams"
+ extends="android.view.ViewGroup.MarginLayoutParams"
+ abstract="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<constructor name="ActionBar.LayoutParams"
+ type="android.app.ActionBar.LayoutParams"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="c" type="android.content.Context">
+</parameter>
+<parameter name="attrs" type="android.util.AttributeSet">
+</parameter>
+</constructor>
+<constructor name="ActionBar.LayoutParams"
+ type="android.app.ActionBar.LayoutParams"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="width" type="int">
+</parameter>
+<parameter name="height" type="int">
+</parameter>
+</constructor>
+<constructor name="ActionBar.LayoutParams"
+ type="android.app.ActionBar.LayoutParams"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="width" type="int">
+</parameter>
+<parameter name="height" type="int">
+</parameter>
+<parameter name="gravity" type="int">
+</parameter>
+</constructor>
+<constructor name="ActionBar.LayoutParams"
+ type="android.app.ActionBar.LayoutParams"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="gravity" type="int">
+</parameter>
+</constructor>
+<constructor name="ActionBar.LayoutParams"
+ type="android.app.ActionBar.LayoutParams"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="source" type="android.app.ActionBar.LayoutParams">
+</parameter>
+</constructor>
+<constructor name="ActionBar.LayoutParams"
+ type="android.app.ActionBar.LayoutParams"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="source" type="android.view.ViewGroup.LayoutParams">
+</parameter>
+</constructor>
+<field name="gravity"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+</class>
<interface name="ActionBar.NavigationCallback"
abstract="true"
static="true"
@@ -19933,7 +20177,7 @@
>
</method>
<method name="setCustomView"
- return="void"
+ return="android.app.ActionBar.Tab"
abstract="true"
native="false"
synchronized="false"
@@ -19946,7 +20190,7 @@
</parameter>
</method>
<method name="setIcon"
- return="void"
+ return="android.app.ActionBar.Tab"
abstract="true"
native="false"
synchronized="false"
@@ -19959,7 +20203,7 @@
</parameter>
</method>
<method name="setTabListener"
- return="void"
+ return="android.app.ActionBar.Tab"
abstract="true"
native="false"
synchronized="false"
@@ -19972,7 +20216,7 @@
</parameter>
</method>
<method name="setTag"
- return="void"
+ return="android.app.ActionBar.Tab"
abstract="true"
native="false"
synchronized="false"
@@ -19985,7 +20229,7 @@
</parameter>
</method>
<method name="setText"
- return="void"
+ return="android.app.ActionBar.Tab"
abstract="true"
native="false"
synchronized="false"
@@ -245127,7 +245371,7 @@
deprecated="not deprecated"
visibility="public"
>
-<parameter name="arg0" type="T">
+<parameter name="t" type="T">
</parameter>
</method>
</interface>
diff --git a/core/java/android/app/ActionBar.java b/core/java/android/app/ActionBar.java
index 7df9295..66038d8 100644
--- a/core/java/android/app/ActionBar.java
+++ b/core/java/android/app/ActionBar.java
@@ -16,8 +16,16 @@
package android.app;
+import android.app.ActionBar.Tab;
+import android.content.Context;
+import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.view.Gravity;
import android.view.View;
+import android.view.ViewDebug;
+import android.view.ViewGroup;
+import android.view.ViewGroup.MarginLayoutParams;
import android.view.Window;
import android.widget.SpinnerAdapter;
@@ -37,9 +45,16 @@ public abstract class ActionBar {
public static final int NAVIGATION_MODE_STANDARD = 0;
/**
- * Dropdown list navigation mode. Instead of static title text this mode
- * presents a dropdown menu for navigation within the activity.
+ * List navigation mode. Instead of static title text this mode
+ * presents a list menu for navigation within the activity.
+ * e.g. this might be presented to the user as a dropdown list.
*/
+ public static final int NAVIGATION_MODE_LIST = 1;
+
+ /**
+ * @deprecated use NAVIGATION_MODE_LIST
+ */
+ @Deprecated
public static final int NAVIGATION_MODE_DROPDOWN_LIST = 1;
/**
@@ -47,24 +62,77 @@ public abstract class ActionBar {
* presents a series of tabs for navigation within the activity.
*/
public static final int NAVIGATION_MODE_TABS = 2;
-
- /**
- * Custom navigation mode. This navigation mode is set implicitly whenever
- * a custom navigation view is set. See {@link #setCustomNavigationMode(View)}.
- */
- public static final int NAVIGATION_MODE_CUSTOM = 3;
/**
* Use logo instead of icon if available. This flag will cause appropriate
* navigation modes to use a wider logo in place of the standard icon.
+ *
+ * @see #setDisplayOptions(int)
+ * @see #setDisplayOptions(int, int)
*/
public static final int DISPLAY_USE_LOGO = 0x1;
/**
- * Hide 'home' elements in this action bar, leaving more space for other
+ * Show 'home' elements in this action bar, leaving more space for other
* navigation elements. This includes logo and icon.
+ *
+ * @see #setDisplayOptions(int)
+ * @see #setDisplayOptions(int, int)
+ */
+ public static final int DISPLAY_SHOW_HOME = 0x2;
+
+ /**
+ * @deprecated Display flags are now positive for consistency - 'show' instead of 'hide'.
+ * Use DISPLAY_SHOW_HOME.
+ */
+ @Deprecated
+ public static final int DISPLAY_HIDE_HOME = 0x1000;
+
+ /**
+ * Display the 'home' element such that it appears as an 'up' affordance.
+ * e.g. show an arrow to the left indicating the action that will be taken.
+ *
+ * Set this flag if selecting the 'home' button in the action bar to return
+ * up by a single level in your UI rather than back to the top level or front page.
+ *
+ * @see #setDisplayOptions(int)
+ * @see #setDisplayOptions(int, int)
+ */
+ public static final int DISPLAY_HOME_AS_UP = 0x4;
+
+ /**
+ * Show the activity title and subtitle, if present.
+ *
+ * @see #setTitle(CharSequence)
+ * @see #setTitle(int)
+ * @see #setSubtitle(CharSequence)
+ * @see #setSubtitle(int)
+ * @see #setDisplayOptions(int)
+ * @see #setDisplayOptions(int, int)
+ */
+ public static final int DISPLAY_SHOW_TITLE = 0x8;
+
+ /**
+ * Show the custom view if one has been set.
+ * @see #setCustomView(View)
+ * @see #setDisplayOptions(int)
+ * @see #setDisplayOptions(int, int)
+ */
+ public static final int DISPLAY_SHOW_CUSTOM = 0x10;
+
+ /**
+ * Set the action bar into custom navigation mode, supplying a view
+ * for custom navigation.
+ *
+ * Custom navigation views appear between the application icon and
+ * any action buttons and may use any space available there. Common
+ * use cases for custom navigation views might include an auto-suggesting
+ * address bar for a browser or other navigation mechanisms that do not
+ * translate well to provided navigation modes.
+ *
+ * @param view Custom navigation view to place in the ActionBar.
*/
- public static final int DISPLAY_HIDE_HOME = 0x2;
+ public abstract void setCustomView(View view);
/**
* Set the action bar into custom navigation mode, supplying a view
@@ -77,7 +145,15 @@ public abstract class ActionBar {
* translate well to provided navigation modes.
*
* @param view Custom navigation view to place in the ActionBar.
+ * @param layoutParams How this custom view should layout in the bar.
*/
+ public abstract void setCustomView(View view, LayoutParams layoutParams);
+
+ /**
+ * @param view
+ * @deprecated Use {@link #setCustomView(View)} and {@link #setDisplayOptions(int)} instead.
+ */
+ @Deprecated
public abstract void setCustomNavigationMode(View view);
/**
@@ -89,11 +165,31 @@ public abstract class ActionBar {
* within the dropdown navigation menu.
* @param callback A NavigationCallback that will receive events when the user
* selects a navigation item.
+ * @deprecated See setListNavigationCallbacks.
*/
+ @Deprecated
public abstract void setDropdownNavigationMode(SpinnerAdapter adapter,
NavigationCallback callback);
/**
+ * Set the adapter and navigation callback for list navigation mode.
+ *
+ * The supplied adapter will provide views for the expanded list as well as
+ * the currently selected item. (These may be displayed differently.)
+ *
+ * The supplied NavigationCallback will alert the application when the user
+ * changes the current list selection.
+ *
+ * @param adapter An adapter that will provide views both to display
+ * the current navigation selection and populate views
+ * within the dropdown navigation menu.
+ * @param callback A NavigationCallback that will receive events when the user
+ * selects a navigation item.
+ */
+ public abstract void setListNavigationCallbacks(SpinnerAdapter adapter,
+ NavigationCallback callback);
+
+ /**
* Set the action bar into dropdown navigation mode and supply an adapter that will
* provide views for navigation choices.
*
@@ -104,31 +200,51 @@ public abstract class ActionBar {
* selects a navigation item.
* @param defaultSelectedPosition Position within the provided adapter that should be
* selected from the outset.
+ * @deprecated See setListNavigationCallbacks and setSelectedNavigationItem.
*/
+ @Deprecated
public abstract void setDropdownNavigationMode(SpinnerAdapter adapter,
NavigationCallback callback, int defaultSelectedPosition);
/**
- * Set the selected navigation item in dropdown or tabbed navigation modes.
+ * Set the selected navigation item in list or tabbed navigation modes.
*
* @param position Position of the item to select.
*/
public abstract void setSelectedNavigationItem(int position);
/**
- * Get the position of the selected navigation item in dropdown or tabbed navigation modes.
+ * Get the position of the selected navigation item in list or tabbed navigation modes.
*
* @return Position of the selected item.
+ * @deprecated Use {@link #getSelectedNavigationIndex()} instead.
*/
+ @Deprecated
public abstract int getSelectedNavigationItem();
/**
+ * Get the position of the selected navigation item in list or tabbed navigation modes.
+ *
+ * @return Position of the selected item.
+ */
+ public abstract int getSelectedNavigationIndex();
+
+ /**
+ * Get the number of navigation items present in the current navigation mode.
+ *
+ * @return Number of navigation items.
+ */
+ public abstract int getNavigationItemCount();
+
+ /**
* Set the action bar into standard navigation mode, using the currently set title
* and/or subtitle.
*
* Standard navigation mode is default. The title is automatically set to the name of
* your Activity on startup if an action bar is present.
+ * @deprecated See setNavigationMode
*/
+ @Deprecated
public abstract void setStandardNavigationMode();
/**
@@ -181,10 +297,10 @@ public abstract class ActionBar {
* Set selected display options. Only the options specified by mask will be changed.
* To change all display option bits at once, see {@link #setDisplayOptions(int)}.
*
- * <p>Example: setDisplayOptions(0, DISPLAY_HIDE_HOME) will disable the
- * {@link #DISPLAY_HIDE_HOME} option.
- * setDisplayOptions(DISPLAY_HIDE_HOME, DISPLAY_HIDE_HOME | DISPLAY_USE_LOGO)
- * will enable {@link #DISPLAY_HIDE_HOME} and disable {@link #DISPLAY_USE_LOGO}.
+ * <p>Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the
+ * {@link #DISPLAY_SHOW_HOME} option.
+ * setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_HIDE_HOME | DISPLAY_USE_LOGO)
+ * will enable {@link #DISPLAY_SHOW_HOME} and disable {@link #DISPLAY_USE_LOGO}.
*
* @param options A combination of the bits defined by the DISPLAY_ constants
* defined in ActionBar.
@@ -226,9 +342,8 @@ public abstract class ActionBar {
* Returns the current navigation mode. The result will be one of:
* <ul>
* <li>{@link #NAVIGATION_MODE_STANDARD}</li>
- * <li>{@link #NAVIGATION_MODE_DROPDOWN_LIST}</li>
+ * <li>{@link #NAVIGATION_MODE_LIST}</li>
* <li>{@link #NAVIGATION_MODE_TABS}</li>
- * <li>{@link #NAVIGATION_MODE_CUSTOM}</li>
* </ul>
*
* @return The current navigation mode.
@@ -241,7 +356,17 @@ public abstract class ActionBar {
* @see #setCustomNavigationMode(View)
*/
public abstract int getNavigationMode();
-
+
+ /**
+ * Set the current navigation mode.
+ *
+ * @param mode The new mode to set.
+ * @see #NAVIGATION_MODE_STANDARD
+ * @see #NAVIGATION_MODE_LIST
+ * @see #NAVIGATION_MODE_TABS
+ */
+ public abstract void setNavigationMode(int mode);
+
/**
* @return The current set of display options.
*/
@@ -254,6 +379,8 @@ public abstract class ActionBar {
* @see #insertTab(Tab, int)
* @see #removeTab(Tab)
* @see #removeTabAt(int)
+ *
+ * @deprecated See {@link #setNavigationMode(int)}
*/
public abstract void setTabNavigationMode();
@@ -285,22 +412,31 @@ public abstract class ActionBar {
public abstract void addTab(Tab tab, int position);
/**
- * Remove a tab from the action bar.
+ * Remove a tab from the action bar. If the removed tab was selected it will be deselected
+ * and another tab will be selected if present.
*
* @param tab The tab to remove
*/
public abstract void removeTab(Tab tab);
/**
- * Remove a tab from the action bar.
+ * Remove a tab from the action bar. If the removed tab was selected it will be deselected
+ * and another tab will be selected if present.
*
* @param position Position of the tab to remove
*/
public abstract void removeTabAt(int position);
/**
+ * Remove all tabs from the action bar and deselect the current tab.
+ */
+ public abstract void removeAllTabs();
+
+ /**
* Select the specified tab. If it is not a child of this action bar it will be added.
*
+ * <p>Note: If you want to select by index, use {@link #setSelectedNavigationItem(int)}.</p>
+ *
* @param tab Tab to select
*/
public abstract void selectTab(Tab tab);
@@ -314,6 +450,14 @@ public abstract class ActionBar {
public abstract Tab getSelectedTab();
/**
+ * Returns the tab at the specified index.
+ *
+ * @param index Index value in the range 0-get
+ * @return
+ */
+ public abstract Tab getTabAt(int index);
+
+ /**
* Retrieve the current height of the ActionBar.
*
* @return The ActionBar's height
@@ -395,24 +539,27 @@ public abstract class ActionBar {
* Set the icon displayed on this tab.
*
* @param icon The drawable to use as an icon
+ * @return The current instance for call chaining
*/
- public abstract void setIcon(Drawable icon);
+ public abstract Tab setIcon(Drawable icon);
/**
* Set the text displayed on this tab. Text may be truncated if there is not
* room to display the entire string.
*
* @param text The text to display
+ * @return The current instance for call chaining
*/
- public abstract void setText(CharSequence text);
+ public abstract Tab setText(CharSequence text);
/**
* Set a custom view to be used for this tab. This overrides values set by
* {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
*
* @param view Custom view to be used as a tab.
+ * @return The current instance for call chaining
*/
- public abstract void setCustomView(View view);
+ public abstract Tab setCustomView(View view);
/**
* Retrieve a previously set custom view for this tab.
@@ -425,8 +572,9 @@ public abstract class ActionBar {
* Give this Tab an arbitrary object to hold for later use.
*
* @param obj Object to store
+ * @return The current instance for call chaining
*/
- public abstract void setTag(Object obj);
+ public abstract Tab setTag(Object obj);
/**
* @return This Tab's tag object.
@@ -438,8 +586,9 @@ public abstract class ActionBar {
* All tabs must have a TabListener set before being added to the ActionBar.
*
* @param listener Listener to handle tab selection events
+ * @return The current instance for call chaining
*/
- public abstract void setTabListener(TabListener listener);
+ public abstract Tab setTabListener(TabListener listener);
/**
* Select this tab. Only valid if the tab has been added to the action bar.
@@ -481,4 +630,65 @@ public abstract class ActionBar {
*/
public void onTabReselected(Tab tab, FragmentTransaction ft);
}
+
+ /**
+ * Per-child layout information associated with action bar custom views.
+ *
+ * @attr ref android.R.styleable#ActionBar_LayoutParams_layout_gravity
+ */
+ public static class LayoutParams extends MarginLayoutParams {
+ /**
+ * Gravity for the view associated with these LayoutParams.
+ *
+ * @see android.view.Gravity
+ */
+ @ViewDebug.ExportedProperty(category = "layout", mapping = {
+ @ViewDebug.IntToString(from = -1, to = "NONE"),
+ @ViewDebug.IntToString(from = Gravity.NO_GRAVITY, to = "NONE"),
+ @ViewDebug.IntToString(from = Gravity.TOP, to = "TOP"),
+ @ViewDebug.IntToString(from = Gravity.BOTTOM, to = "BOTTOM"),
+ @ViewDebug.IntToString(from = Gravity.LEFT, to = "LEFT"),
+ @ViewDebug.IntToString(from = Gravity.RIGHT, to = "RIGHT"),
+ @ViewDebug.IntToString(from = Gravity.CENTER_VERTICAL, to = "CENTER_VERTICAL"),
+ @ViewDebug.IntToString(from = Gravity.FILL_VERTICAL, to = "FILL_VERTICAL"),
+ @ViewDebug.IntToString(from = Gravity.CENTER_HORIZONTAL, to = "CENTER_HORIZONTAL"),
+ @ViewDebug.IntToString(from = Gravity.FILL_HORIZONTAL, to = "FILL_HORIZONTAL"),
+ @ViewDebug.IntToString(from = Gravity.CENTER, to = "CENTER"),
+ @ViewDebug.IntToString(from = Gravity.FILL, to = "FILL")
+ })
+ public int gravity = -1;
+
+ public LayoutParams(Context c, AttributeSet attrs) {
+ super(c, attrs);
+
+ TypedArray a = c.obtainStyledAttributes(attrs,
+ com.android.internal.R.styleable.ActionBar_LayoutParams);
+ gravity = a.getInt(
+ com.android.internal.R.styleable.ActionBar_LayoutParams_layout_gravity, -1);
+ }
+
+ public LayoutParams(int width, int height) {
+ super(width, height);
+ this.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
+ }
+
+ public LayoutParams(int width, int height, int gravity) {
+ super(width, height);
+ this.gravity = gravity;
+ }
+
+ public LayoutParams(int gravity) {
+ this(WRAP_CONTENT, MATCH_PARENT, gravity);
+ }
+
+ public LayoutParams(LayoutParams source) {
+ super(source);
+
+ this.gravity = source.gravity;
+ }
+
+ public LayoutParams(ViewGroup.LayoutParams source) {
+ super(source);
+ }
+ }
}
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index 3015363..f4a041c 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -52,9 +52,6 @@ import java.util.ArrayList;
public class ActionBarImpl extends ActionBar {
private static final int NORMAL_VIEW = 0;
private static final int CONTEXT_VIEW = 1;
-
- private static final int TAB_SWITCH_SHOW_HIDE = 0;
- private static final int TAB_SWITCH_ADD_REMOVE = 1;
private Context mContext;
private Activity mActivity;
@@ -67,9 +64,7 @@ public class ActionBarImpl extends ActionBar {
private ArrayList<TabImpl> mTabs = new ArrayList<TabImpl>();
- private int mTabContainerViewId = android.R.id.content;
private TabImpl mSelectedTab;
- private int mTabSwitchMode = TAB_SWITCH_ADD_REMOVE;
private ActionMode mActionMode;
@@ -133,7 +128,9 @@ public class ActionBarImpl extends ActionBar {
public void setCustomNavigationMode(View view) {
cleanupTabs();
- mActionView.setCustomNavigationView(view);
+ setCustomView(view);
+ setDisplayOptions(DISPLAY_SHOW_CUSTOM, DISPLAY_SHOW_CUSTOM | DISPLAY_SHOW_TITLE);
+ mActionView.setNavigationMode(NAVIGATION_MODE_STANDARD);
mActionView.setCallback(null);
}
@@ -144,16 +141,17 @@ public class ActionBarImpl extends ActionBar {
public void setDropdownNavigationMode(SpinnerAdapter adapter, NavigationCallback callback,
int defaultSelectedPosition) {
cleanupTabs();
- mActionView.setNavigationMode(NAVIGATION_MODE_DROPDOWN_LIST);
- mActionView.setDropdownAdapter(adapter);
+ setDisplayOptions(0, DISPLAY_SHOW_CUSTOM | DISPLAY_SHOW_TITLE);
+ mActionView.setNavigationMode(NAVIGATION_MODE_LIST);
+ setListNavigationCallbacks(adapter, callback);
if (defaultSelectedPosition >= 0) {
mActionView.setDropdownSelectedPosition(defaultSelectedPosition);
}
- mActionView.setCallback(callback);
}
public void setStandardNavigationMode() {
cleanupTabs();
+ setDisplayOptions(DISPLAY_SHOW_TITLE, DISPLAY_SHOW_TITLE | DISPLAY_SHOW_CUSTOM);
mActionView.setNavigationMode(NAVIGATION_MODE_STANDARD);
mActionView.setCallback(null);
}
@@ -163,24 +161,21 @@ public class ActionBarImpl extends ActionBar {
case NAVIGATION_MODE_TABS:
selectTab(mTabs.get(position));
break;
- case NAVIGATION_MODE_DROPDOWN_LIST:
+ case NAVIGATION_MODE_LIST:
mActionView.setDropdownSelectedPosition(position);
break;
default:
throw new IllegalStateException(
- "setSelectedNavigationItem not valid for current navigation mode");
+ "setSelectedNavigationIndex not valid for current navigation mode");
}
}
public int getSelectedNavigationItem() {
- switch (mActionView.getNavigationMode()) {
- case NAVIGATION_MODE_TABS:
- return mSelectedTab.getPosition();
- case NAVIGATION_MODE_DROPDOWN_LIST:
- return mActionView.getDropdownSelectedPosition();
- default:
- return -1;
- }
+ return getSelectedNavigationIndex();
+ }
+
+ public void removeAllTabs() {
+ cleanupTabs();
}
private void cleanupTabs() {
@@ -321,6 +316,7 @@ public class ActionBarImpl extends ActionBar {
throw new IllegalStateException(
"Tab navigation mode cannot be used outside of an Activity");
}
+ setDisplayOptions(0, DISPLAY_SHOW_TITLE | DISPLAY_SHOW_CUSTOM);
mActionView.setNavigationMode(NAVIGATION_MODE_TABS);
}
@@ -510,8 +506,9 @@ public class ActionBarImpl extends ActionBar {
}
@Override
- public void setTag(Object tag) {
+ public Tab setTag(Object tag) {
mTag = tag;
+ return this;
}
public ActionBar.TabListener getCallback() {
@@ -519,8 +516,9 @@ public class ActionBarImpl extends ActionBar {
}
@Override
- public void setTabListener(ActionBar.TabListener callback) {
+ public Tab setTabListener(ActionBar.TabListener callback) {
mCallback = callback;
+ return this;
}
@Override
@@ -529,8 +527,9 @@ public class ActionBarImpl extends ActionBar {
}
@Override
- public void setCustomView(View view) {
+ public Tab setCustomView(View view) {
mCustomView = view;
+ return this;
}
@Override
@@ -553,13 +552,15 @@ public class ActionBarImpl extends ActionBar {
}
@Override
- public void setIcon(Drawable icon) {
+ public Tab setIcon(Drawable icon) {
mIcon = icon;
+ return this;
}
@Override
- public void setText(CharSequence text) {
+ public Tab setText(CharSequence text) {
mText = text;
+ return this;
}
@Override
@@ -567,4 +568,56 @@ public class ActionBarImpl extends ActionBar {
selectTab(this);
}
}
+
+ @Override
+ public void setCustomView(View view) {
+ mActionView.setCustomNavigationView(view);
+ }
+
+ @Override
+ public void setCustomView(View view, LayoutParams layoutParams) {
+ view.setLayoutParams(layoutParams);
+ mActionView.setCustomNavigationView(view);
+ }
+
+ @Override
+ public void setListNavigationCallbacks(SpinnerAdapter adapter, NavigationCallback callback) {
+ mActionView.setDropdownAdapter(adapter);
+ mActionView.setCallback(callback);
+ }
+
+ @Override
+ public int getSelectedNavigationIndex() {
+ switch (mActionView.getNavigationMode()) {
+ case NAVIGATION_MODE_TABS:
+ return mSelectedTab.getPosition();
+ case NAVIGATION_MODE_LIST:
+ return mActionView.getDropdownSelectedPosition();
+ default:
+ return -1;
+ }
+ }
+
+ @Override
+ public int getNavigationItemCount() {
+ switch (mActionView.getNavigationMode()) {
+ case NAVIGATION_MODE_TABS:
+ return mTabs.size();
+ case NAVIGATION_MODE_LIST:
+ SpinnerAdapter adapter = mActionView.getDropdownAdapter();
+ return adapter != null ? adapter.getCount() : 0;
+ default:
+ return 0;
+ }
+ }
+
+ @Override
+ public void setNavigationMode(int mode) {
+ mActionView.setNavigationMode(mode);
+ }
+
+ @Override
+ public Tab getTabAt(int index) {
+ return mTabs.get(index);
+ }
}
diff --git a/core/java/com/android/internal/view/menu/ActionMenuView.java b/core/java/com/android/internal/view/menu/ActionMenuView.java
index 2888074..621defe 100644
--- a/core/java/com/android/internal/view/menu/ActionMenuView.java
+++ b/core/java/com/android/internal/view/menu/ActionMenuView.java
@@ -24,10 +24,10 @@ import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewParent;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
-import android.widget.LinearLayout.LayoutParams;
import java.util.ArrayList;
@@ -169,6 +169,10 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
final MenuItemImpl itemData = itemsToShow.get(i);
final View actionView = itemData.getActionView();
if (actionView != null) {
+ final ViewParent parent = actionView.getParent();
+ if (parent instanceof ViewGroup) {
+ ((ViewGroup) parent).removeView(actionView);
+ }
addView(actionView, makeActionViewLayoutParams());
} else {
needsDivider = addItemView(i == 0 || !needsDivider,
diff --git a/core/java/com/android/internal/widget/ActionBarContextView.java b/core/java/com/android/internal/widget/ActionBarContextView.java
index 38f76d3..e93c414 100644
--- a/core/java/com/android/internal/widget/ActionBarContextView.java
+++ b/core/java/com/android/internal/widget/ActionBarContextView.java
@@ -26,9 +26,6 @@ import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.Button;
-import android.widget.ButtonGroup;
-import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index 4c3bba1..be96e48 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -26,20 +26,21 @@ import android.app.ActionBar.NavigationCallback;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ApplicationInfo;
+import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.TypedArray;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.text.TextUtils.TruncateAt;
import android.util.AttributeSet;
-import android.util.DisplayMetrics;
+import android.util.Log;
import android.view.ActionMode;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewParent;
import android.widget.AdapterView;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
@@ -63,19 +64,27 @@ public class ActionBarView extends ViewGroup {
* Display options that require re-layout as opposed to a simple invalidate
*/
private static final int DISPLAY_RELAYOUT_MASK =
- ActionBar.DISPLAY_HIDE_HOME |
- ActionBar.DISPLAY_USE_LOGO;
+ ActionBar.DISPLAY_SHOW_HOME |
+ ActionBar.DISPLAY_USE_LOGO |
+ ActionBar.DISPLAY_HOME_AS_UP |
+ ActionBar.DISPLAY_SHOW_CUSTOM |
+ ActionBar.DISPLAY_SHOW_TITLE;
+
+ private static final int DEFAULT_CUSTOM_GRAVITY = Gravity.LEFT | Gravity.CENTER_VERTICAL;
private final int mContentHeight;
private int mNavigationMode;
- private int mDisplayOptions;
+ private int mDisplayOptions = ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP;
private CharSequence mTitle;
private CharSequence mSubtitle;
private Drawable mIcon;
private Drawable mLogo;
private Drawable mDivider;
+ private Drawable mHomeAsUpIndicator;
+ private LinearLayout mHomeLayout;
+ private ImageView mHomeAsUpView;
private ImageView mIconView;
private ImageView mLogoView;
private LinearLayout mTitleLayout;
@@ -98,7 +107,8 @@ public class ActionBarView extends ViewGroup {
private ActionBarContextView mContextView;
private ActionMenuItem mLogoNavItem;
-
+
+ private SpinnerAdapter mSpinnerAdapter;
private NavigationCallback mCallback;
private final AdapterView.OnItemSelectedListener mNavItemSelectedListener =
@@ -122,30 +132,56 @@ public class ActionBarView extends ViewGroup {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar);
- final int colorFilter = a.getColor(R.styleable.ActionBar_colorFilter, 0);
-
- if (colorFilter != 0) {
- final Drawable d = getBackground();
- d.setDither(true);
- d.setColorFilter(new PorterDuffColorFilter(colorFilter, PorterDuff.Mode.OVERLAY));
- }
-
- ApplicationInfo info = context.getApplicationInfo();
+ ApplicationInfo appInfo = context.getApplicationInfo();
PackageManager pm = context.getPackageManager();
mNavigationMode = a.getInt(R.styleable.ActionBar_navigationMode,
ActionBar.NAVIGATION_MODE_STANDARD);
mTitle = a.getText(R.styleable.ActionBar_title);
mSubtitle = a.getText(R.styleable.ActionBar_subtitle);
- mDisplayOptions = a.getInt(R.styleable.ActionBar_displayOptions, DISPLAY_DEFAULT);
mLogo = a.getDrawable(R.styleable.ActionBar_logo);
if (mLogo == null) {
- mLogo = info.loadLogo(pm);
+ if (context instanceof Activity) {
+ try {
+ mLogo = pm.getActivityLogo(((Activity) context).getComponentName());
+ } catch (NameNotFoundException e) {
+ Log.e(TAG, "Activity component name not found!", e);
+ }
+ }
+ if (mLogo == null) {
+ mLogo = appInfo.loadLogo(pm);
+ }
}
+
mIcon = a.getDrawable(R.styleable.ActionBar_icon);
if (mIcon == null) {
- mIcon = info.loadIcon(pm);
+ if (context instanceof Activity) {
+ try {
+ mIcon = pm.getActivityIcon(((Activity) context).getComponentName());
+ } catch (NameNotFoundException e) {
+ Log.e(TAG, "Activity component name not found!", e);
+ }
+ }
+ if (mIcon == null) {
+ mIcon = appInfo.loadIcon(pm);
+ }
}
+
+ mHomeLayout = new LinearLayout(context, null,
+ com.android.internal.R.attr.actionButtonStyle);
+ mHomeLayout.setClickable(true);
+ mHomeLayout.setFocusable(true);
+ mHomeLayout.setOnClickListener(mHomeClickListener);
+ mHomeLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
+ LayoutParams.MATCH_PARENT));
+
+ mHomeAsUpIndicator = a.getDrawable(R.styleable.ActionBar_homeAsUpIndicator);
+
+ mHomeAsUpView = new ImageView(context);
+ mHomeAsUpView.setImageDrawable(mHomeAsUpIndicator);
+ mHomeAsUpView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
+ LayoutParams.MATCH_PARENT));
+ mHomeLayout.addView(mHomeAsUpView);
Drawable background = a.getDrawable(R.styleable.ActionBar_background);
if (background != null) {
@@ -155,11 +191,14 @@ public class ActionBarView extends ViewGroup {
mTitleStyleRes = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
mSubtitleStyleRes = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);
+ setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, DISPLAY_DEFAULT));
+
final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
if (customNavId != 0) {
LayoutInflater inflater = LayoutInflater.from(context);
mCustomNavView = (View) inflater.inflate(customNavId, null);
- mNavigationMode = ActionBar.NAVIGATION_MODE_CUSTOM;
+ mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD;
+ setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM);
}
mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
@@ -241,9 +280,13 @@ public class ActionBarView extends ViewGroup {
}
public void setCustomNavigationView(View view) {
+ final boolean showCustom = (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0;
+ if (mCustomNavView != null && showCustom) {
+ removeView(mCustomNavView);
+ }
mCustomNavView = view;
- if (view != null) {
- setNavigationMode(ActionBar.NAVIGATION_MODE_CUSTOM);
+ if (mCustomNavView != null && showCustom) {
+ addView(mCustomNavView);
}
}
@@ -296,15 +339,43 @@ public class ActionBarView extends ViewGroup {
}
public void setDisplayOptions(int options) {
+ // TODO Remove this once DISPLAY_HIDE_HOME is removed
+ if ((options & ActionBar.DISPLAY_HIDE_HOME) != 0) {
+ options &= ~(ActionBar.DISPLAY_HIDE_HOME | ActionBar.DISPLAY_SHOW_HOME);
+ }
+ // End TODO
+
final int flagsChanged = options ^ mDisplayOptions;
mDisplayOptions = options;
if ((flagsChanged & DISPLAY_RELAYOUT_MASK) != 0) {
- final int vis = (options & ActionBar.DISPLAY_HIDE_HOME) != 0 ? GONE : VISIBLE;
- if (mLogoView != null) {
- mLogoView.setVisibility(vis);
+ final int vis = (options & ActionBar.DISPLAY_SHOW_HOME) != 0 ? VISIBLE : GONE;
+ mHomeLayout.setVisibility(vis);
+
+ if ((flagsChanged & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
+ mHomeAsUpView.setVisibility((options & ActionBar.DISPLAY_HOME_AS_UP) != 0
+ ? VISIBLE : GONE);
}
- if (mIconView != null) {
- mIconView.setVisibility(vis);
+
+ if (mLogoView != null && (flagsChanged & ActionBar.DISPLAY_USE_LOGO) != 0) {
+ final boolean logoVis = (options & ActionBar.DISPLAY_USE_LOGO) != 0;
+ mLogoView.setVisibility(logoVis ? VISIBLE : GONE);
+ mIconView.setVisibility(logoVis ? GONE : VISIBLE);
+ }
+
+ if ((flagsChanged & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
+ if ((options & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
+ initTitle();
+ } else {
+ removeView(mTitleLayout);
+ }
+ }
+
+ if ((flagsChanged & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
+ if ((options & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
+ addView(mCustomNavView);
+ } else {
+ removeView(mCustomNavView);
+ }
}
requestLayout();
@@ -317,52 +388,27 @@ public class ActionBarView extends ViewGroup {
final int oldMode = mNavigationMode;
if (mode != oldMode) {
switch (oldMode) {
- case ActionBar.NAVIGATION_MODE_STANDARD:
- if (mTitleLayout != null) {
- removeView(mTitleLayout);
- mTitleLayout = null;
- mTitleView = null;
- mSubtitleView = null;
- }
- break;
- case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
+ case ActionBar.NAVIGATION_MODE_LIST:
if (mSpinner != null) {
removeView(mSpinner);
- mSpinner = null;
- }
- break;
- case ActionBar.NAVIGATION_MODE_CUSTOM:
- if (mCustomNavView != null) {
- removeView(mCustomNavView);
- mCustomNavView = null;
}
break;
case ActionBar.NAVIGATION_MODE_TABS:
if (mTabLayout != null) {
removeView(mTabScrollView);
- mTabLayout = null;
- mTabScrollView = null;
}
}
switch (mode) {
- case ActionBar.NAVIGATION_MODE_STANDARD:
- initTitle();
- break;
- case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
+ case ActionBar.NAVIGATION_MODE_LIST:
mSpinner = new Spinner(mContext, null,
com.android.internal.R.attr.actionDropDownStyle);
+ mSpinner.setAdapter(mSpinnerAdapter);
mSpinner.setOnItemSelectedListener(mNavItemSelectedListener);
addView(mSpinner);
break;
- case ActionBar.NAVIGATION_MODE_CUSTOM:
- addView(mCustomNavView);
- break;
case ActionBar.NAVIGATION_MODE_TABS:
- mTabScrollView = new HorizontalScrollView(getContext());
- mTabLayout = new LinearLayout(getContext(), null,
- com.android.internal.R.attr.actionBarTabBarStyle);
- mTabScrollView.addView(mTabLayout);
+ ensureTabsExist();
addView(mTabScrollView);
break;
}
@@ -371,8 +417,24 @@ public class ActionBarView extends ViewGroup {
}
}
+ private void ensureTabsExist() {
+ if (mTabScrollView == null) {
+ mTabScrollView = new HorizontalScrollView(getContext());
+ mTabLayout = new LinearLayout(getContext(), null,
+ com.android.internal.R.attr.actionBarTabBarStyle);
+ mTabScrollView.addView(mTabLayout);
+ }
+ }
+
public void setDropdownAdapter(SpinnerAdapter adapter) {
- mSpinner.setAdapter(adapter);
+ mSpinnerAdapter = adapter;
+ if (mSpinner != null) {
+ mSpinner.setAdapter(adapter);
+ }
+ }
+
+ public SpinnerAdapter getDropdownAdapter() {
+ return mSpinnerAdapter;
}
public void setDropdownSelectedPosition(int position) {
@@ -407,6 +469,7 @@ public class ActionBarView extends ViewGroup {
}
public void addTab(ActionBar.Tab tab) {
+ ensureTabsExist();
final boolean isFirst = mTabLayout.getChildCount() == 0;
View tabView = createTabView(tab);
mTabLayout.addView(tabView);
@@ -416,6 +479,7 @@ public class ActionBarView extends ViewGroup {
}
public void addTab(ActionBar.Tab tab, int position) {
+ ensureTabsExist();
final boolean isFirst = mTabLayout.getChildCount() == 0;
final TabView tabView = createTabView(tab);
mTabLayout.addView(tabView, position);
@@ -425,46 +489,50 @@ public class ActionBarView extends ViewGroup {
}
public void removeTabAt(int position) {
- mTabLayout.removeViewAt(position);
+ if (mTabLayout != null) {
+ mTabLayout.removeViewAt(position);
+ }
}
@Override
protected LayoutParams generateDefaultLayoutParams() {
// Used by custom nav views if they don't supply layout params. Everything else
// added to an ActionBarView should have them already.
- return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
+ return new ActionBar.LayoutParams(DEFAULT_CUSTOM_GRAVITY);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
- if ((mDisplayOptions & ActionBar.DISPLAY_HIDE_HOME) == 0) {
- if (mLogo != null && (mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) != 0) {
- mLogoView = new ImageView(getContext(), null,
- com.android.internal.R.attr.actionButtonStyle);
- mLogoView.setAdjustViewBounds(true);
- mLogoView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
- LayoutParams.MATCH_PARENT));
- mLogoView.setImageDrawable(mLogo);
- mLogoView.setClickable(true);
- mLogoView.setFocusable(true);
- mLogoView.setOnClickListener(mHomeClickListener);
- addView(mLogoView);
- } else if (mIcon != null) {
- mIconView = new ImageView(getContext(), null,
- com.android.internal.R.attr.actionButtonStyle);
- mIconView.setAdjustViewBounds(true);
- mIconView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
- LayoutParams.MATCH_PARENT));
- mIconView.setImageDrawable(mIcon);
- mIconView.setClickable(true);
- mIconView.setFocusable(true);
- mIconView.setOnClickListener(mHomeClickListener);
- addView(mIconView);
- }
+ final Context context = getContext();
+
+ if (mLogo != null) {
+ mLogoView = new ImageView(context);
+ mLogoView.setScaleType(ImageView.ScaleType.CENTER);
+ mLogoView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
+ LayoutParams.MATCH_PARENT));
+ mLogoView.setImageDrawable(mLogo);
+ mLogoView.setVisibility((mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) != 0
+ ? VISIBLE : GONE);
+ mHomeLayout.addView(mLogoView);
}
+ if (mIcon != null) {
+ mIconView = new ImageView(context, null,
+ com.android.internal.R.attr.actionButtonStyle);
+ mIconView.setScaleType(ImageView.ScaleType.CENTER);
+ mIconView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
+ LayoutParams.MATCH_PARENT));
+ mIconView.setImageDrawable(mIcon);
+ mIconView.setVisibility(
+ (mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) == 0 || mLogo == null
+ ? VISIBLE : GONE);
+ mHomeLayout.addView(mIconView);
+ }
+
+ addView(mHomeLayout);
+
switch (mNavigationMode) {
case ActionBar.NAVIGATION_MODE_STANDARD:
if (mLogoView == null) {
@@ -472,19 +540,23 @@ public class ActionBarView extends ViewGroup {
}
break;
- case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
+ case ActionBar.NAVIGATION_MODE_LIST:
throw new UnsupportedOperationException(
- "Inflating dropdown list navigation isn't supported yet!");
+ "Inflating list navigation isn't supported yet!");
case ActionBar.NAVIGATION_MODE_TABS:
throw new UnsupportedOperationException(
"Inflating tab navigation isn't supported yet!");
-
- case ActionBar.NAVIGATION_MODE_CUSTOM:
- if (mCustomNavView != null) {
+ }
+
+ if (mCustomNavView != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
+ final ViewParent parent = mCustomNavView.getParent();
+ if (parent != this) {
+ if (parent instanceof ViewGroup) {
+ ((ViewGroup) parent).removeView(mCustomNavView);
+ }
addView(mCustomNavView);
}
- break;
}
}
@@ -513,6 +585,7 @@ public class ActionBarView extends ViewGroup {
}
public void setTabSelected(int position) {
+ ensureTabsExist();
final int tabCount = mTabLayout.getChildCount();
for (int i = 0; i < tabCount; i++) {
final View child = mTabLayout.getChildAt(i);
@@ -544,57 +617,40 @@ public class ActionBarView extends ViewGroup {
mContentHeight : MeasureSpec.getSize(heightMeasureSpec);
final int verticalPadding = getPaddingTop() + getPaddingBottom();
- int availableWidth = contentWidth - getPaddingLeft() - getPaddingRight();
+ final int paddingLeft = getPaddingLeft();
+ final int paddingRight = getPaddingRight();
final int height = maxHeight - verticalPadding;
final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
- if (mLogoView != null && mLogoView.getVisibility() != GONE) {
- availableWidth = measureChildView(mLogoView, availableWidth, childSpecHeight, 0);
- }
- if (mIconView != null && mIconView.getVisibility() != GONE) {
- availableWidth = measureChildView(mIconView, availableWidth, childSpecHeight, 0);
+ int availableWidth = contentWidth - paddingLeft - paddingRight;
+ int leftOfCenter = availableWidth / 2;
+ int rightOfCenter = leftOfCenter;
+
+ if (mHomeLayout.getVisibility() != GONE) {
+ availableWidth = measureChildView(mHomeLayout, availableWidth, childSpecHeight, 0);
+ leftOfCenter -= mHomeLayout.getMeasuredWidth();
}
if (mMenuView != null) {
availableWidth = measureChildView(mMenuView, availableWidth,
childSpecHeight, 0);
+ rightOfCenter -= mMenuView.getMeasuredWidth();
}
-
+
+ if (mTitleLayout != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
+ availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0);
+ leftOfCenter -= mTitleLayout.getMeasuredWidth();
+ }
+
switch (mNavigationMode) {
- case ActionBar.NAVIGATION_MODE_STANDARD:
- if (mTitleLayout != null) {
- measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0);
- }
- break;
- case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
+ case ActionBar.NAVIGATION_MODE_LIST:
if (mSpinner != null) {
mSpinner.measure(
MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
- }
- break;
- case ActionBar.NAVIGATION_MODE_CUSTOM:
- if (mCustomNavView != null) {
- LayoutParams lp = mCustomNavView.getLayoutParams();
- final int customNavWidthMode = lp.width != LayoutParams.WRAP_CONTENT ?
- MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
- final int customNavWidth = lp.width >= 0 ?
- Math.min(lp.width, availableWidth) : availableWidth;
-
- // If the action bar is wrapping to its content height, don't allow a custom
- // view to MATCH_PARENT.
- int customNavHeightMode;
- if (mContentHeight <= 0) {
- customNavHeightMode = MeasureSpec.AT_MOST;
- } else {
- customNavHeightMode = lp.height != LayoutParams.WRAP_CONTENT ?
- MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
- }
- final int customNavHeight = lp.height >= 0 ?
- Math.min(lp.height, height) : height;
- mCustomNavView.measure(
- MeasureSpec.makeMeasureSpec(customNavWidth, customNavWidthMode),
- MeasureSpec.makeMeasureSpec(customNavHeight, customNavHeightMode));
+ final int spinnerWidth = mSpinner.getMeasuredWidth();
+ availableWidth -= spinnerWidth;
+ leftOfCenter -= spinnerWidth;
}
break;
case ActionBar.NAVIGATION_MODE_TABS:
@@ -602,10 +658,56 @@ public class ActionBarView extends ViewGroup {
mTabScrollView.measure(
MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
+ final int tabWidth = mTabScrollView.getMeasuredWidth();
+ availableWidth -= tabWidth;
+ leftOfCenter -= tabWidth;
}
break;
}
+ if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
+ final LayoutParams lp = generateLayoutParams(mCustomNavView.getLayoutParams());
+ final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ?
+ (ActionBar.LayoutParams) lp : null;
+
+ int horizontalMargin = 0;
+ int verticalMargin = 0;
+ if (ablp != null) {
+ horizontalMargin = ablp.leftMargin + ablp.rightMargin;
+ verticalMargin = ablp.topMargin + ablp.bottomMargin;
+ }
+
+ // If the action bar is wrapping to its content height, don't allow a custom
+ // view to MATCH_PARENT.
+ int customNavHeightMode;
+ if (mContentHeight <= 0) {
+ customNavHeightMode = MeasureSpec.AT_MOST;
+ } else {
+ customNavHeightMode = lp.height != LayoutParams.WRAP_CONTENT ?
+ MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
+ }
+ final int customNavHeight = Math.max(0,
+ (lp.height >= 0 ? Math.min(lp.height, height) : height) - verticalMargin);
+
+ final int customNavWidthMode = lp.width != LayoutParams.WRAP_CONTENT ?
+ MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
+ int customNavWidth = Math.max(0,
+ (lp.width >= 0 ? Math.min(lp.width, availableWidth) : availableWidth)
+ - horizontalMargin);
+ final int hgrav = (ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY) &
+ Gravity.HORIZONTAL_GRAVITY_MASK;
+
+ // Centering a custom view is treated specially; we try to center within the whole
+ // action bar rather than in the available space.
+ if (hgrav == Gravity.CENTER_HORIZONTAL && lp.width == LayoutParams.MATCH_PARENT) {
+ customNavWidth = Math.min(leftOfCenter, rightOfCenter) * 2;
+ }
+
+ mCustomNavView.measure(
+ MeasureSpec.makeMeasureSpec(customNavWidth, customNavWidthMode),
+ MeasureSpec.makeMeasureSpec(customNavHeight, customNavHeightMode));
+ }
+
if (mContentHeight <= 0) {
int measuredHeight = 0;
final int count = getChildCount();
@@ -642,39 +744,89 @@ public class ActionBarView extends ViewGroup {
final int y = getPaddingTop();
final int contentHeight = b - t - getPaddingTop() - getPaddingBottom();
- if (mLogoView != null && mLogoView.getVisibility() != GONE) {
- x += positionChild(mLogoView, x, y, contentHeight);
- }
- if (mIconView != null && mIconView.getVisibility() != GONE) {
- x += positionChild(mIconView, x, y, contentHeight);
+ if (mHomeLayout.getVisibility() != GONE) {
+ x += positionChild(mHomeLayout, x, y, contentHeight);
}
+ if (mTitleLayout != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
+ x += positionChild(mTitleLayout, x, y, contentHeight);
+ }
+
switch (mNavigationMode) {
case ActionBar.NAVIGATION_MODE_STANDARD:
- if (mTitleLayout != null) {
- x += positionChild(mTitleLayout, x, y, contentHeight);
- }
break;
- case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
+ case ActionBar.NAVIGATION_MODE_LIST:
if (mSpinner != null) {
x += positionChild(mSpinner, x, y, contentHeight);
}
break;
- case ActionBar.NAVIGATION_MODE_CUSTOM:
- if (mCustomNavView != null) {
- x += positionChild(mCustomNavView, x, y, contentHeight);
- }
- break;
case ActionBar.NAVIGATION_MODE_TABS:
if (mTabScrollView != null) {
x += positionChild(mTabScrollView, x, y, contentHeight);
}
}
- x = r - l - getPaddingRight();
-
+ int menuLeft = r - l - getPaddingRight();
if (mMenuView != null) {
- x -= positionChildInverse(mMenuView, x, y, contentHeight);
+ positionChildInverse(mMenuView, menuLeft, y, contentHeight);
+ menuLeft -= mMenuView.getMeasuredWidth();
+ }
+
+ if (mCustomNavView != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
+ LayoutParams lp = mCustomNavView.getLayoutParams();
+ final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ?
+ (ActionBar.LayoutParams) lp : null;
+
+ final int gravity = ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY;
+ final int navWidth = mCustomNavView.getMeasuredWidth();
+
+ int topMargin = 0;
+ int bottomMargin = 0;
+ if (ablp != null) {
+ x += ablp.leftMargin;
+ menuLeft -= ablp.rightMargin;
+ topMargin = ablp.topMargin;
+ bottomMargin = ablp.bottomMargin;
+ }
+
+ int hgravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
+ // See if we actually have room to truly center; if not push against left or right.
+ if (hgravity == Gravity.CENTER_HORIZONTAL) {
+ final int centeredLeft = ((mRight - mLeft) - navWidth) / 2;
+ if (centeredLeft < x) {
+ hgravity = Gravity.LEFT;
+ } else if (centeredLeft + navWidth > menuLeft) {
+ hgravity = Gravity.RIGHT;
+ }
+ }
+
+ int xpos = 0;
+ switch (hgravity) {
+ case Gravity.CENTER_HORIZONTAL:
+ xpos = ((mRight - mLeft) - navWidth) / 2;
+ break;
+ case Gravity.LEFT:
+ xpos = x;
+ break;
+ case Gravity.RIGHT:
+ xpos = menuLeft - navWidth;
+ break;
+ }
+
+ int ypos = 0;
+ switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
+ case Gravity.CENTER_VERTICAL:
+ ypos = ((mBottom - mTop) - mCustomNavView.getMeasuredHeight()) / 2;
+ break;
+ case Gravity.TOP:
+ ypos = getPaddingTop() + topMargin;
+ break;
+ case Gravity.BOTTOM:
+ ypos = getHeight() - getPaddingBottom() - mCustomNavView.getMeasuredHeight()
+ - bottomMargin;
+ break;
+ }
+ x += positionChild(mCustomNavView, xpos, ypos, contentHeight);
}
}
diff --git a/core/res/res/drawable-hdpi/ic_ab_back_holo_dark.png b/core/res/res/drawable-hdpi/ic_ab_back_holo_dark.png
new file mode 100644
index 0000000..a8da981
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_ab_back_holo_dark.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_ab_back_holo_light.png b/core/res/res/drawable-hdpi/ic_ab_back_holo_light.png
new file mode 100644
index 0000000..af0f308
--- /dev/null
+++ b/core/res/res/drawable-hdpi/ic_ab_back_holo_light.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_ab_back_holo_dark.png b/core/res/res/drawable-mdpi/ic_ab_back_holo_dark.png
new file mode 100644
index 0000000..7aae741
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_ab_back_holo_dark.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_ab_back_holo_light.png b/core/res/res/drawable-mdpi/ic_ab_back_holo_light.png
new file mode 100644
index 0000000..66ef51c
--- /dev/null
+++ b/core/res/res/drawable-mdpi/ic_ab_back_holo_light.png
Binary files differ
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index f0d5fd8..0cac7eb 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -4240,18 +4240,21 @@
<attr name="navigationMode">
<!-- Normal static title text -->
<enum name="normal" value="0" />
- <!-- The action bar will use a drop-down selection in place of title text. -->
- <enum name="dropdownList" value="1" />
- <!-- The action bar will use a series of horizontal tabs in place of title text. -->
- <enum name="tabBar" value="2" />
+ <!-- The action bar will use a selection list for navigation. -->
+ <enum name="listMode" value="1" />
+ <!-- The action bar will use a series of horizontal tabs for navigation. -->
+ <enum name="tabMode" value="2" />
</attr>
<!-- Options affecting how the action bar is displayed. -->
<attr name="displayOptions">
- <flag name="useLogo" value="1" />
- <flag name="hideHome" value="2" />
+ <flag name="useLogo" value="0x1" />
+ <flag name="showHome" value="0x2" />
+ <flag name="homeAsUp" value="0x4" />
+ <flag name="showTitle" value="0x8" />
+ <flag name="showCustom" value="0x10" />
+ <!-- DEPRECATED - Remove this later!! -->
+ <flag name="hideHome" value="0x1000" />
</attr>
- <!-- Specifies the color used to style the action bar. -->
- <attr name="colorFilter" format="color" />
<!-- Specifies title text used for navigationMode="normal" -->
<attr name="title" />
<!-- Specifies subtitle text used for navigationMode="normal" -->
@@ -4272,6 +4275,8 @@
<attr name="customNavigationLayout" format="reference" />
<!-- Specifies a fixed height. -->
<attr name="height" />
+ <!-- Specifies a drawable to use for the 'home as up' indicator. -->
+ <attr name="homeAsUpIndicator" format="reference" />
</declare-styleable>
<declare-styleable name="ActionMode">
@@ -4305,4 +4310,8 @@
<flag name="end" value="4" />
</attr>
</declare-styleable>
+
+ <declare-styleable name="ActionBar_LayoutParams">
+ <attr name="layout_gravity" />
+ </declare-styleable>
</resources>
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index bc20fbb..d704366 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1357,6 +1357,7 @@
<public type="attr" name="dividerVertical" />
<public type="attr" name="buttonGroupStyle" />
<public type="attr" name="alertDialogButtonGroupStyle" />
+ <public type="attr" name="homeAsUpIndicator" />
<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 df11c34..adf1715 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -911,7 +911,7 @@
<style name="Widget.ActionBar">
<item name="android:background">@android:drawable/action_bar_background</item>
- <item name="android:displayOptions">useLogo</item>
+ <item name="android:displayOptions">useLogo|showHome|showTitle</item>
<item name="android:divider">@android:drawable/action_bar_divider</item>
<item name="android:height">?android:attr/actionBarSize</item>
<item name="android:paddingLeft">0dip</item>
@@ -1536,6 +1536,7 @@
<item name="android:subtitleTextStyle">@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle</item>
<item name="android:background">@null</item>
<item name="android:divider">?android:attr/dividerVertical</item>
+ <item name="android:homeAsUpIndicator">@android:drawable/ic_ab_back_holo_dark</item>
</style>
<!-- Light widget styles -->
@@ -1788,6 +1789,7 @@
<item name="android:titleTextStyle">@android:style/TextAppearance.Holo.Widget.ActionBar.Title</item>
<item name="android:subtitleTextStyle">@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle</item>
<item name="android:background">@null</item>
+ <item name="android:homeAsUpIndicator">@android:drawable/ic_ab_back_holo_light</item>
</style>
<!-- Animation Styles -->