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

Commit 5dd6beee authored by Kshitij's avatar Kshitij
Browse files

fix: Improve translation reliability

- Often when rotating, translation of the wrong dimension is used
- This happens because the view draws before a new rotation is committed,
  causing DisplayController to report old dimensions
- Also readjust translation onConfigChanged/rotate
parent adb00510
Loading
Loading
Loading
Loading
+26 −9
Original line number Diff line number Diff line
@@ -219,9 +219,11 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
    private final RecentsHitboxExtender mHitboxExtender = new RecentsHitboxExtender();
    private ImageView mRecentsButton;
    private Space mSpace;
    private Point mWindow;
    private int mWindowWidth;
    private int mWindowHeight;
    private boolean mIsInHome = true;

    /** @noinspection SuspiciousNameCombination*/
    public NavbarButtonsViewController(TaskbarActivityContext context,
                                       @Nullable Context navigationBarPanelContext, NearestTouchFrame navButtonsView) {
        mContext = context;
@@ -237,7 +239,15 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
        mOnBackgroundIconColor = Utilities.isDarkTheme(context)
                ? context.getColor(R.color.taskbar_nav_icon_light_color)
                : context.getColor(R.color.taskbar_nav_icon_dark_color);
        mWindow = DisplayController.INSTANCE.get(context).getInfo().currentSize;
        boolean isLandscape = context.getDeviceProfile().isLandscape;
        Point window = DisplayController.INSTANCE.get(context).getInfo().currentSize;
        if (isLandscape) {
            mWindowWidth = window.y;
            mWindowHeight = window.x;
        } else {
            mWindowWidth = window.x;
            mWindowHeight = window.y;
        }
    }

    /**
@@ -672,20 +682,27 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
            // Additional spacing, eat up half of space between last icon and nav button
            navMarginEnd += res.getDimensionPixelSize(R.dimen.taskbar_hotseat_nav_spacing) / 2;
        }
        return ((float) mWindow.x / 2) - ((float) mNavButtonContainer.getMeasuredWidth() / 2) - navMarginEnd;
        boolean isLandscape = mContext.getDeviceProfile().isLandscape;
        return ((float) (isLandscape ? mWindowHeight : mWindowWidth) / 2)
                - ((float) mNavButtonContainer.getMeasuredWidth() / 2) - navMarginEnd;
    }


    /**
     * Sets the translationY of the nav buttons based on the current device state.
     * Sets the translations of the nav buttons based on the current device state.
     */

    public void updateNavButtonTranslations() {
        updateNavButtonTranslations(false);
    }

    public void updateNavButtonTranslations(boolean force) {
        if (mContext.isPhoneButtonNavMode() || NAV_TRANSLATION_DISABLED) {
            if (mWindow.x != 0) {
            if (mWindowWidth != 0) {
                TaskbarUIController uiController = mControllers.uiController;
                final boolean isInHome = (uiController instanceof LauncherTaskbarUIController
                        && ((LauncherTaskbarUIController) uiController).isInHome());
                if (isInHome != mIsInHome) {
                if (isInHome != mIsInHome || force) {
                    mIsInHome = isInHome;
                    float translation = getTranslationForNavContainer();
                    setAnimatedTranslationNavContainerX(isInHome ? 0 : translation);
@@ -766,7 +783,6 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
    }

    public void onConfigurationChanged(@Config int configChanges) {
        mWindow = DisplayController.INSTANCE.get(mContext).getInfo().currentSize;
        if (mFloatingRotationButton != null) {
            mFloatingRotationButton.onConfigurationChanged(configChanges);
        }
@@ -774,6 +790,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
            handleSetupUi();
        }
        updateButtonLayoutSpacing();
        updateNavButtonTranslations(true);
    }

    private void handleSetupUi() {
@@ -1038,7 +1055,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
     */
    public void onUiControllerChanged() {
        updateNavButtonInAppDisplayProgressForSysui();
        updateNavButtonTranslationY();
        updateNavButtonTranslations(true);
    }

    @Override