Merge "[User Switcher] Change layout of menu." into tm-qpr-dev
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2022 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License
|
||||
-->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<size android:height="@dimen/bouncer_user_switcher_popup_items_divider_height"/>
|
||||
<solid android:color="@color/user_switcher_fullscreen_bg"/>
|
||||
</shape>
|
||||
@@ -119,6 +119,7 @@
|
||||
<dimen name="bouncer_user_switcher_width">248dp</dimen>
|
||||
<dimen name="bouncer_user_switcher_popup_header_height">12dp</dimen>
|
||||
<dimen name="bouncer_user_switcher_popup_divider_height">4dp</dimen>
|
||||
<dimen name="bouncer_user_switcher_popup_items_divider_height">2dp</dimen>
|
||||
<dimen name="bouncer_user_switcher_item_padding_vertical">10dp</dimen>
|
||||
<dimen name="bouncer_user_switcher_item_padding_horizontal">12dp</dimen>
|
||||
<dimen name="bouncer_user_switcher_header_padding_end">44dp</dimen>
|
||||
|
||||
@@ -36,9 +36,7 @@ class UserSwitcherPopupMenu(
|
||||
private var adapter: ListAdapter? = null
|
||||
|
||||
init {
|
||||
setBackgroundDrawable(
|
||||
res.getDrawable(R.drawable.bouncer_user_switcher_popup_bg, context.getTheme())
|
||||
)
|
||||
setBackgroundDrawable(null)
|
||||
setModal(false)
|
||||
setOverlapAnchor(true)
|
||||
}
|
||||
|
||||
@@ -18,12 +18,15 @@
|
||||
package com.android.systemui.user.ui.binder
|
||||
|
||||
import android.content.Context
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.BaseAdapter
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.LinearLayout.SHOW_DIVIDER_MIDDLE
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.helper.widget.Flow as FlowWidget
|
||||
import androidx.core.view.isVisible
|
||||
@@ -36,6 +39,7 @@ import com.android.systemui.R
|
||||
import com.android.systemui.classifier.FalsingCollector
|
||||
import com.android.systemui.user.UserSwitcherPopupMenu
|
||||
import com.android.systemui.user.UserSwitcherRootView
|
||||
import com.android.systemui.user.shared.model.UserActionModel
|
||||
import com.android.systemui.user.ui.viewmodel.UserActionViewModel
|
||||
import com.android.systemui.user.ui.viewmodel.UserSwitcherViewModel
|
||||
import com.android.systemui.util.children
|
||||
@@ -168,15 +172,10 @@ object UserSwitcherViewBinder {
|
||||
onDismissed: () -> Unit,
|
||||
): UserSwitcherPopupMenu {
|
||||
return UserSwitcherPopupMenu(context).apply {
|
||||
this.setDropDownGravity(Gravity.END)
|
||||
this.anchorView = anchorView
|
||||
setAdapter(adapter)
|
||||
setOnDismissListener { onDismissed() }
|
||||
setOnItemClickListener { _, _, position, _ ->
|
||||
val itemPositionExcludingHeader = position - 1
|
||||
adapter.getItem(itemPositionExcludingHeader).onClicked()
|
||||
dismiss()
|
||||
}
|
||||
|
||||
show()
|
||||
}
|
||||
}
|
||||
@@ -186,38 +185,67 @@ object UserSwitcherViewBinder {
|
||||
private val layoutInflater: LayoutInflater,
|
||||
) : BaseAdapter() {
|
||||
|
||||
private val items = mutableListOf<UserActionViewModel>()
|
||||
private var sections = listOf<List<UserActionViewModel>>()
|
||||
|
||||
override fun getCount(): Int {
|
||||
return items.size
|
||||
return sections.size
|
||||
}
|
||||
|
||||
override fun getItem(position: Int): UserActionViewModel {
|
||||
return items[position]
|
||||
override fun getItem(position: Int): List<UserActionViewModel> {
|
||||
return sections[position]
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return getItem(position).viewKey
|
||||
return position.toLong()
|
||||
}
|
||||
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
val view =
|
||||
convertView
|
||||
?: layoutInflater.inflate(
|
||||
val section = getItem(position)
|
||||
val context = parent.context
|
||||
val sectionView =
|
||||
convertView as? LinearLayout
|
||||
?: LinearLayout(context, null).apply {
|
||||
this.orientation = LinearLayout.VERTICAL
|
||||
this.background =
|
||||
parent.resources.getDrawable(
|
||||
R.drawable.bouncer_user_switcher_popup_bg,
|
||||
context.theme
|
||||
)
|
||||
this.showDividers = SHOW_DIVIDER_MIDDLE
|
||||
this.dividerDrawable =
|
||||
context.getDrawable(
|
||||
R.drawable.fullscreen_userswitcher_menu_item_divider
|
||||
)
|
||||
}
|
||||
sectionView.removeAllViewsInLayout()
|
||||
|
||||
for (viewModel in section) {
|
||||
val view =
|
||||
layoutInflater.inflate(
|
||||
R.layout.user_switcher_fullscreen_popup_item,
|
||||
parent,
|
||||
false
|
||||
/* parent= */ null
|
||||
)
|
||||
val viewModel = getItem(position)
|
||||
view.requireViewById<ImageView>(R.id.icon).setImageResource(viewModel.iconResourceId)
|
||||
view.requireViewById<TextView>(R.id.text).text =
|
||||
view.resources.getString(viewModel.textResourceId)
|
||||
return view
|
||||
view
|
||||
.requireViewById<ImageView>(R.id.icon)
|
||||
.setImageResource(viewModel.iconResourceId)
|
||||
view.requireViewById<TextView>(R.id.text).text =
|
||||
view.resources.getString(viewModel.textResourceId)
|
||||
view.setOnClickListener { viewModel.onClicked() }
|
||||
sectionView.addView(view)
|
||||
}
|
||||
return sectionView
|
||||
}
|
||||
|
||||
fun setItems(items: List<UserActionViewModel>) {
|
||||
this.items.clear()
|
||||
this.items.addAll(items)
|
||||
val primarySection =
|
||||
items.filter {
|
||||
it.viewKey != UserActionModel.NAVIGATE_TO_USER_MANAGEMENT.ordinal.toLong()
|
||||
}
|
||||
val secondarySection =
|
||||
items.filter {
|
||||
it.viewKey == UserActionModel.NAVIGATE_TO_USER_MANAGEMENT.ordinal.toLong()
|
||||
}
|
||||
this.sections = listOf(primarySection, secondarySection)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user