blob: f33dc20607bd0b007b8fb8ce98cd16bcca61792b [file] [log] [blame]
Daniel Sandler08d05e32012-08-08 16:39:54 -04001/*
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;
Chet Haase4d179dc2012-08-22 07:14:42 -070020import android.content.res.Resources;
21import android.graphics.Canvas;
22import android.graphics.drawable.Drawable;
Daniel Sandler08d05e32012-08-08 16:39:54 -040023import android.util.AttributeSet;
Chris Wren64161cc2012-12-17 16:49:30 -050024import android.util.EventLog;
Daniel Sandler040c2e42012-10-17 00:56:33 -040025import android.util.Slog;
26import android.view.MotionEvent;
Daniel Sandler13522a22012-09-27 14:46:58 -040027import android.view.View;
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -070028import android.view.accessibility.AccessibilityEvent;
Daniel Sandler13522a22012-09-27 14:46:58 -040029
Chris Wren64161cc2012-12-17 16:49:30 -050030import com.android.systemui.EventLogTags;
Chet Haase4d179dc2012-08-22 07:14:42 -070031import com.android.systemui.R;
Daniel Sandler151f00d2012-10-02 22:33:08 -040032import com.android.systemui.statusbar.GestureRecorder;
Daniel Sandler08d05e32012-08-08 16:39:54 -040033
34public class NotificationPanelView extends PanelView {
Chris Wren64161cc2012-12-17 16:49:30 -050035 public static final boolean DEBUG_GESTURES = true;
Chet Haase4d179dc2012-08-22 07:14:42 -070036
37 Drawable mHandleBar;
Daniel Sandler076324ae2012-11-30 16:14:21 -050038 int mHandleBarHeight;
Daniel Sandler13522a22012-09-27 14:46:58 -040039 View mHandleView;
Daniel Sandler040c2e42012-10-17 00:56:33 -040040 int mFingers;
41 PhoneStatusBar mStatusBar;
Daniel Sandler2017a052012-10-17 15:39:28 -040042 boolean mOkToFlip;
Chet Haase4d179dc2012-08-22 07:14:42 -070043
Daniel Sandler08d05e32012-08-08 16:39:54 -040044 public NotificationPanelView(Context context, AttributeSet attrs) {
45 super(context, attrs);
Daniel Sandler13522a22012-09-27 14:46:58 -040046 }
Chet Haase4d179dc2012-08-22 07:14:42 -070047
Daniel Sandler040c2e42012-10-17 00:56:33 -040048 public void setStatusBar(PhoneStatusBar bar) {
49 mStatusBar = bar;
50 }
51
Daniel Sandler13522a22012-09-27 14:46:58 -040052 @Override
53 protected void onFinishInflate() {
54 super.onFinishInflate();
55
56 Resources resources = getContext().getResources();
Chet Haase4d179dc2012-08-22 07:14:42 -070057 mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
Daniel Sandler076324ae2012-11-30 16:14:21 -050058 mHandleBarHeight = resources.getDimensionPixelSize(R.dimen.close_handle_height);
Daniel Sandler13522a22012-09-27 14:46:58 -040059 mHandleView = findViewById(R.id.handle);
Daniel Sandler08d05e32012-08-08 16:39:54 -040060 }
61
Daniel Sandler08d05e32012-08-08 16:39:54 -040062 @Override
63 public void fling(float vel, boolean always) {
Daniel Sandler151f00d2012-10-02 22:33:08 -040064 GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
65 if (gr != null) {
66 gr.tag(
67 "fling " + ((vel > 0) ? "open" : "closed"),
68 "notifications,v=" + vel);
69 }
Daniel Sandler08d05e32012-08-08 16:39:54 -040070 super.fling(vel, always);
71 }
Chet Haase4d179dc2012-08-22 07:14:42 -070072
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -070073 @Override
74 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
75 if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
76 event.getText()
77 .add(getContext().getString(R.string.accessibility_desc_notification_shade));
78 return true;
79 }
80
81 return super.dispatchPopulateAccessibilityEvent(event);
82 }
83
Daniel Sandler13522a22012-09-27 14:46:58 -040084 // We draw the handle ourselves so that it's always glued to the bottom of the window.
Chet Haase4d179dc2012-08-22 07:14:42 -070085 @Override
86 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
87 super.onLayout(changed, left, top, right, bottom);
88 if (changed) {
Daniel Sandler13522a22012-09-27 14:46:58 -040089 final int pl = getPaddingLeft();
90 final int pr = getPaddingRight();
91 mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight);
Chet Haase4d179dc2012-08-22 07:14:42 -070092 }
93 }
94
95 @Override
96 public void draw(Canvas canvas) {
97 super.draw(canvas);
Daniel Sandler13522a22012-09-27 14:46:58 -040098 final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
99 canvas.translate(0, off);
100 mHandleBar.setState(mHandleView.getDrawableState());
Chet Haase4d179dc2012-08-22 07:14:42 -0700101 mHandleBar.draw(canvas);
Daniel Sandler13522a22012-09-27 14:46:58 -0400102 canvas.translate(0, -off);
Chet Haase4d179dc2012-08-22 07:14:42 -0700103 }
Daniel Sandler040c2e42012-10-17 00:56:33 -0400104
105 @Override
106 public boolean onTouchEvent(MotionEvent event) {
Chris Wren64161cc2012-12-17 16:49:30 -0500107 if (DEBUG_GESTURES) {
108 if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
109 EventLog.writeEvent(EventLogTags.SYSUI_NOTIFICATIONPANEL_TOUCH,
110 event.getActionMasked(), (int) event.getX(), (int) event.getY());
111 }
112 }
Daniel Sandler040c2e42012-10-17 00:56:33 -0400113 if (PhoneStatusBar.SETTINGS_DRAG_SHORTCUT && mStatusBar.mHasFlipSettings) {
114 switch (event.getActionMasked()) {
115 case MotionEvent.ACTION_DOWN:
Daniel Sandler2017a052012-10-17 15:39:28 -0400116 mOkToFlip = getExpandedHeight() == 0;
Daniel Sandler040c2e42012-10-17 00:56:33 -0400117 break;
118 case MotionEvent.ACTION_POINTER_DOWN:
Daniel Sandler2017a052012-10-17 15:39:28 -0400119 if (mOkToFlip) {
Daniel Sandler040c2e42012-10-17 00:56:33 -0400120 float miny = event.getY(0);
121 float maxy = miny;
122 for (int i=1; i<event.getPointerCount(); i++) {
123 final float y = event.getY(i);
124 if (y < miny) miny = y;
125 if (y > maxy) maxy = y;
126 }
127 if (maxy - miny < mHandleBarHeight) {
128 if (getMeasuredHeight() < mHandleBarHeight) {
129 mStatusBar.switchToSettings();
130 } else {
131 mStatusBar.flipToSettings();
132 }
Daniel Sandler2017a052012-10-17 15:39:28 -0400133 mOkToFlip = false;
Daniel Sandler040c2e42012-10-17 00:56:33 -0400134 }
135 }
136 break;
137 }
138 }
139 return mHandleView.dispatchTouchEvent(event);
140 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400141}