Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 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 | |
| 17 | package com.android.systemui.statusbar.tablet; |
| 18 | |
Chris Wren | 1e8f65d | 2012-06-06 18:08:56 -0400 | [diff] [blame] | 19 | import java.util.ArrayList; |
| 20 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.util.AttributeSet; |
| 23 | import android.view.MotionEvent; |
| 24 | import android.view.SoundEffectConstants; |
| 25 | import android.view.View; |
| 26 | import android.view.accessibility.AccessibilityEvent; |
| 27 | import android.widget.RelativeLayout; |
| 28 | |
Chris Wren | 1e8f65d | 2012-06-06 18:08:56 -0400 | [diff] [blame] | 29 | import com.android.systemui.R; |
| 30 | |
| 31 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 32 | public class NotificationPanelTitle extends RelativeLayout implements View.OnClickListener { |
| 33 | private NotificationPanel mPanel; |
Chris Wren | 1e8f65d | 2012-06-06 18:08:56 -0400 | [diff] [blame] | 34 | private ArrayList<View> buttons; |
John Spurlock | 3623128 | 2012-06-23 17:11:27 -0400 | [diff] [blame] | 35 | private View mSettingsButton; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 36 | |
| 37 | public NotificationPanelTitle(Context context, AttributeSet attrs) { |
| 38 | super(context, attrs); |
Chris Wren | 1e8f65d | 2012-06-06 18:08:56 -0400 | [diff] [blame] | 39 | buttons = new ArrayList<View>(); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 40 | setOnClickListener(this); |
| 41 | } |
| 42 | |
| 43 | public void setPanel(NotificationPanel p) { |
| 44 | mPanel = p; |
| 45 | } |
| 46 | |
| 47 | @Override |
Chris Wren | 1e8f65d | 2012-06-06 18:08:56 -0400 | [diff] [blame] | 48 | public void onFinishInflate() { |
| 49 | super.onFinishInflate(); |
John Spurlock | 3623128 | 2012-06-23 17:11:27 -0400 | [diff] [blame] | 50 | buttons.add(mSettingsButton = findViewById(R.id.settings_button)); |
Chris Wren | 1e8f65d | 2012-06-06 18:08:56 -0400 | [diff] [blame] | 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 |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 65 | public boolean onTouchEvent(MotionEvent e) { |
John Spurlock | 3623128 | 2012-06-23 17:11:27 -0400 | [diff] [blame] | 66 | if (!mSettingsButton.isEnabled()) |
| 67 | return false; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 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) { |
John Spurlock | 3623128 | 2012-06-23 17:11:27 -0400 | [diff] [blame] | 93 | if (mSettingsButton.isEnabled() && v == this) { |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 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 | } |