Merge "Home Controls: Add max columns for edit activity." into tm-dev
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user