StatusBarWindowView.java revision 67b2260093774f5866f781aede52830440f4ed0e
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.app.StatusBarManager;
20import android.content.Context;
21import android.graphics.Canvas;
22import android.graphics.Paint;
23import android.util.AttributeSet;
24import android.view.KeyEvent;
25import android.view.MotionEvent;
26import android.view.View;
27import android.view.ViewGroup;
28import android.view.ViewRootImpl;
29import android.widget.FrameLayout;
30import android.widget.ScrollView;
31
32import com.android.systemui.ExpandHelper;
33import com.android.systemui.R;
34import com.android.systemui.statusbar.BaseStatusBar;
35
36
37public class StatusBarWindowView extends FrameLayout
38{
39    public static final String TAG = "StatusBarWindowView";
40    public static final boolean DEBUG = BaseStatusBar.DEBUG;
41
42    private ExpandHelper mExpandHelper;
43    private ViewGroup latestItems;
44    private NotificationPanelView mNotificationPanel;
45    private ScrollView mScrollView;
46
47    PhoneStatusBar mService;
48
49    public StatusBarWindowView(Context context, AttributeSet attrs) {
50        super(context, attrs);
51        setMotionEventSplittingEnabled(false);
52        setWillNotDraw(!DEBUG);
53    }
54
55    @Override
56    protected void onAttachedToWindow () {
57        super.onAttachedToWindow();
58
59        if (BaseStatusBar.ENABLE_NOTIFICATION_STACK) {
60            latestItems = (ViewGroup) findViewById(R.id.notification_stack_scroller);
61        } else {
62            latestItems = (ViewGroup) findViewById(R.id.latestItems);
63        }
64        mScrollView = (ScrollView) findViewById(R.id.scroll);
65        mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
66        int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height);
67        int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height);
68        mExpandHelper = new ExpandHelper(getContext(), (ExpandHelper.Callback) latestItems,
69                minHeight, maxHeight);
70        mExpandHelper.setEventSource(this);
71        mExpandHelper.setScrollView(mScrollView);
72
73        // We really need to be able to animate while window animations are going on
74        // so that activities may be started asynchronously from panel animations
75        final ViewRootImpl root = getViewRootImpl();
76        if (root != null) {
77            root.setDrawDuringWindowsAnimating(true);
78        }
79    }
80
81    @Override
82    public boolean dispatchKeyEvent(KeyEvent event) {
83        boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
84        switch (event.getKeyCode()) {
85        case KeyEvent.KEYCODE_BACK:
86            if (!down) {
87                mService.animateCollapsePanels();
88            }
89            return true;
90        }
91        return super.dispatchKeyEvent(event);
92    }
93
94    @Override
95    public boolean onInterceptTouchEvent(MotionEvent ev) {
96        boolean intercept = false;
97        if (mNotificationPanel.isFullyExpanded() && mScrollView.getVisibility() == View.VISIBLE) {
98            intercept = mExpandHelper.onInterceptTouchEvent(ev);
99        }
100        if (!intercept) {
101            super.onInterceptTouchEvent(ev);
102        }
103        if (intercept) {
104            MotionEvent cancellation = MotionEvent.obtain(ev);
105            cancellation.setAction(MotionEvent.ACTION_CANCEL);
106            latestItems.onInterceptTouchEvent(cancellation);
107            cancellation.recycle();
108        }
109        return intercept;
110    }
111
112    @Override
113    public boolean onTouchEvent(MotionEvent ev) {
114        boolean handled = false;
115        if (mNotificationPanel.isFullyExpanded()) {
116            handled = mExpandHelper.onTouchEvent(ev);
117        }
118        if (!handled) {
119            handled = super.onTouchEvent(ev);
120        }
121        final int action = ev.getAction();
122        if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
123            mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
124        }
125        return handled;
126    }
127
128    @Override
129    public void onDraw(Canvas canvas) {
130        super.onDraw(canvas);
131        if (DEBUG) {
132            Paint pt = new Paint();
133            pt.setColor(0x80FFFF00);
134            pt.setStrokeWidth(12.0f);
135            pt.setStyle(Paint.Style.STROKE);
136            canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
137        }
138    }
139
140    public void cancelExpandHelper() {
141        if (mExpandHelper != null) {
142            mExpandHelper.cancel();
143        }
144    }
145}
146
147