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

Commit 7195c8f2 authored by Adam Powell's avatar Adam Powell Committed by Android Git Automerger
Browse files

am a41f9cfb: am 53d49f17: am 17f05497: am c2469500: Merge "Touch action bar...

am a41f9cfb: am 53d49f17: am 17f05497: am c2469500: Merge "Touch action bar title text: you will go to space today!" into jb-mr1.1-dev

# Via Android Git Automerger (3) and others
* commit 'a41f9cfb':
  Touch action bar title text: you will go to space today!
parents 7868d748 a41f9cfb
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -131,6 +131,12 @@ public abstract class ActionBar {
     */
    public static final int DISPLAY_SHOW_CUSTOM = 0x10;

    /**
     * Allow the title to wrap onto multiple lines if space is available
     * @hide pending API approval
     */
    public static final int DISPLAY_TITLE_MULTIPLE_LINES = 0x20;

    /**
     * Set the action bar into custom navigation mode, supplying a view
     * for custom navigation.
@@ -679,6 +685,15 @@ public abstract class ActionBar {
     */
    public Context getThemedContext() { return null; }

    /**
     * Returns true if the Title field has been truncated during layout for lack
     * of available space.
     *
     * @return true if the Title field has been truncated
     * @hide pending API approval
     */
    public boolean isTitleTruncated() { return false; }

    /**
     * Listener interface for ActionBar navigation events.
     */
+5 −0
Original line number Diff line number Diff line
@@ -801,6 +801,11 @@ public class ActionBarImpl extends ActionBar {
        return mThemedContext;
    }
    
    @Override
    public boolean isTitleTruncated() {
        return mActionView != null && mActionView.isTitleTruncated();
    }

    /**
     * @hide 
     */
+98 −69
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.Layout;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
@@ -49,7 +50,6 @@ import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.TouchDelegate;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
@@ -83,7 +83,8 @@ public class ActionBarView extends AbsActionBarView {
            ActionBar.DISPLAY_USE_LOGO |
            ActionBar.DISPLAY_HOME_AS_UP |
            ActionBar.DISPLAY_SHOW_CUSTOM |
            ActionBar.DISPLAY_SHOW_TITLE;
            ActionBar.DISPLAY_SHOW_TITLE |
            ActionBar.DISPLAY_TITLE_MULTIPLE_LINES;

    private static final int DEFAULT_CUSTOM_GRAVITY = Gravity.START | Gravity.CENTER_VERTICAL;
    
@@ -100,6 +101,7 @@ public class ActionBarView extends AbsActionBarView {
    private TextView mTitleView;
    private TextView mSubtitleView;
    private View mTitleUpView;
    private ViewGroup mUpGoerFive;

    private Spinner mSpinner;
    private LinearLayout mListNavLayout;
@@ -137,10 +139,6 @@ public class ActionBarView extends AbsActionBarView {

    Window.Callback mWindowCallback;

    private final Rect mTempRect = new Rect();
    private int mMaxHomeSlop;
    private static final int MAX_HOME_SLOP = 32; // dp

    private final AdapterView.OnItemSelectedListener mNavItemSelectedListener =
            new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView parent, View view, int position, long id) {
@@ -219,9 +217,11 @@ public class ActionBarView extends AbsActionBarView {
                com.android.internal.R.styleable.ActionBar_homeLayout,
                com.android.internal.R.layout.action_bar_home);

        mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
        mUpGoerFive = (ViewGroup) inflater.inflate(
                com.android.internal.R.layout.action_bar_up_container, this, false);
        mHomeLayout = (HomeView) inflater.inflate(homeResId, mUpGoerFive, false);

        mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
        mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, mUpGoerFive, false);
        mExpandedHomeLayout.setUp(true);
        mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
        mExpandedHomeLayout.setContentDescription(getResources().getText(
@@ -250,16 +250,14 @@ public class ActionBarView extends AbsActionBarView {
        a.recycle();
        
        mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
        mHomeLayout.setOnClickListener(mUpClickListener);
        mHomeLayout.setClickable(true);
        mHomeLayout.setFocusable(true);

        mUpGoerFive.setOnClickListener(mUpClickListener);
        mUpGoerFive.setClickable(true);
        mUpGoerFive.setFocusable(true);

        if (getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
            setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
        }

        mMaxHomeSlop =
                (int) (MAX_HOME_SLOP * context.getResources().getDisplayMetrics().density + 0.5f);
    }

    @Override
@@ -269,8 +267,8 @@ public class ActionBarView extends AbsActionBarView {
        mTitleView = null;
        mSubtitleView = null;
        mTitleUpView = null;
        if (mTitleLayout != null && mTitleLayout.getParent() == this) {
            removeView(mTitleLayout);
        if (mTitleLayout != null && mTitleLayout.getParent() == mUpGoerFive) {
            mUpGoerFive.removeView(mTitleLayout);
        }
        mTitleLayout = null;
        if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
@@ -551,19 +549,19 @@ public class ActionBarView extends AbsActionBarView {
    }

    public void setHomeButtonEnabled(boolean enable) {
        mHomeLayout.setEnabled(enable);
        mHomeLayout.setFocusable(enable);
        mUpGoerFive.setEnabled(enable);
        mUpGoerFive.setFocusable(enable);
        // Make sure the home button has an accurate content description for accessibility.
        if (!enable) {
            mHomeLayout.setContentDescription(null);
            mHomeLayout.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
            mUpGoerFive.setContentDescription(null);
            mUpGoerFive.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
        } else {
            mHomeLayout.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_AUTO);
            mUpGoerFive.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_AUTO);
            if ((mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
                mHomeLayout.setContentDescription(mContext.getResources().getText(
                mUpGoerFive.setContentDescription(mContext.getResources().getText(
                        R.string.action_bar_up_description));
            } else {
                mHomeLayout.setContentDescription(mContext.getResources().getText(
                mUpGoerFive.setContentDescription(mContext.getResources().getText(
                        R.string.action_bar_home_description));
            }
        }
@@ -600,7 +598,7 @@ public class ActionBarView extends AbsActionBarView {
                if ((options & ActionBar.DISPLAY_SHOW_TITLE) != 0) {
                    initTitle();
                } else {
                    removeView(mTitleLayout);
                    mUpGoerFive.removeView(mTitleLayout);
                }
            }

@@ -608,8 +606,6 @@ public class ActionBarView extends AbsActionBarView {
                    (ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME)) != 0) {
                final boolean homeAsUp = (mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0;
                mTitleUpView.setVisibility(!showHome ? (homeAsUp ? VISIBLE : INVISIBLE) : GONE);
                mTitleLayout.setEnabled(!showHome && homeAsUp);
                mTitleLayout.setClickable(!showHome && homeAsUp);
            }

            if ((flagsChanged & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
@@ -620,6 +616,17 @@ public class ActionBarView extends AbsActionBarView {
                }
            }
            
            if (mTitleLayout != null &&
                    (flagsChanged & ActionBar.DISPLAY_TITLE_MULTIPLE_LINES) != 0) {
                if ((options & ActionBar.DISPLAY_TITLE_MULTIPLE_LINES) != 0) {
                    mTitleView.setSingleLine(false);
                    mTitleView.setMaxLines(2);
                } else {
                    mTitleView.setMaxLines(1);
                    mTitleView.setSingleLine(true);
                }
            }

            requestLayout();
        } else {
            invalidate();
@@ -754,7 +761,8 @@ public class ActionBarView extends AbsActionBarView {
    protected void onFinishInflate() {
        super.onFinishInflate();

        addView(mHomeLayout);
        mUpGoerFive.addView(mHomeLayout, 0);
        addView(mUpGoerFive);

        if (mCustomNavView != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
            final ViewParent parent = mCustomNavView.getParent();
@@ -776,8 +784,6 @@ public class ActionBarView extends AbsActionBarView {
            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);
            }
@@ -797,11 +803,9 @@ public class ActionBarView extends AbsActionBarView {
            final boolean showHome = (mDisplayOptions & ActionBar.DISPLAY_SHOW_HOME) != 0;
            final boolean showTitleUp = !showHome;
            mTitleUpView.setVisibility(showTitleUp ? (homeAsUp ? VISIBLE : INVISIBLE) : GONE);
            mTitleLayout.setEnabled(homeAsUp && showTitleUp);
            mTitleLayout.setClickable(homeAsUp && showTitleUp);
        }

        addView(mTitleLayout);
        mUpGoerFive.addView(mTitleLayout);
        if (mExpandedActionView != null ||
                (TextUtils.isEmpty(mTitle) && TextUtils.isEmpty(mSubtitle))) {
            // Don't show while in expanded mode or with empty text
@@ -821,6 +825,28 @@ public class ActionBarView extends AbsActionBarView {
        return mIsCollapsed;
    }

    /**
     * @return True if any characters in the title were truncated
     */
    public boolean isTitleTruncated() {
        if (mTitleView == null) {
            return false;
        }

        final Layout titleLayout = mTitleView.getLayout();
        if (titleLayout == null) {
            return false;
        }

        final int lineCount = titleLayout.getLineCount();
        for (int i = 0; i < lineCount; i++) {
            if (titleLayout.getEllipsisCount(i) > 0) {
                return true;
            }
        }
        return false;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        final int childCount = getChildCount();
@@ -829,7 +855,16 @@ public class ActionBarView extends AbsActionBarView {
            for (int i = 0; i < childCount; i++) {
                final View child = getChildAt(i);
                if (child.getVisibility() != GONE &&
                        !(child == mMenuView && mMenuView.getChildCount() == 0)) {
                        !(child == mMenuView && mMenuView.getChildCount() == 0) &&
                        child != mUpGoerFive) {
                    visibleChildren++;
                }
            }

            final int upChildCount = mUpGoerFive.getChildCount();
            for (int i = 0; i < upChildCount; i++) {
                final View child = mUpGoerFive.getChildAt(i);
                if (child.getVisibility() != GONE) {
                    visibleChildren++;
                }
            }
@@ -873,7 +908,8 @@ public class ActionBarView extends AbsActionBarView {

        HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;

        if (homeLayout.getVisibility() != GONE) {
        int homeWidth = 0;
        if (homeLayout.getVisibility() != GONE && homeLayout.getParent() == mUpGoerFive) {
            final ViewGroup.LayoutParams lp = homeLayout.getLayoutParams();
            int homeWidthSpec;
            if (lp.width < 0) {
@@ -881,10 +917,18 @@ public class ActionBarView extends AbsActionBarView {
            } else {
                homeWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
            }

            /*
             * This is a little weird.
             * We're only measuring the *home* affordance within the Up container here
             * on purpose, because we want to give the available space to all other views before
             * the title text. We'll remeasure the whole up container again later.
             */
            homeLayout.measure(homeWidthSpec, exactHeightSpec);
            final int homeWidth = homeLayout.getMeasuredWidth() + homeLayout.getStartOffset();
            availableWidth = Math.max(0, availableWidth - homeWidth);
            leftOfCenter = Math.max(0, availableWidth - homeWidth);
            homeWidth = homeLayout.getMeasuredWidth();
            final int homeOffsetWidth = homeWidth + homeLayout.getStartOffset();
            availableWidth = Math.max(0, availableWidth - homeOffsetWidth);
            leftOfCenter = Math.max(0, availableWidth - homeOffsetWidth);
        }
        
        if (mMenuView != null && mMenuView.getParent() == this) {
@@ -986,9 +1030,13 @@ public class ActionBarView extends AbsActionBarView {
            availableWidth -= horizontalMargin + customView.getMeasuredWidth();
        }

        if (mExpandedActionView == null && showTitle) {
            availableWidth = measureChildView(mTitleLayout, availableWidth,
        /*
         * Measure the whole up container now, allowing for the full home+title sections.
         * (This will re-measure the home view.)
         */
        availableWidth = measureChildView(mUpGoerFive, availableWidth + homeWidth,
                MeasureSpec.makeMeasureSpec(mContentHeight, MeasureSpec.EXACTLY), 0);
        if (mTitleLayout != null) {
            leftOfCenter = Math.max(0, leftOfCenter - mTitleLayout.getMeasuredWidth());
        }

@@ -1035,25 +1083,17 @@ public class ActionBarView extends AbsActionBarView {
        final int y = getPaddingTop();

        HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;
        boolean needsTouchDelegate = false;
        int homeSlop = mMaxHomeSlop;
        int homeRight = 0;
        if (homeLayout.getVisibility() != GONE) {
            final int startOffset = homeLayout.getStartOffset();
            x += positionChild(homeLayout,
        final int startOffset = homeLayout.getVisibility() != GONE &&
                homeLayout.getParent() == mUpGoerFive ? homeLayout.getStartOffset() : 0;

        // Position the up container based on where the edge of the home layout should go.
        x += positionChild(mUpGoerFive,
                next(x, startOffset, isLayoutRtl), y, contentHeight, isLayoutRtl);
        x = next(x, startOffset, isLayoutRtl);
            needsTouchDelegate = homeLayout == mHomeLayout;
            homeRight = x;
        }

        if (mExpandedActionView == null) {
            final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE &&
                    (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;
            if (showTitle) {
                x += positionChild(mTitleLayout, x, y, contentHeight, isLayoutRtl);
                homeSlop = mTitleLayout.getWidth();
            }

            switch (mNavigationMode) {
                case ActionBar.NAVIGATION_MODE_STANDARD:
@@ -1063,7 +1103,6 @@ public class ActionBarView extends AbsActionBarView {
                        if (showTitle) {
                            x = next(x, mItemPadding, isLayoutRtl);
                        }
                        homeSlop = Math.min(homeSlop, Math.max(x - homeRight, 0));
                        x += positionChild(mListNavLayout, x, y, contentHeight, isLayoutRtl);
                        x = next(x, mItemPadding, isLayoutRtl);
                    }
@@ -1071,7 +1110,6 @@ public class ActionBarView extends AbsActionBarView {
                case ActionBar.NAVIGATION_MODE_TABS:
                    if (mTabScrollView != null) {
                        if (showTitle) x = next(x, mItemPadding, isLayoutRtl);
                        homeSlop = Math.min(homeSlop, Math.max(x - homeRight, 0));
                        x += positionChild(mTabScrollView, x, y, contentHeight, isLayoutRtl);
                        x = next(x, mItemPadding, isLayoutRtl);
                    }
@@ -1176,7 +1214,6 @@ public class ActionBarView extends AbsActionBarView {
            final int customWidth = customView.getMeasuredWidth();
            customView.layout(xpos, ypos, xpos + customWidth,
                    ypos + customView.getMeasuredHeight());
            homeSlop = Math.min(homeSlop, Math.max(xpos - homeRight, 0));
            x = next(x, customWidth, isLayoutRtl);
        }

@@ -1186,14 +1223,6 @@ public class ActionBarView extends AbsActionBarView {
            mProgressView.layout(mProgressBarPadding, -halfProgressHeight,
                    mProgressBarPadding + mProgressView.getMeasuredWidth(), halfProgressHeight);
        }

        if (needsTouchDelegate) {
            mTempRect.set(homeLayout.getLeft(), homeLayout.getTop(),
                    homeLayout.getRight() + homeSlop, homeLayout.getBottom());
            setTouchDelegate(new TouchDelegate(mTempRect, homeLayout));
        } else {
            setTouchDelegate(null);
        }
    }

    @Override
@@ -1493,8 +1522,8 @@ public class ActionBarView extends AbsActionBarView {
            if (mExpandedActionView.getParent() != ActionBarView.this) {
                addView(mExpandedActionView);
            }
            if (mExpandedHomeLayout.getParent() != ActionBarView.this) {
                addView(mExpandedHomeLayout);
            if (mExpandedHomeLayout.getParent() != mUpGoerFive) {
                mUpGoerFive.addView(mExpandedHomeLayout);
            }
            mHomeLayout.setVisibility(GONE);
            if (mTitleLayout != null) mTitleLayout.setVisibility(GONE);
@@ -1520,7 +1549,7 @@ public class ActionBarView extends AbsActionBarView {
            }

            removeView(mExpandedActionView);
            removeView(mExpandedHomeLayout);
            mUpGoerFive.removeView(mExpandedHomeLayout);
            mExpandedActionView = null;
            if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_HOME) != 0) {
                mHomeLayout.setVisibility(VISIBLE);
+1 −3
Original line number Diff line number Diff line
@@ -17,9 +17,7 @@
<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/actionBarItemBackground"
      android:animateLayoutChanges="true">
      android:layout_height="match_parent">
    <ImageView android:id="@android:id/up"
               android:src="?android:attr/homeAsUpIndicator"
               android:layout_gravity="center_vertical|start"
+1 −2
Original line number Diff line number Diff line
@@ -16,10 +16,9 @@

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_height="match_parent"
              android:orientation="horizontal"
              android:paddingEnd="8dip"
              android:background="?android:attr/actionBarItemBackground"
              android:enabled="false">

    <ImageView android:id="@android:id/up"
Loading