ActionBarContainer.java revision 01feaee3d9767ef1185783877e92244f14d7d4ba
145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell/* 245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * Copyright (C) 2010 The Android Open Source Project 345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * 445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * Licensed under the Apache License, Version 2.0 (the "License"); 545f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * you may not use this file except in compliance with the License. 645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * You may obtain a copy of the License at 745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * 845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * http://www.apache.org/licenses/LICENSE-2.0 945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * 1045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * Unless required by applicable law or agreed to in writing, software 1145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * distributed under the License is distributed on an "AS IS" BASIS, 1245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * See the License for the specific language governing permissions and 1445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * limitations under the License. 1545f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell */ 1645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell 1745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellpackage com.android.internal.widget; 1845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell 1945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.content.Context; 2045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.content.res.TypedArray; 2145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.util.AttributeSet; 226ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powellimport android.view.MotionEvent; 2345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.widget.FrameLayout; 2445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell 2545f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell/** 2645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * This class acts as a container for the action bar view and action mode context views. 2745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * It applies special styles as needed to help handle animated transitions between them. 2845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * @hide 2945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell */ 3045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellpublic class ActionBarContainer extends FrameLayout { 3101feaee3d9767ef1185783877e92244f14d7d4baAdam Powell private boolean mIsTransitioning; 3201feaee3d9767ef1185783877e92244f14d7d4baAdam Powell 3345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell public ActionBarContainer(Context context) { 3445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell this(context, null); 3545f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell } 3645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell 3745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell public ActionBarContainer(Context context, AttributeSet attrs) { 3845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell super(context, attrs); 3945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell 4045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell TypedArray a = context.obtainStyledAttributes(attrs, 4145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell com.android.internal.R.styleable.ActionBar); 4245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell setBackgroundDrawable(a.getDrawable(com.android.internal.R.styleable.ActionBar_background)); 4345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell a.recycle(); 4445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell } 456ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell 4601feaee3d9767ef1185783877e92244f14d7d4baAdam Powell /** 4701feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * Set the action bar into a "transitioning" state. While transitioning 4801feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * the bar will block focus and touch from all of its descendants. This 4901feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * prevents the user from interacting with the bar while it is animating 5001feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * in or out. 5101feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * 5201feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * @param isTransitioning true if the bar is currently transitioning, false otherwise. 5301feaee3d9767ef1185783877e92244f14d7d4baAdam Powell */ 5401feaee3d9767ef1185783877e92244f14d7d4baAdam Powell public void setTransitioning(boolean isTransitioning) { 5501feaee3d9767ef1185783877e92244f14d7d4baAdam Powell mIsTransitioning = isTransitioning; 5601feaee3d9767ef1185783877e92244f14d7d4baAdam Powell setDescendantFocusability(isTransitioning ? FOCUS_BLOCK_DESCENDANTS 5701feaee3d9767ef1185783877e92244f14d7d4baAdam Powell : FOCUS_AFTER_DESCENDANTS); 5801feaee3d9767ef1185783877e92244f14d7d4baAdam Powell } 5901feaee3d9767ef1185783877e92244f14d7d4baAdam Powell 6001feaee3d9767ef1185783877e92244f14d7d4baAdam Powell @Override 6101feaee3d9767ef1185783877e92244f14d7d4baAdam Powell public boolean onInterceptTouchEvent(MotionEvent ev) { 6201feaee3d9767ef1185783877e92244f14d7d4baAdam Powell return mIsTransitioning || super.onInterceptTouchEvent(ev); 6301feaee3d9767ef1185783877e92244f14d7d4baAdam Powell } 6401feaee3d9767ef1185783877e92244f14d7d4baAdam Powell 656ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell @Override 666ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell public boolean onTouchEvent(MotionEvent ev) { 676ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell super.onTouchEvent(ev); 686ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell return true; 696ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell } 7045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell} 71