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