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

This commit is contained in:
Adam Powell
2011-08-22 17:52:46 -07:00
committed by Android (Google) Code Review

View File

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