2017-10-17 17:17:16 -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;
|
|
|
|
|
|
|
|
|
|
import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
|
|
|
|
|
import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
|
2017-10-23 17:14:52 -07:00
|
|
|
import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
|
2018-05-23 12:54:27 -07:00
|
|
|
|
2017-12-12 12:02:29 -08:00
|
|
|
import static com.android.launcher3.anim.Interpolators.ACCEL_2;
|
2018-03-02 12:24:41 -08:00
|
|
|
import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
|
2017-12-12 12:02:29 -08:00
|
|
|
|
|
|
|
|
import android.view.animation.Interpolator;
|
2017-10-20 17:05:27 -07:00
|
|
|
|
2017-10-19 16:15:09 -07:00
|
|
|
import com.android.launcher3.states.SpringLoadedState;
|
2018-03-02 12:24:41 -08:00
|
|
|
import com.android.launcher3.uioverrides.AllAppsState;
|
2018-09-05 12:47:21 -07:00
|
|
|
import com.android.launcher3.uioverrides.BackgroundAppState;
|
2018-03-02 14:57:46 -08:00
|
|
|
import com.android.launcher3.uioverrides.FastOverviewState;
|
2017-11-06 13:00:42 -08:00
|
|
|
import com.android.launcher3.uioverrides.OverviewState;
|
2018-01-15 14:23:11 -08:00
|
|
|
import com.android.launcher3.uioverrides.UiFactory;
|
2018-08-02 13:35:07 -07:00
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
|
2017-10-17 17:17:16 -07:00
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
|
|
|
|
|
|
2017-10-19 12:36:27 -07:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
2017-10-17 17:17:16 -07:00
|
|
|
|
|
|
|
|
/**
|
2017-10-20 17:05:27 -07:00
|
|
|
* Base state for various states used for the Launcher
|
2017-10-17 17:17:16 -07:00
|
|
|
*/
|
2017-10-19 12:36:27 -07:00
|
|
|
public class LauncherState {
|
|
|
|
|
|
2018-03-14 17:51:49 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set of elements indicating various workspace elements which change visibility across states
|
|
|
|
|
* Note that workspace is not included here as in that case, we animate individual pages
|
|
|
|
|
*/
|
|
|
|
|
public static final int NONE = 0;
|
2018-03-21 08:16:33 -07:00
|
|
|
public static final int HOTSEAT_ICONS = 1 << 0;
|
2018-03-26 12:10:31 -07:00
|
|
|
public static final int HOTSEAT_SEARCH_BOX = 1 << 1;
|
2018-03-21 08:16:33 -07:00
|
|
|
public static final int ALL_APPS_HEADER = 1 << 2;
|
|
|
|
|
public static final int ALL_APPS_HEADER_EXTRA = 1 << 3; // e.g. app predictions
|
|
|
|
|
public static final int ALL_APPS_CONTENT = 1 << 4;
|
2018-05-22 13:22:25 -07:00
|
|
|
public static final int VERTICAL_SWIPE_INDICATOR = 1 << 5;
|
2018-03-14 17:51:49 -07:00
|
|
|
|
2018-05-04 13:19:29 -07:00
|
|
|
protected static final int FLAG_MULTI_PAGE = 1 << 0;
|
|
|
|
|
protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 1;
|
|
|
|
|
protected static final int FLAG_DISABLE_RESTORE = 1 << 2;
|
|
|
|
|
protected static final int FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED = 1 << 3;
|
|
|
|
|
protected static final int FLAG_DISABLE_PAGE_CLIPPING = 1 << 4;
|
|
|
|
|
protected static final int FLAG_PAGE_BACKGROUNDS = 1 << 5;
|
|
|
|
|
protected static final int FLAG_DISABLE_INTERACTION = 1 << 6;
|
|
|
|
|
protected static final int FLAG_OVERVIEW_UI = 1 << 7;
|
|
|
|
|
protected static final int FLAG_HIDE_BACK_BUTTON = 1 << 8;
|
2018-05-08 11:10:44 -07:00
|
|
|
protected static final int FLAG_HAS_SYS_UI_SCRIM = 1 << 9;
|
2018-03-02 14:57:46 -08:00
|
|
|
|
2017-12-12 12:02:29 -08:00
|
|
|
protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER =
|
|
|
|
|
new PageAlphaProvider(ACCEL_2) {
|
|
|
|
|
@Override
|
|
|
|
|
public float getPageAlpha(int pageIndex) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-10-19 12:36:27 -07:00
|
|
|
|
2018-09-05 12:47:21 -07:00
|
|
|
private static final LauncherState[] sAllStates = new LauncherState[6];
|
2017-10-19 12:36:27 -07:00
|
|
|
|
2018-01-15 14:23:11 -08:00
|
|
|
/**
|
|
|
|
|
* TODO: Create a separate class for NORMAL state.
|
|
|
|
|
*/
|
2018-05-08 11:10:44 -07:00
|
|
|
public static final LauncherState NORMAL = new LauncherState(0, ContainerType.WORKSPACE, 0,
|
|
|
|
|
FLAG_DISABLE_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED | FLAG_HIDE_BACK_BUTTON |
|
|
|
|
|
FLAG_HAS_SYS_UI_SCRIM);
|
2017-10-19 12:36:27 -07:00
|
|
|
|
2018-03-14 17:51:49 -07:00
|
|
|
/**
|
|
|
|
|
* Various Launcher states arranged in the increasing order of UI layers
|
|
|
|
|
*/
|
|
|
|
|
public static final LauncherState SPRING_LOADED = new SpringLoadedState(1);
|
|
|
|
|
public static final LauncherState OVERVIEW = new OverviewState(2);
|
|
|
|
|
public static final LauncherState FAST_OVERVIEW = new FastOverviewState(3);
|
|
|
|
|
public static final LauncherState ALL_APPS = new AllAppsState(4);
|
2018-09-05 12:47:21 -07:00
|
|
|
public static final LauncherState BACKGROUND_APP = new BackgroundAppState(5);
|
2018-04-19 11:39:34 -07:00
|
|
|
|
2017-10-19 12:36:27 -07:00
|
|
|
public final int ordinal;
|
|
|
|
|
|
2017-10-18 10:55:56 -07:00
|
|
|
/**
|
|
|
|
|
* Used for containerType in {@link com.android.launcher3.logging.UserEventDispatcher}
|
|
|
|
|
*/
|
2017-10-17 17:17:16 -07:00
|
|
|
public final int containerType;
|
|
|
|
|
|
2017-10-18 10:55:56 -07:00
|
|
|
/**
|
|
|
|
|
* True if the state can be persisted across activity restarts.
|
|
|
|
|
*/
|
2017-12-06 10:25:07 -08:00
|
|
|
public final boolean disableRestore;
|
2017-10-18 10:55:56 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* True if workspace has multiple pages visible.
|
|
|
|
|
*/
|
2017-10-17 17:17:16 -07:00
|
|
|
public final boolean hasMultipleVisiblePages;
|
2017-10-18 10:55:56 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Accessibility flag for workspace and its pages.
|
|
|
|
|
* @see android.view.View#setImportantForAccessibility(int)
|
|
|
|
|
*/
|
2017-10-17 17:17:16 -07:00
|
|
|
public final int workspaceAccessibilityFlag;
|
|
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
/**
|
|
|
|
|
* Properties related to state transition animation
|
|
|
|
|
*
|
|
|
|
|
* @see WorkspaceStateTransitionAnimation
|
|
|
|
|
*/
|
2018-02-28 15:09:36 -08:00
|
|
|
public final boolean hasWorkspacePageBackground;
|
|
|
|
|
|
2017-10-17 17:17:16 -07:00
|
|
|
public final int transitionDuration;
|
|
|
|
|
|
2017-12-05 10:10:55 -08:00
|
|
|
/**
|
|
|
|
|
* True if the state allows workspace icons to be dragged.
|
|
|
|
|
*/
|
|
|
|
|
public final boolean workspaceIconsCanBeDragged;
|
|
|
|
|
|
2017-12-06 10:25:07 -08:00
|
|
|
/**
|
|
|
|
|
* True if the workspace pages should not be clipped relative to the workspace bounds
|
|
|
|
|
* for this state.
|
|
|
|
|
*/
|
|
|
|
|
public final boolean disablePageClipping;
|
|
|
|
|
|
2018-03-02 14:57:46 -08:00
|
|
|
/**
|
|
|
|
|
* True if launcher can not be directly interacted in this state;
|
|
|
|
|
*/
|
|
|
|
|
public final boolean disableInteraction;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* True if the state has overview panel visible.
|
|
|
|
|
*/
|
|
|
|
|
public final boolean overviewUi;
|
|
|
|
|
|
2018-03-20 14:13:16 -07:00
|
|
|
/**
|
|
|
|
|
* True if the back button should be hidden when in this state (assuming no floating views are
|
|
|
|
|
* open, launcher has window focus, etc).
|
|
|
|
|
*/
|
|
|
|
|
public final boolean hideBackButton;
|
|
|
|
|
|
2018-05-08 11:10:44 -07:00
|
|
|
public final boolean hasSysUiScrim;
|
|
|
|
|
|
2018-01-04 15:35:22 -08:00
|
|
|
public LauncherState(int id, int containerType, int transitionDuration, int flags) {
|
2017-10-17 17:17:16 -07:00
|
|
|
this.containerType = containerType;
|
|
|
|
|
this.transitionDuration = transitionDuration;
|
|
|
|
|
|
2018-02-28 15:09:36 -08:00
|
|
|
this.hasWorkspacePageBackground = (flags & FLAG_PAGE_BACKGROUNDS) != 0;
|
2017-10-17 17:17:16 -07:00
|
|
|
this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0;
|
|
|
|
|
this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0
|
|
|
|
|
? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
|
|
|
|
|
: IMPORTANT_FOR_ACCESSIBILITY_AUTO;
|
2017-12-06 10:25:07 -08:00
|
|
|
this.disableRestore = (flags & FLAG_DISABLE_RESTORE) != 0;
|
2017-12-05 10:10:55 -08:00
|
|
|
this.workspaceIconsCanBeDragged = (flags & FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED) != 0;
|
2017-12-06 10:25:07 -08:00
|
|
|
this.disablePageClipping = (flags & FLAG_DISABLE_PAGE_CLIPPING) != 0;
|
2018-03-02 14:57:46 -08:00
|
|
|
this.disableInteraction = (flags & FLAG_DISABLE_INTERACTION) != 0;
|
|
|
|
|
this.overviewUi = (flags & FLAG_OVERVIEW_UI) != 0;
|
2018-03-20 14:13:16 -07:00
|
|
|
this.hideBackButton = (flags & FLAG_HIDE_BACK_BUTTON) != 0;
|
2018-05-08 11:10:44 -07:00
|
|
|
this.hasSysUiScrim = (flags & FLAG_HAS_SYS_UI_SCRIM) != 0;
|
2017-10-19 12:36:27 -07:00
|
|
|
|
|
|
|
|
this.ordinal = id;
|
|
|
|
|
sAllStates[id] = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static LauncherState[] values() {
|
|
|
|
|
return Arrays.copyOf(sAllStates, sAllStates.length);
|
2017-10-17 17:17:16 -07:00
|
|
|
}
|
2017-10-19 16:15:09 -07:00
|
|
|
|
|
|
|
|
public float[] getWorkspaceScaleAndTranslation(Launcher launcher) {
|
2017-12-21 12:40:38 -08:00
|
|
|
return new float[] {1, 0, 0};
|
2017-10-19 16:15:09 -07:00
|
|
|
}
|
|
|
|
|
|
2018-03-15 12:48:51 +00:00
|
|
|
/**
|
2018-04-04 10:23:36 -07:00
|
|
|
* Returns 2 floats designating how to transition overview:
|
|
|
|
|
* scale for the current and adjacent pages
|
|
|
|
|
* translationY factor where 0 is top aligned and 0.5 is centered vertically
|
2018-03-15 12:48:51 +00:00
|
|
|
*/
|
2018-04-04 10:23:36 -07:00
|
|
|
public float[] getOverviewScaleAndTranslationYFactor(Launcher launcher) {
|
2018-05-16 12:23:12 -07:00
|
|
|
return new float[] {1.1f, 0f};
|
2018-03-14 12:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-23 17:14:52 -07:00
|
|
|
public void onStateEnabled(Launcher launcher) {
|
|
|
|
|
dispatchWindowStateChanged(launcher);
|
|
|
|
|
}
|
2017-10-19 16:15:09 -07:00
|
|
|
|
|
|
|
|
public void onStateDisabled(Launcher launcher) { }
|
2017-10-20 17:05:27 -07:00
|
|
|
|
2018-03-14 17:51:49 -07:00
|
|
|
public int getVisibleElements(Launcher launcher) {
|
2018-03-21 08:16:33 -07:00
|
|
|
if (launcher.getDeviceProfile().isVerticalBarLayout()) {
|
2018-05-22 13:22:25 -07:00
|
|
|
return HOTSEAT_ICONS | VERTICAL_SWIPE_INDICATOR;
|
2018-03-21 08:16:33 -07:00
|
|
|
}
|
2018-05-22 13:22:25 -07:00
|
|
|
return HOTSEAT_ICONS | HOTSEAT_SEARCH_BOX | VERTICAL_SWIPE_INDICATOR;
|
2018-03-14 17:51:49 -07:00
|
|
|
}
|
|
|
|
|
|
2018-01-04 15:35:22 -08:00
|
|
|
/**
|
|
|
|
|
* Fraction shift in the vertical translation UI and related properties
|
|
|
|
|
*
|
|
|
|
|
* @see com.android.launcher3.allapps.AllAppsTransitionController
|
|
|
|
|
*/
|
|
|
|
|
public float getVerticalProgress(Launcher launcher) {
|
|
|
|
|
return 1f;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-04 13:19:29 -07:00
|
|
|
public float getWorkspaceScrimAlpha(Launcher launcher) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-23 17:14:52 -07:00
|
|
|
public String getDescription(Launcher launcher) {
|
|
|
|
|
return launcher.getWorkspace().getCurrentPageDescription();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-06 10:25:07 -08:00
|
|
|
public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) {
|
|
|
|
|
if (this != NORMAL || !launcher.getDeviceProfile().shouldFadeAdjacentWorkspaceScreens()) {
|
|
|
|
|
return DEFAULT_ALPHA_PROVIDER;
|
|
|
|
|
}
|
2018-01-04 15:35:22 -08:00
|
|
|
final int centerPage = launcher.getWorkspace().getNextPage();
|
2017-12-12 12:02:29 -08:00
|
|
|
return new PageAlphaProvider(ACCEL_2) {
|
|
|
|
|
@Override
|
|
|
|
|
public float getPageAlpha(int pageIndex) {
|
|
|
|
|
return pageIndex != centerPage ? 0 : 1f;
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-12-06 10:25:07 -08:00
|
|
|
}
|
|
|
|
|
|
2018-01-11 13:59:53 -08:00
|
|
|
public LauncherState getHistoryForState(LauncherState previousState) {
|
|
|
|
|
// No history is supported
|
|
|
|
|
return NORMAL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-15 14:23:11 -08:00
|
|
|
/**
|
|
|
|
|
* Called when the start transition ends and the user settles on this particular state.
|
|
|
|
|
*/
|
|
|
|
|
public void onStateTransitionEnd(Launcher launcher) {
|
2018-06-05 16:26:32 -07:00
|
|
|
if (this == NORMAL || this == SPRING_LOADED) {
|
2018-01-15 14:23:11 -08:00
|
|
|
UiFactory.resetOverview(launcher);
|
2018-06-05 16:26:32 -07:00
|
|
|
}
|
|
|
|
|
if (this == NORMAL) {
|
2018-03-02 12:24:41 -08:00
|
|
|
// Clear any rotation locks when going to normal state
|
|
|
|
|
launcher.getRotationHelper().setCurrentStateRequest(REQUEST_NONE);
|
2018-01-15 14:23:11 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 13:35:07 -07:00
|
|
|
public void onBackPressed(Launcher launcher) {
|
|
|
|
|
if (this != NORMAL) {
|
|
|
|
|
LauncherStateManager lsm = launcher.getStateManager();
|
|
|
|
|
LauncherState lastState = lsm.getLastState();
|
|
|
|
|
launcher.getUserEventDispatcher().logActionCommand(Action.Command.BACK,
|
|
|
|
|
containerType, lastState.containerType);
|
|
|
|
|
lsm.goToState(lastState);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-23 17:14:52 -07:00
|
|
|
protected static void dispatchWindowStateChanged(Launcher launcher) {
|
|
|
|
|
launcher.getWindow().getDecorView().sendAccessibilityEvent(TYPE_WINDOW_STATE_CHANGED);
|
|
|
|
|
}
|
2017-12-06 10:25:07 -08:00
|
|
|
|
2017-12-12 12:02:29 -08:00
|
|
|
public static abstract class PageAlphaProvider {
|
|
|
|
|
|
|
|
|
|
public final Interpolator interpolator;
|
|
|
|
|
|
|
|
|
|
public PageAlphaProvider(Interpolator interpolator) {
|
|
|
|
|
this.interpolator = interpolator;
|
|
|
|
|
}
|
2017-12-06 10:25:07 -08:00
|
|
|
|
2017-12-12 12:02:29 -08:00
|
|
|
public abstract float getPageAlpha(int pageIndex);
|
2017-12-06 10:25:07 -08:00
|
|
|
}
|
2017-10-17 17:17:16 -07:00
|
|
|
}
|