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

Commit 30bd64c8 authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Fix issue with floating rotation button being in the wrong corner (sysui)" into tm-qpr-dev

parents 28a58996 0d0a6775
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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>
+9 −2
Original line number Diff line number Diff line
@@ -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,
+18 −8
Original line number Diff line number Diff line
@@ -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,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
@@ -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")
            }
        }
}
+2 −1
Original line number Diff line number Diff line
@@ -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,
+102 −11
Original line number Diff line number Diff line
@@ -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
    }
}