Allow LauncherState to define floating search side margins.

This lets home screen align to workspace icons while All Apps
aligns with those icons. In addition, on tablets where the QSB
is inlined with the hotseat, floating search bar can also move
horizontally accordingly.

Bug: 275635606
Bug: 259619990
Test: Manual on tablet as well as foldable.
Flag: ENABLE_FLOATING_SEARCH_BAR

Change-Id: I67745c66390736cdf39d969ef7767096ae13c671
diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java
index 035b9c8..bfbca65 100644
--- a/src/com/android/launcher3/LauncherState.java
+++ b/src/com/android/launcher3/LauncherState.java
@@ -33,6 +33,7 @@
 
 import android.content.Context;
 import android.graphics.Color;
+import android.view.View;
 import android.view.animation.Interpolator;
 
 import androidx.annotation.FloatRange;
@@ -218,6 +219,34 @@
                 : -dp.hotseatQsbHeight;
     }
 
+    /**
+     * How far from the start of the screen the <em>floating</em> search bar should rest.
+     * <p>
+     * To use original margin, return a negative value.
+     */
+    public int getFloatingSearchBarRestingMarginStart(Launcher launcher) {
+        boolean isRtl = Utilities.isRtl(launcher.getResources());
+        View qsb = launcher.getHotseat().getQsb();
+        return isRtl ? launcher.getHotseat().getRight() - qsb.getRight() : qsb.getLeft();
+    }
+
+    /**
+     * How far from the end of the screen the <em>floating</em> search bar should rest.
+     * <p>
+     * To use original margin, return a negative value.
+     */
+    public int getFloatingSearchBarRestingMarginEnd(Launcher launcher) {
+        DeviceProfile dp = launcher.getDeviceProfile();
+        if (dp.isQsbInline) {
+            int marginStart = getFloatingSearchBarRestingMarginStart(launcher);
+            return dp.widthPx - marginStart - dp.hotseatQsbWidth;
+        }
+
+        boolean isRtl = Utilities.isRtl(launcher.getResources());
+        View qsb = launcher.getHotseat().getQsb();
+        return isRtl ? qsb.getLeft() : launcher.getHotseat().getRight() - qsb.getRight();
+    }
+
     /** Whether the <em>floating</em> search bar should use the pill UI when not focused. */
     public boolean shouldFloatingSearchBarUsePillWhenUnfocused(Launcher launcher) {
         return false;