blob: b04977a4b2b80fe1f9bb1b4d2e4a2f91bb0d8437 [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
Jorim Jaggi0dd68812014-05-01 19:17:37 +020082 : mHeader.getBottom() + mNotificationTopPadding,
83 mStatusBar.isScreenTurnedOn() && mStatusBar.isExpandedVisible());
Daniel Sandler08d05e32012-08-08 16:39:54 -040084 }
85
Daniel Sandler08d05e32012-08-08 16:39:54 -040086 @Override
87 public void fling(float vel, boolean always) {
Daniel Sandler151f00d2012-10-02 22:33:08 -040088 GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
89 if (gr != null) {
90 gr.tag(
91 "fling " + ((vel > 0) ? "open" : "closed"),
92 "notifications,v=" + vel);
93 }
Daniel Sandler08d05e32012-08-08 16:39:54 -040094 super.fling(vel, always);
95 }
Chet Haase4d179dc2012-08-22 07:14:42 -070096
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -070097 @Override
98 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
99 if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
100 event.getText()
101 .add(getContext().getString(R.string.accessibility_desc_notification_shade));
102 return true;
103 }
104
105 return super.dispatchPopulateAccessibilityEvent(event);
106 }
107
Daniel Sandler040c2e42012-10-17 00:56:33 -0400108 @Override
John Spurlock73203eb2014-04-15 16:14:46 -0400109 public boolean onInterceptTouchEvent(MotionEvent event) {
110 // intercept for quick settings
111 if (event.getAction() == MotionEvent.ACTION_DOWN) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200112 final View target = mStatusBar.getBarState() == StatusBarState.KEYGUARD
113 ? mKeyguardStatusView
114 : mHeader;
John Spurlock73203eb2014-04-15 16:14:46 -0400115 final boolean inTarget = PhoneStatusBar.inBounds(target, event, true);
116 if (inTarget && !isInSettings()) {
117 mTrackingSettings = true;
Jorim Jaggiecbab362014-04-23 16:13:15 +0200118 requestDisallowInterceptTouchEvent(true);
John Spurlock73203eb2014-04-15 16:14:46 -0400119 return true;
120 }
121 if (!inTarget && isInSettings()) {
122 mTrackingSettings = true;
Jorim Jaggiecbab362014-04-23 16:13:15 +0200123 requestDisallowInterceptTouchEvent(true);
John Spurlock73203eb2014-04-15 16:14:46 -0400124 return true;
125 }
126 }
127 return super.onInterceptTouchEvent(event);
128 }
129
130 @Override
Daniel Sandler040c2e42012-10-17 00:56:33 -0400131 public boolean onTouchEvent(MotionEvent event) {
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100132 // TODO: Handle doublefinger swipe to notifications again. Look at history for a reference
133 // implementation.
John Spurlock73203eb2014-04-15 16:14:46 -0400134 if (mTrackingSettings) {
135 mStatusBar.onSettingsEvent(event);
136 if (event.getAction() == MotionEvent.ACTION_UP
137 || event.getAction() == MotionEvent.ACTION_CANCEL) {
138 mTrackingSettings = false;
139 }
140 return true;
141 }
142 if (isInSettings()) {
143 return true;
144 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100145 return super.onTouchEvent(event);
146 }
147
148 @Override
149 protected boolean isScrolledToBottom() {
150 if (!isInSettings()) {
151 return mNotificationStackScroller.isScrolledToBottom();
Chris Wren64161cc2012-12-17 16:49:30 -0500152 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100153 return super.isScrolledToBottom();
154 }
155
156 @Override
157 protected int getMaxPanelHeight() {
158 if (!isInSettings()) {
159 int maxPanelHeight = super.getMaxPanelHeight();
160 int emptyBottomMargin = mNotificationStackScroller.getEmptyBottomMargin();
161 return maxPanelHeight - emptyBottomMargin;
Daniel Sandler040c2e42012-10-17 00:56:33 -0400162 }
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100163 return super.getMaxPanelHeight();
164 }
165
166 private boolean isInSettings() {
167 return mStatusBar != null && mStatusBar.isFlippedToSettings();
168 }
169
170 @Override
171 protected void onHeightUpdated(float expandedHeight) {
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200172 mNotificationStackScroller.setStackHeight(expandedHeight);
Selim Cinekb6d85eb2014-03-28 20:21:01 +0100173 }
174
175 @Override
176 protected int getDesiredMeasureHeight() {
177 return mMaxPanelHeight;
Daniel Sandler040c2e42012-10-17 00:56:33 -0400178 }
Selim Cinek1685e632014-04-08 02:27:49 +0200179
180 @Override
181 protected void onExpandingStarted() {
182 super.onExpandingStarted();
183 mNotificationStackScroller.onExpansionStarted();
184 }
185
186 @Override
187 protected void onExpandingFinished() {
188 super.onExpandingFinished();
189 mNotificationStackScroller.onExpansionStopped();
190 }
Jorim Jaggibe565df2014-04-28 17:51:23 +0200191
192 @Override
193 public void onHeightChanged(ExpandableView view) {
194 requestPanelHeightUpdate();
195 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400196}