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

Commit e2194445 authored by Adam Powell's avatar Adam Powell
Browse files

Clean up some Action Bar style handling.

Action Bar now obeys the titleTextStyle/subtitleTextStyle attributes
and has a better way of handling custom sizes. Any attached Action
Mode bar will keep in sync with the Action Bar's height.

Change-Id: I7d16319f5609d4d6c80a3043dcb60303e6e903db
parent 7777bb0c
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -10657,6 +10657,17 @@
 visibility="public"
>
</field>
<field name="windowActionBarSize"
 type="int"
 transient="false"
 volatile="false"
 value="16843563"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="windowActionBarStyle"
 type="int"
 transient="false"
+1 −0
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ public class ActionBarImpl extends ActionBar {
                com.android.internal.R.id.lower_action_context_bar);
        mAnimatorView = (ViewAnimator) decor.findViewById(
                com.android.internal.R.id.action_bar_animator);
        mActionView.setContextView(mUpperContextView);
        
        if (mActionView == null || mUpperContextView == null || mAnimatorView == null) {
            throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
+26 −7
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.MeasureSpec;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -35,9 +36,6 @@ import android.widget.TextView;
 * @hide
 */
public class ActionBarContextView extends ViewGroup {
    // TODO: This must be defined in the default theme
    private static final int CONTENT_HEIGHT_DIP = 50;
    
    private int mItemPadding;
    private int mItemMargin;
    private int mActionSpacing;
@@ -75,11 +73,15 @@ public class ActionBarContextView extends ViewGroup {
                com.android.internal.R.styleable.Theme_actionModeCloseDrawable);
        mItemMargin = mItemPadding / 2;

        mContentHeight =
                (int) (CONTENT_HEIGHT_DIP * getResources().getDisplayMetrics().density + 0.5f);
        mContentHeight = a.getLayoutDimension(
                com.android.internal.R.styleable.Theme_windowActionBarSize, 0);
        a.recycle();
    }
    
    public void setHeight(int height) {
        mContentHeight = height;
    }

    public void setCustomView(View view) {
        if (mCustomView != null) {
            removeView(mCustomView);
@@ -208,8 +210,12 @@ public class ActionBarContextView extends ViewGroup {
        final int contentWidth = MeasureSpec.getSize(widthMeasureSpec);
        final int itemMargin = mItemPadding;

        int maxHeight = mContentHeight > 0 ?
                mContentHeight : MeasureSpec.getSize(heightMeasureSpec);

        final int verticalPadding = getPaddingTop() + getPaddingBottom();
        int availableWidth = contentWidth - getPaddingLeft() - getPaddingRight();
        final int height = mContentHeight - getPaddingTop() - getPaddingBottom();
        final int height = maxHeight - verticalPadding;
        final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
        
        if (mCloseButton != null) {
@@ -246,7 +252,20 @@ public class ActionBarContextView extends ViewGroup {
                    MeasureSpec.makeMeasureSpec(customHeight, customHeightMode));
        }

        setMeasuredDimension(contentWidth, mContentHeight);
        if (mContentHeight <= 0) {
            int measuredHeight = 0;
            final int count = getChildCount();
            for (int i = 0; i < count; i++) {
                View v = getChildAt(i);
                int paddedViewHeight = v.getMeasuredHeight() + verticalPadding;
                if (paddedViewHeight > measuredHeight) {
                    measuredHeight = paddedViewHeight;
                }
            }
            setMeasuredDimension(contentWidth, measuredHeight);
        } else {
            setMeasuredDimension(contentWidth, maxHeight);
        }
    }

    @Override
+45 −8
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@ public class ActionBarView extends ViewGroup {
    private static final String TAG = "ActionBarView";
    
    // TODO: This must be defined in the default theme
    private static final int CONTENT_HEIGHT_DIP = 50;
    private static final int CONTENT_PADDING_DIP = 3;
    private static final int CONTENT_SPACING_DIP = 6;
    private static final int CONTENT_ACTION_SPACING_DIP = 12;
@@ -90,12 +89,17 @@ public class ActionBarView extends ViewGroup {
    private LinearLayout mTabLayout;
    private View mCustomNavView;
    
    private int mTitleStyleRes;
    private int mSubtitleStyleRes;

    private boolean mShowMenu;
    private boolean mUserTitle;

    private MenuBuilder mOptionsMenu;
    private ActionMenuView mMenuView;
    
    private ActionBarContextView mContextView;

    private ActionMenuItem mLogoNavItem;
    
    private NavigationCallback mCallback;
@@ -151,6 +155,9 @@ public class ActionBarView extends ViewGroup {
            setBackgroundDrawable(background);
        }
        
        mTitleStyleRes = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
        mSubtitleStyleRes = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);

        final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
        if (customNavId != 0) {
            LayoutInflater inflater = LayoutInflater.from(context);
@@ -159,11 +166,7 @@ public class ActionBarView extends ViewGroup {
            addView(mCustomNavView);
        }

        final int padding = a.getDimensionPixelSize(R.styleable.ActionBar_padding,
                (int) (CONTENT_PADDING_DIP * metrics.density + 0.5f));
        setPadding(padding, padding, padding, padding);
        mContentHeight = a.getDimensionPixelSize(R.styleable.ActionBar_height,
                (int) (CONTENT_PADDING_DIP * metrics.density + 0.5f)) - padding * 2;
        mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);

        a.recycle();

@@ -473,13 +476,22 @@ public class ActionBarView extends ViewGroup {
        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);

        if (mTitleStyleRes != 0) {
            mTitleView.setTextAppearance(mContext, mTitleStyleRes);
        }
        if (mTitle != null) {
            mTitleView.setText(mTitle);
        }

        if (mSubtitleStyleRes != 0) {
            mSubtitleView.setTextAppearance(mContext, mSubtitleStyleRes);
        }
        if (mSubtitle != null) {
            mSubtitleView.setText(mSubtitle);
            mSubtitleView.setVisibility(VISIBLE);
        }

        addView(mTitleLayout);
    }

@@ -491,6 +503,10 @@ public class ActionBarView extends ViewGroup {
        }
    }

    public void setContextView(ActionBarContextView view) {
        mContextView = view;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
@@ -507,8 +523,12 @@ public class ActionBarView extends ViewGroup {

        int contentWidth = MeasureSpec.getSize(widthMeasureSpec);

        int maxHeight = mContentHeight > 0 ?
                mContentHeight : MeasureSpec.getSize(heightMeasureSpec);
        
        final int verticalPadding = getPaddingTop() + getPaddingBottom();
        int availableWidth = contentWidth - getPaddingLeft() - getPaddingRight();
        final int height = mContentHeight - getPaddingTop() - getPaddingBottom();
        final int height = maxHeight - verticalPadding;
        final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);

        if (mLogoView != null && mLogoView.getVisibility() != GONE) {
@@ -561,7 +581,24 @@ public class ActionBarView extends ViewGroup {
            break;
        }

        setMeasuredDimension(contentWidth, mContentHeight);
        if (mContentHeight <= 0) {
            int measuredHeight = 0;
            final int count = getChildCount();
            for (int i = 0; i < count; i++) {
                View v = getChildAt(i);
                int paddedViewHeight = v.getMeasuredHeight() + verticalPadding;
                if (paddedViewHeight > measuredHeight) {
                    measuredHeight = paddedViewHeight;
                }
            }
            setMeasuredDimension(contentWidth, measuredHeight);
        } else {
            setMeasuredDimension(contentWidth, maxHeight);
        }

        if (mContextView != null) {
            mContextView.setHeight(getMeasuredHeight());
        }
    }

    private int measureChildView(View child, int availableWidth, int childSpecHeight, int spacing) {
+20 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
	<translate android:fromYDelta="-100%p" android:toYDelta="0"
            android:duration="@android:integer/config_longAnimTime"/>
</set>
Loading