2017-10-19 16:15:09 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2017 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.launcher3.states;
|
|
|
|
|
|
2022-10-13 14:09:38 -07:00
|
|
|
import static com.android.launcher3.config.FeatureFlags.SHOW_HOME_GARDENING;
|
2020-10-23 09:26:44 -07:00
|
|
|
import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME;
|
|
|
|
|
|
2020-03-24 12:13:17 -07:00
|
|
|
import android.content.Context;
|
2017-10-19 16:15:09 -07:00
|
|
|
|
|
|
|
|
import com.android.launcher3.DeviceProfile;
|
|
|
|
|
import com.android.launcher3.Launcher;
|
|
|
|
|
import com.android.launcher3.LauncherState;
|
|
|
|
|
import com.android.launcher3.Workspace;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Definition for spring loaded state used during drag and drop.
|
|
|
|
|
*/
|
|
|
|
|
public class SpringLoadedState extends LauncherState {
|
|
|
|
|
|
2020-04-23 19:00:36 -07:00
|
|
|
private static final int STATE_FLAGS = FLAG_MULTI_PAGE
|
|
|
|
|
| FLAG_WORKSPACE_INACCESSIBLE | FLAG_DISABLE_RESTORE
|
2022-09-09 17:14:45 -07:00
|
|
|
| FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED | FLAG_WORKSPACE_HAS_BACKGROUNDS;
|
2017-10-19 16:15:09 -07:00
|
|
|
|
|
|
|
|
public SpringLoadedState(int id) {
|
2020-10-23 09:26:44 -07:00
|
|
|
super(id, LAUNCHER_STATE_HOME, STATE_FLAGS);
|
2020-02-03 18:36:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-04-14 17:51:59 +01:00
|
|
|
public int getTransitionDuration(Context context, boolean isToState) {
|
2020-02-03 18:36:06 -08:00
|
|
|
return 150;
|
2017-10-19 16:15:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-03-19 13:30:25 -05:00
|
|
|
public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) {
|
2022-10-13 14:09:38 -07:00
|
|
|
|
|
|
|
|
if (SHOW_HOME_GARDENING.get()) {
|
|
|
|
|
return super.getWorkspaceScaleAndTranslation(launcher);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 16:15:09 -07:00
|
|
|
DeviceProfile grid = launcher.getDeviceProfile();
|
2022-04-11 10:23:18 +00:00
|
|
|
Workspace<?> ws = launcher.getWorkspace();
|
2018-01-04 15:35:22 -08:00
|
|
|
if (ws.getChildCount() == 0) {
|
2017-10-19 16:15:09 -07:00
|
|
|
return super.getWorkspaceScaleAndTranslation(launcher);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 09:58:49 +00:00
|
|
|
float shrunkTop = grid.getCellLayoutSpringLoadShrunkTop();
|
2022-07-20 12:08:54 +01:00
|
|
|
float scale = grid.getWorkspaceSpringLoadScale(launcher);
|
2017-10-19 16:15:09 -07:00
|
|
|
|
|
|
|
|
float halfHeight = ws.getHeight() / 2;
|
|
|
|
|
float myCenter = ws.getTop() + halfHeight;
|
|
|
|
|
float cellTopFromCenter = halfHeight - ws.getChildAt(0).getTop();
|
|
|
|
|
float actualCellTop = myCenter - cellTopFromCenter * scale;
|
2022-08-04 14:53:35 +01:00
|
|
|
return new ScaleAndTranslation(scale, 0, shrunkTop - actualCellTop);
|
2017-10-19 16:15:09 -07:00
|
|
|
}
|
|
|
|
|
|
2020-03-24 12:13:17 -07:00
|
|
|
@Override
|
2020-04-20 11:57:11 -07:00
|
|
|
protected float getDepthUnchecked(Context context) {
|
2022-10-13 14:09:38 -07:00
|
|
|
if (SHOW_HOME_GARDENING.get()) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2020-03-24 12:13:17 -07:00
|
|
|
return 0.5f;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-03 15:32:12 -08:00
|
|
|
@Override
|
2019-03-19 13:30:25 -05:00
|
|
|
public ScaleAndTranslation getHotseatScaleAndTranslation(Launcher launcher) {
|
|
|
|
|
return new ScaleAndTranslation(1, 0, 0);
|
2019-03-03 15:32:12 -08:00
|
|
|
}
|
|
|
|
|
|
2018-05-04 13:19:29 -07:00
|
|
|
@Override
|
2021-04-06 13:03:54 -07:00
|
|
|
public float getWorkspaceBackgroundAlpha(Launcher launcher) {
|
2022-10-13 14:09:38 -07:00
|
|
|
if (SHOW_HOME_GARDENING.get()) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 09:52:47 -07:00
|
|
|
return 0.2f;
|
2018-05-04 13:19:29 -07:00
|
|
|
}
|
2017-10-19 16:15:09 -07:00
|
|
|
}
|