Fix issue with floating rotation button being in the wrong corner (sysui)

- Add option for the rotation button to be positioned to the right
  when in ROTATION_0

Bug: 265197526
Test: atest FloatingRotationButtonPositionCalculatorTest
Test: foldable-folded (floating rot button in sysui, natural rot=rot_0)
      foldable-unfolded (floating rot button in launcher, natural rot=rot_0)
      tablet (floating rot in launcher, natural rot=rot_270)
Change-Id: I1f7fb7953e2846c46c15473a7980ffd447956310
This commit is contained in:
Winson Chung
2023-01-24 21:20:06 +00:00
parent 6fb611c962
commit 0d0a67757e
5 changed files with 135 additions and 26 deletions

View File

@@ -828,4 +828,8 @@
<string name="config_wallpaperPickerPackage" translatable="false">
com.android.wallpaper
</string>
<!-- Whether the floating rotation button should be on the left/right in the device's natural
orientation -->
<bool name="floating_rotation_button_position_left">true</bool>
</resources>

View File

@@ -35,6 +35,7 @@ import android.view.WindowManager.LayoutParams;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.FrameLayout;
import androidx.annotation.BoolRes;
import androidx.core.view.OneShotPreDrawListener;
import com.android.systemui.shared.rotation.FloatingRotationButtonPositionCalculator.Position;
@@ -65,6 +66,8 @@ public class FloatingRotationButton implements RotationButton {
private final int mTaskbarBottomMarginResource;
@DimenRes
private final int mButtonDiameterResource;
@BoolRes
private final int mFloatingRotationBtnPositionLeftResource;
private AnimatedVectorDrawable mAnimatedDrawable;
private boolean mIsShowing;
@@ -84,7 +87,7 @@ public class FloatingRotationButton implements RotationButton {
@LayoutRes int layout, @IdRes int keyButtonId, @DimenRes int minMargin,
@DimenRes int roundedContentPadding, @DimenRes int taskbarLeftMargin,
@DimenRes int taskbarBottomMargin, @DimenRes int buttonDiameter,
@DimenRes int rippleMaxWidth) {
@DimenRes int rippleMaxWidth, @BoolRes int floatingRotationBtnPositionLeftResource) {
mWindowManager = context.getSystemService(WindowManager.class);
mKeyButtonContainer = (ViewGroup) LayoutInflater.from(context).inflate(layout, null);
mKeyButtonView = mKeyButtonContainer.findViewById(keyButtonId);
@@ -100,6 +103,7 @@ public class FloatingRotationButton implements RotationButton {
mTaskbarLeftMarginResource = taskbarLeftMargin;
mTaskbarBottomMarginResource = taskbarBottomMargin;
mButtonDiameterResource = buttonDiameter;
mFloatingRotationBtnPositionLeftResource = floatingRotationBtnPositionLeftResource;
updateDimensionResources();
}
@@ -116,8 +120,11 @@ public class FloatingRotationButton implements RotationButton {
int taskbarMarginBottom =
res.getDimensionPixelSize(mTaskbarBottomMarginResource);
boolean floatingRotationButtonPositionLeft =
res.getBoolean(mFloatingRotationBtnPositionLeftResource);
mPositionCalculator = new FloatingRotationButtonPositionCalculator(defaultMargin,
taskbarMarginLeft, taskbarMarginBottom);
taskbarMarginLeft, taskbarMarginBottom, floatingRotationButtonPositionLeft);
final int diameter = res.getDimensionPixelSize(mButtonDiameterResource);
mContainerSize = diameter + Math.max(defaultMargin, Math.max(taskbarMarginLeft,

View File

@@ -10,7 +10,8 @@ import android.view.Surface
class FloatingRotationButtonPositionCalculator(
private val defaultMargin: Int,
private val taskbarMarginLeft: Int,
private val taskbarMarginBottom: Int
private val taskbarMarginBottom: Int,
private val floatingRotationButtonPositionLeft: Boolean
) {
fun calculatePosition(
@@ -18,7 +19,6 @@ class FloatingRotationButtonPositionCalculator(
taskbarVisible: Boolean,
taskbarStashed: Boolean
): Position {
val isTaskbarSide = currentRotation == Surface.ROTATION_0
|| currentRotation == Surface.ROTATION_90
val useTaskbarMargin = isTaskbarSide && taskbarVisible && !taskbarStashed
@@ -55,11 +55,21 @@ class FloatingRotationButtonPositionCalculator(
)
private fun resolveGravity(rotation: Int): Int =
when (rotation) {
Surface.ROTATION_0 -> Gravity.BOTTOM or Gravity.LEFT
Surface.ROTATION_90 -> Gravity.BOTTOM or Gravity.RIGHT
Surface.ROTATION_180 -> Gravity.TOP or Gravity.RIGHT
Surface.ROTATION_270 -> Gravity.TOP or Gravity.LEFT
else -> throw IllegalArgumentException("Invalid rotation $rotation")
if (floatingRotationButtonPositionLeft) {
when (rotation) {
Surface.ROTATION_0 -> Gravity.BOTTOM or Gravity.LEFT
Surface.ROTATION_90 -> Gravity.BOTTOM or Gravity.RIGHT
Surface.ROTATION_180 -> Gravity.TOP or Gravity.RIGHT
Surface.ROTATION_270 -> Gravity.TOP or Gravity.LEFT
else -> throw IllegalArgumentException("Invalid rotation $rotation")
}
} else {
when (rotation) {
Surface.ROTATION_0 -> Gravity.BOTTOM or Gravity.RIGHT
Surface.ROTATION_90 -> Gravity.TOP or Gravity.RIGHT
Surface.ROTATION_180 -> Gravity.TOP or Gravity.LEFT
Surface.ROTATION_270 -> Gravity.BOTTOM or Gravity.LEFT
else -> throw IllegalArgumentException("Invalid rotation $rotation")
}
}
}

View File

@@ -16,13 +16,11 @@
package com.android.systemui.navigationbar;
import static android.app.ActivityManager.LOCK_TASK_MODE_PINNED;
import static android.inputmethodservice.InputMethodService.canImeRenderGesturalNavButtons;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_HOME_DISABLED;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_OVERVIEW_DISABLED;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_PINNING;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SEARCH_DISABLED;
import static com.android.systemui.shared.system.QuickStepContract.isGesturalMode;
@@ -79,9 +77,7 @@ import com.android.systemui.shade.NotificationPanelViewController;
import com.android.systemui.shared.rotation.FloatingRotationButton;
import com.android.systemui.shared.rotation.RotationButton.RotationButtonUpdatesCallback;
import com.android.systemui.shared.rotation.RotationButtonController;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.shared.system.TaskStackChangeListener;
import com.android.systemui.statusbar.phone.AutoHideController;
import com.android.systemui.statusbar.phone.CentralSurfaces;
import com.android.systemui.statusbar.phone.LightBarTransitionsController;
@@ -303,7 +299,8 @@ public class NavigationBarView extends FrameLayout {
R.dimen.floating_rotation_button_taskbar_left_margin,
R.dimen.floating_rotation_button_taskbar_bottom_margin,
R.dimen.floating_rotation_button_diameter,
R.dimen.key_button_ripple_max_width);
R.dimen.key_button_ripple_max_width,
R.bool.floating_rotation_button_position_left);
mRotationButtonController = new RotationButtonController(mLightContext, mLightIconColor,
mDarkIconColor, R.drawable.ic_sysbar_rotate_button_ccw_start_0,
R.drawable.ic_sysbar_rotate_button_ccw_start_90,

View File

@@ -16,40 +16,50 @@ import org.junit.runners.Parameterized
internal class FloatingRotationButtonPositionCalculatorTest(private val testCase: TestCase)
: SysuiTestCase() {
private val calculator = FloatingRotationButtonPositionCalculator(
MARGIN_DEFAULT, MARGIN_TASKBAR_LEFT, MARGIN_TASKBAR_BOTTOM
)
@Test
fun calculatePosition() {
val position = calculator.calculatePosition(
val position = testCase.calculator.calculatePosition(
testCase.rotation,
testCase.taskbarVisible,
testCase.taskbarStashed
)
assertThat(position).isEqualTo(testCase.expectedPosition)
}
internal class TestCase(
val calculator: FloatingRotationButtonPositionCalculator,
val rotation: Int,
val taskbarVisible: Boolean,
val taskbarStashed: Boolean,
val expectedPosition: Position
) {
override fun toString(): String =
"when rotation = $rotation, " +
"when calculator = $calculator, " +
"rotation = $rotation, " +
"taskbarVisible = $taskbarVisible, " +
"taskbarStashed = $taskbarStashed - " +
"expected $expectedPosition"
}
companion object {
private const val MARGIN_DEFAULT = 10
private const val MARGIN_TASKBAR_LEFT = 20
private const val MARGIN_TASKBAR_BOTTOM = 30
private val posLeftCalculator = FloatingRotationButtonPositionCalculator(
MARGIN_DEFAULT, MARGIN_TASKBAR_LEFT, MARGIN_TASKBAR_BOTTOM, true
)
private val posRightCalculator = FloatingRotationButtonPositionCalculator(
MARGIN_DEFAULT, MARGIN_TASKBAR_LEFT, MARGIN_TASKBAR_BOTTOM, false
)
@Parameterized.Parameters(name = "{0}")
@JvmStatic
fun getParams(): Collection<TestCase> =
listOf(
// Position left
TestCase(
calculator = posLeftCalculator,
rotation = Surface.ROTATION_0,
taskbarVisible = false,
taskbarStashed = false,
@@ -60,6 +70,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
)
),
TestCase(
calculator = posLeftCalculator,
rotation = Surface.ROTATION_90,
taskbarVisible = false,
taskbarStashed = false,
@@ -70,6 +81,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
)
),
TestCase(
calculator = posLeftCalculator,
rotation = Surface.ROTATION_180,
taskbarVisible = false,
taskbarStashed = false,
@@ -80,6 +92,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
)
),
TestCase(
calculator = posLeftCalculator,
rotation = Surface.ROTATION_270,
taskbarVisible = false,
taskbarStashed = false,
@@ -90,6 +103,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
)
),
TestCase(
calculator = posLeftCalculator,
rotation = Surface.ROTATION_0,
taskbarVisible = true,
taskbarStashed = false,
@@ -100,6 +114,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
)
),
TestCase(
calculator = posLeftCalculator,
rotation = Surface.ROTATION_0,
taskbarVisible = true,
taskbarStashed = true,
@@ -110,6 +125,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
)
),
TestCase(
calculator = posLeftCalculator,
rotation = Surface.ROTATION_90,
taskbarVisible = true,
taskbarStashed = false,
@@ -118,11 +134,86 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
translationX = -MARGIN_TASKBAR_LEFT,
translationY = -MARGIN_TASKBAR_BOTTOM
)
),
// Position right
TestCase(
calculator = posRightCalculator,
rotation = Surface.ROTATION_0,
taskbarVisible = false,
taskbarStashed = false,
expectedPosition = Position(
gravity = Gravity.BOTTOM or Gravity.RIGHT,
translationX = -MARGIN_DEFAULT,
translationY = -MARGIN_DEFAULT
)
),
TestCase(
calculator = posRightCalculator,
rotation = Surface.ROTATION_90,
taskbarVisible = false,
taskbarStashed = false,
expectedPosition = Position(
gravity = Gravity.TOP or Gravity.RIGHT,
translationX = -MARGIN_DEFAULT,
translationY = MARGIN_DEFAULT
)
),
TestCase(
calculator = posRightCalculator,
rotation = Surface.ROTATION_180,
taskbarVisible = false,
taskbarStashed = false,
expectedPosition = Position(
gravity = Gravity.TOP or Gravity.LEFT,
translationX = MARGIN_DEFAULT,
translationY = MARGIN_DEFAULT
)
),
TestCase(
calculator = posRightCalculator,
rotation = Surface.ROTATION_270,
taskbarVisible = false,
taskbarStashed = false,
expectedPosition = Position(
gravity = Gravity.BOTTOM or Gravity.LEFT,
translationX = MARGIN_DEFAULT,
translationY = -MARGIN_DEFAULT
)
),
TestCase(
calculator = posRightCalculator,
rotation = Surface.ROTATION_0,
taskbarVisible = true,
taskbarStashed = false,
expectedPosition = Position(
gravity = Gravity.BOTTOM or Gravity.RIGHT,
translationX = -MARGIN_TASKBAR_LEFT,
translationY = -MARGIN_TASKBAR_BOTTOM
)
),
TestCase(
calculator = posRightCalculator,
rotation = Surface.ROTATION_0,
taskbarVisible = true,
taskbarStashed = true,
expectedPosition = Position(
gravity = Gravity.BOTTOM or Gravity.RIGHT,
translationX = -MARGIN_DEFAULT,
translationY = -MARGIN_DEFAULT
)
),
TestCase(
calculator = posRightCalculator,
rotation = Surface.ROTATION_90,
taskbarVisible = true,
taskbarStashed = false,
expectedPosition = Position(
gravity = Gravity.TOP or Gravity.RIGHT,
translationX = -MARGIN_TASKBAR_LEFT,
translationY = MARGIN_TASKBAR_BOTTOM
)
)
)
private const val MARGIN_DEFAULT = 10
private const val MARGIN_TASKBAR_LEFT = 20
private const val MARGIN_TASKBAR_BOTTOM = 30
}
}