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

Commit 3fe16ef8 authored by Shuhao Wu's avatar Shuhao Wu Committed by Steve Kondik
Browse files

[2/2] 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
parent d25b891d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3186,6 +3186,12 @@ public final class Settings {
         */
        public static final String VOICE_LAUNCH_INTENT = "voice_launch_intent";

        /**
         * 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
@@ -65,6 +65,7 @@ public class NavigationBarView extends LinearLayout {
    int mBarSize;
    boolean mVertical;
    boolean mScreenOn;
    boolean mLeftInLandscape;

    boolean mShowMenu;
    int mDisabledFlags = 0;
@@ -419,6 +420,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++) {
@@ -430,6 +436,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(mVertical);
+6 −0
Original line number Diff line number Diff line
@@ -447,6 +447,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);
            }
/*
            boolean showInsidePercent = Settings.System.getIntForUser(resolver,
                    Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0, mCurrentUserId) == 1;
+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);

+40 −4
Original line number Diff line number Diff line
@@ -313,6 +313,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];

@@ -762,7 +763,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.ACCELEROMETER_ROTATION_ANGLES), false, this,
                    UserHandle.USER_ALL);

            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.NAVBAR_LEFT_IN_LANDSCAPE), false, this,
                    UserHandle.USER_ALL);
            updateSettings();
        }

@@ -1668,6 +1671,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                mDevForceNavbar = devForceNavbar;
            }

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

            updateKeyAssignments();

            // Configure rotation lock.
@@ -2400,7 +2406,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                return isKeyguard ? -1 : R.anim.dock_top_enter;
            }
        } else if (win == mNavigationBar) {
            // 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) {
@@ -2412,10 +2418,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;
                }
            }
        }
@@ -3588,6 +3596,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