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

Commit f363dc9e authored by Ale Nijamkin's avatar Ale Nijamkin Committed by Android (Google) Code Review
Browse files

Merge "Lock screen preview in quick affordance picker." into tm-qpr-dev

parents efb83639 5ec382d4
Loading
Loading
Loading
Loading
+66 −14
Original line number Diff line number Diff line
@@ -15,8 +15,7 @@
  ~
  -->

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
@@ -30,11 +29,21 @@

    </FrameLayout>

    <!-- TODO(b/254858701): plug in the preview here. -->
    <View
    <com.android.wallpaper.picker.DisplayAspectRatioFrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
        android:layout_weight="1"
        android:paddingTop="36dp"
        android:paddingBottom="40dp">

        <include
            android:id="@+id/preview"
            layout="@layout/wallpaper_preview_card"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center"/>

    </com.android.wallpaper.picker.DisplayAspectRatioFrameLayout>

    <LinearLayout
        android:layout_width="match_parent"
@@ -46,6 +55,11 @@
        android:paddingTop="22dp"
        android:paddingBottom="62dp">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >

            <androidx.recyclerview.widget.RecyclerView
                android:id="@id/slot_tabs"
                android:layout_width="match_parent"
@@ -53,10 +67,31 @@
                android:clipToPadding="false"
                android:paddingHorizontal="16dp" />

            <!--
            This is just an invisible placeholder put in place so that the parent keeps its height
            stable as the RecyclerView updates from 0 items to N items. Keeping it stable allows the
            layout logic to keep the size of the preview container stable as well, which bodes well
            for setting up the SurfaceView for remote rendering without changing its size after the
            content is loaded into the RecyclerView.

            It's critical for any TextViews inside the included layout to have text.
            -->
            <include
                layout="@layout/keyguard_quick_affordance_slot_tab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="invisible" />

        </FrameLayout>

        <View
            android:layout_width="0dp"
            android:layout_height="22dp" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@id/affordances"
                android:layout_width="match_parent"
@@ -64,6 +99,23 @@
                android:clipToPadding="false"
                android:paddingHorizontal="16dp" />

            <!--
            This is just an invisible placeholder put in place so that the parent keeps its height
            stable as the RecyclerView updates from 0 items to N items. Keeping it stable allows the
            layout logic to keep the size of the preview container stable as well, which bodes well
            for setting up the SurfaceView for remote rendering without changing its size after the
            content is loaded into the RecyclerView.

            It's critical for any TextViews inside the included layout to have text.
            -->
            <include
                layout="@layout/keyguard_quick_affordance"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="invisible" />

        </FrameLayout>

    </LinearLayout>

</LinearLayout>
+4 −2
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@

<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:layout_width="@dimen/keyguard_quick_affordance_picker_item_width"
    android:layout_height="wrap_content"
    android:orientation="vertical"
@@ -48,6 +48,8 @@
        android:layout_height="wrap_content"
        android:textColor="@color/text_color_primary"
        android:singleLine="true"
        android:ellipsize="end"/>
        android:ellipsize="end"
        android:text="Placeholder for stable size calculation, please do not remove."
        tools:ignore="HardcodedText" />

</LinearLayout>
 No newline at end of file
+4 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
@@ -26,4 +27,6 @@
    android:minWidth="48dp"
    android:minHeight="48dp"
    android:gravity="center"
    android:background="@drawable/keyguard_quick_affordance_slot_tab_background" />
    android:background="@drawable/keyguard_quick_affordance_slot_tab_background"
    android:text="Placeholder for stable size calculation, please do not remove."
    tools:ignore="HardcodedText" />
+5 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.view.ViewGroup;

import com.android.customization.model.grid.GridOption;
import com.android.customization.model.grid.GridOptionsManager;
import com.android.wallpaper.R;
import com.android.wallpaper.picker.WorkspaceSurfaceHolderCallback;
import com.android.wallpaper.util.PreviewUtils;
import com.android.wallpaper.util.SurfaceViewUtils;
@@ -80,7 +81,10 @@ class GridOptionPreviewer {

    private class GridOptionSurfaceHolderCallback extends WorkspaceSurfaceHolderCallback {
        private GridOptionSurfaceHolderCallback(SurfaceView workspaceSurface, Context context) {
            super(workspaceSurface, context);
            super(
                    workspaceSurface,
                    new PreviewUtils(
                            context, context.getString(R.string.grid_control_metadata_name)));
        }

        @Override
+0 −78
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.customization.picker.quickaffordance.ui.binder

import android.view.View
import android.widget.ImageView
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.android.customization.picker.quickaffordance.ui.viewmodel.KeyguardQuickAffordancePickerViewModel
import com.android.systemui.shared.keyguard.shared.model.KeyguardQuickAffordanceSlots
import com.android.wallpaper.R
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.launch

object KeyguardQuickAffordancePickerPreviewBinder {

    /** Binds view with view-model for a lock screen quick affordance preview experience. */
    @JvmStatic
    fun bind(
        view: View,
        viewModel: KeyguardQuickAffordancePickerViewModel,
        lifecycleOwner: LifecycleOwner,
    ) {
        val startView: ImageView = view.requireViewById(R.id.start_affordance)
        val endView: ImageView = view.requireViewById(R.id.end_affordance)
        lifecycleOwner.lifecycleScope.launch {
            lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                launch {
                    updateView(
                        view = startView,
                        viewModel = viewModel,
                        slotId = KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START,
                    )
                }

                launch {
                    updateView(
                        view = endView,
                        viewModel = viewModel,
                        slotId = KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END,
                    )
                }
            }
        }
    }

    private suspend fun updateView(
        view: ImageView,
        viewModel: KeyguardQuickAffordancePickerViewModel,
        slotId: String,
    ) {
        viewModel.slots
            .mapNotNull { slotById -> slotById[slotId] }
            .map { slot -> slot.selectedQuickAffordances.firstOrNull() }
            .collect { affordance ->
                view.setImageDrawable(affordance?.icon)
                view.contentDescription = affordance?.contentDescription
            }
    }
}
Loading