Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 1 | package com.android.systemui.statusbar.phone; |
| 2 | |
| 3 | import android.animation.TimeAnimator; |
| 4 | import android.animation.TimeAnimator.TimeListener; |
| 5 | import android.content.Context; |
| 6 | import android.content.res.Resources; |
| 7 | import android.util.AttributeSet; |
Daniel Sandler | bf526d1 | 2012-09-04 22:56:44 -0400 | [diff] [blame] | 8 | import android.util.Slog; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 9 | import android.view.MotionEvent; |
| 10 | import android.view.VelocityTracker; |
| 11 | import android.view.View; |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame^] | 12 | import android.view.ViewGroup; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 13 | import android.widget.FrameLayout; |
| 14 | |
| 15 | import com.android.systemui.R; |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 16 | import com.android.systemui.statusbar.policy.BatteryController; |
| 17 | import com.android.systemui.statusbar.policy.BluetoothController; |
| 18 | import com.android.systemui.statusbar.policy.LocationController; |
| 19 | import com.android.systemui.statusbar.policy.NetworkController; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 20 | |
| 21 | public class PanelView extends FrameLayout { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame^] | 22 | public static final boolean DEBUG = PanelBar.DEBUG; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 23 | public static final String TAG = PanelView.class.getSimpleName(); |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 24 | public final void LOG(String fmt, Object... args) { |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 25 | if (!DEBUG) return; |
Daniel Sandler | bf526d1 | 2012-09-04 22:56:44 -0400 | [diff] [blame] | 26 | Slog.v(TAG, (mViewName != null ? (mViewName + ": ") : "") + String.format(fmt, args)); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | public static final boolean BRAKES = false; |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 30 | private static final boolean STRETCH_PAST_CONTENTS = true; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 31 | |
| 32 | private float mSelfExpandVelocityPx; // classic value: 2000px/s |
| 33 | private float mSelfCollapseVelocityPx; // classic value: 2000px/s (will be negated to collapse "up") |
| 34 | private float mFlingExpandMinVelocityPx; // classic value: 200px/s |
| 35 | private float mFlingCollapseMinVelocityPx; // classic value: 200px/s |
| 36 | private float mCollapseMinDisplayFraction; // classic value: 0.08 (25px/min(320px,480px) on G1) |
| 37 | private float mExpandMinDisplayFraction; // classic value: 0.5 (drag open halfway to expand) |
| 38 | private float mFlingGestureMaxXVelocityPx; // classic value: 150px/s |
| 39 | |
| 40 | private float mExpandAccelPx; // classic value: 2000px/s/s |
| 41 | private float mCollapseAccelPx; // classic value: 2000px/s/s (will be negated to collapse "up") |
| 42 | |
| 43 | private float mFlingGestureMaxOutputVelocityPx; // how fast can it really go? (should be a little |
| 44 | // faster than mSelfCollapseVelocityPx) |
| 45 | |
| 46 | private float mCollapseBrakingDistancePx = 200; // XXX Resource |
| 47 | private float mExpandBrakingDistancePx = 150; // XXX Resource |
| 48 | private float mBrakingSpeedPx = 150; // XXX Resource |
| 49 | |
| 50 | private View mHandleView; |
| 51 | private float mTouchOffset; |
| 52 | private float mExpandedFraction = 0; |
| 53 | private float mExpandedHeight = 0; |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 54 | private boolean mClosing; |
| 55 | private boolean mRubberbanding; |
| 56 | private boolean mTracking; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 57 | |
| 58 | private TimeAnimator mTimeAnimator; |
| 59 | private VelocityTracker mVelocityTracker; |
| 60 | |
| 61 | private int[] mAbsPos = new int[2]; |
| 62 | PanelBar mBar; |
| 63 | |
| 64 | private final TimeListener mAnimationCallback = new TimeListener() { |
| 65 | @Override |
| 66 | public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) { |
| 67 | animationTick(deltaTime); |
| 68 | } |
| 69 | }; |
| 70 | |
Daniel Sandler | 5a35a0d | 2012-08-16 13:50:40 -0400 | [diff] [blame] | 71 | private final Runnable mStopAnimator = new Runnable() { public void run() { |
| 72 | if (mTimeAnimator.isStarted()) { |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 73 | mTimeAnimator.end(); |
Chet Haase | 179ec6d | 2012-08-20 17:34:33 -0700 | [diff] [blame] | 74 | mRubberbanding = false; |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 75 | } |
Daniel Sandler | 5a35a0d | 2012-08-16 13:50:40 -0400 | [diff] [blame] | 76 | }}; |
| 77 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 78 | private float mVel, mAccel; |
| 79 | private int mFullHeight = 0; |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 80 | private String mViewName; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 81 | |
| 82 | private void animationTick(long dtms) { |
| 83 | if (!mTimeAnimator.isStarted()) { |
| 84 | // XXX HAX to work around bug in TimeAnimator.end() not resetting its last time |
| 85 | mTimeAnimator = new TimeAnimator(); |
| 86 | mTimeAnimator.setTimeListener(mAnimationCallback); |
| 87 | |
| 88 | mTimeAnimator.start(); |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 89 | |
| 90 | mRubberbanding = STRETCH_PAST_CONTENTS && mExpandedHeight > getFullHeight(); |
| 91 | mClosing = (mExpandedHeight > 0 && mVel < 0) || mRubberbanding; |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 92 | } else if (dtms > 0) { |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 93 | final float dt = dtms * 0.001f; // ms -> s |
| 94 | LOG("tick: v=%.2fpx/s dt=%.4fs", mVel, dt); |
| 95 | LOG("tick: before: h=%d", (int) mExpandedHeight); |
| 96 | |
| 97 | final float fh = getFullHeight(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 98 | boolean braking = false; |
| 99 | if (BRAKES) { |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 100 | if (mClosing) { |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 101 | braking = mExpandedHeight <= mCollapseBrakingDistancePx; |
| 102 | mAccel = braking ? 10*mCollapseAccelPx : -mCollapseAccelPx; |
| 103 | } else { |
| 104 | braking = mExpandedHeight >= (fh-mExpandBrakingDistancePx); |
| 105 | mAccel = braking ? 10*-mExpandAccelPx : mExpandAccelPx; |
| 106 | } |
| 107 | } else { |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 108 | mAccel = mClosing ? -mCollapseAccelPx : mExpandAccelPx; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | mVel += mAccel * dt; |
| 112 | |
| 113 | if (braking) { |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 114 | if (mClosing && mVel > -mBrakingSpeedPx) { |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 115 | mVel = -mBrakingSpeedPx; |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 116 | } else if (!mClosing && mVel < mBrakingSpeedPx) { |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 117 | mVel = mBrakingSpeedPx; |
| 118 | } |
| 119 | } else { |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 120 | if (mClosing && mVel > -mFlingCollapseMinVelocityPx) { |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 121 | mVel = -mFlingCollapseMinVelocityPx; |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 122 | } else if (!mClosing && mVel > mFlingGestureMaxOutputVelocityPx) { |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 123 | mVel = mFlingGestureMaxOutputVelocityPx; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | float h = mExpandedHeight + mVel * dt; |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 128 | |
| 129 | if (mRubberbanding && h < fh) { |
| 130 | h = fh; |
| 131 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 132 | |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 133 | LOG("tick: new h=%d closing=%s", (int) h, mClosing?"true":"false"); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 134 | |
| 135 | setExpandedHeightInternal(h); |
| 136 | |
| 137 | mBar.panelExpansionChanged(PanelView.this, mExpandedFraction); |
| 138 | |
| 139 | if (mVel == 0 |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 140 | || (mClosing && mExpandedHeight == 0) |
| 141 | || ((mRubberbanding || !mClosing) && mExpandedHeight == fh)) { |
Daniel Sandler | 5a35a0d | 2012-08-16 13:50:40 -0400 | [diff] [blame] | 142 | post(mStopAnimator); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | public PanelView(Context context, AttributeSet attrs) { |
| 148 | super(context, attrs); |
| 149 | |
| 150 | mTimeAnimator = new TimeAnimator(); |
| 151 | mTimeAnimator.setTimeListener(mAnimationCallback); |
| 152 | } |
| 153 | |
| 154 | private void loadDimens() { |
| 155 | final Resources res = getContext().getResources(); |
| 156 | |
| 157 | mSelfExpandVelocityPx = res.getDimension(R.dimen.self_expand_velocity); |
| 158 | mSelfCollapseVelocityPx = res.getDimension(R.dimen.self_collapse_velocity); |
| 159 | mFlingExpandMinVelocityPx = res.getDimension(R.dimen.fling_expand_min_velocity); |
| 160 | mFlingCollapseMinVelocityPx = res.getDimension(R.dimen.fling_collapse_min_velocity); |
| 161 | |
| 162 | mCollapseMinDisplayFraction = res.getFraction(R.dimen.collapse_min_display_fraction, 1, 1); |
| 163 | mExpandMinDisplayFraction = res.getFraction(R.dimen.expand_min_display_fraction, 1, 1); |
| 164 | |
| 165 | mExpandAccelPx = res.getDimension(R.dimen.expand_accel); |
| 166 | mCollapseAccelPx = res.getDimension(R.dimen.collapse_accel); |
| 167 | |
| 168 | mFlingGestureMaxXVelocityPx = res.getDimension(R.dimen.fling_gesture_max_x_velocity); |
| 169 | |
| 170 | mFlingGestureMaxOutputVelocityPx = res.getDimension(R.dimen.fling_gesture_max_output_velocity); |
| 171 | } |
| 172 | |
| 173 | private void trackMovement(MotionEvent event) { |
| 174 | // Add movement to velocity tracker using raw screen X and Y coordinates instead |
| 175 | // of window coordinates because the window frame may be moving at the same time. |
| 176 | float deltaX = event.getRawX() - event.getX(); |
| 177 | float deltaY = event.getRawY() - event.getY(); |
| 178 | event.offsetLocation(deltaX, deltaY); |
| 179 | mVelocityTracker.addMovement(event); |
| 180 | event.offsetLocation(-deltaX, -deltaY); |
| 181 | } |
| 182 | |
Daniel Sandler | bf526d1 | 2012-09-04 22:56:44 -0400 | [diff] [blame] | 183 | // Pass all touches along to the handle, allowing the user to drag the panel closed from its interior |
| 184 | @Override |
| 185 | public boolean onTouchEvent(MotionEvent event) { |
| 186 | return mHandleView.dispatchTouchEvent(event); |
| 187 | } |
| 188 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 189 | @Override |
| 190 | protected void onFinishInflate() { |
| 191 | super.onFinishInflate(); |
| 192 | loadDimens(); |
| 193 | |
| 194 | mHandleView = findViewById(R.id.handle); |
| 195 | LOG("handle view: " + mHandleView); |
| 196 | if (mHandleView != null) { |
| 197 | mHandleView.setOnTouchListener(new View.OnTouchListener() { |
| 198 | @Override |
| 199 | public boolean onTouch(View v, MotionEvent event) { |
| 200 | final float y = event.getY(); |
| 201 | final float rawY = event.getRawY(); |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 202 | LOG("handle.onTouch: a=%s y=%.1f rawY=%.1f off=%.1f", |
| 203 | MotionEvent.actionToString(event.getAction()), |
| 204 | y, rawY, mTouchOffset); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 205 | PanelView.this.getLocationOnScreen(mAbsPos); |
| 206 | |
| 207 | switch (event.getAction()) { |
| 208 | case MotionEvent.ACTION_DOWN: |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 209 | mTracking = true; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 210 | mVelocityTracker = VelocityTracker.obtain(); |
| 211 | trackMovement(event); |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 212 | mBar.onTrackingStarted(PanelView.this); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 213 | mTouchOffset = (rawY - mAbsPos[1]) - PanelView.this.getExpandedHeight(); |
| 214 | break; |
| 215 | |
| 216 | case MotionEvent.ACTION_MOVE: |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 217 | PanelView.this.setExpandedHeightInternal(rawY - mAbsPos[1] - mTouchOffset); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 218 | |
| 219 | mBar.panelExpansionChanged(PanelView.this, mExpandedFraction); |
| 220 | |
| 221 | trackMovement(event); |
| 222 | break; |
| 223 | |
| 224 | case MotionEvent.ACTION_UP: |
| 225 | case MotionEvent.ACTION_CANCEL: |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 226 | mTracking = false; |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 227 | mBar.onTrackingStopped(PanelView.this); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 228 | trackMovement(event); |
| 229 | mVelocityTracker.computeCurrentVelocity(1000); |
| 230 | |
| 231 | float yVel = mVelocityTracker.getYVelocity(); |
| 232 | boolean negative = yVel < 0; |
| 233 | |
| 234 | float xVel = mVelocityTracker.getXVelocity(); |
| 235 | if (xVel < 0) { |
| 236 | xVel = -xVel; |
| 237 | } |
| 238 | if (xVel > mFlingGestureMaxXVelocityPx) { |
| 239 | xVel = mFlingGestureMaxXVelocityPx; // limit how much we care about the x axis |
| 240 | } |
| 241 | |
| 242 | float vel = (float)Math.hypot(yVel, xVel); |
| 243 | if (vel > mFlingGestureMaxOutputVelocityPx) { |
| 244 | vel = mFlingGestureMaxOutputVelocityPx; |
| 245 | } |
| 246 | if (negative) { |
| 247 | vel = -vel; |
| 248 | } |
| 249 | |
| 250 | LOG("gesture: vraw=(%f,%f) vnorm=(%f,%f) vlinear=%f", |
| 251 | mVelocityTracker.getXVelocity(), |
| 252 | mVelocityTracker.getYVelocity(), |
| 253 | xVel, yVel, |
| 254 | vel); |
| 255 | |
Daniel Sandler | cf591db | 2012-08-15 16:11:55 -0400 | [diff] [blame] | 256 | fling(vel, true); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 257 | |
| 258 | mVelocityTracker.recycle(); |
| 259 | mVelocityTracker = null; |
| 260 | |
| 261 | break; |
| 262 | } |
| 263 | return true; |
| 264 | }}); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | public void fling(float vel, boolean always) { |
| 269 | mVel = vel; |
| 270 | |
Daniel Sandler | cf591db | 2012-08-15 16:11:55 -0400 | [diff] [blame] | 271 | if (always||mVel != 0) { |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 272 | animationTick(0); // begin the animation |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | protected void onAttachedToWindow() { |
| 278 | super.onAttachedToWindow(); |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 279 | mViewName = getResources().getResourceName(getId()); |
| 280 | } |
| 281 | |
| 282 | public String getName() { |
| 283 | return mViewName; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Override |
| 287 | protected void onViewAdded(View child) { |
| 288 | LOG("onViewAdded: " + child); |
| 289 | } |
| 290 | |
| 291 | public View getHandle() { |
| 292 | return mHandleView; |
| 293 | } |
| 294 | |
| 295 | // Rubberbands the panel to hold its contents. |
| 296 | @Override |
| 297 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 298 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 299 | |
| 300 | LOG("onMeasure(%d, %d) -> (%d, %d)", |
| 301 | widthMeasureSpec, heightMeasureSpec, getMeasuredWidth(), getMeasuredHeight()); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame^] | 302 | |
| 303 | // Did one of our children change size? |
| 304 | int newHeight = getMeasuredHeight(); |
| 305 | if (newHeight != mFullHeight) { |
| 306 | mFullHeight = newHeight; |
| 307 | // If the user isn't actively poking us, let's rubberband to the content |
| 308 | if (!mTracking && !mRubberbanding && !mTimeAnimator.isStarted() |
| 309 | && mExpandedHeight > 0 && mExpandedHeight != mFullHeight) { |
| 310 | mExpandedHeight = mFullHeight; |
| 311 | } |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 312 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 313 | heightMeasureSpec = MeasureSpec.makeMeasureSpec( |
| 314 | (int) mExpandedHeight, MeasureSpec.AT_MOST); // MeasureSpec.getMode(heightMeasureSpec)); |
| 315 | setMeasuredDimension(widthMeasureSpec, heightMeasureSpec); |
| 316 | } |
| 317 | |
| 318 | |
| 319 | public void setExpandedHeight(float height) { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame^] | 320 | mTracking = mRubberbanding = false; |
Daniel Sandler | 5a35a0d | 2012-08-16 13:50:40 -0400 | [diff] [blame] | 321 | post(mStopAnimator); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 322 | setExpandedHeightInternal(height); |
| 323 | } |
| 324 | |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 325 | @Override |
| 326 | protected void onLayout (boolean changed, int left, int top, int right, int bottom) { |
| 327 | LOG("onLayout: changed=%s, bottom=%d eh=%d fh=%d", changed?"T":"f", bottom, (int)mExpandedHeight, (int)mFullHeight); |
| 328 | super.onLayout(changed, left, top, right, bottom); |
| 329 | } |
| 330 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 331 | public void setExpandedHeightInternal(float h) { |
| 332 | float fh = getFullHeight(); |
| 333 | if (fh == 0) { |
| 334 | // Hmm, full height hasn't been computed yet |
| 335 | } |
| 336 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 337 | if (h < 0) h = 0; |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 338 | if (!(STRETCH_PAST_CONTENTS && (mTracking || mRubberbanding)) && h > fh) h = fh; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 339 | mExpandedHeight = h; |
| 340 | |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame^] | 341 | LOG("setExpansion: height=%.1f fh=%.1f tracking=%s rubber=%s", h, fh, mTracking?"T":"f", mRubberbanding?"T":"f"); |
| 342 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 343 | requestLayout(); |
| 344 | // FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams(); |
| 345 | // lp.height = (int) mExpandedHeight; |
| 346 | // setLayoutParams(lp); |
| 347 | |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame^] | 348 | mExpandedFraction = Math.min(1f, (fh == 0) ? 0 : h / fh); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | private float getFullHeight() { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame^] | 352 | if (mFullHeight <= 0) { |
| 353 | LOG("Forcing measure() since fullHeight=" + mFullHeight); |
| 354 | measure(MeasureSpec.makeMeasureSpec(LayoutParams.WRAP_CONTENT, MeasureSpec.EXACTLY), |
| 355 | MeasureSpec.makeMeasureSpec(LayoutParams.WRAP_CONTENT, MeasureSpec.EXACTLY)); |
| 356 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 357 | return mFullHeight; |
| 358 | } |
| 359 | |
| 360 | public void setExpandedFraction(float frac) { |
| 361 | setExpandedHeight(getFullHeight() * frac); |
| 362 | } |
| 363 | |
| 364 | public float getExpandedHeight() { |
| 365 | return mExpandedHeight; |
| 366 | } |
| 367 | |
| 368 | public float getExpandedFraction() { |
| 369 | return mExpandedFraction; |
| 370 | } |
| 371 | |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 372 | public boolean isFullyExpanded() { |
| 373 | return mExpandedHeight == getFullHeight(); |
| 374 | } |
| 375 | |
| 376 | public boolean isFullyCollapsed() { |
| 377 | return mExpandedHeight == 0; |
| 378 | } |
| 379 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 380 | public void setBar(PanelBar panelBar) { |
| 381 | mBar = panelBar; |
| 382 | } |
| 383 | |
Winson Chung | 43229d7 | 2012-09-12 18:04:18 -0700 | [diff] [blame] | 384 | public void setImeWindowStatus(boolean visible) { |
| 385 | // To be implemented by classes extending PanelView |
| 386 | } |
| 387 | |
Winson Chung | d63c5978 | 2012-09-05 17:34:41 -0700 | [diff] [blame] | 388 | public void setup(NetworkController network, BluetoothController bt, BatteryController batt, |
| 389 | LocationController location) { |
| 390 | // To be implemented by classes extending PanelView |
| 391 | } |
| 392 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 393 | public void collapse() { |
| 394 | // TODO: abort animation or ongoing touch |
Daniel Sandler | b4e56ed | 2012-09-12 23:07:44 -0700 | [diff] [blame] | 395 | if (!isFullyCollapsed()) { |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 396 | fling(-mSelfCollapseVelocityPx, /*always=*/ true); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | public void expand() { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame^] | 401 | if (isFullyCollapsed()) { |
| 402 | mBar.startOpeningPanel(this); |
| 403 | LOG("expand: calling fling(%s, true)", mSelfExpandVelocityPx); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 404 | fling (mSelfExpandVelocityPx, /*always=*/ true); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame^] | 405 | } else if (DEBUG) { |
| 406 | LOG("skipping expansion: is expanded"); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | } |