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

Commit 6f8170bb authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Support e2e in controls activities

Test: manual, check different orientations and nav bar
Fixes: 330435386
Flag: EXEMPT bug fix
Change-Id: Ibb478a19256e5e24b835533e4dd053d9788b1393
parent feb3f74a
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:paddingTop="@dimen/controls_management_top_padding"
    android:paddingStart="@dimen/controls_management_side_padding"
    android:paddingEnd="@dimen/controls_management_side_padding" >

+0 −5
Original line number Diff line number Diff line
@@ -1079,11 +1079,6 @@
        <!-- Setting a placeholder will avoid using the SystemUI icon on the splash screen -->
        <item name="android:windowSplashScreenAnimatedIcon">@drawable/ic_blank</item>
        <item name="wallpaperTextColor">@*android:color/primary_text_material_dark</item>

        <!--
            TODO(b/309578419): Make the activity handle insets properly and then remove this.
        -->
        <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
    </style>

    <style name="Widget.SliceView.VolumePanel">
+132 −108
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.controls.management

import android.app.Activity
import android.app.ActivityOptions
import android.content.ComponentName
import android.content.Context
@@ -34,25 +35,25 @@ import androidx.activity.ComponentActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import com.android.systemui.res.R
import com.android.systemui.controls.CustomIconCache
import com.android.systemui.controls.controller.ControlsControllerImpl
import com.android.systemui.controls.controller.StructureInfo
import com.android.systemui.controls.ui.ControlsActivity
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.res.R
import com.android.systemui.settings.UserTracker
import java.util.concurrent.Executor
import javax.inject.Inject

/**
 * Activity for rearranging and removing controls for a given structure
 */
open class ControlsEditingActivity @Inject constructor(
/** Activity for rearranging and removing controls for a given structure */
open class ControlsEditingActivity
@Inject
constructor(
    @Main private val mainExecutor: Executor,
    private val controller: ControlsControllerImpl,
    private val userTracker: UserTracker,
    private val customIconCache: CustomIconCache,
) : ComponentActivity() {
) : ComponentActivity(), ControlsManagementActivity {

    companion object {
        private const val DEBUG = false
@@ -64,6 +65,9 @@ open class ControlsEditingActivity @Inject constructor(
        private val EMPTY_TEXT_ID = R.string.controls_favorite_removed
    }

    override val activity: Activity
        get() = this

    private lateinit var component: ComponentName
    private lateinit var structure: CharSequence
    private lateinit var model: FavoritesModel
@@ -73,7 +77,8 @@ open class ControlsEditingActivity @Inject constructor(

    private var isFromFavoriting: Boolean = false

    private val userTrackerCallback: UserTracker.Callback = object : UserTracker.Callback {
    private val userTrackerCallback: UserTracker.Callback =
        object : UserTracker.Callback {
            private val startingUser = controller.currentUserId

            override fun onUserChanged(newUser: Int, userContext: Context) {
@@ -98,9 +103,7 @@ open class ControlsEditingActivity @Inject constructor(
            component = it
        } ?: run(this::finish)
        isFromFavoriting = intent.getBooleanExtra(EXTRA_FROM_FAVORITING, false)
        intent.getCharSequenceExtra(EXTRA_STRUCTURE)?.let {
            structure = it
        } ?: run(this::finish)
        intent.getCharSequenceExtra(EXTRA_STRUCTURE)?.let { structure = it } ?: run(this::finish)

        bindViews()

@@ -117,7 +120,9 @@ open class ControlsEditingActivity @Inject constructor(
            Log.d(TAG, "Registered onBackInvokedCallback")
        }
        onBackInvokedDispatcher.registerOnBackInvokedCallback(
                OnBackInvokedDispatcher.PRIORITY_DEFAULT, mOnBackInvokedCallback)
            OnBackInvokedDispatcher.PRIORITY_DEFAULT,
            mOnBackInvokedCallback,
        )
    }

    override fun onStop() {
@@ -142,18 +147,21 @@ open class ControlsEditingActivity @Inject constructor(
                    override fun run() {
                        finish()
                    }
                }
        ).start()
                },
            )
            .start()
    }

    private fun bindViews() {
        setContentView(R.layout.controls_management)

        applyInsets(R.id.controls_management_root)

        lifecycle.addObserver(
            ControlsAnimations.observerForAnimations(
                requireViewById<ViewGroup>(R.id.controls_management_root),
                window,
                intent
                intent,
            )
        )

@@ -163,13 +171,12 @@ open class ControlsEditingActivity @Inject constructor(
        }
        requireViewById<TextView>(R.id.title).text = structure
        setTitle(structure)
        subtitle = requireViewById<TextView>(R.id.subtitle).apply {
            setText(SUBTITLE_ID)
        }
        subtitle = requireViewById<TextView>(R.id.subtitle).apply { setText(SUBTITLE_ID) }
    }

    private fun bindButtons() {
        addControls = requireViewById<Button>(R.id.addControls).apply {
        addControls =
            requireViewById<Button>(R.id.addControls).apply {
                isEnabled = true
                visibility = View.VISIBLE
                setOnClickListener {
@@ -178,13 +185,15 @@ open class ControlsEditingActivity @Inject constructor(
                        Toast.makeText(
                                applicationContext,
                                R.string.controls_favorite_toast_no_changes,
                        Toast.LENGTH_SHORT
                    ).show()
                                Toast.LENGTH_SHORT,
                            )
                            .show()
                    }
                    if (isFromFavoriting) {
                        animateExitAndFinish()
                    } else {
                    startActivity(Intent(context, ControlsFavoritingActivity::class.java).also {
                        startActivity(
                            Intent(context, ControlsFavoritingActivity::class.java).also {
                                it.putExtra(ControlsFavoritingActivity.EXTRA_STRUCTURE, structure)
                                it.putExtra(Intent.EXTRA_COMPONENT_NAME, component)
                                it.putExtra(
@@ -198,20 +207,22 @@ open class ControlsEditingActivity @Inject constructor(
                            },
                            ActivityOptions.makeSceneTransitionAnimation(
                                    this@ControlsEditingActivity
                                  ).toBundle(),
                                )
                                .toBundle(),
                        )
                    }
                }
            }
        saveButton = requireViewById<Button>(R.id.done).apply {
        saveButton =
            requireViewById<Button>(R.id.done).apply {
                isEnabled = isFromFavoriting
                setText(R.string.save)
                setOnClickListener {
                    saveFavorites()
                    startActivity(
                        Intent(applicationContext, ControlsActivity::class.java),
                    ActivityOptions
                        .makeSceneTransitionAnimation(this@ControlsEditingActivity).toBundle()
                        ActivityOptions.makeSceneTransitionAnimation(this@ControlsEditingActivity)
                            .toBundle(),
                    )
                    animateExitAndFinish()
                }
@@ -220,10 +231,12 @@ open class ControlsEditingActivity @Inject constructor(

    private fun saveFavorites() {
        controller.replaceFavoritesForStructure(
                StructureInfo(component, structure, model.favorites))
            StructureInfo(component, structure, model.favorites)
        )
    }

    private val favoritesModelCallback = object : FavoritesModel.FavoritesModelCallback {
    private val favoritesModelCallback =
        object : FavoritesModel.FavoritesModelCallback {
            override fun onNoneChanged(showNoFavorites: Boolean) {
                if (showNoFavorites) {
                    subtitle.setText(EMPTY_TEXT_ID)
@@ -245,41 +258,52 @@ open class ControlsEditingActivity @Inject constructor(
        val elevation = resources.getFloat(R.dimen.control_card_elevation)
        val recyclerView = requireViewById<RecyclerView>(R.id.list)
        recyclerView.alpha = 0.0f
        val adapter = ControlAdapter(elevation, userTracker.userId).apply {
            registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
        val adapter =
            ControlAdapter(elevation, userTracker.userId).apply {
                registerAdapterDataObserver(
                    object : RecyclerView.AdapterDataObserver() {
                        var hasAnimated = false

                        override fun onChanged() {
                            if (!hasAnimated) {
                                hasAnimated = true
                                ControlsAnimations.enterAnimation(recyclerView).start()
                            }
                        }
            })
                    }
                )
            }

        val margin = resources
                .getDimensionPixelSize(R.dimen.controls_card_margin)
        val margin = resources.getDimensionPixelSize(R.dimen.controls_card_margin)
        val itemDecorator = MarginItemDecorator(margin, margin)
        val spanCount = ControlAdapter.findMaxColumns(resources)

        recyclerView.apply {
            this.adapter = adapter
            layoutManager = object : GridLayoutManager(recyclerView.context, spanCount) {
            layoutManager =
                object : GridLayoutManager(recyclerView.context, spanCount) {

                // This will remove from the announcement the row corresponding to the divider,
                        // This will remove from the announcement the row corresponding to the
                        // divider,
                        // as it's not something that should be announced.
                        override fun getRowCountForAccessibility(
                            recycler: RecyclerView.Recycler,
                    state: RecyclerView.State
                            state: RecyclerView.State,
                        ): Int {
                            val initial = super.getRowCountForAccessibility(recycler, state)
                            return if (initial > 0) initial - 1 else initial
                        }
            }.apply {
                spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
                    }
                    .apply {
                        spanSizeLookup =
                            object : GridLayoutManager.SpanSizeLookup() {
                                override fun getSpanSize(position: Int): Int {
                        return if (adapter?.getItemViewType(position)
                                != ControlAdapter.TYPE_CONTROL) spanCount else 1
                                    return if (
                                        adapter?.getItemViewType(position) !=
                                            ControlAdapter.TYPE_CONTROL
                                    )
                                        spanCount
                                    else 1
                                }
                            }
                    }
+211 −157

File changed.

Preview size limit exceeded, changes collapsed.

+40 −0
Original line number Diff line number Diff line
/*
 * 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.
 */

package com.android.systemui.controls.management

import android.app.Activity
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
import android.view.WindowInsets.Type

interface ControlsManagementActivity {
    val activity: Activity
}

fun ControlsManagementActivity.applyInsets(viewId: Int) {
    activity.requireViewById<ViewGroup>(viewId).apply {
        setOnApplyWindowInsetsListener { v: View, insets: WindowInsets ->
            v.apply {
                val paddings = insets.getInsets(Type.systemBars() or Type.displayCutout())
                setPadding(paddings.left, paddings.top, paddings.right, paddings.bottom)
            }

            WindowInsets.CONSUMED
        }
    }
}
Loading