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.graphics.Canvas;
21import android.graphics.Paint;
22import android.util.AttributeSet;
23import android.util.Log;
24import android.view.KeyEvent;
25import android.view.MotionEvent;
26import android.view.View;
27import android.widget.FrameLayout;
28import android.widget.ScrollView;
29import android.widget.TextSwitcher;
30
31import com.android.systemui.ExpandHelper;
32import com.android.systemui.R;
33import com.android.systemui.statusbar.BaseStatusBar;
34import com.android.systemui.statusbar.policy.NotificationRowLayout;
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 NotificationRowLayout 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        latestItems = (NotificationRowLayout) findViewById(R.id.latestItems);
59        mScrollView = (ScrollView) findViewById(R.id.scroll);
60        mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel);
61        int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height);
62        int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height);
63        mExpandHelper = new ExpandHelper(mContext, latestItems, minHeight, maxHeight);
64        mExpandHelper.setEventSource(this);
65        mExpandHelper.setScrollView(mScrollView);
66    }
67
68    @Override
69    public boolean dispatchKeyEvent(KeyEvent event) {
70        boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
71        switch (event.getKeyCode()) {
72        case KeyEvent.KEYCODE_BACK:
73            if (!down) {
74                mService.animateCollapsePanels();
75            }
76            return true;
77        }
78        return super.dispatchKeyEvent(event);
79    }
80
81    @Override
82    public boolean onInterceptTouchEvent(MotionEvent ev) {
83        boolean intercept = false;
84        if (mNotificationPanel.isFullyExpanded() && mScrollView.getVisibility() == View.VISIBLE) {
85            intercept = mExpandHelper.onInterceptTouchEvent(ev);
86        }
87        if (!intercept) {
88            super.onInterceptTouchEvent(ev);
89        }
90        if (intercept) {
91            MotionEvent cancellation = MotionEvent.obtain(ev);
92            cancellation.setAction(MotionEvent.ACTION_CANCEL);
93            latestItems.onInterceptTouchEvent(cancellation);
94            cancellation.recycle();
95        }
96        return intercept;
97    }
98
99    @Override
100    public boolean onTouchEvent(MotionEvent ev) {
101        boolean handled = false;
102        if (mNotificationPanel.isFullyExpanded()) {
103            handled = mExpandHelper.onTouchEvent(ev);
104        }
105        if (!handled) {
106            handled = super.onTouchEvent(ev);
107        }
108        return handled;
109    }
110
111    @Override
112    public void onDraw(Canvas canvas) {
113        super.onDraw(canvas);
114        if (DEBUG) {
115            Paint pt = new Paint();
116            pt.setColor(0x80FFFF00);
117            pt.setStrokeWidth(12.0f);
118            pt.setStyle(Paint.Style.STROKE);
119            canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
120        }
121    }
122
123    public void cancelExpandHelper() {
124        if (mExpandHelper != null) {
125            mExpandHelper.cancel();
126        }
127    }
128}
129
130