blob: 6be6d4d43a19e8b1dc8eadaf4e5e11803b22ec82 [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.view.MotionEvent;
Daniel Sandler13522a22012-09-27 14:46:58 -040026import android.view.View;
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -070027import android.view.accessibility.AccessibilityEvent;
Daniel Sandler13522a22012-09-27 14:46:58 -040028
Chris Wren64161cc2012-12-17 16:49:30 -050029import com.android.systemui.EventLogTags;
Chet Haase4d179dc2012-08-22 07:14:42 -070030import com.android.systemui.R;
Daniel Sandler151f00d2012-10-02 22:33:08 -040031import com.android.systemui.statusbar.GestureRecorder;
Daniel Sandler08d05e32012-08-08 16:39:54 -040032
33public class NotificationPanelView extends PanelView {
Chris Wren64161cc2012-12-17 16:49:30 -050034 public static final boolean DEBUG_GESTURES = true;
Chet Haase4d179dc2012-08-22 07:14:42 -070035
36 Drawable mHandleBar;
Daniel Sandler076324ae2012-11-30 16:14:21 -050037 int mHandleBarHeight;
Daniel Sandler13522a22012-09-27 14:46:58 -040038 View mHandleView;
Daniel Sandler040c2e42012-10-17 00:56:33 -040039 int mFingers;
40 PhoneStatusBar mStatusBar;
Daniel Sandler2017a052012-10-17 15:39:28 -040041 boolean mOkToFlip;
Chet Haase4d179dc2012-08-22 07:14:42 -070042
Daniel Sandler08d05e32012-08-08 16:39:54 -040043 public NotificationPanelView(Context context, AttributeSet attrs) {
44 super(context, attrs);
Daniel Sandler13522a22012-09-27 14:46:58 -040045 }
Chet Haase4d179dc2012-08-22 07:14:42 -070046
Daniel Sandler040c2e42012-10-17 00:56:33 -040047 public void setStatusBar(PhoneStatusBar bar) {
48 mStatusBar = bar;
49 }
50
Daniel Sandler13522a22012-09-27 14:46:58 -040051 @Override
52 protected void onFinishInflate() {
53 super.onFinishInflate();
54
55 Resources resources = getContext().getResources();
Chet Haase4d179dc2012-08-22 07:14:42 -070056 mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
Daniel Sandler076324ae2012-11-30 16:14:21 -050057 mHandleBarHeight = resources.getDimensionPixelSize(R.dimen.close_handle_height);
Daniel Sandler13522a22012-09-27 14:46:58 -040058 mHandleView = findViewById(R.id.handle);
Daniel Sandler08d05e32012-08-08 16:39:54 -040059 }
60
Daniel Sandler08d05e32012-08-08 16:39:54 -040061 @Override
62 public void fling(float vel, boolean always) {
Daniel Sandler151f00d2012-10-02 22:33:08 -040063 GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
64 if (gr != null) {
65 gr.tag(
66 "fling " + ((vel > 0) ? "open" : "closed"),
67 "notifications,v=" + vel);
68 }
Daniel Sandler08d05e32012-08-08 16:39:54 -040069 super.fling(vel, always);
70 }
Chet Haase4d179dc2012-08-22 07:14:42 -070071
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -070072 @Override
73 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
74 if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
75 event.getText()
76 .add(getContext().getString(R.string.accessibility_desc_notification_shade));
77 return true;
78 }
79
80 return super.dispatchPopulateAccessibilityEvent(event);
81 }
82
Daniel Sandler13522a22012-09-27 14:46:58 -040083 // We draw the handle ourselves so that it's always glued to the bottom of the window.
Chet Haase4d179dc2012-08-22 07:14:42 -070084 @Override
85 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
86 super.onLayout(changed, left, top, right, bottom);
87 if (changed) {
Daniel Sandler13522a22012-09-27 14:46:58 -040088 final int pl = getPaddingLeft();
89 final int pr = getPaddingRight();
90 mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight);
Chet Haase4d179dc2012-08-22 07:14:42 -070091 }
92 }
93
94 @Override
95 public void draw(Canvas canvas) {
96 super.draw(canvas);
Daniel Sandler13522a22012-09-27 14:46:58 -040097 final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
98 canvas.translate(0, off);
99 mHandleBar.setState(mHandleView.getDrawableState());
Chet Haase4d179dc2012-08-22 07:14:42 -0700100 mHandleBar.draw(canvas);
Daniel Sandler13522a22012-09-27 14:46:58 -0400101 canvas.translate(0, -off);
Chet Haase4d179dc2012-08-22 07:14:42 -0700102 }
Daniel Sandler040c2e42012-10-17 00:56:33 -0400103
104 @Override
105 public boolean onTouchEvent(MotionEvent event) {
Chris Wren64161cc2012-12-17 16:49:30 -0500106 if (DEBUG_GESTURES) {
107 if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
108 EventLog.writeEvent(EventLogTags.SYSUI_NOTIFICATIONPANEL_TOUCH,
109 event.getActionMasked(), (int) event.getX(), (int) event.getY());
110 }
111 }
Daniel Sandler040c2e42012-10-17 00:56:33 -0400112 if (PhoneStatusBar.SETTINGS_DRAG_SHORTCUT && mStatusBar.mHasFlipSettings) {
113 switch (event.getActionMasked()) {
114 case MotionEvent.ACTION_DOWN:
Daniel Sandler2017a052012-10-17 15:39:28 -0400115 mOkToFlip = getExpandedHeight() == 0;
Daniel Sandler040c2e42012-10-17 00:56:33 -0400116 break;
117 case MotionEvent.ACTION_POINTER_DOWN:
Daniel Sandler2017a052012-10-17 15:39:28 -0400118 if (mOkToFlip) {
Daniel Sandler040c2e42012-10-17 00:56:33 -0400119 float miny = event.getY(0);
120 float maxy = miny;
121 for (int i=1; i<event.getPointerCount(); i++) {
122 final float y = event.getY(i);
123 if (y < miny) miny = y;
124 if (y > maxy) maxy = y;
125 }
126 if (maxy - miny < mHandleBarHeight) {
127 if (getMeasuredHeight() < mHandleBarHeight) {
128 mStatusBar.switchToSettings();
129 } else {
130 mStatusBar.flipToSettings();
131 }
Daniel Sandler2017a052012-10-17 15:39:28 -0400132 mOkToFlip = false;
Daniel Sandler040c2e42012-10-17 00:56:33 -0400133 }
134 }
135 break;
136 }
137 }
138 return mHandleView.dispatchTouchEvent(event);
139 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400140}