diff options
| author | 2025-03-15 17:57:48 -0700 | |
|---|---|---|
| committer | 2025-03-15 17:57:48 -0700 | |
| commit | 64ffccdd4b139903430973e72d56e5e70cc3b910 (patch) | |
| tree | 3146fafa6b891233563cb101c88520e0b07ca96a | |
| parent | 15b076e7590d278bf75905e01a83c0ce4bd1e14d (diff) | |
| parent | 1c157f26c7482e1690b94dbbca0619eb3d12e0f7 (diff) | |
Merge "Refactor HandleMenuActionButton to remove redundant LinearLayout" into main
4 files changed, 35 insertions, 58 deletions
diff --git a/libs/WindowManager/Shell/res/layout/desktop_mode_window_decor_handle_menu_action_button.xml b/libs/WindowManager/Shell/res/layout/desktop_mode_window_decor_handle_menu_action_button.xml index 35e7de0e7c1e..0e5843f3e592 100644 --- a/libs/WindowManager/Shell/res/layout/desktop_mode_window_decor_handle_menu_action_button.xml +++ b/libs/WindowManager/Shell/res/layout/desktop_mode_window_decor_handle_menu_action_button.xml @@ -14,18 +14,7 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" - xmlns:tools="http://schemas.android.com/tools" - android:id="@+id/action_button" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:gravity="start|center_vertical" - android:paddingHorizontal="16dp" - android:importantForAccessibility="yes" - android:orientation="horizontal" - android:background="?android:attr/selectableItemBackground"> - +<merge xmlns:android="http://schemas.android.com/apk/res/android"> <ImageView android:id="@+id/image" android:importantForAccessibility="no" @@ -35,4 +24,4 @@ android:id="@+id/label" android:importantForAccessibility="no" style="@style/DesktopModeHandleMenuActionButtonTextView"/> -</LinearLayout> +</merge> diff --git a/libs/WindowManager/Shell/res/values/styles.xml b/libs/WindowManager/Shell/res/values/styles.xml index 5f1db83d7acb..08cda7b94a78 100644 --- a/libs/WindowManager/Shell/res/values/styles.xml +++ b/libs/WindowManager/Shell/res/values/styles.xml @@ -45,7 +45,13 @@ <item name="android:layout_height">52dp</item> <item name="android:textColor">@androidprv:color/materialColorOnSurface</item> <item name="android:drawableTint">@androidprv:color/materialColorOnSurface</item> - <item name="android:importantForAccessibility">no</item> + <item name="android:importantForAccessibility">yes</item> + <item name="android:gravity">start|center_vertical</item> + <item name="android:paddingHorizontal">16dp</item> + <item name="android:clickable">true</item> + <item name="android:focusable">true</item> + <item name="android:orientation">horizontal</item> + <item name="android:background">?android:attr/selectableItemBackground</item> </style> <style name="DesktopModeHandleMenuActionButtonImage"> diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenu.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenu.kt index 9cc64ac9c276..284fbc310cbe 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenu.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenu.kt @@ -37,7 +37,6 @@ import android.view.WindowInsets.Type.systemBars import android.view.WindowManager import android.widget.ImageButton import android.widget.ImageView -import android.widget.LinearLayout import android.widget.Space import android.window.DesktopModeFlags import android.window.SurfaceSyncGroup @@ -549,9 +548,8 @@ class HandleMenu( private val openInAppOrBrowserPill = rootView.requireViewById<View>( R.id.open_in_app_or_browser_pill ) - private val openInAppOrBrowserBtn = openInAppOrBrowserPill.requireViewById<View>( - R.id.open_in_app_or_browser_button - ) + private val openInAppOrBrowserBtn = openInAppOrBrowserPill + .requireViewById<HandleMenuActionButton>(R.id.open_in_app_or_browser_button) private val openByDefaultBtn = openInAppOrBrowserPill.requireViewById<ImageButton>( R.id.open_by_default_button ) @@ -808,20 +806,15 @@ class HandleMenu( newWindowBtn to shouldShowNewWindowButton, manageWindowBtn to shouldShowManageWindowsButton, changeAspectRatioBtn to shouldShowChangeAspectRatioButton, - ).forEach { - val button = it.first - val shouldShow = it.second - - val buttonRoot = button.requireViewById<LinearLayout>(R.id.action_button) - val label = buttonRoot.requireViewById<MarqueedTextView>(R.id.label) - val image = buttonRoot.requireViewById<ImageView>(R.id.image) - - button.isGone = !shouldShow - label.apply { - setTextColor(style.textColor) - startMarquee() + ).forEach { (button, shouldShow) -> + button.apply { + isGone = !shouldShow + textView.apply { + setTextColor(style.textColor) + startMarquee() + } + iconView.imageTintList = ColorStateList.valueOf(style.textColor) } - image.imageTintList = ColorStateList.valueOf(style.textColor) } } @@ -837,20 +830,20 @@ class HandleMenu( getString(R.string.open_in_browser_text) } - val buttonRoot = openInAppOrBrowserBtn.requireViewById<LinearLayout>(R.id.action_button) - val label = openInAppOrBrowserBtn.requireViewById<MarqueedTextView>(R.id.label) - val image = openInAppOrBrowserBtn.requireViewById<ImageView>(R.id.image) - openInAppOrBrowserBtn.contentDescription = btnText - buttonRoot.contentDescription = btnText - label.apply { - text = btnText - setTextColor(style.textColor) - startMarquee() + openInAppOrBrowserBtn.apply { + contentDescription = btnText + textView.apply { + text = btnText + setTextColor(style.textColor) + startMarquee() + } + iconView.imageTintList = ColorStateList.valueOf(style.textColor) } - image.imageTintList = ColorStateList.valueOf(style.textColor) - openByDefaultBtn.isGone = isBrowserApp - openByDefaultBtn.imageTintList = ColorStateList.valueOf(style.textColor) + openByDefaultBtn.apply { + isGone = isBrowserApp + imageTintList = ColorStateList.valueOf(style.textColor) + } } private fun getString(@StringRes resId: Int): String = context.resources.getString(resId) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenuActionButton.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenuActionButton.kt index a723a7a4ac20..7aba54eef899 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenuActionButton.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/HandleMenuActionButton.kt @@ -39,20 +39,18 @@ class HandleMenuActionButton @JvmOverloads constructor( defStyleAttr: Int = 0 ) : LinearLayout(context, attrs, defStyleAttr) { - private val rootElement: LinearLayout - private val iconView: ImageView - private val textView: MarqueedTextView + val iconView: ImageView + val textView: MarqueedTextView init { - val view = LayoutInflater.from(context).inflate( + LayoutInflater.from(context).inflate( R.layout.desktop_mode_window_decor_handle_menu_action_button, this, true) - rootElement = findViewById(R.id.action_button) iconView = findViewById(R.id.image) textView = findViewById(R.id.label) context.withStyledAttributes(attrs, R.styleable.HandleMenuActionButton) { + contentDescription = getString(R.styleable.HandleMenuActionButton_android_text) textView.text = getString(R.styleable.HandleMenuActionButton_android_text) - rootElement.contentDescription = getString(R.styleable.HandleMenuActionButton_android_text) textView.setTextColor(getColor(R.styleable.HandleMenuActionButton_android_textColor, 0)) iconView.setImageResource(getResourceId( R.styleable.HandleMenuActionButton_android_src, 0)) @@ -62,15 +60,6 @@ class HandleMenuActionButton @JvmOverloads constructor( } /** - * Sets a listener to be invoked when this view is clicked. - * - * @param l the [OnClickListener] that receives click events. - */ - override fun setOnClickListener(l: OnClickListener?) { - rootElement.setOnClickListener(l) - } - - /** * Sets the text color for the text inside the button. * * @param color the color to set for the text, as a color integer. |