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

Commit cb3fa4e4 authored by Kazuki Takise's avatar Kazuki Takise Committed by Android (Google) Code Review
Browse files

Merge "Revert the fadeout effect of app name text" into main

parents 58b2ae30 bc3f2669
Loading
Loading
Loading
Loading
+27 −34
Original line number Diff line number Diff line
@@ -43,25 +43,19 @@
            android:focusable="false"
            android:scaleType="centerCrop"/>

        <FrameLayout
            android:id="@+id/app_name_layout"
            android:layout_marginStart="8dp"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content">

        <TextView
            android:id="@+id/application_name"
                android:layout_width="wrap_content"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
                android:maxWidth="@dimen/desktop_mode_header_app_name_max_width"
            android:maxWidth="130dp"
            android:textSize="14sp"
            android:textFontWeight="500"
            android:lineHeight="20sp"
                android:layout_gravity="start|center_vertical"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:layout_marginStart="8dp"
            android:singleLine="true"
                android:ellipsize="none"
            android:ellipsize="end"
            android:clickable="false"
            android:focusable="false"
            tools:text="Gmail"/>
@@ -71,7 +65,7 @@
            android:src="@drawable/expand_menu_error"
            android:layout_width="@dimen/desktop_mode_header_expand_menu_error_image_width"
            android:layout_height="@dimen/desktop_mode_header_expand_menu_error_image_width"
                android:layout_gravity="end|center_vertical"
            android:layout_gravity="center_vertical"
            android:layout_marginStart="@dimen/desktop_mode_header_expand_menu_error_image_margin"
            android:clickable="false"
            android:focusable="false"
@@ -79,7 +73,6 @@
            android:importantForAccessibility="no"
            android:contentDescription="@null"
            android:scaleType="centerCrop"/>
        </FrameLayout>

        <ImageButton
            android:id="@+id/expand_menu_button"
+0 −2
Original line number Diff line number Diff line
@@ -663,8 +663,6 @@

    <!-- The max width of the app name shown on the app header -->
    <dimen name="desktop_mode_header_app_name_max_width">130dp</dimen>
    <!-- The width of the fadeout effect applied to a long app name shown on the app header -->
    <dimen name="desktop_mode_header_app_name_fadeout_width">48dp</dimen>
    <!-- The width of the expand menu error image on the app header -->
    <dimen name="desktop_mode_header_expand_menu_error_image_width">16dp</dimen>
    <!-- The margin added between app name and expand menu error image on the app header -->
+2 −65
Original line number Diff line number Diff line
@@ -23,15 +23,12 @@ import android.content.res.ColorStateList
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.LinearGradient
import android.graphics.Rect
import android.graphics.Shader
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.View.OnLongClickListener
import android.view.ViewTreeObserver
import android.view.ViewTreeObserver.OnGlobalLayoutListener
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
@@ -82,7 +79,6 @@ import com.android.wm.shell.windowdecor.viewholder.AppHeaderViewHolder.A11yState
import com.android.wm.shell.windowdecor.viewholder.AppHeaderViewHolder.A11yState.NOT_FOCUSED
import com.android.wm.shell.windowdecor.viewholder.AppHeaderViewHolder.A11yState.OPENING
import com.android.wm.shell.windowdecor.viewholder.AppHeaderViewHolder.A11yState.UNKNOWN
import kotlin.math.roundToInt

/**
 * A desktop mode window decoration used when the window is floating (i.e. freeform). It hosts
@@ -126,12 +122,6 @@ class AppHeaderViewHolder(
    private val appNameMaxWidth = context.resources
        .getDimensionPixelSize(R.dimen.desktop_mode_header_app_name_max_width)

    /**
     * The width of the fadeout effect applied to a long app name shown on the app header.
     **/
    private val appNameFadeoutWidth = context.resources
        .getDimensionPixelSize(R.dimen.desktop_mode_header_app_name_fadeout_width)

    /**
     * The width of the expand menu error image on the app header.
     **/
@@ -426,7 +416,6 @@ class AppHeaderViewHolder(
        if (a11yState == OPENING) setA11yStateTo(FOCUSED)

        updateMaximizeButtonContentDescription()
        updateAppNameLayoutAndEffect()
    }

    /** Populates string variables from string templates which rely on app name */
@@ -446,59 +435,6 @@ class AppHeaderViewHolder(
            context.getString(R.string.desktop_mode_talkback_state_not_focused, name)
    }

    private fun updateAppNameLayoutAndEffect() {
        if (!DesktopExperienceFlags.ENABLE_RESTART_MENU_FOR_CONNECTED_DISPLAYS.isTrue()) return
        appNameTextView.viewTreeObserver.addOnPreDrawListener(
            object : ViewTreeObserver.OnPreDrawListener {
                override fun onPreDraw(): Boolean {
                    appNameTextView.viewTreeObserver.removeOnPreDrawListener(this)
                    val errorIconWidth =
                        expandMenuErrorImageWidth + expandMenuErrorImageMargin
                    val textWidth =
                        appNameTextView.paint.measureText(appNameTextView.text.toString())
                            .roundToInt()
                    val isRestartMenuShown =
                        currentTaskInfo.appCompatTaskInfo.isRestartMenuEnabledForDisplayMove

                    // Adjust the right padding of the app text so the error icon will be placed
                    // properly. In case the text is short enough, the padding will be
                    // |errorIconWidth| so the error icon will look like being placed to the right
                    // of the text. Otherwise, the error icon will overlap with the text.
                    val errorIconPadding = if (isRestartMenuShown && textWidth <= appNameMaxWidth) {
                        minOf(appNameMaxWidth - textWidth, errorIconWidth)
                    } else {
                        0
                    }
                    appNameTextView.setPaddingRelative(0, 0, errorIconPadding, 0)

                    // In case the app text (and the error icon) is too long to fit in the app
                    // header, fade out the text by applying the custom shader.
                    val availableWidth = if (isRestartMenuShown) {
                        appNameMaxWidth - errorIconWidth
                    } else {
                        appNameMaxWidth
                    }
                    if (textWidth > availableWidth) {
                        val textColor = appNameTextView.currentTextColor
                        val transparentColor = Color.argb(
                            0, Color.red(textColor),
                            Color.green(textColor), Color.blue(textColor)
                        )
                        appNameTextView.paint.shader = LinearGradient(
                            (availableWidth - appNameFadeoutWidth).toFloat(),
                            0f,
                            availableWidth.toFloat(),
                            0f,
                            textColor,
                            transparentColor,
                            Shader.TileMode.CLAMP
                        )
                    }
                    return true
                }
        })
    }

    private fun updateMaximizeButtonContentDescription() {
        if (this::a11yTextRestore.isInitialized &&
            this::a11yTextMaximize.isInitialized &&
@@ -636,6 +572,8 @@ class AppHeaderViewHolder(
            appNameTextView.apply {
                isVisible = header.type == Header.Type.DEFAULT
                setTextColor(colorStateList)
                maxWidth = if (currentTaskInfo.appCompatTaskInfo.isRestartMenuEnabledForDisplayMove)
                    appNameMaxWidth - expandMenuErrorImageWidth - expandMenuErrorImageMargin else appNameMaxWidth
            }
            appIconImageView.imageAlpha = foregroundAlpha
            defaultFocusHighlightEnabled = false
@@ -690,7 +628,6 @@ class AppHeaderViewHolder(
                }
            }
            updateMaximizeButtonContentDescription()
            updateAppNameLayoutAndEffect()
        }
        // Close button.
        closeWindowButton.apply {