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-11-08 00:48:53 -08:00
|
|
|
import static com.android.launcher3.taskbar.TaskbarLauncherStateController.FLAG_RESUMED;
|
2021-10-05 01:11:08 +02:00
|
|
|
import static com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_EXTRA_NAVIGATION_BAR;
|
2021-05-25 14:35:01 -07:00
|
|
|
|
2020-12-23 16:12:18 -06:00
|
|
|
import android.animation.Animator;
|
2021-10-05 01:11:08 +02:00
|
|
|
import android.annotation.ColorInt;
|
2021-06-08 20:03:43 -07:00
|
|
|
import android.graphics.Rect;
|
2021-10-05 01:11:08 +02:00
|
|
|
import android.os.RemoteException;
|
|
|
|
|
import android.util.Log;
|
2021-01-22 18:45:04 -08:00
|
|
|
import android.view.MotionEvent;
|
2021-10-05 01:11:08 +02:00
|
|
|
import android.view.TaskTransitionSpec;
|
2021-08-16 17:39:12 -07:00
|
|
|
import android.view.View;
|
2021-10-05 01:11:08 +02:00
|
|
|
import android.view.WindowManagerGlobal;
|
2020-12-22 12:40:09 -06:00
|
|
|
|
2021-05-25 14:35:01 -07:00
|
|
|
import androidx.annotation.NonNull;
|
2020-12-23 16:12:18 -06:00
|
|
|
|
2020-12-22 12:40:09 -06:00
|
|
|
import com.android.launcher3.BaseQuickstepLauncher;
|
2021-07-22 14:28:04 -10: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;
|
2021-10-05 01:11:08 +02:00
|
|
|
import com.android.launcher3.R;
|
2021-09-07 12:48:43 -07:00
|
|
|
import com.android.launcher3.Utilities;
|
2021-07-30 16:00:20 -10:00
|
|
|
import com.android.launcher3.config.FeatureFlags;
|
2021-08-30 14:15:56 -07:00
|
|
|
import com.android.launcher3.logging.InstanceId;
|
|
|
|
|
import com.android.launcher3.logging.InstanceIdSequence;
|
2021-08-24 10:56:31 -07:00
|
|
|
import com.android.launcher3.model.data.ItemInfoWithIcon;
|
2021-08-30 14:15:56 -07:00
|
|
|
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
2021-08-04 13:56:43 -10:00
|
|
|
import com.android.launcher3.util.OnboardingPrefs;
|
2021-05-25 14:35:01 -07:00
|
|
|
import com.android.quickstep.AnimatedFloat;
|
2021-06-15 14:49:28 -07:00
|
|
|
import com.android.quickstep.RecentsAnimationCallbacks;
|
2021-05-25 14:35:01 -07:00
|
|
|
|
2021-08-24 10:56:31 -07:00
|
|
|
import java.util.Arrays;
|
2021-10-05 01:11:08 +02:00
|
|
|
import java.util.Set;
|
2021-08-24 10:56:31 -07:00
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
2020-12-22 12:40:09 -06:00
|
|
|
/**
|
2021-05-20 20:18:47 +00:00
|
|
|
* A data source which integrates with a Launcher instance
|
2020-12-22 12:40:09 -06:00
|
|
|
*/
|
2021-05-20 20:18:47 +00:00
|
|
|
public class LauncherTaskbarUIController extends TaskbarUIController {
|
2021-04-16 12:50:22 -07:00
|
|
|
|
2021-10-05 01:11:08 +02:00
|
|
|
private static final String TAG = "TaskbarUIController";
|
|
|
|
|
|
2020-12-22 12:40:09 -06:00
|
|
|
private final BaseQuickstepLauncher mLauncher;
|
|
|
|
|
|
2021-07-22 14:28:04 -10:00
|
|
|
private final DeviceProfile.OnDeviceProfileChangeListener mOnDeviceProfileChangeListener =
|
|
|
|
|
this::onStashedInAppChanged;
|
|
|
|
|
|
2021-06-01 16:54:07 -07:00
|
|
|
// Initialized in init.
|
|
|
|
|
private TaskbarControllers mControllers;
|
2021-07-22 14:28:04 -10:00
|
|
|
private AnimatedFloat mTaskbarOverrideBackgroundAlpha;
|
2021-06-04 15:35:46 -07:00
|
|
|
private TaskbarKeyguardController mKeyguardController;
|
2021-11-08 00:48:53 -08:00
|
|
|
private final TaskbarLauncherStateController
|
|
|
|
|
mTaskbarLauncherStateController = new TaskbarLauncherStateController();
|
2021-09-30 10:14:34 -07:00
|
|
|
|
2021-10-12 21:41:13 -07:00
|
|
|
private final DeviceProfile.OnDeviceProfileChangeListener mProfileChangeListener =
|
|
|
|
|
new DeviceProfile.OnDeviceProfileChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onDeviceProfileChanged(DeviceProfile dp) {
|
|
|
|
|
mControllers.taskbarViewController.onRotationChanged(
|
|
|
|
|
mLauncher.getDeviceProfile());
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-06-15 14:49:28 -07:00
|
|
|
|
2021-10-18 16:02:21 -07:00
|
|
|
public LauncherTaskbarUIController(BaseQuickstepLauncher launcher) {
|
2020-12-22 12:40:09 -06:00
|
|
|
mLauncher = launcher;
|
2021-05-20 20:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2021-06-08 20:03:43 -07:00
|
|
|
protected void init(TaskbarControllers taskbarControllers) {
|
2021-06-01 16:54:07 -07:00
|
|
|
mControllers = taskbarControllers;
|
|
|
|
|
|
2021-11-08 00:48:53 -08:00
|
|
|
mTaskbarLauncherStateController.init(mControllers, mLauncher);
|
2021-07-22 14:28:04 -10:00
|
|
|
mTaskbarOverrideBackgroundAlpha = mControllers.taskbarDragLayerController
|
|
|
|
|
.getOverrideBackgroundAlpha();
|
2021-06-01 16:54:07 -07:00
|
|
|
|
2021-05-20 20:18:47 +00:00
|
|
|
mLauncher.setTaskbarUIController(this);
|
2021-06-04 15:35:46 -07:00
|
|
|
mKeyguardController = taskbarControllers.taskbarKeyguardController;
|
2021-06-17 15:18:15 -07:00
|
|
|
|
2021-09-28 15:09:25 -07:00
|
|
|
onLauncherResumedOrPaused(mLauncher.hasBeenResumed(), true /* fromInit */);
|
2021-07-22 14:28:04 -10:00
|
|
|
|
|
|
|
|
onStashedInAppChanged(mLauncher.getDeviceProfile());
|
|
|
|
|
mLauncher.addOnDeviceProfileChangeListener(mOnDeviceProfileChangeListener);
|
2021-10-12 21:41:13 -07:00
|
|
|
mLauncher.addOnDeviceProfileChangeListener(mProfileChangeListener);
|
2021-05-20 20:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
2021-06-18 12:41:22 -07:00
|
|
|
onLauncherResumedOrPaused(false);
|
2021-11-08 00:48:53 -08:00
|
|
|
mTaskbarLauncherStateController.onDestroy();
|
2021-06-17 15:18:15 -07:00
|
|
|
|
2021-07-22 14:28:04 -10:00
|
|
|
mLauncher.removeOnDeviceProfileChangeListener(mOnDeviceProfileChangeListener);
|
2021-05-20 20:18:47 +00:00
|
|
|
mLauncher.setTaskbarUIController(null);
|
2021-10-12 21:41:13 -07:00
|
|
|
mLauncher.removeOnDeviceProfileChangeListener(mProfileChangeListener);
|
2021-10-05 01:11:08 +02:00
|
|
|
updateTaskTransitionSpec(true);
|
2021-05-20 20:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean isTaskbarTouchable() {
|
2021-11-08 00:48:53 -08:00
|
|
|
return !mTaskbarLauncherStateController.isAnimatingToLauncher();
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
|
|
|
|
|
2021-06-08 20:03:43 -07:00
|
|
|
@Override
|
|
|
|
|
protected void updateContentInsets(Rect outContentInsets) {
|
2021-06-01 16:54:07 -07:00
|
|
|
int contentHeight = mControllers.taskbarStashController.getContentHeight();
|
2021-10-18 16:02:21 -07:00
|
|
|
TaskbarDragLayer dragLayer = mControllers.taskbarActivityContext.getDragLayer();
|
|
|
|
|
outContentInsets.top = dragLayer.getHeight() - contentHeight;
|
2021-06-08 20:03:43 -07:00
|
|
|
}
|
|
|
|
|
|
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-09-28 15:09:25 -07:00
|
|
|
onLauncherResumedOrPaused(isResumed, false /* fromInit */);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onLauncherResumedOrPaused(boolean isResumed, boolean fromInit) {
|
2021-06-04 15:35:46 -07:00
|
|
|
if (mKeyguardController.isScreenOff()) {
|
|
|
|
|
if (!isResumed) {
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
// Resuming implicitly means device unlocked
|
|
|
|
|
mKeyguardController.setScreenOn();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-08 00:48:53 -08:00
|
|
|
mTaskbarLauncherStateController.updateStateForFlag(FLAG_RESUMED, isResumed);
|
|
|
|
|
mTaskbarLauncherStateController.applyState(
|
|
|
|
|
fromInit ? 0 : QuickstepTransitionManager.CONTENT_ALPHA_DURATION);
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-15 14:49:28 -07:00
|
|
|
* Create Taskbar animation when going from an app to Launcher as part of recents transition.
|
2020-12-23 16:12:18 -06:00
|
|
|
* @param toState If known, the state we will end up in when reaching Launcher.
|
2021-06-15 14:49:28 -07:00
|
|
|
* @param callbacks callbacks to track the recents animation lifecycle. The state change is
|
|
|
|
|
* automatically reset once the recents animation finishes
|
2020-12-23 16:12:18 -06:00
|
|
|
*/
|
2021-06-15 14:49:28 -07:00
|
|
|
public Animator createAnimToLauncher(@NonNull LauncherState toState,
|
2021-08-04 22:31:08 -07:00
|
|
|
@NonNull RecentsAnimationCallbacks callbacks, long duration) {
|
2021-11-08 00:48:53 -08:00
|
|
|
return mTaskbarLauncherStateController.createAnimToLauncher(toState, callbacks, duration);
|
2020-12-23 16:12:18 -06:00
|
|
|
}
|
|
|
|
|
|
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-10-21 15:31:51 +01:00
|
|
|
return mControllers.taskbarViewController.isEventOverAnyItem(ev)
|
|
|
|
|
|| mControllers.navbarButtonsViewController.isEventOverAnyItem(ev);
|
2021-01-22 18:45:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isDraggingItem() {
|
2021-10-18 16:02:21 -07:00
|
|
|
return mControllers.taskbarDragController.isDragging();
|
2021-01-11 14:54:23 -06:00
|
|
|
}
|
|
|
|
|
|
2021-08-16 17:39:12 -07:00
|
|
|
public View getRootView() {
|
2021-10-18 16:02:21 -07:00
|
|
|
return mControllers.taskbarActivityContext.getDragLayer();
|
2021-08-16 17:39:12 -07:00
|
|
|
}
|
|
|
|
|
|
2021-07-22 14:28:04 -10:00
|
|
|
@Override
|
|
|
|
|
protected void onStashedInAppChanged() {
|
|
|
|
|
onStashedInAppChanged(mLauncher.getDeviceProfile());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onStashedInAppChanged(DeviceProfile deviceProfile) {
|
|
|
|
|
boolean taskbarStashedInApps = mControllers.taskbarStashController.isStashedInApp();
|
|
|
|
|
deviceProfile.isTaskbarPresentInApps = !taskbarStashedInApps;
|
2021-10-05 01:11:08 +02:00
|
|
|
updateTaskTransitionSpec(taskbarStashedInApps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateTaskTransitionSpec(boolean taskbarIsHidden) {
|
|
|
|
|
try {
|
|
|
|
|
if (taskbarIsHidden) {
|
|
|
|
|
// Clear custom task transition settings when the taskbar is stashed
|
|
|
|
|
WindowManagerGlobal.getWindowManagerService().clearTaskTransitionSpec();
|
|
|
|
|
} else {
|
|
|
|
|
// Adjust task transition spec to account for taskbar being visible
|
|
|
|
|
@ColorInt int taskAnimationBackgroundColor =
|
|
|
|
|
mLauncher.getColor(R.color.taskbar_background);
|
|
|
|
|
|
|
|
|
|
TaskTransitionSpec customTaskAnimationSpec = new TaskTransitionSpec(
|
|
|
|
|
taskAnimationBackgroundColor,
|
|
|
|
|
Set.of(ITYPE_EXTRA_NAVIGATION_BAR)
|
|
|
|
|
);
|
|
|
|
|
WindowManagerGlobal.getWindowManagerService()
|
|
|
|
|
.setTaskTransitionSpec(customTaskAnimationSpec);
|
|
|
|
|
}
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
|
// This shouldn't happen but if it does task animations won't look good until the
|
|
|
|
|
// taskbar stashing state is changed.
|
|
|
|
|
Log.e(TAG, "Failed to update task transition spec to account for new taskbar state",
|
|
|
|
|
e);
|
|
|
|
|
}
|
2021-07-22 14:28:04 -10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets whether the background behind the taskbar/nav bar should be hidden.
|
|
|
|
|
*/
|
|
|
|
|
public void forceHideBackground(boolean forceHide) {
|
|
|
|
|
mTaskbarOverrideBackgroundAlpha.updateValue(forceHide ? 0 : 1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-24 10:56:31 -07:00
|
|
|
@Override
|
|
|
|
|
public Stream<ItemInfoWithIcon> getAppIconsForEdu() {
|
|
|
|
|
return Arrays.stream(mLauncher.getAppsView().getAppsStore().getApps());
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-30 16:00:20 -10:00
|
|
|
/**
|
|
|
|
|
* Starts the taskbar education flow, if the user hasn't seen it yet.
|
|
|
|
|
*/
|
|
|
|
|
public void showEdu() {
|
2021-08-04 13:56:43 -10:00
|
|
|
if (!FeatureFlags.ENABLE_TASKBAR_EDU.get()
|
2021-09-07 12:48:43 -07:00
|
|
|
|| Utilities.IS_RUNNING_IN_TEST_HARNESS
|
2021-08-04 13:56:43 -10:00
|
|
|
|| mLauncher.getOnboardingPrefs().getBoolean(OnboardingPrefs.TASKBAR_EDU_SEEN)) {
|
2021-07-30 16:00:20 -10:00
|
|
|
return;
|
|
|
|
|
}
|
2021-08-04 13:56:43 -10:00
|
|
|
mLauncher.getOnboardingPrefs().markChecked(OnboardingPrefs.TASKBAR_EDU_SEEN);
|
2021-07-30 16:00:20 -10:00
|
|
|
|
|
|
|
|
mControllers.taskbarEduController.showEdu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Manually ends the taskbar education flow.
|
|
|
|
|
*/
|
|
|
|
|
public void hideEdu() {
|
|
|
|
|
if (!FeatureFlags.ENABLE_TASKBAR_EDU.get()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mControllers.taskbarEduController.hideEdu();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-30 14:15:56 -07:00
|
|
|
@Override
|
|
|
|
|
public void onTaskbarIconLaunched(WorkspaceItemInfo item) {
|
|
|
|
|
InstanceId instanceId = new InstanceIdSequence().newInstanceId();
|
2021-10-18 16:02:21 -07:00
|
|
|
mLauncher.logAppLaunch(mControllers.taskbarActivityContext.getStatsLogManager(), item,
|
|
|
|
|
instanceId);
|
2021-08-30 14:15:56 -07:00
|
|
|
}
|
2020-12-22 12:40:09 -06:00
|
|
|
}
|