Skip to content

Commit c30b6da

Browse files
dsandlerAndroid (Google) Code Review
authored andcommitted
Merge "Bring back the notification panel handle peek animation." into jb-mr1-dev
2 parents 3594e85 + 0c1b75c commit c30b6da

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

packages/SystemUI/res/layout/quick_settings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@
4141
android:id="@+id/handle"
4242
android:layout_width="match_parent"
4343
android:layout_height="@dimen/close_handle_height"
44+
android:background="@drawable/status_bar_close"
45+
android:visibility="invisible"
4446
/>
47+
4548
</com.android.systemui.statusbar.phone.SettingsPanelView >

packages/SystemUI/res/layout/status_bar_expanded.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
android:id="@+id/handle"
3434
android:layout_width="match_parent"
3535
android:layout_height="@dimen/close_handle_height"
36+
android:background="@drawable/status_bar_close"
37+
android:visibility="invisible"
3638
/>
3739

3840
<include

packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.android.systemui.statusbar.phone;
22

3+
import android.animation.ObjectAnimator;
34
import android.animation.TimeAnimator;
45
import android.animation.TimeAnimator.TimeListener;
56
import android.content.Context;
@@ -45,14 +46,17 @@ public final void LOG(String fmt, Object... args) {
4546
private float mBrakingSpeedPx = 150; // XXX Resource
4647

4748
private View mHandleView;
49+
private float mPeekHeight;
4850
private float mTouchOffset;
4951
private float mExpandedFraction = 0;
5052
private float mExpandedHeight = 0;
53+
private boolean mJustPeeked;
5154
private boolean mClosing;
5255
private boolean mRubberbanding;
5356
private boolean mTracking;
5457

5558
private TimeAnimator mTimeAnimator;
59+
private ObjectAnimator mPeekAnimator;
5660
private VelocityTracker mVelocityTracker;
5761

5862
private int[] mAbsPos = new int[2];
@@ -68,7 +72,7 @@ public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime)
6872
private final Runnable mStopAnimator = new Runnable() {
6973
@Override
7074
public void run() {
71-
if (mTimeAnimator.isStarted()) {
75+
if (mTimeAnimator != null && mTimeAnimator.isStarted()) {
7276
mTimeAnimator.end();
7377
mRubberbanding = false;
7478
mClosing = false;
@@ -82,12 +86,27 @@ public void run() {
8286
protected float mInitialTouchY;
8387
protected float mFinalTouchY;
8488

89+
private void runPeekAnimation() {
90+
if (DEBUG) LOG("peek to height=%.1f", mPeekHeight);
91+
if (mTimeAnimator.isStarted()) {
92+
return;
93+
}
94+
if (mPeekAnimator == null) {
95+
mPeekAnimator = ObjectAnimator.ofFloat(this,
96+
"expandedHeight", mPeekHeight)
97+
.setDuration(300);
98+
}
99+
mPeekAnimator.start();
100+
}
101+
85102
private void animationTick(long dtms) {
86103
if (!mTimeAnimator.isStarted()) {
87104
// XXX HAX to work around bug in TimeAnimator.end() not resetting its last time
88105
mTimeAnimator = new TimeAnimator();
89106
mTimeAnimator.setTimeListener(mAnimationCallback);
90107

108+
mPeekAnimator.cancel();
109+
91110
mTimeAnimator.start();
92111

93112
mRubberbanding = STRETCH_PAST_CONTENTS // is it enabled at all?
@@ -182,6 +201,10 @@ private void loadDimens() {
182201
mFlingGestureMaxXVelocityPx = res.getDimension(R.dimen.fling_gesture_max_x_velocity);
183202

184203
mFlingGestureMaxOutputVelocityPx = res.getDimension(R.dimen.fling_gesture_max_output_velocity);
204+
205+
mPeekHeight = res.getDimension(R.dimen.close_handle_height)
206+
+ getPaddingBottom() // our window might have a dropshadow
207+
- (mHandleView == null ? 0 : mHandleView.getPaddingTop()); // the handle might have a topshadow
185208
}
186209

187210
private void trackMovement(MotionEvent event) {
@@ -203,9 +226,10 @@ public boolean onTouchEvent(MotionEvent event) {
203226
@Override
204227
protected void onFinishInflate() {
205228
super.onFinishInflate();
229+
mHandleView = findViewById(R.id.handle);
230+
206231
loadDimens();
207232

208-
mHandleView = findViewById(R.id.handle);
209233
if (DEBUG) LOG("handle view: " + mHandleView);
210234
if (mHandleView != null) {
211235
mHandleView.setOnTouchListener(new View.OnTouchListener() {
@@ -228,12 +252,24 @@ public boolean onTouch(View v, MotionEvent event) {
228252
mTimeAnimator.cancel(); // end any outstanding animations
229253
mBar.onTrackingStarted(PanelView.this);
230254
mTouchOffset = (rawY - mAbsPos[1]) - PanelView.this.getExpandedHeight();
255+
if (mExpandedHeight == 0) {
256+
mJustPeeked = true;
257+
runPeekAnimation();
258+
}
231259
break;
232260

233261
case MotionEvent.ACTION_MOVE:
234-
PanelView.this.setExpandedHeightInternal(rawY - mAbsPos[1] - mTouchOffset);
235-
236-
mBar.panelExpansionChanged(PanelView.this, mExpandedFraction);
262+
final float h = rawY - mAbsPos[1] - mTouchOffset;
263+
if (h > mPeekHeight) {
264+
if (mPeekAnimator.isRunning()) {
265+
mPeekAnimator.cancel();
266+
}
267+
mJustPeeked = false;
268+
}
269+
if (!mJustPeeked) {
270+
PanelView.this.setExpandedHeightInternal(h);
271+
mBar.panelExpansionChanged(PanelView.this, mExpandedFraction);
272+
}
237273

238274
trackMovement(event);
239275
break;
@@ -267,7 +303,8 @@ public boolean onTouch(View v, MotionEvent event) {
267303
// preventing spurious flings due to touch screen jitter
268304
final float deltaY = Math.abs(mFinalTouchY - mInitialTouchY);
269305
if (deltaY < mFlingGestureMinDistPx
270-
|| vel < mFlingExpandMinVelocityPx) {
306+
|| vel < mFlingExpandMinVelocityPx
307+
|| mJustPeeked) {
271308
vel = 0;
272309
}
273310

@@ -347,9 +384,13 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
347384

348385

349386
public void setExpandedHeight(float height) {
387+
if (DEBUG) LOG("setExpandedHeight(%.1f)", height);
350388
mTracking = mRubberbanding = false;
351-
post(mStopAnimator);
389+
if (mTimeAnimator.isRunning()) {
390+
post(mStopAnimator);
391+
}
352392
setExpandedHeightInternal(height);
393+
mBar.panelExpansionChanged(PanelView.this, mExpandedFraction);
353394
}
354395

355396
@Override

0 commit comments

Comments
 (0)