• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.wallpapers.data.repository
18 
19 import android.graphics.PointF
20 import android.graphics.RectF
21 import com.android.systemui.dagger.SysUISingleton
22 import javax.inject.Inject
23 import kotlinx.coroutines.flow.MutableStateFlow
24 import kotlinx.coroutines.flow.StateFlow
25 import kotlinx.coroutines.flow.asStateFlow
26 
27 interface WallpaperFocalAreaRepository {
28 
29     /** The top of shortcut in screen, used by wallpaper to find remaining space in lockscreen */
30     val shortcutAbsoluteTop: StateFlow<Float>
31 
32     val notificationStackAbsoluteBottom: StateFlow<Float>
33 
34     val wallpaperFocalAreaBounds: StateFlow<RectF>
35 
36     /** It will be true when wallpaper requires focal area info. */
37     val hasFocalArea: StateFlow<Boolean>
38 
39     /** top of notifications without bcsmartspace in small clock settings */
40     val notificationDefaultTop: StateFlow<Float>
41 
setShortcutAbsoluteTopnull42     fun setShortcutAbsoluteTop(top: Float)
43 
44     /** Set bottom of notifications from notification stack, used as top for focal area bounds */
45     fun setNotificationStackAbsoluteBottom(bottom: Float)
46 
47     fun setWallpaperFocalAreaBounds(bounds: RectF)
48 
49     fun setNotificationDefaultTop(top: Float)
50 
51     fun setTapPosition(tapPosition: PointF)
52 }
53 
54 @SysUISingleton
55 class WallpaperFocalAreaRepositoryImpl
56 @Inject
57 constructor(val wallpaperRepository: WallpaperRepository) : WallpaperFocalAreaRepository {
58 
59     private val _shortcutAbsoluteTop = MutableStateFlow(0F)
60     override val shortcutAbsoluteTop = _shortcutAbsoluteTop.asStateFlow()
61 
62     private val _notificationStackAbsoluteBottom = MutableStateFlow(0F)
63     override val notificationStackAbsoluteBottom = _notificationStackAbsoluteBottom.asStateFlow()
64 
65     private val _wallpaperFocalAreaBounds = MutableStateFlow(RectF(0F, 0F, 0F, 0F))
66     override val wallpaperFocalAreaBounds: StateFlow<RectF> =
67         _wallpaperFocalAreaBounds.asStateFlow()
68 
69     private val _notificationDefaultTop = MutableStateFlow(0F)
70     override val notificationDefaultTop: StateFlow<Float> = _notificationDefaultTop.asStateFlow()
71 
72     override val hasFocalArea = wallpaperRepository.shouldSendFocalArea
73 
74     override fun setShortcutAbsoluteTop(top: Float) {
75         _shortcutAbsoluteTop.value = top
76     }
77 
78     override fun setNotificationStackAbsoluteBottom(bottom: Float) {
79         _notificationStackAbsoluteBottom.value = bottom
80     }
81 
82     override fun setNotificationDefaultTop(top: Float) {
83         _notificationDefaultTop.value = top
84     }
85 
86     override fun setWallpaperFocalAreaBounds(bounds: RectF) {
87         _wallpaperFocalAreaBounds.value = bounds
88         wallpaperRepository.sendLockScreenLayoutChangeCommand(bounds)
89     }
90 
91     override fun setTapPosition(tapPosition: PointF) {
92         wallpaperRepository.sendTapCommand(tapPosition)
93     }
94 }
95