Merge "Fix issue with floating rotation button being in the wrong corner (sysui)" into tm-qpr-dev
This commit is contained in:
@@ -828,4 +828,8 @@
|
|||||||
<string name="config_wallpaperPickerPackage" translatable="false">
|
<string name="config_wallpaperPickerPackage" translatable="false">
|
||||||
com.android.wallpaper
|
com.android.wallpaper
|
||||||
</string>
|
</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>
|
</resources>
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import android.view.WindowManager.LayoutParams;
|
|||||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
import androidx.annotation.BoolRes;
|
||||||
import androidx.core.view.OneShotPreDrawListener;
|
import androidx.core.view.OneShotPreDrawListener;
|
||||||
|
|
||||||
import com.android.systemui.shared.rotation.FloatingRotationButtonPositionCalculator.Position;
|
import com.android.systemui.shared.rotation.FloatingRotationButtonPositionCalculator.Position;
|
||||||
@@ -65,6 +66,8 @@ public class FloatingRotationButton implements RotationButton {
|
|||||||
private final int mTaskbarBottomMarginResource;
|
private final int mTaskbarBottomMarginResource;
|
||||||
@DimenRes
|
@DimenRes
|
||||||
private final int mButtonDiameterResource;
|
private final int mButtonDiameterResource;
|
||||||
|
@BoolRes
|
||||||
|
private final int mFloatingRotationBtnPositionLeftResource;
|
||||||
|
|
||||||
private AnimatedVectorDrawable mAnimatedDrawable;
|
private AnimatedVectorDrawable mAnimatedDrawable;
|
||||||
private boolean mIsShowing;
|
private boolean mIsShowing;
|
||||||
@@ -84,7 +87,7 @@ public class FloatingRotationButton implements RotationButton {
|
|||||||
@LayoutRes int layout, @IdRes int keyButtonId, @DimenRes int minMargin,
|
@LayoutRes int layout, @IdRes int keyButtonId, @DimenRes int minMargin,
|
||||||
@DimenRes int roundedContentPadding, @DimenRes int taskbarLeftMargin,
|
@DimenRes int roundedContentPadding, @DimenRes int taskbarLeftMargin,
|
||||||
@DimenRes int taskbarBottomMargin, @DimenRes int buttonDiameter,
|
@DimenRes int taskbarBottomMargin, @DimenRes int buttonDiameter,
|
||||||
@DimenRes int rippleMaxWidth) {
|
@DimenRes int rippleMaxWidth, @BoolRes int floatingRotationBtnPositionLeftResource) {
|
||||||
mWindowManager = context.getSystemService(WindowManager.class);
|
mWindowManager = context.getSystemService(WindowManager.class);
|
||||||
mKeyButtonContainer = (ViewGroup) LayoutInflater.from(context).inflate(layout, null);
|
mKeyButtonContainer = (ViewGroup) LayoutInflater.from(context).inflate(layout, null);
|
||||||
mKeyButtonView = mKeyButtonContainer.findViewById(keyButtonId);
|
mKeyButtonView = mKeyButtonContainer.findViewById(keyButtonId);
|
||||||
@@ -100,6 +103,7 @@ public class FloatingRotationButton implements RotationButton {
|
|||||||
mTaskbarLeftMarginResource = taskbarLeftMargin;
|
mTaskbarLeftMarginResource = taskbarLeftMargin;
|
||||||
mTaskbarBottomMarginResource = taskbarBottomMargin;
|
mTaskbarBottomMarginResource = taskbarBottomMargin;
|
||||||
mButtonDiameterResource = buttonDiameter;
|
mButtonDiameterResource = buttonDiameter;
|
||||||
|
mFloatingRotationBtnPositionLeftResource = floatingRotationBtnPositionLeftResource;
|
||||||
|
|
||||||
updateDimensionResources();
|
updateDimensionResources();
|
||||||
}
|
}
|
||||||
@@ -116,8 +120,11 @@ public class FloatingRotationButton implements RotationButton {
|
|||||||
int taskbarMarginBottom =
|
int taskbarMarginBottom =
|
||||||
res.getDimensionPixelSize(mTaskbarBottomMarginResource);
|
res.getDimensionPixelSize(mTaskbarBottomMarginResource);
|
||||||
|
|
||||||
|
boolean floatingRotationButtonPositionLeft =
|
||||||
|
res.getBoolean(mFloatingRotationBtnPositionLeftResource);
|
||||||
|
|
||||||
mPositionCalculator = new FloatingRotationButtonPositionCalculator(defaultMargin,
|
mPositionCalculator = new FloatingRotationButtonPositionCalculator(defaultMargin,
|
||||||
taskbarMarginLeft, taskbarMarginBottom);
|
taskbarMarginLeft, taskbarMarginBottom, floatingRotationButtonPositionLeft);
|
||||||
|
|
||||||
final int diameter = res.getDimensionPixelSize(mButtonDiameterResource);
|
final int diameter = res.getDimensionPixelSize(mButtonDiameterResource);
|
||||||
mContainerSize = diameter + Math.max(defaultMargin, Math.max(taskbarMarginLeft,
|
mContainerSize = diameter + Math.max(defaultMargin, Math.max(taskbarMarginLeft,
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ import android.view.Surface
|
|||||||
class FloatingRotationButtonPositionCalculator(
|
class FloatingRotationButtonPositionCalculator(
|
||||||
private val defaultMargin: Int,
|
private val defaultMargin: Int,
|
||||||
private val taskbarMarginLeft: Int,
|
private val taskbarMarginLeft: Int,
|
||||||
private val taskbarMarginBottom: Int
|
private val taskbarMarginBottom: Int,
|
||||||
|
private val floatingRotationButtonPositionLeft: Boolean
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun calculatePosition(
|
fun calculatePosition(
|
||||||
@@ -18,7 +19,6 @@ class FloatingRotationButtonPositionCalculator(
|
|||||||
taskbarVisible: Boolean,
|
taskbarVisible: Boolean,
|
||||||
taskbarStashed: Boolean
|
taskbarStashed: Boolean
|
||||||
): Position {
|
): Position {
|
||||||
|
|
||||||
val isTaskbarSide = currentRotation == Surface.ROTATION_0
|
val isTaskbarSide = currentRotation == Surface.ROTATION_0
|
||||||
|| currentRotation == Surface.ROTATION_90
|
|| currentRotation == Surface.ROTATION_90
|
||||||
val useTaskbarMargin = isTaskbarSide && taskbarVisible && !taskbarStashed
|
val useTaskbarMargin = isTaskbarSide && taskbarVisible && !taskbarStashed
|
||||||
@@ -55,11 +55,21 @@ class FloatingRotationButtonPositionCalculator(
|
|||||||
)
|
)
|
||||||
|
|
||||||
private fun resolveGravity(rotation: Int): Int =
|
private fun resolveGravity(rotation: Int): Int =
|
||||||
when (rotation) {
|
if (floatingRotationButtonPositionLeft) {
|
||||||
Surface.ROTATION_0 -> Gravity.BOTTOM or Gravity.LEFT
|
when (rotation) {
|
||||||
Surface.ROTATION_90 -> Gravity.BOTTOM or Gravity.RIGHT
|
Surface.ROTATION_0 -> Gravity.BOTTOM or Gravity.LEFT
|
||||||
Surface.ROTATION_180 -> Gravity.TOP or Gravity.RIGHT
|
Surface.ROTATION_90 -> Gravity.BOTTOM or Gravity.RIGHT
|
||||||
Surface.ROTATION_270 -> Gravity.TOP or Gravity.LEFT
|
Surface.ROTATION_180 -> Gravity.TOP or Gravity.RIGHT
|
||||||
else -> throw IllegalArgumentException("Invalid rotation $rotation")
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -301,7 +301,8 @@ public class NavigationBarView extends FrameLayout {
|
|||||||
R.dimen.floating_rotation_button_taskbar_left_margin,
|
R.dimen.floating_rotation_button_taskbar_left_margin,
|
||||||
R.dimen.floating_rotation_button_taskbar_bottom_margin,
|
R.dimen.floating_rotation_button_taskbar_bottom_margin,
|
||||||
R.dimen.floating_rotation_button_diameter,
|
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,
|
mRotationButtonController = new RotationButtonController(mLightContext, mLightIconColor,
|
||||||
mDarkIconColor, R.drawable.ic_sysbar_rotate_button_ccw_start_0,
|
mDarkIconColor, R.drawable.ic_sysbar_rotate_button_ccw_start_0,
|
||||||
R.drawable.ic_sysbar_rotate_button_ccw_start_90,
|
R.drawable.ic_sysbar_rotate_button_ccw_start_90,
|
||||||
|
|||||||
@@ -16,40 +16,50 @@ import org.junit.runners.Parameterized
|
|||||||
internal class FloatingRotationButtonPositionCalculatorTest(private val testCase: TestCase)
|
internal class FloatingRotationButtonPositionCalculatorTest(private val testCase: TestCase)
|
||||||
: SysuiTestCase() {
|
: SysuiTestCase() {
|
||||||
|
|
||||||
private val calculator = FloatingRotationButtonPositionCalculator(
|
|
||||||
MARGIN_DEFAULT, MARGIN_TASKBAR_LEFT, MARGIN_TASKBAR_BOTTOM
|
|
||||||
)
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun calculatePosition() {
|
fun calculatePosition() {
|
||||||
val position = calculator.calculatePosition(
|
val position = testCase.calculator.calculatePosition(
|
||||||
testCase.rotation,
|
testCase.rotation,
|
||||||
testCase.taskbarVisible,
|
testCase.taskbarVisible,
|
||||||
testCase.taskbarStashed
|
testCase.taskbarStashed
|
||||||
)
|
)
|
||||||
|
|
||||||
assertThat(position).isEqualTo(testCase.expectedPosition)
|
assertThat(position).isEqualTo(testCase.expectedPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class TestCase(
|
internal class TestCase(
|
||||||
|
val calculator: FloatingRotationButtonPositionCalculator,
|
||||||
val rotation: Int,
|
val rotation: Int,
|
||||||
val taskbarVisible: Boolean,
|
val taskbarVisible: Boolean,
|
||||||
val taskbarStashed: Boolean,
|
val taskbarStashed: Boolean,
|
||||||
val expectedPosition: Position
|
val expectedPosition: Position
|
||||||
) {
|
) {
|
||||||
override fun toString(): String =
|
override fun toString(): String =
|
||||||
"when rotation = $rotation, " +
|
"when calculator = $calculator, " +
|
||||||
|
"rotation = $rotation, " +
|
||||||
"taskbarVisible = $taskbarVisible, " +
|
"taskbarVisible = $taskbarVisible, " +
|
||||||
"taskbarStashed = $taskbarStashed - " +
|
"taskbarStashed = $taskbarStashed - " +
|
||||||
"expected $expectedPosition"
|
"expected $expectedPosition"
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
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}")
|
@Parameterized.Parameters(name = "{0}")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getParams(): Collection<TestCase> =
|
fun getParams(): Collection<TestCase> =
|
||||||
listOf(
|
listOf(
|
||||||
|
// Position left
|
||||||
TestCase(
|
TestCase(
|
||||||
|
calculator = posLeftCalculator,
|
||||||
rotation = Surface.ROTATION_0,
|
rotation = Surface.ROTATION_0,
|
||||||
taskbarVisible = false,
|
taskbarVisible = false,
|
||||||
taskbarStashed = false,
|
taskbarStashed = false,
|
||||||
@@ -60,6 +70,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
TestCase(
|
TestCase(
|
||||||
|
calculator = posLeftCalculator,
|
||||||
rotation = Surface.ROTATION_90,
|
rotation = Surface.ROTATION_90,
|
||||||
taskbarVisible = false,
|
taskbarVisible = false,
|
||||||
taskbarStashed = false,
|
taskbarStashed = false,
|
||||||
@@ -70,6 +81,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
TestCase(
|
TestCase(
|
||||||
|
calculator = posLeftCalculator,
|
||||||
rotation = Surface.ROTATION_180,
|
rotation = Surface.ROTATION_180,
|
||||||
taskbarVisible = false,
|
taskbarVisible = false,
|
||||||
taskbarStashed = false,
|
taskbarStashed = false,
|
||||||
@@ -80,6 +92,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
TestCase(
|
TestCase(
|
||||||
|
calculator = posLeftCalculator,
|
||||||
rotation = Surface.ROTATION_270,
|
rotation = Surface.ROTATION_270,
|
||||||
taskbarVisible = false,
|
taskbarVisible = false,
|
||||||
taskbarStashed = false,
|
taskbarStashed = false,
|
||||||
@@ -90,6 +103,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
TestCase(
|
TestCase(
|
||||||
|
calculator = posLeftCalculator,
|
||||||
rotation = Surface.ROTATION_0,
|
rotation = Surface.ROTATION_0,
|
||||||
taskbarVisible = true,
|
taskbarVisible = true,
|
||||||
taskbarStashed = false,
|
taskbarStashed = false,
|
||||||
@@ -100,6 +114,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
TestCase(
|
TestCase(
|
||||||
|
calculator = posLeftCalculator,
|
||||||
rotation = Surface.ROTATION_0,
|
rotation = Surface.ROTATION_0,
|
||||||
taskbarVisible = true,
|
taskbarVisible = true,
|
||||||
taskbarStashed = true,
|
taskbarStashed = true,
|
||||||
@@ -110,6 +125,7 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
TestCase(
|
TestCase(
|
||||||
|
calculator = posLeftCalculator,
|
||||||
rotation = Surface.ROTATION_90,
|
rotation = Surface.ROTATION_90,
|
||||||
taskbarVisible = true,
|
taskbarVisible = true,
|
||||||
taskbarStashed = false,
|
taskbarStashed = false,
|
||||||
@@ -118,11 +134,86 @@ internal class FloatingRotationButtonPositionCalculatorTest(private val testCase
|
|||||||
translationX = -MARGIN_TASKBAR_LEFT,
|
translationX = -MARGIN_TASKBAR_LEFT,
|
||||||
translationY = -MARGIN_TASKBAR_BOTTOM
|
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user