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

Unverified Commit 4dd95913 authored by Shuhao Wu's avatar Shuhao Wu Committed by Michael Bestas
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 f494baf8
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3785,6 +3785,12 @@ public final class Settings {
          */
         public static final String VOLUME_KEY_CURSOR_CONTROL = "volume_key_cursor_control";

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

    boolean mShowMenu;
@@ -534,6 +535,11 @@ public class NavigationBarView extends LinearLayout {
        updateCurrentView();
    }

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

    public boolean needsReorient(int rotation) {
        return mCurrentRotation != rotation;
    }
@@ -567,6 +573,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
@@ -491,6 +491,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 −5
Original line number Diff line number Diff line
@@ -53,6 +53,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() {
@@ -80,6 +81,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
@@ -107,6 +109,7 @@ public class DeadZone extends View {
        mShouldFlash = dbg;
        mFlashFrac = 0f;
        postInvalidate();
        mFlashFrac = dbg ? 1f : 0f;
    }

    // I made you a touch event...
@@ -130,10 +133,19 @@ public class DeadZone extends View {
                Slog.v(TAG, this + " ACTION_DOWN: " + event.getX() + "," + event.getY());
            }
            int size = (int) getSize(event.getEventTime());
            // In the vertical orientation consume taps along the left edge.
            // In horizontal orientation consume taps along the top edge.
            final boolean consumeEvent = mVertical ? event.getX() < size : event.getY() < size;
            if (consumeEvent) {
            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() + ")");
                }
@@ -163,6 +175,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) {
@@ -170,7 +187,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 −3
Original line number Diff line number Diff line
@@ -430,6 +430,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    // This is for car dock and this is updated from resource.
    private boolean mEnableCarDockHomeCapture = true;

    boolean mNavigationBarLeftInLandscape = false; // Navigation bar left handed?

    boolean mBootMessageNeedsHiding;
    KeyguardServiceDelegate mKeyguardDelegate;
    final Runnable mWindowManagerDrawCallback = new Runnable() {
@@ -1029,7 +1031,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.DEV_FORCE_SHOW_NAVBAR), false, this,
                    UserHandle.USER_ALL);

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

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

            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,
@@ -3221,10 +3228,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            } else if (mNavigationBarPosition == NAV_BAR_RIGHT) {
                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;
                }
            } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
                if (transit == TRANSIT_EXIT
@@ -4696,6 +4705,34 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    // we can tell the app that it is covered by it.
                    mSystemBottom = mTmpNavigationFrame.top;
                }
            } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
                // Landscape screen; nav bar goes to the left.
                int right = overscanLeft + getNavigationBarWidth(displayRotation, uiMode);
                mTmpNavigationFrame.set(left, 0, right, displayHeight);
                mStableLeft = 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 - unless we expanded the status
                    // bar.
                    mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
                }
                if (navVisible && !navTranslucent && !navAllowedHidden
                        && !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 if (mNavigationBarPosition == NAV_BAR_RIGHT) {
                // Landscape screen; nav bar goes to the right.
                int left = displayWidth - overscanRight
Loading