• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.launcher3.taskbar
18 
19 import android.content.Context
20 import com.android.launcher3.statehandlers.DesktopVisibilityController
21 import com.android.launcher3.statehandlers.DesktopVisibilityController.TaskbarDesktopModeListener
22 import com.android.launcher3.taskbar.TaskbarBackgroundRenderer.Companion.MAX_ROUNDNESS
23 
24 /** Handles Taskbar in Desktop Windowing mode. */
25 class TaskbarDesktopModeController(
26     private val context: Context,
27     private val desktopVisibilityController: DesktopVisibilityController,
28 ) : TaskbarDesktopModeListener {
29     private lateinit var taskbarControllers: TaskbarControllers
30     private lateinit var taskbarSharedState: TaskbarSharedState
31 
initnull32     fun init(controllers: TaskbarControllers, sharedState: TaskbarSharedState) {
33         taskbarControllers = controllers
34         taskbarSharedState = sharedState
35         desktopVisibilityController.registerTaskbarDesktopModeListener(this)
36     }
37 
isInDesktopModenull38     fun isInDesktopMode(displayId: Int) = desktopVisibilityController.isInDesktopMode(displayId)
39 
40     fun isInDesktopModeAndNotInOverview(displayId: Int) =
41         desktopVisibilityController.isInDesktopModeAndNotInOverview(displayId)
42 
43     override fun onTaskbarCornerRoundingUpdate(doesAnyTaskRequireTaskbarRounding: Boolean) {
44         if (taskbarControllers.taskbarActivityContext.isDestroyed) return
45         taskbarSharedState.showCornerRadiusInDesktopMode = doesAnyTaskRequireTaskbarRounding
46         val cornerRadius = getTaskbarCornerRoundness(doesAnyTaskRequireTaskbarRounding)
47         taskbarControllers.taskbarCornerRoundness.animateToValue(cornerRadius).start()
48     }
49 
shouldShowDesktopTasksInTaskbarnull50     fun shouldShowDesktopTasksInTaskbar(): Boolean {
51         val activityContext = taskbarControllers.taskbarActivityContext
52         return isInDesktopMode(context.displayId) ||
53             activityContext.showDesktopTaskbarForFreeformDisplay() ||
54             (activityContext.showLockedTaskbarOnHome() &&
55                 taskbarControllers.taskbarStashController.isOnHome)
56     }
57 
getTaskbarCornerRoundnessnull58     fun getTaskbarCornerRoundness(doesAnyTaskRequireTaskbarRounding: Boolean): Float {
59         return if (doesAnyTaskRequireTaskbarRounding) {
60             MAX_ROUNDNESS
61         } else {
62             0f
63         }
64     }
65 
onDestroynull66     fun onDestroy() = desktopVisibilityController.unregisterTaskbarDesktopModeListener(this)
67 }
68