1/* 2 * Copyright (C) 2012 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.systemui.statusbar.phone; 18 19import android.content.Context; 20import android.util.AttributeSet; 21import android.view.MotionEvent; 22import android.widget.FrameLayout; 23 24public class PanelHolder extends FrameLayout { 25 26 private int mSelectedPanelIndex = -1; 27 private PanelBar mBar; 28 29 public PanelHolder(Context context, AttributeSet attrs) { 30 super(context, attrs); 31 setChildrenDrawingOrderEnabled(true); 32 } 33 34 @Override 35 protected void onFinishInflate() { 36 super.onFinishInflate(); 37 setChildrenDrawingOrderEnabled(true); 38 } 39 40 public int getPanelIndex(PanelView pv) { 41 final int N = getChildCount(); 42 for (int i=0; i<N; i++) { 43 final PanelView v = (PanelView) getChildAt(i); 44 if (pv == v) return i; 45 } 46 return -1; 47 } 48 49 public void setSelectedPanel(PanelView pv) { 50 mSelectedPanelIndex = getPanelIndex(pv); 51 } 52 53 @Override 54 protected int getChildDrawingOrder(int childCount, int i) { 55 if (mSelectedPanelIndex == -1) { 56 return i; 57 } else { 58 if (i == childCount - 1) { 59 return mSelectedPanelIndex; 60 } else if (i >= mSelectedPanelIndex) { 61 return i + 1; 62 } else { 63 return i; 64 } 65 } 66 } 67 68 @Override 69 public boolean onTouchEvent(MotionEvent event) { 70 switch (event.getAction()) { 71 case MotionEvent.ACTION_DOWN: 72 PanelBar.LOG("PanelHolder got touch in open air, closing panels"); 73 mBar.collapseAllPanels(true); 74 break; 75 } 76 return false; 77 } 78 79 public void setBar(PanelBar panelBar) { 80 mBar = panelBar; 81 } 82} 83