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.
|
|
|
|
|
*/
|
2017-11-06 13:00:42 -08:00
|
|
|
package com.android.launcher3.uioverrides;
|
2017-10-19 16:15:09 -07:00
|
|
|
|
|
|
|
|
import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS;
|
2018-03-09 22:01:47 +00:00
|
|
|
import static com.android.launcher3.anim.Interpolators.DEACCEL_2;
|
2018-03-02 12:24:41 -08:00
|
|
|
import static com.android.launcher3.states.RotationHelper.REQUEST_ROTATE;
|
2017-10-19 16:15:09 -07:00
|
|
|
|
2017-12-06 10:25:07 -08:00
|
|
|
import android.graphics.Rect;
|
2017-10-20 17:05:27 -07:00
|
|
|
import android.view.View;
|
2017-10-19 16:15:09 -07:00
|
|
|
|
|
|
|
|
import com.android.launcher3.Launcher;
|
|
|
|
|
import com.android.launcher3.LauncherState;
|
2017-12-06 10:25:07 -08:00
|
|
|
import com.android.launcher3.Workspace;
|
2017-10-19 16:15:09 -07:00
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
|
2018-03-13 09:57:05 -07:00
|
|
|
import com.android.quickstep.views.RecentsView;
|
2017-10-19 16:15:09 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Definition for overview state
|
|
|
|
|
*/
|
|
|
|
|
public class OverviewState extends LauncherState {
|
|
|
|
|
|
2018-02-05 16:34:57 -08:00
|
|
|
private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED
|
2018-03-09 22:01:47 +00:00
|
|
|
| FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_UI;
|
2017-10-19 16:15:09 -07:00
|
|
|
|
|
|
|
|
public OverviewState(int id) {
|
2018-03-05 08:34:13 -08:00
|
|
|
this(id, OVERVIEW_TRANSITION_MS, STATE_FLAGS);
|
2018-03-02 14:57:46 -08:00
|
|
|
}
|
|
|
|
|
|
2018-03-05 08:34:13 -08:00
|
|
|
protected OverviewState(int id, int transitionDuration, int stateFlags) {
|
|
|
|
|
super(id, ContainerType.TASKSWITCHER, transitionDuration, stateFlags);
|
2017-10-19 16:15:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public float[] getWorkspaceScaleAndTranslation(Launcher launcher) {
|
2017-12-06 10:25:07 -08:00
|
|
|
Rect pageRect = new Rect();
|
2018-03-09 20:55:51 +00:00
|
|
|
RecentsView.getPageRect(launcher.getDeviceProfile(), launcher, pageRect);
|
2018-01-17 11:03:38 -08:00
|
|
|
|
2017-12-15 13:05:42 -08:00
|
|
|
if (launcher.getWorkspace().getNormalChildWidth() <= 0 || pageRect.isEmpty()) {
|
2017-12-06 10:25:07 -08:00
|
|
|
return super.getWorkspaceScaleAndTranslation(launcher);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 20:55:51 +00:00
|
|
|
return getScaleAndTranslationForPageRect(launcher, pageRect);
|
2017-10-19 16:15:09 -07:00
|
|
|
}
|
|
|
|
|
|
2018-03-14 12:05:00 +00:00
|
|
|
@Override
|
|
|
|
|
public float getOverviewTranslationX(Launcher launcher) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 16:15:09 -07:00
|
|
|
@Override
|
|
|
|
|
public void onStateEnabled(Launcher launcher) {
|
2017-11-10 17:54:44 -08:00
|
|
|
RecentsView rv = launcher.getOverviewPanel();
|
|
|
|
|
rv.setOverviewStateEnabled(true);
|
2017-10-19 16:15:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onStateDisabled(Launcher launcher) {
|
2017-11-10 17:54:44 -08:00
|
|
|
RecentsView rv = launcher.getOverviewPanel();
|
|
|
|
|
rv.setOverviewStateEnabled(false);
|
2017-10-19 16:15:09 -07:00
|
|
|
}
|
2017-10-20 17:05:27 -07:00
|
|
|
|
2018-03-02 12:24:41 -08:00
|
|
|
@Override
|
|
|
|
|
public void onStateTransitionEnd(Launcher launcher) {
|
|
|
|
|
launcher.getRotationHelper().setCurrentStateRequest(REQUEST_ROTATE);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
@Override
|
|
|
|
|
public View getFinalFocus(Launcher launcher) {
|
|
|
|
|
return launcher.getOverviewPanel();
|
|
|
|
|
}
|
2017-12-15 13:05:42 -08:00
|
|
|
|
2018-01-04 15:35:22 -08:00
|
|
|
public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) {
|
2018-03-09 22:01:47 +00:00
|
|
|
return new PageAlphaProvider(DEACCEL_2) {
|
2018-01-04 15:35:22 -08:00
|
|
|
@Override
|
|
|
|
|
public float getPageAlpha(int pageIndex) {
|
2018-03-09 22:01:47 +00:00
|
|
|
return 0;
|
2018-01-04 15:35:22 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 20:55:51 +00:00
|
|
|
public static float[] getScaleAndTranslationForPageRect(Launcher launcher, Rect pageRect) {
|
2017-12-15 13:05:42 -08:00
|
|
|
Workspace ws = launcher.getWorkspace();
|
|
|
|
|
float childWidth = ws.getNormalChildWidth();
|
|
|
|
|
|
2018-03-02 16:31:55 -08:00
|
|
|
float scale = pageRect.width() / childWidth;
|
2017-12-15 13:05:42 -08:00
|
|
|
Rect insets = launcher.getDragLayer().getInsets();
|
2017-12-21 12:40:38 -08:00
|
|
|
|
2018-01-18 14:02:47 -08:00
|
|
|
float halfHeight = ws.getExpectedHeight() / 2;
|
2017-12-15 13:05:42 -08:00
|
|
|
float childTop = halfHeight - scale * (halfHeight - ws.getPaddingTop() - insets.top);
|
2017-12-21 12:40:38 -08:00
|
|
|
float translationY = pageRect.top - childTop;
|
|
|
|
|
|
2018-03-09 20:55:51 +00:00
|
|
|
return new float[] {scale, 0, translationY};
|
2017-12-15 13:05:42 -08:00
|
|
|
}
|
2017-10-19 16:15:09 -07:00
|
|
|
}
|