2020-12-22 12:40:09 -06:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2021 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.taskbar;
|
|
|
|
|
|
2021-04-16 12:50:22 -07:00
|
|
|
import static android.view.View.GONE;
|
|
|
|
|
import static android.view.View.INVISIBLE;
|
|
|
|
|
import static android.view.View.VISIBLE;
|
2020-12-22 12:40:09 -06:00
|
|
|
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
|
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
|
|
|
|
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
|
|
|
|
|
|
|
|
|
import static com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_BOTTOM_TAPPABLE_ELEMENT;
|
|
|
|
|
import static com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_EXTRA_NAVIGATION_BAR;
|
|
|
|
|
|
2020-12-23 16:12:18 -06:00
|
|
|
import android.animation.Animator;
|
2021-03-03 17:33:28 -08:00
|
|
|
import android.animation.AnimatorListenerAdapter;
|
2021-01-27 16:27:15 -08:00
|
|
|
import android.app.ActivityOptions;
|
2020-12-22 12:40:09 -06:00
|
|
|
import android.graphics.PixelFormat;
|
|
|
|
|
import android.graphics.Point;
|
2021-03-02 12:28:25 -08:00
|
|
|
import android.graphics.Rect;
|
2021-04-16 12:50:22 -07:00
|
|
|
import android.inputmethodservice.InputMethodService;
|
2020-12-22 12:40:09 -06:00
|
|
|
import android.view.Gravity;
|
2021-01-22 18:45:04 -08:00
|
|
|
import android.view.MotionEvent;
|
2021-01-11 14:54:23 -06:00
|
|
|
import android.view.View;
|
2020-12-22 12:40:09 -06:00
|
|
|
import android.view.WindowManager;
|
|
|
|
|
|
2020-12-23 16:12:18 -06:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
2021-02-02 17:12:08 -08:00
|
|
|
import com.android.launcher3.AbstractFloatingView;
|
2020-12-22 12:40:09 -06:00
|
|
|
import com.android.launcher3.BaseQuickstepLauncher;
|
2021-03-09 17:27:53 -08:00
|
|
|
import com.android.launcher3.DeviceProfile;
|
2020-12-23 16:12:18 -06:00
|
|
|
import com.android.launcher3.LauncherState;
|
2021-03-07 15:09:11 -08:00
|
|
|
import com.android.launcher3.QuickstepTransitionManager;
|
2020-12-22 12:40:09 -06:00
|
|
|
import com.android.launcher3.R;
|
2021-04-05 16:14:39 -07:00
|
|
|
import com.android.launcher3.anim.AlphaUpdateListener;
|
2020-12-23 16:12:18 -06:00
|
|
|
import com.android.launcher3.anim.PendingAnimation;
|
2021-02-02 17:12:08 -08:00
|
|
|
import com.android.launcher3.folder.Folder;
|
|
|
|
|
import com.android.launcher3.folder.FolderIcon;
|
|
|
|
|
import com.android.launcher3.model.data.FolderInfo;
|
2021-01-11 14:54:23 -06:00
|
|
|
import com.android.launcher3.model.data.ItemInfo;
|
2020-12-23 16:12:18 -06:00
|
|
|
import com.android.launcher3.states.StateAnimationConfig;
|
2021-03-25 12:31:23 -07:00
|
|
|
import com.android.launcher3.taskbar.TaskbarNavButtonController.TaskbarButton;
|
2021-01-11 14:54:23 -06:00
|
|
|
import com.android.launcher3.touch.ItemClickHandler;
|
2021-03-22 14:43:58 -07:00
|
|
|
import com.android.launcher3.views.ActivityContext;
|
2020-12-23 16:12:18 -06:00
|
|
|
import com.android.quickstep.AnimatedFloat;
|
2021-03-25 12:31:23 -07:00
|
|
|
import com.android.quickstep.SysUINavigationMode;
|
2021-04-16 12:50:22 -07:00
|
|
|
import com.android.quickstep.TouchInteractionService.TaskbarOverviewProxyDelegate;
|
2021-01-27 16:27:15 -08:00
|
|
|
import com.android.systemui.shared.recents.model.Task;
|
|
|
|
|
import com.android.systemui.shared.system.ActivityManagerWrapper;
|
2020-12-22 12:40:09 -06:00
|
|
|
import com.android.systemui.shared.system.WindowManagerWrapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Interfaces with Launcher/WindowManager/SystemUI to determine what to show in TaskbarView.
|
|
|
|
|
*/
|
2021-04-16 12:50:22 -07:00
|
|
|
public class TaskbarController implements TaskbarOverviewProxyDelegate {
|
2020-12-22 12:40:09 -06:00
|
|
|
|
|
|
|
|
private static final String WINDOW_TITLE = "Taskbar";
|
|
|
|
|
|
|
|
|
|
private final TaskbarContainerView mTaskbarContainerView;
|
2021-03-22 14:43:58 -07:00
|
|
|
private final TaskbarView mTaskbarViewInApp;
|
|
|
|
|
private final TaskbarView mTaskbarViewOnHome;
|
2021-04-16 12:50:22 -07:00
|
|
|
private final ImeBarView mImeBarView;
|
|
|
|
|
|
2020-12-22 12:40:09 -06:00
|
|
|
private final BaseQuickstepLauncher mLauncher;
|
|
|
|
|
private final WindowManager mWindowManager;
|
|
|
|
|
// Layout width and height of the Taskbar in the default state.
|
|
|
|
|
private final Point mTaskbarSize;
|
2020-12-23 16:12:18 -06:00
|
|
|
private final TaskbarStateHandler mTaskbarStateHandler;
|
2021-03-22 17:32:50 -07:00
|
|
|
private final TaskbarAnimationController mTaskbarAnimationController;
|
2021-01-11 14:54:23 -06:00
|
|
|
private final TaskbarHotseatController mHotseatController;
|
2021-01-22 18:45:04 -08:00
|
|
|
private final TaskbarDragController mDragController;
|
2021-03-25 12:31:23 -07:00
|
|
|
private final TaskbarNavButtonController mNavButtonController;
|
2020-12-22 12:40:09 -06:00
|
|
|
|
2020-12-23 16:12:18 -06:00
|
|
|
// Initialized in init().
|
2020-12-22 12:40:09 -06:00
|
|
|
private WindowManager.LayoutParams mWindowLayoutParams;
|
2021-03-25 12:31:23 -07:00
|
|
|
private SysUINavigationMode.Mode mNavMode = SysUINavigationMode.Mode.NO_BUTTON;
|
|
|
|
|
private final SysUINavigationMode.NavigationModeChangeListener mNavigationModeChangeListener =
|
|
|
|
|
this::onNavModeChanged;
|
2020-12-22 12:40:09 -06:00
|
|
|
|
2021-03-08 10:14:10 -08:00
|
|
|
private @Nullable Animator mAnimator;
|
2021-03-03 17:33:28 -08:00
|
|
|
private boolean mIsAnimatingToLauncher;
|
|
|
|
|
|
2020-12-22 12:40:09 -06:00
|
|
|
public TaskbarController(BaseQuickstepLauncher launcher,
|
2021-03-22 14:43:58 -07:00
|
|
|
TaskbarContainerView taskbarContainerView, TaskbarView taskbarViewOnHome) {
|
2020-12-22 12:40:09 -06:00
|
|
|
mLauncher = launcher;
|
|
|
|
|
mTaskbarContainerView = taskbarContainerView;
|
2021-02-02 17:12:08 -08:00
|
|
|
mTaskbarContainerView.construct(createTaskbarContainerViewCallbacks());
|
2021-04-16 12:50:22 -07:00
|
|
|
ButtonProvider buttonProvider = new ButtonProvider(launcher);
|
2021-03-22 14:43:58 -07:00
|
|
|
mTaskbarViewInApp = mTaskbarContainerView.findViewById(R.id.taskbar_view);
|
2021-04-16 12:50:22 -07:00
|
|
|
mTaskbarViewInApp.construct(createTaskbarViewCallbacks(), buttonProvider);
|
2021-03-22 14:43:58 -07:00
|
|
|
mTaskbarViewOnHome = taskbarViewOnHome;
|
2021-04-16 12:50:22 -07:00
|
|
|
mTaskbarViewOnHome.construct(createTaskbarViewCallbacks(), buttonProvider);
|
|
|
|
|
mImeBarView = mTaskbarContainerView.findViewById(R.id.ime_bar_view);
|
|
|
|
|
mImeBarView.construct(buttonProvider);
|
2021-03-25 12:31:23 -07:00
|
|
|
mNavButtonController = new TaskbarNavButtonController(launcher);
|
2020-12-22 12:40:09 -06:00
|
|
|
mWindowManager = mLauncher.getWindowManager();
|
2021-02-12 11:24:40 -08:00
|
|
|
mTaskbarSize = new Point(MATCH_PARENT, mLauncher.getDeviceProfile().taskbarSize);
|
2020-12-23 16:12:18 -06:00
|
|
|
mTaskbarStateHandler = mLauncher.getTaskbarStateHandler();
|
2021-03-22 17:32:50 -07:00
|
|
|
mTaskbarAnimationController = new TaskbarAnimationController(mLauncher,
|
|
|
|
|
createTaskbarAnimationControllerCallbacks());
|
2021-01-11 14:54:23 -06:00
|
|
|
mHotseatController = new TaskbarHotseatController(mLauncher,
|
|
|
|
|
createTaskbarHotseatControllerCallbacks());
|
2021-01-22 18:45:04 -08:00
|
|
|
mDragController = new TaskbarDragController(mLauncher);
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
|
|
|
|
|
2021-03-22 17:32:50 -07:00
|
|
|
private TaskbarAnimationControllerCallbacks createTaskbarAnimationControllerCallbacks() {
|
|
|
|
|
return new TaskbarAnimationControllerCallbacks() {
|
2020-12-23 16:12:18 -06:00
|
|
|
@Override
|
|
|
|
|
public void updateTaskbarBackgroundAlpha(float alpha) {
|
2021-04-07 11:06:40 -07:00
|
|
|
mTaskbarContainerView.setTaskbarBackgroundAlpha(alpha);
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateTaskbarVisibilityAlpha(float alpha) {
|
2021-04-16 12:50:22 -07:00
|
|
|
mTaskbarViewInApp.setAlpha(alpha);
|
2021-03-22 14:43:58 -07:00
|
|
|
mTaskbarViewOnHome.setAlpha(alpha);
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
2021-03-22 17:32:50 -07:00
|
|
|
|
2021-04-16 12:50:22 -07:00
|
|
|
@Override
|
|
|
|
|
public void updateImeBarVisibilityAlpha(float alpha) {
|
|
|
|
|
if (mNavMode != SysUINavigationMode.Mode.THREE_BUTTONS) {
|
|
|
|
|
// TODO Remove sysui IME bar for gesture nav as well
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mImeBarView.setAlpha(alpha);
|
|
|
|
|
mImeBarView.setVisibility(alpha == 0 ? GONE : VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 17:32:50 -07:00
|
|
|
@Override
|
|
|
|
|
public void updateTaskbarScale(float scale) {
|
|
|
|
|
mTaskbarViewInApp.setScaleX(scale);
|
|
|
|
|
mTaskbarViewInApp.setScaleY(scale);
|
|
|
|
|
}
|
2021-04-07 11:06:40 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateTaskbarTranslationY(float translationY) {
|
|
|
|
|
if (translationY < 0) {
|
|
|
|
|
// Resize to accommodate the max translation we'll reach.
|
|
|
|
|
setTaskbarWindowHeight(mTaskbarSize.y
|
|
|
|
|
+ mLauncher.getHotseat().getTaskbarOffsetY());
|
|
|
|
|
} else {
|
|
|
|
|
setTaskbarWindowHeight(mTaskbarSize.y);
|
|
|
|
|
}
|
|
|
|
|
mTaskbarViewInApp.setTranslationY(translationY);
|
|
|
|
|
}
|
2020-12-23 16:12:18 -06:00
|
|
|
};
|
2020-12-22 12:40:09 -06:00
|
|
|
}
|
|
|
|
|
|
2021-02-02 17:12:08 -08:00
|
|
|
private TaskbarContainerViewCallbacks createTaskbarContainerViewCallbacks() {
|
|
|
|
|
return new TaskbarContainerViewCallbacks() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onViewRemoved() {
|
2021-04-16 12:50:22 -07:00
|
|
|
// Ensure no other children present (like Folders, etc)
|
|
|
|
|
for (int i = 0; i < mTaskbarContainerView.getChildCount(); i++) {
|
|
|
|
|
View v = mTaskbarContainerView.getChildAt(i);
|
|
|
|
|
if (!((v instanceof TaskbarView) || (v instanceof ImeBarView))){
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-02-02 17:12:08 -08:00
|
|
|
}
|
2021-04-16 12:50:22 -07:00
|
|
|
setTaskbarWindowFullscreen(false);
|
2021-02-02 17:12:08 -08:00
|
|
|
}
|
2021-04-05 16:14:39 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isTaskbarTouchable() {
|
|
|
|
|
return mTaskbarContainerView.getAlpha() > AlphaUpdateListener.ALPHA_CUTOFF_THRESHOLD
|
2021-04-16 12:50:22 -07:00
|
|
|
&& (mTaskbarViewInApp.getVisibility() == VISIBLE
|
|
|
|
|
|| mImeBarView.getVisibility() == VISIBLE)
|
2021-04-05 16:14:39 -07:00
|
|
|
&& !mIsAnimatingToLauncher;
|
|
|
|
|
}
|
2021-02-02 17:12:08 -08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 14:54:23 -06:00
|
|
|
private TaskbarViewCallbacks createTaskbarViewCallbacks() {
|
|
|
|
|
return new TaskbarViewCallbacks() {
|
|
|
|
|
@Override
|
|
|
|
|
public View.OnClickListener getItemOnClickListener() {
|
2021-01-27 16:27:15 -08:00
|
|
|
return view -> {
|
|
|
|
|
Object tag = view.getTag();
|
|
|
|
|
if (tag instanceof Task) {
|
|
|
|
|
Task task = (Task) tag;
|
|
|
|
|
ActivityManagerWrapper.getInstance().startActivityFromRecents(task.key,
|
|
|
|
|
ActivityOptions.makeBasic());
|
2021-02-02 17:12:08 -08:00
|
|
|
} else if (tag instanceof FolderInfo) {
|
2021-03-22 17:19:41 -07:00
|
|
|
FolderIcon folderIcon = (FolderIcon) view;
|
|
|
|
|
Folder folder = folderIcon.getFolder();
|
|
|
|
|
|
|
|
|
|
setTaskbarWindowFullscreen(true);
|
|
|
|
|
|
|
|
|
|
mTaskbarContainerView.post(() -> {
|
|
|
|
|
folder.animateOpen();
|
|
|
|
|
|
|
|
|
|
folder.iterateOverItems((itemInfo, itemView) -> {
|
|
|
|
|
itemView.setOnClickListener(getItemOnClickListener());
|
|
|
|
|
itemView.setOnLongClickListener(getItemOnLongClickListener());
|
|
|
|
|
// To play haptic when dragging, like other Taskbar items do.
|
|
|
|
|
itemView.setHapticFeedbackEnabled(true);
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
});
|
2021-01-27 16:27:15 -08:00
|
|
|
} else {
|
|
|
|
|
ItemClickHandler.INSTANCE.onClick(view);
|
|
|
|
|
}
|
2021-02-02 17:12:08 -08:00
|
|
|
|
|
|
|
|
AbstractFloatingView.closeAllOpenViews(
|
|
|
|
|
mTaskbarContainerView.getTaskbarActivityContext());
|
2021-01-27 16:27:15 -08:00
|
|
|
};
|
2021-01-11 14:54:23 -06:00
|
|
|
}
|
2021-01-22 18:45:04 -08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public View.OnLongClickListener getItemOnLongClickListener() {
|
2021-03-22 17:19:41 -07:00
|
|
|
return mDragController::startSystemDragOnLongClick;
|
2021-01-22 18:45:04 -08:00
|
|
|
}
|
2021-03-03 17:33:28 -08:00
|
|
|
|
|
|
|
|
@Override
|
2021-03-22 14:43:58 -07:00
|
|
|
public int getEmptyHotseatViewVisibility(TaskbarView taskbarView) {
|
2021-03-03 17:33:28 -08:00
|
|
|
// When on the home screen, we want the empty hotseat views to take up their full
|
|
|
|
|
// space so that the others line up with the home screen hotseat.
|
2021-03-22 14:43:58 -07:00
|
|
|
boolean isOnHomeScreen = taskbarView == mTaskbarViewOnHome
|
|
|
|
|
|| mLauncher.hasBeenResumed() || mIsAnimatingToLauncher;
|
2021-04-16 12:50:22 -07:00
|
|
|
return isOnHomeScreen ? INVISIBLE : GONE;
|
2021-03-22 14:43:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public float getNonIconScale(TaskbarView taskbarView) {
|
|
|
|
|
return taskbarView == mTaskbarViewOnHome ? getTaskbarScaleOnHome() : 1f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemPositionsChanged(TaskbarView taskbarView) {
|
|
|
|
|
if (taskbarView == mTaskbarViewOnHome) {
|
|
|
|
|
alignRealHotseatWithTaskbar();
|
|
|
|
|
}
|
2021-03-03 17:33:28 -08:00
|
|
|
}
|
2021-03-25 12:31:23 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onNavigationButtonClick(@TaskbarButton int buttonType) {
|
|
|
|
|
mNavButtonController.onButtonClick(buttonType);
|
|
|
|
|
}
|
2021-01-11 14:54:23 -06:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TaskbarHotseatControllerCallbacks createTaskbarHotseatControllerCallbacks() {
|
|
|
|
|
return new TaskbarHotseatControllerCallbacks() {
|
|
|
|
|
@Override
|
|
|
|
|
public void updateHotseatItems(ItemInfo[] hotseatItemInfos) {
|
2021-03-22 14:43:58 -07:00
|
|
|
mTaskbarViewInApp.updateHotseatItems(hotseatItemInfos);
|
2021-01-11 14:54:23 -06:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-22 12:40:09 -06:00
|
|
|
/**
|
|
|
|
|
* Initializes the Taskbar, including adding it to the screen.
|
|
|
|
|
*/
|
|
|
|
|
public void init() {
|
2021-03-25 12:31:23 -07:00
|
|
|
mNavMode = SysUINavigationMode.INSTANCE.get(mLauncher)
|
|
|
|
|
.addModeChangeListener(mNavigationModeChangeListener);
|
|
|
|
|
mTaskbarViewInApp.init(mHotseatController.getNumHotseatIcons(), mNavMode);
|
|
|
|
|
mTaskbarViewOnHome.init(mHotseatController.getNumHotseatIcons(), mNavMode);
|
2021-03-22 14:43:58 -07:00
|
|
|
mTaskbarContainerView.init(mTaskbarViewInApp);
|
2021-04-16 12:50:22 -07:00
|
|
|
mImeBarView.init(createTaskbarViewCallbacks());
|
2020-12-22 12:40:09 -06:00
|
|
|
addToWindowManager();
|
2020-12-23 16:12:18 -06:00
|
|
|
mTaskbarStateHandler.setTaskbarCallbacks(createTaskbarStateHandlerCallbacks());
|
2021-03-22 17:32:50 -07:00
|
|
|
mTaskbarAnimationController.init();
|
2021-01-11 14:54:23 -06:00
|
|
|
mHotseatController.init();
|
2021-03-02 12:28:25 -08:00
|
|
|
|
2021-03-25 17:15:18 -07:00
|
|
|
setWhichTaskbarViewIsVisible(mLauncher.hasBeenResumed()
|
|
|
|
|
? mTaskbarViewOnHome
|
|
|
|
|
: mTaskbarViewInApp);
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TaskbarStateHandlerCallbacks createTaskbarStateHandlerCallbacks() {
|
|
|
|
|
return new TaskbarStateHandlerCallbacks() {
|
|
|
|
|
@Override
|
|
|
|
|
public AnimatedFloat getAlphaTarget() {
|
2021-03-22 17:32:50 -07:00
|
|
|
return mTaskbarAnimationController.getTaskbarVisibilityForLauncherState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public AnimatedFloat getScaleTarget() {
|
|
|
|
|
return mTaskbarAnimationController.getTaskbarScaleForLauncherState();
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
2021-04-07 11:06:40 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public AnimatedFloat getTranslationYTarget() {
|
|
|
|
|
return mTaskbarAnimationController.getTaskbarTranslationYForLauncherState();
|
|
|
|
|
}
|
2020-12-23 16:12:18 -06:00
|
|
|
};
|
2020-12-22 12:40:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the Taskbar from the screen, and removes any obsolete listeners etc.
|
|
|
|
|
*/
|
|
|
|
|
public void cleanup() {
|
2021-03-10 09:33:11 -08:00
|
|
|
if (mAnimator != null) {
|
|
|
|
|
// End this first, in case it relies on properties that are about to be cleaned up.
|
|
|
|
|
mAnimator.end();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 14:43:58 -07:00
|
|
|
mTaskbarViewInApp.cleanup();
|
|
|
|
|
mTaskbarViewOnHome.cleanup();
|
2021-02-02 11:04:25 -08:00
|
|
|
mTaskbarContainerView.cleanup();
|
2021-04-16 12:50:22 -07:00
|
|
|
mImeBarView.cleanup();
|
2020-12-22 12:40:09 -06:00
|
|
|
removeFromWindowManager();
|
2020-12-23 16:12:18 -06:00
|
|
|
mTaskbarStateHandler.setTaskbarCallbacks(null);
|
2021-03-22 17:32:50 -07:00
|
|
|
mTaskbarAnimationController.cleanup();
|
2021-01-11 14:54:23 -06:00
|
|
|
mHotseatController.cleanup();
|
2021-03-25 17:15:18 -07:00
|
|
|
|
|
|
|
|
setWhichTaskbarViewIsVisible(null);
|
2021-03-25 12:31:23 -07:00
|
|
|
SysUINavigationMode.INSTANCE.get(mLauncher)
|
|
|
|
|
.removeModeChangeListener(mNavigationModeChangeListener);
|
2020-12-22 12:40:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void removeFromWindowManager() {
|
2021-02-17 15:20:31 -08:00
|
|
|
mWindowManager.removeViewImmediate(mTaskbarContainerView);
|
2020-12-22 12:40:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addToWindowManager() {
|
|
|
|
|
final int gravity = Gravity.BOTTOM;
|
|
|
|
|
|
|
|
|
|
mWindowLayoutParams = new WindowManager.LayoutParams(
|
|
|
|
|
mTaskbarSize.x,
|
|
|
|
|
mTaskbarSize.y,
|
|
|
|
|
TYPE_APPLICATION_OVERLAY,
|
|
|
|
|
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
|
|
|
|
|
PixelFormat.TRANSLUCENT);
|
|
|
|
|
mWindowLayoutParams.setTitle(WINDOW_TITLE);
|
|
|
|
|
mWindowLayoutParams.packageName = mLauncher.getPackageName();
|
|
|
|
|
mWindowLayoutParams.gravity = gravity;
|
|
|
|
|
mWindowLayoutParams.setFitInsetsTypes(0);
|
|
|
|
|
mWindowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
|
|
|
|
|
mWindowLayoutParams.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
2021-02-04 08:36:08 -08:00
|
|
|
mWindowLayoutParams.setSystemApplicationOverlay(true);
|
2020-12-22 12:40:09 -06:00
|
|
|
|
|
|
|
|
WindowManagerWrapper wmWrapper = WindowManagerWrapper.getInstance();
|
|
|
|
|
wmWrapper.setProvidesInsetsTypes(
|
|
|
|
|
mWindowLayoutParams,
|
|
|
|
|
new int[] { ITYPE_EXTRA_NAVIGATION_BAR, ITYPE_BOTTOM_TAPPABLE_ELEMENT }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
TaskbarContainerView.LayoutParams taskbarLayoutParams =
|
|
|
|
|
new TaskbarContainerView.LayoutParams(mTaskbarSize.x, mTaskbarSize.y);
|
|
|
|
|
taskbarLayoutParams.gravity = gravity;
|
2021-03-22 14:43:58 -07:00
|
|
|
mTaskbarViewInApp.setLayoutParams(taskbarLayoutParams);
|
2020-12-22 12:40:09 -06:00
|
|
|
|
|
|
|
|
mWindowManager.addView(mTaskbarContainerView, mWindowLayoutParams);
|
|
|
|
|
}
|
2020-12-23 16:12:18 -06:00
|
|
|
|
2021-03-25 12:31:23 -07:00
|
|
|
private void onNavModeChanged(SysUINavigationMode.Mode newMode) {
|
|
|
|
|
mNavMode = newMode;
|
|
|
|
|
cleanup();
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 16:12:18 -06:00
|
|
|
/**
|
|
|
|
|
* Should be called from onResume() and onPause(), and animates the Taskbar accordingly.
|
|
|
|
|
*/
|
|
|
|
|
public void onLauncherResumedOrPaused(boolean isResumed) {
|
2021-03-07 15:09:11 -08:00
|
|
|
long duration = QuickstepTransitionManager.CONTENT_ALPHA_DURATION;
|
2021-03-08 10:14:10 -08:00
|
|
|
if (mAnimator != null) {
|
|
|
|
|
mAnimator.cancel();
|
|
|
|
|
}
|
2020-12-23 16:12:18 -06:00
|
|
|
if (isResumed) {
|
2021-03-08 10:14:10 -08:00
|
|
|
mAnimator = createAnimToLauncher(null, duration);
|
2020-12-23 16:12:18 -06:00
|
|
|
} else {
|
2021-03-08 10:14:10 -08:00
|
|
|
mAnimator = createAnimToApp(duration);
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
2021-03-08 10:14:10 -08:00
|
|
|
mAnimator.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
mAnimator = null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
mAnimator.start();
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create Taskbar animation when going from an app to Launcher.
|
|
|
|
|
* @param toState If known, the state we will end up in when reaching Launcher.
|
|
|
|
|
*/
|
|
|
|
|
public Animator createAnimToLauncher(@Nullable LauncherState toState, long duration) {
|
|
|
|
|
PendingAnimation anim = new PendingAnimation(duration);
|
2021-03-22 17:32:50 -07:00
|
|
|
anim.add(mTaskbarAnimationController.createAnimToBackgroundAlpha(0, duration));
|
2020-12-23 16:12:18 -06:00
|
|
|
if (toState != null) {
|
|
|
|
|
mTaskbarStateHandler.setStateWithAnimation(toState, new StateAnimationConfig(), anim);
|
|
|
|
|
}
|
2021-03-03 17:33:28 -08:00
|
|
|
|
|
|
|
|
anim.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
|
mIsAnimatingToLauncher = true;
|
2021-03-22 14:43:58 -07:00
|
|
|
mTaskbarViewInApp.updateHotseatItemsVisibility();
|
2021-03-03 17:33:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
mIsAnimatingToLauncher = false;
|
2021-03-25 17:15:18 -07:00
|
|
|
setWhichTaskbarViewIsVisible(mTaskbarViewOnHome);
|
2021-03-03 17:33:28 -08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-23 16:12:18 -06:00
|
|
|
return anim.buildAnim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Animator createAnimToApp(long duration) {
|
2021-03-02 12:28:25 -08:00
|
|
|
PendingAnimation anim = new PendingAnimation(duration);
|
2021-03-22 17:32:50 -07:00
|
|
|
anim.add(mTaskbarAnimationController.createAnimToBackgroundAlpha(1, duration));
|
2021-03-03 17:33:28 -08:00
|
|
|
anim.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animator animation) {
|
2021-03-22 14:43:58 -07:00
|
|
|
mTaskbarViewInApp.updateHotseatItemsVisibility();
|
2021-03-25 17:15:18 -07:00
|
|
|
setWhichTaskbarViewIsVisible(mTaskbarViewInApp);
|
2021-03-22 14:43:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
2021-03-03 17:33:28 -08:00
|
|
|
}
|
|
|
|
|
});
|
2021-03-02 12:28:25 -08:00
|
|
|
return anim.buildAnim();
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Should be called when the IME visibility changes, so we can hide/show Taskbar accordingly.
|
|
|
|
|
*/
|
|
|
|
|
public void setIsImeVisible(boolean isImeVisible) {
|
2021-03-22 17:32:50 -07:00
|
|
|
mTaskbarAnimationController.animateToVisibilityForIme(isImeVisible ? 0 : 1);
|
2021-04-16 12:50:22 -07:00
|
|
|
blockTaskbarTouchesForIme(isImeVisible);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* When in 3 button nav, the above doesn't get called since we prevent sysui nav bar from
|
|
|
|
|
* instantiating at all, which is what's responsible for sending sysui state flags over.
|
|
|
|
|
*
|
|
|
|
|
* @param vis IME visibility flag
|
|
|
|
|
* @param backDisposition Used to determine back button behavior for software keyboard
|
|
|
|
|
* See BACK_DISPOSITION_* constants in {@link InputMethodService}
|
|
|
|
|
*/
|
|
|
|
|
public void updateImeStatus(int displayId, int vis, int backDisposition,
|
|
|
|
|
boolean showImeSwitcher) {
|
|
|
|
|
if (displayId != mTaskbarContainerView.getContext().getDisplayId() ||
|
|
|
|
|
mNavMode != SysUINavigationMode.Mode.THREE_BUTTONS) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean imeVisible = (vis & InputMethodService.IME_VISIBLE) != 0;
|
|
|
|
|
mTaskbarAnimationController.animateToVisibilityForIme(imeVisible ? 0 : 1);
|
|
|
|
|
mImeBarView.setImeSwitcherVisibility(showImeSwitcher);
|
|
|
|
|
blockTaskbarTouchesForIme(imeVisible);
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
|
|
|
|
|
2021-01-11 14:54:23 -06:00
|
|
|
/**
|
|
|
|
|
* Should be called when one or more items in the Hotseat have changed.
|
|
|
|
|
*/
|
|
|
|
|
public void onHotseatUpdated() {
|
|
|
|
|
mHotseatController.onHotseatUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-22 18:45:04 -08:00
|
|
|
/**
|
|
|
|
|
* @param ev MotionEvent in screen coordinates.
|
|
|
|
|
* @return Whether any Taskbar item could handle the given MotionEvent if given the chance.
|
|
|
|
|
*/
|
|
|
|
|
public boolean isEventOverAnyTaskbarItem(MotionEvent ev) {
|
2021-03-22 14:43:58 -07:00
|
|
|
return mTaskbarViewInApp.isEventOverAnyItem(ev);
|
2021-01-22 18:45:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isDraggingItem() {
|
2021-03-22 14:43:58 -07:00
|
|
|
return mTaskbarViewInApp.isDraggingItem() || mTaskbarViewOnHome.isDraggingItem();
|
2021-01-22 18:45:04 -08:00
|
|
|
}
|
|
|
|
|
|
2021-01-11 14:54:23 -06:00
|
|
|
/**
|
|
|
|
|
* @return Whether the given View is in the same window as Taskbar.
|
|
|
|
|
*/
|
|
|
|
|
public boolean isViewInTaskbar(View v) {
|
2021-02-17 15:20:31 -08:00
|
|
|
return mTaskbarContainerView.isAttachedToWindow()
|
|
|
|
|
&& mTaskbarContainerView.getWindowId().equals(v.getWindowId());
|
2021-01-11 14:54:23 -06:00
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:28:25 -08:00
|
|
|
/**
|
|
|
|
|
* Pads the Hotseat to line up exactly with Taskbar's copy of the Hotseat.
|
|
|
|
|
*/
|
|
|
|
|
public void alignRealHotseatWithTaskbar() {
|
|
|
|
|
Rect hotseatBounds = new Rect();
|
2021-03-09 17:27:53 -08:00
|
|
|
DeviceProfile grid = mLauncher.getDeviceProfile();
|
2021-03-18 13:57:20 -07:00
|
|
|
int hotseatHeight = grid.workspacePadding.bottom + grid.taskbarSize;
|
2021-04-07 11:06:40 -07:00
|
|
|
int taskbarOffset = mLauncher.getHotseat().getTaskbarOffsetY();
|
|
|
|
|
int hotseatTopDiff = hotseatHeight - grid.taskbarSize - taskbarOffset;
|
|
|
|
|
int hotseatBottomDiff = taskbarOffset;
|
2021-03-09 17:27:53 -08:00
|
|
|
|
2021-03-22 14:43:58 -07:00
|
|
|
mTaskbarViewOnHome.getHotseatBounds().roundOut(hotseatBounds);
|
|
|
|
|
mLauncher.getHotseat().setPadding(hotseatBounds.left,
|
|
|
|
|
hotseatBounds.top + hotseatTopDiff,
|
|
|
|
|
mTaskbarViewOnHome.getWidth() - hotseatBounds.right,
|
2021-04-07 11:06:40 -07:00
|
|
|
mTaskbarViewOnHome.getHeight() - hotseatBounds.bottom + hotseatBottomDiff);
|
2021-03-02 12:28:25 -08:00
|
|
|
}
|
|
|
|
|
|
2021-03-25 17:15:18 -07:00
|
|
|
private void setWhichTaskbarViewIsVisible(@Nullable TaskbarView visibleTaskbar) {
|
|
|
|
|
mTaskbarViewInApp.setVisibility(visibleTaskbar == mTaskbarViewInApp
|
2021-04-16 12:50:22 -07:00
|
|
|
? VISIBLE : INVISIBLE);
|
2021-03-25 17:15:18 -07:00
|
|
|
mTaskbarViewOnHome.setVisibility(visibleTaskbar == mTaskbarViewOnHome
|
2021-04-16 12:50:22 -07:00
|
|
|
? VISIBLE : INVISIBLE);
|
2021-03-25 17:15:18 -07:00
|
|
|
mLauncher.getHotseat().setIconsAlpha(visibleTaskbar != mTaskbarViewInApp ? 1f : 0f);
|
2021-03-10 16:18:40 -08:00
|
|
|
}
|
|
|
|
|
|
2021-04-16 12:50:22 -07:00
|
|
|
private void blockTaskbarTouchesForIme(boolean block) {
|
|
|
|
|
mTaskbarViewOnHome.setTouchesEnabled(!block);
|
|
|
|
|
mTaskbarViewInApp.setTouchesEnabled(!block);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 14:43:58 -07:00
|
|
|
/**
|
|
|
|
|
* Returns the ratio of the taskbar icon size on home vs in an app.
|
|
|
|
|
*/
|
|
|
|
|
public float getTaskbarScaleOnHome() {
|
|
|
|
|
DeviceProfile inAppDp = mTaskbarContainerView.getTaskbarActivityContext()
|
|
|
|
|
.getDeviceProfile();
|
|
|
|
|
DeviceProfile onHomeDp = ActivityContext.lookupContext(mTaskbarViewOnHome.getContext())
|
|
|
|
|
.getDeviceProfile();
|
|
|
|
|
return (float) onHomeDp.cellWidthPx / inAppDp.cellWidthPx;
|
2021-03-02 12:28:25 -08:00
|
|
|
}
|
|
|
|
|
|
2021-02-02 17:12:08 -08:00
|
|
|
/**
|
|
|
|
|
* Updates the TaskbarContainer to MATCH_PARENT vs original Taskbar size.
|
|
|
|
|
*/
|
|
|
|
|
private void setTaskbarWindowFullscreen(boolean fullscreen) {
|
2021-04-07 11:06:40 -07:00
|
|
|
setTaskbarWindowHeight(fullscreen ? MATCH_PARENT : mTaskbarSize.y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the TaskbarContainer height (pass mTaskbarSize.y to reset).
|
|
|
|
|
*/
|
|
|
|
|
private void setTaskbarWindowHeight(int height) {
|
|
|
|
|
mWindowLayoutParams.width = mTaskbarSize.x;
|
|
|
|
|
mWindowLayoutParams.height = height;
|
2021-02-02 17:12:08 -08:00
|
|
|
mWindowManager.updateViewLayout(mTaskbarContainerView, mWindowLayoutParams);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 16:12:18 -06:00
|
|
|
/**
|
|
|
|
|
* Contains methods that TaskbarStateHandler can call to interface with TaskbarController.
|
|
|
|
|
*/
|
|
|
|
|
protected interface TaskbarStateHandlerCallbacks {
|
|
|
|
|
AnimatedFloat getAlphaTarget();
|
2021-03-22 17:32:50 -07:00
|
|
|
AnimatedFloat getScaleTarget();
|
2021-04-07 11:06:40 -07:00
|
|
|
AnimatedFloat getTranslationYTarget();
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-22 17:32:50 -07:00
|
|
|
* Contains methods that TaskbarAnimationController can call to interface with
|
2020-12-23 16:12:18 -06:00
|
|
|
* TaskbarController.
|
|
|
|
|
*/
|
2021-03-22 17:32:50 -07:00
|
|
|
protected interface TaskbarAnimationControllerCallbacks {
|
2020-12-23 16:12:18 -06:00
|
|
|
void updateTaskbarBackgroundAlpha(float alpha);
|
|
|
|
|
void updateTaskbarVisibilityAlpha(float alpha);
|
2021-04-16 12:50:22 -07:00
|
|
|
void updateImeBarVisibilityAlpha(float alpha);
|
2021-03-22 17:32:50 -07:00
|
|
|
void updateTaskbarScale(float scale);
|
2021-04-07 11:06:40 -07:00
|
|
|
void updateTaskbarTranslationY(float translationY);
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
2021-01-11 14:54:23 -06:00
|
|
|
|
2021-02-02 17:12:08 -08:00
|
|
|
/**
|
|
|
|
|
* Contains methods that TaskbarContainerView can call to interface with TaskbarController.
|
|
|
|
|
*/
|
|
|
|
|
protected interface TaskbarContainerViewCallbacks {
|
|
|
|
|
void onViewRemoved();
|
2021-04-05 16:14:39 -07:00
|
|
|
boolean isTaskbarTouchable();
|
2021-02-02 17:12:08 -08:00
|
|
|
}
|
|
|
|
|
|
2021-01-11 14:54:23 -06:00
|
|
|
/**
|
|
|
|
|
* Contains methods that TaskbarView can call to interface with TaskbarController.
|
|
|
|
|
*/
|
|
|
|
|
protected interface TaskbarViewCallbacks {
|
|
|
|
|
View.OnClickListener getItemOnClickListener();
|
2021-01-22 18:45:04 -08:00
|
|
|
View.OnLongClickListener getItemOnLongClickListener();
|
2021-03-22 14:43:58 -07:00
|
|
|
int getEmptyHotseatViewVisibility(TaskbarView taskbarView);
|
|
|
|
|
/** Returns how much to scale non-icon elements such as spacing and dividers. */
|
|
|
|
|
float getNonIconScale(TaskbarView taskbarView);
|
|
|
|
|
void onItemPositionsChanged(TaskbarView taskbarView);
|
2021-03-25 12:31:23 -07:00
|
|
|
void onNavigationButtonClick(@TaskbarButton int buttonType);
|
2021-01-11 14:54:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Contains methods that TaskbarHotseatController can call to interface with TaskbarController.
|
|
|
|
|
*/
|
|
|
|
|
protected interface TaskbarHotseatControllerCallbacks {
|
|
|
|
|
void updateHotseatItems(ItemInfo[] hotseatItemInfos);
|
|
|
|
|
}
|
2020-12-22 12:40:09 -06:00
|
|
|
}
|