1e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell/* 2e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Copyright (C) 2014 The Android Open Source Project 3e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 4e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Licensed under the Apache License, Version 2.0 (the "License"); 5e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * you may not use this file except in compliance with the License. 6e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * You may obtain a copy of the License at 7e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 8e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * http://www.apache.org/licenses/LICENSE-2.0 9e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 10e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Unless required by applicable law or agreed to in writing, software 11e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * distributed under the License is distributed on an "AS IS" BASIS, 12e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * See the License for the specific language governing permissions and 14e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * limitations under the License. 15e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 16e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 17e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellpackage android.widget; 18e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1980756e38882720860db52f1fcc21fa1505a02abfTor Norbyeimport android.annotation.ColorInt; 20417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbyeimport android.annotation.DrawableRes; 21417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbyeimport android.annotation.MenuRes; 22e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.annotation.NonNull; 23e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viveretteimport android.annotation.Nullable; 24417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbyeimport android.annotation.StringRes; 25417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbyeimport android.annotation.StyleRes; 2667960a0a555808eaf512454f0a344c672c398292Kirill Grouchnikovimport android.annotation.TestApi; 27e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powellimport android.app.ActionBar; 28e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.content.Context; 29e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.content.res.TypedArray; 30e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.graphics.drawable.Drawable; 31e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.os.Parcel; 32e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.os.Parcelable; 33e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powellimport android.text.Layout; 34e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.text.TextUtils; 35e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.util.AttributeSet; 36e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powellimport android.view.CollapsibleActionView; 373d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viveretteimport android.view.ContextThemeWrapper; 38e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.view.Gravity; 39e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.view.Menu; 40e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.view.MenuInflater; 41e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.view.MenuItem; 4261d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powellimport android.view.MotionEvent; 43e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.view.View; 44e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport android.view.ViewGroup; 451abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshevimport android.view.ViewParent; 463d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette 47e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport com.android.internal.R; 48e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powellimport com.android.internal.view.menu.MenuBuilder; 49e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powellimport com.android.internal.view.menu.MenuItemImpl; 50e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powellimport com.android.internal.view.menu.MenuPresenter; 51e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powellimport com.android.internal.view.menu.MenuView; 52e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powellimport com.android.internal.view.menu.SubMenuBuilder; 53e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powellimport com.android.internal.widget.DecorToolbar; 54e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powellimport com.android.internal.widget.ToolbarWidgetWrapper; 55e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 56e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport java.util.ArrayList; 57e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellimport java.util.List; 58e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 59e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell/** 60e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * A standard toolbar for use within application content. 61e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 62e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>A Toolbar is a generalization of {@link android.app.ActionBar action bars} for use 63e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * within application layouts. While an action bar is traditionally part of an 64e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * {@link android.app.Activity Activity's} opaque window decor controlled by the framework, 65e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy. 66e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * An application may choose to designate a Toolbar as the action bar for an Activity 67e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * using the {@link android.app.Activity#setActionBar(Toolbar) setActionBar()} method.</p> 68e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 69e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>Toolbar supports a more focused feature set than ActionBar. From start to end, a toolbar 70e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * may contain a combination of the following optional elements: 71e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 72e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <ul> 73e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <li><em>A navigation button.</em> This may be an Up arrow, navigation menu toggle, close, 74e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * collapse, done or another glyph of the app's choosing. This button should always be used 75e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * to access other navigational destinations within the container of the Toolbar and 76157afde397f817e0a3a21c5d47011db462b6fff6Alan Viverette * its signified content or otherwise leave the current context signified by the Toolbar. 77157afde397f817e0a3a21c5d47011db462b6fff6Alan Viverette * The navigation button is vertically aligned within the Toolbar's 78157afde397f817e0a3a21c5d47011db462b6fff6Alan Viverette * {@link android.R.styleable#View_minHeight minimum height}, if set.</li> 79e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <li><em>A branded logo image.</em> This may extend to the height of the bar and can be 80e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * arbitrarily wide.</li> 81e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <li><em>A title and subtitle.</em> The title should be a signpost for the Toolbar's current 82e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * position in the navigation hierarchy and the content contained there. The subtitle, 83e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * if present should indicate any extended information about the current content. 84e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * If an app uses a logo image it should strongly consider omitting a title and subtitle.</li> 85e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <li><em>One or more custom views.</em> The application may add arbitrary child views 86e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * to the Toolbar. They will appear at this position within the layout. If a child view's 87e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * {@link LayoutParams} indicates a {@link Gravity} value of 88e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * {@link Gravity#CENTER_HORIZONTAL CENTER_HORIZONTAL} the view will attempt to center 89e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * within the available space remaining in the Toolbar after all other elements have been 90e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * measured.</li> 91e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <li><em>An {@link ActionMenuView action menu}.</em> The menu of actions will pin to the 92e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * end of the Toolbar offering a few 93e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <a href="http://developer.android.com/design/patterns/actionbar.html#ActionButtons"> 94157afde397f817e0a3a21c5d47011db462b6fff6Alan Viverette * frequent, important or typical</a> actions along with an optional overflow menu for 95157afde397f817e0a3a21c5d47011db462b6fff6Alan Viverette * additional actions. Action buttons are vertically aligned within the Toolbar's 96157afde397f817e0a3a21c5d47011db462b6fff6Alan Viverette * {@link android.R.styleable#View_minHeight minimum height}, if set.</li> 97e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * </ul> 98e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * </p> 99e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 100e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>In modern Android UIs developers should lean more on a visually distinct color scheme for 101e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * toolbars than on their application icon. The use of application icon plus title as a standard 102e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * layout is discouraged on API 21 devices and newer.</p> 1034db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * 1044db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_buttonGravity 1054db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_collapseContentDescription 1064db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_collapseIcon 1074db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_contentInsetEnd 1084db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_contentInsetLeft 1094db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_contentInsetRight 1104db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_contentInsetStart 111679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetStartWithNavigation 112679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetEndWithActions 1134db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_gravity 1144db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_logo 1154db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_logoDescription 1164db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_maxButtonHeight 1174db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_navigationContentDescription 1184db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_navigationIcon 1194db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_popupTheme 1204db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_subtitle 1214db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_subtitleTextAppearance 1224db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_subtitleTextColor 1234db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_title 1244db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMargin 1254db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMarginBottom 1264db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMarginEnd 1274db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMarginStart 1284db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMarginTop 1294db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleTextAppearance 1304db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleTextColor 131e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 132e43340c80dc66c45edc793ecd0343774aa34d108Adam Powellpublic class Toolbar extends ViewGroup { 133e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private static final String TAG = "Toolbar"; 134e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 135e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private ActionMenuView mMenuView; 136e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private TextView mTitleTextView; 137e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private TextView mSubtitleTextView; 138e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private ImageButton mNavButtonView; 139e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private ImageView mLogoView; 140e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 141e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private Drawable mCollapseIcon; 14285085343b378f00a34448b69e582226fa584b005Alan Viverette private CharSequence mCollapseDescription; 143e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private ImageButton mCollapseButtonView; 144e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell View mExpandedActionView; 145e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 1463d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette /** Context against which to inflate popup menus. */ 1473d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette private Context mPopupContext; 1483d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette 1493d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette /** Theme resource against which to inflate popup menus. */ 1503d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette private int mPopupTheme; 1513d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette 152e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private int mTitleTextAppearance; 153e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private int mSubtitleTextAppearance; 154e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private int mNavButtonStyle; 155e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 156e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private int mButtonGravity; 157e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 158e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private int mMaxButtonHeight; 15976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 160e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private int mTitleMarginStart; 161e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private int mTitleMarginEnd; 162e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private int mTitleMarginTop; 163e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private int mTitleMarginBottom; 164e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1653b925c1ab092cf63329845ecad73aa58db24c86dChris Banes private RtlSpacingHelper mContentInsets; 166679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell private int mContentInsetStartWithNavigation; 167679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell private int mContentInsetEndWithActions; 16876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 169e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private int mGravity = Gravity.START | Gravity.CENTER_VERTICAL; 170e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 171e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private CharSequence mTitleText; 172e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private CharSequence mSubtitleText; 173e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1741a264ce3d915b187b71101436bec3328c76288b0Adam Powell private int mTitleTextColor; 1751a264ce3d915b187b71101436bec3328c76288b0Adam Powell private int mSubtitleTextColor; 1761a264ce3d915b187b71101436bec3328c76288b0Adam Powell 17761d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell private boolean mEatingTouch; 17861d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell 179e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell // Clear me after use. 180e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private final ArrayList<View> mTempViews = new ArrayList<View>(); 181e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1825f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell // Used to hold views that will be removed while we have an expanded action view. 1835f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell private final ArrayList<View> mHiddenViews = new ArrayList<>(); 1845f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell 1857a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell private final int[] mTempMargins = new int[2]; 1867a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell 187e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private OnMenuItemClickListener mOnMenuItemClickListener; 188e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 189e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private final ActionMenuView.OnMenuItemClickListener mMenuViewItemClickListener = 190e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell new ActionMenuView.OnMenuItemClickListener() { 191e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell @Override 192e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public boolean onMenuItemClick(MenuItem item) { 193e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (mOnMenuItemClickListener != null) { 194e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return mOnMenuItemClickListener.onMenuItemClick(item); 195e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 196e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return false; 197e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 198e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell }; 199e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 200e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private ToolbarWidgetWrapper mWrapper; 201e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private ActionMenuPresenter mOuterActionMenuPresenter; 202e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private ExpandedActionViewMenuPresenter mExpandedMenuPresenter; 20304c0d4607897157f01c908475fa0c6d7301cf7e5Adam Powell private MenuPresenter.Callback mActionMenuPresenterCallback; 204c46125042493e66f7dfdccec24e3b0739600b194Adam Powell private MenuBuilder.Callback mMenuBuilderCallback; 205e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 206360c1d89227570510de7bb11195c986300488464Adam Powell private boolean mCollapsible; 207360c1d89227570510de7bb11195c986300488464Adam Powell 20831c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell private final Runnable mShowOverflowMenuRunnable = new Runnable() { 20931c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell @Override public void run() { 21031c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell showOverflowMenu(); 21131c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell } 21231c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell }; 21331c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell 214e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public Toolbar(Context context) { 215e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell this(context, null); 216e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 217e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 218e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public Toolbar(Context context, AttributeSet attrs) { 219e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell this(context, attrs, com.android.internal.R.attr.toolbarStyle); 220e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 221e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 222e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public Toolbar(Context context, AttributeSet attrs, int defStyleAttr) { 223e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell this(context, attrs, defStyleAttr, 0); 224e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 225e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 226e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public Toolbar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 227e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell super(context, attrs, defStyleAttr, defStyleRes); 228e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 229e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Toolbar, 230e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell defStyleAttr, defStyleRes); 231e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 232e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mTitleTextAppearance = a.getResourceId(R.styleable.Toolbar_titleTextAppearance, 0); 233e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mSubtitleTextAppearance = a.getResourceId(R.styleable.Toolbar_subtitleTextAppearance, 0); 234e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mNavButtonStyle = a.getResourceId(R.styleable.Toolbar_navigationButtonStyle, 0); 235e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mGravity = a.getInteger(R.styleable.Toolbar_gravity, mGravity); 236e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mButtonGravity = a.getInteger(R.styleable.Toolbar_buttonGravity, Gravity.TOP); 23776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mTitleMarginStart = mTitleMarginEnd = mTitleMarginTop = mTitleMarginBottom = 2384db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette a.getDimensionPixelOffset(R.styleable.Toolbar_titleMargin, 0); 239e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 240e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int marginStart = a.getDimensionPixelOffset(R.styleable.Toolbar_titleMarginStart, -1); 241e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (marginStart >= 0) { 242e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mTitleMarginStart = marginStart; 243e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 244e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 245e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int marginEnd = a.getDimensionPixelOffset(R.styleable.Toolbar_titleMarginEnd, -1); 246e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (marginEnd >= 0) { 247e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mTitleMarginEnd = marginEnd; 248e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 249e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 250e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int marginTop = a.getDimensionPixelOffset(R.styleable.Toolbar_titleMarginTop, -1); 251e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (marginTop >= 0) { 252e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mTitleMarginTop = marginTop; 253e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 254e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 255e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int marginBottom = a.getDimensionPixelOffset(R.styleable.Toolbar_titleMarginBottom, 256e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell -1); 257e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (marginBottom >= 0) { 258e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mTitleMarginBottom = marginBottom; 259e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 260e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 261e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mMaxButtonHeight = a.getDimensionPixelSize(R.styleable.Toolbar_maxButtonHeight, -1); 262e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 26376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell final int contentInsetStart = 26476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell a.getDimensionPixelOffset(R.styleable.Toolbar_contentInsetStart, 26576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell RtlSpacingHelper.UNDEFINED); 26676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell final int contentInsetEnd = 26776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell a.getDimensionPixelOffset(R.styleable.Toolbar_contentInsetEnd, 26876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell RtlSpacingHelper.UNDEFINED); 26976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell final int contentInsetLeft = 27076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell a.getDimensionPixelSize(R.styleable.Toolbar_contentInsetLeft, 0); 27176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell final int contentInsetRight = 27276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell a.getDimensionPixelSize(R.styleable.Toolbar_contentInsetRight, 0); 27376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 2743b925c1ab092cf63329845ecad73aa58db24c86dChris Banes ensureContentInsets(); 27576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mContentInsets.setAbsolute(contentInsetLeft, contentInsetRight); 27676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 27776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell if (contentInsetStart != RtlSpacingHelper.UNDEFINED || 27876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell contentInsetEnd != RtlSpacingHelper.UNDEFINED) { 27976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mContentInsets.setRelative(contentInsetStart, contentInsetEnd); 28076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 28176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 282679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell mContentInsetStartWithNavigation = a.getDimensionPixelOffset( 283679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell R.styleable.Toolbar_contentInsetStartWithNavigation, RtlSpacingHelper.UNDEFINED); 284679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell mContentInsetEndWithActions = a.getDimensionPixelOffset( 285679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell R.styleable.Toolbar_contentInsetEndWithActions, RtlSpacingHelper.UNDEFINED); 286679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell 287e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mCollapseIcon = a.getDrawable(R.styleable.Toolbar_collapseIcon); 28885085343b378f00a34448b69e582226fa584b005Alan Viverette mCollapseDescription = a.getText(R.styleable.Toolbar_collapseContentDescription); 289e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 290e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final CharSequence title = a.getText(R.styleable.Toolbar_title); 291e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (!TextUtils.isEmpty(title)) { 292e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell setTitle(title); 293e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 294e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 295e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final CharSequence subtitle = a.getText(R.styleable.Toolbar_subtitle); 296e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (!TextUtils.isEmpty(subtitle)) { 29707a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell setSubtitle(subtitle); 298e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2993d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette 30077e5037d8125b94e524264dc1890ab9b6b7df0afAlan Viverette // Set the default context, since setPopupTheme() may be a no-op. 30177e5037d8125b94e524264dc1890ab9b6b7df0afAlan Viverette mPopupContext = mContext; 30222a117d1b60869ed36d125796396f190b4b002fbAlan Viverette setPopupTheme(a.getResourceId(R.styleable.Toolbar_popupTheme, 0)); 3037c13bc2a7090544a04fc93813794a8b97bc86ff7Adam Powell 3047c13bc2a7090544a04fc93813794a8b97bc86ff7Adam Powell final Drawable navIcon = a.getDrawable(R.styleable.Toolbar_navigationIcon); 3057c13bc2a7090544a04fc93813794a8b97bc86ff7Adam Powell if (navIcon != null) { 3067c13bc2a7090544a04fc93813794a8b97bc86ff7Adam Powell setNavigationIcon(navIcon); 30712b0321c0b400f105cad40568a1f572020ba6336Adam Powell } 30812b0321c0b400f105cad40568a1f572020ba6336Adam Powell 30912b0321c0b400f105cad40568a1f572020ba6336Adam Powell final CharSequence navDesc = a.getText( 31012b0321c0b400f105cad40568a1f572020ba6336Adam Powell R.styleable.Toolbar_navigationContentDescription); 31112b0321c0b400f105cad40568a1f572020ba6336Adam Powell if (!TextUtils.isEmpty(navDesc)) { 31212b0321c0b400f105cad40568a1f572020ba6336Adam Powell setNavigationContentDescription(navDesc); 3137c13bc2a7090544a04fc93813794a8b97bc86ff7Adam Powell } 3146b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell 3156b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell final Drawable logo = a.getDrawable(R.styleable.Toolbar_logo); 3166b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell if (logo != null) { 3176b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell setLogo(logo); 3186b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell } 3196b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell 3206b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell final CharSequence logoDesc = a.getText(R.styleable.Toolbar_logoDescription); 3216b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell if (!TextUtils.isEmpty(logoDesc)) { 3226b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell setLogoDescription(logoDesc); 3236b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell } 3246b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell 3256b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell if (a.hasValue(R.styleable.Toolbar_titleTextColor)) { 3266b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell setTitleTextColor(a.getColor(R.styleable.Toolbar_titleTextColor, 0xffffffff)); 3276b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell } 3286b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell 3296b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell if (a.hasValue(R.styleable.Toolbar_subtitleTextColor)) { 3306b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell setSubtitleTextColor(a.getColor(R.styleable.Toolbar_subtitleTextColor, 0xffffffff)); 3316b3fc9a9035c87a23828c8f481732cb3213302a4Adam Powell } 33222a117d1b60869ed36d125796396f190b4b002fbAlan Viverette a.recycle(); 3333d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette } 3343d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette 3351abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev @Override 3361abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev protected void onAttachedToWindow() { 3371abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev super.onAttachedToWindow(); 3381abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev 3391abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev // If the container is a cluster, unmark itself as a cluster to avoid having nested 3401abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev // clusters. 3411abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev ViewParent parent = getParent(); 3421abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev while (parent != null && parent instanceof ViewGroup) { 3431abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev final ViewGroup vgParent = (ViewGroup) parent; 3441abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev if (vgParent.isKeyboardNavigationCluster()) { 3451abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev setKeyboardNavigationCluster(false); 34618b886e8b2fa9d02869132a2e8f1eca997b22f6fEvan Rosky if (vgParent.getTouchscreenBlocksFocus()) { 34718b886e8b2fa9d02869132a2e8f1eca997b22f6fEvan Rosky setTouchscreenBlocksFocus(false); 34818b886e8b2fa9d02869132a2e8f1eca997b22f6fEvan Rosky } 3491abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev break; 3501abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev } 3511abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev parent = vgParent.getParent(); 3521abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev } 3531abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev } 3541abe85c867f552a5cdf50fba3f60d796284c2102Vadim Tryshev 3553d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette /** 3563d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette * Specifies the theme to use when inflating popup menus. By default, uses 3573d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette * the same theme as the toolbar itself. 3583d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette * 3593d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette * @param resId theme used to inflate popup menus 3603d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette * @see #getPopupTheme() 3613d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette */ 362417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbye public void setPopupTheme(@StyleRes int resId) { 3633d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette if (mPopupTheme != resId) { 3643d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette mPopupTheme = resId; 3653d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette if (resId == 0) { 3663d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette mPopupContext = mContext; 3673d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette } else { 3683d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette mPopupContext = new ContextThemeWrapper(mContext, resId); 3693d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette } 3703d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette } 3713d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette } 3723d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette 3733d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette /** 3743d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette * @return resource identifier of the theme used to inflate popup menus, or 3753d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette * 0 if menus are inflated against the toolbar theme 3763d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette * @see #setPopupTheme(int) 3773d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette */ 3783d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette public int getPopupTheme() { 3793d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette return mPopupTheme; 380e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 381e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 3824db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette /** 3834db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * Sets the title margin. 3844db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * 3854db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @param start the starting title margin in pixels 3864db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @param top the top title margin in pixels 3874db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @param end the ending title margin in pixels 3884db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @param bottom the bottom title margin in pixels 3894db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @see #getTitleMarginStart() 3904db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @see #getTitleMarginTop() 3914db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @see #getTitleMarginEnd() 3924db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @see #getTitleMarginBottom() 3934db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMargin 3944db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette */ 3954db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette public void setTitleMargin(int start, int top, int end, int bottom) { 3964db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette mTitleMarginStart = start; 3974db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette mTitleMarginTop = top; 3984db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette mTitleMarginEnd = end; 3994db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette mTitleMarginBottom = bottom; 4004db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette 4014db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette requestLayout(); 4024db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette } 4034db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette 4044db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette /** 4054db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @return the starting title margin in pixels 4064db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @see #setTitleMarginStart(int) 4074db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMarginStart 4084db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette */ 4094db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette public int getTitleMarginStart() { 4104db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette return mTitleMarginStart; 4114db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette } 4124db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette 4134db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette /** 4144db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * Sets the starting title margin in pixels. 4154db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * 4164db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @param margin the starting title margin in pixels 4174db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @see #getTitleMarginStart() 4184db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMarginStart 4194db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette */ 4204db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette public void setTitleMarginStart(int margin) { 4214db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette mTitleMarginStart = margin; 4224db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette 4234db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette requestLayout(); 4244db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette } 4254db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette 4264db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette /** 4274db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @return the top title margin in pixels 4284db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @see #setTitleMarginTop(int) 4294db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMarginTop 4304db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette */ 4314db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette public int getTitleMarginTop() { 4324db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette return mTitleMarginTop; 4334db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette } 4344db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette 4354db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette /** 4364db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * Sets the top title margin in pixels. 4374db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * 4384db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @param margin the top title margin in pixels 4394db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @see #getTitleMarginTop() 4404db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMarginTop 4414db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette */ 4424db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette public void setTitleMarginTop(int margin) { 4434db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette mTitleMarginTop = margin; 4444db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette 4454db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette requestLayout(); 4464db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette } 4474db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette 4484db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette /** 4494db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @return the ending title margin in pixels 4504db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @see #setTitleMarginEnd(int) 4514db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMarginEnd 4524db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette */ 4534db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette public int getTitleMarginEnd() { 4544db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette return mTitleMarginEnd; 4554db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette } 4564db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette 4574db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette /** 4584db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * Sets the ending title margin in pixels. 4594db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * 4604db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @param margin the ending title margin in pixels 4614db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @see #getTitleMarginEnd() 4624db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMarginEnd 4634db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette */ 4644db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette public void setTitleMarginEnd(int margin) { 4654db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette mTitleMarginEnd = margin; 4664db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette 4674db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette requestLayout(); 4684db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette } 4694db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette 4704db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette /** 4714db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @return the bottom title margin in pixels 4724db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @see #setTitleMarginBottom(int) 4734db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMarginBottom 4744db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette */ 4754db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette public int getTitleMarginBottom() { 4764db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette return mTitleMarginBottom; 4774db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette } 4784db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette 4794db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette /** 4804db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * Sets the bottom title margin in pixels. 4814db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * 4824db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @param margin the bottom title margin in pixels 4834db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @see #getTitleMarginBottom() 4844db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette * @attr ref android.R.styleable#Toolbar_titleMarginBottom 4854db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette */ 4864db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette public void setTitleMarginBottom(int margin) { 4874db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette mTitleMarginBottom = margin; 4884db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette requestLayout(); 4894db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette } 4904db9d1b48b49ffc43f1c2d46660ca67a88d673f4Alan Viverette 49176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell @Override 49276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public void onRtlPropertiesChanged(@ResolvedLayoutDir int layoutDirection) { 49376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell super.onRtlPropertiesChanged(layoutDirection); 4943b925c1ab092cf63329845ecad73aa58db24c86dChris Banes ensureContentInsets(); 49576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mContentInsets.setDirection(layoutDirection == LAYOUT_DIRECTION_RTL); 49676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 49776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 498e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 499e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Set a logo drawable from a resource id. 500e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 501e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>This drawable should generally take the place of title text. The logo cannot be 502e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * clicked. Apps using a logo should also supply a description using 503e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * {@link #setLogoDescription(int)}.</p> 504e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 505e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param resId ID of a drawable resource 506e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 507417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbye public void setLogo(@DrawableRes int resId) { 508e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell setLogo(getContext().getDrawable(resId)); 509e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 510e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 511e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell /** @hide */ 512e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public boolean canShowOverflowMenu() { 513e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return getVisibility() == VISIBLE && mMenuView != null && mMenuView.isOverflowReserved(); 514e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 515e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 516e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell /** 517e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * Check whether the overflow menu is currently showing. This may not reflect 518e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * a pending show operation in progress. 519e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * 520e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * @return true if the overflow menu is currently showing 521e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell */ 522e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public boolean isOverflowMenuShowing() { 523e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return mMenuView != null && mMenuView.isOverflowMenuShowing(); 524e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 525e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 526e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell /** @hide */ 527e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public boolean isOverflowMenuShowPending() { 528e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return mMenuView != null && mMenuView.isOverflowMenuShowPending(); 529e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 530e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 531e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell /** 532e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * Show the overflow items from the associated menu. 533e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * 534e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * @return true if the menu was able to be shown, false otherwise 535e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell */ 536e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public boolean showOverflowMenu() { 537e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return mMenuView != null && mMenuView.showOverflowMenu(); 538e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 539e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 540e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell /** 541e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * Hide the overflow items from the associated menu. 542e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * 543e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * @return true if the menu was able to be hidden, false otherwise 544e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell */ 545e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public boolean hideOverflowMenu() { 546e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return mMenuView != null && mMenuView.hideOverflowMenu(); 547e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 548e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 549e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell /** @hide */ 550e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public void setMenu(MenuBuilder menu, ActionMenuPresenter outerPresenter) { 551e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (menu == null && mMenuView == null) { 552e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return; 553e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 554e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 555e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell ensureMenuView(); 556e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final MenuBuilder oldMenu = mMenuView.peekMenu(); 557e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (oldMenu == menu) { 558e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return; 559e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 560e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 561e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (oldMenu != null) { 562e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell oldMenu.removeMenuPresenter(mOuterActionMenuPresenter); 563e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell oldMenu.removeMenuPresenter(mExpandedMenuPresenter); 564e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 565e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 566e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (mExpandedMenuPresenter == null) { 567e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter(); 568e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 569e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 570e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell outerPresenter.setExpandedActionViewsExclusive(true); 571e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (menu != null) { 5723d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette menu.addMenuPresenter(outerPresenter, mPopupContext); 5733d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette menu.addMenuPresenter(mExpandedMenuPresenter, mPopupContext); 574e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } else { 5753d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette outerPresenter.initForMenu(mPopupContext, null); 5763d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette mExpandedMenuPresenter.initForMenu(mPopupContext, null); 577e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell outerPresenter.updateMenuView(true); 578e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mExpandedMenuPresenter.updateMenuView(true); 579e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 5803d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette mMenuView.setPopupTheme(mPopupTheme); 581e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mMenuView.setPresenter(outerPresenter); 582e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mOuterActionMenuPresenter = outerPresenter; 583e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 584e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 585e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell /** 586e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * Dismiss all currently showing popup menus, including overflow or submenus. 587e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell */ 588e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public void dismissPopupMenus() { 589e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (mMenuView != null) { 590e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mMenuView.dismissPopupMenus(); 591e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 592e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 593e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 594e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell /** @hide */ 595e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public boolean isTitleTruncated() { 596e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (mTitleTextView == null) { 597e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return false; 598e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 599e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 600e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final Layout titleLayout = mTitleTextView.getLayout(); 601e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (titleLayout == null) { 602e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return false; 603e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 604e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 605e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final int lineCount = titleLayout.getLineCount(); 606e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell for (int i = 0; i < lineCount; i++) { 607e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (titleLayout.getEllipsisCount(i) > 0) { 608e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return true; 609e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 610e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 611e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return false; 612e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 613e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 614e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 615e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Set a logo drawable. 616e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 617e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>This drawable should generally take the place of title text. The logo cannot be 618e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * clicked. Apps using a logo should also supply a description using 619e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * {@link #setLogoDescription(int)}.</p> 620e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 621e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param drawable Drawable to use as a logo 622e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 623e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public void setLogo(Drawable drawable) { 624e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (drawable != null) { 625e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell ensureLogoView(); 6265f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell if (!isChildOrHidden(mLogoView)) { 6275f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell addSystemView(mLogoView, true); 628e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 6295f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell } else if (mLogoView != null && isChildOrHidden(mLogoView)) { 630e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell removeView(mLogoView); 6315f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell mHiddenViews.remove(mLogoView); 632e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 633e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (mLogoView != null) { 634e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mLogoView.setImageDrawable(drawable); 635e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 636e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 637e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 638e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 639e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Return the current logo drawable. 640e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 641e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @return The current logo drawable 642e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @see #setLogo(int) 643e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @see #setLogo(android.graphics.drawable.Drawable) 644e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 645e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public Drawable getLogo() { 646e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return mLogoView != null ? mLogoView.getDrawable() : null; 647e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 648e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 649e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 650e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Set a description of the toolbar's logo. 651e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 652e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>This description will be used for accessibility or other similar descriptions 653e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * of the UI.</p> 654e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 655e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param resId String resource id 656e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 657417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbye public void setLogoDescription(@StringRes int resId) { 658e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell setLogoDescription(getContext().getText(resId)); 659e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 660e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 661e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 662e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Set a description of the toolbar's logo. 663e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 664e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>This description will be used for accessibility or other similar descriptions 665e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * of the UI.</p> 666e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 667e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param description Description to set 668e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 669e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public void setLogoDescription(CharSequence description) { 670e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (!TextUtils.isEmpty(description)) { 671e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell ensureLogoView(); 672e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 673e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (mLogoView != null) { 674e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mLogoView.setContentDescription(description); 675e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 676e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 677e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 678e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 679e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Return the description of the toolbar's logo. 680e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 681e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @return A description of the logo 682e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 683e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public CharSequence getLogoDescription() { 684e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return mLogoView != null ? mLogoView.getContentDescription() : null; 685e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 686e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 687e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private void ensureLogoView() { 688e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (mLogoView == null) { 689e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mLogoView = new ImageView(getContext()); 690e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 691e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 692e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 693e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 694e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * Check whether this Toolbar is currently hosting an expanded action view. 695e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 696e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * <p>An action view may be expanded either directly from the 697e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * {@link android.view.MenuItem MenuItem} it belongs to or by user action. If the Toolbar 698e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * has an expanded action view it can be collapsed using the {@link #collapseActionView()} 699e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * method.</p> 700e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * 701e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * @return true if the Toolbar has an expanded action view 702e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell */ 703e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public boolean hasExpandedActionView() { 704e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return mExpandedMenuPresenter != null && 705e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mExpandedMenuPresenter.mCurrentExpandedItem != null; 706e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 707e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 708e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell /** 709e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * Collapse a currently expanded action view. If this Toolbar does not have an 710e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * expanded action view this method has no effect. 711e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * 712e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * <p>An action view may be expanded either directly from the 713e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * {@link android.view.MenuItem MenuItem} it belongs to or by user action.</p> 714e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * 715e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * @see #hasExpandedActionView() 716e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell */ 717e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public void collapseActionView() { 718e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final MenuItemImpl item = mExpandedMenuPresenter == null ? null : 719e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mExpandedMenuPresenter.mCurrentExpandedItem; 720e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (item != null) { 721e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell item.collapseActionView(); 722e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 723e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 724e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 725e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell /** 726e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * Returns the title of this toolbar. 727e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * 728e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * @return The current title. 729e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 730e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public CharSequence getTitle() { 731e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return mTitleText; 732e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 733e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 734e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 735e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Set the title of this toolbar. 736e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 737e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>A title should be used as the anchor for a section of content. It should 738e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * describe or name the content being viewed.</p> 739e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 740e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param resId Resource ID of a string to set as the title 741e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 742417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbye public void setTitle(@StringRes int resId) { 743e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell setTitle(getContext().getText(resId)); 744e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 745e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 746e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 747e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Set the title of this toolbar. 748e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 749e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>A title should be used as the anchor for a section of content. It should 750e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * describe or name the content being viewed.</p> 751e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 752e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param title Title to set 753e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 754e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public void setTitle(CharSequence title) { 755e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (!TextUtils.isEmpty(title)) { 756e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (mTitleTextView == null) { 757e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final Context context = getContext(); 758e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mTitleTextView = new TextView(context); 759e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mTitleTextView.setSingleLine(); 760e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mTitleTextView.setEllipsize(TextUtils.TruncateAt.END); 7611a264ce3d915b187b71101436bec3328c76288b0Adam Powell if (mTitleTextAppearance != 0) { 762bb98ebd6b15f4cf942b156892988801c95601f2fAlan Viverette mTitleTextView.setTextAppearance(mTitleTextAppearance); 7631a264ce3d915b187b71101436bec3328c76288b0Adam Powell } 7641a264ce3d915b187b71101436bec3328c76288b0Adam Powell if (mTitleTextColor != 0) { 7651a264ce3d915b187b71101436bec3328c76288b0Adam Powell mTitleTextView.setTextColor(mTitleTextColor); 7661a264ce3d915b187b71101436bec3328c76288b0Adam Powell } 767e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 7685f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell if (!isChildOrHidden(mTitleTextView)) { 7695f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell addSystemView(mTitleTextView, true); 770e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 7715f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell } else if (mTitleTextView != null && isChildOrHidden(mTitleTextView)) { 772e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell removeView(mTitleTextView); 7735f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell mHiddenViews.remove(mTitleTextView); 774e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 775e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (mTitleTextView != null) { 776e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mTitleTextView.setText(title); 777e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 778e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mTitleText = title; 779e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 780e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 781e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 782e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Return the subtitle of this toolbar. 783e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 784e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @return The current subtitle 785e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 786e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public CharSequence getSubtitle() { 787e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return mSubtitleText; 788e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 789e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 790e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 791e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Set the subtitle of this toolbar. 792e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 793e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>Subtitles should express extended information about the current content.</p> 794e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 795e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param resId String resource ID 796e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 797417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbye public void setSubtitle(@StringRes int resId) { 798e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell setSubtitle(getContext().getText(resId)); 799e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 800e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 801e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 802e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Set the subtitle of this toolbar. 803e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 804e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>Subtitles should express extended information about the current content.</p> 805e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 806e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param subtitle Subtitle to set 807e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 808e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public void setSubtitle(CharSequence subtitle) { 809e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (!TextUtils.isEmpty(subtitle)) { 810e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (mSubtitleTextView == null) { 811e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final Context context = getContext(); 812e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mSubtitleTextView = new TextView(context); 813e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mSubtitleTextView.setSingleLine(); 814e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mSubtitleTextView.setEllipsize(TextUtils.TruncateAt.END); 8151a264ce3d915b187b71101436bec3328c76288b0Adam Powell if (mSubtitleTextAppearance != 0) { 816bb98ebd6b15f4cf942b156892988801c95601f2fAlan Viverette mSubtitleTextView.setTextAppearance(mSubtitleTextAppearance); 8171a264ce3d915b187b71101436bec3328c76288b0Adam Powell } 8181a264ce3d915b187b71101436bec3328c76288b0Adam Powell if (mSubtitleTextColor != 0) { 8191a264ce3d915b187b71101436bec3328c76288b0Adam Powell mSubtitleTextView.setTextColor(mSubtitleTextColor); 8201a264ce3d915b187b71101436bec3328c76288b0Adam Powell } 821e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 8225f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell if (!isChildOrHidden(mSubtitleTextView)) { 8235f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell addSystemView(mSubtitleTextView, true); 824e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 8255f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell } else if (mSubtitleTextView != null && isChildOrHidden(mSubtitleTextView)) { 826e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell removeView(mSubtitleTextView); 8275f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell mHiddenViews.remove(mSubtitleTextView); 828e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 829e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (mSubtitleTextView != null) { 830e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mSubtitleTextView.setText(subtitle); 831e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 832e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mSubtitleText = subtitle; 833e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 834e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 835e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 836ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell * Sets the text color, size, style, hint color, and highlight color 837ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell * from the specified TextAppearance resource. 838ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell */ 839417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbye public void setTitleTextAppearance(Context context, @StyleRes int resId) { 840ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell mTitleTextAppearance = resId; 841ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell if (mTitleTextView != null) { 842bb98ebd6b15f4cf942b156892988801c95601f2fAlan Viverette mTitleTextView.setTextAppearance(resId); 843ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell } 844ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell } 845ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell 846ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell /** 847ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell * Sets the text color, size, style, hint color, and highlight color 848ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell * from the specified TextAppearance resource. 849ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell */ 850417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbye public void setSubtitleTextAppearance(Context context, @StyleRes int resId) { 851ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell mSubtitleTextAppearance = resId; 852ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell if (mSubtitleTextView != null) { 853bb98ebd6b15f4cf942b156892988801c95601f2fAlan Viverette mSubtitleTextView.setTextAppearance(resId); 854ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell } 855ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell } 856ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell 857ebba5d4edd763b19124b715a0f084d2f00c84a47Adam Powell /** 8581a264ce3d915b187b71101436bec3328c76288b0Adam Powell * Sets the text color of the title, if present. 8591a264ce3d915b187b71101436bec3328c76288b0Adam Powell * 8601a264ce3d915b187b71101436bec3328c76288b0Adam Powell * @param color The new text color in 0xAARRGGBB format 8611a264ce3d915b187b71101436bec3328c76288b0Adam Powell */ 86280756e38882720860db52f1fcc21fa1505a02abfTor Norbye public void setTitleTextColor(@ColorInt int color) { 8631a264ce3d915b187b71101436bec3328c76288b0Adam Powell mTitleTextColor = color; 8641a264ce3d915b187b71101436bec3328c76288b0Adam Powell if (mTitleTextView != null) { 8651a264ce3d915b187b71101436bec3328c76288b0Adam Powell mTitleTextView.setTextColor(color); 8661a264ce3d915b187b71101436bec3328c76288b0Adam Powell } 8671a264ce3d915b187b71101436bec3328c76288b0Adam Powell } 8681a264ce3d915b187b71101436bec3328c76288b0Adam Powell 8691a264ce3d915b187b71101436bec3328c76288b0Adam Powell /** 8701a264ce3d915b187b71101436bec3328c76288b0Adam Powell * Sets the text color of the subtitle, if present. 8711a264ce3d915b187b71101436bec3328c76288b0Adam Powell * 8721a264ce3d915b187b71101436bec3328c76288b0Adam Powell * @param color The new text color in 0xAARRGGBB format 8731a264ce3d915b187b71101436bec3328c76288b0Adam Powell */ 87480756e38882720860db52f1fcc21fa1505a02abfTor Norbye public void setSubtitleTextColor(@ColorInt int color) { 8751a264ce3d915b187b71101436bec3328c76288b0Adam Powell mSubtitleTextColor = color; 8761a264ce3d915b187b71101436bec3328c76288b0Adam Powell if (mSubtitleTextView != null) { 8771a264ce3d915b187b71101436bec3328c76288b0Adam Powell mSubtitleTextView.setTextColor(color); 8781a264ce3d915b187b71101436bec3328c76288b0Adam Powell } 8791a264ce3d915b187b71101436bec3328c76288b0Adam Powell } 8801a264ce3d915b187b71101436bec3328c76288b0Adam Powell 8811a264ce3d915b187b71101436bec3328c76288b0Adam Powell /** 8827901b2a54981b769bf27852c41ce612871a8e019Adam Powell * Retrieve the currently configured content description for the navigation button view. 8837901b2a54981b769bf27852c41ce612871a8e019Adam Powell * This will be used to describe the navigation action to users through mechanisms such 8847901b2a54981b769bf27852c41ce612871a8e019Adam Powell * as screen readers or tooltips. 8857901b2a54981b769bf27852c41ce612871a8e019Adam Powell * 8867901b2a54981b769bf27852c41ce612871a8e019Adam Powell * @return The navigation button's content description 887d760249623a57d35dc0b4e57972eb9a72934d500Adam Powell * 888d760249623a57d35dc0b4e57972eb9a72934d500Adam Powell * @attr ref android.R.styleable#Toolbar_navigationContentDescription 8897901b2a54981b769bf27852c41ce612871a8e019Adam Powell */ 890e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette @Nullable 8917901b2a54981b769bf27852c41ce612871a8e019Adam Powell public CharSequence getNavigationContentDescription() { 8927901b2a54981b769bf27852c41ce612871a8e019Adam Powell return mNavButtonView != null ? mNavButtonView.getContentDescription() : null; 8937901b2a54981b769bf27852c41ce612871a8e019Adam Powell } 8947901b2a54981b769bf27852c41ce612871a8e019Adam Powell 8957901b2a54981b769bf27852c41ce612871a8e019Adam Powell /** 896e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * Set a content description for the navigation button if one is present. The content 897e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * description will be read via screen readers or other accessibility systems to explain 898e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * the action of the navigation button. 899e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * 900e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * @param resId Resource ID of a content description string to set, or 0 to 901e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * clear the description 902d760249623a57d35dc0b4e57972eb9a72934d500Adam Powell * 903d760249623a57d35dc0b4e57972eb9a72934d500Adam Powell * @attr ref android.R.styleable#Toolbar_navigationContentDescription 904e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell */ 905417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbye public void setNavigationContentDescription(@StringRes int resId) { 906e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette setNavigationContentDescription(resId != 0 ? getContext().getText(resId) : null); 907e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 908e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 909e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell /** 910e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * Set a content description for the navigation button if one is present. The content 911e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * description will be read via screen readers or other accessibility systems to explain 912e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * the action of the navigation button. 913e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell * 914e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * @param description Content description to set, or <code>null</code> to 915e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * clear the content description 916d760249623a57d35dc0b4e57972eb9a72934d500Adam Powell * 917d760249623a57d35dc0b4e57972eb9a72934d500Adam Powell * @attr ref android.R.styleable#Toolbar_navigationContentDescription 918e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell */ 919e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette public void setNavigationContentDescription(@Nullable CharSequence description) { 920e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette if (!TextUtils.isEmpty(description)) { 921e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette ensureNavButtonView(); 922e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette } 923e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette if (mNavButtonView != null) { 924e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette mNavButtonView.setContentDescription(description); 925e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette } 926e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette } 927e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette 928e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette /** 929e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * Set the icon to use for the toolbar's navigation button. 930e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * 931e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * <p>The navigation button appears at the start of the toolbar if present. Setting an icon 932e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * will make the navigation button visible.</p> 933e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * 934e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * <p>If you use a navigation icon you should also set a description for its action using 935e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * {@link #setNavigationContentDescription(int)}. This is used for accessibility and 936e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * tooltips.</p> 937e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * 938e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * @param resId Resource ID of a drawable to set 939d760249623a57d35dc0b4e57972eb9a72934d500Adam Powell * 940d760249623a57d35dc0b4e57972eb9a72934d500Adam Powell * @attr ref android.R.styleable#Toolbar_navigationIcon 941e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette */ 942417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbye public void setNavigationIcon(@DrawableRes int resId) { 943e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette setNavigationIcon(getContext().getDrawable(resId)); 944e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 945e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 946e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell /** 947e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Set the icon to use for the toolbar's navigation button. 948e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 949e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>The navigation button appears at the start of the toolbar if present. Setting an icon 950e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * will make the navigation button visible.</p> 951e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 952e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>If you use a navigation icon you should also set a description for its action using 953e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * {@link #setNavigationContentDescription(int)}. This is used for accessibility and 954e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * tooltips.</p> 955e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 956e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette * @param icon Drawable to set, may be null to clear the icon 957d760249623a57d35dc0b4e57972eb9a72934d500Adam Powell * 958d760249623a57d35dc0b4e57972eb9a72934d500Adam Powell * @attr ref android.R.styleable#Toolbar_navigationIcon 959e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 960e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette public void setNavigationIcon(@Nullable Drawable icon) { 961e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (icon != null) { 962e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell ensureNavButtonView(); 9635f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell if (!isChildOrHidden(mNavButtonView)) { 9645f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell addSystemView(mNavButtonView, true); 965e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 9665f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell } else if (mNavButtonView != null && isChildOrHidden(mNavButtonView)) { 967e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell removeView(mNavButtonView); 9685f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell mHiddenViews.remove(mNavButtonView); 969e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 970e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (mNavButtonView != null) { 971e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mNavButtonView.setImageDrawable(icon); 972e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 973e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 974e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 975e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 976e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Return the current drawable used as the navigation icon. 977e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 978e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @return The navigation icon drawable 979d760249623a57d35dc0b4e57972eb9a72934d500Adam Powell * 980d760249623a57d35dc0b4e57972eb9a72934d500Adam Powell * @attr ref android.R.styleable#Toolbar_navigationIcon 981e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 982e88700a2ad69e9b99824f2de3d8ba3d44054b24cAlan Viverette @Nullable 983e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public Drawable getNavigationIcon() { 984e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return mNavButtonView != null ? mNavButtonView.getDrawable() : null; 985e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 986e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 987e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 988e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Set a listener to respond to navigation events. 989e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 990e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>This listener will be called whenever the user clicks the navigation button 991e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * at the start of the toolbar. An icon must be set for the navigation button to appear.</p> 992e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 993e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param listener Listener to set 994e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @see #setNavigationIcon(android.graphics.drawable.Drawable) 995e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 996e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public void setNavigationOnClickListener(OnClickListener listener) { 997e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell ensureNavButtonView(); 998e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mNavButtonView.setOnClickListener(listener); 999e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1000e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1001e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 100267960a0a555808eaf512454f0a344c672c398292Kirill Grouchnikov * @hide 100367960a0a555808eaf512454f0a344c672c398292Kirill Grouchnikov */ 100467960a0a555808eaf512454f0a344c672c398292Kirill Grouchnikov @Nullable 100567960a0a555808eaf512454f0a344c672c398292Kirill Grouchnikov @TestApi 100667960a0a555808eaf512454f0a344c672c398292Kirill Grouchnikov public View getNavigationView() { 100767960a0a555808eaf512454f0a344c672c398292Kirill Grouchnikov return mNavButtonView; 100867960a0a555808eaf512454f0a344c672c398292Kirill Grouchnikov } 100967960a0a555808eaf512454f0a344c672c398292Kirill Grouchnikov 101067960a0a555808eaf512454f0a344c672c398292Kirill Grouchnikov /** 1011a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes * Return the Menu shown in the toolbar. 10129cc36ca1b520c06f882e84b909f3a2b75d303a06Chris Banes * 1013a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes * <p>Applications that wish to populate the toolbar's menu can do so from here. To use 1014a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes * an XML menu resource, use {@link #inflateMenu(int)}.</p> 10159cc36ca1b520c06f882e84b909f3a2b75d303a06Chris Banes * 1016a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes * @return The toolbar's Menu 10179cc36ca1b520c06f882e84b909f3a2b75d303a06Chris Banes */ 1018a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes public Menu getMenu() { 1019a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes ensureMenu(); 1020a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes return mMenuView.getMenu(); 10219cc36ca1b520c06f882e84b909f3a2b75d303a06Chris Banes } 10229cc36ca1b520c06f882e84b909f3a2b75d303a06Chris Banes 10239cc36ca1b520c06f882e84b909f3a2b75d303a06Chris Banes /** 1024a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes * Set the icon to use for the overflow button. 10259cc36ca1b520c06f882e84b909f3a2b75d303a06Chris Banes * 1026a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes * @param icon Drawable to set, may be null to clear the icon 10279cc36ca1b520c06f882e84b909f3a2b75d303a06Chris Banes */ 1028a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes public void setOverflowIcon(@Nullable Drawable icon) { 1029a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes ensureMenu(); 1030a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes mMenuView.setOverflowIcon(icon); 10319cc36ca1b520c06f882e84b909f3a2b75d303a06Chris Banes } 10329cc36ca1b520c06f882e84b909f3a2b75d303a06Chris Banes 10339cc36ca1b520c06f882e84b909f3a2b75d303a06Chris Banes /** 1034a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes * Return the current drawable used as the overflow icon. 1035e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 1036a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes * @return The overflow icon drawable 1037e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 1038a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes @Nullable 1039a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes public Drawable getOverflowIcon() { 104007a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell ensureMenu(); 1041a41b78973db3dfde159f7d641f794f462ad323d3Chris Banes return mMenuView.getOverflowIcon(); 1042e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 1043e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 104407a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell private void ensureMenu() { 104507a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell ensureMenuView(); 104607a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell if (mMenuView.peekMenu() == null) { 104707a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell // Initialize a new menu for the first time. 104807a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell final MenuBuilder menu = (MenuBuilder) mMenuView.getMenu(); 104907a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell if (mExpandedMenuPresenter == null) { 105007a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter(); 105107a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell } 105207a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell mMenuView.setExpandedActionViewsExclusive(true); 10533d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette menu.addMenuPresenter(mExpandedMenuPresenter, mPopupContext); 105407a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell } 105507a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell } 105607a74548ae5c1e064508cb1c79ac34de1142b240Adam Powell 1057e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private void ensureMenuView() { 1058e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (mMenuView == null) { 1059e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mMenuView = new ActionMenuView(getContext()); 10603d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette mMenuView.setPopupTheme(mPopupTheme); 1061e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mMenuView.setOnMenuItemClickListener(mMenuViewItemClickListener); 1062c46125042493e66f7dfdccec24e3b0739600b194Adam Powell mMenuView.setMenuCallbacks(mActionMenuPresenterCallback, mMenuBuilderCallback); 1063e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final LayoutParams lp = generateDefaultLayoutParams(); 1064e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell lp.gravity = Gravity.END | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK); 1065e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mMenuView.setLayoutParams(lp); 10665f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell addSystemView(mMenuView, false); 1067e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1068e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1069e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1070e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private MenuInflater getMenuInflater() { 1071e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return new MenuInflater(getContext()); 1072e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1073e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1074e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 1075e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Inflate a menu resource into this toolbar. 1076e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 1077e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>Inflate an XML menu resource into this toolbar. Existing items in the menu will not 1078e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * be modified or removed.</p> 1079e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 1080e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param resId ID of a menu resource to inflate 1081e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 1082417ee5ba89f7e0fe5efd34fce74bf1ee5923d976Tor Norbye public void inflateMenu(@MenuRes int resId) { 1083e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell getMenuInflater().inflate(resId, getMenu()); 1084e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1085e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1086e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 1087e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Set a listener to respond to menu item click events. 1088e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 1089e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * <p>This listener will be invoked whenever a user selects a menu item from 1090e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * the action buttons presented at the end of the toolbar or the associated overflow.</p> 1091e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 1092e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param listener Listener to set 1093e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 1094e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public void setOnMenuItemClickListener(OnMenuItemClickListener listener) { 1095e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mOnMenuItemClickListener = listener; 1096e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1097e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 109876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell /** 1099679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Sets the content insets for this toolbar relative to layout direction. 110076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 110176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * <p>The content inset affects the valid area for Toolbar content other than 110276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * the navigation button and menu. Insets define the minimum margin for these components 110376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * and can be used to effectively align Toolbar content along well-known gridlines.</p> 110476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 110576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @param contentInsetStart Content inset for the toolbar starting edge 110676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @param contentInsetEnd Content inset for the toolbar ending edge 110776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 110876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #setContentInsetsAbsolute(int, int) 110976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetStart() 111076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetEnd() 111176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetLeft() 111276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetRight() 1113679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetEnd 1114679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetStart 111576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell */ 111676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public void setContentInsetsRelative(int contentInsetStart, int contentInsetEnd) { 11173b925c1ab092cf63329845ecad73aa58db24c86dChris Banes ensureContentInsets(); 111876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mContentInsets.setRelative(contentInsetStart, contentInsetEnd); 111976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 112076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 112176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell /** 1122679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Gets the starting content inset for this toolbar. 112376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 112476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * <p>The content inset affects the valid area for Toolbar content other than 112576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * the navigation button and menu. Insets define the minimum margin for these components 112676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * and can be used to effectively align Toolbar content along well-known gridlines.</p> 112776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 112876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @return The starting content inset for this toolbar 112976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 113076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #setContentInsetsRelative(int, int) 113176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #setContentInsetsAbsolute(int, int) 113276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetEnd() 113376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetLeft() 113476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetRight() 1135679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetStart 113676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell */ 113776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public int getContentInsetStart() { 11383b925c1ab092cf63329845ecad73aa58db24c86dChris Banes return mContentInsets != null ? mContentInsets.getStart() : 0; 113976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 114076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 114176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell /** 1142679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Gets the ending content inset for this toolbar. 114376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 114476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * <p>The content inset affects the valid area for Toolbar content other than 114576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * the navigation button and menu. Insets define the minimum margin for these components 114676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * and can be used to effectively align Toolbar content along well-known gridlines.</p> 114776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 114876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @return The ending content inset for this toolbar 114976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 115076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #setContentInsetsRelative(int, int) 115176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #setContentInsetsAbsolute(int, int) 115276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetStart() 115376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetLeft() 115476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetRight() 1155679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetEnd 115676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell */ 115776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public int getContentInsetEnd() { 11583b925c1ab092cf63329845ecad73aa58db24c86dChris Banes return mContentInsets != null ? mContentInsets.getEnd() : 0; 115976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 116076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 116176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell /** 1162679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Sets the content insets for this toolbar. 116376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 116476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * <p>The content inset affects the valid area for Toolbar content other than 116576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * the navigation button and menu. Insets define the minimum margin for these components 116676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * and can be used to effectively align Toolbar content along well-known gridlines.</p> 116776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 116876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @param contentInsetLeft Content inset for the toolbar's left edge 116976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @param contentInsetRight Content inset for the toolbar's right edge 117076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 117176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #setContentInsetsAbsolute(int, int) 117276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetStart() 117376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetEnd() 117476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetLeft() 117576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetRight() 1176679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetLeft 1177679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetRight 117876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell */ 117976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public void setContentInsetsAbsolute(int contentInsetLeft, int contentInsetRight) { 11803b925c1ab092cf63329845ecad73aa58db24c86dChris Banes ensureContentInsets(); 118176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell mContentInsets.setAbsolute(contentInsetLeft, contentInsetRight); 118276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 118376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 118476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell /** 1185679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Gets the left content inset for this toolbar. 118676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 118776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * <p>The content inset affects the valid area for Toolbar content other than 118876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * the navigation button and menu. Insets define the minimum margin for these components 118976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * and can be used to effectively align Toolbar content along well-known gridlines.</p> 119076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 119176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @return The left content inset for this toolbar 119276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 119376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #setContentInsetsRelative(int, int) 119476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #setContentInsetsAbsolute(int, int) 119576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetStart() 119676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetEnd() 119776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetRight() 1198679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetLeft 119976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell */ 120076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public int getContentInsetLeft() { 12013b925c1ab092cf63329845ecad73aa58db24c86dChris Banes return mContentInsets != null ? mContentInsets.getLeft() : 0; 120276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 120376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 120476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell /** 1205679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Gets the right content inset for this toolbar. 120676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 120776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * <p>The content inset affects the valid area for Toolbar content other than 120876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * the navigation button and menu. Insets define the minimum margin for these components 120976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * and can be used to effectively align Toolbar content along well-known gridlines.</p> 121076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 121176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @return The right content inset for this toolbar 121276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * 121376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #setContentInsetsRelative(int, int) 121476d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #setContentInsetsAbsolute(int, int) 121576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetStart() 121676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetEnd() 121776d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell * @see #getContentInsetLeft() 1218679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetRight 121976d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell */ 122076d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell public int getContentInsetRight() { 12213b925c1ab092cf63329845ecad73aa58db24c86dChris Banes return mContentInsets != null ? mContentInsets.getRight() : 0; 122276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell } 122376d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 1224679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell /** 1225679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Gets the start content inset to use when a navigation button is present. 1226679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1227679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * <p>Different content insets are often called for when additional buttons are present 1228679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * in the toolbar, as well as at different toolbar sizes. The larger value of 1229679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * {@link #getContentInsetStart()} and this value will be used during layout.</p> 1230679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1231679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @return the start content inset used when a navigation icon has been set in pixels 1232679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1233679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @see #setContentInsetStartWithNavigation(int) 1234679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetStartWithNavigation 1235679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell */ 1236679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell public int getContentInsetStartWithNavigation() { 1237679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell return mContentInsetStartWithNavigation != RtlSpacingHelper.UNDEFINED 1238679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell ? mContentInsetStartWithNavigation 1239679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell : getContentInsetStart(); 1240679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1241679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell 1242679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell /** 1243679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Sets the start content inset to use when a navigation button is present. 1244679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1245679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * <p>Different content insets are often called for when additional buttons are present 1246679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * in the toolbar, as well as at different toolbar sizes. The larger value of 1247679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * {@link #getContentInsetStart()} and this value will be used during layout.</p> 1248679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1249679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @param insetStartWithNavigation the inset to use when a navigation icon has been set 1250679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * in pixels 1251679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1252679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @see #getContentInsetStartWithNavigation() 1253679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetStartWithNavigation 1254679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell */ 1255679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell public void setContentInsetStartWithNavigation(int insetStartWithNavigation) { 1256679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell if (insetStartWithNavigation < 0) { 1257679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell insetStartWithNavigation = RtlSpacingHelper.UNDEFINED; 1258679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1259679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell if (insetStartWithNavigation != mContentInsetStartWithNavigation) { 1260679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell mContentInsetStartWithNavigation = insetStartWithNavigation; 1261679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell if (getNavigationIcon() != null) { 1262679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell requestLayout(); 1263679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1264679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1265679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1266679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell 1267679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell /** 1268679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Gets the end content inset to use when action buttons are present. 1269679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1270679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * <p>Different content insets are often called for when additional buttons are present 1271679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * in the toolbar, as well as at different toolbar sizes. The larger value of 1272679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * {@link #getContentInsetEnd()} and this value will be used during layout.</p> 1273679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1274679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @return the end content inset used when a menu has been set in pixels 1275679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1276679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @see #setContentInsetEndWithActions(int) 1277679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetEndWithActions 1278679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell */ 1279679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell public int getContentInsetEndWithActions() { 1280679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell return mContentInsetEndWithActions != RtlSpacingHelper.UNDEFINED 1281679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell ? mContentInsetEndWithActions 1282679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell : getContentInsetEnd(); 1283679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1284679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell 1285679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell /** 1286679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Sets the start content inset to use when action buttons are present. 1287679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1288679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * <p>Different content insets are often called for when additional buttons are present 1289679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * in the toolbar, as well as at different toolbar sizes. The larger value of 1290679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * {@link #getContentInsetEnd()} and this value will be used during layout.</p> 1291679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1292679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @param insetEndWithActions the inset to use when a menu has been set in pixels 1293679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1294679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @see #setContentInsetEndWithActions(int) 1295679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @attr ref android.R.styleable#Toolbar_contentInsetEndWithActions 1296679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell */ 1297679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell public void setContentInsetEndWithActions(int insetEndWithActions) { 1298679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell if (insetEndWithActions < 0) { 1299679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell insetEndWithActions = RtlSpacingHelper.UNDEFINED; 1300679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1301679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell if (insetEndWithActions != mContentInsetEndWithActions) { 1302679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell mContentInsetEndWithActions = insetEndWithActions; 1303679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell if (getNavigationIcon() != null) { 1304679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell requestLayout(); 1305679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1306679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1307679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1308679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell 1309679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell /** 1310679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Gets the content inset that will be used on the starting side of the bar in the current 1311679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * toolbar configuration. 1312679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1313679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @return the current content inset start in pixels 1314679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1315679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @see #getContentInsetStartWithNavigation() 1316679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell */ 1317679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell public int getCurrentContentInsetStart() { 1318679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell return getNavigationIcon() != null 1319679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell ? Math.max(getContentInsetStart(), Math.max(mContentInsetStartWithNavigation, 0)) 1320679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell : getContentInsetStart(); 1321679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1322679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell 1323679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell /** 1324679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Gets the content inset that will be used on the ending side of the bar in the current 1325679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * toolbar configuration. 1326679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1327679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @return the current content inset end in pixels 1328679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1329679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @see #getContentInsetEndWithActions() 1330679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell */ 1331679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell public int getCurrentContentInsetEnd() { 1332679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell boolean hasActions = false; 1333679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell if (mMenuView != null) { 1334679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell final MenuBuilder mb = mMenuView.peekMenu(); 1335679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell hasActions = mb != null && mb.hasVisibleItems(); 1336679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1337679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell return hasActions 1338679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell ? Math.max(getContentInsetEnd(), Math.max(mContentInsetEndWithActions, 0)) 1339679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell : getContentInsetEnd(); 1340679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1341679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell 1342679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell /** 1343679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Gets the content inset that will be used on the left side of the bar in the current 1344679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * toolbar configuration. 1345679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1346679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @return the current content inset left in pixels 1347679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1348679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @see #getContentInsetStartWithNavigation() 1349679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @see #getContentInsetEndWithActions() 1350679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell */ 1351679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell public int getCurrentContentInsetLeft() { 1352679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell return isLayoutRtl() 1353679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell ? getCurrentContentInsetEnd() 1354679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell : getCurrentContentInsetStart(); 1355679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1356679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell 1357679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell /** 1358679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * Gets the content inset that will be used on the right side of the bar in the current 1359679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * toolbar configuration. 1360679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1361679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @return the current content inset right in pixels 1362679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * 1363679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @see #getContentInsetStartWithNavigation() 1364679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell * @see #getContentInsetEndWithActions() 1365679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell */ 1366679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell public int getCurrentContentInsetRight() { 1367679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell return isLayoutRtl() 1368679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell ? getCurrentContentInsetStart() 1369679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell : getCurrentContentInsetEnd(); 1370679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell } 1371679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell 1372e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private void ensureNavButtonView() { 1373e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (mNavButtonView == null) { 1374e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mNavButtonView = new ImageButton(getContext(), null, 0, mNavButtonStyle); 1375e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final LayoutParams lp = generateDefaultLayoutParams(); 1376e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell lp.gravity = Gravity.START | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK); 1377e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mNavButtonView.setLayoutParams(lp); 1378e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 1379e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 1380e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 1381e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private void ensureCollapseButtonView() { 1382e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (mCollapseButtonView == null) { 1383e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mCollapseButtonView = new ImageButton(getContext(), null, 0, mNavButtonStyle); 1384e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mCollapseButtonView.setImageDrawable(mCollapseIcon); 138585085343b378f00a34448b69e582226fa584b005Alan Viverette mCollapseButtonView.setContentDescription(mCollapseDescription); 1386e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final LayoutParams lp = generateDefaultLayoutParams(); 1387e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell lp.gravity = Gravity.START | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK); 1388e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell lp.mViewType = LayoutParams.EXPANDED; 1389e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mCollapseButtonView.setLayoutParams(lp); 1390e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mCollapseButtonView.setOnClickListener(new OnClickListener() { 1391e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell @Override 1392e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public void onClick(View v) { 1393e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell collapseActionView(); 1394e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 1395e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell }); 1396e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1397e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1398e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 13995f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell private void addSystemView(View v, boolean allowHide) { 1400e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette final ViewGroup.LayoutParams vlp = v.getLayoutParams(); 1401e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette final LayoutParams lp; 1402e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette if (vlp == null) { 1403e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette lp = generateDefaultLayoutParams(); 1404e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette } else if (!checkLayoutParams(vlp)) { 1405e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette lp = generateLayoutParams(vlp); 1406e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette } else { 1407e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette lp = (LayoutParams) vlp; 1408e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette } 1409e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell lp.mViewType = LayoutParams.SYSTEM; 14105f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell 14115f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell if (allowHide && mExpandedActionView != null) { 14125f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell v.setLayoutParams(lp); 14135f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell mHiddenViews.add(v); 14145f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell } else { 14155f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell addView(v, lp); 14165f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell } 1417e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1418e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1419e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell @Override 1420e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell protected Parcelable onSaveInstanceState() { 1421e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell SavedState state = new SavedState(super.onSaveInstanceState()); 142231c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell 142331c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell if (mExpandedMenuPresenter != null && mExpandedMenuPresenter.mCurrentExpandedItem != null) { 142431c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell state.expandedMenuItemId = mExpandedMenuPresenter.mCurrentExpandedItem.getItemId(); 142531c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell } 142631c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell 142731c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell state.isOverflowOpen = isOverflowMenuShowing(); 142831c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell 1429e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return state; 1430e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1431e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1432e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell @Override 1433e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell protected void onRestoreInstanceState(Parcelable state) { 1434e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final SavedState ss = (SavedState) state; 1435e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell super.onRestoreInstanceState(ss.getSuperState()); 143631c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell 143731c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell final Menu menu = mMenuView != null ? mMenuView.peekMenu() : null; 143831c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell if (ss.expandedMenuItemId != 0 && mExpandedMenuPresenter != null && menu != null) { 143931c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell final MenuItem item = menu.findItem(ss.expandedMenuItemId); 144031c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell if (item != null) { 144131c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell item.expandActionView(); 144231c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell } 144331c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell } 144431c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell 144531c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell if (ss.isOverflowOpen) { 144631c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell postShowOverflowMenu(); 144731c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell } 144831c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell } 144931c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell 145031c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell private void postShowOverflowMenu() { 145131c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell removeCallbacks(mShowOverflowMenuRunnable); 145231c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell post(mShowOverflowMenuRunnable); 145331c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell } 145431c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell 145531c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell @Override 145631c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell protected void onDetachedFromWindow() { 145731c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell super.onDetachedFromWindow(); 145831c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell removeCallbacks(mShowOverflowMenuRunnable); 1459e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1460e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 146161d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell @Override 146261d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell public boolean onTouchEvent(MotionEvent ev) { 146361d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell // Toolbars always eat touch events, but should still respect the touch event dispatch 146461d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell // contract. If the normal View implementation doesn't want the events, we'll just silently 146561d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell // eat the rest of the gesture without reporting the events to the default implementation 146661d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell // since that's what it expects. 146761d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell 146861d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell final int action = ev.getActionMasked(); 146961d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell if (action == MotionEvent.ACTION_DOWN) { 147061d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell mEatingTouch = false; 147161d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell } 147261d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell 147361d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell if (!mEatingTouch) { 147461d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell final boolean handled = super.onTouchEvent(ev); 147561d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell if (action == MotionEvent.ACTION_DOWN && !handled) { 147661d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell mEatingTouch = true; 147761d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell } 147861d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell } 147961d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell 148061d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { 148161d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell mEatingTouch = false; 148261d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell } 148361d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell 148461d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell return true; 148561d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell } 148661d15b98561ab500ccaec5d21d98c8c0ea3ae47fAdam Powell 1487eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell /** 1488eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell * @hide 1489eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell */ 1490eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell @Override 1491eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell protected void onSetLayoutParams(View child, ViewGroup.LayoutParams lp) { 1492eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell /* 1493eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell * Apps may set ActionBar.LayoutParams on their action bar custom views when 1494eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell * a Toolbar is actually acting in the role of the action bar. Perform a quick 1495eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell * switch with Toolbar.LayoutParams whenever this happens. This does leave open 1496eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell * one potential gotcha: if an app retains the ActionBar.LayoutParams reference 1497eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell * and attempts to keep making changes to it before layout those changes won't 1498eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell * be reflected in the final results. 1499eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell */ 1500eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell if (!checkLayoutParams(lp)) { 1501eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell child.setLayoutParams(generateLayoutParams(lp)); 1502eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell } 1503eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell } 1504eb97f473fc075c91760c2b657a7014681cd6f3ceAdam Powell 1505e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private void measureChildConstrained(View child, int parentWidthSpec, int widthUsed, 1506e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell int parentHeightSpec, int heightUsed, int heightConstraint) { 1507e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); 1508e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 1509e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell int childWidthSpec = getChildMeasureSpec(parentWidthSpec, 1510e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mPaddingLeft + mPaddingRight + lp.leftMargin + lp.rightMargin 1511e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell + widthUsed, lp.width); 1512e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell int childHeightSpec = getChildMeasureSpec(parentHeightSpec, 1513e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin 1514e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell + heightUsed, lp.height); 1515e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 1516e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final int childHeightMode = MeasureSpec.getMode(childHeightSpec); 1517e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (childHeightMode != MeasureSpec.EXACTLY && heightConstraint >= 0) { 1518e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final int size = childHeightMode != MeasureSpec.UNSPECIFIED ? 1519e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell Math.min(MeasureSpec.getSize(childHeightSpec), heightConstraint) : 1520e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell heightConstraint; 1521e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell childHeightSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY); 1522e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 1523e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell child.measure(childWidthSpec, childHeightSpec); 1524e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 1525e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 15267a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell /** 15277a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell * Returns the width + uncollapsed margins 15287a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell */ 15297a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell private int measureChildCollapseMargins(View child, 15307a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell int parentWidthMeasureSpec, int widthUsed, 15317a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell int parentHeightMeasureSpec, int heightUsed, int[] collapsingMargins) { 15327a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); 15337a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell 15347a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int leftDiff = lp.leftMargin - collapsingMargins[0]; 15357a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int rightDiff = lp.rightMargin - collapsingMargins[1]; 15367a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int leftMargin = Math.max(0, leftDiff); 15377a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int rightMargin = Math.max(0, rightDiff); 15387a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int hMargins = leftMargin + rightMargin; 15397a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell collapsingMargins[0] = Math.max(0, -leftDiff); 15407a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell collapsingMargins[1] = Math.max(0, -rightDiff); 15417a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell 15427a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, 15437a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell mPaddingLeft + mPaddingRight + hMargins + widthUsed, lp.width); 15447a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec, 15457a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin 15467a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell + heightUsed, lp.height); 15477a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell 15487a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell child.measure(childWidthMeasureSpec, childHeightMeasureSpec); 15497a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell return child.getMeasuredWidth() + hMargins; 15507a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell } 15517a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell 1552360c1d89227570510de7bb11195c986300488464Adam Powell /** 1553360c1d89227570510de7bb11195c986300488464Adam Powell * Returns true if the Toolbar is collapsible and has no child views with a measured size > 0. 1554360c1d89227570510de7bb11195c986300488464Adam Powell */ 1555360c1d89227570510de7bb11195c986300488464Adam Powell private boolean shouldCollapse() { 1556360c1d89227570510de7bb11195c986300488464Adam Powell if (!mCollapsible) return false; 1557360c1d89227570510de7bb11195c986300488464Adam Powell 1558360c1d89227570510de7bb11195c986300488464Adam Powell final int childCount = getChildCount(); 1559360c1d89227570510de7bb11195c986300488464Adam Powell for (int i = 0; i < childCount; i++) { 1560360c1d89227570510de7bb11195c986300488464Adam Powell final View child = getChildAt(i); 1561360c1d89227570510de7bb11195c986300488464Adam Powell if (shouldLayout(child) && child.getMeasuredWidth() > 0 && 1562360c1d89227570510de7bb11195c986300488464Adam Powell child.getMeasuredHeight() > 0) { 1563360c1d89227570510de7bb11195c986300488464Adam Powell return false; 1564360c1d89227570510de7bb11195c986300488464Adam Powell } 1565360c1d89227570510de7bb11195c986300488464Adam Powell } 1566360c1d89227570510de7bb11195c986300488464Adam Powell return true; 1567360c1d89227570510de7bb11195c986300488464Adam Powell } 1568360c1d89227570510de7bb11195c986300488464Adam Powell 1569e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell @Override 1570e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 1571e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int width = 0; 1572e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int height = 0; 1573e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int childState = 0; 1574e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 15757a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int[] collapsingMargins = mTempMargins; 15767a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int marginStartIndex; 15777a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int marginEndIndex; 15787a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell if (isLayoutRtl()) { 15797a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell marginStartIndex = 1; 15807a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell marginEndIndex = 0; 15817a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell } else { 15827a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell marginStartIndex = 0; 15837a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell marginEndIndex = 1; 15847a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell } 15857a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell 1586e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell // System views measure first. 1587e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 158876d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell int navWidth = 0; 1589e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (shouldLayout(mNavButtonView)) { 1590e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell measureChildConstrained(mNavButtonView, widthMeasureSpec, width, heightMeasureSpec, 0, 1591e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mMaxButtonHeight); 159276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell navWidth = mNavButtonView.getMeasuredWidth() + getHorizontalMargins(mNavButtonView); 1593e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell height = Math.max(height, mNavButtonView.getMeasuredHeight() + 1594e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell getVerticalMargins(mNavButtonView)); 1595e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell childState = combineMeasuredStates(childState, mNavButtonView.getMeasuredState()); 1596e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1597e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1598e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (shouldLayout(mCollapseButtonView)) { 1599e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell measureChildConstrained(mCollapseButtonView, widthMeasureSpec, width, 1600e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell heightMeasureSpec, 0, mMaxButtonHeight); 1601e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell navWidth = mCollapseButtonView.getMeasuredWidth() + 1602e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell getHorizontalMargins(mCollapseButtonView); 1603e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell height = Math.max(height, mCollapseButtonView.getMeasuredHeight() + 1604e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell getVerticalMargins(mCollapseButtonView)); 1605e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell childState = combineMeasuredStates(childState, mCollapseButtonView.getMeasuredState()); 1606e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 1607e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 1608679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell final int contentInsetStart = getCurrentContentInsetStart(); 16097a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell width += Math.max(contentInsetStart, navWidth); 16107a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell collapsingMargins[marginStartIndex] = Math.max(0, contentInsetStart - navWidth); 161176d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 161276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell int menuWidth = 0; 1613e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (shouldLayout(mMenuView)) { 1614e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell measureChildConstrained(mMenuView, widthMeasureSpec, width, heightMeasureSpec, 0, 1615e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mMaxButtonHeight); 161676d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell menuWidth = mMenuView.getMeasuredWidth() + getHorizontalMargins(mMenuView); 1617e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell height = Math.max(height, mMenuView.getMeasuredHeight() + 1618e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell getVerticalMargins(mMenuView)); 1619e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell childState = combineMeasuredStates(childState, mMenuView.getMeasuredState()); 1620e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1621e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1622679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell final int contentInsetEnd = getCurrentContentInsetEnd(); 16237a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell width += Math.max(contentInsetEnd, menuWidth); 16247a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell collapsingMargins[marginEndIndex] = Math.max(0, contentInsetEnd - menuWidth); 162576d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 1626e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (shouldLayout(mExpandedActionView)) { 16277a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell width += measureChildCollapseMargins(mExpandedActionView, widthMeasureSpec, width, 16287a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell heightMeasureSpec, 0, collapsingMargins); 1629e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell height = Math.max(height, mExpandedActionView.getMeasuredHeight() + 1630e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell getVerticalMargins(mExpandedActionView)); 1631e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell childState = combineMeasuredStates(childState, mExpandedActionView.getMeasuredState()); 1632e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 1633e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 1634e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (shouldLayout(mLogoView)) { 16357a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell width += measureChildCollapseMargins(mLogoView, widthMeasureSpec, width, 16367a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell heightMeasureSpec, 0, collapsingMargins); 1637e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell height = Math.max(height, mLogoView.getMeasuredHeight() + 1638e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell getVerticalMargins(mLogoView)); 1639e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell childState = combineMeasuredStates(childState, mLogoView.getMeasuredState()); 1640e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1641e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1642b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell final int childCount = getChildCount(); 1643b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell for (int i = 0; i < childCount; i++) { 1644b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell final View child = getChildAt(i); 1645b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 1646b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell if (lp.mViewType != LayoutParams.CUSTOM || !shouldLayout(child)) { 1647b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell // We already got all system views above. Skip them and GONE views. 1648b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell continue; 1649b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell } 1650b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell 1651b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell width += measureChildCollapseMargins(child, widthMeasureSpec, width, 1652b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell heightMeasureSpec, 0, collapsingMargins); 1653b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell height = Math.max(height, child.getMeasuredHeight() + getVerticalMargins(child)); 1654b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell childState = combineMeasuredStates(childState, child.getMeasuredState()); 1655b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell } 1656b606a3a312fe6d69d97c66d76803eb2412d8329aAdam Powell 1657e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int titleWidth = 0; 1658e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int titleHeight = 0; 1659e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int titleVertMargins = mTitleMarginTop + mTitleMarginBottom; 1660e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int titleHorizMargins = mTitleMarginStart + mTitleMarginEnd; 1661e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (shouldLayout(mTitleTextView)) { 16627a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell titleWidth = measureChildCollapseMargins(mTitleTextView, widthMeasureSpec, 16637a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell width + titleHorizMargins, heightMeasureSpec, titleVertMargins, 16647a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell collapsingMargins); 1665e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell titleWidth = mTitleTextView.getMeasuredWidth() + getHorizontalMargins(mTitleTextView); 1666e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell titleHeight = mTitleTextView.getMeasuredHeight() + getVerticalMargins(mTitleTextView); 1667e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell childState = combineMeasuredStates(childState, mTitleTextView.getMeasuredState()); 1668e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1669e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (shouldLayout(mSubtitleTextView)) { 16707a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell titleWidth = Math.max(titleWidth, measureChildCollapseMargins(mSubtitleTextView, 16717a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell widthMeasureSpec, width + titleHorizMargins, 16727a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell heightMeasureSpec, titleHeight + titleVertMargins, 16737a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell collapsingMargins)); 1674e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell titleHeight += mSubtitleTextView.getMeasuredHeight() + 1675e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell getVerticalMargins(mSubtitleTextView); 1676e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell childState = combineMeasuredStates(childState, mSubtitleTextView.getMeasuredState()); 1677e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1678e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1679e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell width += titleWidth; 1680e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell height = Math.max(height, titleHeight); 1681e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1682e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell // Measurement already took padding into account for available space for the children, 1683e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell // add it in for the final size. 1684e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell width += getPaddingLeft() + getPaddingRight(); 1685e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell height += getPaddingTop() + getPaddingBottom(); 1686e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1687e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int measuredWidth = resolveSizeAndState( 1688e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell Math.max(width, getSuggestedMinimumWidth()), 1689e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell widthMeasureSpec, childState & MEASURED_STATE_MASK); 1690e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int measuredHeight = resolveSizeAndState( 1691e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell Math.max(height, getSuggestedMinimumHeight()), 1692e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT); 1693360c1d89227570510de7bb11195c986300488464Adam Powell 1694360c1d89227570510de7bb11195c986300488464Adam Powell setMeasuredDimension(measuredWidth, shouldCollapse() ? 0 : measuredHeight); 1695e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1696e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1697e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell @Override 1698e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell protected void onLayout(boolean changed, int l, int t, int r, int b) { 1699e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL; 1700e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int width = getWidth(); 1701e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int height = getHeight(); 1702e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int paddingLeft = getPaddingLeft(); 1703e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int paddingRight = getPaddingRight(); 1704e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int paddingTop = getPaddingTop(); 1705e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int paddingBottom = getPaddingBottom(); 1706e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int left = paddingLeft; 1707e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int right = width - paddingRight; 1708e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 17097a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int[] collapsingMargins = mTempMargins; 17107a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell collapsingMargins[0] = collapsingMargins[1] = 0; 17117a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell 1712e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette // Align views within the minimum toolbar height, if set. 17138053117a3d750779340a29abc2d2328c31350d6bChris Banes final int minHeight = getMinimumHeight(); 17148053117a3d750779340a29abc2d2328c31350d6bChris Banes final int alignmentHeight = minHeight >= 0 ? Math.min(minHeight, b - t) : 0; 1715e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette 1716e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (shouldLayout(mNavButtonView)) { 1717e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (isRtl) { 1718e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette right = layoutChildRight(mNavButtonView, right, collapsingMargins, 1719e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette alignmentHeight); 1720e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } else { 1721e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette left = layoutChildLeft(mNavButtonView, left, collapsingMargins, 1722e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette alignmentHeight); 1723e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1724e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1725e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1726e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (shouldLayout(mCollapseButtonView)) { 1727e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (isRtl) { 1728e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette right = layoutChildRight(mCollapseButtonView, right, collapsingMargins, 1729e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette alignmentHeight); 1730e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } else { 1731e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette left = layoutChildLeft(mCollapseButtonView, left, collapsingMargins, 1732e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette alignmentHeight); 1733e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 1734e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 1735e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 1736e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (shouldLayout(mMenuView)) { 1737e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (isRtl) { 1738e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette left = layoutChildLeft(mMenuView, left, collapsingMargins, 1739e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette alignmentHeight); 1740e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } else { 1741e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette right = layoutChildRight(mMenuView, right, collapsingMargins, 1742e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette alignmentHeight); 1743e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1744e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1745e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1746679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell final int contentInsetLeft = getCurrentContentInsetLeft(); 1747679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell final int contentInsetRight = getCurrentContentInsetRight(); 1748679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell collapsingMargins[0] = Math.max(0, contentInsetLeft - left); 1749679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell collapsingMargins[1] = Math.max(0, contentInsetRight - (width - paddingRight - right)); 1750679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell left = Math.max(left, contentInsetLeft); 1751679be2d6c423d1d2c8f7d94901ddcffcb9510619Adam Powell right = Math.min(right, width - paddingRight - contentInsetRight); 175276d8f968059d27ef8500cabf7690c18552c22d5aAdam Powell 1753e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (shouldLayout(mExpandedActionView)) { 1754e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (isRtl) { 1755e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette right = layoutChildRight(mExpandedActionView, right, collapsingMargins, 1756e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette alignmentHeight); 1757e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } else { 1758e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette left = layoutChildLeft(mExpandedActionView, left, collapsingMargins, 1759e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette alignmentHeight); 1760e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 1761e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 1762e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 1763e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (shouldLayout(mLogoView)) { 1764e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (isRtl) { 1765e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette right = layoutChildRight(mLogoView, right, collapsingMargins, 1766e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette alignmentHeight); 1767e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } else { 1768e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette left = layoutChildLeft(mLogoView, left, collapsingMargins, 1769e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette alignmentHeight); 1770e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1771e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1772e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1773e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final boolean layoutTitle = shouldLayout(mTitleTextView); 1774e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final boolean layoutSubtitle = shouldLayout(mSubtitleTextView); 1775e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int titleHeight = 0; 1776e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (layoutTitle) { 1777e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final LayoutParams lp = (LayoutParams) mTitleTextView.getLayoutParams(); 1778e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell titleHeight += lp.topMargin + mTitleTextView.getMeasuredHeight() + lp.bottomMargin; 1779e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1780e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (layoutSubtitle) { 1781e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final LayoutParams lp = (LayoutParams) mSubtitleTextView.getLayoutParams(); 1782b3e411458cd7b96bb308e2de3086efc4da10d64dAdam Powell titleHeight += lp.topMargin + mSubtitleTextView.getMeasuredHeight() + lp.bottomMargin; 1783e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1784e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1785e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (layoutTitle || layoutSubtitle) { 1786e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int titleTop; 1787e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final View topChild = layoutTitle ? mTitleTextView : mSubtitleTextView; 1788e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final View bottomChild = layoutSubtitle ? mSubtitleTextView : mTitleTextView; 1789e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final LayoutParams toplp = (LayoutParams) topChild.getLayoutParams(); 1790e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final LayoutParams bottomlp = (LayoutParams) bottomChild.getLayoutParams(); 17914c9765a654f7db15091d373f989908da54bfd155Adam Powell final boolean titleHasWidth = layoutTitle && mTitleTextView.getMeasuredWidth() > 0 17924c9765a654f7db15091d373f989908da54bfd155Adam Powell || layoutSubtitle && mSubtitleTextView.getMeasuredWidth() > 0; 1793e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 1794e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell switch (mGravity & Gravity.VERTICAL_GRAVITY_MASK) { 1795e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell case Gravity.TOP: 1796e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell titleTop = getPaddingTop() + toplp.topMargin + mTitleMarginTop; 1797e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell break; 1798e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell default: 1799e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell case Gravity.CENTER_VERTICAL: 1800e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int space = height - paddingTop - paddingBottom; 1801e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int spaceAbove = (space - titleHeight) / 2; 1802e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (spaceAbove < toplp.topMargin + mTitleMarginTop) { 1803e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell spaceAbove = toplp.topMargin + mTitleMarginTop; 1804e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } else { 1805e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int spaceBelow = height - paddingBottom - titleHeight - 1806e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell spaceAbove - paddingTop; 1807e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (spaceBelow < toplp.bottomMargin + mTitleMarginBottom) { 1808e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell spaceAbove = Math.max(0, spaceAbove - 1809e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell (bottomlp.bottomMargin + mTitleMarginBottom - spaceBelow)); 1810e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1811e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1812e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell titleTop = paddingTop + spaceAbove; 1813e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell break; 1814e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell case Gravity.BOTTOM: 1815e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell titleTop = height - paddingBottom - bottomlp.bottomMargin - mTitleMarginBottom - 1816e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell titleHeight; 1817e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell break; 1818e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1819e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (isRtl) { 18204c9765a654f7db15091d373f989908da54bfd155Adam Powell final int rd = (titleHasWidth ? mTitleMarginStart : 0) - collapsingMargins[1]; 18217a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell right -= Math.max(0, rd); 18227a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell collapsingMargins[1] = Math.max(0, -rd); 1823e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int titleRight = right; 1824e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int subtitleRight = right; 18257a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell 1826e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (layoutTitle) { 1827e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final LayoutParams lp = (LayoutParams) mTitleTextView.getLayoutParams(); 1828e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int titleLeft = titleRight - mTitleTextView.getMeasuredWidth(); 1829e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int titleBottom = titleTop + mTitleTextView.getMeasuredHeight(); 1830e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mTitleTextView.layout(titleLeft, titleTop, titleRight, titleBottom); 18317a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell titleRight = titleLeft - mTitleMarginEnd; 1832e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell titleTop = titleBottom + lp.bottomMargin; 1833e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1834e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (layoutSubtitle) { 1835e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final LayoutParams lp = (LayoutParams) mSubtitleTextView.getLayoutParams(); 1836e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell titleTop += lp.topMargin; 1837e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int subtitleLeft = subtitleRight - mSubtitleTextView.getMeasuredWidth(); 1838e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int subtitleBottom = titleTop + mSubtitleTextView.getMeasuredHeight(); 1839e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mSubtitleTextView.layout(subtitleLeft, titleTop, subtitleRight, subtitleBottom); 18407a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell subtitleRight = subtitleRight - mTitleMarginEnd; 1841e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell titleTop = subtitleBottom + lp.bottomMargin; 1842e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 18434c9765a654f7db15091d373f989908da54bfd155Adam Powell if (titleHasWidth) { 18444c9765a654f7db15091d373f989908da54bfd155Adam Powell right = Math.min(titleRight, subtitleRight); 18454c9765a654f7db15091d373f989908da54bfd155Adam Powell } 1846e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } else { 18474c9765a654f7db15091d373f989908da54bfd155Adam Powell final int ld = (titleHasWidth ? mTitleMarginStart : 0) - collapsingMargins[0]; 18487a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell left += Math.max(0, ld); 18497a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell collapsingMargins[0] = Math.max(0, -ld); 1850e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int titleLeft = left; 1851e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int subtitleLeft = left; 18527a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell 1853e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (layoutTitle) { 1854e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final LayoutParams lp = (LayoutParams) mTitleTextView.getLayoutParams(); 1855e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int titleRight = titleLeft + mTitleTextView.getMeasuredWidth(); 1856e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int titleBottom = titleTop + mTitleTextView.getMeasuredHeight(); 1857e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mTitleTextView.layout(titleLeft, titleTop, titleRight, titleBottom); 18587a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell titleLeft = titleRight + mTitleMarginEnd; 1859e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell titleTop = titleBottom + lp.bottomMargin; 1860e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1861e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (layoutSubtitle) { 1862e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final LayoutParams lp = (LayoutParams) mSubtitleTextView.getLayoutParams(); 1863e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell titleTop += lp.topMargin; 1864e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int subtitleRight = subtitleLeft + mSubtitleTextView.getMeasuredWidth(); 1865e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int subtitleBottom = titleTop + mSubtitleTextView.getMeasuredHeight(); 1866e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mSubtitleTextView.layout(subtitleLeft, titleTop, subtitleRight, subtitleBottom); 18677a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell subtitleLeft = subtitleRight + mTitleMarginEnd; 1868e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell titleTop = subtitleBottom + lp.bottomMargin; 1869e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 18704c9765a654f7db15091d373f989908da54bfd155Adam Powell if (titleHasWidth) { 18714c9765a654f7db15091d373f989908da54bfd155Adam Powell left = Math.max(titleLeft, subtitleLeft); 18724c9765a654f7db15091d373f989908da54bfd155Adam Powell } 1873e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1874e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1875e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1876e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell // Get all remaining children sorted for layout. This is all prepared 1877e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell // such that absolute layout direction can be used below. 1878e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1879e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell addCustomViewsWithGravity(mTempViews, Gravity.LEFT); 1880e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int leftViewsCount = mTempViews.size(); 1881e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell for (int i = 0; i < leftViewsCount; i++) { 1882e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette left = layoutChildLeft(mTempViews.get(i), left, collapsingMargins, 1883e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette alignmentHeight); 1884e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1885e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1886e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell addCustomViewsWithGravity(mTempViews, Gravity.RIGHT); 1887e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int rightViewsCount = mTempViews.size(); 1888e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell for (int i = 0; i < rightViewsCount; i++) { 1889e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette right = layoutChildRight(mTempViews.get(i), right, collapsingMargins, 1890e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette alignmentHeight); 1891e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1892e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1893e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell // Centered views try to center with respect to the whole bar, but views pinned 1894e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell // to the left or right can push the mass of centered views to one side or the other. 1895e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell addCustomViewsWithGravity(mTempViews, Gravity.CENTER_HORIZONTAL); 18967a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int centerViewsWidth = getViewListMeasuredWidth(mTempViews, collapsingMargins); 1897e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int parentCenter = paddingLeft + (width - paddingLeft - paddingRight) / 2; 1898e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int halfCenterViewsWidth = centerViewsWidth / 2; 1899e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int centerLeft = parentCenter - halfCenterViewsWidth; 1900e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int centerRight = centerLeft + centerViewsWidth; 1901e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (centerLeft < left) { 1902e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell centerLeft = left; 1903e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } else if (centerRight > right) { 1904e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell centerLeft -= centerRight - right; 1905e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1906e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1907e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int centerViewsCount = mTempViews.size(); 1908e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell for (int i = 0; i < centerViewsCount; i++) { 1909e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette centerLeft = layoutChildLeft(mTempViews.get(i), centerLeft, collapsingMargins, 1910e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette alignmentHeight); 1911e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1912e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette 1913e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mTempViews.clear(); 1914e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1915e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 19167a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell private int getViewListMeasuredWidth(List<View> views, int[] collapsingMargins) { 19177a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell int collapseLeft = collapsingMargins[0]; 19187a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell int collapseRight = collapsingMargins[1]; 1919e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int width = 0; 1920e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int count = views.size(); 1921e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell for (int i = 0; i < count; i++) { 1922e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final View v = views.get(i); 1923e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final LayoutParams lp = (LayoutParams) v.getLayoutParams(); 19247a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int l = lp.leftMargin - collapseLeft; 19257a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int r = lp.rightMargin - collapseRight; 19267a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int leftMargin = Math.max(0, l); 19277a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int rightMargin = Math.max(0, r); 19287a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell collapseLeft = Math.max(0, -l); 19297a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell collapseRight = Math.max(0, -r); 19307a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell width += leftMargin + v.getMeasuredWidth() + rightMargin; 1931e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1932e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return width; 1933e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1934e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1935e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette private int layoutChildLeft(View child, int left, int[] collapsingMargins, 1936e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette int alignmentHeight) { 1937e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 19387a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int l = lp.leftMargin - collapsingMargins[0]; 19397a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell left += Math.max(0, l); 19407a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell collapsingMargins[0] = Math.max(0, -l); 1941e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette final int top = getChildTop(child, alignmentHeight); 19427a8a284d46c740e8b2cd1ccd088c0ba41e020642Adam Powell final int childWidth = child.getMeasuredWidth(); 19437a8a284d46c740e8b2cd1ccd088c0ba41e020642Adam Powell child.layout(left, top, left + childWidth, top + child.getMeasuredHeight()); 19447a8a284d46c740e8b2cd1ccd088c0ba41e020642Adam Powell left += childWidth + lp.rightMargin; 1945e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return left; 1946e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1947e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1948e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette private int layoutChildRight(View child, int right, int[] collapsingMargins, 1949e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette int alignmentHeight) { 1950e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 19517a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell final int r = lp.rightMargin - collapsingMargins[1]; 19527a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell right -= Math.max(0, r); 19537a32401c2a62f778da7056cc9aa65bd1489aa153Adam Powell collapsingMargins[1] = Math.max(0, -r); 1954e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette final int top = getChildTop(child, alignmentHeight); 19557a8a284d46c740e8b2cd1ccd088c0ba41e020642Adam Powell final int childWidth = child.getMeasuredWidth(); 19567a8a284d46c740e8b2cd1ccd088c0ba41e020642Adam Powell child.layout(right - childWidth, top, right, top + child.getMeasuredHeight()); 19577a8a284d46c740e8b2cd1ccd088c0ba41e020642Adam Powell right -= childWidth + lp.leftMargin; 1958e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return right; 1959e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1960e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1961e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette private int getChildTop(View child, int alignmentHeight) { 1962e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 1963e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette final int childHeight = child.getMeasuredHeight(); 1964e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette final int alignmentOffset = alignmentHeight > 0 ? (childHeight - alignmentHeight) / 2 : 0; 1965e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell switch (getChildVerticalGravity(lp.gravity)) { 1966e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell case Gravity.TOP: 1967e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette return getPaddingTop() - alignmentOffset; 1968e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1969e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell case Gravity.BOTTOM: 1970e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette return getHeight() - getPaddingBottom() - childHeight 1971e3cb7baeb9563cd78fecbd84f9ab43be62d25013Alan Viverette - lp.bottomMargin - alignmentOffset; 1972e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1973e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell default: 1974e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell case Gravity.CENTER_VERTICAL: 1975e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int paddingTop = getPaddingTop(); 1976e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int paddingBottom = getPaddingBottom(); 1977e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int height = getHeight(); 1978e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int space = height - paddingTop - paddingBottom; 1979e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int spaceAbove = (space - childHeight) / 2; 1980e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (spaceAbove < lp.topMargin) { 1981e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell spaceAbove = lp.topMargin; 1982e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } else { 1983e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int spaceBelow = height - paddingBottom - childHeight - 1984e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell spaceAbove - paddingTop; 1985e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (spaceBelow < lp.bottomMargin) { 1986e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell spaceAbove = Math.max(0, spaceAbove - (lp.bottomMargin - spaceBelow)); 1987e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1988e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1989e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return paddingTop + spaceAbove; 1990e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1991e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 1992e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 1993e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private int getChildVerticalGravity(int gravity) { 1994e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int vgrav = gravity & Gravity.VERTICAL_GRAVITY_MASK; 1995e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell switch (vgrav) { 1996e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell case Gravity.TOP: 1997e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell case Gravity.BOTTOM: 1998e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell case Gravity.CENTER_VERTICAL: 1999e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return vgrav; 2000e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell default: 2001e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return mGravity & Gravity.VERTICAL_GRAVITY_MASK; 2002e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2003e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2004e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2005e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 2006e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Prepare a list of non-SYSTEM child views. If the layout direction is RTL 2007e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * this will be in reverse child order. 2008e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 2009e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param views List to populate. It will be cleared before use. 2010e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param gravity Horizontal gravity to match against 2011e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 2012e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private void addCustomViewsWithGravity(List<View> views, int gravity) { 2013e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL; 2014e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int childCount = getChildCount(); 2015e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int absGrav = Gravity.getAbsoluteGravity(gravity, getLayoutDirection()); 2016e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2017e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell views.clear(); 2018e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2019e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (isRtl) { 2020e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell for (int i = childCount - 1; i >= 0; i--) { 2021e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final View child = getChildAt(i); 2022e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 2023e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (lp.mViewType == LayoutParams.CUSTOM && shouldLayout(child) && 2024e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell getChildHorizontalGravity(lp.gravity) == absGrav) { 2025e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell views.add(child); 2026e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2027e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2028e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } else { 2029e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell for (int i = 0; i < childCount; i++) { 2030e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final View child = getChildAt(i); 2031e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 2032e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (lp.mViewType == LayoutParams.CUSTOM && shouldLayout(child) && 2033e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell getChildHorizontalGravity(lp.gravity) == absGrav) { 2034e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell views.add(child); 2035e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2036e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2037e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2038e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2039e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2040e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private int getChildHorizontalGravity(int gravity) { 2041e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int ld = getLayoutDirection(); 2042e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int absGrav = Gravity.getAbsoluteGravity(gravity, ld); 2043e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final int hGrav = absGrav & Gravity.HORIZONTAL_GRAVITY_MASK; 2044e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell switch (hGrav) { 2045e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell case Gravity.LEFT: 2046e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell case Gravity.RIGHT: 2047e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell case Gravity.CENTER_HORIZONTAL: 2048e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return hGrav; 2049e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell default: 2050e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return ld == LAYOUT_DIRECTION_RTL ? Gravity.RIGHT : Gravity.LEFT; 2051e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2052e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2053e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2054e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private boolean shouldLayout(View view) { 2055e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return view != null && view.getParent() == this && view.getVisibility() != GONE; 2056e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2057e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2058e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private int getHorizontalMargins(View v) { 2059e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final MarginLayoutParams mlp = (MarginLayoutParams) v.getLayoutParams(); 2060e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return mlp.getMarginStart() + mlp.getMarginEnd(); 2061e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2062e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2063e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private int getVerticalMargins(View v) { 2064e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell final MarginLayoutParams mlp = (MarginLayoutParams) v.getLayoutParams(); 2065e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return mlp.topMargin + mlp.bottomMargin; 2066e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2067e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2068e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell @Override 2069e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public LayoutParams generateLayoutParams(AttributeSet attrs) { 2070e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return new LayoutParams(getContext(), attrs); 2071e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2072e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2073e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell @Override 2074e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) { 2075e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (p instanceof LayoutParams) { 2076e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return new LayoutParams((LayoutParams) p); 2077e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } else if (p instanceof ActionBar.LayoutParams) { 2078e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return new LayoutParams((ActionBar.LayoutParams) p); 2079e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } else if (p instanceof MarginLayoutParams) { 2080e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return new LayoutParams((MarginLayoutParams) p); 2081e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } else { 2082e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return new LayoutParams(p); 2083e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2084e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2085e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2086e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell @Override 2087e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell protected LayoutParams generateDefaultLayoutParams() { 2088e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 2089e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2090e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2091e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell @Override 2092e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell protected boolean checkLayoutParams(ViewGroup.LayoutParams p) { 2093e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return super.checkLayoutParams(p) && p instanceof LayoutParams; 2094e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2095e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2096e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private static boolean isCustomView(View child) { 2097e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return ((LayoutParams) child.getLayoutParams()).mViewType == LayoutParams.CUSTOM; 2098e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2099e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2100e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell /** @hide */ 2101e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public DecorToolbar getWrapper() { 2102e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (mWrapper == null) { 21032aa09a94dd540650d3ebad7363e4fb3aab2ebc95Adam Powell mWrapper = new ToolbarWidgetWrapper(this, true); 2104e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2105e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return mWrapper; 2106e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2107e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 21085f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell void removeChildrenForExpandedActionView() { 2109e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final int childCount = getChildCount(); 21105f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell // Go backwards since we're removing from the list 21115f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell for (int i = childCount - 1; i >= 0; i--) { 2112e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final View child = getChildAt(i); 2113e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 2114e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (lp.mViewType != LayoutParams.EXPANDED && child != mMenuView) { 21155f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell removeViewAt(i); 21165f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell mHiddenViews.add(child); 2117e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2118e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2119e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2120e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 21215f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell void addChildrenForExpandedActionView() { 21225f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell final int count = mHiddenViews.size(); 21235f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell // Re-add in reverse order since we removed in reverse order 21245f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell for (int i = count - 1; i >= 0; i--) { 21255f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell addView(mHiddenViews.get(i)); 212631c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell } 21275f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell mHiddenViews.clear(); 21285f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell } 21295f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell 21305f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell private boolean isChildOrHidden(View child) { 21315f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell return child.getParent() == this || mHiddenViews.contains(child); 213231c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell } 213331c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell 2134e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 2135360c1d89227570510de7bb11195c986300488464Adam Powell * Force the toolbar to collapse to zero-height during measurement if 2136360c1d89227570510de7bb11195c986300488464Adam Powell * it could be considered "empty" (no visible elements with nonzero measured size) 2137360c1d89227570510de7bb11195c986300488464Adam Powell * @hide 2138360c1d89227570510de7bb11195c986300488464Adam Powell */ 2139360c1d89227570510de7bb11195c986300488464Adam Powell public void setCollapsible(boolean collapsible) { 2140360c1d89227570510de7bb11195c986300488464Adam Powell mCollapsible = collapsible; 2141360c1d89227570510de7bb11195c986300488464Adam Powell requestLayout(); 2142360c1d89227570510de7bb11195c986300488464Adam Powell } 2143360c1d89227570510de7bb11195c986300488464Adam Powell 2144360c1d89227570510de7bb11195c986300488464Adam Powell /** 214504c0d4607897157f01c908475fa0c6d7301cf7e5Adam Powell * Must be called before the menu is accessed 214604c0d4607897157f01c908475fa0c6d7301cf7e5Adam Powell * @hide 214704c0d4607897157f01c908475fa0c6d7301cf7e5Adam Powell */ 2148c46125042493e66f7dfdccec24e3b0739600b194Adam Powell public void setMenuCallbacks(MenuPresenter.Callback pcb, MenuBuilder.Callback mcb) { 2149c46125042493e66f7dfdccec24e3b0739600b194Adam Powell mActionMenuPresenterCallback = pcb; 2150c46125042493e66f7dfdccec24e3b0739600b194Adam Powell mMenuBuilderCallback = mcb; 21515190f1737f6eab674262c650b9685aa1f220d706Alan Viverette if (mMenuView != null) { 21525190f1737f6eab674262c650b9685aa1f220d706Alan Viverette mMenuView.setMenuCallbacks(pcb, mcb); 21535190f1737f6eab674262c650b9685aa1f220d706Alan Viverette } 215404c0d4607897157f01c908475fa0c6d7301cf7e5Adam Powell } 215504c0d4607897157f01c908475fa0c6d7301cf7e5Adam Powell 21563b925c1ab092cf63329845ecad73aa58db24c86dChris Banes private void ensureContentInsets() { 21573b925c1ab092cf63329845ecad73aa58db24c86dChris Banes if (mContentInsets == null) { 21583b925c1ab092cf63329845ecad73aa58db24c86dChris Banes mContentInsets = new RtlSpacingHelper(); 21593b925c1ab092cf63329845ecad73aa58db24c86dChris Banes } 21603b925c1ab092cf63329845ecad73aa58db24c86dChris Banes } 21613b925c1ab092cf63329845ecad73aa58db24c86dChris Banes 216204c0d4607897157f01c908475fa0c6d7301cf7e5Adam Powell /** 21630bffc736e1f260724764d31f7499cbc09471a535Deepanshu Gupta * Accessor to enable LayoutLib to get ActionMenuPresenter directly. 21640bffc736e1f260724764d31f7499cbc09471a535Deepanshu Gupta */ 21650bffc736e1f260724764d31f7499cbc09471a535Deepanshu Gupta ActionMenuPresenter getOuterActionMenuPresenter() { 21660bffc736e1f260724764d31f7499cbc09471a535Deepanshu Gupta return mOuterActionMenuPresenter; 21670bffc736e1f260724764d31f7499cbc09471a535Deepanshu Gupta } 21680bffc736e1f260724764d31f7499cbc09471a535Deepanshu Gupta 21690bffc736e1f260724764d31f7499cbc09471a535Deepanshu Gupta Context getPopupContext() { 21700bffc736e1f260724764d31f7499cbc09471a535Deepanshu Gupta return mPopupContext; 21710bffc736e1f260724764d31f7499cbc09471a535Deepanshu Gupta } 21720bffc736e1f260724764d31f7499cbc09471a535Deepanshu Gupta 21730bffc736e1f260724764d31f7499cbc09471a535Deepanshu Gupta /** 2174e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Interface responsible for receiving menu item click events if the items themselves 2175e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * do not have individual item click listeners. 2176e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 2177e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public interface OnMenuItemClickListener { 2178e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 2179e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * This method will be invoked when a menu item is clicked if the item itself did 2180e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * not already handle the event. 2181e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 2182e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @param item {@link MenuItem} that was clicked 2183e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @return <code>true</code> if the event was handled, <code>false</code> otherwise. 2184e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 2185e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public boolean onMenuItemClick(MenuItem item); 2186e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2187e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2188e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell /** 2189e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * Layout information for child views of Toolbars. 2190e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * 2191d76008352eeb246af76ba4a81eaeb4901ca4ef7fAdam Powell * <p>Toolbar.LayoutParams extends ActionBar.LayoutParams for compatibility with existing 2192d76008352eeb246af76ba4a81eaeb4901ca4ef7fAdam Powell * ActionBar API. See {@link android.app.Activity#setActionBar(Toolbar) Activity.setActionBar} 2193d76008352eeb246af76ba4a81eaeb4901ca4ef7fAdam Powell * for more info on how to use a Toolbar as your Activity's ActionBar.</p> 2194d76008352eeb246af76ba4a81eaeb4901ca4ef7fAdam Powell * 2195e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell * @attr ref android.R.styleable#Toolbar_LayoutParams_layout_gravity 2196e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell */ 2197e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public static class LayoutParams extends ActionBar.LayoutParams { 2198e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell static final int CUSTOM = 0; 2199e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell static final int SYSTEM = 1; 2200e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell static final int EXPANDED = 2; 2201e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2202e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell int mViewType = CUSTOM; 2203e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2204e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public LayoutParams(@NonNull Context c, AttributeSet attrs) { 2205e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell super(c, attrs); 2206e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2207e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2208e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public LayoutParams(int width, int height) { 2209e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell super(width, height); 2210e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell this.gravity = Gravity.CENTER_VERTICAL | Gravity.START; 2211e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2212e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2213e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public LayoutParams(int width, int height, int gravity) { 2214e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell super(width, height); 2215e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell this.gravity = gravity; 2216e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2217e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2218e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public LayoutParams(int gravity) { 2219e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell this(WRAP_CONTENT, MATCH_PARENT, gravity); 2220e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2221e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2222e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public LayoutParams(LayoutParams source) { 2223e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell super(source); 2224e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2225e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mViewType = source.mViewType; 2226e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2227e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2228e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public LayoutParams(ActionBar.LayoutParams source) { 2229e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell super(source); 2230e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2231e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2232e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public LayoutParams(MarginLayoutParams source) { 2233e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell super(source); 2234d76008352eeb246af76ba4a81eaeb4901ca4ef7fAdam Powell // ActionBar.LayoutParams doesn't have a MarginLayoutParams constructor. 2235d76008352eeb246af76ba4a81eaeb4901ca4ef7fAdam Powell // Fake it here and copy over the relevant data. 2236d76008352eeb246af76ba4a81eaeb4901ca4ef7fAdam Powell copyMarginsFrom(source); 2237e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2238e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2239e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public LayoutParams(ViewGroup.LayoutParams source) { 2240e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell super(source); 2241e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2242e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2243e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2244e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell static class SavedState extends BaseSavedState { 224531c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell public int expandedMenuItemId; 224631c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell public boolean isOverflowOpen; 224731c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell 2248e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public SavedState(Parcel source) { 2249e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell super(source); 225031c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell expandedMenuItemId = source.readInt(); 225131c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell isOverflowOpen = source.readInt() != 0; 2252e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2253e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2254e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public SavedState(Parcelable superState) { 2255e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell super(superState); 2256e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2257e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2258e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell @Override 2259e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public void writeToParcel(Parcel out, int flags) { 2260e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell super.writeToParcel(out, flags); 226131c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell out.writeInt(expandedMenuItemId); 226231c91c81798802f62d55f8bccb6d4071471c1aa4Adam Powell out.writeInt(isOverflowOpen ? 1 : 0); 2263e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2264e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2265e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public static final Creator<SavedState> CREATOR = new Creator<SavedState>() { 2266e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2267e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell @Override 2268e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public SavedState createFromParcel(Parcel source) { 2269e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return new SavedState(source); 2270e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2271e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell 2272e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell @Override 2273e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell public SavedState[] newArray(int size) { 2274e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell return new SavedState[size]; 2275e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2276e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell }; 2277e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 2278e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2279e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell private class ExpandedActionViewMenuPresenter implements MenuPresenter { 2280e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell MenuBuilder mMenu; 2281e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell MenuItemImpl mCurrentExpandedItem; 2282e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2283e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell @Override 228428a8468995c71ba3fbba12557d143e7599db38d8Alan Viverette public void initForMenu(@NonNull Context context, @Nullable MenuBuilder menu) { 2285e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell // Clear the expanded action view when menus change. 2286e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (mMenu != null && mCurrentExpandedItem != null) { 2287e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mMenu.collapseItemActionView(mCurrentExpandedItem); 2288e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2289e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mMenu = menu; 2290e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2291e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2292e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell @Override 2293e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public MenuView getMenuView(ViewGroup root) { 2294e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return null; 2295e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2296e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2297e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell @Override 2298e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public void updateMenuView(boolean cleared) { 2299e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell // Make sure the expanded item we have is still there. 2300e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (mCurrentExpandedItem != null) { 2301e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell boolean found = false; 2302e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2303e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (mMenu != null) { 2304e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final int count = mMenu.size(); 2305e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell for (int i = 0; i < count; i++) { 2306e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final MenuItem item = mMenu.getItem(i); 2307e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (item == mCurrentExpandedItem) { 2308e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell found = true; 2309e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell break; 2310e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2311e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2312e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2313e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2314e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (!found) { 2315e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell // The item we had expanded disappeared. Collapse. 2316e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell collapseItemActionView(mMenu, mCurrentExpandedItem); 2317e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2318e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2319e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2320e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2321e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell @Override 2322e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public void setCallback(Callback cb) { 2323e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2324e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2325e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell @Override 2326e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public boolean onSubMenuSelected(SubMenuBuilder subMenu) { 2327e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return false; 2328e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2329e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2330e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell @Override 2331e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { 2332e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2333e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2334e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell @Override 2335e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public boolean flagActionItems() { 2336e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return false; 2337e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2338e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2339e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell @Override 2340e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item) { 2341e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell ensureCollapseButtonView(); 2342e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (mCollapseButtonView.getParent() != Toolbar.this) { 2343e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell addView(mCollapseButtonView); 2344e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2345e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mExpandedActionView = item.getActionView(); 2346e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mCurrentExpandedItem = item; 2347e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (mExpandedActionView.getParent() != Toolbar.this) { 2348e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell final LayoutParams lp = generateDefaultLayoutParams(); 2349e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell lp.gravity = Gravity.START | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK); 2350e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell lp.mViewType = LayoutParams.EXPANDED; 2351e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mExpandedActionView.setLayoutParams(lp); 2352e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell addView(mExpandedActionView); 2353e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2354e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 23555f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell removeChildrenForExpandedActionView(); 2356e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell requestLayout(); 2357e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell item.setActionViewExpanded(true); 2358e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2359e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (mExpandedActionView instanceof CollapsibleActionView) { 2360e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell ((CollapsibleActionView) mExpandedActionView).onActionViewExpanded(); 2361e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2362e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2363e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return true; 2364e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2365e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2366e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell @Override 2367e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item) { 2368e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell // Do this before detaching the actionview from the hierarchy, in case 2369e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell // it needs to dismiss the soft keyboard, etc. 2370e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell if (mExpandedActionView instanceof CollapsibleActionView) { 2371e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell ((CollapsibleActionView) mExpandedActionView).onActionViewCollapsed(); 2372e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2373e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2374e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell removeView(mExpandedActionView); 2375e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell removeView(mCollapseButtonView); 2376e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mExpandedActionView = null; 2377e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 23785f6228454de9bc18847a28e7c21e8fb9bab3d6acAdam Powell addChildrenForExpandedActionView(); 2379e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell mCurrentExpandedItem = null; 2380e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell requestLayout(); 2381e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell item.setActionViewExpanded(false); 2382e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2383e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return true; 2384e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2385e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2386e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell @Override 2387e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public int getId() { 2388e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return 0; 2389e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2390e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2391e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell @Override 2392e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public Parcelable onSaveInstanceState() { 2393e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell return null; 2394e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2395e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell 2396e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell @Override 2397e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell public void onRestoreInstanceState(Parcelable state) { 2398e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2399e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell } 2400e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell} 2401