• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2023 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 package com.android.launcher3.taskbar
17 
18 import android.view.View
19 import com.android.launcher3.LauncherPrefs
20 import com.android.launcher3.LauncherPrefs.Companion.TASKBAR_PINNING
21 import com.android.launcher3.taskbar.TaskbarDividerPopupView.Companion.createAndPopulate
22 import java.io.PrintWriter
23 
24 /** Controls taskbar pinning through a popup view. */
25 class TaskbarDividerPopupController(private val context: TaskbarActivityContext) :
26     TaskbarControllers.LoggableTaskbarController {
27 
28     private lateinit var controllers: TaskbarControllers
29     private val launcherPrefs = LauncherPrefs.get(context)
30 
31     fun init(taskbarControllers: TaskbarControllers) {
32         controllers = taskbarControllers
33     }
34 
35     fun showPinningView(view: View) {
36         context.isTaskbarWindowFullscreen = true
37 
38         view.post {
39             val popupView = createAndPopulate(view, context)
40             popupView.requestFocus()
41 
42             popupView.onCloseCallback =
43                 callback@{ didPreferenceChange ->
44                     context.dragLayer.post { context.onPopupVisibilityChanged(false) }
45 
46                     if (!didPreferenceChange) {
47                         return@callback
48                     }
49 
50                     if (launcherPrefs.get(TASKBAR_PINNING)) {
51                         animateTransientToPersistentTaskbar()
52                     } else {
53                         animatePersistentToTransientTaskbar()
54                     }
55                 }
56             popupView.changePreference = {
57                 launcherPrefs.put(TASKBAR_PINNING, !launcherPrefs.get(TASKBAR_PINNING))
58             }
59             context.onPopupVisibilityChanged(true)
60             popupView.show()
61         }
62     }
63 
64     // TODO(b/265436799): provide animation/transition from transient taskbar to persistent one
65     private fun animateTransientToPersistentTaskbar() {}
66 
67     // TODO(b/265436799): provide animation/transition from persistent taskbar to transient one
68     private fun animatePersistentToTransientTaskbar() {}
69 
70     override fun dumpLogs(prefix: String, pw: PrintWriter) {
71         pw.println(prefix + "TaskbarPinningController:")
72     }
73 }
74