blob: ec7d80a9aa1481f4ce6654154980a3bd5e6e093e [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;
20import android.util.AttributeSet;
Daniel Sandler040c2e42012-10-17 00:56:33 -040021import android.view.MotionEvent;
Daniel Sandler13522a22012-09-27 14:46:58 -040022import android.view.View;
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -070023import android.view.accessibility.AccessibilityEvent;
Daniel Sandler13522a22012-09-27 14:46:58 -040024
Chet Haase4d179dc2012-08-22 07:14:42 -070025import com.android.systemui.R;
Jorim Jaggibe565df2014-04-28 17:51:23 +020026import com.android.systemui.statusbar.ExpandableView;
Daniel Sandler151f00d2012-10-02 22:33:08 -040027import com.android.systemui.statusbar.GestureRecorder;
Jorim Jaggiecbab362014-04-23 16:13:15 +020028import com.android.systemui.statusbar.StatusBarState;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010029import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Daniel Sandler08d05e32012-08-08 16:39:54 -040030
Jorim Jaggibe565df2014-04-28 17:51:23 +020031public class NotificationPanelView extends PanelView implements
32 ExpandableView.OnHeightChangedListener {
Chris Wren64161cc2012-12-17 16:49:30 -050033 public static final boolean DEBUG_GESTURES = true;
Chet Haase4d179dc2012-08-22 07:14:42 -070034
Daniel Sandler040c2e42012-10-17 00:56:33 -040035 PhoneStatusBar mStatusBar;
John Spurlock73203eb2014-04-15 16:14:46 -040036 private View mHeader;
37 private View mKeyguardStatusView;
38
Selim Cinekb6d85eb2014-03-28 20:21:01 +010039 private NotificationStackScrollLayout mNotificationStackScroller;
John Spurlock73203eb2014-04-15 16:14:46 -040040 private boolean mTrackingSettings;
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +020041 private int mNotificationTopPadding;
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) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +010048 if (mStatusBar != null) {
49 mStatusBar.setOnFlipRunnable(null);
50 }
Daniel Sandler040c2e42012-10-17 00:56:33 -040051 mStatusBar = bar;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010052 if (bar != null) {
53 mStatusBar.setOnFlipRunnable(new Runnable() {
54 @Override
55 public void run() {
56 requestPanelHeightUpdate();
57 }
58 });
59 }
Daniel Sandler040c2e42012-10-17 00:56:33 -040060 }
61
Daniel Sandler13522a22012-09-27 14:46:58 -040062 @Override
63 protected void onFinishInflate() {
64 super.onFinishInflate();
65
John Spurlock73203eb2014-04-15 16:14:46 -040066 mHeader = findViewById(R.id.header);
67 mKeyguardStatusView = findViewById(R.id.keyguard_status_view);
Selim Cinekb6d85eb2014-03-28 20:21:01 +010068 mNotificationStackScroller = (NotificationStackScrollLayout)
69 findViewById(R.id.notification_stack_scroller);
Jorim Jaggibe565df2014-04-28 17:51:23 +020070 mNotificationStackScroller.setOnHeightChangedListener(this);
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +020071 mNotificationTopPadding = getResources().getDimensionPixelSize(
72 R.dimen.notifications_top_padding);
73 }
74
75 @Override
76 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
77 super.onLayout(changed, left, top, right, bottom);
78 int keyguardBottomMargin =
79 ((MarginLayoutParams) mKeyguardStatusView.getLayoutParams()).bottomMargin;
Jorim Jaggiecbab362014-04-23 16:13:15 +020080 mNotificationStackScroller.setTopPadding(mStatusBar.getBarState() == StatusBarState.KEYGUARD
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +020081 ? mKeyguardStatusView.getBottom() + keyguardBottomMargin
82 : mHeader.getBottom() + mNotificationTopPadding);
Daniel Sandler08d05e32012-08-08 16:39:54 -040083 }
84
Daniel Sandler08d05e32012-08-08 16:39:54 -040085 @Override
86 public void fling(float vel, boolean always) {
Daniel Sandler151f00d2012-10-02 22:33:08 -040087 GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
88 if (gr != null) {
89 gr.tag(
90 "fling " + ((vel > 0) ? "open" : "closed"),
91 "notifications,v=" + vel);
92 }
Daniel Sandler08d05e32012-08-08 16:39:54 -040093 super.fling(vel, always);
94 }
Chet Haase4d179dc2012-08-22 07:14:42 -070095
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -070096 @Override
97 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
98 if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
99 event.getText()
100 .add(getContext().getString(R.string.accessibility_desc_notification_shade));
101 return true;
102 }
103
104 return super.dispatchPopulateAccessibilityEvent(event);
105 }
106
Daniel Sandler040c2e42012-10-17 00:56:33 -0400107 @Override
John Spurlock73203eb2014-04-15 16:14:46 -0400108 public boolean onInterceptTouchEvent(MotionEvent event) {
109 // intercept for quick settings
110 if (event.getAction() == MotionEvent.ACTION_DOWN) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200111 final View target = mStatusBar.getBarState() == StatusBarState.KEYGUARD
112 ? mKeyguardStatusView
113 : mHeader;
John Spurlock73203eb2014-04-15 16:14:46 -0400114 final boolean inTarget = PhoneStatusBar.inBounds(target, event, true);
115 if (inTarget && !isInSettings()) {
116 mTrackingSettings = true;
Jorim Jaggiecbab362014-04-23 16:13:15 +0200117 requestDisallowInterceptTouchEvent(true);
John Spurlock73203eb2014-04-15 16:14:46 -0400118 return true;
119 }
120 if (!inTarget && isInSettings()) {
121 mTrackingSettings = true;
Jorim Jaggiecbab362014-04-23 16:13:15 +0200122 requestDisallowInterceptTouchEvent(true);
John Spurlock73203eb2014-04-15 16:14:46 -0400123 return true;
124 }
125 }
126 return super.onInterceptTouchEvent(event);
127 }
128
129 @Override
Daniel Sandler040c2e42012-10-17 00:56:33 -0400130 public boolean onTouchEvent(MotionEvent event) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100131 // TODO: Handle doublefinger swipe to notifications again. Look at history for a reference
132 // implementation.
John Spurlock73203eb2014-04-15 16:14:46 -0400133 if (mTrackingSettings) {
134 mStatusBar.onSettingsEvent(event);
135 if (event.getAction() == MotionEvent.ACTION_UP
136 || event.getAction() == MotionEvent.ACTION_CANCEL) {
137 mTrackingSettings = false;
138 }
139 return true;
140 }
141 if (isInSettings()) {
142 return true;
143 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100144 return super.onTouchEvent(event);
145 }
146
147 @Override
148 protected boolean isScrolledToBottom() {
149 if (!isInSettings()) {
150 return mNotificationStackScroller.isScrolledToBottom();
Chris Wren64161cc2012-12-17 16:49:30 -0500151 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100152 return super.isScrolledToBottom();
153 }
154
155 @Override
156 protected int getMaxPanelHeight() {
157 if (!isInSettings()) {
158 int maxPanelHeight = super.getMaxPanelHeight();
159 int emptyBottomMargin = mNotificationStackScroller.getEmptyBottomMargin();
160 return maxPanelHeight - emptyBottomMargin;
Daniel Sandler040c2e42012-10-17 00:56:33 -0400161 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100162 return super.getMaxPanelHeight();
163 }
164
165 private boolean isInSettings() {
166 return mStatusBar != null && mStatusBar.isFlippedToSettings();
167 }
168
169 @Override
170 protected void onHeightUpdated(float expandedHeight) {
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200171 mNotificationStackScroller.setStackHeight(expandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100172 }
173
174 @Override
175 protected int getDesiredMeasureHeight() {
176 return mMaxPanelHeight;
Daniel Sandler040c2e42012-10-17 00:56:33 -0400177 }
Selim Cinek1685e632014-04-08 02:27:49 +0200178
179 @Override
180 protected void onExpandingStarted() {
181 super.onExpandingStarted();
182 mNotificationStackScroller.onExpansionStarted();
183 }
184
185 @Override
186 protected void onExpandingFinished() {
187 super.onExpandingFinished();
188 mNotificationStackScroller.onExpansionStopped();
189 }
Jorim Jaggibe565df2014-04-28 17:51:23 +0200190
191 @Override
192 public void onHeightChanged(ExpandableView view) {
193 requestPanelHeightUpdate();
194 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400195}