blob: c339634f263e8c3451d9347b9af16baee1a55185 [file] [log] [blame]
Sunny Goyalc99cb172017-10-19 16:15:09 -07001/*
2 * Copyright (C) 2017 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 */
Sunny Goyal85525172017-11-06 13:00:42 -080016package com.android.launcher3.uioverrides;
Sunny Goyalc99cb172017-10-19 16:15:09 -070017
18import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS;
19import static com.android.launcher3.Utilities.isAccessibilityEnabled;
20
21import android.graphics.Rect;
Sunny Goyalbe93f262017-10-20 17:05:27 -070022import android.view.View;
Sunny Goyalc99cb172017-10-19 16:15:09 -070023import android.view.accessibility.AccessibilityNodeInfo;
24
25import com.android.launcher3.DeviceProfile;
26import com.android.launcher3.Launcher;
27import com.android.launcher3.LauncherState;
28import com.android.launcher3.Workspace;
29import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
30
31/**
32 * Definition for overview state
33 */
34public class OverviewState extends LauncherState {
35
36 // The percent to shrink the workspace during overview mode
37 public static final float SCALE_FACTOR = 0.7f;
38
Sunny Goyalc4fa8c32017-11-07 12:23:58 -080039 private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE;
Sunny Goyalc99cb172017-10-19 16:15:09 -070040
41 public OverviewState(int id) {
Sunny Goyalbe93f262017-10-20 17:05:27 -070042 super(id, ContainerType.WORKSPACE, OVERVIEW_TRANSITION_MS, 1f, STATE_FLAGS);
Sunny Goyalc99cb172017-10-19 16:15:09 -070043 }
44
45 @Override
46 public float[] getWorkspaceScaleAndTranslation(Launcher launcher) {
47 DeviceProfile grid = launcher.getDeviceProfile();
48 Workspace ws = launcher.getWorkspace();
49 Rect insets = launcher.getDragLayer().getInsets();
50
Sunny Goyal16764582017-11-06 16:00:34 -080051 int overviewButtonBarHeight = OverviewPanel.getButtonBarHeight(launcher);
Sunny Goyalc99cb172017-10-19 16:15:09 -070052 int scaledHeight = (int) (SCALE_FACTOR * ws.getNormalChildHeight());
53 Rect workspacePadding = grid.getWorkspacePadding(null);
54 int workspaceTop = insets.top + workspacePadding.top;
55 int workspaceBottom = ws.getViewportHeight() - insets.bottom - workspacePadding.bottom;
56 int overviewTop = insets.top;
57 int overviewBottom = ws.getViewportHeight() - insets.bottom - overviewButtonBarHeight;
58 int workspaceOffsetTopEdge =
59 workspaceTop + ((workspaceBottom - workspaceTop) - scaledHeight) / 2;
60 int overviewOffsetTopEdge = overviewTop + (overviewBottom - overviewTop - scaledHeight) / 2;
61 return new float[] {SCALE_FACTOR, -workspaceOffsetTopEdge + overviewOffsetTopEdge };
62 }
63
64 @Override
65 public void onStateEnabled(Launcher launcher) {
66 launcher.getWorkspace().setPageRearrangeEnabled(true);
67
68 if (isAccessibilityEnabled(launcher)) {
69 launcher.getOverviewPanel().getChildAt(0).performAccessibilityAction(
70 AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
71 }
72 }
73
74 @Override
75 public void onStateDisabled(Launcher launcher) {
76 launcher.getWorkspace().setPageRearrangeEnabled(false);
77 }
Sunny Goyalbe93f262017-10-20 17:05:27 -070078
79 @Override
80 public View getFinalFocus(Launcher launcher) {
81 return launcher.getOverviewPanel();
82 }
Sunny Goyalc99cb172017-10-19 16:15:09 -070083}