From 54c7d7e61cd975d73b7eb0a5a0c75d21b6a7a12b Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Fri, 17 Jun 2011 20:30:13 -0700 Subject: Allow the action bar title to take on the role of "up" in the absence of a standard "home" icon. Change-Id: Ie1a9adca674500a29da36956455667bbb55a616f --- .../com/android/internal/widget/ActionBarView.java | 36 +++++++++++++------ core/res/res/layout/action_bar_title_item.xml | 41 +++++++++++++++------- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java index 9d8d361..290f90d 100644 --- a/core/java/com/android/internal/widget/ActionBarView.java +++ b/core/java/com/android/internal/widget/ActionBarView.java @@ -96,6 +96,8 @@ public class ActionBarView extends AbsActionBarView { private LinearLayout mTitleLayout; private TextView mTitleView; private TextView mSubtitleView; + private View mTitleUpView; + private Spinner mSpinner; private LinearLayout mListNavLayout; private ScrollingTabContainerView mTabScrollView; @@ -152,6 +154,16 @@ public class ActionBarView extends AbsActionBarView { } }; + private final OnClickListener mUpClickListener = new OnClickListener() { + public void onClick(View v) { + Context context = getContext(); + if (context instanceof Activity) { + Activity activity = (Activity) context; + activity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mLogoNavItem); + } + } + }; + public ActionBarView(Context context, AttributeSet attrs) { super(context, attrs); @@ -230,15 +242,7 @@ public class ActionBarView extends AbsActionBarView { a.recycle(); mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle); - mHomeLayout.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - Context context = getContext(); - if (context instanceof Activity) { - Activity activity = (Activity) context; - activity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mLogoNavItem); - } - } - }); + mHomeLayout.setOnClickListener(mUpClickListener); mHomeLayout.setClickable(true); mHomeLayout.setFocusable(true); } @@ -438,7 +442,8 @@ public class ActionBarView extends AbsActionBarView { } if ((flagsChanged & DISPLAY_RELAYOUT_MASK) != 0) { - final int vis = (options & ActionBar.DISPLAY_SHOW_HOME) != 0 ? VISIBLE : GONE; + final boolean showHome = (options & ActionBar.DISPLAY_SHOW_HOME) != 0; + final int vis = showHome ? VISIBLE : GONE; mHomeLayout.setVisibility(vis); if ((flagsChanged & ActionBar.DISPLAY_HOME_AS_UP) != 0) { @@ -458,6 +463,14 @@ public class ActionBarView extends AbsActionBarView { } } + if ((flagsChanged & + (ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME)) != 0) { + final boolean homeAsUp = (options & ActionBar.DISPLAY_HOME_AS_UP) != 0; + final boolean titleUp = homeAsUp && !showHome; + mTitleUpView.setVisibility(titleUp ? VISIBLE : GONE); + mTitleLayout.setEnabled(titleUp); + } + if ((flagsChanged & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) { if ((options & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) { addView(mCustomNavView); @@ -641,6 +654,9 @@ public class ActionBarView extends AbsActionBarView { mTitleLayout = (LinearLayout) inflater.inflate(R.layout.action_bar_title_item, null); mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title); mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle); + mTitleUpView = (View) mTitleLayout.findViewById(R.id.up); + + mTitleLayout.setOnClickListener(mUpClickListener); if (mTitleStyleRes != 0) { mTitleView.setTextAppearance(mContext, mTitleStyleRes); diff --git a/core/res/res/layout/action_bar_title_item.xml b/core/res/res/layout/action_bar_title_item.xml index d8b729d..e803b26 100644 --- a/core/res/res/layout/action_bar_title_item.xml +++ b/core/res/res/layout/action_bar_title_item.xml @@ -17,17 +17,32 @@ - - + android:orientation="horizontal" + android:paddingRight="16dip" + android:background="?android:attr/selectableItemBackground" + android:enabled="false"> + + + + + + + -- cgit v1.1