Loading packages/SystemUI/res/values/config.xml +4 −0 Original line number Diff line number Diff line Loading @@ -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> packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java +9 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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); Loading @@ -100,6 +103,7 @@ public class FloatingRotationButton implements RotationButton { mTaskbarLeftMarginResource = taskbarLeftMargin; mTaskbarBottomMarginResource = taskbarBottomMargin; mButtonDiameterResource = buttonDiameter; mFloatingRotationBtnPositionLeftResource = floatingRotationBtnPositionLeftResource; updateDimensionResources(); } Loading @@ -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, Loading packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButtonPositionCalculator.kt +18 −8 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -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 Loading Loading @@ -55,6 +55,7 @@ class FloatingRotationButtonPositionCalculator( ) private fun resolveGravity(rotation: Int): Int = if (floatingRotationButtonPositionLeft) { when (rotation) { Surface.ROTATION_0 -> Gravity.BOTTOM or Gravity.LEFT Surface.ROTATION_90 -> Gravity.BOTTOM or Gravity.RIGHT Loading @@ -62,4 +63,13 @@ class FloatingRotationButtonPositionCalculator( 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") } } } packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java +2 −1 Original line number Diff line number Diff line Loading @@ -301,7 +301,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, Loading packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/FloatingRotationButtonPositionCalculatorTest.kt +102 −11 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -60,6 +70,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase ) ), TestCase( calculator = posLeftCalculator, rotation = Surface.ROTATION_90, taskbarVisible = false, taskbarStashed = false, Loading @@ -70,6 +81,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase ) ), TestCase( calculator = posLeftCalculator, rotation = Surface.ROTATION_180, taskbarVisible = false, taskbarStashed = false, Loading @@ -80,6 +92,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase ) ), TestCase( calculator = posLeftCalculator, rotation = Surface.ROTATION_270, taskbarVisible = false, taskbarStashed = false, Loading @@ -90,6 +103,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase ) ), TestCase( calculator = posLeftCalculator, rotation = Surface.ROTATION_0, taskbarVisible = true, taskbarStashed = false, Loading @@ -100,6 +114,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase ) ), TestCase( calculator = posLeftCalculator, rotation = Surface.ROTATION_0, taskbarVisible = true, taskbarStashed = true, Loading @@ -110,6 +125,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase ) ), TestCase( calculator = posLeftCalculator, rotation = Surface.ROTATION_90, taskbarVisible = true, taskbarStashed = false, Loading @@ -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 } } Loading
packages/SystemUI/res/values/config.xml +4 −0 Original line number Diff line number Diff line Loading @@ -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>
packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java +9 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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); Loading @@ -100,6 +103,7 @@ public class FloatingRotationButton implements RotationButton { mTaskbarLeftMarginResource = taskbarLeftMargin; mTaskbarBottomMarginResource = taskbarBottomMargin; mButtonDiameterResource = buttonDiameter; mFloatingRotationBtnPositionLeftResource = floatingRotationBtnPositionLeftResource; updateDimensionResources(); } Loading @@ -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, Loading
packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButtonPositionCalculator.kt +18 −8 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -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 Loading Loading @@ -55,6 +55,7 @@ class FloatingRotationButtonPositionCalculator( ) private fun resolveGravity(rotation: Int): Int = if (floatingRotationButtonPositionLeft) { when (rotation) { Surface.ROTATION_0 -> Gravity.BOTTOM or Gravity.LEFT Surface.ROTATION_90 -> Gravity.BOTTOM or Gravity.RIGHT Loading @@ -62,4 +63,13 @@ class FloatingRotationButtonPositionCalculator( 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") } } }
packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java +2 −1 Original line number Diff line number Diff line Loading @@ -301,7 +301,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, Loading
packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/FloatingRotationButtonPositionCalculatorTest.kt +102 −11 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -60,6 +70,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase ) ), TestCase( calculator = posLeftCalculator, rotation = Surface.ROTATION_90, taskbarVisible = false, taskbarStashed = false, Loading @@ -70,6 +81,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase ) ), TestCase( calculator = posLeftCalculator, rotation = Surface.ROTATION_180, taskbarVisible = false, taskbarStashed = false, Loading @@ -80,6 +92,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase ) ), TestCase( calculator = posLeftCalculator, rotation = Surface.ROTATION_270, taskbarVisible = false, taskbarStashed = false, Loading @@ -90,6 +103,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase ) ), TestCase( calculator = posLeftCalculator, rotation = Surface.ROTATION_0, taskbarVisible = true, taskbarStashed = false, Loading @@ -100,6 +114,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase ) ), TestCase( calculator = posLeftCalculator, rotation = Surface.ROTATION_0, taskbarVisible = true, taskbarStashed = true, Loading @@ -110,6 +125,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase ) ), TestCase( calculator = posLeftCalculator, rotation = Surface.ROTATION_90, taskbarVisible = true, taskbarStashed = false, Loading @@ -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 } }