64896f3098
This means adding the search view to the drag layer, so it can persist and animate across Launcher states (i.e. Home, All Apps, Overview, Overview from App). Some high level things: - LauncherState now has a flag indicating if the floating search bar should be visible, as well as a method indicating how high it should rest when the keyboard is not showing. By default the height is set negative if the flag is not present, so the search bar will rest off screen in that state. - LauncherState also has a new method indicating if the search bar should show as a pill when not focused. Currently this is done in phone portrait mode in all apps and overview. - SearchUiManager now has a method for gestures to hint that the search bar will be focused or unfocused soon, e.g. for the app -> overview case, we hint that it will be focused when crossing the threshold, and unfocused if retracting. This allows the search bar to animate during the gesture and take or release focus after the state change completes. - AllAppsTransitionController lets the apps panel translate in from the bottom of the screen, for example when coming from an app and we don't want to pop it in halfway up the screen. Instead it can slide in gracefully from behind the keyboard and floating search bar. - KeyboardInsetAnimationCallback can now notify listeners of keyboard alpha changes during controlled animations. And StateAnimationConfig has a new animation type to control the keyboard alpha during the all apps transition. - This new ANIM_ALL_APPS_KEYBOARD_FADE is used to pop the keyboard in at the threshold for going from an app to all apps. Note that its position moves linearly before this, so the search bar starts moving up accordingly before the keyboard alpha is non-0. Fix: 266761289 Fix: 268845147 Fix: 267683921 Fix: 265849321 Fix: 266446733 Fix: 269301440 Bug: 275635606 Bug: 259619990 Bug: 261866704 Test: Manual with all the state transitions on phone and tablet (also folding/unfolding foldable). Flag: ENABLE_FLOATING_SEARCH_BAR, ENABLE_ALL_APPS_FROM_OVERVIEW (latter just for the background app interpolator changes). Change-Id: I6f06552e95747348a62260279626cf407bf145b0
203 lines
7.9 KiB
Java
203 lines
7.9 KiB
Java
/*
|
|
* Copyright (C) 2022 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.allapps;
|
|
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.VisibleForTesting;
|
|
|
|
import com.android.launcher3.R;
|
|
import com.android.launcher3.appprediction.PredictionRowView;
|
|
import com.android.launcher3.model.data.AppInfo;
|
|
import com.android.launcher3.model.data.ItemInfo;
|
|
import com.android.launcher3.taskbar.TaskbarControllers;
|
|
import com.android.launcher3.taskbar.overlay.TaskbarOverlayContext;
|
|
import com.android.launcher3.util.PackageUserKey;
|
|
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.function.Predicate;
|
|
|
|
/**
|
|
* Handles the all apps overlay window initialization, updates, and its data.
|
|
* <p>
|
|
* All apps is in an application overlay window instead of taskbar's navigation bar panel window,
|
|
* because a navigation bar panel is higher than UI components that all apps should be below such as
|
|
* the notification tray.
|
|
* <p>
|
|
* The all apps window is created and destroyed upon opening and closing all apps, respectively.
|
|
* Application data may be bound while the window does not exist, so this controller will store
|
|
* the models for the next all apps session.
|
|
*/
|
|
public final class TaskbarAllAppsController {
|
|
|
|
private TaskbarControllers mControllers;
|
|
private @Nullable TaskbarOverlayContext mOverlayContext;
|
|
private @Nullable TaskbarAllAppsSlideInView mSlideInView;
|
|
private @Nullable TaskbarAllAppsContainerView mAppsView;
|
|
private @Nullable TaskbarSearchSessionController mSearchSessionController;
|
|
|
|
// Application data models.
|
|
private AppInfo[] mApps;
|
|
private int mAppsModelFlags;
|
|
private List<ItemInfo> mPredictedApps;
|
|
private boolean mDisallowGlobalDrag;
|
|
private boolean mDisallowLongClick;
|
|
|
|
private Map<PackageUserKey, Integer> mPackageUserKeytoUidMap = Collections.emptyMap();
|
|
|
|
/** Initialize the controller. */
|
|
public void init(TaskbarControllers controllers, boolean allAppsVisible) {
|
|
mControllers = controllers;
|
|
|
|
/*
|
|
* Recreate All Apps if it was open in the previous Taskbar instance (e.g. the configuration
|
|
* changed).
|
|
*/
|
|
if (allAppsVisible) {
|
|
show(false);
|
|
}
|
|
}
|
|
|
|
/** Clean up the controller. */
|
|
public void onDestroy() {
|
|
cleanUpOverlay();
|
|
}
|
|
|
|
/** Updates the current {@link AppInfo} instances. */
|
|
public void setApps(AppInfo[] apps, int flags, Map<PackageUserKey, Integer> map) {
|
|
mApps = apps;
|
|
mAppsModelFlags = flags;
|
|
mPackageUserKeytoUidMap = map;
|
|
if (mAppsView != null) {
|
|
mAppsView.getAppsStore().setApps(mApps, mAppsModelFlags, mPackageUserKeytoUidMap);
|
|
}
|
|
}
|
|
|
|
public void setDisallowGlobalDrag(boolean disableDragForOverviewState) {
|
|
mDisallowGlobalDrag = disableDragForOverviewState;
|
|
}
|
|
|
|
public void setDisallowLongClick(boolean disallowLongClick) {
|
|
mDisallowLongClick = disallowLongClick;
|
|
}
|
|
|
|
/** Updates the current predictions. */
|
|
public void setPredictedApps(List<ItemInfo> predictedApps) {
|
|
mPredictedApps = predictedApps;
|
|
if (mAppsView != null) {
|
|
mAppsView.getFloatingHeaderView()
|
|
.findFixedRowByType(PredictionRowView.class)
|
|
.setPredictedApps(mPredictedApps);
|
|
}
|
|
if (mSearchSessionController != null) {
|
|
mSearchSessionController.setZeroStatePredictedItems(predictedApps);
|
|
}
|
|
}
|
|
|
|
/** Updates the current notification dots. */
|
|
public void updateNotificationDots(Predicate<PackageUserKey> updatedDots) {
|
|
if (mAppsView != null) {
|
|
mAppsView.getAppsStore().updateNotificationDots(updatedDots);
|
|
}
|
|
}
|
|
|
|
/** Toggles visibility of {@link TaskbarAllAppsContainerView} in the overlay window. */
|
|
public void toggle() {
|
|
if (isOpen()) {
|
|
mSlideInView.close(true);
|
|
} else {
|
|
show(true);
|
|
}
|
|
}
|
|
|
|
/** Returns {@code true} if All Apps is open. */
|
|
public boolean isOpen() {
|
|
return mSlideInView != null && mSlideInView.isOpen();
|
|
}
|
|
|
|
private void show(boolean animate) {
|
|
if (mAppsView != null) {
|
|
return;
|
|
}
|
|
// mControllers and getSharedState should never be null here. Do not handle null-pointer
|
|
// to catch invalid states.
|
|
mControllers.getSharedState().allAppsVisible = true;
|
|
|
|
mOverlayContext = mControllers.taskbarOverlayController.requestWindow();
|
|
|
|
// Initialize search session for All Apps.
|
|
mSearchSessionController = TaskbarSearchSessionController.newInstance(mOverlayContext);
|
|
mOverlayContext.setSearchSessionController(mSearchSessionController);
|
|
mSearchSessionController.setZeroStatePredictedItems(mPredictedApps);
|
|
mSearchSessionController.startLifecycle();
|
|
|
|
mSlideInView = (TaskbarAllAppsSlideInView) mOverlayContext.getLayoutInflater().inflate(
|
|
R.layout.taskbar_all_apps_sheet, mOverlayContext.getDragLayer(), false);
|
|
mSlideInView.addOnCloseListener(() -> {
|
|
mControllers.getSharedState().allAppsVisible = false;
|
|
cleanUpOverlay();
|
|
});
|
|
TaskbarAllAppsViewController viewController = new TaskbarAllAppsViewController(
|
|
mOverlayContext, mSlideInView, mControllers);
|
|
|
|
viewController.show(animate);
|
|
mAppsView = mOverlayContext.getAppsView();
|
|
mAppsView.getAppsStore().setApps(mApps, mAppsModelFlags, mPackageUserKeytoUidMap);
|
|
mAppsView.getFloatingHeaderView()
|
|
.findFixedRowByType(PredictionRowView.class)
|
|
.setPredictedApps(mPredictedApps);
|
|
// 1 alternative that would be more work:
|
|
// Create a shared drag layer between taskbar and taskbarAllApps so that when dragging
|
|
// starts and taskbarAllApps can close, but the drag layer that the view is being dragged in
|
|
// doesn't also close
|
|
mOverlayContext.getDragController().setDisallowGlobalDrag(mDisallowGlobalDrag);
|
|
mOverlayContext.getDragController().setDisallowLongClick(mDisallowLongClick);
|
|
}
|
|
|
|
private void cleanUpOverlay() {
|
|
// Floating search bar is added to the drag layer in ActivityAllAppsContainerView onAttach;
|
|
// removed here as this is a special case that we remove the all apps panel.
|
|
if (mAppsView != null && mOverlayContext != null
|
|
&& mAppsView.getSearchUiDelegate().isSearchBarFloating()) {
|
|
mOverlayContext.getDragLayer().removeView(mAppsView.getSearchView());
|
|
mAppsView.getSearchUiDelegate().onDestroySearchBar();
|
|
}
|
|
if (mSearchSessionController != null) {
|
|
mSearchSessionController.onDestroy();
|
|
mSearchSessionController = null;
|
|
}
|
|
if (mOverlayContext != null) {
|
|
mOverlayContext.setSearchSessionController(null);
|
|
mOverlayContext = null;
|
|
}
|
|
mSlideInView = null;
|
|
mAppsView = null;
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public int getTaskbarAllAppsTopPadding() {
|
|
// Allow null-pointer since this should only be null if the apps view is not showing.
|
|
return mAppsView.getActiveRecyclerView().getClipBounds().top;
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public int getTaskbarAllAppsScroll() {
|
|
// Allow null-pointer since this should only be null if the apps view is not showing.
|
|
return mAppsView.getActiveRecyclerView().computeVerticalScrollOffset();
|
|
}
|
|
}
|