blob: d180ab9185ac3119c124d79ffc56db81fbe1fbc1 [file] [log] [blame]
Svetoslav Ganov6179ea32011-06-28 01:12:41 -07001/*
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
Chris Wren1e8f65d2012-06-06 18:08:56 -040019import java.util.ArrayList;
20
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070021import 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
Chris Wren1e8f65d2012-06-06 18:08:56 -040029import com.android.systemui.R;
30
31
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070032public class NotificationPanelTitle extends RelativeLayout implements View.OnClickListener {
33 private NotificationPanel mPanel;
Chris Wren1e8f65d2012-06-06 18:08:56 -040034 private ArrayList<View> buttons;
John Spurlock36231282012-06-23 17:11:27 -040035 private View mSettingsButton;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070036
37 public NotificationPanelTitle(Context context, AttributeSet attrs) {
38 super(context, attrs);
Chris Wren1e8f65d2012-06-06 18:08:56 -040039 buttons = new ArrayList<View>();
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070040 setOnClickListener(this);
41 }
42
43 public void setPanel(NotificationPanel p) {
44 mPanel = p;
45 }
46
47 @Override
Chris Wren1e8f65d2012-06-06 18:08:56 -040048 public void onFinishInflate() {
49 super.onFinishInflate();
John Spurlock36231282012-06-23 17:11:27 -040050 buttons.add(mSettingsButton = findViewById(R.id.settings_button));
Chris Wren1e8f65d2012-06-06 18:08:56 -040051 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
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070065 public boolean onTouchEvent(MotionEvent e) {
John Spurlock36231282012-06-23 17:11:27 -040066 if (!mSettingsButton.isEnabled())
67 return false;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070068 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) {
John Spurlock36231282012-06-23 17:11:27 -040093 if (mSettingsButton.isEnabled() && v == this) {
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070094 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}