Merge "Adjust the layout of nav buttons in 3 button mode with task bar / nav bar unification" into main

This commit is contained in:
Tracy Zhou authored and Android (Google) Code Review committed 2024-01-03 00:12:56 +00:00
commit 9742e603b5
4 files changed
+75 -45

No files matched your search

-1
View File
@@ -322,7 +322,6 @@
<!-- Taskbar -->
<dimen name="taskbar_size">@*android:dimen/taskbar_frame_height</dimen>
<dimen name="taskbar_phone_size">@*android:dimen/navigation_bar_frame_height</dimen>
<dimen name="taskbar_ime_size">48dp</dimen>
<dimen name="taskbar_icon_min_touch_size">48dp</dimen>
<!-- Note that this applies to both sides of all icons, so visible space is double this. -->
@@ -22,10 +22,8 @@ import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.core.view.children
import com.android.launcher3.R
import com.android.launcher3.taskbar.TaskbarActivityContext
import com.android.launcher3.util.DimensionUtils
import com.android.systemui.shared.rotation.RotationButton
open class PhoneLandscapeNavLayoutter(
@@ -48,43 +46,62 @@ open class PhoneLandscapeNavLayoutter(
) {
override fun layoutButtons(context: TaskbarActivityContext, isA11yButtonPersistent: Boolean) {
// TODO(b/230395757): Polish pending, this is just to make it usable
val endStartMargins = resources.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
val taskbarDimensions = DimensionUtils.getTaskbarPhoneDimensions(context.deviceProfile,
resources, context.isPhoneMode)
navButtonContainer.removeAllViews()
navButtonContainer.orientation = LinearLayout.VERTICAL
val totalHeight = context.deviceProfile.heightPx
val homeButtonHeight = resources.getDimensionPixelSize(
R.dimen.taskbar_phone_home_button_size)
val roundedCornerContentMargin = resources.getDimensionPixelSize(
R.dimen.taskbar_phone_rounded_corner_content_margin)
val contentPadding = resources.getDimensionPixelSize(R.dimen.taskbar_phone_content_padding)
val contentWidth = totalHeight - roundedCornerContentMargin * 2 - contentPadding * 2
// left:back:space(reserved for home):overview:right = 0.25:0.5:1:0.5:0.25
val contextualButtonHeight = contentWidth / (0.25f + 0.5f + 1f + 0.5f + 0.25f) * 0.25f
val sideButtonHeight = contextualButtonHeight * 2
val navButtonContainerHeight = contentWidth - contextualButtonHeight * 2
val navContainerParams = FrameLayout.LayoutParams(
taskbarDimensions.x, ViewGroup.LayoutParams.MATCH_PARENT)
ViewGroup.LayoutParams.MATCH_PARENT, navButtonContainerHeight.toInt())
navContainerParams.apply {
topMargin = endStartMargins
bottomMargin = endStartMargins
topMargin =
(contextualButtonHeight + contentPadding + roundedCornerContentMargin).toInt()
bottomMargin =
(contextualButtonHeight + contentPadding + roundedCornerContentMargin).toInt()
marginEnd = 0
marginStart = 0
}
navButtonContainer.layoutParams = navContainerParams
navButtonContainer.gravity = Gravity.CENTER
// Ensure order of buttons is correct
navButtonContainer.removeAllViews()
navButtonContainer.orientation = LinearLayout.VERTICAL
addThreeButtons()
navButtonContainer.layoutParams = navContainerParams
navButtonContainer.gravity = Gravity.CENTER
// Add the spaces in between the nav buttons
val spaceInBetween: Int =
resources.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween_phone)
navButtonContainer.children.forEachIndexed { i, navButton ->
val spaceInBetween = (navButtonContainerHeight - homeButtonHeight -
sideButtonHeight * 2) / 2.0f
for (i in 0 until navButtonContainer.childCount) {
val navButton = navButtonContainer.getChildAt(i)
val buttonLayoutParams = navButton.layoutParams as LinearLayout.LayoutParams
buttonLayoutParams.weight = 1f
val margin = (spaceInBetween / 2).toInt()
when (i) {
0 -> {
buttonLayoutParams.bottomMargin = spaceInBetween / 2
// First button
buttonLayoutParams.bottomMargin = margin
buttonLayoutParams.height = sideButtonHeight.toInt()
}
navButtonContainer.childCount - 1 -> {
buttonLayoutParams.topMargin = spaceInBetween / 2
// Last button
buttonLayoutParams.topMargin = margin
buttonLayoutParams.height = sideButtonHeight.toInt()
}
else -> {
buttonLayoutParams.bottomMargin = spaceInBetween / 2
buttonLayoutParams.topMargin = spaceInBetween / 2
// other buttons
buttonLayoutParams.topMargin = margin
buttonLayoutParams.bottomMargin = margin
buttonLayoutParams.height = homeButtonHeight
}
}
}
@@ -24,7 +24,6 @@ import android.widget.ImageView
import android.widget.LinearLayout
import com.android.launcher3.R
import com.android.launcher3.taskbar.TaskbarActivityContext
import com.android.launcher3.util.DimensionUtils
import com.android.systemui.shared.rotation.RotationButton
class PhonePortraitNavLayoutter(
@@ -47,26 +46,33 @@ class PhonePortraitNavLayoutter(
) {
override fun layoutButtons(context: TaskbarActivityContext, isA11yButtonPersistent: Boolean) {
// TODO(b/230395757): Polish pending, this is just to make it usable
val taskbarDimensions =
DimensionUtils.getTaskbarPhoneDimensions(context.deviceProfile, resources,
context.isPhoneMode)
val endStartMargins = resources.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
val totalWidth = context.deviceProfile.widthPx
val homeButtonWidth = resources.getDimensionPixelSize(R.dimen.taskbar_phone_home_button_size)
val roundedCornerContentMargin = resources.getDimensionPixelSize(
R.dimen.taskbar_phone_rounded_corner_content_margin)
val contentPadding = resources.getDimensionPixelSize(R.dimen.taskbar_phone_content_padding)
val contentWidth = totalWidth - roundedCornerContentMargin * 2 - contentPadding * 2
// left:back:space(reserved for home):overview:right = 0.25:0.5:1:0.5:0.25
val contextualButtonWidth = contentWidth / (0.25f + 0.5f + 1f + 0.5f + 0.25f) * 0.25f
val sideButtonWidth = contextualButtonWidth * 2
val navButtonContainerWidth = contentWidth - contextualButtonWidth * 2
val navContainerParams = FrameLayout.LayoutParams(navButtonContainerWidth.toInt(),
ViewGroup.LayoutParams.MATCH_PARENT)
navContainerParams.apply {
topMargin = 0
bottomMargin = 0
marginEnd =
(contextualButtonWidth + contentPadding + roundedCornerContentMargin).toInt()
marginStart =
(contextualButtonWidth + contentPadding + roundedCornerContentMargin).toInt()
}
// Ensure order of buttons is correct
navButtonContainer.removeAllViews()
navButtonContainer.orientation = LinearLayout.HORIZONTAL
val navContainerParams = FrameLayout.LayoutParams(
taskbarDimensions.x, ViewGroup.LayoutParams.MATCH_PARENT)
navContainerParams.apply {
topMargin = 0
bottomMargin = 0
marginEnd = endStartMargins
marginStart = endStartMargins
}
// Swap recents and back button in case we were landscape prior to this
navButtonContainer.addView(backButton)
navButtonContainer.addView(homeButton)
navButtonContainer.addView(recentsButton)
@@ -75,25 +81,28 @@ class PhonePortraitNavLayoutter(
navButtonContainer.gravity = Gravity.CENTER
// Add the spaces in between the nav buttons
val spaceInBetween =
resources.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween_phone)
val spaceInBetween = (navButtonContainerWidth - homeButtonWidth -
sideButtonWidth * 2) / 2.0f
for (i in 0 until navButtonContainer.childCount) {
val navButton = navButtonContainer.getChildAt(i)
val buttonLayoutParams = navButton.layoutParams as LinearLayout.LayoutParams
buttonLayoutParams.weight = 1f
val margin = (spaceInBetween / 2).toInt()
when (i) {
0 -> {
// First button
buttonLayoutParams.marginEnd = spaceInBetween / 2
buttonLayoutParams.marginEnd = margin
buttonLayoutParams.width = sideButtonWidth.toInt()
}
navButtonContainer.childCount - 1 -> {
// Last button
buttonLayoutParams.marginStart = spaceInBetween / 2
buttonLayoutParams.marginStart = margin
buttonLayoutParams.width = sideButtonWidth.toInt()
}
else -> {
// other buttons
buttonLayoutParams.marginStart = spaceInBetween / 2
buttonLayoutParams.marginEnd = spaceInBetween / 2
buttonLayoutParams.marginStart = margin
buttonLayoutParams.marginEnd = margin
buttonLayoutParams.width = homeButtonWidth
}
}
}
+5
View File
@@ -369,6 +369,11 @@
<!-- Taskbar related (placeholders to compile in Launcher3 without Quickstep) -->
<dimen name="taskbar_size">0dp</dimen>
<dimen name="taskbar_phone_size">@*android:dimen/navigation_bar_frame_height</dimen>
<dimen name="taskbar_phone_home_button_size">80dp</dimen>
<dimen name="taskbar_phone_content_padding">8dp</dimen>
<dimen name="taskbar_phone_rounded_corner_content_margin">
@*android:dimen/rounded_corner_content_padding
</dimen>
<dimen name="taskbar_stashed_size">0dp</dimen>
<dimen name="qsb_widget_height">0dp</dimen>
<dimen name="qsb_shadow_height">0dp</dimen>