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

Commit 2a2cc073 authored by Shuhao Wu's avatar Shuhao Wu Committed by Steve Kondik
Browse files

Left handed navbar during landscape mode

This patch allows for the navbar to be moved to the left side of the
screen during landscape mode. Left handed people are more used to this
option.

This patch must go with another patch that changes
packages/apps/Settings

Screenshot: http://i.imgur.com/jWqJcEV.png

Change-Id: Ic95e3fda1f55efd2ec908c8d7226e638ec0ab80a

Expanded Desktop : Fix Left handed navbar during landscape mode

from http://review.cyanogenmod.org/#/c/57454
when you enable expanded desktop and left handed navbar.
you need to swipe from right edge to show navbar.
but this patch will change to swipe from left edge to show navbar.
Video avalible at http://youtu.be/rUy14LQj9iE

Patchset2 : change tab to whitespace
Patchset3 : remove \r after @override in PhoneWindowManager.java
Patchset4 : Update commit message
Patchset5 : Address code formating comments
Patchset6 : Whitespace

Altaf-Mahdi
Add left gesture for edge gesture service

Change-Id: I65a15c6f5e662e429a818484de6b71e81c7ae713
parent b16a02f9
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3738,6 +3738,12 @@ public final class Settings {
         */
        public static final String VOLUME_WAKE_SCREEN = "volume_wake_screen";

        /**
         * Whether navigation bar is placed on the left side in landscape mode
         * @hide
         */
        public static final String NAVBAR_LEFT_IN_LANDSCAPE = "navigation_bar_left";

        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
+7 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ public class NavigationBarView extends LinearLayout {
    int mBarSize;
    boolean mVertical;
    boolean mScreenOn;
    boolean mLeftInLandscape;

    boolean mShowMenu;
    int mDisabledFlags = 0;
@@ -451,6 +452,11 @@ public class NavigationBarView extends LinearLayout {
        return mVertical;
    }

    public void setLeftInLandscape(boolean leftInLandscape) {
        mLeftInLandscape = leftInLandscape;
        mDeadZone.setStartFromRight(leftInLandscape);
    }

    public void reorient() {
        final int rot = mDisplay.getRotation();
        for (int i=0; i<4; i++) {
@@ -463,6 +469,7 @@ public class NavigationBarView extends LinearLayout {
        getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener);

        mDeadZone = (DeadZone) mCurrentView.findViewById(R.id.deadzone);
        mDeadZone.setStartFromRight(mLeftInLandscape);

        // force the low profile & disabled states into compliance
        mBarTransitions.init();
+6 −0
Original line number Diff line number Diff line
@@ -418,6 +418,12 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
            mAutomaticBrightness = mode != Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
            mBrightnessControl = Settings.System.getInt(
                    resolver, Settings.System.STATUS_BAR_BRIGHTNESS_CONTROL, 0) == 1;

            if (mNavigationBarView != null) {
                boolean navLeftInLandscape = Settings.System.getInt(resolver,
                        Settings.System.NAVBAR_LEFT_IN_LANDSCAPE, 0) == 1;
                mNavigationBarView.setLeftInLandscape(navLeftInLandscape);
            }
        }
    }

+32 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ public class DeadZone extends View {
    // mHold ms, then move back over the course of mDecay ms
    private int mHold, mDecay;
    private boolean mVertical;
    private boolean mStartFromRight;
    private long mLastPokeTime;

    private final Runnable mDebugFlash = new Runnable() {
@@ -73,6 +74,7 @@ public class DeadZone extends View {

        int index = a.getInt(R.styleable.DeadZone_orientation, -1);
        mVertical = (index == VERTICAL);
        mStartFromRight = false; // Assume deadzone is starting from the left side of the zone

        if (DEBUG)
            Slog.v(TAG, this + " size=[" + mSizeMin + "-" + mSizeMax + "] hold=" + mHold
@@ -100,6 +102,7 @@ public class DeadZone extends View {
        mShouldFlash = dbg;
        mFlashFrac = 0f;
        postInvalidate();
        mFlashFrac = dbg ? 1f : 0f;
    }

    // I made you a touch event...
@@ -117,7 +120,19 @@ public class DeadZone extends View {
                Slog.v(TAG, this + " ACTION_DOWN: " + event.getX() + "," + event.getY());
            }
            int size = (int) getSize(event.getEventTime());
            if ((mVertical && event.getX() < size) || event.getY() < size) {
            boolean isCaptured;
            if (mVertical && mStartFromRight) {
                // Landscape on the left side of the screen
                float pixelsFromRight = getWidth() - event.getX();
                isCaptured = 0 <= pixelsFromRight && pixelsFromRight < size;
            } else if (mVertical) {
                // Landscape
                isCaptured = event.getX() < size;
            } else {
                // Portrait
                isCaptured = event.getY() < size;
            }
            if (isCaptured) {
                if (CHATTY) {
                    Slog.v(TAG, "consuming errant click: (" + event.getX() + "," + event.getY() + ")");
                }
@@ -147,6 +162,11 @@ public class DeadZone extends View {
        return mFlashFrac;
    }

    public void setStartFromRight(boolean startFromRight) {
        mStartFromRight = startFromRight;
        if (mShouldFlash) postInvalidate();
    }

    @Override
    public void onDraw(Canvas can) {
        if (!mShouldFlash || mFlashFrac <= 0f) {
@@ -154,7 +174,17 @@ public class DeadZone extends View {
        }

        final int size = (int) getSize(SystemClock.uptimeMillis());
        can.clipRect(0, 0, mVertical ? size : can.getWidth(), mVertical ? can.getHeight() : size);
        if (mVertical && mStartFromRight) {
            // Landscape on the left side of the screen
            can.clipRect(can.getWidth() - size, 0, can.getWidth(), can.getHeight());
        } else if (mVertical) {
            // Landscape
            can.clipRect(0, 0, size, can.getHeight());
        } else {
            // Portrait
            can.clipRect(0, 0, can.getWidth(), size);
        }

        final float frac = DEBUG ? (mFlashFrac - 0.5f) + 0.5f : mFlashFrac;
        can.drawARGB((int) (frac * 0xFF), 0xDD, 0xEE, 0xAA);

+54 −4
Original line number Diff line number Diff line
@@ -363,6 +363,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    boolean mCanHideNavigationBar = false;
    boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
    boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
    boolean mNavigationBarLeftInLandscape = false; // Navigation bar left handed?
    int[] mNavigationBarHeightForRotation = new int[4];
    int[] mNavigationBarWidthForRotation = new int[4];

@@ -885,6 +886,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.VOLUME_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.NAVBAR_LEFT_IN_LANDSCAPE), false, this,
                    UserHandle.USER_ALL);
            updateSettings();
        }

@@ -949,6 +953,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                target = mStatusBar;
            } else if (position == EdgeGesturePosition.BOTTOM  && mNavigationBarOnBottom) {
                target = mNavigationBar;
            } else if (position == EdgeGesturePosition.LEFT
                    && !mNavigationBarOnBottom && mNavigationBarLeftInLandscape) {
                target = mNavigationBar;
            } else if (position == EdgeGesturePosition.RIGHT && !mNavigationBarOnBottom) {
                target = mNavigationBar;
            }
@@ -977,6 +984,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            if (mNavigationBar != null && !mNavigationBar.isVisibleLw()) {
                if (mNavigationBarOnBottom) {
                    flags |= EdgeGesturePosition.BOTTOM.FLAG;
                } else if (mNavigationBarLeftInLandscape) {
                    flags |= EdgeGesturePosition.LEFT.FLAG;
                } else {
                    flags |= EdgeGesturePosition.RIGHT.FLAG;
                }
@@ -1739,7 +1748,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    }
                    @Override
                    public void onSwipeFromRight() {
                        if (mNavigationBar != null && !mNavigationBarOnBottom) {
                        if (mNavigationBar != null && !mNavigationBarOnBottom &&
                                !mNavigationBarLeftInLandscape) {
                            requestTransientBars(mNavigationBar);
                        }
                    }
                    @Override
                    public void onSwipeFromLeft() {
                        if (mNavigationBar != null && !mNavigationBarOnBottom &&
                                mNavigationBarLeftInLandscape) {
                            requestTransientBars(mNavigationBar);
                        }
                    }
@@ -2108,6 +2125,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                updateEdgeGestureListenerState();
            }

            mNavigationBarLeftInLandscape = Settings.System.getInt(resolver,
                    Settings.System.NAVBAR_LEFT_IN_LANDSCAPE, 0) == 1;

            // Configure rotation lock.
            int userRotation = Settings.System.getIntForUser(resolver,
                    Settings.System.USER_ROTATION, Surface.ROTATION_0,
@@ -2875,7 +2895,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            if (win.getAttrs().windowAnimations != 0) {
                return 0;
            }
            // This can be on either the bottom or the right.
            // This can be on either the bottom, left, or the right.
            if (mNavigationBarOnBottom) {
                if (transit == TRANSIT_EXIT
                        || transit == TRANSIT_HIDE) {
@@ -2887,10 +2907,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            } else {
                if (transit == TRANSIT_EXIT
                        || transit == TRANSIT_HIDE) {
                    return R.anim.dock_right_exit;
                    return mNavigationBarLeftInLandscape
                            ? R.anim.dock_left_exit : R.anim.dock_right_exit;
                } else if (transit == TRANSIT_ENTER
                        || transit == TRANSIT_SHOW) {
                    return R.anim.dock_right_enter;
                    return mNavigationBarLeftInLandscape
                            ? R.anim.dock_left_enter : R.anim.dock_right_enter;
                }
            }
        }
@@ -4119,6 +4141,34 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                        // we can tell the app that it is covered by it.
                        mSystemBottom = mTmpNavigationFrame.top;
                    }
                } else if (mNavigationBarLeftInLandscape) {
                    // Landscape screen; nav bar goes to the left.
                    int right = overscanLeft + mNavigationBarWidthForRotation[displayRotation];
                    mTmpNavigationFrame.set(0, 0, right, displayHeight);
                    mStableLeft = mStableFullscreenLeft = mTmpNavigationFrame.right;
                    mStableFullscreenLeft = mTmpNavigationFrame.right;
                    if (transientNavBarShowing) {
                        mNavigationBarController.setBarShowingLw(true);
                    } else if (navVisible) {
                        mNavigationBarController.setBarShowingLw(true);
                        mDockLeft = mTmpNavigationFrame.right;
                        mRestrictedScreenLeft = mDockLeft;
                        mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
                        mRestrictedOverscanScreenLeft = mRestrictedScreenLeft;
                        mRestrictedOverscanScreenWidth = mDockRight
                                - mRestrictedOverscanScreenLeft;
                    } else {
                        // We currently want to hide the navigation UI.
                        mNavigationBarController.setBarShowingLw(false);
                    }

                    if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
                            && !mNavigationBarController.wasRecentlyTranslucent()) {
                        // If the nav bar is currently requested to be visible,
                        // and not in the process of animating on or off, then
                        // we can tell the app that it is covered by it.
                        mSystemLeft = mTmpNavigationFrame.right;
                    }
                } else {
                    // Landscape screen; nav bar goes to the right.
                    int left = displayWidth - overscanRight
Loading