• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.MotionEvent;
22 import android.view.SoundEffectConstants;
23 import android.view.View;
24 import android.view.accessibility.AccessibilityEvent;
25 import android.widget.RelativeLayout;
26 
27 public class NotificationPanelTitle extends RelativeLayout implements View.OnClickListener {
28     private NotificationPanel mPanel;
29 
NotificationPanelTitle(Context context, AttributeSet attrs)30     public NotificationPanelTitle(Context context, AttributeSet attrs) {
31         super(context, attrs);
32         setOnClickListener(this);
33     }
34 
setPanel(NotificationPanel p)35     public void setPanel(NotificationPanel p) {
36         mPanel = p;
37     }
38 
39     @Override
onTouchEvent(MotionEvent e)40     public boolean onTouchEvent(MotionEvent e) {
41         switch (e.getAction()) {
42             case MotionEvent.ACTION_DOWN:
43                 setPressed(true);
44                 break;
45             case MotionEvent.ACTION_MOVE:
46                 final int x = (int) e.getX();
47                 final int y = (int) e.getY();
48                 setPressed(x > 0 && x < getWidth() && y > 0 && y < getHeight());
49                 break;
50             case MotionEvent.ACTION_UP:
51                 if (isPressed()) {
52                     playSoundEffect(SoundEffectConstants.CLICK);
53                     mPanel.swapPanels();
54                     setPressed(false);
55                 }
56                 break;
57             case MotionEvent.ACTION_CANCEL:
58                 setPressed(false);
59                 break;
60         }
61         return true;
62     }
63 
64     @Override
onClick(View v)65     public void onClick(View v) {
66         if (v == this) {
67             mPanel.swapPanels();
68         }
69     }
70 
71     @Override
onRequestSendAccessibilityEvent(View child, AccessibilityEvent event)72     public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
73         if (super.onRequestSendAccessibilityEvent(child, event)) {
74             AccessibilityEvent record = AccessibilityEvent.obtain();
75             onInitializeAccessibilityEvent(record);
76             dispatchPopulateAccessibilityEvent(record);
77             event.appendRecord(record);
78             return true;
79         }
80         return false;
81     }
82 }
83