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.util.EventLog;
22import android.view.MotionEvent;
23import android.widget.FrameLayout;
24
25import com.android.systemui.EventLogTags;
26
27public class PanelHolder extends FrameLayout {
28    public static final boolean DEBUG_GESTURES = true;
29
30    private int mSelectedPanelIndex = -1;
31    private PanelBar mBar;
32
33    public PanelHolder(Context context, AttributeSet attrs) {
34        super(context, attrs);
35        setChildrenDrawingOrderEnabled(true);
36    }
37
38    @Override
39    protected void onFinishInflate() {
40        super.onFinishInflate();
41        setChildrenDrawingOrderEnabled(true);
42    }
43
44    public int getPanelIndex(PanelView pv) {
45        final int N = getChildCount();
46        for (int i=0; i<N; i++) {
47            final PanelView v = (PanelView) getChildAt(i);
48            if (pv == v) return i;
49        }
50        return -1;
51    }
52
53    public void setSelectedPanel(PanelView pv) {
54        mSelectedPanelIndex = getPanelIndex(pv);
55    }
56
57    @Override
58    protected int getChildDrawingOrder(int childCount, int i) {
59        if (mSelectedPanelIndex == -1) {
60            return i;
61        } else {
62            if (i == childCount - 1) {
63                return mSelectedPanelIndex;
64            } else if (i >= mSelectedPanelIndex) {
65                return i + 1;
66            } else {
67                return i;
68            }
69        }
70    }
71
72    @Override
73    public boolean onTouchEvent(MotionEvent event) {
74        if (DEBUG_GESTURES) {
75            if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
76                EventLog.writeEvent(EventLogTags.SYSUI_PANELHOLDER_TOUCH,
77                        event.getActionMasked(), (int) event.getX(), (int) event.getY());
78            }
79        }
80        return false;
81    }
82
83    public void setBar(PanelBar panelBar) {
84        mBar = panelBar;
85    }
86}
87