Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 17 | package com.android.internal.widget; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 18 | |
Adam Powell | fd75eef | 2012-08-02 10:27:31 -0700 | [diff] [blame] | 19 | import android.animation.LayoutTransition; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 20 | import android.app.ActionBar; |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 21 | import android.app.ActionBar.OnNavigationListener; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.pm.ApplicationInfo; |
| 24 | import android.content.pm.PackageManager; |
Adam Powell | 45c0b19 | 2011-07-28 15:11:57 -0700 | [diff] [blame] | 25 | import android.content.res.Configuration; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 26 | import android.content.res.TypedArray; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 27 | import android.graphics.drawable.Drawable; |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 28 | import android.os.Parcel; |
| 29 | import android.os.Parcelable; |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 30 | import android.text.Layout; |
Adam Powell | 2a7ea67 | 2011-01-23 20:25:15 -0800 | [diff] [blame] | 31 | import android.text.TextUtils; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 32 | import android.util.AttributeSet; |
Adam Powell | 038f1c8 | 2011-07-21 14:28:10 -0700 | [diff] [blame] | 33 | import android.view.CollapsibleActionView; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 34 | import android.view.Gravity; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 35 | import android.view.LayoutInflater; |
| 36 | import android.view.Menu; |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 37 | import android.view.MenuItem; |
Adam Powell | 7bc3ca0 | 2011-08-26 18:29:58 -0700 | [diff] [blame] | 38 | import android.view.MotionEvent; |
Adam Powell | 89e0645 | 2010-06-23 20:24:52 -0700 | [diff] [blame] | 39 | import android.view.View; |
| 40 | import android.view.ViewGroup; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 41 | import android.view.ViewParent; |
Adam Powell | 8d12e20 | 2010-11-15 16:44:17 -0800 | [diff] [blame] | 42 | import android.view.Window; |
Adam Powell | 7bc3ca0 | 2011-08-26 18:29:58 -0700 | [diff] [blame] | 43 | import android.view.accessibility.AccessibilityEvent; |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 44 | import android.widget.AdapterView; |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 45 | import android.widget.FrameLayout; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 46 | import android.widget.ImageView; |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 47 | import android.widget.LinearLayout; |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 48 | import android.widget.ProgressBar; |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 49 | import android.widget.Spinner; |
| 50 | import android.widget.SpinnerAdapter; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 51 | import android.widget.TextView; |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 52 | import com.android.internal.R; |
| 53 | import com.android.internal.view.menu.ActionMenuItem; |
| 54 | import com.android.internal.view.menu.ActionMenuPresenter; |
| 55 | import com.android.internal.view.menu.ActionMenuView; |
| 56 | import com.android.internal.view.menu.MenuBuilder; |
| 57 | import com.android.internal.view.menu.MenuItemImpl; |
| 58 | import com.android.internal.view.menu.MenuPresenter; |
| 59 | import com.android.internal.view.menu.MenuView; |
| 60 | import com.android.internal.view.menu.SubMenuBuilder; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 61 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 62 | /** |
| 63 | * @hide |
| 64 | */ |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 65 | public class ActionBarView extends AbsActionBarView { |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 66 | private static final String TAG = "ActionBarView"; |
Adam Powell | be4d68e | 2010-10-08 18:16:34 -0700 | [diff] [blame] | 67 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Display options applied by default |
| 70 | */ |
| 71 | public static final int DISPLAY_DEFAULT = 0; |
| 72 | |
| 73 | /** |
| 74 | * Display options that require re-layout as opposed to a simple invalidate |
| 75 | */ |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 76 | private static final int DISPLAY_RELAYOUT_MASK = |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 77 | ActionBar.DISPLAY_SHOW_HOME | |
| 78 | ActionBar.DISPLAY_USE_LOGO | |
| 79 | ActionBar.DISPLAY_HOME_AS_UP | |
| 80 | ActionBar.DISPLAY_SHOW_CUSTOM | |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 81 | ActionBar.DISPLAY_SHOW_TITLE | |
| 82 | ActionBar.DISPLAY_TITLE_MULTIPLE_LINES; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 83 | |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 84 | private static final int DEFAULT_CUSTOM_GRAVITY = Gravity.START | Gravity.CENTER_VERTICAL; |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 85 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 86 | private int mNavigationMode; |
Adam Powell | 82f24e8 | 2011-08-18 20:15:20 -0700 | [diff] [blame] | 87 | private int mDisplayOptions = -1; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 88 | private CharSequence mTitle; |
| 89 | private CharSequence mSubtitle; |
| 90 | private Drawable mIcon; |
| 91 | private Drawable mLogo; |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 92 | private CharSequence mHomeDescription; |
| 93 | private int mHomeDescriptionRes; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 94 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 95 | private HomeView mHomeLayout; |
| 96 | private HomeView mExpandedHomeLayout; |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 97 | private LinearLayout mTitleLayout; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 98 | private TextView mTitleView; |
| 99 | private TextView mSubtitleView; |
Adam Powell | 54c7d7e | 2011-06-17 20:30:13 -0700 | [diff] [blame] | 100 | private View mTitleUpView; |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 101 | private ViewGroup mUpGoerFive; |
Adam Powell | 54c7d7e | 2011-06-17 20:30:13 -0700 | [diff] [blame] | 102 | |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 103 | private Spinner mSpinner; |
Adam Powell | 3f7f7ac | 2010-12-05 16:44:38 -0800 | [diff] [blame] | 104 | private LinearLayout mListNavLayout; |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 105 | private ScrollingTabContainerView mTabScrollView; |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 106 | private View mCustomNavView; |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 107 | private ProgressBar mProgressView; |
| 108 | private ProgressBar mIndeterminateProgressView; |
| 109 | |
| 110 | private int mProgressBarPadding; |
Adam Powell | 3f7f7ac | 2010-12-05 16:44:38 -0800 | [diff] [blame] | 111 | private int mItemPadding; |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 112 | |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 113 | private int mTitleStyleRes; |
| 114 | private int mSubtitleStyleRes; |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 115 | private int mProgressStyle; |
| 116 | private int mIndeterminateProgressStyle; |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 117 | |
Adam Powell | e92ea34 | 2010-07-14 14:45:50 -0700 | [diff] [blame] | 118 | private boolean mUserTitle; |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 119 | private boolean mIncludeTabs; |
Adam Powell | d21aa12 | 2011-05-27 13:09:52 -0700 | [diff] [blame] | 120 | private boolean mIsCollapsable; |
Adam Powell | f6ce6a9 | 2011-06-29 10:25:01 -0700 | [diff] [blame] | 121 | private boolean mIsCollapsed; |
Adam Powell | 62f3303 | 2013-02-04 12:44:34 -0800 | [diff] [blame] | 122 | private boolean mWasHomeEnabled; // Was it enabled before action view expansion? |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 123 | |
Adam Powell | 96675b1 | 2010-06-10 18:58:59 -0700 | [diff] [blame] | 124 | private MenuBuilder mOptionsMenu; |
Adam Powell | 8c16aa9 | 2013-04-04 10:47:52 -0700 | [diff] [blame] | 125 | private boolean mMenuPrepared; |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 126 | |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 127 | private ActionBarContextView mContextView; |
| 128 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 129 | private ActionMenuItem mLogoNavItem; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 130 | |
| 131 | private SpinnerAdapter mSpinnerAdapter; |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 132 | private OnNavigationListener mCallback; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 133 | |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 134 | private Runnable mTabSelector; |
| 135 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 136 | private ExpandedActionViewMenuPresenter mExpandedMenuPresenter; |
| 137 | View mExpandedActionView; |
| 138 | |
Adam Powell | 915ce0d | 2011-09-28 15:52:57 -0700 | [diff] [blame] | 139 | Window.Callback mWindowCallback; |
| 140 | |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 141 | private final AdapterView.OnItemSelectedListener mNavItemSelectedListener = |
| 142 | new AdapterView.OnItemSelectedListener() { |
| 143 | public void onItemSelected(AdapterView parent, View view, int position, long id) { |
| 144 | if (mCallback != null) { |
| 145 | mCallback.onNavigationItemSelected(position, id); |
| 146 | } |
| 147 | } |
| 148 | public void onNothingSelected(AdapterView parent) { |
| 149 | // Do nothing |
| 150 | } |
| 151 | }; |
| 152 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 153 | private final OnClickListener mExpandedActionViewUpListener = new OnClickListener() { |
| 154 | @Override |
| 155 | public void onClick(View v) { |
| 156 | final MenuItemImpl item = mExpandedMenuPresenter.mCurrentExpandedItem; |
| 157 | if (item != null) { |
| 158 | item.collapseActionView(); |
| 159 | } |
| 160 | } |
| 161 | }; |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 162 | |
Adam Powell | 54c7d7e | 2011-06-17 20:30:13 -0700 | [diff] [blame] | 163 | private final OnClickListener mUpClickListener = new OnClickListener() { |
| 164 | public void onClick(View v) { |
Adam Powell | 8c16aa9 | 2013-04-04 10:47:52 -0700 | [diff] [blame] | 165 | if (mMenuPrepared) { |
| 166 | // Only invoke the window callback if the options menu has been initialized. |
| 167 | mWindowCallback.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, mLogoNavItem); |
| 168 | } |
Adam Powell | 54c7d7e | 2011-06-17 20:30:13 -0700 | [diff] [blame] | 169 | } |
| 170 | }; |
| 171 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 172 | public ActionBarView(Context context, AttributeSet attrs) { |
| 173 | super(context, attrs); |
| 174 | |
Adam Powell | 654e4e4 | 2011-01-03 16:33:50 -0800 | [diff] [blame] | 175 | // Background is always provided by the container. |
| 176 | setBackgroundResource(0); |
| 177 | |
Adam Powell | 45c0b19 | 2011-07-28 15:11:57 -0700 | [diff] [blame] | 178 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar, |
| 179 | com.android.internal.R.attr.actionBarStyle, 0); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 180 | |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 181 | ApplicationInfo appInfo = context.getApplicationInfo(); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 182 | PackageManager pm = context.getPackageManager(); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 183 | mNavigationMode = a.getInt(R.styleable.ActionBar_navigationMode, |
| 184 | ActionBar.NAVIGATION_MODE_STANDARD); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 185 | mTitle = a.getText(R.styleable.ActionBar_title); |
| 186 | mSubtitle = a.getText(R.styleable.ActionBar_subtitle); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 187 | mLogo = a.getDrawable(R.styleable.ActionBar_logo); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 188 | mIcon = a.getDrawable(R.styleable.ActionBar_icon); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 189 | |
Ed Heyl | 1c60300 | 2010-11-18 12:18:23 -0800 | [diff] [blame] | 190 | final LayoutInflater inflater = LayoutInflater.from(context); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 191 | |
Ed Heyl | 1c60300 | 2010-11-18 12:18:23 -0800 | [diff] [blame] | 192 | final int homeResId = a.getResourceId( |
Adam Powell | b33be1c | 2010-11-18 12:11:40 -0800 | [diff] [blame] | 193 | com.android.internal.R.styleable.ActionBar_homeLayout, |
| 194 | com.android.internal.R.layout.action_bar_home); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 195 | |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 196 | mUpGoerFive = (ViewGroup) inflater.inflate( |
| 197 | com.android.internal.R.layout.action_bar_up_container, this, false); |
| 198 | mHomeLayout = (HomeView) inflater.inflate(homeResId, mUpGoerFive, false); |
Ed Heyl | 1c60300 | 2010-11-18 12:18:23 -0800 | [diff] [blame] | 199 | |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 200 | mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, mUpGoerFive, false); |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 201 | mExpandedHomeLayout.setUp(true); |
| 202 | mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener); |
Adam Powell | 7bc3ca0 | 2011-08-26 18:29:58 -0700 | [diff] [blame] | 203 | mExpandedHomeLayout.setContentDescription(getResources().getText( |
| 204 | R.string.action_bar_up_description)); |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 205 | |
Adam Powell | 62f3303 | 2013-02-04 12:44:34 -0800 | [diff] [blame] | 206 | // This needs to highlight/be focusable on its own. |
| 207 | // TODO: Clean up the handoff between expanded/normal. |
| 208 | final Drawable upBackground = mUpGoerFive.getBackground(); |
| 209 | if (upBackground != null) { |
| 210 | mExpandedHomeLayout.setBackground(upBackground.getConstantState().newDrawable()); |
| 211 | } |
| 212 | mExpandedHomeLayout.setEnabled(true); |
| 213 | mExpandedHomeLayout.setFocusable(true); |
| 214 | |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 215 | mTitleStyleRes = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0); |
| 216 | mSubtitleStyleRes = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0); |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 217 | mProgressStyle = a.getResourceId(R.styleable.ActionBar_progressBarStyle, 0); |
| 218 | mIndeterminateProgressStyle = a.getResourceId( |
| 219 | R.styleable.ActionBar_indeterminateProgressStyle, 0); |
| 220 | |
| 221 | mProgressBarPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_progressBarPadding, 0); |
Adam Powell | 3f7f7ac | 2010-12-05 16:44:38 -0800 | [diff] [blame] | 222 | mItemPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_itemPadding, 0); |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 223 | |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 224 | setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, DISPLAY_DEFAULT)); |
| 225 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 226 | final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0); |
| 227 | if (customNavId != 0) { |
Ed Heyl | 1c60300 | 2010-11-18 12:18:23 -0800 | [diff] [blame] | 228 | mCustomNavView = (View) inflater.inflate(customNavId, this, false); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 229 | mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD; |
| 230 | setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 233 | mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0); |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 234 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 235 | a.recycle(); |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 236 | |
Ben Komalo | ad199ec | 2010-11-01 12:24:16 -0700 | [diff] [blame] | 237 | mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle); |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 238 | |
| 239 | mUpGoerFive.setOnClickListener(mUpClickListener); |
| 240 | mUpGoerFive.setClickable(true); |
| 241 | mUpGoerFive.setFocusable(true); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 242 | |
| 243 | if (getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 244 | setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 245 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 246 | } |
Adam Powell | a7db037 | 2010-06-30 17:08:47 -0700 | [diff] [blame] | 247 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 248 | @Override |
Adam Powell | 45c0b19 | 2011-07-28 15:11:57 -0700 | [diff] [blame] | 249 | protected void onConfigurationChanged(Configuration newConfig) { |
| 250 | super.onConfigurationChanged(newConfig); |
| 251 | |
Adam Powell | 07a047f | 2011-08-31 10:33:20 -0700 | [diff] [blame] | 252 | mTitleView = null; |
| 253 | mSubtitleView = null; |
| 254 | mTitleUpView = null; |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 255 | if (mTitleLayout != null && mTitleLayout.getParent() == mUpGoerFive) { |
| 256 | mUpGoerFive.removeView(mTitleLayout); |
Adam Powell | 07a047f | 2011-08-31 10:33:20 -0700 | [diff] [blame] | 257 | } |
| 258 | mTitleLayout = null; |
| 259 | if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0) { |
| 260 | initTitle(); |
| 261 | } |
Adam Powell | 425689e | 2011-09-08 18:09:33 -0700 | [diff] [blame] | 262 | |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 263 | if (mHomeDescriptionRes != 0) { |
| 264 | setHomeActionContentDescription(mHomeDescriptionRes); |
| 265 | } |
| 266 | |
Adam Powell | 425689e | 2011-09-08 18:09:33 -0700 | [diff] [blame] | 267 | if (mTabScrollView != null && mIncludeTabs) { |
| 268 | ViewGroup.LayoutParams lp = mTabScrollView.getLayoutParams(); |
Adam Powell | b844011 | 2011-09-12 19:14:11 -0700 | [diff] [blame] | 269 | if (lp != null) { |
| 270 | lp.width = LayoutParams.WRAP_CONTENT; |
| 271 | lp.height = LayoutParams.MATCH_PARENT; |
| 272 | } |
Adam Powell | 425689e | 2011-09-08 18:09:33 -0700 | [diff] [blame] | 273 | mTabScrollView.setAllowCollapse(true); |
| 274 | } |
Adam Powell | 45c0b19 | 2011-07-28 15:11:57 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Adam Powell | 915ce0d | 2011-09-28 15:52:57 -0700 | [diff] [blame] | 277 | /** |
| 278 | * Set the window callback used to invoke menu items; used for dispatching home button presses. |
| 279 | * @param cb Window callback to dispatch to |
| 280 | */ |
| 281 | public void setWindowCallback(Window.Callback cb) { |
| 282 | mWindowCallback = cb; |
| 283 | } |
| 284 | |
Adam Powell | 45c0b19 | 2011-07-28 15:11:57 -0700 | [diff] [blame] | 285 | @Override |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 286 | public void onDetachedFromWindow() { |
| 287 | super.onDetachedFromWindow(); |
| 288 | removeCallbacks(mTabSelector); |
Adam Powell | 97e1836 | 2011-10-20 15:37:18 -0700 | [diff] [blame] | 289 | if (mActionMenuPresenter != null) { |
| 290 | mActionMenuPresenter.hideOverflowMenu(); |
| 291 | mActionMenuPresenter.hideSubMenus(); |
| 292 | } |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | @Override |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 296 | public boolean shouldDelayChildPressedState() { |
| 297 | return false; |
| 298 | } |
| 299 | |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 300 | public void initProgress() { |
| 301 | mProgressView = new ProgressBar(mContext, null, 0, mProgressStyle); |
| 302 | mProgressView.setId(R.id.progress_horizontal); |
| 303 | mProgressView.setMax(10000); |
Adam Powell | 45b075d | 2012-01-09 15:41:40 -0800 | [diff] [blame] | 304 | mProgressView.setVisibility(GONE); |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 305 | addView(mProgressView); |
| 306 | } |
| 307 | |
| 308 | public void initIndeterminateProgress() { |
| 309 | mIndeterminateProgressView = new ProgressBar(mContext, null, 0, |
| 310 | mIndeterminateProgressStyle); |
| 311 | mIndeterminateProgressView.setId(R.id.progress_circular); |
Adam Powell | 45b075d | 2012-01-09 15:41:40 -0800 | [diff] [blame] | 312 | mIndeterminateProgressView.setVisibility(GONE); |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 313 | addView(mIndeterminateProgressView); |
| 314 | } |
| 315 | |
Adam Powell | a05aba9 | 2011-09-23 14:22:49 -0700 | [diff] [blame] | 316 | @Override |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 317 | public void setSplitActionBar(boolean splitActionBar) { |
| 318 | if (mSplitActionBar != splitActionBar) { |
| 319 | if (mMenuView != null) { |
Adam Powell | 894bf54 | 2011-07-22 13:39:08 -0700 | [diff] [blame] | 320 | final ViewGroup oldParent = (ViewGroup) mMenuView.getParent(); |
| 321 | if (oldParent != null) { |
| 322 | oldParent.removeView(mMenuView); |
| 323 | } |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 324 | if (splitActionBar) { |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 325 | if (mSplitView != null) { |
| 326 | mSplitView.addView(mMenuView); |
| 327 | } |
Adam Powell | f203e0a | 2012-03-06 17:40:12 -0800 | [diff] [blame] | 328 | mMenuView.getLayoutParams().width = LayoutParams.MATCH_PARENT; |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 329 | } else { |
| 330 | addView(mMenuView); |
Adam Powell | f203e0a | 2012-03-06 17:40:12 -0800 | [diff] [blame] | 331 | mMenuView.getLayoutParams().width = LayoutParams.WRAP_CONTENT; |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 332 | } |
Adam Powell | f203e0a | 2012-03-06 17:40:12 -0800 | [diff] [blame] | 333 | mMenuView.requestLayout(); |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 334 | } |
Adam Powell | a05aba9 | 2011-09-23 14:22:49 -0700 | [diff] [blame] | 335 | if (mSplitView != null) { |
| 336 | mSplitView.setVisibility(splitActionBar ? VISIBLE : GONE); |
| 337 | } |
Adam Powell | f203e0a | 2012-03-06 17:40:12 -0800 | [diff] [blame] | 338 | |
| 339 | if (mActionMenuPresenter != null) { |
| 340 | if (!splitActionBar) { |
| 341 | mActionMenuPresenter.setExpandedActionViewsExclusive( |
| 342 | getResources().getBoolean( |
| 343 | com.android.internal.R.bool.action_bar_expanded_action_views_exclusive)); |
| 344 | } else { |
| 345 | mActionMenuPresenter.setExpandedActionViewsExclusive(false); |
| 346 | // Allow full screen width in split mode. |
| 347 | mActionMenuPresenter.setWidthLimit( |
| 348 | getContext().getResources().getDisplayMetrics().widthPixels, true); |
| 349 | // No limit to the item count; use whatever will fit. |
| 350 | mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE); |
| 351 | } |
| 352 | } |
Adam Powell | a05aba9 | 2011-09-23 14:22:49 -0700 | [diff] [blame] | 353 | super.setSplitActionBar(splitActionBar); |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
| 357 | public boolean isSplitActionBar() { |
| 358 | return mSplitActionBar; |
| 359 | } |
| 360 | |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 361 | public boolean hasEmbeddedTabs() { |
| 362 | return mIncludeTabs; |
| 363 | } |
| 364 | |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 365 | public void setEmbeddedTabView(ScrollingTabContainerView tabs) { |
Adam Powell | e0adac0 | 2011-06-14 13:46:30 -0700 | [diff] [blame] | 366 | if (mTabScrollView != null) { |
| 367 | removeView(mTabScrollView); |
| 368 | } |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 369 | mTabScrollView = tabs; |
| 370 | mIncludeTabs = tabs != null; |
Adam Powell | c307642 | 2011-06-01 18:19:04 -0700 | [diff] [blame] | 371 | if (mIncludeTabs && mNavigationMode == ActionBar.NAVIGATION_MODE_TABS) { |
Adam Powell | 39a8dc4 | 2011-05-27 18:44:00 -0700 | [diff] [blame] | 372 | addView(mTabScrollView); |
Adam Powell | f5645cb | 2011-08-10 22:49:02 -0700 | [diff] [blame] | 373 | ViewGroup.LayoutParams lp = mTabScrollView.getLayoutParams(); |
| 374 | lp.width = LayoutParams.WRAP_CONTENT; |
| 375 | lp.height = LayoutParams.MATCH_PARENT; |
| 376 | tabs.setAllowCollapse(true); |
Adam Powell | 39a8dc4 | 2011-05-27 18:44:00 -0700 | [diff] [blame] | 377 | } |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Adam Powell | 8515ee8 | 2010-11-30 14:09:55 -0800 | [diff] [blame] | 380 | public void setCallback(OnNavigationListener callback) { |
Adam Powell | 96675b1 | 2010-06-10 18:58:59 -0700 | [diff] [blame] | 381 | mCallback = callback; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 382 | } |
Adam Powell | a7db037 | 2010-06-30 17:08:47 -0700 | [diff] [blame] | 383 | |
Adam Powell | 8c16aa9 | 2013-04-04 10:47:52 -0700 | [diff] [blame] | 384 | public void setMenuPrepared() { |
| 385 | mMenuPrepared = true; |
| 386 | } |
| 387 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 388 | public void setMenu(Menu menu, MenuPresenter.Callback cb) { |
Adam Powell | f2d7a5d | 2011-02-07 18:05:24 -0800 | [diff] [blame] | 389 | if (menu == mOptionsMenu) return; |
| 390 | |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 391 | if (mOptionsMenu != null) { |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 392 | mOptionsMenu.removeMenuPresenter(mActionMenuPresenter); |
| 393 | mOptionsMenu.removeMenuPresenter(mExpandedMenuPresenter); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Adam Powell | 96675b1 | 2010-06-10 18:58:59 -0700 | [diff] [blame] | 396 | MenuBuilder builder = (MenuBuilder) menu; |
| 397 | mOptionsMenu = builder; |
| 398 | if (mMenuView != null) { |
Adam Powell | 894bf54 | 2011-07-22 13:39:08 -0700 | [diff] [blame] | 399 | final ViewGroup oldParent = (ViewGroup) mMenuView.getParent(); |
| 400 | if (oldParent != null) { |
| 401 | oldParent.removeView(mMenuView); |
| 402 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 403 | } |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 404 | if (mActionMenuPresenter == null) { |
Adam Powell | 538e565 | 2011-10-11 13:47:08 -0700 | [diff] [blame] | 405 | mActionMenuPresenter = new ActionMenuPresenter(mContext); |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 406 | mActionMenuPresenter.setCallback(cb); |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 407 | mActionMenuPresenter.setId(com.android.internal.R.id.action_menu_presenter); |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 408 | mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter(); |
Adam Powell | 696cba5 | 2011-03-29 10:38:16 -0700 | [diff] [blame] | 409 | } |
Adam Powell | 3526556 | 2011-05-27 15:29:41 -0700 | [diff] [blame] | 410 | |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 411 | ActionMenuView menuView; |
Adam Powell | 96675b1 | 2010-06-10 18:58:59 -0700 | [diff] [blame] | 412 | final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, |
| 413 | LayoutParams.MATCH_PARENT); |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 414 | if (!mSplitActionBar) { |
Adam Powell | b187cd9 | 2011-07-20 14:17:56 -0700 | [diff] [blame] | 415 | mActionMenuPresenter.setExpandedActionViewsExclusive( |
| 416 | getResources().getBoolean( |
| 417 | com.android.internal.R.bool.action_bar_expanded_action_views_exclusive)); |
Adam Powell | f35d049 | 2011-08-17 13:56:47 -0700 | [diff] [blame] | 418 | configPresenters(builder); |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 419 | menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); |
Adam Powell | 894bf54 | 2011-07-22 13:39:08 -0700 | [diff] [blame] | 420 | final ViewGroup oldParent = (ViewGroup) menuView.getParent(); |
| 421 | if (oldParent != null && oldParent != this) { |
| 422 | oldParent.removeView(menuView); |
| 423 | } |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 424 | addView(menuView, layoutParams); |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 425 | } else { |
Adam Powell | b187cd9 | 2011-07-20 14:17:56 -0700 | [diff] [blame] | 426 | mActionMenuPresenter.setExpandedActionViewsExclusive(false); |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 427 | // Allow full screen width in split mode. |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 428 | mActionMenuPresenter.setWidthLimit( |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 429 | getContext().getResources().getDisplayMetrics().widthPixels, true); |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 430 | // No limit to the item count; use whatever will fit. |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 431 | mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE); |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 432 | // Span the whole width |
| 433 | layoutParams.width = LayoutParams.MATCH_PARENT; |
Adam Powell | f35d049 | 2011-08-17 13:56:47 -0700 | [diff] [blame] | 434 | configPresenters(builder); |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 435 | menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 436 | if (mSplitView != null) { |
Adam Powell | 894bf54 | 2011-07-22 13:39:08 -0700 | [diff] [blame] | 437 | final ViewGroup oldParent = (ViewGroup) menuView.getParent(); |
| 438 | if (oldParent != null && oldParent != mSplitView) { |
| 439 | oldParent.removeView(menuView); |
| 440 | } |
Adam Powell | 9a5cc28 | 2011-08-28 16:18:16 -0700 | [diff] [blame] | 441 | menuView.setVisibility(getAnimatedVisibility()); |
Adam Powell | 1ab418a | 2011-06-09 20:49:49 -0700 | [diff] [blame] | 442 | mSplitView.addView(menuView, layoutParams); |
| 443 | } else { |
| 444 | // We'll add this later if we missed it this time. |
| 445 | menuView.setLayoutParams(layoutParams); |
| 446 | } |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 447 | } |
Adam Powell | 96675b1 | 2010-06-10 18:58:59 -0700 | [diff] [blame] | 448 | mMenuView = menuView; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 449 | } |
Adam Powell | a7db037 | 2010-06-30 17:08:47 -0700 | [diff] [blame] | 450 | |
Adam Powell | f35d049 | 2011-08-17 13:56:47 -0700 | [diff] [blame] | 451 | private void configPresenters(MenuBuilder builder) { |
| 452 | if (builder != null) { |
| 453 | builder.addMenuPresenter(mActionMenuPresenter); |
| 454 | builder.addMenuPresenter(mExpandedMenuPresenter); |
| 455 | } else { |
| 456 | mActionMenuPresenter.initForMenu(mContext, null); |
| 457 | mExpandedMenuPresenter.initForMenu(mContext, null); |
| 458 | mActionMenuPresenter.updateMenuView(true); |
| 459 | mExpandedMenuPresenter.updateMenuView(true); |
| 460 | } |
| 461 | } |
| 462 | |
Adam Powell | b80d332 | 2011-07-15 21:33:11 -0700 | [diff] [blame] | 463 | public boolean hasExpandedActionView() { |
| 464 | return mExpandedMenuPresenter != null && |
| 465 | mExpandedMenuPresenter.mCurrentExpandedItem != null; |
| 466 | } |
| 467 | |
| 468 | public void collapseActionView() { |
| 469 | final MenuItemImpl item = mExpandedMenuPresenter == null ? null : |
| 470 | mExpandedMenuPresenter.mCurrentExpandedItem; |
| 471 | if (item != null) { |
| 472 | item.collapseActionView(); |
| 473 | } |
| 474 | } |
| 475 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 476 | public void setCustomNavigationView(View view) { |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 477 | final boolean showCustom = (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0; |
| 478 | if (mCustomNavView != null && showCustom) { |
| 479 | removeView(mCustomNavView); |
| 480 | } |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 481 | mCustomNavView = view; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 482 | if (mCustomNavView != null && showCustom) { |
| 483 | addView(mCustomNavView); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 484 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 485 | } |
Adam Powell | a7db037 | 2010-06-30 17:08:47 -0700 | [diff] [blame] | 486 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 487 | public CharSequence getTitle() { |
| 488 | return mTitle; |
| 489 | } |
Adam Powell | a7db037 | 2010-06-30 17:08:47 -0700 | [diff] [blame] | 490 | |
Adam Powell | e92ea34 | 2010-07-14 14:45:50 -0700 | [diff] [blame] | 491 | /** |
| 492 | * Set the action bar title. This will always replace or override window titles. |
| 493 | * @param title Title to set |
| 494 | * |
| 495 | * @see #setWindowTitle(CharSequence) |
| 496 | */ |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 497 | public void setTitle(CharSequence title) { |
Adam Powell | e92ea34 | 2010-07-14 14:45:50 -0700 | [diff] [blame] | 498 | mUserTitle = true; |
| 499 | setTitleImpl(title); |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * Set the window title. A window title will always be replaced or overridden by a user title. |
| 504 | * @param title Title to set |
| 505 | * |
| 506 | * @see #setTitle(CharSequence) |
| 507 | */ |
| 508 | public void setWindowTitle(CharSequence title) { |
| 509 | if (!mUserTitle) { |
| 510 | setTitleImpl(title); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | private void setTitleImpl(CharSequence title) { |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 515 | mTitle = title; |
| 516 | if (mTitleView != null) { |
| 517 | mTitleView.setText(title); |
Adam Powell | b0e217e | 2011-08-12 11:36:51 -0700 | [diff] [blame] | 518 | final boolean visible = mExpandedActionView == null && |
Adam Powell | 71f3417 | 2011-08-11 20:07:11 -0700 | [diff] [blame] | 519 | (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0 && |
Adam Powell | b0e217e | 2011-08-12 11:36:51 -0700 | [diff] [blame] | 520 | (!TextUtils.isEmpty(mTitle) || !TextUtils.isEmpty(mSubtitle)); |
| 521 | mTitleLayout.setVisibility(visible ? VISIBLE : GONE); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 522 | } |
| 523 | if (mLogoNavItem != null) { |
| 524 | mLogoNavItem.setTitle(title); |
| 525 | } |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 526 | mUpGoerFive.setContentDescription(buildHomeContentDescription()); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 527 | } |
Adam Powell | a7db037 | 2010-06-30 17:08:47 -0700 | [diff] [blame] | 528 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 529 | public CharSequence getSubtitle() { |
| 530 | return mSubtitle; |
| 531 | } |
Adam Powell | a7db037 | 2010-06-30 17:08:47 -0700 | [diff] [blame] | 532 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 533 | public void setSubtitle(CharSequence subtitle) { |
| 534 | mSubtitle = subtitle; |
| 535 | if (mSubtitleView != null) { |
| 536 | mSubtitleView.setText(subtitle); |
Adam Powell | 0458796 | 2010-11-11 22:15:07 -0800 | [diff] [blame] | 537 | mSubtitleView.setVisibility(subtitle != null ? VISIBLE : GONE); |
Adam Powell | b0e217e | 2011-08-12 11:36:51 -0700 | [diff] [blame] | 538 | final boolean visible = mExpandedActionView == null && |
Adam Powell | 71f3417 | 2011-08-11 20:07:11 -0700 | [diff] [blame] | 539 | (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0 && |
Adam Powell | b0e217e | 2011-08-12 11:36:51 -0700 | [diff] [blame] | 540 | (!TextUtils.isEmpty(mTitle) || !TextUtils.isEmpty(mSubtitle)); |
| 541 | mTitleLayout.setVisibility(visible ? VISIBLE : GONE); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 542 | } |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 543 | mUpGoerFive.setContentDescription(buildHomeContentDescription()); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 544 | } |
Adam Powell | a7db037 | 2010-06-30 17:08:47 -0700 | [diff] [blame] | 545 | |
Adam Powell | c29f4e5 | 2011-07-13 20:40:52 -0700 | [diff] [blame] | 546 | public void setHomeButtonEnabled(boolean enable) { |
Adam Powell | 07cf971 | 2013-02-05 16:13:57 -0800 | [diff] [blame] | 547 | setHomeButtonEnabled(enable, true); |
| 548 | } |
| 549 | |
| 550 | private void setHomeButtonEnabled(boolean enable, boolean recordState) { |
| 551 | if (recordState) { |
| 552 | mWasHomeEnabled = enable; |
| 553 | } |
| 554 | |
| 555 | if (mExpandedActionView != null) { |
| 556 | // There's an action view currently showing and we want to keep the state |
| 557 | // configured for the action view at the moment. If we needed to record the |
| 558 | // new state for later we will have done so above. |
| 559 | return; |
| 560 | } |
| 561 | |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 562 | mUpGoerFive.setEnabled(enable); |
| 563 | mUpGoerFive.setFocusable(enable); |
Adam Powell | c29f4e5 | 2011-07-13 20:40:52 -0700 | [diff] [blame] | 564 | // Make sure the home button has an accurate content description for accessibility. |
| 565 | if (!enable) { |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 566 | mUpGoerFive.setContentDescription(null); |
| 567 | mUpGoerFive.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); |
Adam Powell | c29f4e5 | 2011-07-13 20:40:52 -0700 | [diff] [blame] | 568 | } else { |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 569 | mUpGoerFive.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_AUTO); |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 570 | mUpGoerFive.setContentDescription(buildHomeContentDescription()); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Compose a content description for the Home/Up affordance. |
| 576 | * |
| 577 | * <p>As this encompasses the icon/logo, title and subtitle all in one, we need |
| 578 | * a description for the whole wad of stuff that can be localized properly.</p> |
| 579 | */ |
| 580 | private CharSequence buildHomeContentDescription() { |
| 581 | final CharSequence homeDesc; |
| 582 | if (mHomeDescription != null) { |
| 583 | homeDesc = mHomeDescription; |
| 584 | } else { |
Casey Burkhardt | 4aeb961 | 2012-10-01 14:13:41 -0700 | [diff] [blame] | 585 | if ((mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0) { |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 586 | homeDesc = mContext.getResources().getText(R.string.action_bar_up_description); |
Casey Burkhardt | 4aeb961 | 2012-10-01 14:13:41 -0700 | [diff] [blame] | 587 | } else { |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 588 | homeDesc = mContext.getResources().getText(R.string.action_bar_home_description); |
Casey Burkhardt | 4aeb961 | 2012-10-01 14:13:41 -0700 | [diff] [blame] | 589 | } |
Adam Powell | c29f4e5 | 2011-07-13 20:40:52 -0700 | [diff] [blame] | 590 | } |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 591 | |
| 592 | final CharSequence title = getTitle(); |
| 593 | final CharSequence subtitle = getSubtitle(); |
| 594 | if (!TextUtils.isEmpty(title)) { |
| 595 | final String result; |
| 596 | if (!TextUtils.isEmpty(subtitle)) { |
| 597 | result = getResources().getString( |
| 598 | R.string.action_bar_home_subtitle_description_format, |
| 599 | title, subtitle, homeDesc); |
| 600 | } else { |
| 601 | result = getResources().getString(R.string.action_bar_home_description_format, |
| 602 | title, homeDesc); |
| 603 | } |
| 604 | return result; |
| 605 | } |
| 606 | return homeDesc; |
Adam Powell | c29f4e5 | 2011-07-13 20:40:52 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 609 | public void setDisplayOptions(int options) { |
Adam Powell | 82f24e8 | 2011-08-18 20:15:20 -0700 | [diff] [blame] | 610 | final int flagsChanged = mDisplayOptions == -1 ? -1 : options ^ mDisplayOptions; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 611 | mDisplayOptions = options; |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 612 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 613 | if ((flagsChanged & DISPLAY_RELAYOUT_MASK) != 0) { |
Adam Powell | 54c7d7e | 2011-06-17 20:30:13 -0700 | [diff] [blame] | 614 | final boolean showHome = (options & ActionBar.DISPLAY_SHOW_HOME) != 0; |
Adam Powell | a8743f1 | 2011-11-11 18:35:53 -0800 | [diff] [blame] | 615 | final int vis = showHome && mExpandedActionView == null ? VISIBLE : GONE; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 616 | mHomeLayout.setVisibility(vis); |
| 617 | |
| 618 | if ((flagsChanged & ActionBar.DISPLAY_HOME_AS_UP) != 0) { |
Adam Powell | c29f4e5 | 2011-07-13 20:40:52 -0700 | [diff] [blame] | 619 | final boolean setUp = (options & ActionBar.DISPLAY_HOME_AS_UP) != 0; |
| 620 | mHomeLayout.setUp(setUp); |
| 621 | |
| 622 | // Showing home as up implicitly enables interaction with it. |
| 623 | // In honeycomb it was always enabled, so make this transition |
| 624 | // a bit easier for developers in the common case. |
| 625 | // (It would be silly to show it as up without responding to it.) |
| 626 | if (setUp) { |
| 627 | setHomeButtonEnabled(true); |
| 628 | } |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 629 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 630 | |
Ed Heyl | 1c60300 | 2010-11-18 12:18:23 -0800 | [diff] [blame] | 631 | if ((flagsChanged & ActionBar.DISPLAY_USE_LOGO) != 0) { |
| 632 | final boolean logoVis = mLogo != null && (options & ActionBar.DISPLAY_USE_LOGO) != 0; |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 633 | mHomeLayout.setIcon(logoVis ? mLogo : mIcon); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | if ((flagsChanged & ActionBar.DISPLAY_SHOW_TITLE) != 0) { |
| 637 | if ((options & ActionBar.DISPLAY_SHOW_TITLE) != 0) { |
| 638 | initTitle(); |
| 639 | } else { |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 640 | mUpGoerFive.removeView(mTitleLayout); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
Adam Powell | 15a16a8 | 2011-06-20 10:35:27 -0700 | [diff] [blame] | 644 | if (mTitleLayout != null && (flagsChanged & |
Adam Powell | 54c7d7e | 2011-06-17 20:30:13 -0700 | [diff] [blame] | 645 | (ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME)) != 0) { |
Adam Powell | b1e2f25 | 2011-08-22 17:42:12 -0700 | [diff] [blame] | 646 | final boolean homeAsUp = (mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0; |
| 647 | mTitleUpView.setVisibility(!showHome ? (homeAsUp ? VISIBLE : INVISIBLE) : GONE); |
Adam Powell | 54c7d7e | 2011-06-17 20:30:13 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 650 | if ((flagsChanged & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) { |
| 651 | if ((options & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) { |
| 652 | addView(mCustomNavView); |
| 653 | } else { |
| 654 | removeView(mCustomNavView); |
| 655 | } |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 656 | } |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 657 | |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 658 | if (mTitleLayout != null && |
| 659 | (flagsChanged & ActionBar.DISPLAY_TITLE_MULTIPLE_LINES) != 0) { |
| 660 | if ((options & ActionBar.DISPLAY_TITLE_MULTIPLE_LINES) != 0) { |
| 661 | mTitleView.setSingleLine(false); |
| 662 | mTitleView.setMaxLines(2); |
| 663 | } else { |
| 664 | mTitleView.setMaxLines(1); |
| 665 | mTitleView.setSingleLine(true); |
| 666 | } |
| 667 | } |
| 668 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 669 | requestLayout(); |
| 670 | } else { |
| 671 | invalidate(); |
| 672 | } |
Adam Powell | f3cd1d9 | 2011-04-26 17:31:52 -0700 | [diff] [blame] | 673 | |
| 674 | // Make sure the home button has an accurate content description for accessibility. |
Adam Powell | c29f4e5 | 2011-07-13 20:40:52 -0700 | [diff] [blame] | 675 | if (!mHomeLayout.isEnabled()) { |
Adam Powell | f3cd1d9 | 2011-04-26 17:31:52 -0700 | [diff] [blame] | 676 | mHomeLayout.setContentDescription(null); |
Casey Burkhardt | 4aeb961 | 2012-10-01 14:13:41 -0700 | [diff] [blame] | 677 | mHomeLayout.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); |
Adam Powell | f3cd1d9 | 2011-04-26 17:31:52 -0700 | [diff] [blame] | 678 | } else { |
Casey Burkhardt | 4aeb961 | 2012-10-01 14:13:41 -0700 | [diff] [blame] | 679 | mHomeLayout.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_AUTO); |
| 680 | if ((options & ActionBar.DISPLAY_HOME_AS_UP) != 0) { |
| 681 | mHomeLayout.setContentDescription(mContext.getResources().getText( |
| 682 | R.string.action_bar_up_description)); |
| 683 | } else { |
| 684 | mHomeLayout.setContentDescription(mContext.getResources().getText( |
| 685 | R.string.action_bar_home_description)); |
| 686 | } |
Adam Powell | f3cd1d9 | 2011-04-26 17:31:52 -0700 | [diff] [blame] | 687 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 690 | public void setIcon(Drawable icon) { |
| 691 | mIcon = icon; |
| 692 | if (icon != null && |
| 693 | ((mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) == 0 || mLogo == null)) { |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 694 | mHomeLayout.setIcon(icon); |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 695 | } |
Adam Powell | f821819 | 2012-02-21 17:10:10 -0800 | [diff] [blame] | 696 | if (mExpandedActionView != null) { |
| 697 | mExpandedHomeLayout.setIcon(mIcon.getConstantState().newDrawable(getResources())); |
| 698 | } |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 699 | } |
| 700 | |
Adam Powell | 45c515b | 2011-04-21 18:50:20 -0700 | [diff] [blame] | 701 | public void setIcon(int resId) { |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 702 | setIcon(resId != 0 ? mContext.getResources().getDrawable(resId) : null); |
| 703 | } |
| 704 | |
| 705 | public boolean hasIcon() { |
| 706 | return mIcon != null; |
Adam Powell | 45c515b | 2011-04-21 18:50:20 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 709 | public void setLogo(Drawable logo) { |
| 710 | mLogo = logo; |
| 711 | if (logo != null && (mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) != 0) { |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 712 | mHomeLayout.setIcon(logo); |
Adam Powell | 1969b87 | 2011-03-22 11:52:48 -0700 | [diff] [blame] | 713 | } |
| 714 | } |
| 715 | |
Adam Powell | 45c515b | 2011-04-21 18:50:20 -0700 | [diff] [blame] | 716 | public void setLogo(int resId) { |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 717 | setLogo(resId != 0 ? mContext.getResources().getDrawable(resId) : null); |
| 718 | } |
| 719 | |
| 720 | public boolean hasLogo() { |
| 721 | return mLogo != null; |
Adam Powell | 45c515b | 2011-04-21 18:50:20 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 724 | public void setNavigationMode(int mode) { |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 725 | final int oldMode = mNavigationMode; |
| 726 | if (mode != oldMode) { |
| 727 | switch (oldMode) { |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 728 | case ActionBar.NAVIGATION_MODE_LIST: |
Adam Powell | c307642 | 2011-06-01 18:19:04 -0700 | [diff] [blame] | 729 | if (mListNavLayout != null) { |
Adam Powell | 3f7f7ac | 2010-12-05 16:44:38 -0800 | [diff] [blame] | 730 | removeView(mListNavLayout); |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 731 | } |
| 732 | break; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 733 | case ActionBar.NAVIGATION_MODE_TABS: |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 734 | if (mTabScrollView != null && mIncludeTabs) { |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 735 | removeView(mTabScrollView); |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 736 | } |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 737 | } |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 738 | |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 739 | switch (mode) { |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 740 | case ActionBar.NAVIGATION_MODE_LIST: |
Adam Powell | 3f7f7ac | 2010-12-05 16:44:38 -0800 | [diff] [blame] | 741 | if (mSpinner == null) { |
| 742 | mSpinner = new Spinner(mContext, null, |
| 743 | com.android.internal.R.attr.actionDropDownStyle); |
Adam Powell | 29c04ef | 2012-12-10 15:42:22 -0800 | [diff] [blame] | 744 | mSpinner.setId(com.android.internal.R.id.action_bar_spinner); |
Adam Powell | 3f7f7ac | 2010-12-05 16:44:38 -0800 | [diff] [blame] | 745 | mListNavLayout = new LinearLayout(mContext, null, |
| 746 | com.android.internal.R.attr.actionBarTabBarStyle); |
| 747 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( |
Adam Powell | e7d4684 | 2011-01-13 21:36:09 -0800 | [diff] [blame] | 748 | LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); |
Adam Powell | 3f7f7ac | 2010-12-05 16:44:38 -0800 | [diff] [blame] | 749 | params.gravity = Gravity.CENTER; |
| 750 | mListNavLayout.addView(mSpinner, params); |
| 751 | } |
| 752 | if (mSpinner.getAdapter() != mSpinnerAdapter) { |
| 753 | mSpinner.setAdapter(mSpinnerAdapter); |
| 754 | } |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 755 | mSpinner.setOnItemSelectedListener(mNavItemSelectedListener); |
Adam Powell | 3f7f7ac | 2010-12-05 16:44:38 -0800 | [diff] [blame] | 756 | addView(mListNavLayout); |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 757 | break; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 758 | case ActionBar.NAVIGATION_MODE_TABS: |
Adam Powell | f8ac6b7 | 2011-05-23 18:14:09 -0700 | [diff] [blame] | 759 | if (mTabScrollView != null && mIncludeTabs) { |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 760 | addView(mTabScrollView); |
| 761 | } |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 762 | break; |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 763 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 764 | mNavigationMode = mode; |
| 765 | requestLayout(); |
| 766 | } |
| 767 | } |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 768 | |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 769 | public void setDropdownAdapter(SpinnerAdapter adapter) { |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 770 | mSpinnerAdapter = adapter; |
| 771 | if (mSpinner != null) { |
| 772 | mSpinner.setAdapter(adapter); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | public SpinnerAdapter getDropdownAdapter() { |
| 777 | return mSpinnerAdapter; |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 778 | } |
Adam Powell | 1780977 | 2010-07-21 13:25:11 -0700 | [diff] [blame] | 779 | |
| 780 | public void setDropdownSelectedPosition(int position) { |
| 781 | mSpinner.setSelection(position); |
| 782 | } |
| 783 | |
| 784 | public int getDropdownSelectedPosition() { |
| 785 | return mSpinner.getSelectedItemPosition(); |
| 786 | } |
| 787 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 788 | public View getCustomNavigationView() { |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 789 | return mCustomNavView; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 790 | } |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 791 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 792 | public int getNavigationMode() { |
| 793 | return mNavigationMode; |
| 794 | } |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 795 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 796 | public int getDisplayOptions() { |
| 797 | return mDisplayOptions; |
| 798 | } |
Adam Powell | a7db037 | 2010-06-30 17:08:47 -0700 | [diff] [blame] | 799 | |
| 800 | @Override |
Adam Powell | 9a5cc28 | 2011-08-28 16:18:16 -0700 | [diff] [blame] | 801 | protected ViewGroup.LayoutParams generateDefaultLayoutParams() { |
Adam Powell | a7db037 | 2010-06-30 17:08:47 -0700 | [diff] [blame] | 802 | // Used by custom nav views if they don't supply layout params. Everything else |
| 803 | // added to an ActionBarView should have them already. |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 804 | return new ActionBar.LayoutParams(DEFAULT_CUSTOM_GRAVITY); |
Adam Powell | a7db037 | 2010-06-30 17:08:47 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 807 | @Override |
| 808 | protected void onFinishInflate() { |
| 809 | super.onFinishInflate(); |
| 810 | |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 811 | mUpGoerFive.addView(mHomeLayout, 0); |
| 812 | addView(mUpGoerFive); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 813 | |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 814 | if (mCustomNavView != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) { |
| 815 | final ViewParent parent = mCustomNavView.getParent(); |
| 816 | if (parent != this) { |
| 817 | if (parent instanceof ViewGroup) { |
| 818 | ((ViewGroup) parent).removeView(mCustomNavView); |
| 819 | } |
Adam Powell | a408291 | 2010-06-04 18:34:02 -0700 | [diff] [blame] | 820 | addView(mCustomNavView); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 821 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 822 | } |
| 823 | } |
Adam Powell | c8b0b00 | 2011-06-23 14:39:05 -0700 | [diff] [blame] | 824 | |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 825 | private void initTitle() { |
Adam Powell | 15a16a8 | 2011-06-20 10:35:27 -0700 | [diff] [blame] | 826 | if (mTitleLayout == null) { |
| 827 | LayoutInflater inflater = LayoutInflater.from(getContext()); |
Adam Powell | 9e58df5 | 2011-08-15 17:06:49 -0700 | [diff] [blame] | 828 | mTitleLayout = (LinearLayout) inflater.inflate(R.layout.action_bar_title_item, |
| 829 | this, false); |
Adam Powell | 15a16a8 | 2011-06-20 10:35:27 -0700 | [diff] [blame] | 830 | mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title); |
| 831 | mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle); |
| 832 | mTitleUpView = (View) mTitleLayout.findViewById(R.id.up); |
Adam Powell | 54c7d7e | 2011-06-17 20:30:13 -0700 | [diff] [blame] | 833 | |
Adam Powell | 15a16a8 | 2011-06-20 10:35:27 -0700 | [diff] [blame] | 834 | if (mTitleStyleRes != 0) { |
| 835 | mTitleView.setTextAppearance(mContext, mTitleStyleRes); |
| 836 | } |
| 837 | if (mTitle != null) { |
| 838 | mTitleView.setText(mTitle); |
| 839 | } |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 840 | |
Adam Powell | 15a16a8 | 2011-06-20 10:35:27 -0700 | [diff] [blame] | 841 | if (mSubtitleStyleRes != 0) { |
| 842 | mSubtitleView.setTextAppearance(mContext, mSubtitleStyleRes); |
| 843 | } |
| 844 | if (mSubtitle != null) { |
| 845 | mSubtitleView.setText(mSubtitle); |
| 846 | mSubtitleView.setVisibility(VISIBLE); |
| 847 | } |
| 848 | |
| 849 | final boolean homeAsUp = (mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0; |
Adam Powell | b1e2f25 | 2011-08-22 17:42:12 -0700 | [diff] [blame] | 850 | final boolean showHome = (mDisplayOptions & ActionBar.DISPLAY_SHOW_HOME) != 0; |
Adam Powell | 6231ab8 | 2012-06-22 14:08:11 -0700 | [diff] [blame] | 851 | final boolean showTitleUp = !showHome; |
| 852 | mTitleUpView.setVisibility(showTitleUp ? (homeAsUp ? VISIBLE : INVISIBLE) : GONE); |
Adam Powell | 0e94b51 | 2010-06-29 17:58:20 -0700 | [diff] [blame] | 853 | } |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 854 | |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 855 | mUpGoerFive.addView(mTitleLayout); |
Adam Powell | 82f24e8 | 2011-08-18 20:15:20 -0700 | [diff] [blame] | 856 | if (mExpandedActionView != null || |
| 857 | (TextUtils.isEmpty(mTitle) && TextUtils.isEmpty(mSubtitle))) { |
| 858 | // Don't show while in expanded mode or with empty text |
Adam Powell | 71f3417 | 2011-08-11 20:07:11 -0700 | [diff] [blame] | 859 | mTitleLayout.setVisibility(GONE); |
Adam Powell | 6684e92 | 2013-03-26 15:38:26 -0700 | [diff] [blame] | 860 | } else { |
| 861 | mTitleLayout.setVisibility(VISIBLE); |
Adam Powell | 71f3417 | 2011-08-11 20:07:11 -0700 | [diff] [blame] | 862 | } |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 863 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 864 | |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 865 | public void setContextView(ActionBarContextView view) { |
| 866 | mContextView = view; |
| 867 | } |
| 868 | |
Adam Powell | d21aa12 | 2011-05-27 13:09:52 -0700 | [diff] [blame] | 869 | public void setCollapsable(boolean collapsable) { |
| 870 | mIsCollapsable = collapsable; |
| 871 | } |
| 872 | |
Adam Powell | f6ce6a9 | 2011-06-29 10:25:01 -0700 | [diff] [blame] | 873 | public boolean isCollapsed() { |
| 874 | return mIsCollapsed; |
| 875 | } |
| 876 | |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 877 | /** |
| 878 | * @return True if any characters in the title were truncated |
| 879 | */ |
| 880 | public boolean isTitleTruncated() { |
| 881 | if (mTitleView == null) { |
| 882 | return false; |
| 883 | } |
| 884 | |
| 885 | final Layout titleLayout = mTitleView.getLayout(); |
| 886 | if (titleLayout == null) { |
| 887 | return false; |
| 888 | } |
| 889 | |
| 890 | final int lineCount = titleLayout.getLineCount(); |
| 891 | for (int i = 0; i < lineCount; i++) { |
| 892 | if (titleLayout.getEllipsisCount(i) > 0) { |
| 893 | return true; |
| 894 | } |
| 895 | } |
| 896 | return false; |
| 897 | } |
| 898 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 899 | @Override |
| 900 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Adam Powell | d21aa12 | 2011-05-27 13:09:52 -0700 | [diff] [blame] | 901 | final int childCount = getChildCount(); |
| 902 | if (mIsCollapsable) { |
| 903 | int visibleChildren = 0; |
| 904 | for (int i = 0; i < childCount; i++) { |
| 905 | final View child = getChildAt(i); |
| 906 | if (child.getVisibility() != GONE && |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 907 | !(child == mMenuView && mMenuView.getChildCount() == 0) && |
| 908 | child != mUpGoerFive) { |
| 909 | visibleChildren++; |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | final int upChildCount = mUpGoerFive.getChildCount(); |
| 914 | for (int i = 0; i < upChildCount; i++) { |
| 915 | final View child = mUpGoerFive.getChildAt(i); |
| 916 | if (child.getVisibility() != GONE) { |
Adam Powell | d21aa12 | 2011-05-27 13:09:52 -0700 | [diff] [blame] | 917 | visibleChildren++; |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | if (visibleChildren == 0) { |
| 922 | // No size for an empty action bar when collapsable. |
| 923 | setMeasuredDimension(0, 0); |
Adam Powell | f6ce6a9 | 2011-06-29 10:25:01 -0700 | [diff] [blame] | 924 | mIsCollapsed = true; |
Adam Powell | d21aa12 | 2011-05-27 13:09:52 -0700 | [diff] [blame] | 925 | return; |
| 926 | } |
| 927 | } |
Adam Powell | f6ce6a9 | 2011-06-29 10:25:01 -0700 | [diff] [blame] | 928 | mIsCollapsed = false; |
Adam Powell | d21aa12 | 2011-05-27 13:09:52 -0700 | [diff] [blame] | 929 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 930 | int widthMode = MeasureSpec.getMode(widthMeasureSpec); |
| 931 | if (widthMode != MeasureSpec.EXACTLY) { |
| 932 | throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + |
| 933 | "with android:layout_width=\"match_parent\" (or fill_parent)"); |
| 934 | } |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 935 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 936 | int heightMode = MeasureSpec.getMode(heightMeasureSpec); |
| 937 | if (heightMode != MeasureSpec.AT_MOST) { |
| 938 | throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + |
| 939 | "with android:layout_height=\"wrap_content\""); |
| 940 | } |
| 941 | |
| 942 | int contentWidth = MeasureSpec.getSize(widthMeasureSpec); |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 943 | |
Adam Powell | 570470a | 2012-08-06 17:00:17 -0700 | [diff] [blame] | 944 | int maxHeight = mContentHeight >= 0 ? |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 945 | mContentHeight : MeasureSpec.getSize(heightMeasureSpec); |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 946 | |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 947 | final int verticalPadding = getPaddingTop() + getPaddingBottom(); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 948 | final int paddingLeft = getPaddingLeft(); |
| 949 | final int paddingRight = getPaddingRight(); |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 950 | final int height = maxHeight - verticalPadding; |
Adam Powell | a170078 | 2010-05-13 13:27:35 -0700 | [diff] [blame] | 951 | final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST); |
Adam Powell | 6322af5 | 2012-08-08 15:59:12 -0700 | [diff] [blame] | 952 | final int exactHeightSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 953 | |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 954 | int availableWidth = contentWidth - paddingLeft - paddingRight; |
| 955 | int leftOfCenter = availableWidth / 2; |
| 956 | int rightOfCenter = leftOfCenter; |
| 957 | |
Adam Powell | b1e2f25 | 2011-08-22 17:42:12 -0700 | [diff] [blame] | 958 | HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout; |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 959 | |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 960 | int homeWidth = 0; |
| 961 | if (homeLayout.getVisibility() != GONE && homeLayout.getParent() == mUpGoerFive) { |
Adam Powell | 9a5cc28 | 2011-08-28 16:18:16 -0700 | [diff] [blame] | 962 | final ViewGroup.LayoutParams lp = homeLayout.getLayoutParams(); |
Adam Powell | 0d5d1b7e | 2011-06-22 17:40:40 -0700 | [diff] [blame] | 963 | int homeWidthSpec; |
| 964 | if (lp.width < 0) { |
| 965 | homeWidthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST); |
| 966 | } else { |
| 967 | homeWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY); |
| 968 | } |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 969 | |
| 970 | /* |
| 971 | * This is a little weird. |
| 972 | * We're only measuring the *home* affordance within the Up container here |
| 973 | * on purpose, because we want to give the available space to all other views before |
| 974 | * the title text. We'll remeasure the whole up container again later. |
| 975 | */ |
Adam Powell | 6322af5 | 2012-08-08 15:59:12 -0700 | [diff] [blame] | 976 | homeLayout.measure(homeWidthSpec, exactHeightSpec); |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 977 | homeWidth = homeLayout.getMeasuredWidth(); |
| 978 | final int homeOffsetWidth = homeWidth + homeLayout.getStartOffset(); |
| 979 | availableWidth = Math.max(0, availableWidth - homeOffsetWidth); |
| 980 | leftOfCenter = Math.max(0, availableWidth - homeOffsetWidth); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 981 | } |
Casey Burkhardt | 8452a7f | 2013-04-30 15:56:41 -0700 | [diff] [blame] | 982 | |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 983 | if (mMenuView != null && mMenuView.getParent() == this) { |
Adam Powell | 6322af5 | 2012-08-08 15:59:12 -0700 | [diff] [blame] | 984 | availableWidth = measureChildView(mMenuView, availableWidth, exactHeightSpec, 0); |
Adam Powell | 1b4a162 | 2011-05-17 12:13:13 -0700 | [diff] [blame] | 985 | rightOfCenter = Math.max(0, rightOfCenter - mMenuView.getMeasuredWidth()); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 986 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 987 | |
Adam Powell | aa8e509b | 2011-08-25 09:29:21 -0700 | [diff] [blame] | 988 | if (mIndeterminateProgressView != null && |
| 989 | mIndeterminateProgressView.getVisibility() != GONE) { |
| 990 | availableWidth = measureChildView(mIndeterminateProgressView, availableWidth, |
| 991 | childSpecHeight, 0); |
| 992 | rightOfCenter = Math.max(0, |
| 993 | rightOfCenter - mIndeterminateProgressView.getMeasuredWidth()); |
| 994 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 995 | |
Adam Powell | aa8e509b | 2011-08-25 09:29:21 -0700 | [diff] [blame] | 996 | final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE && |
| 997 | (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0; |
| 998 | |
| 999 | if (mExpandedActionView == null) { |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1000 | switch (mNavigationMode) { |
| 1001 | case ActionBar.NAVIGATION_MODE_LIST: |
| 1002 | if (mListNavLayout != null) { |
| 1003 | final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding; |
| 1004 | availableWidth = Math.max(0, availableWidth - itemPaddingSize); |
| 1005 | leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize); |
| 1006 | mListNavLayout.measure( |
| 1007 | MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST), |
| 1008 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); |
| 1009 | final int listNavWidth = mListNavLayout.getMeasuredWidth(); |
| 1010 | availableWidth = Math.max(0, availableWidth - listNavWidth); |
| 1011 | leftOfCenter = Math.max(0, leftOfCenter - listNavWidth); |
| 1012 | } |
| 1013 | break; |
| 1014 | case ActionBar.NAVIGATION_MODE_TABS: |
| 1015 | if (mTabScrollView != null) { |
| 1016 | final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding; |
| 1017 | availableWidth = Math.max(0, availableWidth - itemPaddingSize); |
| 1018 | leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize); |
| 1019 | mTabScrollView.measure( |
| 1020 | MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST), |
| 1021 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); |
| 1022 | final int tabWidth = mTabScrollView.getMeasuredWidth(); |
| 1023 | availableWidth = Math.max(0, availableWidth - tabWidth); |
| 1024 | leftOfCenter = Math.max(0, leftOfCenter - tabWidth); |
| 1025 | } |
| 1026 | break; |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 1027 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1030 | View customView = null; |
| 1031 | if (mExpandedActionView != null) { |
| 1032 | customView = mExpandedActionView; |
| 1033 | } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && |
| 1034 | mCustomNavView != null) { |
| 1035 | customView = mCustomNavView; |
| 1036 | } |
| 1037 | |
| 1038 | if (customView != null) { |
Adam Powell | 9a5cc28 | 2011-08-28 16:18:16 -0700 | [diff] [blame] | 1039 | final ViewGroup.LayoutParams lp = generateLayoutParams(customView.getLayoutParams()); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1040 | final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ? |
| 1041 | (ActionBar.LayoutParams) lp : null; |
| 1042 | |
| 1043 | int horizontalMargin = 0; |
| 1044 | int verticalMargin = 0; |
| 1045 | if (ablp != null) { |
| 1046 | horizontalMargin = ablp.leftMargin + ablp.rightMargin; |
| 1047 | verticalMargin = ablp.topMargin + ablp.bottomMargin; |
| 1048 | } |
| 1049 | |
| 1050 | // If the action bar is wrapping to its content height, don't allow a custom |
| 1051 | // view to MATCH_PARENT. |
| 1052 | int customNavHeightMode; |
| 1053 | if (mContentHeight <= 0) { |
| 1054 | customNavHeightMode = MeasureSpec.AT_MOST; |
| 1055 | } else { |
| 1056 | customNavHeightMode = lp.height != LayoutParams.WRAP_CONTENT ? |
| 1057 | MeasureSpec.EXACTLY : MeasureSpec.AT_MOST; |
| 1058 | } |
| 1059 | final int customNavHeight = Math.max(0, |
| 1060 | (lp.height >= 0 ? Math.min(lp.height, height) : height) - verticalMargin); |
| 1061 | |
| 1062 | final int customNavWidthMode = lp.width != LayoutParams.WRAP_CONTENT ? |
| 1063 | MeasureSpec.EXACTLY : MeasureSpec.AT_MOST; |
| 1064 | int customNavWidth = Math.max(0, |
| 1065 | (lp.width >= 0 ? Math.min(lp.width, availableWidth) : availableWidth) |
| 1066 | - horizontalMargin); |
| 1067 | final int hgrav = (ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY) & |
| 1068 | Gravity.HORIZONTAL_GRAVITY_MASK; |
| 1069 | |
| 1070 | // Centering a custom view is treated specially; we try to center within the whole |
| 1071 | // action bar rather than in the available space. |
| 1072 | if (hgrav == Gravity.CENTER_HORIZONTAL && lp.width == LayoutParams.MATCH_PARENT) { |
| 1073 | customNavWidth = Math.min(leftOfCenter, rightOfCenter) * 2; |
| 1074 | } |
| 1075 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1076 | customView.measure( |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1077 | MeasureSpec.makeMeasureSpec(customNavWidth, customNavWidthMode), |
| 1078 | MeasureSpec.makeMeasureSpec(customNavHeight, customNavHeightMode)); |
Adam Powell | aa8e509b | 2011-08-25 09:29:21 -0700 | [diff] [blame] | 1079 | availableWidth -= horizontalMargin + customView.getMeasuredWidth(); |
| 1080 | } |
| 1081 | |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 1082 | /* |
| 1083 | * Measure the whole up container now, allowing for the full home+title sections. |
| 1084 | * (This will re-measure the home view.) |
| 1085 | */ |
| 1086 | availableWidth = measureChildView(mUpGoerFive, availableWidth + homeWidth, |
| 1087 | MeasureSpec.makeMeasureSpec(mContentHeight, MeasureSpec.EXACTLY), 0); |
| 1088 | if (mTitleLayout != null) { |
Adam Powell | aa8e509b | 2011-08-25 09:29:21 -0700 | [diff] [blame] | 1089 | leftOfCenter = Math.max(0, leftOfCenter - mTitleLayout.getMeasuredWidth()); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 1092 | if (mContentHeight <= 0) { |
| 1093 | int measuredHeight = 0; |
Adam Powell | d21aa12 | 2011-05-27 13:09:52 -0700 | [diff] [blame] | 1094 | for (int i = 0; i < childCount; i++) { |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 1095 | View v = getChildAt(i); |
| 1096 | int paddedViewHeight = v.getMeasuredHeight() + verticalPadding; |
| 1097 | if (paddedViewHeight > measuredHeight) { |
| 1098 | measuredHeight = paddedViewHeight; |
| 1099 | } |
| 1100 | } |
| 1101 | setMeasuredDimension(contentWidth, measuredHeight); |
| 1102 | } else { |
| 1103 | setMeasuredDimension(contentWidth, maxHeight); |
| 1104 | } |
| 1105 | |
| 1106 | if (mContextView != null) { |
Adam Powell | 425689e | 2011-09-08 18:09:33 -0700 | [diff] [blame] | 1107 | mContextView.setContentHeight(getMeasuredHeight()); |
Adam Powell | e219444 | 2010-08-12 18:13:03 -0700 | [diff] [blame] | 1108 | } |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 1109 | |
| 1110 | if (mProgressView != null && mProgressView.getVisibility() != GONE) { |
| 1111 | mProgressView.measure(MeasureSpec.makeMeasureSpec( |
| 1112 | contentWidth - mProgressBarPadding * 2, MeasureSpec.EXACTLY), |
| 1113 | MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST)); |
| 1114 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 1117 | @Override |
| 1118 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 1119 | final int contentHeight = b - t - getPaddingTop() - getPaddingBottom(); |
| 1120 | |
Adam Powell | d21aa12 | 2011-05-27 13:09:52 -0700 | [diff] [blame] | 1121 | if (contentHeight <= 0) { |
| 1122 | // Nothing to do if we can't see anything. |
| 1123 | return; |
| 1124 | } |
| 1125 | |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1126 | final boolean isLayoutRtl = isLayoutRtl(); |
| 1127 | final int direction = isLayoutRtl ? +1 : -1; |
| 1128 | int menuStart = isLayoutRtl ? getPaddingLeft() : r - l - getPaddingRight(); |
| 1129 | // In LTR mode, we start from left padding and go to the right; in RTL mode, we start |
| 1130 | // from the padding right and go to the left (in reverse way) |
| 1131 | int x = isLayoutRtl ? r - l - getPaddingRight() : getPaddingLeft(); |
| 1132 | final int y = getPaddingTop(); |
| 1133 | |
Adam Powell | b1e2f25 | 2011-08-22 17:42:12 -0700 | [diff] [blame] | 1134 | HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout; |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 1135 | final int startOffset = homeLayout.getVisibility() != GONE && |
| 1136 | homeLayout.getParent() == mUpGoerFive ? homeLayout.getStartOffset() : 0; |
| 1137 | |
| 1138 | // Position the up container based on where the edge of the home layout should go. |
| 1139 | x += positionChild(mUpGoerFive, |
| 1140 | next(x, startOffset, isLayoutRtl), y, contentHeight, isLayoutRtl); |
| 1141 | x = next(x, startOffset, isLayoutRtl); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1142 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1143 | if (mExpandedActionView == null) { |
| 1144 | final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE && |
Adam Powell | 15a16a8 | 2011-06-20 10:35:27 -0700 | [diff] [blame] | 1145 | (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0; |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1146 | |
| 1147 | switch (mNavigationMode) { |
| 1148 | case ActionBar.NAVIGATION_MODE_STANDARD: |
| 1149 | break; |
| 1150 | case ActionBar.NAVIGATION_MODE_LIST: |
| 1151 | if (mListNavLayout != null) { |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1152 | if (showTitle) { |
| 1153 | x = next(x, mItemPadding, isLayoutRtl); |
| 1154 | } |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1155 | x += positionChild(mListNavLayout, x, y, contentHeight, isLayoutRtl); |
| 1156 | x = next(x, mItemPadding, isLayoutRtl); |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1157 | } |
| 1158 | break; |
| 1159 | case ActionBar.NAVIGATION_MODE_TABS: |
| 1160 | if (mTabScrollView != null) { |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1161 | if (showTitle) x = next(x, mItemPadding, isLayoutRtl); |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1162 | x += positionChild(mTabScrollView, x, y, contentHeight, isLayoutRtl); |
| 1163 | x = next(x, mItemPadding, isLayoutRtl); |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1164 | } |
| 1165 | break; |
Adam Powell | 661c908 | 2010-07-02 10:09:44 -0700 | [diff] [blame] | 1166 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Adam Powell | 9b4bee0 | 2011-04-27 19:24:47 -0700 | [diff] [blame] | 1169 | if (mMenuView != null && mMenuView.getParent() == this) { |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1170 | positionChild(mMenuView, menuStart, y, contentHeight, !isLayoutRtl); |
| 1171 | menuStart += direction * mMenuView.getMeasuredWidth(); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 1174 | if (mIndeterminateProgressView != null && |
| 1175 | mIndeterminateProgressView.getVisibility() != GONE) { |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1176 | positionChild(mIndeterminateProgressView, menuStart, y, contentHeight, !isLayoutRtl); |
| 1177 | menuStart += direction * mIndeterminateProgressView.getMeasuredWidth(); |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 1178 | } |
| 1179 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1180 | View customView = null; |
| 1181 | if (mExpandedActionView != null) { |
| 1182 | customView = mExpandedActionView; |
| 1183 | } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && |
| 1184 | mCustomNavView != null) { |
| 1185 | customView = mCustomNavView; |
| 1186 | } |
| 1187 | if (customView != null) { |
Fabrice Di Meglio | 6bf6eb7 | 2012-10-10 15:30:28 -0700 | [diff] [blame] | 1188 | final int layoutDirection = getLayoutDirection(); |
Fabrice Di Meglio | bb4b601 | 2012-10-26 16:27:55 -0700 | [diff] [blame] | 1189 | ViewGroup.LayoutParams lp = customView.getLayoutParams(); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1190 | final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ? |
| 1191 | (ActionBar.LayoutParams) lp : null; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1192 | final int gravity = ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY; |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1193 | final int navWidth = customView.getMeasuredWidth(); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1194 | |
| 1195 | int topMargin = 0; |
| 1196 | int bottomMargin = 0; |
| 1197 | if (ablp != null) { |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1198 | x = next(x, ablp.getMarginStart(), isLayoutRtl); |
| 1199 | menuStart += direction * ablp.getMarginEnd(); |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1200 | topMargin = ablp.topMargin; |
| 1201 | bottomMargin = ablp.bottomMargin; |
| 1202 | } |
| 1203 | |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1204 | int hgravity = gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1205 | // See if we actually have room to truly center; if not push against left or right. |
| 1206 | if (hgravity == Gravity.CENTER_HORIZONTAL) { |
| 1207 | final int centeredLeft = ((mRight - mLeft) - navWidth) / 2; |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1208 | if (isLayoutRtl) { |
| 1209 | final int centeredStart = centeredLeft + navWidth; |
| 1210 | final int centeredEnd = centeredLeft; |
| 1211 | if (centeredStart > x) { |
| 1212 | hgravity = Gravity.RIGHT; |
| 1213 | } else if (centeredEnd < menuStart) { |
| 1214 | hgravity = Gravity.LEFT; |
| 1215 | } |
| 1216 | } else { |
| 1217 | final int centeredStart = centeredLeft; |
| 1218 | final int centeredEnd = centeredLeft + navWidth; |
| 1219 | if (centeredStart < x) { |
| 1220 | hgravity = Gravity.LEFT; |
| 1221 | } else if (centeredEnd > menuStart) { |
| 1222 | hgravity = Gravity.RIGHT; |
| 1223 | } |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1224 | } |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1225 | } else if (gravity == Gravity.NO_GRAVITY) { |
| 1226 | hgravity = Gravity.START; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | int xpos = 0; |
Fabrice Di Meglio | 6bf6eb7 | 2012-10-10 15:30:28 -0700 | [diff] [blame] | 1230 | switch (Gravity.getAbsoluteGravity(hgravity, layoutDirection)) { |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1231 | case Gravity.CENTER_HORIZONTAL: |
| 1232 | xpos = ((mRight - mLeft) - navWidth) / 2; |
| 1233 | break; |
| 1234 | case Gravity.LEFT: |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1235 | xpos = isLayoutRtl ? menuStart : x; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1236 | break; |
| 1237 | case Gravity.RIGHT: |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1238 | xpos = isLayoutRtl ? x - navWidth : menuStart - navWidth; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1239 | break; |
| 1240 | } |
| 1241 | |
Adam Powell | 7a2424d | 2011-08-18 11:59:11 -0700 | [diff] [blame] | 1242 | int vgravity = gravity & Gravity.VERTICAL_GRAVITY_MASK; |
| 1243 | |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1244 | if (gravity == Gravity.NO_GRAVITY) { |
Adam Powell | 7a2424d | 2011-08-18 11:59:11 -0700 | [diff] [blame] | 1245 | vgravity = Gravity.CENTER_VERTICAL; |
| 1246 | } |
| 1247 | |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1248 | int ypos = 0; |
Adam Powell | 7a2424d | 2011-08-18 11:59:11 -0700 | [diff] [blame] | 1249 | switch (vgravity) { |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1250 | case Gravity.CENTER_VERTICAL: |
Adam Powell | 6556c07 | 2011-06-24 17:16:57 -0700 | [diff] [blame] | 1251 | final int paddedTop = getPaddingTop(); |
| 1252 | final int paddedBottom = mBottom - mTop - getPaddingBottom(); |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1253 | ypos = ((paddedBottom - paddedTop) - customView.getMeasuredHeight()) / 2; |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1254 | break; |
| 1255 | case Gravity.TOP: |
| 1256 | ypos = getPaddingTop() + topMargin; |
| 1257 | break; |
| 1258 | case Gravity.BOTTOM: |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1259 | ypos = getHeight() - getPaddingBottom() - customView.getMeasuredHeight() |
Adam Powell | 9ab9787 | 2010-10-26 21:47:29 -0700 | [diff] [blame] | 1260 | - bottomMargin; |
| 1261 | break; |
| 1262 | } |
Adam Powell | 6556c07 | 2011-06-24 17:16:57 -0700 | [diff] [blame] | 1263 | final int customWidth = customView.getMeasuredWidth(); |
| 1264 | customView.layout(xpos, ypos, xpos + customWidth, |
| 1265 | ypos + customView.getMeasuredHeight()); |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1266 | x = next(x, customWidth, isLayoutRtl); |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 1267 | } |
Adam Powell | 6af97e1 | 2010-11-11 21:11:53 -0800 | [diff] [blame] | 1268 | |
| 1269 | if (mProgressView != null) { |
| 1270 | mProgressView.bringToFront(); |
| 1271 | final int halfProgressHeight = mProgressView.getMeasuredHeight() / 2; |
| 1272 | mProgressView.layout(mProgressBarPadding, -halfProgressHeight, |
| 1273 | mProgressBarPadding + mProgressView.getMeasuredWidth(), halfProgressHeight); |
| 1274 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1277 | @Override |
Adam Powell | 9a5cc28 | 2011-08-28 16:18:16 -0700 | [diff] [blame] | 1278 | public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) { |
Adam Powell | aad47fd | 2011-08-17 17:33:33 -0700 | [diff] [blame] | 1279 | return new ActionBar.LayoutParams(getContext(), attrs); |
| 1280 | } |
| 1281 | |
| 1282 | @Override |
Adam Powell | 9a5cc28 | 2011-08-28 16:18:16 -0700 | [diff] [blame] | 1283 | public ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) { |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1284 | if (lp == null) { |
| 1285 | lp = generateDefaultLayoutParams(); |
| 1286 | } |
| 1287 | return lp; |
| 1288 | } |
| 1289 | |
| 1290 | @Override |
| 1291 | public Parcelable onSaveInstanceState() { |
| 1292 | Parcelable superState = super.onSaveInstanceState(); |
| 1293 | SavedState state = new SavedState(superState); |
| 1294 | |
| 1295 | if (mExpandedMenuPresenter != null && mExpandedMenuPresenter.mCurrentExpandedItem != null) { |
| 1296 | state.expandedMenuItemId = mExpandedMenuPresenter.mCurrentExpandedItem.getItemId(); |
| 1297 | } |
| 1298 | |
| 1299 | state.isOverflowOpen = isOverflowMenuShowing(); |
| 1300 | |
| 1301 | return state; |
| 1302 | } |
| 1303 | |
| 1304 | @Override |
| 1305 | public void onRestoreInstanceState(Parcelable p) { |
| 1306 | SavedState state = (SavedState) p; |
| 1307 | |
| 1308 | super.onRestoreInstanceState(state.getSuperState()); |
| 1309 | |
| 1310 | if (state.expandedMenuItemId != 0 && |
| 1311 | mExpandedMenuPresenter != null && mOptionsMenu != null) { |
| 1312 | final MenuItem item = mOptionsMenu.findItem(state.expandedMenuItemId); |
| 1313 | if (item != null) { |
| 1314 | item.expandActionView(); |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | if (state.isOverflowOpen) { |
| 1319 | postShowOverflowMenu(); |
| 1320 | } |
| 1321 | } |
| 1322 | |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 1323 | public void setHomeAsUpIndicator(Drawable indicator) { |
| 1324 | mHomeLayout.setUpIndicator(indicator); |
| 1325 | } |
| 1326 | |
| 1327 | public void setHomeAsUpIndicator(int resId) { |
| 1328 | mHomeLayout.setUpIndicator(resId); |
| 1329 | } |
| 1330 | |
| 1331 | public void setHomeActionContentDescription(CharSequence description) { |
| 1332 | mHomeDescription = description; |
| 1333 | } |
| 1334 | |
| 1335 | public void setHomeActionContentDescription(int resId) { |
| 1336 | mHomeDescriptionRes = resId; |
Adam Powell | 2eeb419 | 2013-04-18 13:53:27 -0700 | [diff] [blame] | 1337 | mHomeDescription = resId != 0 ? getResources().getText(resId) : null; |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1340 | static class SavedState extends BaseSavedState { |
| 1341 | int expandedMenuItemId; |
| 1342 | boolean isOverflowOpen; |
| 1343 | |
| 1344 | SavedState(Parcelable superState) { |
| 1345 | super(superState); |
| 1346 | } |
| 1347 | |
| 1348 | private SavedState(Parcel in) { |
| 1349 | super(in); |
| 1350 | expandedMenuItemId = in.readInt(); |
| 1351 | isOverflowOpen = in.readInt() != 0; |
| 1352 | } |
| 1353 | |
| 1354 | @Override |
| 1355 | public void writeToParcel(Parcel out, int flags) { |
| 1356 | super.writeToParcel(out, flags); |
| 1357 | out.writeInt(expandedMenuItemId); |
| 1358 | out.writeInt(isOverflowOpen ? 1 : 0); |
| 1359 | } |
| 1360 | |
| 1361 | public static final Parcelable.Creator<SavedState> CREATOR = |
| 1362 | new Parcelable.Creator<SavedState>() { |
| 1363 | public SavedState createFromParcel(Parcel in) { |
| 1364 | return new SavedState(in); |
| 1365 | } |
| 1366 | |
| 1367 | public SavedState[] newArray(int size) { |
| 1368 | return new SavedState[size]; |
| 1369 | } |
| 1370 | }; |
| 1371 | } |
| 1372 | |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1373 | private static class HomeView extends FrameLayout { |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 1374 | private ImageView mUpView; |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1375 | private ImageView mIconView; |
Adam Powell | b1e2f25 | 2011-08-22 17:42:12 -0700 | [diff] [blame] | 1376 | private int mUpWidth; |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 1377 | private int mUpIndicatorRes; |
| 1378 | private Drawable mDefaultUpIndicator; |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1379 | |
Adam Powell | fd75eef | 2012-08-02 10:27:31 -0700 | [diff] [blame] | 1380 | private static final long DEFAULT_TRANSITION_DURATION = 150; |
| 1381 | |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1382 | public HomeView(Context context) { |
| 1383 | this(context, null); |
| 1384 | } |
| 1385 | |
| 1386 | public HomeView(Context context, AttributeSet attrs) { |
| 1387 | super(context, attrs); |
Adam Powell | fd75eef | 2012-08-02 10:27:31 -0700 | [diff] [blame] | 1388 | LayoutTransition t = getLayoutTransition(); |
| 1389 | if (t != null) { |
| 1390 | // Set a lower duration than the default |
| 1391 | t.setDuration(DEFAULT_TRANSITION_DURATION); |
| 1392 | } |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1393 | } |
| 1394 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1395 | public void setUp(boolean isUp) { |
| 1396 | mUpView.setVisibility(isUp ? VISIBLE : GONE); |
| 1397 | } |
| 1398 | |
| 1399 | public void setIcon(Drawable icon) { |
| 1400 | mIconView.setImageDrawable(icon); |
| 1401 | } |
| 1402 | |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 1403 | public void setUpIndicator(Drawable d) { |
| 1404 | mUpView.setImageDrawable(d != null ? d : mDefaultUpIndicator); |
| 1405 | mUpIndicatorRes = 0; |
| 1406 | } |
| 1407 | |
| 1408 | public void setUpIndicator(int resId) { |
| 1409 | mUpIndicatorRes = resId; |
| 1410 | mUpView.setImageDrawable(resId != 0 ? getResources().getDrawable(resId) : null); |
| 1411 | } |
| 1412 | |
| 1413 | @Override |
| 1414 | protected void onConfigurationChanged(Configuration newConfig) { |
| 1415 | super.onConfigurationChanged(newConfig); |
| 1416 | if (mUpIndicatorRes != 0) { |
| 1417 | // Reload for config change |
| 1418 | setUpIndicator(mUpIndicatorRes); |
| 1419 | } |
| 1420 | } |
| 1421 | |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1422 | @Override |
Adam Powell | 7bc3ca0 | 2011-08-26 18:29:58 -0700 | [diff] [blame] | 1423 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 1424 | onPopulateAccessibilityEvent(event); |
| 1425 | return true; |
| 1426 | } |
| 1427 | |
| 1428 | @Override |
| 1429 | public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 1430 | super.onPopulateAccessibilityEvent(event); |
| 1431 | final CharSequence cdesc = getContentDescription(); |
| 1432 | if (!TextUtils.isEmpty(cdesc)) { |
| 1433 | event.getText().add(cdesc); |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | @Override |
| 1438 | public boolean dispatchHoverEvent(MotionEvent event) { |
| 1439 | // Don't allow children to hover; we want this to be treated as a single component. |
| 1440 | return onHoverEvent(event); |
| 1441 | } |
| 1442 | |
| 1443 | @Override |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1444 | protected void onFinishInflate() { |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 1445 | mUpView = (ImageView) findViewById(com.android.internal.R.id.up); |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1446 | mIconView = (ImageView) findViewById(com.android.internal.R.id.home); |
Adam Powell | e0e2f4f | 2013-04-05 16:27:35 -0700 | [diff] [blame] | 1447 | mDefaultUpIndicator = mUpView.getDrawable(); |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1448 | } |
| 1449 | |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1450 | public int getStartOffset() { |
Adam Powell | b1e2f25 | 2011-08-22 17:42:12 -0700 | [diff] [blame] | 1451 | return mUpView.getVisibility() == GONE ? mUpWidth : 0; |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1454 | @Override |
| 1455 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 1456 | measureChildWithMargins(mUpView, widthMeasureSpec, 0, heightMeasureSpec, 0); |
| 1457 | final LayoutParams upLp = (LayoutParams) mUpView.getLayoutParams(); |
Adam Powell | b1e2f25 | 2011-08-22 17:42:12 -0700 | [diff] [blame] | 1458 | mUpWidth = upLp.leftMargin + mUpView.getMeasuredWidth() + upLp.rightMargin; |
| 1459 | int width = mUpView.getVisibility() == GONE ? 0 : mUpWidth; |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1460 | int height = upLp.topMargin + mUpView.getMeasuredHeight() + upLp.bottomMargin; |
| 1461 | measureChildWithMargins(mIconView, widthMeasureSpec, width, heightMeasureSpec, 0); |
| 1462 | final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams(); |
| 1463 | width += iconLp.leftMargin + mIconView.getMeasuredWidth() + iconLp.rightMargin; |
| 1464 | height = Math.max(height, |
| 1465 | iconLp.topMargin + mIconView.getMeasuredHeight() + iconLp.bottomMargin); |
Adam Powell | 0d5d1b7e | 2011-06-22 17:40:40 -0700 | [diff] [blame] | 1466 | |
| 1467 | final int widthMode = MeasureSpec.getMode(widthMeasureSpec); |
| 1468 | final int heightMode = MeasureSpec.getMode(heightMeasureSpec); |
| 1469 | final int widthSize = MeasureSpec.getSize(widthMeasureSpec); |
| 1470 | final int heightSize = MeasureSpec.getSize(heightMeasureSpec); |
| 1471 | |
| 1472 | switch (widthMode) { |
| 1473 | case MeasureSpec.AT_MOST: |
| 1474 | width = Math.min(width, widthSize); |
| 1475 | break; |
| 1476 | case MeasureSpec.EXACTLY: |
| 1477 | width = widthSize; |
| 1478 | break; |
| 1479 | case MeasureSpec.UNSPECIFIED: |
| 1480 | default: |
| 1481 | break; |
| 1482 | } |
| 1483 | switch (heightMode) { |
| 1484 | case MeasureSpec.AT_MOST: |
| 1485 | height = Math.min(height, heightSize); |
| 1486 | break; |
| 1487 | case MeasureSpec.EXACTLY: |
| 1488 | height = heightSize; |
| 1489 | break; |
| 1490 | case MeasureSpec.UNSPECIFIED: |
| 1491 | default: |
| 1492 | break; |
| 1493 | } |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1494 | setMeasuredDimension(width, height); |
| 1495 | } |
| 1496 | |
| 1497 | @Override |
| 1498 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 1499 | final int vCenter = (b - t) / 2; |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1500 | final boolean isLayoutRtl = isLayoutRtl(); |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1501 | final int width = getWidth(); |
Adam Powell | c8b0b00 | 2011-06-23 14:39:05 -0700 | [diff] [blame] | 1502 | int upOffset = 0; |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1503 | if (mUpView.getVisibility() != GONE) { |
| 1504 | final LayoutParams upLp = (LayoutParams) mUpView.getLayoutParams(); |
| 1505 | final int upHeight = mUpView.getMeasuredHeight(); |
| 1506 | final int upWidth = mUpView.getMeasuredWidth(); |
Adam Powell | c8b0b00 | 2011-06-23 14:39:05 -0700 | [diff] [blame] | 1507 | upOffset = upLp.leftMargin + upWidth + upLp.rightMargin; |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1508 | final int upTop = vCenter - upHeight / 2; |
| 1509 | final int upBottom = upTop + upHeight; |
| 1510 | final int upRight; |
| 1511 | final int upLeft; |
| 1512 | if (isLayoutRtl) { |
| 1513 | upRight = width; |
| 1514 | upLeft = upRight - upWidth; |
| 1515 | r -= upOffset; |
| 1516 | } else { |
| 1517 | upRight = upWidth; |
| 1518 | upLeft = 0; |
| 1519 | l += upOffset; |
| 1520 | } |
| 1521 | mUpView.layout(upLeft, upTop, upRight, upBottom); |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1522 | } |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1523 | |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1524 | final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams(); |
| 1525 | final int iconHeight = mIconView.getMeasuredHeight(); |
| 1526 | final int iconWidth = mIconView.getMeasuredWidth(); |
| 1527 | final int hCenter = (r - l) / 2; |
Adam Powell | c8b0b00 | 2011-06-23 14:39:05 -0700 | [diff] [blame] | 1528 | final int iconTop = Math.max(iconLp.topMargin, vCenter - iconHeight / 2); |
Fabrice Di Meglio | cf1ba02 | 2012-06-25 15:49:11 -0700 | [diff] [blame] | 1529 | final int iconBottom = iconTop + iconHeight; |
| 1530 | final int iconLeft; |
| 1531 | final int iconRight; |
| 1532 | int marginStart = iconLp.getMarginStart(); |
| 1533 | final int delta = Math.max(marginStart, hCenter - iconWidth / 2); |
| 1534 | if (isLayoutRtl) { |
| 1535 | iconRight = width - upOffset - delta; |
| 1536 | iconLeft = iconRight - iconWidth; |
| 1537 | } else { |
| 1538 | iconLeft = upOffset + delta; |
| 1539 | iconRight = iconLeft + iconWidth; |
| 1540 | } |
| 1541 | mIconView.layout(iconLeft, iconTop, iconRight, iconBottom); |
Adam Powell | 2b0952b | 2011-03-09 00:15:38 -0800 | [diff] [blame] | 1542 | } |
| 1543 | } |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1544 | |
| 1545 | private class ExpandedActionViewMenuPresenter implements MenuPresenter { |
| 1546 | MenuBuilder mMenu; |
| 1547 | MenuItemImpl mCurrentExpandedItem; |
| 1548 | |
| 1549 | @Override |
| 1550 | public void initForMenu(Context context, MenuBuilder menu) { |
| 1551 | // Clear the expanded action view when menus change. |
Adam Powell | 6b0e97c | 2011-08-03 12:06:32 -0700 | [diff] [blame] | 1552 | if (mMenu != null && mCurrentExpandedItem != null) { |
| 1553 | mMenu.collapseItemActionView(mCurrentExpandedItem); |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1554 | } |
| 1555 | mMenu = menu; |
| 1556 | } |
| 1557 | |
| 1558 | @Override |
| 1559 | public MenuView getMenuView(ViewGroup root) { |
| 1560 | return null; |
| 1561 | } |
| 1562 | |
| 1563 | @Override |
| 1564 | public void updateMenuView(boolean cleared) { |
| 1565 | // Make sure the expanded item we have is still there. |
| 1566 | if (mCurrentExpandedItem != null) { |
| 1567 | boolean found = false; |
Adam Powell | f35d049 | 2011-08-17 13:56:47 -0700 | [diff] [blame] | 1568 | |
| 1569 | if (mMenu != null) { |
| 1570 | final int count = mMenu.size(); |
| 1571 | for (int i = 0; i < count; i++) { |
| 1572 | final MenuItem item = mMenu.getItem(i); |
| 1573 | if (item == mCurrentExpandedItem) { |
| 1574 | found = true; |
| 1575 | break; |
| 1576 | } |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | if (!found) { |
| 1581 | // The item we had expanded disappeared. Collapse. |
| 1582 | collapseItemActionView(mMenu, mCurrentExpandedItem); |
| 1583 | } |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | @Override |
| 1588 | public void setCallback(Callback cb) { |
| 1589 | } |
| 1590 | |
| 1591 | @Override |
| 1592 | public boolean onSubMenuSelected(SubMenuBuilder subMenu) { |
| 1593 | return false; |
| 1594 | } |
| 1595 | |
| 1596 | @Override |
| 1597 | public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { |
| 1598 | } |
| 1599 | |
| 1600 | @Override |
| 1601 | public boolean flagActionItems() { |
| 1602 | return false; |
| 1603 | } |
| 1604 | |
| 1605 | @Override |
| 1606 | public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item) { |
| 1607 | mExpandedActionView = item.getActionView(); |
Adam Powell | 28fa07e | 2011-07-15 20:17:25 -0700 | [diff] [blame] | 1608 | mExpandedHomeLayout.setIcon(mIcon.getConstantState().newDrawable(getResources())); |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1609 | mCurrentExpandedItem = item; |
| 1610 | if (mExpandedActionView.getParent() != ActionBarView.this) { |
| 1611 | addView(mExpandedActionView); |
| 1612 | } |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 1613 | if (mExpandedHomeLayout.getParent() != mUpGoerFive) { |
| 1614 | mUpGoerFive.addView(mExpandedHomeLayout); |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1615 | } |
| 1616 | mHomeLayout.setVisibility(GONE); |
Adam Powell | 15a16a8 | 2011-06-20 10:35:27 -0700 | [diff] [blame] | 1617 | if (mTitleLayout != null) mTitleLayout.setVisibility(GONE); |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1618 | if (mTabScrollView != null) mTabScrollView.setVisibility(GONE); |
| 1619 | if (mSpinner != null) mSpinner.setVisibility(GONE); |
| 1620 | if (mCustomNavView != null) mCustomNavView.setVisibility(GONE); |
Adam Powell | 07cf971 | 2013-02-05 16:13:57 -0800 | [diff] [blame] | 1621 | setHomeButtonEnabled(false, false); |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1622 | requestLayout(); |
| 1623 | item.setActionViewExpanded(true); |
Adam Powell | 038f1c8 | 2011-07-21 14:28:10 -0700 | [diff] [blame] | 1624 | |
| 1625 | if (mExpandedActionView instanceof CollapsibleActionView) { |
| 1626 | ((CollapsibleActionView) mExpandedActionView).onActionViewExpanded(); |
| 1627 | } |
Amith Yamasani | 10da590 | 2011-07-26 16:14:26 -0700 | [diff] [blame] | 1628 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1629 | return true; |
| 1630 | } |
| 1631 | |
| 1632 | @Override |
| 1633 | public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item) { |
Amith Yamasani | 10da590 | 2011-07-26 16:14:26 -0700 | [diff] [blame] | 1634 | // Do this before detaching the actionview from the hierarchy, in case |
| 1635 | // it needs to dismiss the soft keyboard, etc. |
| 1636 | if (mExpandedActionView instanceof CollapsibleActionView) { |
| 1637 | ((CollapsibleActionView) mExpandedActionView).onActionViewCollapsed(); |
| 1638 | } |
| 1639 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1640 | removeView(mExpandedActionView); |
Adam Powell | 27cba38 | 2013-01-22 18:55:20 -0800 | [diff] [blame] | 1641 | mUpGoerFive.removeView(mExpandedHomeLayout); |
Adam Powell | b0e217e | 2011-08-12 11:36:51 -0700 | [diff] [blame] | 1642 | mExpandedActionView = null; |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1643 | if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_HOME) != 0) { |
| 1644 | mHomeLayout.setVisibility(VISIBLE); |
| 1645 | } |
| 1646 | if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0) { |
Adam Powell | 15a16a8 | 2011-06-20 10:35:27 -0700 | [diff] [blame] | 1647 | if (mTitleLayout == null) { |
| 1648 | initTitle(); |
| 1649 | } else { |
| 1650 | mTitleLayout.setVisibility(VISIBLE); |
| 1651 | } |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1652 | } |
Adam Powell | 6684e92 | 2013-03-26 15:38:26 -0700 | [diff] [blame] | 1653 | if (mTabScrollView != null) mTabScrollView.setVisibility(VISIBLE); |
| 1654 | if (mSpinner != null) mSpinner.setVisibility(VISIBLE); |
| 1655 | if (mCustomNavView != null) mCustomNavView.setVisibility(VISIBLE); |
| 1656 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1657 | mExpandedHomeLayout.setIcon(null); |
| 1658 | mCurrentExpandedItem = null; |
Adam Powell | 62f3303 | 2013-02-04 12:44:34 -0800 | [diff] [blame] | 1659 | setHomeButtonEnabled(mWasHomeEnabled); // Set by expandItemActionView above |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1660 | requestLayout(); |
| 1661 | item.setActionViewExpanded(false); |
Adam Powell | 038f1c8 | 2011-07-21 14:28:10 -0700 | [diff] [blame] | 1662 | |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1663 | return true; |
| 1664 | } |
Adam Powell | 11ed1d6 | 2011-07-11 21:19:59 -0700 | [diff] [blame] | 1665 | |
| 1666 | @Override |
| 1667 | public int getId() { |
| 1668 | return 0; |
| 1669 | } |
| 1670 | |
| 1671 | @Override |
| 1672 | public Parcelable onSaveInstanceState() { |
| 1673 | return null; |
| 1674 | } |
| 1675 | |
| 1676 | @Override |
| 1677 | public void onRestoreInstanceState(Parcelable state) { |
| 1678 | } |
Adam Powell | 8d02dea | 2011-05-31 21:35:13 -0700 | [diff] [blame] | 1679 | } |
Adam Powell | 33b9743 | 2010-04-20 10:01:14 -0700 | [diff] [blame] | 1680 | } |