Home Controls: Add max columns for edit activity.

Moved the findMaxColumns function from ControlsUiControllerImpl to
ControlAdapter to be used as a shared functin. It is used across 3
files.

I removed orientation from configChanges in the manifest so that the
recyclerview can recalculate max columns again after rotation.

I moved the spanCount calculation one level higher so that we can set
the spancount for ZONE type view holders to be the max number of
columns. This makes it so that the view holder will take up the whole
row.

Fixes: 222729341
Test: manual test on device
Change-Id: Id0819e417c8d5995474abb0a8060ee9e694fe4a7
This commit is contained in:
Aaron Liu
2022-03-04 22:48:18 +00:00
parent c6c97b7b84
commit c1903b0b1e
5 changed files with 48 additions and 40 deletions

View File

@@ -794,7 +794,7 @@
android:noHistory="true"
android:showForAllUsers="true"
android:finishOnTaskLaunch="true"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboard|keyboardHidden"
android:configChanges="screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden"
android:visibleToInstantApps="true">
</activity>
@@ -805,7 +805,7 @@
android:showForAllUsers="true"
android:finishOnTaskLaunch="true"
android:launchMode="singleInstance"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboard|keyboardHidden"
android:configChanges="screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden"
android:visibleToInstantApps="true">
</activity>

View File

@@ -17,10 +17,13 @@
package com.android.systemui.controls.management
import android.content.ComponentName
import android.content.res.Configuration
import android.content.res.Resources
import android.graphics.Rect
import android.os.Bundle
import android.service.controls.Control
import android.service.controls.DeviceTypes
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -32,7 +35,6 @@ import android.widget.TextView
import androidx.core.view.AccessibilityDelegateCompat
import androidx.core.view.ViewCompat
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.android.systemui.R
import com.android.systemui.controls.ControlInterface
@@ -56,11 +58,32 @@ class ControlAdapter(
const val TYPE_ZONE = 0
const val TYPE_CONTROL = 1
const val TYPE_DIVIDER = 2
}
val spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return if (getItemViewType(position) != TYPE_CONTROL) 2 else 1
/**
* For low-dp width screens that also employ an increased font scale, adjust the
* number of columns. This helps prevent text truncation on these devices.
*
*/
@JvmStatic
fun findMaxColumns(res: Resources): Int {
var maxColumns = res.getInteger(R.integer.controls_max_columns)
val maxColumnsAdjustWidth =
res.getInteger(R.integer.controls_max_columns_adjust_below_width_dp)
val outValue = TypedValue()
res.getValue(R.dimen.controls_max_columns_adjust_above_font_scale, outValue, true)
val maxColumnsAdjustFontScale = outValue.getFloat()
val config = res.configuration
val isPortrait = config.orientation == Configuration.ORIENTATION_PORTRAIT
if (isPortrait &&
config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED &&
config.screenWidthDp <= maxColumnsAdjustWidth &&
config.fontScale >= maxColumnsAdjustFontScale) {
maxColumns--
}
return maxColumns
}
}

View File

@@ -195,10 +195,11 @@ class ControlsEditingActivity @Inject constructor(
val margin = resources
.getDimensionPixelSize(R.dimen.controls_card_margin)
val itemDecorator = MarginItemDecorator(margin, margin)
val spanCount = ControlAdapter.findMaxColumns(resources)
recyclerView.apply {
this.adapter = adapter
layoutManager = object : GridLayoutManager(recyclerView.context, 2) {
layoutManager = object : GridLayoutManager(recyclerView.context, spanCount) {
// This will remove from the announcement the row corresponding to the divider,
// as it's not something that should be announced.
@@ -210,7 +211,12 @@ class ControlsEditingActivity @Inject constructor(
return if (initial > 0) initial - 1 else initial
}
}.apply {
spanSizeLookup = adapter.spanSizeLookup
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return if (adapter?.getItemViewType(position)
!= ControlAdapter.TYPE_CONTROL) spanCount else 1
}
}
}
addItemDecoration(itemDecorator)
}

View File

@@ -60,11 +60,17 @@ class StructureAdapter(
val margin = itemView.context.resources
.getDimensionPixelSize(R.dimen.controls_card_margin)
val itemDecorator = MarginItemDecorator(margin, margin)
val spanCount = ControlAdapter.findMaxColumns(itemView.resources)
recyclerView.apply {
this.adapter = controlAdapter
layoutManager = GridLayoutManager(recyclerView.context, 2).apply {
spanSizeLookup = controlAdapter.spanSizeLookup
layoutManager = GridLayoutManager(recyclerView.context, spanCount).apply {
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return if (adapter?.getItemViewType(position)
!= ControlAdapter.TYPE_CONTROL) spanCount else 1
}
}
}
addItemDecoration(itemDecorator)
}

View File

@@ -25,12 +25,10 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.res.Configuration
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.service.controls.Control
import android.util.Log
import android.util.TypedValue
import android.view.ContextThemeWrapper
import android.view.LayoutInflater
import android.view.View
@@ -51,6 +49,7 @@ import com.android.systemui.controls.CustomIconCache
import com.android.systemui.controls.controller.ControlInfo
import com.android.systemui.controls.controller.ControlsController
import com.android.systemui.controls.controller.StructureInfo
import com.android.systemui.controls.management.ControlAdapter
import com.android.systemui.controls.management.ControlsEditingActivity
import com.android.systemui.controls.management.ControlsFavoritingActivity
import com.android.systemui.controls.management.ControlsListingController
@@ -386,7 +385,7 @@ class ControlsUiControllerImpl @Inject constructor (
visibility = View.VISIBLE
}
val maxColumns = findMaxColumns()
val maxColumns = ControlAdapter.findMaxColumns(activityContext.resources)
val listView = parent.requireViewById(R.id.global_actions_controls_list) as ViewGroup
var lastRow: ViewGroup = createRow(inflater, listView)
@@ -432,32 +431,6 @@ class ControlsUiControllerImpl @Inject constructor (
}
}
/**
* For low-dp width screens that also employ an increased font scale, adjust the
* number of columns. This helps prevent text truncation on these devices.
*/
private fun findMaxColumns(): Int {
val res = activityContext.resources
var maxColumns = res.getInteger(R.integer.controls_max_columns)
val maxColumnsAdjustWidth =
res.getInteger(R.integer.controls_max_columns_adjust_below_width_dp)
val outValue = TypedValue()
res.getValue(R.dimen.controls_max_columns_adjust_above_font_scale, outValue, true)
val maxColumnsAdjustFontScale = outValue.getFloat()
val config = res.configuration
val isPortrait = config.orientation == Configuration.ORIENTATION_PORTRAIT
if (isPortrait &&
config.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED &&
config.screenWidthDp <= maxColumnsAdjustWidth &&
config.fontScale >= maxColumnsAdjustFontScale) {
maxColumns--
}
return maxColumns
}
override fun getPreferredStructure(structures: List<StructureInfo>): StructureInfo {
if (structures.isEmpty()) return EMPTY_STRUCTURE