1 /*
2  * 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.states
17 
18 import android.content.Context
19 import com.android.launcher3.Flags.enableScalingRevealHomeAnimation
20 import com.android.launcher3.Launcher
21 import com.android.launcher3.LauncherState
22 import com.android.launcher3.logging.StatsLogManager
23 import com.android.launcher3.views.ActivityContext
24 
25 /** Definition for Edit Mode state used for home gardening multi-select */
26 class EditModeState(id: Int) : LauncherState(id, StatsLogManager.LAUNCHER_STATE_HOME, STATE_FLAGS) {
27 
28     companion object {
29         const val DEPTH_15_PERCENT = 0.15f
30 
31         private val STATE_FLAGS =
32             (FLAG_MULTI_PAGE or
33                 FLAG_WORKSPACE_INACCESSIBLE or
34                 FLAG_DISABLE_RESTORE or
35                 FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED or
36                 FLAG_WORKSPACE_HAS_BACKGROUNDS)
37     }
38 
getTransitionDurationnull39     override fun <T> getTransitionDuration(context: T, isToState: Boolean): Int where
40     T : Context?,
41     T : ActivityContext? {
42         return 150
43     }
44 
getDepthUncheckednull45     override fun <T> getDepthUnchecked(context: T): Float where T : Context?, T : ActivityContext? {
46         if (enableScalingRevealHomeAnimation()) {
47             return DEPTH_15_PERCENT
48         } else {
49             return 0.5f
50         }
51     }
52 
getWorkspaceScaleAndTranslationnull53     override fun getWorkspaceScaleAndTranslation(launcher: Launcher): ScaleAndTranslation {
54         val scale = launcher.deviceProfile.getWorkspaceSpringLoadScale(launcher)
55         return ScaleAndTranslation(scale, 0f, 0f)
56     }
57 
getHotseatScaleAndTranslationnull58     override fun getHotseatScaleAndTranslation(launcher: Launcher): ScaleAndTranslation {
59         val scale = launcher.deviceProfile.getWorkspaceSpringLoadScale(launcher)
60         return ScaleAndTranslation(scale, 0f, 0f)
61     }
62 
getWorkspaceBackgroundAlphanull63     override fun getWorkspaceBackgroundAlpha(launcher: Launcher): Float {
64         return 0.2f
65     }
66 
onLeavingStatenull67     override fun onLeavingState(launcher: Launcher?, toState: LauncherState?) {
68         // cleanup any changes to workspace
69     }
70 }
71