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

Commit 1202535c authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Lazily inflate the maximize button's progress bar" into main

parents 13c5ef45 1efe8591
Loading
Loading
Loading
Loading
+34 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2024 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.
  -->
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="44dp"
    android:layout_height="40dp"
    android:importantForAccessibility="noHideDescendants">
    <ProgressBar
        android:id="@+id/progress_bar"
        style="?android:attr/progressBarStyleHorizontal"
        android:progressDrawable="@drawable/circular_progress"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:indeterminate="false"
        android:layout_marginHorizontal="6dp"
        android:layout_marginVertical="4dp"
        android:visibility="invisible"/>
</FrameLayout>
+6 −13
Original line number Original line Diff line number Diff line
@@ -17,21 +17,14 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android"
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">


    <FrameLayout
    <ViewStub
        android:id="@+id/stub_progress_bar_container"
        android:inflatedId="@+id/inflatedProgressBarContainer"
        android:layout="@layout/desktop_header_maximize_menu_button_progress_indicator_layout"
        android:layout_width="44dp"
        android:layout_width="44dp"
        android:layout_height="40dp"
        android:layout_height="40dp"
        android:importantForAccessibility="noHideDescendants">
        android:importantForAccessibility="noHideDescendants"
        <ProgressBar
        />
            android:id="@+id/progress_bar"
            style="?android:attr/progressBarStyleHorizontal"
            android:progressDrawable="@drawable/circular_progress"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:indeterminate="false"
            android:layout_marginHorizontal="6dp"
            android:layout_marginVertical="4dp"
            android:visibility="invisible"/>
    </FrameLayout>


    <ImageButton
    <ImageButton
        android:id="@+id/maximize_window"
        android:id="@+id/maximize_window"
+30 −12
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.graphics.drawable.RippleDrawable
import android.util.AttributeSet
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.LayoutInflater
import android.view.View
import android.view.View
import android.view.ViewStub
import android.widget.FrameLayout
import android.widget.FrameLayout
import android.widget.ImageButton
import android.widget.ImageButton
import android.widget.ProgressBar
import android.widget.ProgressBar
@@ -46,13 +47,17 @@ class MaximizeButtonView(
    private val hoverProgressAnimatorSet = AnimatorSet()
    private val hoverProgressAnimatorSet = AnimatorSet()
    var hoverDisabled = false
    var hoverDisabled = false


    private val progressBar: ProgressBar
    private lateinit var stubProgressBarContainer: ViewStub
    private val maximizeWindow: ImageButton
    private val maximizeWindow: ImageButton
    private val progressBar: ProgressBar by lazy {
        (stubProgressBarContainer.inflate() as FrameLayout)
            .requireViewById(R.id.progress_bar)
    }


    init {
    init {
        LayoutInflater.from(context).inflate(R.layout.maximize_menu_button, this, true)
        LayoutInflater.from(context).inflate(R.layout.maximize_menu_button, this, true)


        progressBar = requireViewById(R.id.progress_bar)
        stubProgressBarContainer = requireViewById(R.id.stub_progress_bar_container)
        maximizeWindow = requireViewById(R.id.maximize_window)
        maximizeWindow = requireViewById(R.id.maximize_window)
    }
    }


@@ -115,21 +120,34 @@ class MaximizeButtonView(
            requireNotNull(rippleDrawable) { "Ripple drawable must be non-null" }
            requireNotNull(rippleDrawable) { "Ripple drawable must be non-null" }
            maximizeWindow.imageTintList = iconForegroundColor
            maximizeWindow.imageTintList = iconForegroundColor
            maximizeWindow.background = rippleDrawable
            maximizeWindow.background = rippleDrawable
            stubProgressBarContainer.setOnInflateListener { _, inflated ->
                val progressBar = (inflated as FrameLayout)
                    .requireViewById(R.id.progress_bar) as ProgressBar
                progressBar.progressTintList = ColorStateList.valueOf(baseForegroundColor)
                progressBar.progressTintList = ColorStateList.valueOf(baseForegroundColor)
                    .withAlpha(OPACITY_15)
                    .withAlpha(OPACITY_15)
                progressBar.progressBackgroundTintList = ColorStateList.valueOf(Color.TRANSPARENT)
                progressBar.progressBackgroundTintList = ColorStateList.valueOf(Color.TRANSPARENT)
            }
        } else {
        } else {
            if (darkMode) {
            val progressTint = if (darkMode) {
                progressBar.progressTintList = ColorStateList.valueOf(
                ColorStateList.valueOf(
                    resources.getColor(R.color.desktop_mode_maximize_menu_progress_dark))
                    resources.getColor(R.color.desktop_mode_maximize_menu_progress_dark))
                maximizeWindow.background?.setTintList(ContextCompat.getColorStateList(context,
                    R.color.desktop_mode_caption_button_color_selector_dark))
            } else {
            } else {
                progressBar.progressTintList = ColorStateList.valueOf(
                ColorStateList.valueOf(
                    resources.getColor(R.color.desktop_mode_maximize_menu_progress_light))
                    resources.getColor(R.color.desktop_mode_maximize_menu_progress_light))
                maximizeWindow.background?.setTintList(ContextCompat.getColorStateList(context,
                    R.color.desktop_mode_caption_button_color_selector_light))
            }
            }
            val backgroundTint = if (darkMode) {
                ContextCompat.getColorStateList(context,
                    R.color.desktop_mode_caption_button_color_selector_dark)
            } else {
                ContextCompat.getColorStateList(context,
                    R.color.desktop_mode_caption_button_color_selector_light)
            }
            stubProgressBarContainer.setOnInflateListener { _, inflated ->
                val progressBar = (inflated as FrameLayout)
                    .requireViewById(R.id.progress_bar) as ProgressBar
                progressBar.progressTintList = progressTint
            }
            maximizeWindow.background?.setTintList(backgroundTint)
        }
        }
    }
    }