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;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2021-03-10 16:18:40 -08:00
|
|
|
import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
|
|
|
|
|
import static com.android.launcher3.AbstractFloatingView.TYPE_REPLACE_TASKBAR_WITH_HOTSEAT;
|
2021-03-02 12:28:25 -08:00
|
|
|
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
|
|
|
|
|
import static com.android.launcher3.anim.Interpolators.LINEAR;
|
2020-12-22 12:40:09 -06:00
|
|
|
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;
|
|
|
|
|
import android.content.ComponentName;
|
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;
|
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-10 16:18:40 -08:00
|
|
|
import com.android.launcher3.Hotseat;
|
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;
|
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-01-11 14:54:23 -06:00
|
|
|
import com.android.launcher3.touch.ItemClickHandler;
|
2020-12-23 16:12:18 -06:00
|
|
|
import com.android.quickstep.AnimatedFloat;
|
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;
|
|
|
|
|
|
2021-01-27 16:27:15 -08:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2020-12-22 12:40:09 -06:00
|
|
|
/**
|
|
|
|
|
* Interfaces with Launcher/WindowManager/SystemUI to determine what to show in TaskbarView.
|
|
|
|
|
*/
|
|
|
|
|
public class TaskbarController {
|
|
|
|
|
|
|
|
|
|
private static final String WINDOW_TITLE = "Taskbar";
|
|
|
|
|
|
|
|
|
|
private final TaskbarContainerView mTaskbarContainerView;
|
|
|
|
|
private final TaskbarView mTaskbarView;
|
|
|
|
|
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;
|
|
|
|
|
private final TaskbarVisibilityController mTaskbarVisibilityController;
|
2021-01-11 14:54:23 -06:00
|
|
|
private final TaskbarHotseatController mHotseatController;
|
2021-01-27 16:27:15 -08:00
|
|
|
private final TaskbarRecentsController mRecentsController;
|
2021-01-22 18:45:04 -08:00
|
|
|
private final TaskbarDragController mDragController;
|
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-01-27 16:27:15 -08:00
|
|
|
// Contains all loaded Tasks, not yet deduped from Hotseat items.
|
|
|
|
|
private List<Task> mLatestLoadedRecentTasks;
|
|
|
|
|
// Contains all loaded Hotseat items.
|
|
|
|
|
private ItemInfo[] mLatestLoadedHotseatItems;
|
|
|
|
|
|
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,
|
|
|
|
|
TaskbarContainerView taskbarContainerView) {
|
|
|
|
|
mLauncher = launcher;
|
|
|
|
|
mTaskbarContainerView = taskbarContainerView;
|
2021-02-02 17:12:08 -08:00
|
|
|
mTaskbarContainerView.construct(createTaskbarContainerViewCallbacks());
|
2020-12-22 12:40:09 -06:00
|
|
|
mTaskbarView = mTaskbarContainerView.findViewById(R.id.taskbar_view);
|
2021-02-02 17:12:08 -08:00
|
|
|
mTaskbarView.construct(createTaskbarViewCallbacks());
|
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();
|
|
|
|
|
mTaskbarVisibilityController = new TaskbarVisibilityController(mLauncher,
|
|
|
|
|
createTaskbarVisibilityControllerCallbacks());
|
2021-01-11 14:54:23 -06:00
|
|
|
mHotseatController = new TaskbarHotseatController(mLauncher,
|
|
|
|
|
createTaskbarHotseatControllerCallbacks());
|
2021-01-27 16:27:15 -08:00
|
|
|
mRecentsController = new TaskbarRecentsController(mLauncher,
|
|
|
|
|
createTaskbarRecentsControllerCallbacks());
|
2021-01-22 18:45:04 -08:00
|
|
|
mDragController = new TaskbarDragController(mLauncher);
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TaskbarVisibilityControllerCallbacks createTaskbarVisibilityControllerCallbacks() {
|
|
|
|
|
return new TaskbarVisibilityControllerCallbacks() {
|
|
|
|
|
@Override
|
|
|
|
|
public void updateTaskbarBackgroundAlpha(float alpha) {
|
|
|
|
|
mTaskbarView.setBackgroundAlpha(alpha);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateTaskbarVisibilityAlpha(float alpha) {
|
|
|
|
|
mTaskbarContainerView.setAlpha(alpha);
|
|
|
|
|
}
|
|
|
|
|
};
|
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() {
|
|
|
|
|
if (mTaskbarContainerView.getChildCount() == 1) {
|
|
|
|
|
// Only TaskbarView remains.
|
|
|
|
|
setTaskbarWindowFullscreen(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
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-10 16:18:40 -08:00
|
|
|
if (mLauncher.hasBeenResumed()) {
|
|
|
|
|
FolderInfo folderInfo = (FolderInfo) tag;
|
|
|
|
|
onClickedOnFolderFromHome(folderInfo);
|
|
|
|
|
} else {
|
|
|
|
|
FolderIcon folderIcon = (FolderIcon) view;
|
|
|
|
|
onClickedOnFolderInApp(folderIcon);
|
|
|
|
|
}
|
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
|
|
|
|
2021-03-10 16:18:40 -08:00
|
|
|
// Open the real folder in Launcher.
|
|
|
|
|
private void onClickedOnFolderFromHome(FolderInfo folderInfo) {
|
|
|
|
|
alignRealHotseatWithTaskbar();
|
|
|
|
|
|
|
|
|
|
FolderIcon folderIcon = (FolderIcon) mLauncher.getHotseat()
|
|
|
|
|
.getFirstItemMatch((info, v) -> info == folderInfo);
|
|
|
|
|
folderIcon.post(folderIcon::performClick);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Open the Taskbar folder, and handle clicks on folder items.
|
|
|
|
|
private void onClickedOnFolderInApp(FolderIcon folderIcon) {
|
|
|
|
|
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-22 18:45:04 -08:00
|
|
|
@Override
|
|
|
|
|
public View.OnLongClickListener getItemOnLongClickListener() {
|
2021-02-26 09:15:31 -08:00
|
|
|
return view -> {
|
|
|
|
|
if (mLauncher.hasBeenResumed() && view.getTag() instanceof ItemInfo) {
|
|
|
|
|
alignRealHotseatWithTaskbar();
|
|
|
|
|
return mDragController.startWorkspaceDragOnLongClick(view);
|
|
|
|
|
} else {
|
|
|
|
|
return mDragController.startSystemDragOnLongClick(view);
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-01-22 18:45:04 -08:00
|
|
|
}
|
2021-03-03 17:33:28 -08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getEmptyHotseatViewVisibility() {
|
|
|
|
|
// 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.
|
|
|
|
|
return mLauncher.hasBeenResumed() || mIsAnimatingToLauncher
|
|
|
|
|
? View.INVISIBLE : View.GONE;
|
|
|
|
|
}
|
2021-01-11 14:54:23 -06:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TaskbarHotseatControllerCallbacks createTaskbarHotseatControllerCallbacks() {
|
|
|
|
|
return new TaskbarHotseatControllerCallbacks() {
|
|
|
|
|
@Override
|
|
|
|
|
public void updateHotseatItems(ItemInfo[] hotseatItemInfos) {
|
|
|
|
|
mTaskbarView.updateHotseatItems(hotseatItemInfos);
|
2021-01-27 16:27:15 -08:00
|
|
|
mLatestLoadedHotseatItems = hotseatItemInfos;
|
|
|
|
|
dedupeAndUpdateRecentItems();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TaskbarRecentsControllerCallbacks createTaskbarRecentsControllerCallbacks() {
|
|
|
|
|
return new TaskbarRecentsControllerCallbacks() {
|
|
|
|
|
@Override
|
|
|
|
|
public void updateRecentItems(ArrayList<Task> recentTasks) {
|
|
|
|
|
mLatestLoadedRecentTasks = recentTasks;
|
|
|
|
|
dedupeAndUpdateRecentItems();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateRecentTaskAtIndex(int taskIndex, Task task) {
|
|
|
|
|
mTaskbarView.updateRecentTaskAtIndex(taskIndex, task);
|
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-01-27 16:27:15 -08:00
|
|
|
mTaskbarView.init(mHotseatController.getNumHotseatIcons(),
|
|
|
|
|
mRecentsController.getNumRecentIcons());
|
2021-02-02 11:04:25 -08:00
|
|
|
mTaskbarContainerView.init(mTaskbarView);
|
2020-12-22 12:40:09 -06:00
|
|
|
addToWindowManager();
|
2020-12-23 16:12:18 -06:00
|
|
|
mTaskbarStateHandler.setTaskbarCallbacks(createTaskbarStateHandlerCallbacks());
|
|
|
|
|
mTaskbarVisibilityController.init();
|
2021-01-11 14:54:23 -06:00
|
|
|
mHotseatController.init();
|
2021-01-27 16:27:15 -08:00
|
|
|
mRecentsController.init();
|
2021-03-02 12:28:25 -08:00
|
|
|
|
|
|
|
|
SCALE_PROPERTY.set(mTaskbarView, mLauncher.hasBeenResumed() ? getTaskbarScaleOnHome() : 1f);
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TaskbarStateHandlerCallbacks createTaskbarStateHandlerCallbacks() {
|
|
|
|
|
return new TaskbarStateHandlerCallbacks() {
|
|
|
|
|
@Override
|
|
|
|
|
public AnimatedFloat getAlphaTarget() {
|
|
|
|
|
return mTaskbarVisibilityController.getTaskbarVisibilityForLauncherState();
|
|
|
|
|
}
|
|
|
|
|
};
|
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-01-11 14:54:23 -06:00
|
|
|
mTaskbarView.cleanup();
|
2021-02-02 11:04:25 -08:00
|
|
|
mTaskbarContainerView.cleanup();
|
2020-12-22 12:40:09 -06:00
|
|
|
removeFromWindowManager();
|
2020-12-23 16:12:18 -06:00
|
|
|
mTaskbarStateHandler.setTaskbarCallbacks(null);
|
|
|
|
|
mTaskbarVisibilityController.cleanup();
|
2021-01-11 14:54:23 -06:00
|
|
|
mHotseatController.cleanup();
|
2021-01-27 16:27:15 -08:00
|
|
|
mRecentsController.cleanup();
|
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;
|
|
|
|
|
mTaskbarView.setLayoutParams(taskbarLayoutParams);
|
|
|
|
|
|
|
|
|
|
mWindowManager.addView(mTaskbarContainerView, mWindowLayoutParams);
|
|
|
|
|
}
|
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);
|
2021-03-10 16:18:40 -08:00
|
|
|
replaceTaskbarWithHotseatOrViceVersa();
|
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);
|
|
|
|
|
anim.add(mTaskbarVisibilityController.createAnimToBackgroundAlpha(0, duration));
|
|
|
|
|
if (toState != null) {
|
|
|
|
|
mTaskbarStateHandler.setStateWithAnimation(toState, new StateAnimationConfig(), anim);
|
|
|
|
|
}
|
2021-03-02 12:28:25 -08:00
|
|
|
anim.addFloat(mTaskbarView, SCALE_PROPERTY, mTaskbarView.getScaleX(),
|
|
|
|
|
getTaskbarScaleOnHome(), LINEAR);
|
2021-03-03 17:33:28 -08:00
|
|
|
|
|
|
|
|
anim.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
|
mIsAnimatingToLauncher = true;
|
|
|
|
|
mTaskbarView.updateHotseatItemsVisibility();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
mIsAnimatingToLauncher = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
anim.addOnFrameCallback(this::alignRealHotseatWithTaskbar);
|
|
|
|
|
|
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);
|
|
|
|
|
anim.add(mTaskbarVisibilityController.createAnimToBackgroundAlpha(1, duration));
|
|
|
|
|
anim.addFloat(mTaskbarView, SCALE_PROPERTY, mTaskbarView.getScaleX(), 1f, LINEAR);
|
2021-03-03 17:33:28 -08:00
|
|
|
anim.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
|
mTaskbarView.updateHotseatItemsVisibility();
|
2021-03-10 16:18:40 -08:00
|
|
|
setReplaceTaskbarWithHotseat(false);
|
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) {
|
|
|
|
|
mTaskbarVisibilityController.animateToVisibilityForIme(isImeVisible ? 0 : 1);
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
|
|
return mTaskbarView.isEventOverAnyItem(ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isDraggingItem() {
|
|
|
|
|
return mTaskbarView.isDraggingItem();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:27:15 -08:00
|
|
|
private void dedupeAndUpdateRecentItems() {
|
|
|
|
|
if (mLatestLoadedRecentTasks == null || mLatestLoadedHotseatItems == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final int numRecentIcons = mRecentsController.getNumRecentIcons();
|
|
|
|
|
|
|
|
|
|
// From most recent to least recently opened.
|
|
|
|
|
List<Task> dedupedTasksInDescendingOrder = new ArrayList<>();
|
|
|
|
|
for (int i = mLatestLoadedRecentTasks.size() - 1; i >= 0; i--) {
|
|
|
|
|
Task task = mLatestLoadedRecentTasks.get(i);
|
|
|
|
|
boolean isTaskInHotseat = false;
|
|
|
|
|
for (ItemInfo hotseatItem : mLatestLoadedHotseatItems) {
|
|
|
|
|
if (hotseatItem == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
ComponentName hotseatActivity = hotseatItem.getTargetComponent();
|
|
|
|
|
if (hotseatActivity != null && task.key.sourceComponent.getPackageName()
|
|
|
|
|
.equals(hotseatActivity.getPackageName())) {
|
|
|
|
|
isTaskInHotseat = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isTaskInHotseat) {
|
|
|
|
|
dedupedTasksInDescendingOrder.add(task);
|
|
|
|
|
if (dedupedTasksInDescendingOrder.size() == numRecentIcons) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TaskbarView expects an array of all the recent tasks to show, in the order to show them.
|
|
|
|
|
// So we create an array of the proper size, then fill it in such that the most recent items
|
|
|
|
|
// are at the end. If there aren't enough elements to fill the array, leave them null.
|
|
|
|
|
Task[] tasksArray = new Task[numRecentIcons];
|
|
|
|
|
for (int i = 0; i < tasksArray.length; i++) {
|
|
|
|
|
Task task = i >= dedupedTasksInDescendingOrder.size()
|
|
|
|
|
? null
|
|
|
|
|
: dedupedTasksInDescendingOrder.get(i);
|
|
|
|
|
tasksArray[tasksArray.length - 1 - i] = task;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mTaskbarView.updateRecentTasks(tasksArray);
|
|
|
|
|
mRecentsController.loadIconsForTasks(tasksArray);
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
mTaskbarView.getHotseatBoundsAtScale(getTaskbarScaleOnHome()).roundOut(hotseatBounds);
|
|
|
|
|
mLauncher.getHotseat().setPadding(hotseatBounds.left, hotseatBounds.top,
|
|
|
|
|
mTaskbarView.getWidth() - hotseatBounds.right,
|
|
|
|
|
mTaskbarView.getHeight() - hotseatBounds.bottom);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 16:18:40 -08:00
|
|
|
/**
|
|
|
|
|
* A view was added or removed from DragLayer, check if we need to hide our hotseat copy and
|
|
|
|
|
* show the real one instead.
|
|
|
|
|
*/
|
|
|
|
|
public void onLauncherDragLayerHierarchyChanged() {
|
|
|
|
|
replaceTaskbarWithHotseatOrViceVersa();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void replaceTaskbarWithHotseatOrViceVersa() {
|
|
|
|
|
boolean replaceTaskbarWithHotseat = AbstractFloatingView.getTopOpenViewWithType(mLauncher,
|
|
|
|
|
TYPE_ALL & TYPE_REPLACE_TASKBAR_WITH_HOTSEAT) != null;
|
|
|
|
|
if (!mLauncher.hasBeenResumed()) {
|
|
|
|
|
replaceTaskbarWithHotseat = false;
|
|
|
|
|
}
|
|
|
|
|
setReplaceTaskbarWithHotseat(replaceTaskbarWithHotseat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setReplaceTaskbarWithHotseat(boolean replaceTaskbarWithHotseat) {
|
|
|
|
|
Hotseat hotseat = mLauncher.getHotseat();
|
|
|
|
|
if (replaceTaskbarWithHotseat) {
|
|
|
|
|
alignRealHotseatWithTaskbar();
|
|
|
|
|
hotseat.getReplaceTaskbarAlpha().setValue(1f);
|
|
|
|
|
mTaskbarView.setHotseatViewsHidden(true);
|
|
|
|
|
} else {
|
|
|
|
|
hotseat.getReplaceTaskbarAlpha().setValue(0f);
|
|
|
|
|
mTaskbarView.setHotseatViewsHidden(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 12:28:25 -08:00
|
|
|
private float getTaskbarScaleOnHome() {
|
|
|
|
|
return 1f / mTaskbarContainerView.getTaskbarActivityContext().getTaskbarIconScale();
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-02 17:12:08 -08:00
|
|
|
/**
|
|
|
|
|
* Updates the TaskbarContainer to MATCH_PARENT vs original Taskbar size.
|
|
|
|
|
*/
|
|
|
|
|
private void setTaskbarWindowFullscreen(boolean fullscreen) {
|
|
|
|
|
if (fullscreen) {
|
|
|
|
|
mWindowLayoutParams.width = MATCH_PARENT;
|
|
|
|
|
mWindowLayoutParams.height = MATCH_PARENT;
|
|
|
|
|
} else {
|
|
|
|
|
mWindowLayoutParams.width = mTaskbarSize.x;
|
|
|
|
|
mWindowLayoutParams.height = mTaskbarSize.y;
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Contains methods that TaskbarVisibilityController can call to interface with
|
|
|
|
|
* TaskbarController.
|
|
|
|
|
*/
|
|
|
|
|
protected interface TaskbarVisibilityControllerCallbacks {
|
|
|
|
|
void updateTaskbarBackgroundAlpha(float alpha);
|
|
|
|
|
void updateTaskbarVisibilityAlpha(float alpha);
|
|
|
|
|
}
|
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-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-03 17:33:28 -08:00
|
|
|
int getEmptyHotseatViewVisibility();
|
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);
|
|
|
|
|
}
|
2021-01-27 16:27:15 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Contains methods that TaskbarRecentsController can call to interface with TaskbarController.
|
|
|
|
|
*/
|
|
|
|
|
protected interface TaskbarRecentsControllerCallbacks {
|
|
|
|
|
void updateRecentItems(ArrayList<Task> recentTasks);
|
|
|
|
|
void updateRecentTaskAtIndex(int taskIndex, Task task);
|
|
|
|
|
}
|
2020-12-22 12:40:09 -06:00
|
|
|
}
|