Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 1 | /* |
| 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 Goyal | 8552517 | 2017-11-06 13:00:42 -0800 | [diff] [blame] | 16 | package com.android.launcher3.uioverrides; |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 17 | |
| 18 | import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS; |
| 19 | import static com.android.launcher3.Utilities.isAccessibilityEnabled; |
| 20 | |
| 21 | import android.graphics.Rect; |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 22 | import android.view.View; |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 23 | import android.view.accessibility.AccessibilityNodeInfo; |
| 24 | |
| 25 | import com.android.launcher3.DeviceProfile; |
| 26 | import com.android.launcher3.Launcher; |
| 27 | import com.android.launcher3.LauncherState; |
| 28 | import com.android.launcher3.Workspace; |
| 29 | import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; |
| 30 | |
| 31 | /** |
| 32 | * Definition for overview state |
| 33 | */ |
| 34 | public 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 Goyal | c4fa8c3 | 2017-11-07 12:23:58 -0800 | [diff] [blame^] | 39 | private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE; |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 40 | |
| 41 | public OverviewState(int id) { |
Sunny Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 42 | super(id, ContainerType.WORKSPACE, OVERVIEW_TRANSITION_MS, 1f, STATE_FLAGS); |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 43 | } |
| 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 Goyal | 1676458 | 2017-11-06 16:00:34 -0800 | [diff] [blame] | 51 | int overviewButtonBarHeight = OverviewPanel.getButtonBarHeight(launcher); |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 52 | 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 Goyal | be93f26 | 2017-10-20 17:05:27 -0700 | [diff] [blame] | 78 | |
| 79 | @Override |
| 80 | public View getFinalFocus(Launcher launcher) { |
| 81 | return launcher.getOverviewPanel(); |
| 82 | } |
Sunny Goyal | c99cb17 | 2017-10-19 16:15:09 -0700 | [diff] [blame] | 83 | } |