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;
|
2017-10-17 17:17:16 -07:00
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
|
|
import com.android.launcher3.states.AllAppsState;
|
2017-10-19 16:15:09 -07:00
|
|
|
import com.android.launcher3.states.SpringLoadedState;
|
2017-11-06 13:00:42 -08:00
|
|
|
import com.android.launcher3.uioverrides.OverviewState;
|
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 {
|
|
|
|
|
|
|
|
|
|
protected static final int FLAG_SHOW_SCRIM = 1 << 0;
|
|
|
|
|
protected static final int FLAG_MULTI_PAGE = 1 << 1;
|
2017-11-07 12:23:58 -08:00
|
|
|
protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 2;
|
|
|
|
|
protected static final int FLAG_DO_NOT_RESTORE = 1 << 3;
|
2017-12-05 10:10:55 -08:00
|
|
|
protected static final int FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED = 1 << 4;
|
2017-10-19 12:36:27 -07:00
|
|
|
|
|
|
|
|
private static final LauncherState[] sAllStates = new LauncherState[4];
|
|
|
|
|
|
2017-10-19 16:15:09 -07:00
|
|
|
public static final LauncherState NORMAL = new LauncherState(0, ContainerType.WORKSPACE,
|
2017-12-05 10:10:55 -08:00
|
|
|
0, 1f, FLAG_DO_NOT_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED);
|
2017-10-19 12:36:27 -07:00
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
public static final LauncherState ALL_APPS = new AllAppsState(1);
|
2017-10-17 17:17:16 -07:00
|
|
|
|
2017-10-19 16:15:09 -07:00
|
|
|
public static final LauncherState SPRING_LOADED = new SpringLoadedState(2);
|
2017-10-19 12:36:27 -07:00
|
|
|
|
2017-11-06 13:00:42 -08:00
|
|
|
public static final LauncherState OVERVIEW = new OverviewState(3);
|
2017-10-17 17:17:16 -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.
|
|
|
|
|
*/
|
|
|
|
|
public final boolean doNotRestore;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2017-10-17 17:17:16 -07:00
|
|
|
public final boolean hasScrim;
|
|
|
|
|
public final int transitionDuration;
|
|
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
/**
|
|
|
|
|
* Fraction shift in the vertical translation UI and related properties
|
|
|
|
|
*
|
|
|
|
|
* @see com.android.launcher3.allapps.AllAppsTransitionController
|
|
|
|
|
*/
|
|
|
|
|
public final float verticalProgress;
|
|
|
|
|
|
2017-12-05 10:10:55 -08:00
|
|
|
/**
|
|
|
|
|
* True if the state allows workspace icons to be dragged.
|
|
|
|
|
*/
|
|
|
|
|
public final boolean workspaceIconsCanBeDragged;
|
|
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
public LauncherState(int id, int containerType, int transitionDuration, float verticalProgress,
|
|
|
|
|
int flags) {
|
2017-10-17 17:17:16 -07:00
|
|
|
this.containerType = containerType;
|
|
|
|
|
this.transitionDuration = transitionDuration;
|
|
|
|
|
|
|
|
|
|
this.hasScrim = (flags & FLAG_SHOW_SCRIM) != 0;
|
|
|
|
|
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-10-18 10:55:56 -07:00
|
|
|
this.doNotRestore = (flags & FLAG_DO_NOT_RESTORE) != 0;
|
2017-12-05 10:10:55 -08:00
|
|
|
this.workspaceIconsCanBeDragged = (flags & FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED) != 0;
|
2017-10-19 12:36:27 -07:00
|
|
|
|
2017-10-20 17:05:27 -07:00
|
|
|
this.verticalProgress = verticalProgress;
|
|
|
|
|
|
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) {
|
|
|
|
|
return new float[] {1, 0};
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
public View getFinalFocus(Launcher launcher) {
|
|
|
|
|
return launcher.getWorkspace();
|
|
|
|
|
}
|
2017-10-23 17:14:52 -07:00
|
|
|
|
|
|
|
|
public String getDescription(Launcher launcher) {
|
|
|
|
|
return launcher.getWorkspace().getCurrentPageDescription();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static void dispatchWindowStateChanged(Launcher launcher) {
|
|
|
|
|
launcher.getWindow().getDecorView().sendAccessibilityEvent(TYPE_WINDOW_STATE_CHANGED);
|
|
|
|
|
}
|
2017-10-17 17:17:16 -07:00
|
|
|
}
|