Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c157f26 authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Refactor HandleMenuActionButton to remove redundant LinearLayout

HandleMenuActionButton extended LinearLayout, but its constructor
inflated another LinearLayout as a child. This prevented direct
configuration of HandleMenuActionButton's padding in
desktop_mode_window_decor_handle_menu.xml, as the inner LinearLayout has
the default padding now.

This change uses <merge> in
desktop_mode_window_decor_handle_menu_action_button.xml, allowing direct
addition of child elements to HandleMenuActionButton and eliminating the
edundant inner LinearLayout.

Bug: 403072612
Flag: com.android.window.flags.enable_desktop_windowing_mode
Test: Manually check there is no user visible changes
Test: Manually check the talk back support does not regress b/398128081
Change-Id: I55ac41e56c644eb754e5edae18f19ec0296aace2
parent cac7da8b
Loading
Loading
Loading
Loading
+2 −13
Original line number Diff line number Diff line
@@ -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>
+7 −1
Original line number Diff line number Diff line
@@ -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">
+22 −29
Original line number Diff line number Diff line
@@ -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 {
            ).forEach { (button, shouldShow) ->
                button.apply {
                    isGone = !shouldShow
                    textView.apply {
                        setTextColor(style.textColor)
                        startMarquee()
                    }
                image.imageTintList = ColorStateList.valueOf(style.textColor)
                    iconView.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 {
            openInAppOrBrowserBtn.apply {
                contentDescription = btnText
                textView.apply {
                    text = btnText
                    setTextColor(style.textColor)
                    startMarquee()
                }
            image.imageTintList = ColorStateList.valueOf(style.textColor)
                iconView.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)
+4 −15
Original line number Diff line number Diff line
@@ -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))
@@ -61,15 +59,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.
     *