StatusBarWindowView.java revision 257f283b0e4cc1c1fa4e7f2472d3ee4ab3b451d0
1c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler/*
2c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler * Copyright (C) 2012 The Android Open Source Project
3c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler *
4c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler * Licensed under the Apache License, Version 2.0 (the "License");
5c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler * you may not use this file except in compliance with the License.
6c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler * You may obtain a copy of the License at
7c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler *
8c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler *      http://www.apache.org/licenses/LICENSE-2.0
9c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler *
10c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler * Unless required by applicable law or agreed to in writing, software
11c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler * distributed under the License is distributed on an "AS IS" BASIS,
12c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler * See the License for the specific language governing permissions and
14c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler * limitations under the License.
15c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler */
16c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler
17c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandlerpackage com.android.systemui.statusbar.phone;
18c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler
19257f283b0e4cc1c1fa4e7f2472d3ee4ab3b451d0John Spurlockimport android.app.StatusBarManager;
20c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandlerimport android.content.Context;
21198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandlerimport android.graphics.Canvas;
22198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandlerimport android.graphics.Paint;
23c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandlerimport android.util.AttributeSet;
24c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandlerimport android.view.KeyEvent;
255de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wrenimport android.view.MotionEvent;
26b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandlerimport android.view.View;
27b10d885c3bb9d634c1c21178319fdf1c04c16bc3Daniel Sandlerimport android.view.ViewRootImpl;
28c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandlerimport android.widget.FrameLayout;
299b2cd15f0fed990f532f35590c2a2896b90dc7fcChris Wrenimport android.widget.ScrollView;
30c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler
315de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wrenimport com.android.systemui.ExpandHelper;
325de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wrenimport com.android.systemui.R;
33198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandlerimport com.android.systemui.statusbar.BaseStatusBar;
345de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wrenimport com.android.systemui.statusbar.policy.NotificationRowLayout;
355de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren
36c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler
37c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandlerpublic class StatusBarWindowView extends FrameLayout
38c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler{
39198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler    public static final String TAG = "StatusBarWindowView";
40198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler    public static final boolean DEBUG = BaseStatusBar.DEBUG;
415de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren
425de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren    private ExpandHelper mExpandHelper;
435de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren    private NotificationRowLayout latestItems;
44b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler    private NotificationPanelView mNotificationPanel;
45101784e5605338f22e32f587ffcaa09b582d556cDaniel Sandler    private ScrollView mScrollView;
465de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren
47c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler    PhoneStatusBar mService;
48c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler
49c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler    public StatusBarWindowView(Context context, AttributeSet attrs) {
50c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler        super(context, attrs);
515de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren        setMotionEventSplittingEnabled(false);
52198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler        setWillNotDraw(!DEBUG);
535de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren    }
545de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren
555de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren    @Override
565de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren    protected void onAttachedToWindow () {
575de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren        super.onAttachedToWindow();
585de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren        latestItems = (NotificationRowLayout) findViewById(R.id.latestItems);
59101784e5605338f22e32f587ffcaa09b582d556cDaniel Sandler        mScrollView = (ScrollView) findViewById(R.id.scroll);
60b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler        mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
615de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren        int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height);
625de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren        int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height);
635de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren        mExpandHelper = new ExpandHelper(mContext, latestItems, minHeight, maxHeight);
645de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren        mExpandHelper.setEventSource(this);
65101784e5605338f22e32f587ffcaa09b582d556cDaniel Sandler        mExpandHelper.setScrollView(mScrollView);
66b10d885c3bb9d634c1c21178319fdf1c04c16bc3Daniel Sandler
67b10d885c3bb9d634c1c21178319fdf1c04c16bc3Daniel Sandler        // We really need to be able to animate while window animations are going on
68b10d885c3bb9d634c1c21178319fdf1c04c16bc3Daniel Sandler        // so that activities may be started asynchronously from panel animations
69b10d885c3bb9d634c1c21178319fdf1c04c16bc3Daniel Sandler        final ViewRootImpl root = getViewRootImpl();
70b10d885c3bb9d634c1c21178319fdf1c04c16bc3Daniel Sandler        if (root != null) {
71b10d885c3bb9d634c1c21178319fdf1c04c16bc3Daniel Sandler            root.setDrawDuringWindowsAnimating(true);
72b10d885c3bb9d634c1c21178319fdf1c04c16bc3Daniel Sandler        }
73c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler    }
74c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler
75c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler    @Override
76c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler    public boolean dispatchKeyEvent(KeyEvent event) {
77c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler        boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
78c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler        switch (event.getKeyCode()) {
79c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler        case KeyEvent.KEYCODE_BACK:
80c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler            if (!down) {
8111cf178100e71d3f9f34ab5865e03a277c5eadaaDaniel Sandler                mService.animateCollapsePanels();
82c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler            }
83c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler            return true;
84c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler        }
85c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler        return super.dispatchKeyEvent(event);
86c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler    }
875de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren
885de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren    @Override
895de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren    public boolean onInterceptTouchEvent(MotionEvent ev) {
90b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler        boolean intercept = false;
91101784e5605338f22e32f587ffcaa09b582d556cDaniel Sandler        if (mNotificationPanel.isFullyExpanded() && mScrollView.getVisibility() == View.VISIBLE) {
92b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler            intercept = mExpandHelper.onInterceptTouchEvent(ev);
93b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler        }
94b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler        if (!intercept) {
95b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler            super.onInterceptTouchEvent(ev);
96b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler        }
975de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren        if (intercept) {
98a4b7f2f75e7803193429ec1179fb5e2eb1c6fbdaDianne Hackborn            MotionEvent cancellation = MotionEvent.obtain(ev);
99a4b7f2f75e7803193429ec1179fb5e2eb1c6fbdaDianne Hackborn            cancellation.setAction(MotionEvent.ACTION_CANCEL);
1005de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren            latestItems.onInterceptTouchEvent(cancellation);
101a4b7f2f75e7803193429ec1179fb5e2eb1c6fbdaDianne Hackborn            cancellation.recycle();
1025de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren        }
1035de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren        return intercept;
1045de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren    }
1055de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren
1065de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren    @Override
1075de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren    public boolean onTouchEvent(MotionEvent ev) {
108b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler        boolean handled = false;
109b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler        if (mNotificationPanel.isFullyExpanded()) {
110b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler            handled = mExpandHelper.onTouchEvent(ev);
111b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler        }
112b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler        if (!handled) {
113b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler            handled = super.onTouchEvent(ev);
114b4e56edde684c2a09cb225c99571fddb39b43b34Daniel Sandler        }
115257f283b0e4cc1c1fa4e7f2472d3ee4ab3b451d0John Spurlock        final int action = ev.getAction();
116257f283b0e4cc1c1fa4e7f2472d3ee4ab3b451d0John Spurlock        if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
117257f283b0e4cc1c1fa4e7f2472d3ee4ab3b451d0John Spurlock            mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
118257f283b0e4cc1c1fa4e7f2472d3ee4ab3b451d0John Spurlock        }
1195de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren        return handled;
1205de6e94e36e2adbdd4ebfb5c1903c23c9ea3c388Chris Wren    }
121198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler
122198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler    @Override
123198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler    public void onDraw(Canvas canvas) {
124198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler        super.onDraw(canvas);
125198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler        if (DEBUG) {
126198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler            Paint pt = new Paint();
127198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler            pt.setColor(0x80FFFF00);
128198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler            pt.setStrokeWidth(12.0f);
129198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler            pt.setStyle(Paint.Style.STROKE);
130198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler            canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
131198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler        }
132198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8Daniel Sandler    }
133ac47ff70c322614ff2ca9ad82fe41338daf55877Daniel Sandler
134ac47ff70c322614ff2ca9ad82fe41338daf55877Daniel Sandler    public void cancelExpandHelper() {
1351a3bdd5097e83659590895991904bbc6250cd5f2Daniel Sandler        if (mExpandHelper != null) {
1361a3bdd5097e83659590895991904bbc6250cd5f2Daniel Sandler            mExpandHelper.cancel();
1371a3bdd5097e83659590895991904bbc6250cd5f2Daniel Sandler        }
138ac47ff70c322614ff2ca9ad82fe41338daf55877Daniel Sandler    }
139c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler}
140c4f2a5652dd42fdb43a94e341b7a2034b0211a21Daniel Sandler
141