Fix bug 5143392 - Add padding to left of action bar app icon to
prevent icon from moving when drilling into hierarchy

Fix up the layout of home/up/titles in the action bar such that showing/hiding
the "up" indicator never changes the position of the icon, logo, or title.

Change-Id: Ic2117babe3a54619a4b787d5374295955a58fb34
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index 28181ba..4efb29f 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -550,10 +550,9 @@
 
             if (mTitleLayout != null && (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);
+                final boolean homeAsUp = (mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0;
+                mTitleUpView.setVisibility(!showHome ? (homeAsUp ? VISIBLE : INVISIBLE) : GONE);
+                mTitleLayout.setEnabled(!showHome && homeAsUp);
             }
 
             if ((flagsChanged & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
@@ -730,10 +729,9 @@
             }
 
             final boolean homeAsUp = (mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0;
-            final boolean titleUp = homeAsUp &&
-                    (mDisplayOptions & ActionBar.DISPLAY_SHOW_HOME) == 0;
-            mTitleUpView.setVisibility(titleUp ? VISIBLE : GONE);
-            mTitleLayout.setEnabled(titleUp);
+            final boolean showHome = (mDisplayOptions & ActionBar.DISPLAY_SHOW_HOME) != 0;
+            mTitleUpView.setVisibility(!showHome ? (homeAsUp ? VISIBLE : INVISIBLE) : GONE);
+            mTitleLayout.setEnabled(homeAsUp && !showHome);
         }
 
         addView(mTitleLayout);
@@ -805,7 +803,7 @@
         int leftOfCenter = availableWidth / 2;
         int rightOfCenter = leftOfCenter;
 
-        View homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;
+        HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;
 
         if (homeLayout.getVisibility() != GONE) {
             final LayoutParams lp = homeLayout.getLayoutParams();
@@ -817,7 +815,7 @@
             }
             homeLayout.measure(homeWidthSpec,
                     MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
-            final int homeWidth = homeLayout.getMeasuredWidth();
+            final int homeWidth = homeLayout.getMeasuredWidth() + homeLayout.getLeftOffset();
             availableWidth = Math.max(0, availableWidth - homeWidth);
             leftOfCenter = Math.max(0, availableWidth - homeWidth);
         }
@@ -962,9 +960,10 @@
             return;
         }
 
-        View homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;
+        HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;
         if (homeLayout.getVisibility() != GONE) {
-            x += positionChild(homeLayout, x, y, contentHeight);
+            final int leftOffset = homeLayout.getLeftOffset();
+            x += positionChild(homeLayout, x + leftOffset, y, contentHeight) + leftOffset;
         }
 
         if (mExpandedActionView == null) {
@@ -1171,6 +1170,7 @@
     private static class HomeView extends FrameLayout {
         private View mUpView;
         private ImageView mIconView;
+        private int mUpWidth;
 
         public HomeView(Context context) {
             this(context, null);
@@ -1194,15 +1194,16 @@
             mIconView = (ImageView) findViewById(com.android.internal.R.id.home);
         }
 
-        public int getVerticalIconPadding() {
-            return mIconView.getPaddingTop() + mIconView.getPaddingBottom();
+        public int getLeftOffset() {
+            return mUpView.getVisibility() == GONE ? mUpWidth : 0;
         }
 
         @Override
         protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
             measureChildWithMargins(mUpView, widthMeasureSpec, 0, heightMeasureSpec, 0);
             final LayoutParams upLp = (LayoutParams) mUpView.getLayoutParams();
-            int width = upLp.leftMargin + mUpView.getMeasuredWidth() + upLp.rightMargin;
+            mUpWidth = upLp.leftMargin + mUpView.getMeasuredWidth() + upLp.rightMargin;
+            int width = mUpView.getVisibility() == GONE ? 0 : mUpWidth;
             int height = upLp.topMargin + mUpView.getMeasuredHeight() + upLp.bottomMargin;
             measureChildWithMargins(mIconView, widthMeasureSpec, width, heightMeasureSpec, 0);
             final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();