blob: 87fc6fce8d3953f15e0c1b777d79e8cbb318bb07 [file] [log] [blame]
Joe Onoratoddf680b2010-09-26 13:59:40 -07001/*
2 * Copyright (C) 2010 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.tablet;
18
Joe Onorato7c270fa2010-12-08 17:31:42 -080019import android.animation.Animator;
Daniel Sandler14db0bc2011-01-20 12:11:23 -050020import android.animation.AnimatorListenerAdapter;
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -050021import android.animation.AnimatorSet;
Joe Onorato7c270fa2010-12-08 17:31:42 -080022import android.animation.ObjectAnimator;
Joe Onoratoddf680b2010-09-26 13:59:40 -070023import android.content.Context;
Joe Onorato7c270fa2010-12-08 17:31:42 -080024import android.graphics.Rect;
Joe Onoratoddf680b2010-09-26 13:59:40 -070025import android.util.AttributeSet;
Joe Onorato8a576712010-11-15 16:50:34 -080026import android.util.Slog;
Chris Wren9b2cd152012-06-11 10:39:36 -040027import android.view.Gravity;
Svetoslav Ganov73b9c292012-07-30 16:13:46 -070028import android.view.KeyEvent;
Joe Onoratocf2b1992010-11-16 21:36:42 -080029import android.view.LayoutInflater;
Daniel Sandler8f491b52011-03-03 00:00:22 -050030import android.view.MotionEvent;
Joe Onorato8a576712010-11-15 16:50:34 -080031import android.view.View;
Joe Onorato7c270fa2010-12-08 17:31:42 -080032import android.view.ViewGroup;
Chet Haase41bff382011-08-29 16:00:23 -070033import android.view.ViewTreeObserver;
34import android.view.animation.AccelerateInterpolator;
35import android.view.animation.DecelerateInterpolator;
36import android.view.animation.Interpolator;
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -070037import android.widget.ImageView;
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -050038import android.widget.RelativeLayout;
Joe Onoratoddf680b2010-09-26 13:59:40 -070039
Chris Wren1e8f65d2012-06-06 18:08:56 -040040import com.android.systemui.ExpandHelper;
Joe Onoratofd52b182010-11-10 18:00:52 -080041import com.android.systemui.R;
Chris Wren1e8f65d2012-06-06 18:08:56 -040042import com.android.systemui.statusbar.policy.NotificationRowLayout;
Joe Onoratoddf680b2010-09-26 13:59:40 -070043
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -050044public class NotificationPanel extends RelativeLayout implements StatusBarPanel,
Joe Onorato8a576712010-11-15 16:50:34 -080045 View.OnClickListener {
Chris Wren1e8f65d2012-06-06 18:08:56 -040046 private ExpandHelper mExpandHelper;
47 private NotificationRowLayout latestItems;
48
Daniel Sandleref6e9362010-12-17 14:50:03 -050049 static final String TAG = "Tablet/NotificationPanel";
50 static final boolean DEBUG = false;
Joe Onorato8a576712010-11-15 16:50:34 -080051
Daniel Sandler40c15452011-01-22 01:26:22 -050052 final static int PANEL_FADE_DURATION = 150;
53
Joe Onorato7c270fa2010-12-08 17:31:42 -080054 boolean mShowing;
Daniel Sandler06a0d4b2011-08-05 00:19:21 -040055 boolean mHasClearableNotifications = false;
Daniel Sandler40c15452011-01-22 01:26:22 -050056 int mNotificationCount = 0;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070057 NotificationPanelTitle mTitleArea;
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -070058 ImageView mSettingsButton;
59 ImageView mNotificationButton;
Joe Onorato8a576712010-11-15 16:50:34 -080060 View mNotificationScroller;
Joe Onorato7c270fa2010-12-08 17:31:42 -080061 ViewGroup mContentFrame;
Joe Onorato6223fba2011-01-18 18:00:30 -080062 Rect mContentArea = new Rect();
Joe Onorato755cc742010-11-27 15:45:35 -080063 View mSettingsView;
Joe Onorato7c270fa2010-12-08 17:31:42 -080064 ViewGroup mContentParent;
Daniel Sandler1347c302011-08-01 16:47:53 -040065 TabletStatusBar mBar;
Daniel Sandler06a0d4b2011-08-05 00:19:21 -040066 View mClearButton;
Chet Haase41bff382011-08-29 16:00:23 -070067 static Interpolator sAccelerateInterpolator = new AccelerateInterpolator();
68 static Interpolator sDecelerateInterpolator = new DecelerateInterpolator();
Joe Onorato7c270fa2010-12-08 17:31:42 -080069
Daniel Sandler641a4992011-01-26 21:19:10 -050070 // amount to slide mContentParent down by when mContentFrame is missing
71 float mContentFrameMissingTranslation;
72
Joe Onorato7c270fa2010-12-08 17:31:42 -080073 Choreographer mChoreo = new Choreographer();
Joe Onorato8a576712010-11-15 16:50:34 -080074
Joe Onoratoddf680b2010-09-26 13:59:40 -070075 public NotificationPanel(Context context, AttributeSet attrs) {
76 this(context, attrs, 0);
77 }
78
79 public NotificationPanel(Context context, AttributeSet attrs, int defStyle) {
80 super(context, attrs, defStyle);
81 }
82
Daniel Sandler1347c302011-08-01 16:47:53 -040083 public void setBar(TabletStatusBar b) {
84 mBar = b;
85 }
86
Joe Onorato8a576712010-11-15 16:50:34 -080087 @Override
88 public void onFinishInflate() {
89 super.onFinishInflate();
90
Joe Onorato7c270fa2010-12-08 17:31:42 -080091 setWillNotDraw(false);
92
93 mContentParent = (ViewGroup)findViewById(R.id.content_parent);
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -050094 mContentParent.bringToFront();
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070095 mTitleArea = (NotificationPanelTitle) findViewById(R.id.title_area);
96 mTitleArea.setPanel(this);
Joe Onoratocf2b1992010-11-16 21:36:42 -080097
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -070098 mSettingsButton = (ImageView) findViewById(R.id.settings_button);
99 mNotificationButton = (ImageView) findViewById(R.id.notification_button);
Joe Onorato8a576712010-11-15 16:50:34 -0800100
Joe Onorato244e4152010-12-16 13:22:34 -0800101 mNotificationScroller = findViewById(R.id.notification_scroller);
Joe Onorato7c270fa2010-12-08 17:31:42 -0800102 mContentFrame = (ViewGroup)findViewById(R.id.content_frame);
Daniel Sandler06a0d4b2011-08-05 00:19:21 -0400103 mContentFrameMissingTranslation = 0; // not needed with current assets
104
105 // the "X" that appears in place of the clock when the panel is showing notifications
106 mClearButton = findViewById(R.id.clear_all_button);
107 mClearButton.setOnClickListener(mClearButtonListener);
Daniel Sandler641a4992011-01-26 21:19:10 -0500108
109 mShowing = false;
Joe Onorato7c270fa2010-12-08 17:31:42 -0800110 }
111
Chris Wren1e8f65d2012-06-06 18:08:56 -0400112 @Override
113 protected void onAttachedToWindow () {
114 super.onAttachedToWindow();
115 latestItems = (NotificationRowLayout) findViewById(R.id.content);
116 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height);
117 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height);
118 mExpandHelper = new ExpandHelper(mContext, latestItems, minHeight, maxHeight);
119 mExpandHelper.setEventSource(this);
Chris Wren9b2cd152012-06-11 10:39:36 -0400120 mExpandHelper.setGravity(Gravity.BOTTOM);
Chris Wren1e8f65d2012-06-06 18:08:56 -0400121 }
122
Daniel Sandler06a0d4b2011-08-05 00:19:21 -0400123 private View.OnClickListener mClearButtonListener = new View.OnClickListener() {
124 public void onClick(View v) {
125 mBar.clearAll();
126 }
127 };
128
129 public View getClearButton() {
130 return mClearButton;
131 }
132
Joe Onorato7c270fa2010-12-08 17:31:42 -0800133 public void show(boolean show, boolean animate) {
134 if (animate) {
135 if (mShowing != show) {
136 mShowing = show;
137 if (show) {
138 setVisibility(View.VISIBLE);
Chet Haase41bff382011-08-29 16:00:23 -0700139 // Don't start the animation until we've created the layer, which is done
140 // right before we are drawn
141 mContentParent.setLayerType(View.LAYER_TYPE_HARDWARE, null);
142 getViewTreeObserver().addOnPreDrawListener(mPreDrawListener);
143 } else {
144 mChoreo.startAnimation(show);
Joe Onorato7c270fa2010-12-08 17:31:42 -0800145 }
Joe Onorato7c270fa2010-12-08 17:31:42 -0800146 }
147 } else {
148 mShowing = show;
149 setVisibility(show ? View.VISIBLE : View.GONE);
Joe Onorato7c270fa2010-12-08 17:31:42 -0800150 }
151 }
152
153 /**
Chet Haase41bff382011-08-29 16:00:23 -0700154 * This is used only when we've created a hardware layer and are waiting until it's
155 * been created in order to start the appearing animation.
156 */
157 private ViewTreeObserver.OnPreDrawListener mPreDrawListener =
158 new ViewTreeObserver.OnPreDrawListener() {
159 @Override
160 public boolean onPreDraw() {
161 getViewTreeObserver().removeOnPreDrawListener(this);
162 mChoreo.startAnimation(true);
Chet Haase3c4ce722011-09-02 15:37:25 -0700163 return false;
Chet Haase41bff382011-08-29 16:00:23 -0700164 }
165 };
166
167 /**
Joe Onorato7c270fa2010-12-08 17:31:42 -0800168 * Whether the panel is showing, or, if it's animating, whether it will be
169 * when the animation is done.
170 */
171 public boolean isShowing() {
172 return mShowing;
Joe Onorato8a576712010-11-15 16:50:34 -0800173 }
174
175 @Override
176 public void onVisibilityChanged(View v, int vis) {
177 super.onVisibilityChanged(v, vis);
178 // when we hide, put back the notifications
Daniel Sandler641a4992011-01-26 21:19:10 -0500179 if (vis != View.VISIBLE) {
Daniel Sandler14db0bc2011-01-20 12:11:23 -0500180 if (mSettingsView != null) removeSettingsView();
181 mNotificationScroller.setVisibility(View.VISIBLE);
182 mNotificationScroller.setAlpha(1f);
Joe Onorato43861912010-11-27 16:08:58 -0800183 mNotificationScroller.scrollTo(0, 0);
Daniel Sandler14db0bc2011-01-20 12:11:23 -0500184 updatePanelModeButtons();
Joe Onorato8a576712010-11-15 16:50:34 -0800185 }
186 }
187
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700188 @Override
189 public boolean dispatchHoverEvent(MotionEvent event) {
190 // Ignore hover events outside of this panel bounds since such events
191 // generate spurious accessibility events with the panel content when
192 // tapping outside of it, thus confusing the user.
193 final int x = (int) event.getX();
194 final int y = (int) event.getY();
195 if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
196 return super.dispatchHoverEvent(event);
197 }
198 return true;
199 }
200
Svetoslav Ganov73b9c292012-07-30 16:13:46 -0700201 @Override
202 public boolean dispatchKeyEvent(KeyEvent event) {
203 final int keyCode = event.getKeyCode();
204 switch (keyCode) {
205 // We exclusively handle the back key by hiding this panel.
206 case KeyEvent.KEYCODE_BACK: {
207 if (event.getAction() == KeyEvent.ACTION_UP) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400208 mBar.animateCollapsePanels();
Svetoslav Ganov73b9c292012-07-30 16:13:46 -0700209 }
210 return true;
211 }
212 // We react to the home key but let the system handle it.
213 case KeyEvent.KEYCODE_HOME: {
214 if (event.getAction() == KeyEvent.ACTION_UP) {
Daniel Sandler11cf1782012-09-27 14:03:08 -0400215 mBar.animateCollapsePanels();
Svetoslav Ganov73b9c292012-07-30 16:13:46 -0700216 }
217 } break;
218 }
219 return super.dispatchKeyEvent(event);
220 }
221
Daniel Sandler14db0bc2011-01-20 12:11:23 -0500222 /*
Joe Onorato4cddc982010-11-21 11:48:15 -0800223 @Override
224 protected void onLayout(boolean changed, int l, int t, int r, int b) {
225 super.onLayout(changed, l, t, r, b);
Daniel Sandler2f447aa2011-01-14 16:39:19 -0500226
Daniel Sandler14db0bc2011-01-20 12:11:23 -0500227 if (DEBUG) Slog.d(TAG, String.format("PANEL: onLayout: (%d, %d, %d, %d)", l, t, r, b));
Joe Onorato7c270fa2010-12-08 17:31:42 -0800228 }
229
230 @Override
231 public void onSizeChanged(int w, int h, int oldw, int oldh) {
232 super.onSizeChanged(w, h, oldw, oldh);
Daniel Sandler14db0bc2011-01-20 12:11:23 -0500233
234 if (DEBUG) {
235 Slog.d(TAG, String.format("PANEL: onSizeChanged: (%d -> %d, %d -> %d)",
236 oldw, w, oldh, h));
237 }
Joe Onorato4cddc982010-11-21 11:48:15 -0800238 }
Daniel Sandler14db0bc2011-01-20 12:11:23 -0500239 */
Joe Onorato4cddc982010-11-21 11:48:15 -0800240
Joe Onorato8a576712010-11-15 16:50:34 -0800241 public void onClick(View v) {
John Spurlock36231282012-06-23 17:11:27 -0400242 if (mSettingsButton.isEnabled() && v == mTitleArea) {
Daniel Sandler14db0bc2011-01-20 12:11:23 -0500243 swapPanels();
Joe Onorato8a576712010-11-15 16:50:34 -0800244 }
245 }
246
Daniel Sandler40c15452011-01-22 01:26:22 -0500247 public void setNotificationCount(int n) {
Daniel Sandler40c15452011-01-22 01:26:22 -0500248 mNotificationCount = n;
249 }
250
251 public void setContentFrameVisible(final boolean showing, boolean animate) {
Daniel Sandler40c15452011-01-22 01:26:22 -0500252 }
Joe Onorato8a576712010-11-15 16:50:34 -0800253
Daniel Sandler14db0bc2011-01-20 12:11:23 -0500254 public void swapPanels() {
255 final View toShow, toHide;
256 if (mSettingsView == null) {
257 addSettingsView();
258 toShow = mSettingsView;
259 toHide = mNotificationScroller;
260 } else {
261 toShow = mNotificationScroller;
262 toHide = mSettingsView;
263 }
264 Animator a = ObjectAnimator.ofFloat(toHide, "alpha", 1f, 0f)
265 .setDuration(PANEL_FADE_DURATION);
266 a.addListener(new AnimatorListenerAdapter() {
267 @Override
268 public void onAnimationEnd(Animator _a) {
269 toHide.setVisibility(View.GONE);
Daniel Sandler40c15452011-01-22 01:26:22 -0500270 if (toShow != null) {
Daniel Sandler40c15452011-01-22 01:26:22 -0500271 toShow.setVisibility(View.VISIBLE);
272 if (toShow == mSettingsView || mNotificationCount > 0) {
273 ObjectAnimator.ofFloat(toShow, "alpha", 0f, 1f)
274 .setDuration(PANEL_FADE_DURATION)
275 .start();
276 }
277
278 if (toHide == mSettingsView) {
279 removeSettingsView();
280 }
Daniel Sandler14db0bc2011-01-20 12:11:23 -0500281 }
Daniel Sandler1347c302011-08-01 16:47:53 -0400282 updateClearButton();
Daniel Sandler14db0bc2011-01-20 12:11:23 -0500283 updatePanelModeButtons();
284 }
285 });
286 a.start();
287 }
288
Daniel Sandler1347c302011-08-01 16:47:53 -0400289 public void updateClearButton() {
290 if (mBar != null) {
291 final boolean showX
292 = (isShowing()
Daniel Sandler06a0d4b2011-08-05 00:19:21 -0400293 && mHasClearableNotifications
294 && mNotificationScroller.getVisibility() == View.VISIBLE);
295 getClearButton().setVisibility(showX ? View.VISIBLE : View.INVISIBLE);
Daniel Sandler1347c302011-08-01 16:47:53 -0400296 }
297 }
298
Daniel Sandler06a0d4b2011-08-05 00:19:21 -0400299 public void setClearable(boolean clearable) {
300 mHasClearableNotifications = clearable;
301 }
302
Daniel Sandler14db0bc2011-01-20 12:11:23 -0500303 public void updatePanelModeButtons() {
304 final boolean settingsVisible = (mSettingsView != null);
John Spurlock36231282012-06-23 17:11:27 -0400305 mSettingsButton.setVisibility(!settingsVisible && mSettingsButton.isEnabled() ? View.VISIBLE : View.GONE);
Daniel Sandler5962fd52012-01-11 14:57:04 -0500306 mNotificationButton.setVisibility(settingsVisible ? View.VISIBLE : View.GONE);
Joe Onorato8a576712010-11-15 16:50:34 -0800307 }
308
Joe Onoratoddf680b2010-09-26 13:59:40 -0700309 public boolean isInContentArea(int x, int y) {
Chris Wren1e8f65d2012-06-06 18:08:56 -0400310 mContentArea.left = mContentFrame.getLeft() + mContentFrame.getPaddingLeft();
311 mContentArea.top = mContentFrame.getTop() + mContentFrame.getPaddingTop()
Daniel Sandler641a4992011-01-26 21:19:10 -0500312 + (int)mContentParent.getTranslationY(); // account for any adjustment
Chris Wren1e8f65d2012-06-06 18:08:56 -0400313 mContentArea.right = mContentFrame.getRight() - mContentFrame.getPaddingRight();
314 mContentArea.bottom = mContentFrame.getBottom() - mContentFrame.getPaddingBottom();
Daniel Sandler641a4992011-01-26 21:19:10 -0500315
Joe Onorato6223fba2011-01-18 18:00:30 -0800316 offsetDescendantRectToMyCoords(mContentParent, mContentArea);
Joe Onorato7c270fa2010-12-08 17:31:42 -0800317 return mContentArea.contains(x, y);
Joe Onoratoddf680b2010-09-26 13:59:40 -0700318 }
Joe Onorato8a576712010-11-15 16:50:34 -0800319
Joe Onorato755cc742010-11-27 15:45:35 -0800320 void removeSettingsView() {
321 if (mSettingsView != null) {
322 mContentFrame.removeView(mSettingsView);
323 mSettingsView = null;
Joe Onorato8a576712010-11-15 16:50:34 -0800324 }
325 }
326
Daniel Sandler14db0bc2011-01-20 12:11:23 -0500327 // NB: it will be invisible until you show it
Joe Onorato755cc742010-11-27 15:45:35 -0800328 void addSettingsView() {
Joe Onoratocf2b1992010-11-16 21:36:42 -0800329 LayoutInflater infl = LayoutInflater.from(getContext());
Daniel Sandler4a066c52012-04-20 14:49:13 -0400330 mSettingsView = infl.inflate(R.layout.system_bar_settings_view, mContentFrame, false);
Daniel Sandler14db0bc2011-01-20 12:11:23 -0500331 mSettingsView.setVisibility(View.GONE);
Daniel Sandler2f447aa2011-01-14 16:39:19 -0500332 mContentFrame.addView(mSettingsView);
Joe Onorato8a576712010-11-15 16:50:34 -0800333 }
Joe Onorato7c270fa2010-12-08 17:31:42 -0800334
335 private class Choreographer implements Animator.AnimatorListener {
Joe Onorato244e4152010-12-16 13:22:34 -0800336 boolean mVisible;
Joe Onorato7c270fa2010-12-08 17:31:42 -0800337 int mPanelHeight;
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500338 AnimatorSet mContentAnim;
Joe Onorato7c270fa2010-12-08 17:31:42 -0800339
340 // should group this into a multi-property animation
Chet Haase41bff382011-08-29 16:00:23 -0700341 final static int OPEN_DURATION = 250;
342 final static int CLOSE_DURATION = 250;
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500343
344 // the panel will start to appear this many px from the end
Daniel Sandler1347c302011-08-01 16:47:53 -0400345 final int HYPERSPACE_OFFRAMP = 200;
Joe Onorato7c270fa2010-12-08 17:31:42 -0800346
347 Choreographer() {
348 }
349
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500350 void createAnimation(boolean appearing) {
Daniel Sandleradd26202011-01-20 02:53:43 -0500351 // mVisible: previous state; appearing: new state
352
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500353 float start, end;
Joe Onorato7c270fa2010-12-08 17:31:42 -0800354
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500355 // 0: on-screen
356 // height: off-screen
357 float y = mContentParent.getTranslationY();
358 if (appearing) {
359 // we want to go from near-the-top to the top, unless we're half-open in the right
360 // general vicinity
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500361 end = 0;
Daniel Sandler641a4992011-01-26 21:19:10 -0500362 if (mNotificationCount == 0) {
363 end += mContentFrameMissingTranslation;
364 }
Daniel Sandler8c989182011-01-30 01:24:09 -0500365 start = HYPERSPACE_OFFRAMP+end;
Joe Onorato7c270fa2010-12-08 17:31:42 -0800366 } else {
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500367 start = y;
368 end = y + HYPERSPACE_OFFRAMP;
Joe Onorato7c270fa2010-12-08 17:31:42 -0800369 }
Daniel Sandler641a4992011-01-26 21:19:10 -0500370
Daniel Sandleradd26202011-01-20 02:53:43 -0500371 Animator posAnim = ObjectAnimator.ofFloat(mContentParent, "translationY",
372 start, end);
Chet Haase41bff382011-08-29 16:00:23 -0700373 posAnim.setInterpolator(appearing ? sDecelerateInterpolator : sAccelerateInterpolator);
Joe Onorato7c270fa2010-12-08 17:31:42 -0800374
Daniel Sandlerf844dc42011-01-24 23:44:47 -0500375 if (mContentAnim != null && mContentAnim.isRunning()) {
376 mContentAnim.cancel();
377 }
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500378
Daniel Sandler8c989182011-01-30 01:24:09 -0500379 Animator fadeAnim = ObjectAnimator.ofFloat(mContentParent, "alpha",
Chet Haase41bff382011-08-29 16:00:23 -0700380 appearing ? 1.0f : 0.0f);
381 fadeAnim.setInterpolator(appearing ? sAccelerateInterpolator : sDecelerateInterpolator);
Daniel Sandler8c989182011-01-30 01:24:09 -0500382
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500383 mContentAnim = new AnimatorSet();
384 mContentAnim
Daniel Sandler8c989182011-01-30 01:24:09 -0500385 .play(fadeAnim)
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500386 .with(posAnim)
387 ;
Daniel Sandleradd26202011-01-20 02:53:43 -0500388 mContentAnim.setDuration((DEBUG?10:1)*(appearing ? OPEN_DURATION : CLOSE_DURATION));
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500389 mContentAnim.addListener(this);
390 }
391
392 void startAnimation(boolean appearing) {
393 if (DEBUG) Slog.d(TAG, "startAnimation(appearing=" + appearing + ")");
394
395 createAnimation(appearing);
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500396 mContentAnim.start();
397
398 mVisible = appearing;
Daniel Sandler1347c302011-08-01 16:47:53 -0400399
400 // we want to start disappearing promptly
401 if (!mVisible) updateClearButton();
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500402 }
403
Joe Onorato7c270fa2010-12-08 17:31:42 -0800404 public void onAnimationCancel(Animator animation) {
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500405 if (DEBUG) Slog.d(TAG, "onAnimationCancel");
Joe Onorato7c270fa2010-12-08 17:31:42 -0800406 }
407
408 public void onAnimationEnd(Animator animation) {
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500409 if (DEBUG) Slog.d(TAG, "onAnimationEnd");
410 if (! mVisible) {
Joe Onorato7c270fa2010-12-08 17:31:42 -0800411 setVisibility(View.GONE);
412 }
Daniel Sandler7d9ea8c2011-01-11 10:28:58 -0500413 mContentParent.setLayerType(View.LAYER_TYPE_NONE, null);
414 mContentAnim = null;
Daniel Sandler1347c302011-08-01 16:47:53 -0400415
416 // we want to show the X lazily
417 if (mVisible) updateClearButton();
Joe Onorato7c270fa2010-12-08 17:31:42 -0800418 }
419
420 public void onAnimationRepeat(Animator animation) {
421 }
422
423 public void onAnimationStart(Animator animation) {
424 }
425 }
Chris Wren1e8f65d2012-06-06 18:08:56 -0400426
427 @Override
428 public boolean onInterceptTouchEvent(MotionEvent ev) {
429 MotionEvent cancellation = MotionEvent.obtain(ev);
430 cancellation.setAction(MotionEvent.ACTION_CANCEL);
431
432 boolean intercept = mExpandHelper.onInterceptTouchEvent(ev) ||
433 super.onInterceptTouchEvent(ev);
434 if (intercept) {
435 latestItems.onInterceptTouchEvent(cancellation);
436 }
437 return intercept;
438 }
439
440 @Override
441 public boolean onTouchEvent(MotionEvent ev) {
442 boolean handled = mExpandHelper.onTouchEvent(ev) ||
443 super.onTouchEvent(ev);
444 return handled;
445 }
John Spurlock36231282012-06-23 17:11:27 -0400446
447 public void setSettingsEnabled(boolean settingsEnabled) {
448 if (mSettingsButton != null) {
449 mSettingsButton.setEnabled(settingsEnabled);
450 mSettingsButton.setVisibility(settingsEnabled ? View.VISIBLE : View.GONE);
451 }
452 }
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700453
454 public void refreshLayout(int layoutDirection) {
455 // Force asset reloading
456 mSettingsButton.setImageDrawable(null);
457 mSettingsButton.setImageResource(R.drawable.ic_notify_settings);
458
459 // Force asset reloading
460 mNotificationButton.setImageDrawable(null);
461 mNotificationButton.setImageResource(R.drawable.ic_notifications);
462 }
Joe Onoratoddf680b2010-09-26 13:59:40 -0700463}
464