1/*
2 * Copyright (C) 2011 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.tablet;
18
19import java.util.ArrayList;
20
21import android.content.Context;
22import android.util.AttributeSet;
23import android.view.MotionEvent;
24import android.view.SoundEffectConstants;
25import android.view.View;
26import android.view.accessibility.AccessibilityEvent;
27import android.widget.RelativeLayout;
28
29import com.android.systemui.R;
30
31
32public class NotificationPanelTitle extends RelativeLayout implements View.OnClickListener {
33    private NotificationPanel mPanel;
34    private ArrayList<View> buttons;
35    private View mSettingsButton;
36
37    public NotificationPanelTitle(Context context, AttributeSet attrs) {
38        super(context, attrs);
39        buttons = new ArrayList<View>();
40        setOnClickListener(this);
41    }
42
43    public void setPanel(NotificationPanel p) {
44        mPanel = p;
45    }
46
47    @Override
48    public void onFinishInflate() {
49        super.onFinishInflate();
50        buttons.add(mSettingsButton = findViewById(R.id.settings_button));
51        buttons.add(findViewById(R.id.notification_button));
52    }
53
54    @Override
55    public void setPressed(boolean pressed) {
56        super.setPressed(pressed);
57        for (View button : buttons) {
58            if (button != null) {
59                button.setPressed(pressed);
60            }
61        }
62    }
63
64    @Override
65    public boolean onTouchEvent(MotionEvent e) {
66        if (!mSettingsButton.isEnabled())
67            return false;
68        switch (e.getAction()) {
69            case MotionEvent.ACTION_DOWN:
70                setPressed(true);
71                break;
72            case MotionEvent.ACTION_MOVE:
73                final int x = (int) e.getX();
74                final int y = (int) e.getY();
75                setPressed(x > 0 && x < getWidth() && y > 0 && y < getHeight());
76                break;
77            case MotionEvent.ACTION_UP:
78                if (isPressed()) {
79                    playSoundEffect(SoundEffectConstants.CLICK);
80                    mPanel.swapPanels();
81                    setPressed(false);
82                }
83                break;
84            case MotionEvent.ACTION_CANCEL:
85                setPressed(false);
86                break;
87        }
88        return true;
89    }
90
91    @Override
92    public void onClick(View v) {
93        if (mSettingsButton.isEnabled() && v == this) {
94            mPanel.swapPanels();
95        }
96    }
97
98    @Override
99    public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
100        if (super.onRequestSendAccessibilityEvent(child, event)) {
101            AccessibilityEvent record = AccessibilityEvent.obtain();
102            onInitializeAccessibilityEvent(record);
103            dispatchPopulateAccessibilityEvent(record);
104            event.appendRecord(record);
105            return true;
106        }
107        return false;
108    }
109}
110