Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2b0952b1 authored by Adam Powell's avatar Adam Powell
Browse files

Fix bug 4065021 - Adjust spacing of the "home" action bar item to be

consistent with the "up" indicator

Make sure that the "home" affordance in the action bar always occupies
the same amount of space regardless of whether or not the "up"
indicator is visible. This means centering the application icon/logo
in the remaining space after the "up" indicator has been added.

Change-Id: I3c81cfe8255546d4dd676af913895713baba4f13
parent 949d0c8c
Loading
Loading
Loading
Loading
+57 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -957,4 +958,60 @@ public class ActionBarView extends ViewGroup {
            }
        }
    }

    private static class HomeView extends FrameLayout {
        private View mUpView;
        private View mIconView;

        public HomeView(Context context) {
            this(context, null);
        }

        public HomeView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        @Override
        protected void onFinishInflate() {
            mUpView = findViewById(com.android.internal.R.id.up);
            mIconView = (ImageView) findViewById(com.android.internal.R.id.home);
        }

        @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;
            int height = upLp.topMargin + mUpView.getMeasuredHeight() + upLp.bottomMargin;
            measureChildWithMargins(mIconView, widthMeasureSpec, width, heightMeasureSpec, 0);
            final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();
            width += iconLp.leftMargin + mIconView.getMeasuredWidth() + iconLp.rightMargin;
            height = Math.max(height,
                    iconLp.topMargin + mIconView.getMeasuredHeight() + iconLp.bottomMargin);
            setMeasuredDimension(width, height);
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            final int vCenter = (b - t) / 2;
            int width = r - l;
            if (mUpView.getVisibility() != GONE) {
                final LayoutParams upLp = (LayoutParams) mUpView.getLayoutParams();
                final int upHeight = mUpView.getMeasuredHeight();
                final int upWidth = mUpView.getMeasuredWidth();
                final int upTop = t + vCenter - upHeight / 2;
                mUpView.layout(l, upTop, l + upWidth, upTop + upHeight);
                final int upOffset = upLp.leftMargin + upWidth + upLp.rightMargin;
                width -= upOffset;
                l += upOffset;
            }
            final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();
            final int iconHeight = mIconView.getMeasuredHeight();
            final int iconWidth = mIconView.getMeasuredWidth();
            final int hCenter = (r - l) / 2;
            final int iconLeft = l + iconLp.leftMargin + hCenter - iconWidth / 2;
            final int iconTop = t + iconLp.topMargin + vCenter - iconHeight / 2;
            mIconView.layout(iconLeft, iconTop, iconLeft + iconWidth, iconTop + iconHeight);
        }
    }
}
+7 −7
Original line number Diff line number Diff line
@@ -14,14 +14,14 @@
     limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<view xmlns:android="http://schemas.android.com/apk/res/android"
      class="com.android.internal.widget.ActionBarView$HomeView"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
              android:background="?android:attr/selectableItemBackground"
              android:orientation="horizontal">
      android:background="?android:attr/selectableItemBackground" >
    <ImageView android:id="@android:id/up"
               android:src="?android:attr/homeAsUpIndicator"
               android:layout_gravity="top|left"
               android:layout_gravity="center_vertical|left"
               android:visibility="gone"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
@@ -33,4 +33,4 @@
               android:paddingRight="16dip"
               android:layout_gravity="center"
               android:scaleType="center" />
</LinearLayout>
</view>