blob: c18565df9cdd3416ba7645643c52522c2f9f8da5 [file] [log] [blame]
Adam Powell45f1e082010-12-10 14:20:13 -08001/*
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 com.android.internal.widget;
18
19import android.content.Context;
20import android.content.res.TypedArray;
21import android.util.AttributeSet;
Adam Powell640a66e2011-04-29 10:18:53 -070022import android.view.ActionMode;
Adam Powell6ecf3d12010-12-19 13:14:58 -080023import android.view.MotionEvent;
Adam Powelldae78242011-04-25 15:23:41 -070024import android.view.View;
Adam Powell45f1e082010-12-10 14:20:13 -080025import android.widget.FrameLayout;
26
27/**
28 * This class acts as a container for the action bar view and action mode context views.
29 * It applies special styles as needed to help handle animated transitions between them.
30 * @hide
31 */
32public class ActionBarContainer extends FrameLayout {
Adam Powell01feaee2011-02-10 15:05:05 -080033 private boolean mIsTransitioning;
Adam Powelldae78242011-04-25 15:23:41 -070034 private View mTabContainer;
Adam Powell01feaee2011-02-10 15:05:05 -080035
Adam Powell45f1e082010-12-10 14:20:13 -080036 public ActionBarContainer(Context context) {
37 this(context, null);
38 }
39
40 public ActionBarContainer(Context context, AttributeSet attrs) {
41 super(context, attrs);
42
43 TypedArray a = context.obtainStyledAttributes(attrs,
44 com.android.internal.R.styleable.ActionBar);
45 setBackgroundDrawable(a.getDrawable(com.android.internal.R.styleable.ActionBar_background));
46 a.recycle();
47 }
Adam Powell6ecf3d12010-12-19 13:14:58 -080048
Adam Powell01feaee2011-02-10 15:05:05 -080049 /**
50 * Set the action bar into a "transitioning" state. While transitioning
51 * the bar will block focus and touch from all of its descendants. This
52 * prevents the user from interacting with the bar while it is animating
53 * in or out.
54 *
55 * @param isTransitioning true if the bar is currently transitioning, false otherwise.
56 */
57 public void setTransitioning(boolean isTransitioning) {
58 mIsTransitioning = isTransitioning;
59 setDescendantFocusability(isTransitioning ? FOCUS_BLOCK_DESCENDANTS
60 : FOCUS_AFTER_DESCENDANTS);
61 }
62
63 @Override
64 public boolean onInterceptTouchEvent(MotionEvent ev) {
65 return mIsTransitioning || super.onInterceptTouchEvent(ev);
66 }
67
Adam Powell6ecf3d12010-12-19 13:14:58 -080068 @Override
69 public boolean onTouchEvent(MotionEvent ev) {
70 super.onTouchEvent(ev);
Adam Powelldae78242011-04-25 15:23:41 -070071
72 // An action bar always eats touch events.
Adam Powell6ecf3d12010-12-19 13:14:58 -080073 return true;
74 }
Adam Powelldae78242011-04-25 15:23:41 -070075
76 public void setTabContainer(View tabView) {
77 if (mTabContainer != null) {
78 removeView(mTabContainer);
79 }
80 mTabContainer = tabView;
81 addView(tabView);
82 }
83
84 public View getTabContainer() {
85 return mTabContainer;
86 }
87
88 @Override
Adam Powell640a66e2011-04-29 10:18:53 -070089 public ActionMode startActionModeForChild(View child, ActionMode.Callback callback) {
90 // No starting an action mode for an action bar child! (Where would it go?)
91 return null;
92 }
93
94 @Override
Adam Powelldae78242011-04-25 15:23:41 -070095 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
96 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
97 if (mTabContainer != null && mTabContainer.getVisibility() != GONE) {
98 final int mode = MeasureSpec.getMode(heightMeasureSpec);
99 if (mode == MeasureSpec.AT_MOST) {
100 final int measuredHeight = getMeasuredHeight();
101 final int maxHeight = MeasureSpec.getSize(heightMeasureSpec);
102 setMeasuredDimension(getMeasuredWidth(),
103 Math.min(measuredHeight + mTabContainer.getMeasuredHeight(), maxHeight));
104 }
105 }
106 }
107
108 @Override
109 public void onLayout(boolean changed, int l, int t, int r, int b) {
110 super.onLayout(changed, l, t, r, b);
111 if (mTabContainer != null && mTabContainer.getVisibility() != GONE) {
112 final int containerHeight = getMeasuredHeight();
113 mTabContainer.layout(l, containerHeight - mTabContainer.getMeasuredHeight(),
114 r, containerHeight);
115 }
116 }
Adam Powell45f1e082010-12-10 14:20:13 -0800117}