Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c1b75c1 authored by Daniel Sandler's avatar Daniel Sandler
Browse files

Bring back the notification panel handle peek animation.

Bug: 7286201
Change-Id: Id93d6a00689ffb7f97e89af935460b1debec3850
parent ebf7e285
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -41,5 +41,8 @@
        android:id="@+id/handle"
        android:id="@+id/handle"
        android:layout_width="match_parent"
        android:layout_width="match_parent"
        android:layout_height="@dimen/close_handle_height"
        android:layout_height="@dimen/close_handle_height"
        android:background="@drawable/status_bar_close"
        android:visibility="invisible"
        />
        />

</com.android.systemui.statusbar.phone.SettingsPanelView >
</com.android.systemui.statusbar.phone.SettingsPanelView >
 No newline at end of file
+2 −0
Original line number Original line Diff line number Diff line
@@ -33,6 +33,8 @@
        android:id="@+id/handle"
        android:id="@+id/handle"
        android:layout_width="match_parent"
        android:layout_width="match_parent"
        android:layout_height="@dimen/close_handle_height"
        android:layout_height="@dimen/close_handle_height"
        android:background="@drawable/status_bar_close"
        android:visibility="invisible"
        />
        />


    <include
    <include
+48 −7
Original line number Original line Diff line number Diff line
package com.android.systemui.statusbar.phone;
package com.android.systemui.statusbar.phone;


import android.animation.ObjectAnimator;
import android.animation.TimeAnimator;
import android.animation.TimeAnimator;
import android.animation.TimeAnimator.TimeListener;
import android.animation.TimeAnimator.TimeListener;
import android.content.Context;
import android.content.Context;
@@ -45,14 +46,17 @@ public class PanelView extends FrameLayout {
    private float mBrakingSpeedPx = 150; // XXX Resource
    private float mBrakingSpeedPx = 150; // XXX Resource


    private View mHandleView;
    private View mHandleView;
    private float mPeekHeight;
    private float mTouchOffset;
    private float mTouchOffset;
    private float mExpandedFraction = 0;
    private float mExpandedFraction = 0;
    private float mExpandedHeight = 0;
    private float mExpandedHeight = 0;
    private boolean mJustPeeked;
    private boolean mClosing;
    private boolean mClosing;
    private boolean mRubberbanding;
    private boolean mRubberbanding;
    private boolean mTracking;
    private boolean mTracking;


    private TimeAnimator mTimeAnimator;
    private TimeAnimator mTimeAnimator;
    private ObjectAnimator mPeekAnimator;
    private VelocityTracker mVelocityTracker;
    private VelocityTracker mVelocityTracker;


    private int[] mAbsPos = new int[2];
    private int[] mAbsPos = new int[2];
@@ -68,7 +72,7 @@ public class PanelView extends FrameLayout {
    private final Runnable mStopAnimator = new Runnable() {
    private final Runnable mStopAnimator = new Runnable() {
        @Override
        @Override
        public void run() {
        public void run() {
            if (mTimeAnimator.isStarted()) {
            if (mTimeAnimator != null && mTimeAnimator.isStarted()) {
                mTimeAnimator.end();
                mTimeAnimator.end();
                mRubberbanding = false;
                mRubberbanding = false;
                mClosing = false;
                mClosing = false;
@@ -82,12 +86,27 @@ public class PanelView extends FrameLayout {
    protected float mInitialTouchY;
    protected float mInitialTouchY;
    protected float mFinalTouchY;
    protected float mFinalTouchY;


    private void runPeekAnimation() {
        if (DEBUG) LOG("peek to height=%.1f", mPeekHeight);
        if (mTimeAnimator.isStarted()) {
            return;
        }
        if (mPeekAnimator == null) {
            mPeekAnimator = ObjectAnimator.ofFloat(this, 
                    "expandedHeight", mPeekHeight)
                .setDuration(300);
        }
        mPeekAnimator.start();
    }

    private void animationTick(long dtms) {
    private void animationTick(long dtms) {
        if (!mTimeAnimator.isStarted()) {
        if (!mTimeAnimator.isStarted()) {
            // XXX HAX to work around bug in TimeAnimator.end() not resetting its last time
            // XXX HAX to work around bug in TimeAnimator.end() not resetting its last time
            mTimeAnimator = new TimeAnimator();
            mTimeAnimator = new TimeAnimator();
            mTimeAnimator.setTimeListener(mAnimationCallback);
            mTimeAnimator.setTimeListener(mAnimationCallback);


            mPeekAnimator.cancel();

            mTimeAnimator.start();
            mTimeAnimator.start();


            mRubberbanding = STRETCH_PAST_CONTENTS // is it enabled at all?
            mRubberbanding = STRETCH_PAST_CONTENTS // is it enabled at all?
@@ -182,6 +201,10 @@ public class PanelView extends FrameLayout {
        mFlingGestureMaxXVelocityPx = res.getDimension(R.dimen.fling_gesture_max_x_velocity);
        mFlingGestureMaxXVelocityPx = res.getDimension(R.dimen.fling_gesture_max_x_velocity);


        mFlingGestureMaxOutputVelocityPx = res.getDimension(R.dimen.fling_gesture_max_output_velocity);
        mFlingGestureMaxOutputVelocityPx = res.getDimension(R.dimen.fling_gesture_max_output_velocity);

        mPeekHeight = res.getDimension(R.dimen.close_handle_height) 
            + getPaddingBottom() // our window might have a dropshadow
            - (mHandleView == null ? 0 : mHandleView.getPaddingTop()); // the handle might have a topshadow
    }
    }


    private void trackMovement(MotionEvent event) {
    private void trackMovement(MotionEvent event) {
@@ -203,9 +226,10 @@ public class PanelView extends FrameLayout {
    @Override
    @Override
    protected void onFinishInflate() {
    protected void onFinishInflate() {
        super.onFinishInflate();
        super.onFinishInflate();
        mHandleView = findViewById(R.id.handle);

        loadDimens();
        loadDimens();


        mHandleView = findViewById(R.id.handle);
        if (DEBUG) LOG("handle view: " + mHandleView);
        if (DEBUG) LOG("handle view: " + mHandleView);
        if (mHandleView != null) {
        if (mHandleView != null) {
            mHandleView.setOnTouchListener(new View.OnTouchListener() {
            mHandleView.setOnTouchListener(new View.OnTouchListener() {
@@ -228,12 +252,24 @@ public class PanelView extends FrameLayout {
                            mTimeAnimator.cancel(); // end any outstanding animations
                            mTimeAnimator.cancel(); // end any outstanding animations
                            mBar.onTrackingStarted(PanelView.this);
                            mBar.onTrackingStarted(PanelView.this);
                            mTouchOffset = (rawY - mAbsPos[1]) - PanelView.this.getExpandedHeight();
                            mTouchOffset = (rawY - mAbsPos[1]) - PanelView.this.getExpandedHeight();
                            if (mExpandedHeight == 0) {
                                mJustPeeked = true;
                                runPeekAnimation();
                            }
                            break;
                            break;


                        case MotionEvent.ACTION_MOVE:
                        case MotionEvent.ACTION_MOVE:
                            PanelView.this.setExpandedHeightInternal(rawY - mAbsPos[1] - mTouchOffset);
                            final float h = rawY - mAbsPos[1] - mTouchOffset;

                            if (h > mPeekHeight) {
                                if (mPeekAnimator.isRunning()) {
                                    mPeekAnimator.cancel();
                                }
                                mJustPeeked = false;
                            }
                            if (!mJustPeeked) {
                                PanelView.this.setExpandedHeightInternal(h);
                                mBar.panelExpansionChanged(PanelView.this, mExpandedFraction);
                                mBar.panelExpansionChanged(PanelView.this, mExpandedFraction);
                            }


                            trackMovement(event);
                            trackMovement(event);
                            break;
                            break;
@@ -267,7 +303,8 @@ public class PanelView extends FrameLayout {
                            // preventing spurious flings due to touch screen jitter
                            // preventing spurious flings due to touch screen jitter
                            final float deltaY = Math.abs(mFinalTouchY - mInitialTouchY);
                            final float deltaY = Math.abs(mFinalTouchY - mInitialTouchY);
                            if (deltaY < mFlingGestureMinDistPx
                            if (deltaY < mFlingGestureMinDistPx
                                    || vel < mFlingExpandMinVelocityPx) {
                                    || vel < mFlingExpandMinVelocityPx
                                    || mJustPeeked) {
                                vel = 0;
                                vel = 0;
                            }
                            }


@@ -347,9 +384,13 @@ public class PanelView extends FrameLayout {




    public void setExpandedHeight(float height) {
    public void setExpandedHeight(float height) {
        if (DEBUG) LOG("setExpandedHeight(%.1f)", height);
        mTracking = mRubberbanding = false;
        mTracking = mRubberbanding = false;
        if (mTimeAnimator.isRunning()) {
            post(mStopAnimator);
            post(mStopAnimator);
        }
        setExpandedHeightInternal(height);
        setExpandedHeightInternal(height);
        mBar.panelExpansionChanged(PanelView.this, mExpandedFraction);
    }
    }


    @Override
    @Override