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

Commit 89e1fec9 authored by Jim Miller's avatar Jim Miller Committed by Android (Google) Code Review
Browse files

Merge "Fit and finish for navbar camera affordance" into klp-dev

parents 81f429e0 f4db8f99
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ public class KeyguardViewStateManager implements
        SlidingChallengeLayout.OnChallengeScrolledListener,
        ChallengeLayout.OnBouncerStateChangedListener {

    private static final int WARP_FADE_DURATION = 250;
    private KeyguardWidgetPager mKeyguardWidgetPager;
    private ChallengeLayout mChallengeLayout;
    private KeyguardHostView mKeyguardHostView;
+3 −0
Original line number Diff line number Diff line
@@ -494,6 +494,9 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
    }

    public float getAlphaForPage(int screenCenter, int index, boolean showSidePages) {
        if (getPageWarpIndex() != -1) {
            return index == getPageWarpIndex() ? 1.0f : 0.0f;
        }
        if (showSidePages) {
            return 1f;
        } else {
+58 −12
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
    private static final boolean DEBUG = false;
    private static final boolean DEBUG_WARP = false;
    protected static final int INVALID_PAGE = -1;
    private static final int WARP_PEEK_ANIMATION_DURATION = 250;
    private static final float WARP_ANIMATE_AMOUNT = -40.0f; // in dip

    // the min drag distance for a fling to register, to prevent random page shifts
    private static final int MIN_LENGTH_FOR_FLING = 25;
@@ -253,8 +255,11 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
    private boolean mTopAlignPageWhenShrinkingForBouncer = false;

    // Page warping
    private int mPageSwapIndex = -1;
    private int mPageSwapIndex = -1; // the page we swapped out if needed
    private int mPageWarpIndex = -1; // the page we intend to warp

    private boolean mIsCameraEvent;
    private float mWarpPeekAmount;

    public interface PageSwitchListener {
        void onPageSwitching(View newPage, int newPageIndex);
@@ -303,10 +308,10 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
        mPagingTouchSlop = configuration.getScaledPagingTouchSlop();
        mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
        mDensity = getResources().getDisplayMetrics().density;
        mWarpPeekAmount = mDensity * WARP_ANIMATE_AMOUNT;

        // Scale the fling-to-delete threshold by the density
        mFlingToDeleteThresholdVelocity =
                (int) (mFlingToDeleteThresholdVelocity * mDensity);
        mFlingToDeleteThresholdVelocity = (int) (mFlingToDeleteThresholdVelocity * mDensity);

        mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity);
        mMinFlingVelocity = (int) (MIN_FLING_VELOCITY * mDensity);
@@ -478,9 +483,11 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
        if (DEBUG_WARP) Log.v(TAG, "pageBeginMoving(" + mIsPageMoving + ")");
        if (!mIsPageMoving) {
            mIsPageMoving = true;
            if (mPageSwapIndex != -1) {
            if (mPageWarpIndex != -1) {
                onPageBeginWarp();
                swapPages(mPageSwapIndex, getPageCount() - 1);
                if (mPageSwapIndex != -1) {
                    swapPages(mPageSwapIndex, mPageWarpIndex);
                }
            }
            onPageBeginMoving();
        }
@@ -490,15 +497,23 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
        if (DEBUG_WARP) Log.v(TAG, "pageEndMoving(" + mIsPageMoving + ")");
        if (mIsPageMoving) {
            mIsPageMoving = false;
            if (mPageWarpIndex != -1) {
                if (mPageSwapIndex != -1) {
                swapPages(mPageSwapIndex, getPageCount() - 1);
                    swapPages(mPageSwapIndex, mPageWarpIndex);
                    resetPageWarp();
                }
                onPageEndWarp();
                mPageSwapIndex = -1;
            }
            onPageEndMoving();
        }
    }

    private void resetPageWarp() {
        // TODO: Verify pages have been reset correctly
        mPageSwapIndex = -1;
        mPageWarpIndex = -1;
    }

    protected boolean isPageMoving() {
        return mIsPageMoving;
    }
@@ -757,7 +772,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
        // If a page was swapped when we rebuilt the layout, swap it again now.
        if (mPageSwapIndex  != -1) {
            if (DEBUG_WARP) Log.v(TAG, "onLayout: swapping pages");
            swapPages(mPageSwapIndex, getPageCount() - 1);
            swapPages(mPageSwapIndex, mPageWarpIndex);
        }
    }

@@ -1106,6 +1121,9 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
            }

            case MotionEvent.ACTION_DOWN: {
                if (mIsCameraEvent) {
                    animateWarpPageOnScreen();
                }
                // Remember where the motion event started
                saveDownState(ev);

@@ -1372,6 +1390,8 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc

            if (mTouchState == TOUCH_STATE_SCROLLING) {
                pageBeginMoving();
            } else {
                animateWarpPageOnScreen();
            }
            break;

@@ -1855,14 +1875,17 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc

    protected void snapToPage(int whichPage, int delta, int duration, boolean immediate) {
        if (mPageSwapIndex != -1 && whichPage == mPageSwapIndex) {
            // jump to the last page
            mNextPage = getPageCount() - 1;
            mNextPage = mPageWarpIndex; // jump to the warp page
            if (DEBUG_WARP) Log.v(TAG, "snapToPage(" + whichPage + ") : reset mPageSwapIndex");
            mPageSwapIndex = -1;
        } else {
            mNextPage = whichPage;
        }

        if (mPageWarpIndex != -1) {
            animateWarpPageOffScreen();
            resetPageWarp();
        }

        notifyPageSwitching(whichPage);
        View focusedChild = getFocusedChild();
        if (focusedChild != null && whichPage != mCurrentPage &&
@@ -2613,6 +2636,24 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
        mIsCameraEvent = false;
    }

    private void animateWarpPageOnScreen() {
        if (DEBUG_WARP) Log.v(TAG, "animateWarpPageOnScreen()");
        if (mPageWarpIndex != -1) {
            KeyguardWidgetFrame v = (KeyguardWidgetFrame) getPageAt(mPageWarpIndex);
            if (DEBUG_WARP) Log.v(TAG, "moving page on screen: Tx=" + v.getTranslationX());
            v.animate().translationX(mWarpPeekAmount).setDuration(WARP_PEEK_ANIMATION_DURATION);
        }
    }

    private void animateWarpPageOffScreen() {
        if (DEBUG_WARP) Log.v(TAG, "animateWarpPageOffScreen()");
        if (mPageWarpIndex != -1) {
            KeyguardWidgetFrame v = (KeyguardWidgetFrame) getPageAt(mPageWarpIndex);
            if (DEBUG_WARP) Log.v(TAG, "moving page off screen: Tx=" + v.getTranslationX());
            v.animate().translationX(0.0f).setDuration(WARP_PEEK_ANIMATION_DURATION);
        }
    }

    /**
     * Swaps the position of the views by setting the left and right edges appropriately.
     */
@@ -2631,6 +2672,11 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
        if (pageIndex != mCurrentPage + 1) {
            mPageSwapIndex = mCurrentPage + 1;
        }
        mPageWarpIndex = pageIndex;
    }

    protected int getPageWarpIndex() {
        return mPageWarpIndex;
    }

    public void endWarp() {
+6 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ public class DelegateViewHelper {
    RectF mInitialTouch = new RectF();
    private boolean mStarted;
    private boolean mSwapXY = false;
    private boolean mDisabled;

    public DelegateViewHelper(View sourceView) {
        setSourceView(sourceView);
@@ -49,7 +50,7 @@ public class DelegateViewHelper {
    }

    public boolean onInterceptTouchEvent(MotionEvent event) {
        if (mSourceView == null || mDelegateView == null
        if (mSourceView == null || mDelegateView == null || mDisabled
                || mBar.shouldDisableNavbarGestures()) {
            return false;
        }
@@ -142,4 +143,8 @@ public class DelegateViewHelper {
    public void setSwapXY(boolean swap) {
        mSwapXY = swap;
    }

    public void setDisabled(boolean disabled) {
        mDisabled = disabled;
    }
}
 No newline at end of file
+21 −1
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;

public class NavigationBarView extends LinearLayout {
    private static final int CAMERA_BUTTON_FADE_DURATION = 200;
    final static boolean DEBUG = false;
    final static String TAG = "PhoneStatusBar/NavigationBarView";

@@ -89,7 +90,26 @@ public class NavigationBarView extends LinearLayout {

    private final OnTouchListener mCameraTouchListener = new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
        public boolean onTouch(View cameraButtonView, MotionEvent event) {
            View searchLight = getSearchLight();
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    // disable search gesture while interacting with camera
                    mDelegateHelper.setDisabled(true);
                    cameraButtonView.animate().alpha(0.0f).setDuration(CAMERA_BUTTON_FADE_DURATION);
                    if (searchLight != null) {
                        searchLight.animate().alpha(0.0f).setDuration(CAMERA_BUTTON_FADE_DURATION);
                    }
                    break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL:
                    mDelegateHelper.setDisabled(false);
                    cameraButtonView.animate().alpha(1.0f).setDuration(CAMERA_BUTTON_FADE_DURATION);
                    if (searchLight != null) {
                        searchLight.animate().alpha(1.0f).setDuration(CAMERA_BUTTON_FADE_DURATION);
                    }
                    break;
            }
            return mTouchDelegate.dispatch(event);
        }
    };