blob: 5142c50c8ad1d16e5e4c84a40bdddfbd05cdb960 [file] [log] [blame]
Adam Powell33b97432010-04-20 10:01:14 -07001/*
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
17package android.view;
18
Adam Powell96675b12010-06-10 18:58:59 -070019import com.android.internal.R;
20import com.android.internal.view.menu.ActionMenu;
21import com.android.internal.view.menu.ActionMenuItem;
Adam Powell7ade1be2010-06-17 12:51:21 -070022import com.android.internal.view.menu.ActionMenuView;
Adam Powell96675b12010-06-10 18:58:59 -070023import com.android.internal.view.menu.MenuBuilder;
Adam Powell33b97432010-04-20 10:01:14 -070024
25import android.app.ActionBar;
26import android.app.Activity;
27import android.app.ActionBar.Callback;
28import android.content.Context;
29import android.content.pm.ApplicationInfo;
30import android.content.pm.PackageManager;
31import android.content.res.TypedArray;
32import android.graphics.PorterDuff;
33import android.graphics.PorterDuffColorFilter;
34import android.graphics.drawable.Drawable;
35import android.util.AttributeSet;
36import android.util.DisplayMetrics;
37import android.util.SparseArray;
Adam Powella4082912010-06-04 18:34:02 -070038import android.widget.AdapterView;
Adam Powell33b97432010-04-20 10:01:14 -070039import android.widget.ImageView;
Adam Powella4082912010-06-04 18:34:02 -070040import android.widget.Spinner;
41import android.widget.SpinnerAdapter;
Adam Powell33b97432010-04-20 10:01:14 -070042import android.widget.TextView;
43
Adam Powell33b97432010-04-20 10:01:14 -070044/**
45 * @hide
46 */
47public class ActionBarView extends ViewGroup {
48 private static final String TAG = "ActionBarView";
49
50 // TODO: This must be defined in the default theme
51 private static final int CONTENT_HEIGHT_DIP = 50;
52 private static final int CONTENT_PADDING_DIP = 3;
53 private static final int CONTENT_SPACING_DIP = 6;
54 private static final int CONTENT_ACTION_SPACING_DIP = 12;
55
56 /**
57 * Display options applied by default
58 */
59 public static final int DISPLAY_DEFAULT = 0;
60
61 /**
62 * Display options that require re-layout as opposed to a simple invalidate
63 */
Adam Powella1700782010-05-13 13:27:35 -070064 private static final int DISPLAY_RELAYOUT_MASK =
65 ActionBar.DISPLAY_HIDE_HOME |
66 ActionBar.DISPLAY_USE_LOGO;
Adam Powell33b97432010-04-20 10:01:14 -070067
68 private final int mContentHeight;
69
70 private int mNavigationMode;
71 private int mDisplayOptions;
72 private int mSpacing;
73 private int mActionSpacing;
74 private CharSequence mTitle;
75 private CharSequence mSubtitle;
76 private Drawable mIcon;
77 private Drawable mLogo;
Adam Powell33b97432010-04-20 10:01:14 -070078
79 private ImageView mIconView;
80 private ImageView mLogoView;
81 private TextView mTitleView;
82 private TextView mSubtitleView;
Adam Powella4082912010-06-04 18:34:02 -070083 private Spinner mSpinner;
84 private View mCustomNavView;
Adam Powell33b97432010-04-20 10:01:14 -070085
86 private boolean mShowMenu;
87
Adam Powell96675b12010-06-10 18:58:59 -070088 private MenuBuilder mOptionsMenu;
Adam Powell7ade1be2010-06-17 12:51:21 -070089 private ActionMenuView mMenuView;
Adam Powell96675b12010-06-10 18:58:59 -070090
Adam Powell33b97432010-04-20 10:01:14 -070091 private ActionMenuItem mLogoNavItem;
Adam Powell33b97432010-04-20 10:01:14 -070092
93 private SparseArray<ActionMenu> mContextMenus;
94
95 private Callback mCallback;
Adam Powell33b97432010-04-20 10:01:14 -070096
Adam Powella4082912010-06-04 18:34:02 -070097 private final AdapterView.OnItemSelectedListener mNavItemSelectedListener =
98 new AdapterView.OnItemSelectedListener() {
99 public void onItemSelected(AdapterView parent, View view, int position, long id) {
100 if (mCallback != null) {
101 mCallback.onNavigationItemSelected(position, id);
102 }
103 }
104 public void onNothingSelected(AdapterView parent) {
105 // Do nothing
106 }
107 };
108
Adam Powell33b97432010-04-20 10:01:14 -0700109 private OnClickListener mHomeClickListener = null;
110
111 public ActionBarView(Context context, AttributeSet attrs) {
112 super(context, attrs);
113
114 final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
115 mContentHeight = (int) (CONTENT_HEIGHT_DIP * metrics.density + 0.5f);
116
117 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar);
118
119 final int colorFilter = a.getColor(R.styleable.ActionBar_colorFilter, 0);
120
121 if (colorFilter != 0) {
122 final Drawable d = getBackground();
123 d.setDither(true);
124 d.setColorFilter(new PorterDuffColorFilter(colorFilter, PorterDuff.Mode.OVERLAY));
125 }
126
127 ApplicationInfo info = context.getApplicationInfo();
128 PackageManager pm = context.getPackageManager();
Adam Powella4082912010-06-04 18:34:02 -0700129 mNavigationMode = a.getInt(R.styleable.ActionBar_navigationMode, ActionBar.NAVIGATION_MODE_STANDARD);
Adam Powell33b97432010-04-20 10:01:14 -0700130 mTitle = a.getText(R.styleable.ActionBar_title);
131 mSubtitle = a.getText(R.styleable.ActionBar_subtitle);
132 mDisplayOptions = a.getInt(R.styleable.ActionBar_displayOptions, DISPLAY_DEFAULT);
133
134 mLogo = a.getDrawable(R.styleable.ActionBar_logo);
135 if (mLogo == null) {
136 mLogo = info.loadLogo(pm);
137 }
138 mIcon = a.getDrawable(R.styleable.ActionBar_icon);
139 if (mIcon == null) {
140 mIcon = info.loadIcon(pm);
141 }
Adam Powell33b97432010-04-20 10:01:14 -0700142
143 Drawable background = a.getDrawable(R.styleable.ActionBar_background);
144 if (background != null) {
145 setBackgroundDrawable(background);
146 }
147
148 final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
149 if (customNavId != 0) {
150 LayoutInflater inflater = LayoutInflater.from(context);
Adam Powella4082912010-06-04 18:34:02 -0700151 mCustomNavView = (View) inflater.inflate(customNavId, null);
Adam Powell33b97432010-04-20 10:01:14 -0700152 mNavigationMode = ActionBar.NAVIGATION_MODE_CUSTOM;
153 }
154
155 a.recycle();
156
157 // TODO: Set this in the theme
158 int padding = (int) (CONTENT_PADDING_DIP * metrics.density + 0.5f);
159 setPadding(padding, padding, padding, padding);
160
161 mSpacing = (int) (CONTENT_SPACING_DIP * metrics.density + 0.5f);
162 mActionSpacing = (int) (CONTENT_ACTION_SPACING_DIP * metrics.density + 0.5f);
163
164 if (mLogo != null || mIcon != null || mTitle != null) {
165 mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
166 mHomeClickListener = new OnClickListener() {
167 public void onClick(View v) {
Adam Powell96675b12010-06-10 18:58:59 -0700168 Context context = getContext();
169 if (context instanceof Activity) {
170 Activity activity = (Activity) context;
171 activity.onOptionsItemSelected(mLogoNavItem);
Adam Powell33b97432010-04-20 10:01:14 -0700172 }
173 }
174 };
175 }
176
177 mContextMenus = new SparseArray<ActionMenu>();
178 }
179
Adam Powell96675b12010-06-10 18:58:59 -0700180 public void setCallback(Callback callback) {
181 mCallback = callback;
Adam Powell33b97432010-04-20 10:01:14 -0700182 }
183
Adam Powell96675b12010-06-10 18:58:59 -0700184 public void setMenu(Menu menu) {
185 MenuBuilder builder = (MenuBuilder) menu;
186 mOptionsMenu = builder;
187 if (mMenuView != null) {
188 removeView(mMenuView);
Adam Powell33b97432010-04-20 10:01:14 -0700189 }
Adam Powell7ade1be2010-06-17 12:51:21 -0700190 final ActionMenuView menuView = (ActionMenuView) builder.getMenuView(
191 MenuBuilder.TYPE_ACTION_BUTTON, null);
192 mActionSpacing = menuView.getItemMargin();
Adam Powell96675b12010-06-10 18:58:59 -0700193 final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
194 LayoutParams.MATCH_PARENT);
195 menuView.setLayoutParams(layoutParams);
196 addView(menuView);
197 mMenuView = menuView;
Adam Powell33b97432010-04-20 10:01:14 -0700198 }
199
200 public void setCustomNavigationView(View view) {
Adam Powella4082912010-06-04 18:34:02 -0700201 mCustomNavView = view;
Adam Powell33b97432010-04-20 10:01:14 -0700202 if (view != null) {
203 setNavigationMode(ActionBar.NAVIGATION_MODE_CUSTOM);
204 }
Adam Powell33b97432010-04-20 10:01:14 -0700205 }
206
Adam Powell33b97432010-04-20 10:01:14 -0700207 public CharSequence getTitle() {
208 return mTitle;
209 }
210
211 public void setTitle(CharSequence title) {
212 mTitle = title;
213 if (mTitleView != null) {
214 mTitleView.setText(title);
215 }
216 if (mLogoNavItem != null) {
217 mLogoNavItem.setTitle(title);
218 }
219 }
220
221 public CharSequence getSubtitle() {
222 return mSubtitle;
223 }
224
225 public void setSubtitle(CharSequence subtitle) {
226 mSubtitle = subtitle;
227 if (mSubtitleView != null) {
228 mSubtitleView.setText(subtitle);
229 }
230 }
231
232 public void setDisplayOptions(int options) {
Adam Powella1700782010-05-13 13:27:35 -0700233 final int flagsChanged = options ^ mDisplayOptions;
Adam Powell33b97432010-04-20 10:01:14 -0700234 mDisplayOptions = options;
235 if ((flagsChanged & DISPLAY_RELAYOUT_MASK) != 0) {
Adam Powella1700782010-05-13 13:27:35 -0700236 final int vis = (options & ActionBar.DISPLAY_HIDE_HOME) != 0 ? GONE : VISIBLE;
237 if (mLogoView != null) {
238 mLogoView.setVisibility(vis);
239 }
240 if (mIconView != null) {
241 mIconView.setVisibility(vis);
242 }
243
Adam Powell33b97432010-04-20 10:01:14 -0700244 requestLayout();
245 } else {
246 invalidate();
247 }
248 }
249
250 public void setNavigationMode(int mode) {
Adam Powella1700782010-05-13 13:27:35 -0700251 final int oldMode = mNavigationMode;
252 if (mode != oldMode) {
253 switch (oldMode) {
Adam Powella4082912010-06-04 18:34:02 -0700254 case ActionBar.NAVIGATION_MODE_STANDARD:
Adam Powella1700782010-05-13 13:27:35 -0700255 if (mTitleView != null) {
256 removeView(mTitleView);
257 mTitleView = null;
258 }
259 break;
Adam Powella4082912010-06-04 18:34:02 -0700260 case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
261 if (mSpinner != null) {
262 removeView(mSpinner);
263 mSpinner = null;
Adam Powella1700782010-05-13 13:27:35 -0700264 }
Adam Powella4082912010-06-04 18:34:02 -0700265 break;
266 case ActionBar.NAVIGATION_MODE_CUSTOM:
267 if (mCustomNavView != null) {
268 removeView(mCustomNavView);
269 mCustomNavView = null;
270 }
271 break;
Adam Powella1700782010-05-13 13:27:35 -0700272 }
273
274 switch (mode) {
Adam Powella4082912010-06-04 18:34:02 -0700275 case ActionBar.NAVIGATION_MODE_STANDARD:
Adam Powella1700782010-05-13 13:27:35 -0700276 initTitle();
277 break;
Adam Powella4082912010-06-04 18:34:02 -0700278 case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
279 mSpinner = new Spinner(mContext, null,
280 com.android.internal.R.attr.dropDownSpinnerStyle);
281 mSpinner.setOnItemSelectedListener(mNavItemSelectedListener);
Adam Powell96675b12010-06-10 18:58:59 -0700282 mSpinner.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
283 LayoutParams.WRAP_CONTENT));
Adam Powella4082912010-06-04 18:34:02 -0700284 addView(mSpinner);
285 break;
Adam Powella1700782010-05-13 13:27:35 -0700286 case ActionBar.NAVIGATION_MODE_CUSTOM:
Adam Powell96675b12010-06-10 18:58:59 -0700287 mCustomNavView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
288 LayoutParams.WRAP_CONTENT));
Adam Powella4082912010-06-04 18:34:02 -0700289 addView(mCustomNavView);
Adam Powella1700782010-05-13 13:27:35 -0700290 break;
291 }
Adam Powell33b97432010-04-20 10:01:14 -0700292 mNavigationMode = mode;
293 requestLayout();
294 }
295 }
296
Adam Powella4082912010-06-04 18:34:02 -0700297 public void setDropdownAdapter(SpinnerAdapter adapter) {
298 mSpinner.setAdapter(adapter);
299 }
300
Adam Powell33b97432010-04-20 10:01:14 -0700301 public View getCustomNavigationView() {
Adam Powella4082912010-06-04 18:34:02 -0700302 return mCustomNavView;
Adam Powell33b97432010-04-20 10:01:14 -0700303 }
304
305 public int getNavigationMode() {
306 return mNavigationMode;
307 }
308
309 public int getDisplayOptions() {
310 return mDisplayOptions;
311 }
312
Adam Powell33b97432010-04-20 10:01:14 -0700313 public void setContextMode(int mode) {
314 Callback callback = mCallback;
315 if (callback == null) {
316 throw new IllegalStateException(
317 "Attempted to set ActionBar context mode with no callback");
318 }
319
320 ActionMenu menu = mContextMenus.get(mode);
321 if (menu == null) {
322 // Initialize the new mode
323 menu = new ActionMenu(getContext());
324
325 if (!callback.onCreateContextMode(mode, menu)) {
326 throw new IllegalArgumentException(
327 "ActionBar callback does not know how to create context mode " + mode);
328 }
329 mContextMenus.put(mode, menu);
330 }
331
332 if (callback.onPrepareContextMode(mode, menu)) {
333 // TODO Set mode, animate, etc.
334 }
335 }
336
337 public void exitContextMode() {
338 // TODO Turn off context mode; go back to normal.
339 }
340
Adam Powell33b97432010-04-20 10:01:14 -0700341 @Override
342 protected void onFinishInflate() {
343 super.onFinishInflate();
344
345 if ((mDisplayOptions & ActionBar.DISPLAY_HIDE_HOME) == 0) {
346 if (mLogo != null && (mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) != 0) {
347 mLogoView = new ImageView(getContext());
348 mLogoView.setAdjustViewBounds(true);
349 mLogoView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
Adam Powell96675b12010-06-10 18:58:59 -0700350 LayoutParams.MATCH_PARENT));
Adam Powell33b97432010-04-20 10:01:14 -0700351 mLogoView.setImageDrawable(mLogo);
352 mLogoView.setClickable(true);
Adam Powella1700782010-05-13 13:27:35 -0700353 mLogoView.setFocusable(true);
Adam Powell33b97432010-04-20 10:01:14 -0700354 mLogoView.setOnClickListener(mHomeClickListener);
355 addView(mLogoView);
356 } else if (mIcon != null) {
357 mIconView = new ImageView(getContext());
358 mIconView.setAdjustViewBounds(true);
359 mIconView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
Adam Powell96675b12010-06-10 18:58:59 -0700360 LayoutParams.MATCH_PARENT));
Adam Powell33b97432010-04-20 10:01:14 -0700361 mIconView.setImageDrawable(mIcon);
362 mIconView.setClickable(true);
Adam Powella1700782010-05-13 13:27:35 -0700363 mIconView.setFocusable(true);
Adam Powell33b97432010-04-20 10:01:14 -0700364 mIconView.setOnClickListener(mHomeClickListener);
365 addView(mIconView);
366 }
367 }
368
369 switch (mNavigationMode) {
Adam Powella4082912010-06-04 18:34:02 -0700370 case ActionBar.NAVIGATION_MODE_STANDARD:
Adam Powell33b97432010-04-20 10:01:14 -0700371 if (mLogoView == null) {
Adam Powella1700782010-05-13 13:27:35 -0700372 initTitle();
Adam Powell33b97432010-04-20 10:01:14 -0700373 }
374 break;
375
376 case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
377 throw new UnsupportedOperationException(
Adam Powella4082912010-06-04 18:34:02 -0700378 "Inflating dropdown list navigation isn't supported yet!");
Adam Powell33b97432010-04-20 10:01:14 -0700379
380 case ActionBar.NAVIGATION_MODE_TABS:
381 throw new UnsupportedOperationException(
382 "Tab navigation isn't supported yet!");
383
384 case ActionBar.NAVIGATION_MODE_CUSTOM:
Adam Powella4082912010-06-04 18:34:02 -0700385 if (mCustomNavView != null) {
386 addView(mCustomNavView);
Adam Powell33b97432010-04-20 10:01:14 -0700387 }
388 break;
389 }
390 }
Adam Powella1700782010-05-13 13:27:35 -0700391
392 private void initTitle() {
393 LayoutInflater inflater = LayoutInflater.from(getContext());
394 mTitleView = (TextView) inflater.inflate(R.layout.action_bar_title_item, null);
Adam Powell96675b12010-06-10 18:58:59 -0700395 mTitleView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
396 LayoutParams.WRAP_CONTENT));
Adam Powella1700782010-05-13 13:27:35 -0700397 if (mTitle != null) {
398 mTitleView.setText(mTitle);
399 }
400 addView(mTitleView);
401 }
Adam Powell33b97432010-04-20 10:01:14 -0700402
403 @Override
404 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
405 int widthMode = MeasureSpec.getMode(widthMeasureSpec);
406 if (widthMode != MeasureSpec.EXACTLY) {
407 throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
408 "with android:layout_width=\"match_parent\" (or fill_parent)");
409 }
410
411 int heightMode = MeasureSpec.getMode(heightMeasureSpec);
412 if (heightMode != MeasureSpec.AT_MOST) {
413 throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
414 "with android:layout_height=\"wrap_content\"");
415 }
416
417 int contentWidth = MeasureSpec.getSize(widthMeasureSpec);
418
419 int availableWidth = contentWidth - getPaddingLeft() - getPaddingRight();
Adam Powella1700782010-05-13 13:27:35 -0700420 final int height = mContentHeight - getPaddingTop() - getPaddingBottom();
421 final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
Adam Powell33b97432010-04-20 10:01:14 -0700422
Adam Powella1700782010-05-13 13:27:35 -0700423 if (mLogoView != null && mLogoView.getVisibility() != GONE) {
Adam Powell33b97432010-04-20 10:01:14 -0700424 availableWidth = measureChildView(mLogoView, availableWidth, childSpecHeight, mSpacing);
425 }
Adam Powella1700782010-05-13 13:27:35 -0700426 if (mIconView != null && mIconView.getVisibility() != GONE) {
Adam Powell33b97432010-04-20 10:01:14 -0700427 availableWidth = measureChildView(mIconView, availableWidth, childSpecHeight, mSpacing);
428 }
Adam Powell96675b12010-06-10 18:58:59 -0700429
430 if (mMenuView != null) {
431 availableWidth = measureChildView(mMenuView, availableWidth,
Adam Powell7ade1be2010-06-17 12:51:21 -0700432 childSpecHeight, 0);
Adam Powell33b97432010-04-20 10:01:14 -0700433 }
434
435 switch (mNavigationMode) {
Adam Powella4082912010-06-04 18:34:02 -0700436 case ActionBar.NAVIGATION_MODE_STANDARD:
Adam Powell33b97432010-04-20 10:01:14 -0700437 if (mTitleView != null) {
Adam Powella1700782010-05-13 13:27:35 -0700438 measureChildView(mTitleView, availableWidth, childSpecHeight, mSpacing);
Adam Powell33b97432010-04-20 10:01:14 -0700439 }
440 break;
Adam Powella4082912010-06-04 18:34:02 -0700441 case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
442 if (mSpinner != null) {
443 mSpinner.measure(
444 MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.EXACTLY),
445 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
446 }
447 break;
Adam Powell33b97432010-04-20 10:01:14 -0700448 case ActionBar.NAVIGATION_MODE_CUSTOM:
Adam Powella4082912010-06-04 18:34:02 -0700449 if (mCustomNavView != null) {
450 mCustomNavView.measure(
Adam Powella1700782010-05-13 13:27:35 -0700451 MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.EXACTLY),
452 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
Adam Powell33b97432010-04-20 10:01:14 -0700453 }
454 break;
455 }
456
457 setMeasuredDimension(contentWidth, mContentHeight);
458 }
459
460 private int measureChildView(View child, int availableWidth, int childSpecHeight, int spacing) {
Adam Powella1700782010-05-13 13:27:35 -0700461 child.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
Adam Powell33b97432010-04-20 10:01:14 -0700462 childSpecHeight);
463
464 availableWidth -= child.getMeasuredWidth();
465 availableWidth -= spacing;
466
467 return availableWidth;
468 }
469
470 @Override
471 protected void onLayout(boolean changed, int l, int t, int r, int b) {
472 int x = getPaddingLeft();
473 final int y = getPaddingTop();
474 final int contentHeight = b - t - getPaddingTop() - getPaddingBottom();
475
Adam Powella1700782010-05-13 13:27:35 -0700476 if (mLogoView != null && mLogoView.getVisibility() != GONE) {
Adam Powell33b97432010-04-20 10:01:14 -0700477 x += positionChild(mLogoView, x, y, contentHeight) + mSpacing;
478 }
Adam Powella1700782010-05-13 13:27:35 -0700479 if (mIconView != null && mIconView.getVisibility() != GONE) {
Adam Powell33b97432010-04-20 10:01:14 -0700480 x += positionChild(mIconView, x, y, contentHeight) + mSpacing;
481 }
482
483 switch (mNavigationMode) {
Adam Powella4082912010-06-04 18:34:02 -0700484 case ActionBar.NAVIGATION_MODE_STANDARD:
Adam Powell33b97432010-04-20 10:01:14 -0700485 if (mTitleView != null) {
486 x += positionChild(mTitleView, x, y, contentHeight) + mSpacing;
487 }
488 break;
Adam Powella4082912010-06-04 18:34:02 -0700489 case ActionBar.NAVIGATION_MODE_DROPDOWN_LIST:
490 if (mSpinner != null) {
491 x += positionChild(mSpinner, x, y, contentHeight) + mSpacing;
492 }
493 break;
Adam Powell33b97432010-04-20 10:01:14 -0700494 case ActionBar.NAVIGATION_MODE_CUSTOM:
Adam Powella4082912010-06-04 18:34:02 -0700495 if (mCustomNavView != null) {
496 x += positionChild(mCustomNavView, x, y, contentHeight) + mSpacing;
Adam Powell33b97432010-04-20 10:01:14 -0700497 }
498 break;
499 }
500
501 x = r - l - getPaddingRight();
502
Adam Powell96675b12010-06-10 18:58:59 -0700503 if (mMenuView != null) {
Adam Powell7ade1be2010-06-17 12:51:21 -0700504 x -= positionChildInverse(mMenuView, x + mActionSpacing, y, contentHeight)
505 - mActionSpacing;
Adam Powell33b97432010-04-20 10:01:14 -0700506 }
507 }
508
509 private int positionChild(View child, int x, int y, int contentHeight) {
510 int childWidth = child.getMeasuredWidth();
511 int childHeight = child.getMeasuredHeight();
512 int childTop = y + (contentHeight - childHeight) / 2;
513
514 child.layout(x, childTop, x + childWidth, childTop + childHeight);
515
516 return childWidth;
517 }
518
519 private int positionChildInverse(View child, int x, int y, int contentHeight) {
520 int childWidth = child.getMeasuredWidth();
521 int childHeight = child.getMeasuredHeight();
522 int childTop = y + (contentHeight - childHeight) / 2;
523
524 child.layout(x - childWidth, childTop, x, childTop + childHeight);
525
526 return childWidth;
527 }
Adam Powell33b97432010-04-20 10:01:14 -0700528}