Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.tablet; |
| 18 | |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 19 | import android.animation.Animator; |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 20 | import android.animation.AnimatorListenerAdapter; |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 21 | import android.animation.AnimatorSet; |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 22 | import android.animation.ObjectAnimator; |
| 23 | import android.animation.ValueAnimator; |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 24 | import android.content.Context; |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 25 | import android.content.res.Resources; |
| 26 | import android.graphics.Canvas; |
| 27 | import android.graphics.Rect; |
| 28 | import android.graphics.drawable.Drawable; |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 29 | import android.util.AttributeSet; |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 30 | import android.util.Slog; |
Joe Onorato | cf2b199 | 2010-11-16 21:36:42 -0800 | [diff] [blame] | 31 | import android.view.LayoutInflater; |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 32 | import android.view.View; |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 33 | import android.view.ViewGroup; |
| 34 | import android.view.animation.AccelerateInterpolator; |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 35 | import android.widget.FrameLayout; |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 36 | import android.widget.FrameLayout; |
Joe Onorato | 4cddc98 | 2010-11-21 11:48:15 -0800 | [diff] [blame] | 37 | import android.widget.ImageView; |
| 38 | import android.widget.LinearLayout; |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 39 | import android.widget.RelativeLayout; |
Joe Onorato | 4cddc98 | 2010-11-21 11:48:15 -0800 | [diff] [blame] | 40 | import android.widget.TextView; |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 41 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 42 | import com.android.systemui.R; |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 43 | |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 44 | public class NotificationPanel extends RelativeLayout implements StatusBarPanel, |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 45 | View.OnClickListener { |
Daniel Sandler | ef6e936 | 2010-12-17 14:50:03 -0500 | [diff] [blame] | 46 | static final String TAG = "Tablet/NotificationPanel"; |
| 47 | static final boolean DEBUG = false; |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 48 | |
Daniel Sandler | 40c1545 | 2011-01-22 01:26:22 -0500 | [diff] [blame] | 49 | final static int PANEL_FADE_DURATION = 150; |
| 50 | |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 51 | boolean mShowing; |
Daniel Sandler | 40c1545 | 2011-01-22 01:26:22 -0500 | [diff] [blame] | 52 | int mNotificationCount = 0; |
Joe Onorato | cf2b199 | 2010-11-16 21:36:42 -0800 | [diff] [blame] | 53 | View mTitleArea; |
Daniel Sandler | bc5d9bb | 2011-01-20 00:13:11 -0500 | [diff] [blame] | 54 | View mModeToggle; |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 55 | View mSettingsButton; |
| 56 | View mNotificationButton; |
| 57 | View mNotificationScroller; |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 58 | ViewGroup mContentFrame; |
Joe Onorato | 6223fba | 2011-01-18 18:00:30 -0800 | [diff] [blame] | 59 | Rect mContentArea = new Rect(); |
Joe Onorato | 755cc74 | 2010-11-27 15:45:35 -0800 | [diff] [blame] | 60 | View mSettingsView; |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 61 | ViewGroup mContentParent; |
| 62 | |
Daniel Sandler | 641a499 | 2011-01-26 21:19:10 -0500 | [diff] [blame] | 63 | // amount to slide mContentParent down by when mContentFrame is missing |
| 64 | float mContentFrameMissingTranslation; |
| 65 | |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 66 | Choreographer mChoreo = new Choreographer(); |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 67 | |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 68 | public NotificationPanel(Context context, AttributeSet attrs) { |
| 69 | this(context, attrs, 0); |
| 70 | } |
| 71 | |
| 72 | public NotificationPanel(Context context, AttributeSet attrs, int defStyle) { |
| 73 | super(context, attrs, defStyle); |
| 74 | } |
| 75 | |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 76 | @Override |
| 77 | public void onFinishInflate() { |
| 78 | super.onFinishInflate(); |
| 79 | |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 80 | setWillNotDraw(false); |
| 81 | |
| 82 | mContentParent = (ViewGroup)findViewById(R.id.content_parent); |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 83 | mContentParent.bringToFront(); |
Joe Onorato | cf2b199 | 2010-11-16 21:36:42 -0800 | [diff] [blame] | 84 | mTitleArea = findViewById(R.id.title_area); |
Daniel Sandler | bc5d9bb | 2011-01-20 00:13:11 -0500 | [diff] [blame] | 85 | mModeToggle = findViewById(R.id.mode_toggle); |
| 86 | mModeToggle.setOnClickListener(this); |
Joe Onorato | cf2b199 | 2010-11-16 21:36:42 -0800 | [diff] [blame] | 87 | |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 88 | mSettingsButton = (ImageView)findViewById(R.id.settings_button); |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 89 | mNotificationButton = (ImageView)findViewById(R.id.notification_button); |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 90 | |
Joe Onorato | 244e415 | 2010-12-16 13:22:34 -0800 | [diff] [blame] | 91 | mNotificationScroller = findViewById(R.id.notification_scroller); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 92 | mContentFrame = (ViewGroup)findViewById(R.id.content_frame); |
Daniel Sandler | 641a499 | 2011-01-26 21:19:10 -0500 | [diff] [blame] | 93 | mContentFrameMissingTranslation = |
| 94 | mContentFrame.getBackground().getMinimumHeight() + 10; |
| 95 | |
| 96 | mShowing = false; |
| 97 | |
| 98 | setContentFrameVisible(mNotificationCount > 0, false); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | public void show(boolean show, boolean animate) { |
Daniel Sandler | 40c1545 | 2011-01-22 01:26:22 -0500 | [diff] [blame] | 102 | if (show && !mShowing) { |
Daniel Sandler | 641a499 | 2011-01-26 21:19:10 -0500 | [diff] [blame] | 103 | setContentFrameVisible(mSettingsView != null || mNotificationCount > 0, false); |
Daniel Sandler | 40c1545 | 2011-01-22 01:26:22 -0500 | [diff] [blame] | 104 | } |
| 105 | |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 106 | if (animate) { |
| 107 | if (mShowing != show) { |
| 108 | mShowing = show; |
| 109 | if (show) { |
| 110 | setVisibility(View.VISIBLE); |
| 111 | } |
| 112 | mChoreo.startAnimation(show); |
| 113 | } |
| 114 | } else { |
| 115 | mShowing = show; |
| 116 | setVisibility(show ? View.VISIBLE : View.GONE); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Whether the panel is showing, or, if it's animating, whether it will be |
| 122 | * when the animation is done. |
| 123 | */ |
| 124 | public boolean isShowing() { |
| 125 | return mShowing; |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public void onVisibilityChanged(View v, int vis) { |
| 130 | super.onVisibilityChanged(v, vis); |
| 131 | // when we hide, put back the notifications |
Daniel Sandler | 641a499 | 2011-01-26 21:19:10 -0500 | [diff] [blame] | 132 | if (vis != View.VISIBLE) { |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 133 | if (mSettingsView != null) removeSettingsView(); |
| 134 | mNotificationScroller.setVisibility(View.VISIBLE); |
| 135 | mNotificationScroller.setAlpha(1f); |
Joe Onorato | 4386191 | 2010-11-27 16:08:58 -0800 | [diff] [blame] | 136 | mNotificationScroller.scrollTo(0, 0); |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 137 | updatePanelModeButtons(); |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 141 | /* |
Joe Onorato | 4cddc98 | 2010-11-21 11:48:15 -0800 | [diff] [blame] | 142 | @Override |
| 143 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 144 | super.onLayout(changed, l, t, r, b); |
Daniel Sandler | 2f447aa | 2011-01-14 16:39:19 -0500 | [diff] [blame] | 145 | |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 146 | if (DEBUG) Slog.d(TAG, String.format("PANEL: onLayout: (%d, %d, %d, %d)", l, t, r, b)); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 151 | super.onSizeChanged(w, h, oldw, oldh); |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 152 | |
| 153 | if (DEBUG) { |
| 154 | Slog.d(TAG, String.format("PANEL: onSizeChanged: (%d -> %d, %d -> %d)", |
| 155 | oldw, w, oldh, h)); |
| 156 | } |
Joe Onorato | 4cddc98 | 2010-11-21 11:48:15 -0800 | [diff] [blame] | 157 | } |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 158 | */ |
Joe Onorato | 4cddc98 | 2010-11-21 11:48:15 -0800 | [diff] [blame] | 159 | |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 160 | public void onClick(View v) { |
Daniel Sandler | bc5d9bb | 2011-01-20 00:13:11 -0500 | [diff] [blame] | 161 | if (v == mModeToggle) { |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 162 | swapPanels(); |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
Daniel Sandler | 40c1545 | 2011-01-22 01:26:22 -0500 | [diff] [blame] | 166 | public void setNotificationCount(int n) { |
| 167 | Slog.d(TAG, "notificationCount=" + n); |
| 168 | if (!mShowing) { |
| 169 | // just do it, already |
| 170 | setContentFrameVisible(n > 0, false); |
| 171 | } else if (mSettingsView == null) { |
| 172 | // we're looking at the notifications; time to maybe make some changes |
Daniel Sandler | 641a499 | 2011-01-26 21:19:10 -0500 | [diff] [blame] | 173 | if (mNotificationCount != n) { |
| 174 | setContentFrameVisible(n > 0, true); |
Daniel Sandler | 40c1545 | 2011-01-22 01:26:22 -0500 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | mNotificationCount = n; |
| 178 | } |
| 179 | |
| 180 | public void setContentFrameVisible(final boolean showing, boolean animate) { |
| 181 | if (!animate) { |
| 182 | mContentFrame.setVisibility(showing ? View.VISIBLE : View.GONE); |
Daniel Sandler | 641a499 | 2011-01-26 21:19:10 -0500 | [diff] [blame] | 183 | mContentFrame.setAlpha(1f); |
| 184 | // the translation will be patched up when the window is slid into place |
Daniel Sandler | 40c1545 | 2011-01-22 01:26:22 -0500 | [diff] [blame] | 185 | return; |
| 186 | } |
| 187 | |
Daniel Sandler | 641a499 | 2011-01-26 21:19:10 -0500 | [diff] [blame] | 188 | if (showing) { |
| 189 | mContentFrame.setVisibility(View.VISIBLE); |
| 190 | } |
Daniel Sandler | 40c1545 | 2011-01-22 01:26:22 -0500 | [diff] [blame] | 191 | AnimatorSet set = new AnimatorSet(); |
Daniel Sandler | 40c1545 | 2011-01-22 01:26:22 -0500 | [diff] [blame] | 192 | set.play(ObjectAnimator.ofFloat( |
| 193 | mContentFrame, "alpha", |
| 194 | showing ? 0f : 1f, |
| 195 | showing ? 1f : 0f)) |
| 196 | .with(ObjectAnimator.ofFloat( |
| 197 | mContentParent, "translationY", |
Daniel Sandler | 641a499 | 2011-01-26 21:19:10 -0500 | [diff] [blame] | 198 | showing ? mContentFrameMissingTranslation : 0f, |
| 199 | showing ? 0f : mContentFrameMissingTranslation)) |
| 200 | ; |
| 201 | |
Daniel Sandler | 40c1545 | 2011-01-22 01:26:22 -0500 | [diff] [blame] | 202 | set.setDuration(200); |
Daniel Sandler | 641a499 | 2011-01-26 21:19:10 -0500 | [diff] [blame] | 203 | if (!showing) { |
| 204 | set.addListener(new AnimatorListenerAdapter() { |
| 205 | @Override |
| 206 | public void onAnimationEnd(Animator _a) { |
| 207 | mContentFrame.setVisibility(View.GONE); |
| 208 | mContentFrame.setAlpha(1f); |
| 209 | } |
| 210 | }); |
| 211 | } |
Daniel Sandler | 40c1545 | 2011-01-22 01:26:22 -0500 | [diff] [blame] | 212 | set.start(); |
| 213 | } |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 214 | |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 215 | public void swapPanels() { |
| 216 | final View toShow, toHide; |
| 217 | if (mSettingsView == null) { |
| 218 | addSettingsView(); |
| 219 | toShow = mSettingsView; |
| 220 | toHide = mNotificationScroller; |
| 221 | } else { |
| 222 | toShow = mNotificationScroller; |
| 223 | toHide = mSettingsView; |
| 224 | } |
| 225 | Animator a = ObjectAnimator.ofFloat(toHide, "alpha", 1f, 0f) |
| 226 | .setDuration(PANEL_FADE_DURATION); |
| 227 | a.addListener(new AnimatorListenerAdapter() { |
| 228 | @Override |
| 229 | public void onAnimationEnd(Animator _a) { |
| 230 | toHide.setVisibility(View.GONE); |
Daniel Sandler | 40c1545 | 2011-01-22 01:26:22 -0500 | [diff] [blame] | 231 | if (toShow != null) { |
| 232 | if (mNotificationCount == 0) { |
| 233 | // show the frame for settings, hide for notifications |
| 234 | setContentFrameVisible(toShow == mSettingsView, true); |
| 235 | } |
| 236 | |
| 237 | toShow.setVisibility(View.VISIBLE); |
| 238 | if (toShow == mSettingsView || mNotificationCount > 0) { |
| 239 | ObjectAnimator.ofFloat(toShow, "alpha", 0f, 1f) |
| 240 | .setDuration(PANEL_FADE_DURATION) |
| 241 | .start(); |
| 242 | } |
| 243 | |
| 244 | if (toHide == mSettingsView) { |
| 245 | removeSettingsView(); |
| 246 | } |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 247 | } |
| 248 | updatePanelModeButtons(); |
| 249 | } |
| 250 | }); |
| 251 | a.start(); |
| 252 | } |
| 253 | |
| 254 | public void updatePanelModeButtons() { |
| 255 | final boolean settingsVisible = (mSettingsView != null); |
| 256 | mSettingsButton.setVisibility(!settingsVisible ? View.VISIBLE : View.INVISIBLE); |
| 257 | mNotificationButton.setVisibility(settingsVisible ? View.VISIBLE : View.INVISIBLE); |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 260 | public boolean isInContentArea(int x, int y) { |
Daniel Sandler | 641a499 | 2011-01-26 21:19:10 -0500 | [diff] [blame] | 261 | mContentArea.left = mTitleArea.getLeft() + mTitleArea.getPaddingLeft(); |
| 262 | mContentArea.top = mTitleArea.getTop() + mTitleArea.getPaddingTop() |
| 263 | + (int)mContentParent.getTranslationY(); // account for any adjustment |
| 264 | mContentArea.right = mTitleArea.getRight() - mTitleArea.getPaddingRight(); |
| 265 | |
| 266 | View theBottom = (mContentFrame.getVisibility() == View.VISIBLE) |
| 267 | ? mContentFrame : mTitleArea; |
| 268 | mContentArea.bottom = theBottom.getBottom() - theBottom.getPaddingBottom(); |
| 269 | |
Joe Onorato | 6223fba | 2011-01-18 18:00:30 -0800 | [diff] [blame] | 270 | offsetDescendantRectToMyCoords(mContentParent, mContentArea); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 271 | return mContentArea.contains(x, y); |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 272 | } |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 273 | |
Joe Onorato | 755cc74 | 2010-11-27 15:45:35 -0800 | [diff] [blame] | 274 | void removeSettingsView() { |
| 275 | if (mSettingsView != null) { |
| 276 | mContentFrame.removeView(mSettingsView); |
| 277 | mSettingsView = null; |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 281 | // NB: it will be invisible until you show it |
Joe Onorato | 755cc74 | 2010-11-27 15:45:35 -0800 | [diff] [blame] | 282 | void addSettingsView() { |
Joe Onorato | cf2b199 | 2010-11-16 21:36:42 -0800 | [diff] [blame] | 283 | LayoutInflater infl = LayoutInflater.from(getContext()); |
Joe Onorato | 755cc74 | 2010-11-27 15:45:35 -0800 | [diff] [blame] | 284 | mSettingsView = infl.inflate(R.layout.status_bar_settings_view, mContentFrame, false); |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 285 | mSettingsView.setVisibility(View.GONE); |
Daniel Sandler | 2f447aa | 2011-01-14 16:39:19 -0500 | [diff] [blame] | 286 | mContentFrame.addView(mSettingsView); |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 287 | } |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 288 | |
| 289 | private class Choreographer implements Animator.AnimatorListener { |
Joe Onorato | 244e415 | 2010-12-16 13:22:34 -0800 | [diff] [blame] | 290 | boolean mVisible; |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 291 | int mPanelHeight; |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 292 | AnimatorSet mContentAnim; |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 293 | |
| 294 | // should group this into a multi-property animation |
Daniel Sandler | 14db0bc | 2011-01-20 12:11:23 -0500 | [diff] [blame] | 295 | final static int OPEN_DURATION = 136; |
| 296 | final static int CLOSE_DURATION = 250; |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 297 | |
| 298 | // the panel will start to appear this many px from the end |
Daniel Sandler | add2620 | 2011-01-20 02:53:43 -0500 | [diff] [blame] | 299 | final int HYPERSPACE_OFFRAMP = 100; |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 300 | |
| 301 | Choreographer() { |
| 302 | } |
| 303 | |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 304 | void createAnimation(boolean appearing) { |
Daniel Sandler | add2620 | 2011-01-20 02:53:43 -0500 | [diff] [blame] | 305 | // mVisible: previous state; appearing: new state |
| 306 | |
| 307 | View root = findViewById(R.id.panel_root); |
| 308 | Animator bgAnim = ObjectAnimator.ofInt(root.getBackground(), "alpha", |
| 309 | mVisible ? 255 : 0, appearing ? 255 : 0); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 310 | |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 311 | float start, end; |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 312 | |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 313 | // 0: on-screen |
| 314 | // height: off-screen |
| 315 | float y = mContentParent.getTranslationY(); |
| 316 | if (appearing) { |
| 317 | // we want to go from near-the-top to the top, unless we're half-open in the right |
| 318 | // general vicinity |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 319 | end = 0; |
Daniel Sandler | 641a499 | 2011-01-26 21:19:10 -0500 | [diff] [blame] | 320 | if (mNotificationCount == 0) { |
| 321 | end += mContentFrameMissingTranslation; |
| 322 | } |
Daniel Sandler | 8c98918 | 2011-01-30 01:24:09 -0500 | [diff] [blame] | 323 | start = HYPERSPACE_OFFRAMP+end; |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 324 | } else { |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 325 | start = y; |
| 326 | end = y + HYPERSPACE_OFFRAMP; |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 327 | } |
Daniel Sandler | 641a499 | 2011-01-26 21:19:10 -0500 | [diff] [blame] | 328 | |
Daniel Sandler | add2620 | 2011-01-20 02:53:43 -0500 | [diff] [blame] | 329 | Animator posAnim = ObjectAnimator.ofFloat(mContentParent, "translationY", |
| 330 | start, end); |
Jim Miller | 85babff | 2011-01-11 14:26:03 -0800 | [diff] [blame] | 331 | posAnim.setInterpolator(appearing |
Daniel Sandler | add2620 | 2011-01-20 02:53:43 -0500 | [diff] [blame] | 332 | ? new android.view.animation.DecelerateInterpolator(1.0f) |
| 333 | : new android.view.animation.AccelerateInterpolator(1.0f)); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 334 | |
Daniel Sandler | f844dc4 | 2011-01-24 23:44:47 -0500 | [diff] [blame] | 335 | if (mContentAnim != null && mContentAnim.isRunning()) { |
| 336 | mContentAnim.cancel(); |
| 337 | } |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 338 | |
Daniel Sandler | 8c98918 | 2011-01-30 01:24:09 -0500 | [diff] [blame] | 339 | Animator fadeAnim = ObjectAnimator.ofFloat(mContentParent, "alpha", |
| 340 | mContentParent.getAlpha(), appearing ? 1.0f : 0.0f); |
| 341 | fadeAnim.setInterpolator(appearing |
| 342 | ? new android.view.animation.AccelerateInterpolator(2.0f) |
| 343 | : new android.view.animation.DecelerateInterpolator(2.0f)); |
| 344 | |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 345 | mContentAnim = new AnimatorSet(); |
| 346 | mContentAnim |
Daniel Sandler | 8c98918 | 2011-01-30 01:24:09 -0500 | [diff] [blame] | 347 | .play(fadeAnim) |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 348 | .with(bgAnim) |
| 349 | .with(posAnim) |
| 350 | ; |
Daniel Sandler | add2620 | 2011-01-20 02:53:43 -0500 | [diff] [blame] | 351 | mContentAnim.setDuration((DEBUG?10:1)*(appearing ? OPEN_DURATION : CLOSE_DURATION)); |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 352 | mContentAnim.addListener(this); |
| 353 | } |
| 354 | |
| 355 | void startAnimation(boolean appearing) { |
| 356 | if (DEBUG) Slog.d(TAG, "startAnimation(appearing=" + appearing + ")"); |
| 357 | |
| 358 | createAnimation(appearing); |
| 359 | |
| 360 | mContentParent.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 361 | mContentAnim.start(); |
| 362 | |
| 363 | mVisible = appearing; |
| 364 | } |
| 365 | |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 366 | public void onAnimationCancel(Animator animation) { |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 367 | if (DEBUG) Slog.d(TAG, "onAnimationCancel"); |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | public void onAnimationEnd(Animator animation) { |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 371 | if (DEBUG) Slog.d(TAG, "onAnimationEnd"); |
| 372 | if (! mVisible) { |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 373 | setVisibility(View.GONE); |
| 374 | } |
Daniel Sandler | 7d9ea8c | 2011-01-11 10:28:58 -0500 | [diff] [blame] | 375 | mContentParent.setLayerType(View.LAYER_TYPE_NONE, null); |
| 376 | mContentAnim = null; |
Joe Onorato | 7c270fa | 2010-12-08 17:31:42 -0800 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | public void onAnimationRepeat(Animator animation) { |
| 380 | } |
| 381 | |
| 382 | public void onAnimationStart(Animator animation) { |
| 383 | } |
| 384 | } |
Joe Onorato | ddf680b | 2010-09-26 13:59:40 -0700 | [diff] [blame] | 385 | } |
| 386 | |