Snap for 13355977 from 40d72a51c3 to 25Q3-release
Change-Id: I0709754b0deaa3822e648455a17036faf4d8cf27
This commit is contained in:
commit
b7eb1bbfaf
57 files changed
+1887
-463
No files matched your search
@@ -673,3 +673,10 @@ flag {
|
||||
purpose: PURPOSE_BUGFIX
|
||||
}
|
||||
}
|
||||
|
||||
flag {
|
||||
name: "model_repository"
|
||||
namespace: "launcher"
|
||||
description: "Adds various data repositories for the model"
|
||||
bug: "390572144"
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import android.hardware.display.DisplayManager
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
import android.view.Display.DEFAULT_DISPLAY
|
||||
import com.android.app.displaylib.DefaultDisplayOnlyInstanceRepositoryImpl
|
||||
import com.android.app.displaylib.DisplayLibBackground
|
||||
import com.android.app.displaylib.DisplayLibComponent
|
||||
import com.android.app.displaylib.DisplayRepository
|
||||
@@ -30,9 +31,12 @@ import com.android.app.displaylib.SingleInstanceRepositoryImpl
|
||||
import com.android.app.displaylib.createDisplayLibComponent
|
||||
import com.android.launcher3.Flags.enableOverviewOnConnectedDisplays
|
||||
import com.android.launcher3.util.coroutines.DispatcherProvider
|
||||
import com.android.quickstep.FallbackWindowInterface
|
||||
import com.android.quickstep.RecentsAnimationDeviceState
|
||||
import com.android.quickstep.RotationTouchHelper
|
||||
import com.android.quickstep.TaskAnimationManager
|
||||
import com.android.quickstep.fallback.window.RecentsWindowManager
|
||||
import com.android.quickstep.fallback.window.RecentsWindowManagerInstanceProvider
|
||||
import com.android.systemui.dagger.qualifiers.Background
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
@@ -55,8 +59,8 @@ object PerDisplayRepositoriesModule {
|
||||
@LauncherAppSingleton
|
||||
fun provideRecentsAnimationDeviceStateRepo(
|
||||
repositoryFactory: PerDisplayInstanceRepositoryImpl.Factory<RecentsAnimationDeviceState>,
|
||||
rotationTouchHelperRepository: PerDisplayRepository<RotationTouchHelper>,
|
||||
instanceFactory: RecentsAnimationDeviceState.Factory,
|
||||
rotationTouchHelperRepository: PerDisplayRepository<RotationTouchHelper>,
|
||||
): PerDisplayRepository<RecentsAnimationDeviceState> {
|
||||
return if (enableOverviewOnConnectedDisplays()) {
|
||||
repositoryFactory.create(
|
||||
@@ -97,8 +101,8 @@ object PerDisplayRepositoriesModule {
|
||||
@LauncherAppSingleton
|
||||
fun provideRotationTouchHandlerRepo(
|
||||
repositoryFactory: PerDisplayInstanceRepositoryImpl.Factory<RotationTouchHelper>,
|
||||
@DisplayContext displayContextRepository: PerDisplayRepository<Context>,
|
||||
instanceFactory: RotationTouchHelper.Factory,
|
||||
@DisplayContext displayContextRepository: PerDisplayRepository<Context>,
|
||||
): PerDisplayRepository<RotationTouchHelper> {
|
||||
return if (enableOverviewOnConnectedDisplays()) {
|
||||
repositoryFactory.create(
|
||||
@@ -115,13 +119,48 @@ object PerDisplayRepositoriesModule {
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@LauncherAppSingleton
|
||||
fun provideFallbackWindowInterfaceRepo(
|
||||
repositoryFactory: PerDisplayInstanceRepositoryImpl.Factory<FallbackWindowInterface>,
|
||||
instanceFactory: FallbackWindowInterface.Factory,
|
||||
recentsWindowManagerRepository: PerDisplayRepository<RecentsWindowManager>,
|
||||
): PerDisplayRepository<FallbackWindowInterface> {
|
||||
return if (enableOverviewOnConnectedDisplays()) {
|
||||
repositoryFactory.create(
|
||||
"FallbackWindowInterfaceRepo",
|
||||
{ displayId ->
|
||||
recentsWindowManagerRepository[displayId]?.let { instanceFactory.create(it) }
|
||||
},
|
||||
)
|
||||
} else {
|
||||
SingleInstanceRepositoryImpl(
|
||||
"FallbackWindowInterfaceRepo",
|
||||
instanceFactory.create(recentsWindowManagerRepository[DEFAULT_DISPLAY]),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@LauncherAppSingleton
|
||||
fun provideRecentsWindowManagerRepo(
|
||||
repositoryFactory: PerDisplayInstanceRepositoryImpl.Factory<RecentsWindowManager>,
|
||||
instanceProvider: RecentsWindowManagerInstanceProvider,
|
||||
): PerDisplayRepository<RecentsWindowManager> {
|
||||
return if (enableOverviewOnConnectedDisplays()) {
|
||||
repositoryFactory.create("RecentsWindowManagerRepo", instanceProvider)
|
||||
} else {
|
||||
DefaultDisplayOnlyInstanceRepositoryImpl("RecentsWindowManagerRepo", instanceProvider)
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@LauncherAppSingleton
|
||||
@DisplayContext
|
||||
fun provideDisplayContext(
|
||||
repositoryFactory: PerDisplayInstanceRepositoryImpl.Factory<Context>,
|
||||
@ApplicationContext context: Context,
|
||||
displayRepository: DisplayRepository,
|
||||
@ApplicationContext context: Context,
|
||||
): PerDisplayRepository<Context> {
|
||||
return if (enableOverviewOnConnectedDisplays()) {
|
||||
repositoryFactory.create(
|
||||
|
||||
@@ -53,8 +53,8 @@ import com.android.quickstep.HomeVisibilityState;
|
||||
import com.android.quickstep.LauncherActivityInterface;
|
||||
import com.android.quickstep.RecentsAnimationCallbacks;
|
||||
import com.android.quickstep.SystemUiProxy;
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowFlags;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowManager;
|
||||
import com.android.quickstep.util.SplitTask;
|
||||
import com.android.quickstep.views.RecentsView;
|
||||
import com.android.quickstep.views.RecentsViewContainer;
|
||||
@@ -121,8 +121,8 @@ public class LauncherTaskbarUIController extends TaskbarUIController {
|
||||
mControllers.getSharedState().sysuiStateFlags);
|
||||
final TaskbarActivityContext taskbarContext = mControllers.taskbarActivityContext;
|
||||
if (RecentsWindowFlags.getEnableOverviewInWindow()) {
|
||||
mRecentsViewContainer = RecentsDisplayModel.getINSTANCE()
|
||||
.get(taskbarContext).getRecentsWindowManager(taskbarContext.getDisplayId());
|
||||
mRecentsViewContainer = RecentsWindowManager.REPOSITORY_INSTANCE.get(
|
||||
taskbarContext).get(taskbarContext.getDisplayId());
|
||||
}
|
||||
if (mRecentsViewContainer == null) {
|
||||
mRecentsViewContainer = mLauncher;
|
||||
|
||||
@@ -65,7 +65,6 @@ import com.android.launcher3.util.MultiPropertyFactory.MultiProperty;
|
||||
import com.android.quickstep.RecentsAnimationCallbacks;
|
||||
import com.android.quickstep.RecentsAnimationController;
|
||||
import com.android.quickstep.fallback.RecentsState;
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowFlags;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowManager;
|
||||
import com.android.quickstep.util.ScalingWorkspaceRevealAnim;
|
||||
@@ -1128,8 +1127,9 @@ public class TaskbarLauncherStateController {
|
||||
private void runForRecentsWindowManager(Consumer<RecentsWindowManager> callback) {
|
||||
if (RecentsWindowFlags.getEnableOverviewInWindow()) {
|
||||
final TaskbarActivityContext taskbarContext = mControllers.taskbarActivityContext;
|
||||
RecentsWindowManager recentsWindowManager = RecentsDisplayModel.getINSTANCE()
|
||||
.get(taskbarContext).getRecentsWindowManager(taskbarContext.getDisplayId());
|
||||
RecentsWindowManager recentsWindowManager =
|
||||
RecentsWindowManager.REPOSITORY_INSTANCE.get(taskbarContext).get(
|
||||
taskbarContext.getDisplayId());
|
||||
if (recentsWindowManager != null) {
|
||||
callback.accept(recentsWindowManager);
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.app.displaylib.PerDisplayRepository;
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.InvariantDeviceProfile;
|
||||
import com.android.launcher3.Launcher;
|
||||
@@ -90,7 +91,6 @@ import com.android.quickstep.RecentsActivity;
|
||||
import com.android.quickstep.SystemDecorationChangeObserver;
|
||||
import com.android.quickstep.SystemDecorationChangeObserver.DisplayDecorationListener;
|
||||
import com.android.quickstep.SystemUiProxy;
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowFlags;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowManager;
|
||||
import com.android.quickstep.util.ContextualSearchInvoker;
|
||||
@@ -382,7 +382,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
private final SimpleBroadcastReceiver mGrowthBroadcastReceiver;
|
||||
|
||||
private final AllAppsActionManager mAllAppsActionManager;
|
||||
private final RecentsDisplayModel mRecentsDisplayModel;
|
||||
private final PerDisplayRepository<RecentsWindowManager> mRecentsWindowManagerRepository;
|
||||
|
||||
private final Runnable mActivityOnDestroyCallback = new Runnable() {
|
||||
@Override
|
||||
@@ -444,12 +444,12 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
Context context,
|
||||
AllAppsActionManager allAppsActionManager,
|
||||
TaskbarNavButtonCallbacks navCallbacks,
|
||||
RecentsDisplayModel recentsDisplayModel) {
|
||||
PerDisplayRepository<RecentsWindowManager> recentsWindowManagerRepository) {
|
||||
mBaseContext = context;
|
||||
mPrimaryDisplayId = mBaseContext.getDisplayId();
|
||||
mAllAppsActionManager = allAppsActionManager;
|
||||
mNavCallbacks = navCallbacks;
|
||||
mRecentsDisplayModel = recentsDisplayModel;
|
||||
mRecentsWindowManagerRepository = recentsWindowManagerRepository;
|
||||
|
||||
// Set up primary display.
|
||||
debugPrimaryTaskbar("TaskbarManager constructor");
|
||||
@@ -713,7 +713,7 @@ public class TaskbarManager implements DisplayDecorationListener {
|
||||
private TaskbarUIController createTaskbarUIControllerForNonDefaultDisplay(int displayId) {
|
||||
debugPrimaryTaskbar("createTaskbarUIControllerForNonDefaultDisplay");
|
||||
if (RecentsWindowFlags.Companion.getEnableOverviewInWindow()) {
|
||||
RecentsViewContainer rvc = mRecentsDisplayModel.getRecentsWindowManager(displayId);
|
||||
RecentsViewContainer rvc = mRecentsWindowManagerRepository.get(displayId);
|
||||
if (rvc != null) {
|
||||
return createTaskbarUIControllerForRecentsViewContainer(rvc);
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import com.android.app.displaylib.PerDisplayRepository;
|
||||
import com.android.app.viewcapture.ViewCaptureFactory;
|
||||
import com.android.launcher3.AbstractFloatingView;
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
@@ -178,7 +179,6 @@ import com.android.quickstep.RecentsModel;
|
||||
import com.android.quickstep.SystemUiProxy;
|
||||
import com.android.quickstep.TaskUtils;
|
||||
import com.android.quickstep.TouchInteractionService.TISBinder;
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowManager;
|
||||
import com.android.quickstep.util.ActiveGestureProtoLogProxy;
|
||||
import com.android.quickstep.util.AsyncClockEventDelegate;
|
||||
@@ -865,12 +865,10 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer,
|
||||
if (overviewCommandHelper != null) {
|
||||
overviewCommandHelper.clearPendingCommands();
|
||||
}
|
||||
RecentsDisplayModel recentsDisplayModel = RecentsDisplayModel.getINSTANCE().get(this);
|
||||
recentsDisplayModel.getActiveDisplayResources().forEach(resource -> {
|
||||
RecentsWindowManager recentsWindowManager = resource.getRecentsWindowManager();
|
||||
if (recentsWindowManager != null) {
|
||||
recentsWindowManager.onNewIntent();
|
||||
}
|
||||
PerDisplayRepository<RecentsWindowManager> recentsWindowManagerRepository =
|
||||
RecentsWindowManager.REPOSITORY_INSTANCE.get(this);
|
||||
recentsWindowManagerRepository.forEach(/* createIfAbsent= */ true, recentsWindowManager -> {
|
||||
recentsWindowManager.onNewIntent();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -29,11 +29,14 @@ import android.view.RemoteAnimationTarget;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.app.displaylib.PerDisplayRepository;
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.statemanager.StateManager;
|
||||
import com.android.launcher3.taskbar.TaskbarUIController;
|
||||
import com.android.launcher3.util.DaggerSingletonObject;
|
||||
import com.android.launcher3.util.DisplayController;
|
||||
import com.android.quickstep.GestureState.GestureEndTarget;
|
||||
import com.android.quickstep.dagger.QuickstepBaseAppComponent;
|
||||
import com.android.quickstep.fallback.RecentsState;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowManager;
|
||||
import com.android.quickstep.orientation.RecentsPagedOrientationHandler;
|
||||
@@ -41,6 +44,10 @@ import com.android.quickstep.util.AnimatorControllerWithResistance;
|
||||
import com.android.quickstep.util.ContextInitListener;
|
||||
import com.android.quickstep.views.RecentsView;
|
||||
|
||||
import dagger.assisted.Assisted;
|
||||
import dagger.assisted.AssistedFactory;
|
||||
import dagger.assisted.AssistedInject;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -51,9 +58,14 @@ import java.util.function.Predicate;
|
||||
*/
|
||||
public final class FallbackWindowInterface extends BaseWindowInterface{
|
||||
|
||||
public static final DaggerSingletonObject<PerDisplayRepository<FallbackWindowInterface>>
|
||||
REPOSITORY_INSTANCE = new DaggerSingletonObject<>(
|
||||
QuickstepBaseAppComponent::getFallbackWindowInterfaceRepository);
|
||||
|
||||
private final RecentsWindowManager mRecentsWindowManager;
|
||||
|
||||
public FallbackWindowInterface(RecentsWindowManager recentsWindowManager) {
|
||||
@AssistedInject
|
||||
public FallbackWindowInterface(@Assisted RecentsWindowManager recentsWindowManager) {
|
||||
super(DEFAULT, BACKGROUND_APP);
|
||||
mRecentsWindowManager = recentsWindowManager;
|
||||
}
|
||||
@@ -228,4 +240,10 @@ public final class FallbackWindowInterface extends BaseWindowInterface{
|
||||
animatorSet.playTogether(superAnimator, taskbarAnimator);
|
||||
return animatorSet;
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
public interface Factory {
|
||||
/** Creates a new instance of [FallbackWindowInterface] for a [RecentsWindowManager]. */
|
||||
FallbackWindowInterface create(RecentsWindowManager recentsWindowManager);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.android.quickstep
|
||||
|
||||
import android.content.res.Resources
|
||||
import com.android.quickstep.recents.data.HighResLoadingStateNotifier
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
|
||||
/** Determines when high res or low res thumbnails should be loaded. */
|
||||
class HighResLoadingState : HighResLoadingStateNotifier {
|
||||
@@ -38,7 +39,7 @@ class HighResLoadingState : HighResLoadingStateNotifier {
|
||||
var isEnabled: Boolean = false
|
||||
private set
|
||||
|
||||
private val callbacks = ArrayList<HighResLoadingStateChangedCallback>()
|
||||
private val callbacks = CopyOnWriteArrayList<HighResLoadingStateChangedCallback>()
|
||||
|
||||
interface HighResLoadingStateChangedCallback {
|
||||
fun onHighResLoadingStateChanged(enabled: Boolean)
|
||||
@@ -56,7 +57,7 @@ class HighResLoadingState : HighResLoadingStateNotifier {
|
||||
val prevState = isEnabled
|
||||
isEnabled = forceHighResThumbnails || (visible && !flingingFast)
|
||||
if (prevState != isEnabled) {
|
||||
for (callback in callbacks.asReversed()) {
|
||||
for (callback in callbacks) {
|
||||
callback.onHighResLoadingStateChanged(isEnabled)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.window.TransitionInfo
|
||||
import androidx.annotation.BinderThread
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import com.android.app.displaylib.DisplayRepository
|
||||
import com.android.app.displaylib.PerDisplayRepository
|
||||
import com.android.app.tracing.traceSection
|
||||
import com.android.internal.jank.Cuj
|
||||
@@ -52,7 +53,6 @@ import com.android.quickstep.OverviewCommandHelper.CommandType.HOME
|
||||
import com.android.quickstep.OverviewCommandHelper.CommandType.KEYBOARD_INPUT
|
||||
import com.android.quickstep.OverviewCommandHelper.CommandType.SHOW
|
||||
import com.android.quickstep.OverviewCommandHelper.CommandType.TOGGLE
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel
|
||||
import com.android.quickstep.fallback.window.RecentsWindowFlags.Companion.enableOverviewInWindow
|
||||
import com.android.quickstep.util.ActiveGestureLog
|
||||
import com.android.quickstep.util.ActiveGestureProtoLogProxy
|
||||
@@ -77,7 +77,7 @@ constructor(
|
||||
private val touchInteractionService: TouchInteractionService,
|
||||
private val overviewComponentObserver: OverviewComponentObserver,
|
||||
private val dispatcherProvider: DispatcherProvider = ProductionDispatchers,
|
||||
private val recentsDisplayModel: RecentsDisplayModel,
|
||||
private val displayRepository: DisplayRepository,
|
||||
private val taskbarManager: TaskbarManager,
|
||||
private val taskAnimationManagerRepository: PerDisplayRepository<TaskAnimationManager>,
|
||||
) {
|
||||
@@ -148,19 +148,13 @@ constructor(
|
||||
|
||||
@BinderThread
|
||||
fun addCommandsForAllDisplays(type: CommandType) =
|
||||
addCommandsForDisplays(
|
||||
type,
|
||||
recentsDisplayModel.activeDisplayResources
|
||||
.map { resource -> resource.displayId }
|
||||
.toIntArray(),
|
||||
)
|
||||
addCommandsForDisplays(type, displayRepository.displayIds.value.toIntArray())
|
||||
|
||||
@BinderThread
|
||||
fun addCommandsForDisplaysExcept(type: CommandType, excludedDisplayId: Int) =
|
||||
addCommandsForDisplays(
|
||||
type,
|
||||
recentsDisplayModel.activeDisplayResources
|
||||
.map { resource -> resource.displayId }
|
||||
displayRepository.displayIds.value
|
||||
.filter { displayId -> displayId != excludedDisplayId }
|
||||
.toIntArray(),
|
||||
)
|
||||
|
||||
@@ -43,6 +43,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
import com.android.app.displaylib.PerDisplayRepository;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.dagger.ApplicationContext;
|
||||
import com.android.launcher3.dagger.LauncherAppComponent;
|
||||
@@ -50,7 +51,6 @@ import com.android.launcher3.dagger.LauncherAppSingleton;
|
||||
import com.android.launcher3.util.DaggerSingletonObject;
|
||||
import com.android.launcher3.util.DaggerSingletonTracker;
|
||||
import com.android.launcher3.util.SimpleBroadcastReceiver;
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel;
|
||||
import com.android.quickstep.util.ActiveGestureProtoLogProxy;
|
||||
import com.android.systemui.shared.system.PackageManagerWrapper;
|
||||
|
||||
@@ -77,7 +77,7 @@ public final class OverviewComponentObserver {
|
||||
private final SimpleBroadcastReceiver mUserPreferenceChangeReceiver;
|
||||
private final SimpleBroadcastReceiver mOtherHomeAppUpdateReceiver;
|
||||
|
||||
private final RecentsDisplayModel mRecentsDisplayModel;
|
||||
private final PerDisplayRepository<FallbackWindowInterface> mFallbackWindowInterfaceRepository;
|
||||
|
||||
private final Intent mCurrentHomeIntent;
|
||||
private final Intent mMyHomeIntent;
|
||||
@@ -98,13 +98,13 @@ public final class OverviewComponentObserver {
|
||||
@Inject
|
||||
public OverviewComponentObserver(
|
||||
@ApplicationContext Context context,
|
||||
RecentsDisplayModel recentsDisplayModel,
|
||||
PerDisplayRepository<FallbackWindowInterface> fallbackWindowInterfaceRepository,
|
||||
DaggerSingletonTracker lifecycleTracker) {
|
||||
mUserPreferenceChangeReceiver =
|
||||
new SimpleBroadcastReceiver(context, MAIN_EXECUTOR, this::updateOverviewTargets);
|
||||
mOtherHomeAppUpdateReceiver =
|
||||
new SimpleBroadcastReceiver(context, MAIN_EXECUTOR, this::updateOverviewTargets);
|
||||
mRecentsDisplayModel = recentsDisplayModel;
|
||||
mFallbackWindowInterfaceRepository = fallbackWindowInterfaceRepository;
|
||||
mCurrentHomeIntent = createHomeIntent();
|
||||
mMyHomeIntent = new Intent(mCurrentHomeIntent).setPackage(context.getPackageName());
|
||||
ResolveInfo info = context.getPackageManager().resolveActivity(mMyHomeIntent, 0);
|
||||
@@ -197,7 +197,7 @@ public final class OverviewComponentObserver {
|
||||
// User default home is same as our home app. Use Overview integrated in Launcher.
|
||||
if (enableLauncherOverviewInWindow.isTrue()) {
|
||||
mDefaultDisplayContainerInterface =
|
||||
mRecentsDisplayModel.getFallbackWindowInterface(DEFAULT_DISPLAY);
|
||||
mFallbackWindowInterfaceRepository.get(DEFAULT_DISPLAY);
|
||||
} else {
|
||||
mDefaultDisplayContainerInterface = LauncherActivityInterface.INSTANCE;
|
||||
}
|
||||
@@ -211,7 +211,7 @@ public final class OverviewComponentObserver {
|
||||
// The default home app is a different launcher. Use the fallback Overview instead.
|
||||
if (enableFallbackOverviewInWindow.isTrue()) {
|
||||
mDefaultDisplayContainerInterface =
|
||||
mRecentsDisplayModel.getFallbackWindowInterface(DEFAULT_DISPLAY);
|
||||
mFallbackWindowInterfaceRepository.get(DEFAULT_DISPLAY);
|
||||
} else {
|
||||
mDefaultDisplayContainerInterface = FallbackActivityInterface.INSTANCE;
|
||||
}
|
||||
@@ -314,7 +314,7 @@ public final class OverviewComponentObserver {
|
||||
*/
|
||||
public BaseContainerInterface<?, ?> getContainerInterface(int displayId) {
|
||||
return (enableOverviewOnConnectedDisplays() && displayId != DEFAULT_DISPLAY)
|
||||
? mRecentsDisplayModel.getFallbackWindowInterface(displayId)
|
||||
? mFallbackWindowInterfaceRepository.get(displayId)
|
||||
: mDefaultDisplayContainerInterface;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,8 +149,13 @@ public class RotationTouchHelper implements DisplayInfoChangeListener {
|
||||
mSystemUiProxy = systemUiProxy;
|
||||
|
||||
Resources resources = mApplicationContext.getResources();
|
||||
// TODO(b/408988616): Find a better solution for external display to have resources updated
|
||||
// after configuration changes.
|
||||
Context displayAssociatedContext =
|
||||
mApplicationContext.getAssociatedDisplayId() == mDisplayId
|
||||
? mApplicationContext : displayContext;
|
||||
mOrientationTouchTransformer = new OrientationTouchTransformer(resources, mMode,
|
||||
() -> QuickStepContract.getWindowCornerRadius(displayContext));
|
||||
() -> QuickStepContract.getWindowCornerRadius(displayAssociatedContext));
|
||||
|
||||
// Register for navigation mode and rotation changes
|
||||
mDisplayController.addChangeListenerForDisplay(this, mDisplayId);
|
||||
@@ -397,7 +402,7 @@ public class RotationTouchHelper implements DisplayInfoChangeListener {
|
||||
|
||||
@AssistedFactory
|
||||
public interface Factory {
|
||||
/** Creates a new instance of [RotationTouchHelper] for a given [display]. */
|
||||
/** Creates a new instance of [RotationTouchHelper] for a given [context]. */
|
||||
RotationTouchHelper create(@DisplayContext Context context);
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,6 @@ import com.android.launcher3.taskbar.TaskbarUIController;
|
||||
import com.android.launcher3.util.DaggerSingletonObject;
|
||||
import com.android.launcher3.util.DisplayController;
|
||||
import com.android.quickstep.dagger.QuickstepBaseAppComponent;
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowFlags;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowManager;
|
||||
import com.android.quickstep.util.ActiveGestureProtoLogProxy;
|
||||
@@ -60,14 +59,14 @@ import com.android.systemui.shared.system.QuickStepContract;
|
||||
import com.android.systemui.shared.system.TaskStackChangeListener;
|
||||
import com.android.systemui.shared.system.TaskStackChangeListeners;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
import dagger.assisted.Assisted;
|
||||
import dagger.assisted.AssistedFactory;
|
||||
import dagger.assisted.AssistedInject;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
public class TaskAnimationManager implements RecentsAnimationCallbacks.RecentsAnimationListener {
|
||||
public static final boolean SHELL_TRANSITIONS_ROTATION =
|
||||
SystemProperties.getBoolean("persist.wm.debug.shell_transit_rotate", false);
|
||||
@@ -338,13 +337,12 @@ public class TaskAnimationManager implements RecentsAnimationCallbacks.RecentsAn
|
||||
});
|
||||
}
|
||||
|
||||
if(containerInterface.getCreatedContainer() instanceof RecentsWindowManager
|
||||
if (containerInterface.getCreatedContainer()
|
||||
instanceof RecentsWindowManager recentsWindowManager
|
||||
&& RecentsWindowFlags.Companion.getEnableOverviewInWindow()) {
|
||||
mRecentsAnimationStartPending = getSystemUiProxy().startRecentsActivity(intent, options,
|
||||
mCallbacks, gestureState.useSyntheticRecentsTransition());
|
||||
RecentsDisplayModel.getINSTANCE().get(mCtx)
|
||||
.getRecentsWindowManager(gestureState.getDisplayId())
|
||||
.startRecentsWindow(mCallbacks);
|
||||
recentsWindowManager.startRecentsWindow(mCallbacks);
|
||||
} else {
|
||||
mRecentsAnimationStartPending = getSystemUiProxy().startRecentsActivity(intent,
|
||||
options, mCallbacks, false /* useSyntheticRecentsTransition */);
|
||||
|
||||
@@ -94,8 +94,8 @@ import com.android.launcher3.util.ScreenOnTracker;
|
||||
import com.android.launcher3.util.TraceHelper;
|
||||
import com.android.quickstep.OverviewCommandHelper.CommandType;
|
||||
import com.android.quickstep.OverviewComponentObserver.OverviewChangeListener;
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowFlags;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowManager;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowSwipeHandler;
|
||||
import com.android.quickstep.input.QuickstepKeyGestureEventsManager;
|
||||
import com.android.quickstep.inputconsumers.BubbleBarInputConsumer;
|
||||
@@ -630,7 +630,7 @@ public class TouchInteractionService extends Service {
|
||||
|
||||
private DisplayController.DisplayInfoChangeListener mDisplayInfoChangeListener;
|
||||
|
||||
private RecentsDisplayModel mRecentsDisplayModel;
|
||||
PerDisplayRepository<RecentsWindowManager> mRecentsWindowManagerRepository;
|
||||
|
||||
private SystemDecorationChangeObserver mSystemDecorationChangeObserver;
|
||||
|
||||
@@ -650,7 +650,7 @@ public class TouchInteractionService extends Service {
|
||||
mTaskAnimationManagerRepository = TaskAnimationManager.REPOSITORY_INSTANCE.get(this);
|
||||
mMainChoreographer = Choreographer.getInstance();
|
||||
mRotationTouchHelperRepository = RotationTouchHelper.REPOSITORY_INSTANCE.get(this);
|
||||
mRecentsDisplayModel = RecentsDisplayModel.getINSTANCE().get(this);
|
||||
mRecentsWindowManagerRepository = RecentsWindowManager.REPOSITORY_INSTANCE.get(this);
|
||||
mSystemDecorationChangeObserver = SystemDecorationChangeObserver.getINSTANCE().get(this);
|
||||
mQuickstepKeyGestureEventsHandler = new QuickstepKeyGestureEventsManager(this);
|
||||
mAllAppsActionManager = new AllAppsActionManager(this, UI_HELPER_EXECUTOR,
|
||||
@@ -666,7 +666,7 @@ public class TouchInteractionService extends Service {
|
||||
});
|
||||
|
||||
mTaskbarManager = new TaskbarManager(this, mAllAppsActionManager, mNavCallbacks,
|
||||
mRecentsDisplayModel);
|
||||
mRecentsWindowManagerRepository);
|
||||
mDesktopAppLaunchTransitionManager =
|
||||
new DesktopAppLaunchTransitionManager(this, SystemUiProxy.INSTANCE.get(this));
|
||||
mDesktopAppLaunchTransitionManager.registerTransitions();
|
||||
@@ -753,7 +753,7 @@ public class TouchInteractionService extends Service {
|
||||
+ " instance=" + System.identityHashCode(this));
|
||||
mOverviewComponentObserver = OverviewComponentObserver.INSTANCE.get(this);
|
||||
mOverviewCommandHelper = new OverviewCommandHelper(this,
|
||||
mOverviewComponentObserver, mRecentsDisplayModel, mTaskbarManager,
|
||||
mOverviewComponentObserver, mDisplayRepository, mTaskbarManager,
|
||||
mTaskAnimationManagerRepository);
|
||||
mUserUnlocked = true;
|
||||
mInputConsumer.registerInputConsumer();
|
||||
@@ -1339,12 +1339,14 @@ public class TouchInteractionService extends Service {
|
||||
TaskAnimationManager taskAnimationManager = mTaskAnimationManagerRepository.get(displayId);
|
||||
RecentsAnimationDeviceState deviceState = mDeviceStateRepository.get(displayId);
|
||||
RotationTouchHelper rotationTouchHelper = mRotationTouchHelperRepository.get(displayId);
|
||||
if (taskAnimationManager == null || deviceState == null || rotationTouchHelper == null) {
|
||||
RecentsWindowManager recentsWindowManager = mRecentsWindowManagerRepository.get(displayId);
|
||||
if (taskAnimationManager == null || deviceState == null || rotationTouchHelper == null
|
||||
|| recentsWindowManager == null) {
|
||||
Log.d(TAG, "displayId " + displayId + " not valid");
|
||||
return null;
|
||||
}
|
||||
return new RecentsWindowSwipeHandler(this, taskAnimationManager, deviceState,
|
||||
rotationTouchHelper, gestureState, touchTimeMs,
|
||||
rotationTouchHelper, recentsWindowManager, gestureState, touchTimeMs,
|
||||
taskAnimationManager.isRecentsAnimationRunning(),
|
||||
mInputConsumer, MSDLPlayerWrapper.INSTANCE.get(this));
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.android.launcher3.dagger.LauncherAppComponent;
|
||||
import com.android.launcher3.dagger.LauncherBaseAppComponent;
|
||||
import com.android.launcher3.model.WellbeingModel;
|
||||
import com.android.launcher3.statehandlers.DesktopVisibilityController;
|
||||
import com.android.quickstep.FallbackWindowInterface;
|
||||
import com.android.quickstep.OverviewComponentObserver;
|
||||
import com.android.quickstep.RecentsAnimationDeviceState;
|
||||
import com.android.quickstep.RecentsModel;
|
||||
@@ -31,7 +32,7 @@ import com.android.quickstep.SystemDecorationChangeObserver;
|
||||
import com.android.quickstep.SystemUiProxy;
|
||||
import com.android.quickstep.TaskAnimationManager;
|
||||
import com.android.quickstep.TopTaskTracker;
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowManager;
|
||||
import com.android.quickstep.logging.SettingsChangeLogger;
|
||||
import com.android.quickstep.util.AsyncClockEventDelegate;
|
||||
import com.android.quickstep.util.ContextualSearchHapticManager;
|
||||
@@ -53,8 +54,6 @@ public interface QuickstepBaseAppComponent extends LauncherBaseAppComponent {
|
||||
|
||||
SystemUiProxy getSystemUiProxy();
|
||||
|
||||
RecentsDisplayModel getRecentsDisplayModel();
|
||||
|
||||
OverviewComponentObserver getOverviewComponentObserver();
|
||||
|
||||
DesktopVisibilityController getDesktopVisibilityController();
|
||||
@@ -66,9 +65,15 @@ public interface QuickstepBaseAppComponent extends LauncherBaseAppComponent {
|
||||
ContextualSearchStateManager getContextualSearchStateManager();
|
||||
|
||||
PerDisplayRepository<RecentsAnimationDeviceState> getRecentsAnimationDeviceStateRepository();
|
||||
|
||||
PerDisplayRepository<TaskAnimationManager> getTaskAnimationManagerRepository();
|
||||
|
||||
PerDisplayRepository<RotationTouchHelper> getRotationTouchHelperRepository();
|
||||
|
||||
PerDisplayRepository<RecentsWindowManager> getRecentsWindowManagerRepository();
|
||||
|
||||
PerDisplayRepository<FallbackWindowInterface> getFallbackWindowInterfaceRepository();
|
||||
|
||||
RecentsModel getRecentsModel();
|
||||
|
||||
SettingsChangeLogger getSettingsChangeLogger();
|
||||
|
||||
@@ -43,9 +43,9 @@ import com.android.launcher3.util.SplitConfigurationOptions;
|
||||
import com.android.launcher3.util.SplitConfigurationOptions.SplitSelectSource;
|
||||
import com.android.quickstep.BaseContainerInterface;
|
||||
import com.android.quickstep.FallbackActivityInterface;
|
||||
import com.android.quickstep.FallbackWindowInterface;
|
||||
import com.android.quickstep.GestureState;
|
||||
import com.android.quickstep.RemoteTargetGluer.RemoteTargetHandle;
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowFlags;
|
||||
import com.android.quickstep.util.GroupTask;
|
||||
import com.android.quickstep.util.SingleTask;
|
||||
@@ -83,8 +83,7 @@ public class FallbackRecentsView<CONTAINER_TYPE extends Context & RecentsViewCon
|
||||
@Override
|
||||
public BaseContainerInterface<RecentsState, ?> getContainerInterface(int displayId) {
|
||||
return RecentsWindowFlags.Companion.getEnableOverviewInWindow()
|
||||
? RecentsDisplayModel.getINSTANCE().get(mContext)
|
||||
.getFallbackWindowInterface(displayId)
|
||||
? FallbackWindowInterface.REPOSITORY_INSTANCE.get(mContext).get(displayId)
|
||||
: FallbackActivityInterface.INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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.quickstep.fallback.window
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.view.Display
|
||||
import android.view.Display.DEFAULT_DISPLAY
|
||||
import androidx.core.util.valueIterator
|
||||
import com.android.launcher3.dagger.ApplicationContext
|
||||
import com.android.launcher3.dagger.LauncherAppSingleton
|
||||
import com.android.launcher3.util.DaggerSingletonObject
|
||||
import com.android.launcher3.util.DaggerSingletonTracker
|
||||
import com.android.launcher3.util.WallpaperColorHints
|
||||
import com.android.quickstep.DisplayModel
|
||||
import com.android.quickstep.FallbackWindowInterface
|
||||
import com.android.quickstep.SystemDecorationChangeObserver
|
||||
import com.android.quickstep.dagger.QuickstepBaseAppComponent
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel.RecentsDisplayResource
|
||||
import com.android.quickstep.fallback.window.RecentsWindowFlags.Companion.enableOverviewInWindow
|
||||
import java.io.PrintWriter
|
||||
import javax.inject.Inject
|
||||
|
||||
@LauncherAppSingleton
|
||||
class RecentsDisplayModel
|
||||
@Inject
|
||||
constructor(
|
||||
@ApplicationContext context: Context,
|
||||
private val wallpaperColorHints: WallpaperColorHints,
|
||||
systemDecorationChangeObserver: SystemDecorationChangeObserver,
|
||||
tracker: DaggerSingletonTracker,
|
||||
) : DisplayModel<RecentsDisplayResource>(context, systemDecorationChangeObserver) {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "RecentsDisplayModel"
|
||||
private const val DEBUG = false
|
||||
|
||||
@JvmStatic
|
||||
val INSTANCE: DaggerSingletonObject<RecentsDisplayModel> =
|
||||
DaggerSingletonObject<RecentsDisplayModel>(
|
||||
QuickstepBaseAppComponent::getRecentsDisplayModel
|
||||
)
|
||||
}
|
||||
|
||||
init {
|
||||
if (enableOverviewInWindow) {
|
||||
initializeDisplays()
|
||||
} else {
|
||||
// Always create resource for default display
|
||||
storeDisplayResource(DEFAULT_DISPLAY)
|
||||
}
|
||||
tracker.addCloseable { destroy() }
|
||||
}
|
||||
|
||||
override fun createDisplayResource(display: Display): RecentsDisplayResource {
|
||||
return RecentsDisplayResource(
|
||||
display.displayId,
|
||||
context.createDisplayContext(display),
|
||||
wallpaperColorHints.hints,
|
||||
)
|
||||
}
|
||||
|
||||
fun getRecentsWindowManager(displayId: Int): RecentsWindowManager? {
|
||||
if (DEBUG) Log.d(TAG, "getRecentsWindowManager for display $displayId")
|
||||
return getDisplayResource(displayId)?.recentsWindowManager
|
||||
}
|
||||
|
||||
fun getFallbackWindowInterface(displayId: Int): FallbackWindowInterface? {
|
||||
if (DEBUG) Log.d(TAG, "getFallbackWindowInterface for display $displayId")
|
||||
return getDisplayResource(displayId)?.fallbackWindowInterface
|
||||
}
|
||||
|
||||
val activeDisplayResources: Iterable<RecentsDisplayResource>
|
||||
get() =
|
||||
object : Iterable<RecentsDisplayResource> {
|
||||
override fun iterator() = displayResourceArray.valueIterator()
|
||||
}
|
||||
|
||||
data class RecentsDisplayResource(
|
||||
val displayId: Int,
|
||||
val displayContext: Context,
|
||||
val wallpaperColorHints: Int,
|
||||
) : DisplayResource() {
|
||||
val recentsWindowManager =
|
||||
if (enableOverviewInWindow) RecentsWindowManager(displayContext, wallpaperColorHints)
|
||||
else null
|
||||
val fallbackWindowInterface =
|
||||
if (enableOverviewInWindow) FallbackWindowInterface(recentsWindowManager) else null
|
||||
|
||||
override fun cleanup() {
|
||||
recentsWindowManager?.destroy()
|
||||
}
|
||||
|
||||
override fun dump(prefix: String, writer: PrintWriter) {
|
||||
writer.println("${prefix}RecentsDisplayResource:")
|
||||
|
||||
writer.println("${prefix}\tdisplayId=${displayId}")
|
||||
writer.println("${prefix}\tdisplayContext=${displayContext}")
|
||||
writer.println("${prefix}\twallpaperColorHints=${wallpaperColorHints}")
|
||||
writer.println("${prefix}\trecentsWindowManager=${recentsWindowManager}")
|
||||
writer.println("${prefix}\tfallbackWindowInterface=${fallbackWindowInterface}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,8 @@ import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
|
||||
import android.window.RemoteTransition
|
||||
import com.android.app.displaylib.PerDisplayInstanceProviderWithTeardown
|
||||
import com.android.app.displaylib.PerDisplayRepository
|
||||
import com.android.launcher3.AbstractFloatingView
|
||||
import com.android.launcher3.BaseActivity
|
||||
import com.android.launcher3.LauncherAnimationRunner
|
||||
@@ -40,6 +42,8 @@ import com.android.launcher3.LauncherAnimationRunner.RemoteAnimationFactory
|
||||
import com.android.launcher3.LauncherState
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.compat.AccessibilityManagerCompat
|
||||
import com.android.launcher3.dagger.DisplayContext
|
||||
import com.android.launcher3.dagger.LauncherAppSingleton
|
||||
import com.android.launcher3.statemanager.StateManager
|
||||
import com.android.launcher3.statemanager.StateManager.AtomicAnimationFactory
|
||||
import com.android.launcher3.statemanager.StatefulContainer
|
||||
@@ -47,10 +51,12 @@ import com.android.launcher3.taskbar.TaskbarUIController
|
||||
import com.android.launcher3.testing.TestLogging
|
||||
import com.android.launcher3.testing.shared.TestProtocol.SEQUENCE_MAIN
|
||||
import com.android.launcher3.util.ContextTracker
|
||||
import com.android.launcher3.util.DaggerSingletonObject
|
||||
import com.android.launcher3.util.DisplayController
|
||||
import com.android.launcher3.util.Executors
|
||||
import com.android.launcher3.util.RunnableList
|
||||
import com.android.launcher3.util.SystemUiController
|
||||
import com.android.launcher3.util.WallpaperColorHints
|
||||
import com.android.launcher3.views.BaseDragLayer
|
||||
import com.android.launcher3.views.ScrimView
|
||||
import com.android.quickstep.OverviewComponentObserver
|
||||
@@ -60,6 +66,7 @@ import com.android.quickstep.RecentsAnimationController
|
||||
import com.android.quickstep.RecentsModel
|
||||
import com.android.quickstep.RemoteAnimationTargets
|
||||
import com.android.quickstep.SystemUiProxy
|
||||
import com.android.quickstep.dagger.QuickstepBaseAppComponent
|
||||
import com.android.quickstep.fallback.FallbackRecentsStateController
|
||||
import com.android.quickstep.fallback.FallbackRecentsView
|
||||
import com.android.quickstep.fallback.RecentsDragLayer
|
||||
@@ -81,6 +88,10 @@ import com.android.quickstep.views.RecentsViewContainer
|
||||
import com.android.systemui.shared.recents.model.ThumbnailData
|
||||
import com.android.systemui.shared.system.TaskStackChangeListener
|
||||
import com.android.systemui.shared.system.TaskStackChangeListeners
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Class that will manage RecentsView lifecycle within a window and interface correctly where
|
||||
@@ -91,8 +102,10 @@ import com.android.systemui.shared.system.TaskStackChangeListeners
|
||||
* To add new protologs, see [RecentsWindowProtoLogProxy]. To enable logging to logcat, see
|
||||
* [QuickstepProtoLogGroup.Constants.DEBUG_RECENTS_WINDOW]
|
||||
*/
|
||||
class RecentsWindowManager(context: Context, wallpaperColorHints: Int) :
|
||||
RecentsWindowContext(context, wallpaperColorHints),
|
||||
class RecentsWindowManager
|
||||
@AssistedInject
|
||||
constructor(@Assisted context: Context, wallpaperColorHints: WallpaperColorHints) :
|
||||
RecentsWindowContext(context, wallpaperColorHints.hints),
|
||||
RecentsViewContainer,
|
||||
StatefulContainer<RecentsState> {
|
||||
|
||||
@@ -100,11 +113,17 @@ class RecentsWindowManager(context: Context, wallpaperColorHints: Int) :
|
||||
private const val HOME_APPEAR_DURATION: Long = 250
|
||||
private const val TAG = "RecentsWindowManager"
|
||||
|
||||
@JvmField
|
||||
val REPOSITORY_INSTANCE =
|
||||
DaggerSingletonObject<PerDisplayRepository<RecentsWindowManager>>(
|
||||
QuickstepBaseAppComponent::getRecentsWindowManagerRepository
|
||||
)
|
||||
|
||||
class RecentsWindowTracker : ContextTracker<RecentsWindowManager?>() {
|
||||
override fun isHomeStarted(context: RecentsWindowManager?): Boolean {
|
||||
// if we need to change this block to use context in some way, we will need to
|
||||
// refactor RecentsWindowTracker to be an instance (instead of a singleton) managed
|
||||
// by RecentsDisplayModel. Otherwise bad things will occur.
|
||||
// by PerDisplayRepository. Otherwise bad things will occur.
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -475,4 +494,25 @@ class RecentsWindowManager(context: Context, wallpaperColorHints: Int) :
|
||||
override fun createAtomicAnimationFactory(): AtomicAnimationFactory<RecentsState?>? {
|
||||
return RecentsAtomicAnimationFactory<RecentsWindowManager, RecentsState>(this)
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
/** Creates a new instance of [RecentsWindowManager] for a given [context]. */
|
||||
fun create(@DisplayContext context: Context): RecentsWindowManager
|
||||
}
|
||||
}
|
||||
|
||||
@LauncherAppSingleton
|
||||
class RecentsWindowManagerInstanceProvider
|
||||
@Inject
|
||||
constructor(
|
||||
private val factory: RecentsWindowManager.Factory,
|
||||
@DisplayContext private val displayContextRepository: PerDisplayRepository<Context>,
|
||||
) : PerDisplayInstanceProviderWithTeardown<RecentsWindowManager> {
|
||||
override fun createInstance(displayId: Int) =
|
||||
displayContextRepository[displayId]?.let { factory.create(it) }
|
||||
|
||||
override fun destroyInstance(instance: RecentsWindowManager) {
|
||||
instance.destroy()
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public class RecentsWindowSwipeHandler extends AbsSwipeUpHandler<RecentsWindowMa
|
||||
private static StaticMessageReceiver sMessageReceiver = null;
|
||||
|
||||
private FallbackHomeAnimationFactory mActiveAnimationFactory;
|
||||
private final RecentsDisplayModel mRecentsDisplayModel;
|
||||
private final RecentsWindowManager mRecentsWindowManager;
|
||||
|
||||
private final boolean mRunningOverHome;
|
||||
|
||||
@@ -116,12 +116,13 @@ public class RecentsWindowSwipeHandler extends AbsSwipeUpHandler<RecentsWindowMa
|
||||
|
||||
public RecentsWindowSwipeHandler(Context context, TaskAnimationManager taskAnimationManager,
|
||||
RecentsAnimationDeviceState deviceState, RotationTouchHelper rotationTouchHelper,
|
||||
GestureState gestureState, long touchTimeMs, boolean continuingLastGesture,
|
||||
InputConsumerController inputConsumer, MSDLPlayerWrapper msdlPlayerWrapper) {
|
||||
RecentsWindowManager recentsWindowManager, GestureState gestureState, long touchTimeMs,
|
||||
boolean continuingLastGesture, InputConsumerController inputConsumer,
|
||||
MSDLPlayerWrapper msdlPlayerWrapper) {
|
||||
super(context, taskAnimationManager, deviceState, rotationTouchHelper, gestureState,
|
||||
touchTimeMs, continuingLastGesture, inputConsumer, msdlPlayerWrapper);
|
||||
|
||||
mRecentsDisplayModel = RecentsDisplayModel.getINSTANCE().get(context);
|
||||
mRecentsWindowManager = recentsWindowManager;
|
||||
mRunningOverHome = mGestureState.getRunningTask() != null
|
||||
&& mGestureState.getRunningTask().isHomeTask();
|
||||
|
||||
@@ -167,11 +168,7 @@ public class RecentsWindowSwipeHandler extends AbsSwipeUpHandler<RecentsWindowMa
|
||||
boolean fromHomeToHome = mRunningOverHome
|
||||
&& endTarget == GestureState.GestureEndTarget.HOME;
|
||||
if (fromHomeToHome) {
|
||||
RecentsWindowManager manager =
|
||||
mRecentsDisplayModel.getRecentsWindowManager(mGestureState.getDisplayId());
|
||||
if (manager != null) {
|
||||
manager.startHome(/* finishRecentsAnimation= */ false);
|
||||
}
|
||||
mRecentsWindowManager.startHome(/* finishRecentsAnimation= */ false);
|
||||
}
|
||||
super.animateGestureEnd(
|
||||
startShift,
|
||||
@@ -233,11 +230,7 @@ public class RecentsWindowSwipeHandler extends AbsSwipeUpHandler<RecentsWindowMa
|
||||
// the PiP task appearing.
|
||||
recentsCallback = () -> {
|
||||
callback.run();
|
||||
RecentsWindowManager manager =
|
||||
mRecentsDisplayModel.getRecentsWindowManager(mGestureState.getDisplayId());
|
||||
if (manager != null) {
|
||||
manager.startHome();
|
||||
}
|
||||
mRecentsWindowManager.startHome();
|
||||
};
|
||||
} else {
|
||||
recentsCallback = callback;
|
||||
@@ -276,7 +269,7 @@ public class RecentsWindowSwipeHandler extends AbsSwipeUpHandler<RecentsWindowMa
|
||||
public AnimatorPlaybackController createActivityAnimationToHome() {
|
||||
// copied from {@link LauncherSwipeHandlerV2.LauncherHomeAnimationFactory}
|
||||
long accuracy = 2 * Math.max(mDp.widthPx, mDp.heightPx);
|
||||
return mRecentsDisplayModel.getRecentsWindowManager(mGestureState.getDisplayId())
|
||||
return mRecentsWindowManager
|
||||
.getStateManager()
|
||||
.createAnimationToNewWorkspace(
|
||||
RecentsState.HOME, accuracy, StateAnimationConfig.SKIP_ALL_ANIMATIONS);
|
||||
@@ -333,7 +326,7 @@ public class RecentsWindowSwipeHandler extends AbsSwipeUpHandler<RecentsWindowMa
|
||||
pa.addListener(new AnimationSuccessListener() {
|
||||
@Override
|
||||
public void onAnimationSuccess(Animator animator) {
|
||||
mRecentsDisplayModel.getRecentsWindowManager(mGestureState.getDisplayId())
|
||||
mRecentsWindowManager
|
||||
.getStateManager()
|
||||
.goToState(RecentsState.HOME, false);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.android.quickstep.recents.data.RecentTasksRepository
|
||||
import com.android.quickstep.recents.data.TaskVisualsChangedDelegate
|
||||
import com.android.quickstep.recents.data.TaskVisualsChangedDelegateImpl
|
||||
import com.android.quickstep.recents.data.TasksRepository
|
||||
import com.android.quickstep.recents.domain.usecase.GetRemainingAppTimerDurationUseCase
|
||||
import com.android.quickstep.recents.domain.usecase.GetSysUiStatusNavFlagsUseCase
|
||||
import com.android.quickstep.recents.domain.usecase.GetTaskUseCase
|
||||
import com.android.quickstep.recents.domain.usecase.GetThumbnailPositionUseCase
|
||||
@@ -195,7 +196,13 @@ private constructor(appContext: Context, dispatcherProvider: DispatcherProvider)
|
||||
when (modelClass) {
|
||||
IsThumbnailValidUseCase::class.java ->
|
||||
IsThumbnailValidUseCase(rotationStateRepository = inject(scopeId))
|
||||
GetTaskUseCase::class.java -> GetTaskUseCase(repository = inject(scopeId))
|
||||
GetRemainingAppTimerDurationUseCase::class.java ->
|
||||
GetRemainingAppTimerDurationUseCase(appTimersRepository = inject(scopeId))
|
||||
GetTaskUseCase::class.java ->
|
||||
GetTaskUseCase(
|
||||
tasksRepository = inject(scopeId),
|
||||
getRemainingAppTimerDurationUseCase = inject(scopeId),
|
||||
)
|
||||
GetSysUiStatusNavFlagsUseCase::class.java -> GetSysUiStatusNavFlagsUseCase()
|
||||
GetThumbnailPositionUseCase::class.java ->
|
||||
GetThumbnailPositionUseCase(
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.quickstep.recents.domain.model
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import com.android.systemui.shared.recents.model.ThumbnailData
|
||||
import java.time.Duration
|
||||
|
||||
/**
|
||||
* Data class representing a task in the application.
|
||||
@@ -26,6 +27,7 @@ import com.android.systemui.shared.recents.model.ThumbnailData
|
||||
* title, associated icon, optional thumbnail data, and background color.
|
||||
*
|
||||
* @property id The unique identifier for this task. Must be an integer.
|
||||
* @property packageName top activity package for the task's app
|
||||
* @property title The display title of the task.
|
||||
* @property titleDescription A content description of the task.
|
||||
* @property icon An optional drawable resource representing an icon for the task. Can be null if no
|
||||
@@ -36,9 +38,11 @@ import com.android.systemui.shared.recents.model.ThumbnailData
|
||||
* value.
|
||||
* @property isLocked Indicates whether the [Task] is locked.
|
||||
* @property isMinimized Indicates whether the [Task] is minimized.
|
||||
* @property remainingAppDuration time remaining on the app timer for the application.
|
||||
*/
|
||||
data class TaskModel(
|
||||
val id: TaskId,
|
||||
val packageName: String,
|
||||
val title: String?,
|
||||
val titleDescription: String?,
|
||||
val icon: Drawable?,
|
||||
@@ -46,6 +50,7 @@ data class TaskModel(
|
||||
val backgroundColor: Int,
|
||||
val isLocked: Boolean,
|
||||
val isMinimized: Boolean,
|
||||
val remainingAppDuration: Duration?,
|
||||
)
|
||||
|
||||
typealias TaskId = Int
|
||||
@@ -16,27 +16,46 @@
|
||||
|
||||
package com.android.quickstep.recents.domain.usecase
|
||||
|
||||
import android.os.UserHandle
|
||||
import com.android.launcher3.Flags.enableRefactorDigitalWellbeingToast
|
||||
import com.android.quickstep.recents.data.RecentTasksRepository
|
||||
import com.android.quickstep.recents.domain.model.TaskModel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
class GetTaskUseCase(private val repository: RecentTasksRepository) {
|
||||
class GetTaskUseCase(
|
||||
private val tasksRepository: RecentTasksRepository,
|
||||
private val getRemainingAppTimerDurationUseCase: GetRemainingAppTimerDurationUseCase,
|
||||
) {
|
||||
operator fun invoke(taskId: Int): Flow<TaskModel?> =
|
||||
repository.getTaskDataById(taskId).map { task ->
|
||||
if (task != null) {
|
||||
TaskModel(
|
||||
id = task.key.id,
|
||||
title = task.title,
|
||||
titleDescription = task.titleDescription,
|
||||
icon = task.icon,
|
||||
thumbnail = task.thumbnail,
|
||||
backgroundColor = task.colorBackground,
|
||||
isLocked = task.isLocked,
|
||||
isMinimized = task.isMinimized,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
tasksRepository.getTaskDataById(taskId).map { task ->
|
||||
if (task == null) return@map null
|
||||
|
||||
val packageName = task.topComponent.packageName
|
||||
|
||||
// TODO(b/405359794): If getTask for a single task ends up being called multiple
|
||||
// times by the UI, explore alternatives of loading the timer info only once.
|
||||
val remainingDuration =
|
||||
if (enableRefactorDigitalWellbeingToast()) {
|
||||
getRemainingAppTimerDurationUseCase(
|
||||
packageName = packageName,
|
||||
userHandle = UserHandle(task.key.userId),
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
TaskModel(
|
||||
id = task.key.id,
|
||||
packageName = packageName,
|
||||
title = task.title,
|
||||
titleDescription = task.titleDescription,
|
||||
icon = task.icon,
|
||||
thumbnail = task.thumbnail,
|
||||
backgroundColor = task.colorBackground,
|
||||
isLocked = task.isLocked,
|
||||
isMinimized = task.isMinimized,
|
||||
remainingAppDuration = remainingDuration,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.android.quickstep.recents.ui.viewmodel
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import com.android.systemui.shared.recents.model.ThumbnailData
|
||||
import java.time.Duration
|
||||
|
||||
/**
|
||||
* This class represents the UI state to be consumed by TaskView, GroupTaskView and DesktopTaskView.
|
||||
@@ -49,6 +50,7 @@ sealed class TaskData {
|
||||
* This class provides UI information related to a Task (App) to be displayed within a TaskView.
|
||||
*
|
||||
* @property taskId Identifier of the task
|
||||
* @property packageName package name for the task
|
||||
* @property title App title
|
||||
* @property titleDescription App content description
|
||||
* @property icon App icon
|
||||
@@ -56,9 +58,11 @@ sealed class TaskData {
|
||||
* @property backgroundColor The background color of the task.
|
||||
* @property isLocked Indicates whether the task is locked or not.
|
||||
* @property isLiveTile Indicates whether the task is shown with a live tile or not.
|
||||
* @property remainingAppTimerDuration time remaining on the app timer for the application.
|
||||
*/
|
||||
data class Data(
|
||||
override val taskId: Int,
|
||||
val packageName: String,
|
||||
val title: String?,
|
||||
val titleDescription: String?,
|
||||
val icon: Drawable?,
|
||||
@@ -66,5 +70,6 @@ sealed class TaskData {
|
||||
val backgroundColor: Int,
|
||||
val isLocked: Boolean,
|
||||
val isLiveTile: Boolean,
|
||||
val remainingAppTimerDuration: Duration?,
|
||||
) : TaskData()
|
||||
}
|
||||
@@ -148,6 +148,7 @@ class TaskViewModel(
|
||||
result?.let {
|
||||
TaskData.Data(
|
||||
taskId = taskId,
|
||||
packageName = result.packageName,
|
||||
title = result.title,
|
||||
titleDescription = result.titleDescription,
|
||||
icon = result.icon,
|
||||
@@ -155,6 +156,7 @@ class TaskViewModel(
|
||||
backgroundColor = result.backgroundColor.removeAlpha(),
|
||||
isLocked = result.isLocked,
|
||||
isLiveTile = isLiveTile && !result.isMinimized,
|
||||
remainingAppTimerDuration = result.remainingAppDuration,
|
||||
)
|
||||
} ?: TaskData.NoData(taskId)
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ import com.android.launcher3.util.SettingsCache;
|
||||
import com.android.quickstep.BaseContainerInterface;
|
||||
import com.android.quickstep.SystemUiProxy;
|
||||
import com.android.quickstep.TaskAnimationManager;
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowManager;
|
||||
import com.android.quickstep.orientation.RecentsPagedOrientationHandler;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -601,7 +601,7 @@ public class RecentsOrientedState implements LauncherPrefChangeListener {
|
||||
*/
|
||||
public DeviceProfile getLauncherDeviceProfile(int displayId) {
|
||||
if (enableOverviewOnConnectedDisplays()) {
|
||||
return RecentsDisplayModel.getINSTANCE().get(mContext).getRecentsWindowManager(
|
||||
return RecentsWindowManager.REPOSITORY_INSTANCE.get(mContext).get(
|
||||
displayId).getDeviceProfile();
|
||||
} else {
|
||||
InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(mContext);
|
||||
|
||||
@@ -89,6 +89,7 @@ import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.LocusId;
|
||||
import android.content.pm.LauncherApps;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BlendMode;
|
||||
@@ -201,6 +202,8 @@ import com.android.quickstep.TopTaskTracker;
|
||||
import com.android.quickstep.ViewUtils;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowFlags;
|
||||
import com.android.quickstep.orientation.RecentsPagedOrientationHandler;
|
||||
import com.android.quickstep.recents.data.AppTimersRepository;
|
||||
import com.android.quickstep.recents.data.AppTimersRepositoryImpl;
|
||||
import com.android.quickstep.recents.data.RecentTasksRepository;
|
||||
import com.android.quickstep.recents.data.RecentsDeviceProfileRepository;
|
||||
import com.android.quickstep.recents.data.RecentsDeviceProfileRepositoryImpl;
|
||||
@@ -906,6 +909,12 @@ public abstract class RecentsView<
|
||||
|
||||
recentsDependencies.provide(RecentsDeviceProfileRepository.class, scopeId,
|
||||
() -> new RecentsDeviceProfileRepositoryImpl(mContainer));
|
||||
|
||||
recentsDependencies.provide(AppTimersRepository.class, scopeId,
|
||||
() -> new AppTimersRepositoryImpl(
|
||||
context.getApplicationContext().getSystemService(LauncherApps.class),
|
||||
recentsDependencies.inject(DispatcherProvider.class, scopeId)
|
||||
));
|
||||
} else {
|
||||
mRecentsViewModel = null;
|
||||
mHelper = null;
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ class QuickstepModelDelegateTest {
|
||||
underTest.mHotseatState.predictor = hotseatPredictor
|
||||
underTest.mWidgetsRecommendationState.predictor = widgetRecommendationPredictor
|
||||
underTest.mModel = LauncherAppState.getInstance(context).model
|
||||
underTest.mDataModel = BgDataModel(WidgetsModel(context))
|
||||
underTest.mDataModel = BgDataModel(WidgetsModel(context), { null })
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ import com.android.launcher3.taskbar.rules.TaskbarUnitTestRule.InjectController
|
||||
import com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR
|
||||
import com.android.launcher3.util.TestUtil
|
||||
import com.android.quickstep.AllAppsActionManager
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel
|
||||
import com.android.quickstep.fallback.window.RecentsWindowManager
|
||||
import com.android.quickstep.input.QuickstepKeyGestureEventsManager
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.ParameterizedType
|
||||
@@ -117,7 +117,7 @@ class TaskbarUnitTestRule(
|
||||
PendingIntent(IIntentSender.Default())
|
||||
},
|
||||
object : TaskbarNavButtonCallbacks {},
|
||||
RecentsDisplayModel.INSTANCE.get(context),
|
||||
RecentsWindowManager.REPOSITORY_INSTANCE.get(context),
|
||||
) {
|
||||
override fun recreateTaskbars() {
|
||||
super.recreateTaskbars()
|
||||
|
||||
+7
-12
@@ -19,6 +19,7 @@ package com.android.quickstep
|
||||
import android.platform.test.flag.junit.SetFlagsRule
|
||||
import android.view.Display.DEFAULT_DISPLAY
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.app.displaylib.DisplayRepository
|
||||
import com.android.launcher3.Flags
|
||||
import com.android.launcher3.util.LauncherMultivalentJUnit
|
||||
import com.android.launcher3.util.TestDispatcherProvider
|
||||
@@ -26,10 +27,10 @@ import com.android.launcher3.util.rule.setFlags
|
||||
import com.android.quickstep.OverviewCommandHelper.CommandInfo
|
||||
import com.android.quickstep.OverviewCommandHelper.CommandInfo.CommandStatus
|
||||
import com.android.quickstep.OverviewCommandHelper.CommandType
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.StandardTestDispatcher
|
||||
@@ -59,22 +60,16 @@ class OverviewCommandHelperTest {
|
||||
|
||||
private var pendingCallbacksWithDelays = mutableListOf<Long>()
|
||||
|
||||
private val recentsDisplayModel: RecentsDisplayModel = mock()
|
||||
private val defaultDisplayResource: RecentsDisplayModel.RecentsDisplayResource = mock()
|
||||
private val secondaryDisplayResource: RecentsDisplayModel.RecentsDisplayResource = mock()
|
||||
private val displayRepository: DisplayRepository = mock()
|
||||
private val executeCommandDisplayIds = mutableListOf<Int>()
|
||||
|
||||
private fun setupDefaultDisplay() {
|
||||
whenever(defaultDisplayResource.displayId).thenReturn(DEFAULT_DISPLAY)
|
||||
whenever(recentsDisplayModel.activeDisplayResources)
|
||||
.thenReturn(listOf(defaultDisplayResource))
|
||||
whenever(displayRepository.displayIds).thenReturn(MutableStateFlow(setOf(DEFAULT_DISPLAY)))
|
||||
}
|
||||
|
||||
private fun setupMultipleDisplays() {
|
||||
whenever(defaultDisplayResource.displayId).thenReturn(DEFAULT_DISPLAY)
|
||||
whenever(secondaryDisplayResource.displayId).thenReturn(1)
|
||||
whenever(recentsDisplayModel.activeDisplayResources)
|
||||
.thenReturn(listOf(defaultDisplayResource, secondaryDisplayResource))
|
||||
whenever(displayRepository.displayIds)
|
||||
.thenReturn(MutableStateFlow(setOf(DEFAULT_DISPLAY, 1)))
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@@ -90,7 +85,7 @@ class OverviewCommandHelperTest {
|
||||
touchInteractionService = mock(),
|
||||
overviewComponentObserver = mock(),
|
||||
dispatcherProvider = TestDispatcherProvider(dispatcher),
|
||||
recentsDisplayModel = recentsDisplayModel,
|
||||
displayRepository = displayRepository,
|
||||
taskbarManager = mock(),
|
||||
taskAnimationManagerRepository = mock(),
|
||||
)
|
||||
|
||||
+1
-31
@@ -16,26 +16,15 @@
|
||||
|
||||
package com.android.quickstep;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.launcher3.dagger.LauncherAppComponent;
|
||||
import com.android.launcher3.dagger.LauncherAppSingleton;
|
||||
import com.android.launcher3.util.AllModulesForTest;
|
||||
import com.android.launcher3.util.LauncherMultivalentJUnit;
|
||||
import com.android.quickstep.fallback.FallbackRecentsView;
|
||||
import com.android.quickstep.fallback.RecentsState;
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowManager;
|
||||
import com.android.quickstep.fallback.window.RecentsWindowSwipeHandler;
|
||||
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Component;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
|
||||
@@ -48,19 +37,9 @@ public class RecentsWindowSwipeHandlerTestCase extends AbsSwipeUpHandlerTestCase
|
||||
RecentsWindowSwipeHandler,
|
||||
FallbackWindowInterface> {
|
||||
|
||||
@Mock private RecentsDisplayModel mRecentsDisplayModel;
|
||||
@Mock private FallbackRecentsView<RecentsWindowManager> mRecentsView;
|
||||
@Mock private RecentsWindowManager mRecentsWindowManager;
|
||||
|
||||
@Before
|
||||
public void setRecentsDisplayModel() {
|
||||
when(mRecentsDisplayModel.getRecentsWindowManager(anyInt()))
|
||||
.thenReturn(mRecentsWindowManager);
|
||||
|
||||
mContext.initDaggerComponent(DaggerRecentsWindowSwipeHandlerTestCase_TestComponent.builder()
|
||||
.bindRecentsDisplayModel(mRecentsDisplayModel));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected RecentsWindowSwipeHandler createSwipeHandler(long touchTimeMs,
|
||||
@@ -70,6 +49,7 @@ public class RecentsWindowSwipeHandlerTestCase extends AbsSwipeUpHandlerTestCase
|
||||
mTaskAnimationManager,
|
||||
mDeviceState,
|
||||
mRotationTouchHelper,
|
||||
mRecentsWindowManager,
|
||||
mGestureState,
|
||||
touchTimeMs,
|
||||
continuingLastGesture,
|
||||
@@ -94,14 +74,4 @@ public class RecentsWindowSwipeHandlerTestCase extends AbsSwipeUpHandlerTestCase
|
||||
protected RecentsState getBaseState() {
|
||||
return RecentsState.BG_LAUNCHER;
|
||||
}
|
||||
|
||||
@LauncherAppSingleton
|
||||
@Component(modules = {AllModulesForTest.class})
|
||||
interface TestComponent extends LauncherAppComponent {
|
||||
@Component.Builder
|
||||
interface Builder extends LauncherAppComponent.Builder {
|
||||
@BindsInstance Builder bindRecentsDisplayModel(RecentsDisplayModel model);
|
||||
@Override LauncherAppComponent build();
|
||||
}
|
||||
}
|
||||
}
|
||||
+109
-14
@@ -20,71 +20,165 @@ import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ShapeDrawable
|
||||
import android.os.UserHandle
|
||||
import android.platform.test.annotations.DisableFlags
|
||||
import android.platform.test.annotations.EnableFlags
|
||||
import android.platform.test.flag.junit.SetFlagsRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.launcher3.Flags
|
||||
import com.android.quickstep.recents.data.FakeAppTimersRepository
|
||||
import com.android.quickstep.recents.data.FakeTasksRepository
|
||||
import com.android.quickstep.recents.domain.model.TaskModel
|
||||
import com.android.systemui.shared.recents.model.Task
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import java.time.Duration
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mockito.anyString
|
||||
import org.mockito.Mockito.spy
|
||||
import org.mockito.Mockito.times
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.kotlin.any
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class GetTaskUseCaseTest {
|
||||
@get:Rule val setFlagsRule = SetFlagsRule()
|
||||
|
||||
private val unconfinedTestDispatcher = UnconfinedTestDispatcher()
|
||||
private val testScope = TestScope(unconfinedTestDispatcher)
|
||||
|
||||
private val tasksRepository = FakeTasksRepository()
|
||||
private val sut = GetTaskUseCase(repository = tasksRepository)
|
||||
private val timersRepository = FakeAppTimersRepository()
|
||||
private val getRemainingAppTimerDurationUseCase =
|
||||
spy(GetRemainingAppTimerDurationUseCase(timersRepository))
|
||||
private val sut =
|
||||
GetTaskUseCase(
|
||||
tasksRepository = tasksRepository,
|
||||
getRemainingAppTimerDurationUseCase = getRemainingAppTimerDurationUseCase,
|
||||
)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
tasksRepository.seedTasks(listOf(TASK_1))
|
||||
timersRepository.setTimer(PACKAGE_1, UserHandle(USER_1), REMAINING_APP_DURATION)
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_REFACTOR_DIGITAL_WELLBEING_TOAST)
|
||||
fun taskNotSeeded_returnsNull() =
|
||||
testScope.runTest {
|
||||
val result = sut.invoke(NOT_FOUND_TASK_ID).firstOrNull()
|
||||
|
||||
assertThat(result).isNull()
|
||||
verify(getRemainingAppTimerDurationUseCase, times(0))
|
||||
.invoke(anyString(), any<UserHandle>())
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_REFACTOR_DIGITAL_WELLBEING_TOAST)
|
||||
fun taskNotVisible_returnsNull() =
|
||||
testScope.runTest {
|
||||
val result = sut.invoke(TASK_1_ID).firstOrNull()
|
||||
|
||||
assertThat(result).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_REFACTOR_DIGITAL_WELLBEING_TOAST)
|
||||
fun taskVisible_returnsData() =
|
||||
testScope.runTest {
|
||||
tasksRepository.setVisibleTasks(setOf(TASK_1_ID))
|
||||
val expectedResult =
|
||||
TaskModel(
|
||||
id = TASK_1_ID,
|
||||
title = "Title $TASK_1_ID",
|
||||
titleDescription = "Content Description $TASK_1_ID",
|
||||
icon = TASK_1_ICON,
|
||||
thumbnail = null,
|
||||
backgroundColor = Color.BLACK,
|
||||
isLocked = false,
|
||||
isMinimized = false,
|
||||
)
|
||||
|
||||
val result = sut.invoke(TASK_1_ID).firstOrNull()
|
||||
assertThat(result).isEqualTo(expectedResult)
|
||||
|
||||
assertThat(result)
|
||||
.isEqualTo(
|
||||
TaskModel(
|
||||
id = TASK_1_ID,
|
||||
packageName = PACKAGE_1,
|
||||
title = "Title $TASK_1_ID",
|
||||
titleDescription = "Content Description $TASK_1_ID",
|
||||
icon = TASK_1_ICON,
|
||||
thumbnail = null,
|
||||
backgroundColor = Color.BLACK,
|
||||
isLocked = false,
|
||||
isMinimized = false,
|
||||
remainingAppDuration = ROUNDED_REMAINING_APP_DURATION,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_REFACTOR_DIGITAL_WELLBEING_TOAST)
|
||||
fun taskVisible_noAppTimer_returnsDataWithoutTimer() =
|
||||
testScope.runTest {
|
||||
tasksRepository.setVisibleTasks(setOf(TASK_1_ID))
|
||||
timersRepository.resetTimer(PACKAGE_1, UserHandle(USER_1))
|
||||
|
||||
val result = sut.invoke(TASK_1_ID).firstOrNull()
|
||||
|
||||
assertThat(result)
|
||||
.isEqualTo(
|
||||
TaskModel(
|
||||
id = TASK_1_ID,
|
||||
packageName = PACKAGE_1,
|
||||
title = "Title $TASK_1_ID",
|
||||
titleDescription = "Content Description $TASK_1_ID",
|
||||
icon = TASK_1_ICON,
|
||||
thumbnail = null,
|
||||
backgroundColor = Color.BLACK,
|
||||
isLocked = false,
|
||||
isMinimized = false,
|
||||
remainingAppDuration = null,
|
||||
)
|
||||
)
|
||||
verify(getRemainingAppTimerDurationUseCase, times(1))
|
||||
.invoke(anyString(), any<UserHandle>())
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_ENABLE_REFACTOR_DIGITAL_WELLBEING_TOAST)
|
||||
fun taskVisible_dwbFlagOff_doesNotFetchTimer() =
|
||||
testScope.runTest {
|
||||
tasksRepository.setVisibleTasks(setOf(TASK_1_ID))
|
||||
|
||||
val result = sut.invoke(TASK_1_ID).firstOrNull()
|
||||
|
||||
assertThat(result)
|
||||
.isEqualTo(
|
||||
TaskModel(
|
||||
id = TASK_1_ID,
|
||||
packageName = PACKAGE_1,
|
||||
title = "Title $TASK_1_ID",
|
||||
titleDescription = "Content Description $TASK_1_ID",
|
||||
icon = TASK_1_ICON,
|
||||
thumbnail = null,
|
||||
backgroundColor = Color.BLACK,
|
||||
isLocked = false,
|
||||
isMinimized = false,
|
||||
remainingAppDuration = null,
|
||||
)
|
||||
)
|
||||
verify(getRemainingAppTimerDurationUseCase, times(0))
|
||||
.invoke(anyString(), any<UserHandle>())
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val NOT_FOUND_TASK_ID = 404
|
||||
private const val TASK_1_ID = 1
|
||||
private const val PACKAGE_1 = "com.test.1"
|
||||
private const val USER_1 = 1
|
||||
private val TASK_1_ICON = ShapeDrawable()
|
||||
private val REMAINING_APP_DURATION = Duration.ofHours(2).plusMillis(10)
|
||||
private val ROUNDED_REMAINING_APP_DURATION = Duration.ofHours(2).plusMinutes(1)
|
||||
private val TASK_1 =
|
||||
Task(
|
||||
Task.TaskKey(
|
||||
@@ -92,7 +186,7 @@ class GetTaskUseCaseTest {
|
||||
/* windowingMode = */ 0,
|
||||
/* intent = */ Intent(),
|
||||
/* sourceComponent = */ ComponentName("", ""),
|
||||
/* userId = */ 0,
|
||||
/* userId = */ USER_1,
|
||||
/* lastActiveTime = */ 2000,
|
||||
)
|
||||
)
|
||||
@@ -104,6 +198,7 @@ class GetTaskUseCaseTest {
|
||||
thumbnail = null
|
||||
isLocked = false
|
||||
isMinimized = false
|
||||
topActivity = ComponentName(PACKAGE_1, "SomeClass")
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -33,6 +33,7 @@ import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.LiveTile
|
||||
import com.android.quickstep.task.thumbnail.TaskThumbnailUiState.Snapshot
|
||||
import com.android.systemui.shared.recents.model.ThumbnailData
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import java.time.Duration
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -191,6 +192,7 @@ class TaskUiStateMapperTest {
|
||||
private companion object {
|
||||
const val TASK_TITLE_DESCRIPTION = "Title Description 1"
|
||||
var TASK_ID = 1
|
||||
var PACKAGE_NAME = "com.test"
|
||||
val TASK_ICON = ShapeDrawable()
|
||||
val TASK_THUMBNAIL = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)
|
||||
val TASK_THUMBNAIL_DATA =
|
||||
@@ -199,6 +201,7 @@ class TaskUiStateMapperTest {
|
||||
val TASK_DATA =
|
||||
TaskData.Data(
|
||||
TASK_ID,
|
||||
packageName = PACKAGE_NAME,
|
||||
title = "Task 1",
|
||||
titleDescription = TASK_TITLE_DESCRIPTION,
|
||||
icon = TASK_ICON,
|
||||
@@ -206,6 +209,7 @@ class TaskUiStateMapperTest {
|
||||
backgroundColor = TASK_BACKGROUND_COLOR,
|
||||
isLocked = false,
|
||||
isLiveTile = false,
|
||||
remainingAppTimerDuration = Duration.ofMillis(30),
|
||||
)
|
||||
}
|
||||
}
|
||||
+12
@@ -35,6 +35,7 @@ import com.android.quickstep.recents.viewmodel.RecentsViewData
|
||||
import com.android.quickstep.views.TaskViewType
|
||||
import com.android.systemui.shared.recents.model.ThumbnailData
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import java.time.Duration
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.flow
|
||||
@@ -320,6 +321,7 @@ class TaskViewModelTest {
|
||||
private fun TaskModel.toUiState(isLiveTile: Boolean = false) =
|
||||
TaskData.Data(
|
||||
taskId = id,
|
||||
packageName = packageName,
|
||||
title = title,
|
||||
titleDescription = titleDescription,
|
||||
icon = icon!!,
|
||||
@@ -327,6 +329,7 @@ class TaskViewModelTest {
|
||||
backgroundColor = backgroundColor,
|
||||
isLocked = isLocked,
|
||||
isLiveTile = isLiveTile,
|
||||
remainingAppTimerDuration = remainingAppDuration,
|
||||
)
|
||||
|
||||
private fun createTaskViewModel(taskViewType: TaskViewType) =
|
||||
@@ -341,6 +344,7 @@ class TaskViewModelTest {
|
||||
)
|
||||
|
||||
private companion object {
|
||||
const val PACKAGE_NAME = "com.test"
|
||||
const val INVALID_TASK_ID = -1
|
||||
const val FLAGS_APPEARANCE_LIGHT_THEME = FLAG_LIGHT_STATUS or FLAG_LIGHT_NAV
|
||||
const val FLAGS_APPEARANCE_DEFAULT = 0
|
||||
@@ -352,6 +356,7 @@ class TaskViewModelTest {
|
||||
val TASK_MODEL_1 =
|
||||
TaskModel(
|
||||
1,
|
||||
PACKAGE_NAME,
|
||||
"Title 1",
|
||||
"Content Description 1",
|
||||
ShapeDrawable(),
|
||||
@@ -359,10 +364,12 @@ class TaskViewModelTest {
|
||||
Color.BLACK,
|
||||
/* isLocked= */ false,
|
||||
/* isMinimized= */ false,
|
||||
/*remainingAppDuration= */ Duration.ofMillis(30),
|
||||
)
|
||||
val TASK_MODEL_2 =
|
||||
TaskModel(
|
||||
2,
|
||||
PACKAGE_NAME,
|
||||
"Title 2",
|
||||
"Content Description 2",
|
||||
ShapeDrawable(),
|
||||
@@ -370,10 +377,12 @@ class TaskViewModelTest {
|
||||
Color.RED,
|
||||
/* isLocked= */ true,
|
||||
/* isMinimized= */ false,
|
||||
/*remainingAppDuration= */ Duration.ofHours(5).plusMinutes(2),
|
||||
)
|
||||
val TASK_MODEL_3 =
|
||||
TaskModel(
|
||||
3,
|
||||
PACKAGE_NAME,
|
||||
"Title 3",
|
||||
"Content Description 3",
|
||||
ShapeDrawable(),
|
||||
@@ -381,10 +390,12 @@ class TaskViewModelTest {
|
||||
Color.BLUE,
|
||||
/* isLocked= */ false,
|
||||
/* isMinimized= */ false,
|
||||
/* remainingAppDuration= */ null,
|
||||
)
|
||||
val TASK_MODEL_MINIMIZED =
|
||||
TaskModel(
|
||||
4,
|
||||
PACKAGE_NAME,
|
||||
"Title 4",
|
||||
"Content Description 4",
|
||||
ShapeDrawable(),
|
||||
@@ -392,6 +403,7 @@ class TaskViewModelTest {
|
||||
Color.BLUE,
|
||||
/* isLocked= */ false,
|
||||
/* isMinimized= */ true,
|
||||
/* remainingAppDuration= */ null,
|
||||
)
|
||||
}
|
||||
}
|
||||
-115
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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.quickstep.recents.window
|
||||
|
||||
import android.graphics.Point
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.platform.test.annotations.EnableFlags
|
||||
import android.platform.test.flag.junit.SetFlagsRule
|
||||
import android.view.Display
|
||||
import android.view.DisplayAdjustments
|
||||
import android.view.Surface
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.SmallTest
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.android.launcher3.Flags.FLAG_ENABLE_FALLBACK_OVERVIEW_IN_WINDOW
|
||||
import com.android.launcher3.Flags.FLAG_ENABLE_LAUNCHER_OVERVIEW_IN_WINDOW
|
||||
import com.android.launcher3.util.SandboxApplication
|
||||
import com.android.launcher3.util.window.CachedDisplayInfo
|
||||
import com.android.quickstep.fallback.window.RecentsDisplayModel
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers.anyInt
|
||||
import org.mockito.kotlin.mock
|
||||
import org.mockito.kotlin.whenever
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@EnableFlags(FLAG_ENABLE_LAUNCHER_OVERVIEW_IN_WINDOW, FLAG_ENABLE_FALLBACK_OVERVIEW_IN_WINDOW)
|
||||
class RecentsDisplayModelTest {
|
||||
@get:Rule val setFlagsRule = SetFlagsRule()
|
||||
@get:Rule val context = SandboxApplication()
|
||||
|
||||
// initiate dagger components for injection
|
||||
private val displayManager: DisplayManager = context.spyService(DisplayManager::class.java)
|
||||
private val display: Display = mock()
|
||||
|
||||
private lateinit var recentsDisplayModel: RecentsDisplayModel
|
||||
|
||||
private val width = 2208
|
||||
private val height = 1840
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
// Mock display
|
||||
val displayInfo = CachedDisplayInfo(Point(width, height), Surface.ROTATION_0)
|
||||
whenever(display.rotation).thenReturn(displayInfo.rotation)
|
||||
whenever(display.displayAdjustments).thenReturn(DisplayAdjustments())
|
||||
|
||||
// Mock displayManager
|
||||
whenever(displayManager.getDisplay(anyInt())).thenReturn(display)
|
||||
|
||||
runOnMainSync { recentsDisplayModel = RecentsDisplayModel.INSTANCE.get(context) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEnsureSingleton() {
|
||||
val recentsDisplayModel2 = RecentsDisplayModel.INSTANCE.get(context)
|
||||
assert(recentsDisplayModel == recentsDisplayModel2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDefaultDisplayCreation() {
|
||||
Assert.assertNotNull(recentsDisplayModel.getRecentsWindowManager(Display.DEFAULT_DISPLAY))
|
||||
Assert.assertNotNull(
|
||||
recentsDisplayModel.getFallbackWindowInterface(Display.DEFAULT_DISPLAY)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCreateSeparateInstances() {
|
||||
val displayId = Display.DEFAULT_DISPLAY + 1
|
||||
runOnMainSync { recentsDisplayModel.storeDisplayResource(displayId) }
|
||||
|
||||
val defaultManager = recentsDisplayModel.getRecentsWindowManager(Display.DEFAULT_DISPLAY)
|
||||
val secondaryManager = recentsDisplayModel.getRecentsWindowManager(displayId)
|
||||
Assert.assertNotSame(defaultManager, secondaryManager)
|
||||
|
||||
val defaultInterface =
|
||||
recentsDisplayModel.getFallbackWindowInterface(Display.DEFAULT_DISPLAY)
|
||||
val secondInterface = recentsDisplayModel.getFallbackWindowInterface(displayId)
|
||||
Assert.assertNotSame(defaultInterface, secondInterface)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDestroy() {
|
||||
Assert.assertNotNull(recentsDisplayModel.getRecentsWindowManager(Display.DEFAULT_DISPLAY))
|
||||
Assert.assertNotNull(
|
||||
recentsDisplayModel.getFallbackWindowInterface(Display.DEFAULT_DISPLAY)
|
||||
)
|
||||
recentsDisplayModel.destroy()
|
||||
Assert.assertNull(recentsDisplayModel.getRecentsWindowManager(Display.DEFAULT_DISPLAY))
|
||||
Assert.assertNull(recentsDisplayModel.getFallbackWindowInterface(Display.DEFAULT_DISPLAY))
|
||||
}
|
||||
|
||||
private fun runOnMainSync(f: Runnable) {
|
||||
InstrumentationRegistry.getInstrumentation().runOnMainSync { f.run() }
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ import com.android.launcher3.dagger.LauncherAppSingleton
|
||||
import com.android.launcher3.util.AllModulesMinusWMProxy
|
||||
import com.android.launcher3.util.TestDispatcherProvider
|
||||
import com.android.launcher3.util.coroutines.DispatcherProvider
|
||||
import com.android.quickstep.recents.data.AppTimersRepository
|
||||
import com.android.quickstep.recents.data.FakeAppTimersRepository
|
||||
import com.android.quickstep.recents.data.FakeRecentsDeviceProfileRepository
|
||||
import com.android.quickstep.recents.data.FakeRecentsRotationStateRepository
|
||||
import com.android.quickstep.recents.data.RecentsDeviceProfileRepository
|
||||
@@ -59,6 +61,8 @@ object TaskViewTestDIHelpers {
|
||||
recentsDependencies
|
||||
.getScope(context)[RecentsDeviceProfileRepository::class.java.simpleName] =
|
||||
FakeRecentsDeviceProfileRepository()
|
||||
recentsDependencies.getScope(context)[AppTimersRepository::class.java.simpleName] =
|
||||
FakeAppTimersRepository()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -1938,8 +1938,12 @@ public class DeviceProfile {
|
||||
} else if (inv.isFixedLandscape) {
|
||||
// Center the QSB vertically with hotseat
|
||||
int hotseatBarBottomPadding = getHotseatBarBottomPadding();
|
||||
int hotseatPlusQSBWidth = getHotseatRequiredWidth();
|
||||
int qsbWidth = getAdditionalQsbSpace();
|
||||
int hotseatPlusQSBWidth = getIconToIconWidthForColumns(inv.numColumns);
|
||||
|
||||
// This is needed because of b/235886078 since QSB needs to span to the icon borders
|
||||
int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx);
|
||||
int qsbWidth = getAdditionalQsbSpace() + iconExtraSpacePx / 2;
|
||||
|
||||
int availableWidthPxForHotseat = availableWidthPx - Math.abs(workspacePadding.width())
|
||||
- Math.abs(cellLayoutPaddingPx.width());
|
||||
int remainingSpaceOnSide = (availableWidthPxForHotseat - hotseatPlusQSBWidth) / 2;
|
||||
|
||||
@@ -2815,11 +2815,15 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
|
||||
* to add an item to one of the workspace screens.
|
||||
*/
|
||||
private void onDropExternal(final int[] touchXY, final CellLayout cellLayout, DragObject d) {
|
||||
final int container = mLauncher.isHotseatLayout(cellLayout)
|
||||
? LauncherSettings.Favorites.CONTAINER_HOTSEAT
|
||||
: LauncherSettings.Favorites.CONTAINER_DESKTOP;
|
||||
if (d.dragInfo instanceof PendingAddShortcutInfo) {
|
||||
WorkspaceItemInfo si = ((PendingAddShortcutInfo) d.dragInfo)
|
||||
.getActivityInfo(mLauncher).createWorkspaceItemInfo();
|
||||
if (si != null) {
|
||||
d.dragInfo = si;
|
||||
si.container = container;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2830,10 +2834,6 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
|
||||
spanX = mDragInfo.spanX;
|
||||
spanY = mDragInfo.spanY;
|
||||
}
|
||||
|
||||
final int container = mLauncher.isHotseatLayout(cellLayout)
|
||||
? LauncherSettings.Favorites.CONTAINER_HOTSEAT
|
||||
: LauncherSettings.Favorites.CONTAINER_DESKTOP;
|
||||
final int screenId = getCellLayoutId(cellLayout);
|
||||
if (!mLauncher.isHotseatLayout(cellLayout)
|
||||
&& screenId != getScreenIdForPageIndex(mCurrentPage)
|
||||
|
||||
@@ -194,8 +194,14 @@ public class SpringAnimationBuilder {
|
||||
|
||||
ValueAnimator animator = ValueAnimator.ofFloat(0, mDuration);
|
||||
animator.setDuration(getDuration()).setInterpolator(LINEAR);
|
||||
animator.addUpdateListener(anim ->
|
||||
property.set(target, getInterpolatedValue(anim.getAnimatedFraction())));
|
||||
animator.addUpdateListener(anim -> {
|
||||
float value = getInterpolatedValue(anim.getAnimatedFraction());
|
||||
if (Float.isNaN(value)) {
|
||||
value = 0f;
|
||||
}
|
||||
property.set(target, value);
|
||||
}
|
||||
);
|
||||
animator.addListener(new AnimationSuccessListener() {
|
||||
@Override
|
||||
public void onAnimationSuccess(Animator animation) {
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.folder
|
||||
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import com.android.launcher3.Utilities
|
||||
import com.android.launcher3.graphics.ShapeDelegate
|
||||
|
||||
/**
|
||||
* Start and End values for revealing [Folder] content and background via Clip Animation. Reveal
|
||||
* Animator defined in [ShapeDelegate].
|
||||
*/
|
||||
data class ClipRevealData(
|
||||
/** is folder opening or closing */
|
||||
val isOpening: Boolean,
|
||||
/** shape to clip folder to */
|
||||
val shapeDelegate: ShapeDelegate,
|
||||
/** area to clip background to when folder is closed */
|
||||
val backgroundStartRect: Rect,
|
||||
/** area to clip background to when folder is open */
|
||||
val backgroundEndRect: Rect,
|
||||
/** area to clip content to when folder is closed */
|
||||
val contentStart: Rect,
|
||||
/** area to clip content to when folder is open */
|
||||
val contentEnd: Rect,
|
||||
/** radius of folder when open */
|
||||
val finalRadius: Float,
|
||||
) {
|
||||
companion object Factory {
|
||||
const val EXTRA_FOLDER_REVEAL_RADIUS_PERCENTAGE = 0.125f
|
||||
|
||||
/** Calculates start and end values for revealing [Folder] background and content */
|
||||
fun Folder.getClipRevealData(
|
||||
shapeDelegate: ShapeDelegate,
|
||||
folderAnimationData: FolderAnimationData,
|
||||
): ClipRevealData {
|
||||
val folderBackground = background as GradientDrawable
|
||||
val deviceProfile = mActivityContext.deviceProfile
|
||||
|
||||
with(folderAnimationData) {
|
||||
// Setup start and end area for revealing Folder background
|
||||
val backgroundStartRect =
|
||||
Rect(
|
||||
previewOffsetX,
|
||||
contentOffsetY,
|
||||
Math.round((previewOffsetX + initialFolderSize)),
|
||||
Math.round((contentOffsetY + initialFolderSize)),
|
||||
)
|
||||
val backgroundEndRect = Rect(0, 0, layoutParams.width, layoutParams.height)
|
||||
val finalBackgroundRadius = folderBackground.cornerRadius
|
||||
|
||||
// Get page for revealing Folder Content
|
||||
var page = if (isOpening) content.currentPage else content.destinationPage
|
||||
if (Utilities.isRtl(context.resources)) {
|
||||
page = (content.pageCount - 1) - page
|
||||
}
|
||||
val pageStart = page * layoutParams.width
|
||||
|
||||
// Setup start and end area for revealing Folder Content
|
||||
val extraRadius =
|
||||
((deviceProfile.folderIconSizePx / initialFolderScale) *
|
||||
EXTRA_FOLDER_REVEAL_RADIUS_PERCENTAGE)
|
||||
.toInt()
|
||||
val contentStart =
|
||||
Rect(
|
||||
(pageStart + (backgroundStartRect.left / initialFolderScale)).toInt() -
|
||||
extraRadius,
|
||||
(backgroundStartRect.top / initialFolderScale).toInt() - extraRadius,
|
||||
(pageStart + (backgroundStartRect.right / initialFolderScale)).toInt() +
|
||||
extraRadius,
|
||||
(backgroundStartRect.bottom / initialFolderScale).toInt() + extraRadius,
|
||||
)
|
||||
val contentEnd =
|
||||
Rect(pageStart, 0, pageStart + layoutParams.width, layoutParams.height)
|
||||
return ClipRevealData(
|
||||
isOpening = folderAnimationData.isOpening,
|
||||
shapeDelegate = shapeDelegate,
|
||||
backgroundStartRect = backgroundStartRect,
|
||||
backgroundEndRect = backgroundEndRect,
|
||||
contentStart = contentStart,
|
||||
contentEnd = contentEnd,
|
||||
finalRadius = finalBackgroundRadius,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ public class ClippedFolderIconLayoutRule {
|
||||
public static final int MAX_NUM_ITEMS_IN_PREVIEW = 4;
|
||||
private static final int MIN_NUM_ITEMS_IN_PREVIEW = 2;
|
||||
|
||||
private static final float MIN_SCALE = 0.44f;
|
||||
private static final float MAX_SCALE = 0.51f;
|
||||
public static final float MIN_SCALE = 0.44f;
|
||||
public static final float MAX_SCALE = 0.51f;
|
||||
|
||||
// TODO: figure out exact radius for different icons
|
||||
private static final float MAX_RADIUS_DILATION = 0.25f;
|
||||
@@ -27,22 +27,34 @@ public class ClippedFolderIconLayoutRule {
|
||||
private float mIconSize;
|
||||
private boolean mIsRtl;
|
||||
private float mBaselineIconScale;
|
||||
private int mNumFolderColumns;
|
||||
|
||||
public void init(int availableSpace, float intrinsicIconSize, boolean rtl) {
|
||||
/**
|
||||
* initialize the layout rule
|
||||
*/
|
||||
public void init(int availableSpace, float intrinsicIconSize, boolean rtl,
|
||||
int numFolderColumns) {
|
||||
mAvailableSpace = availableSpace;
|
||||
mRadius = (
|
||||
Flags.enableLauncherIconShapes()
|
||||
? ITEM_RADIUS_SCALE_FACTOR_SHAPES
|
||||
: ITEM_RADIUS_SCALE_FACTOR
|
||||
) * availableSpace / 2f;
|
||||
? ITEM_RADIUS_SCALE_FACTOR_SHAPES
|
||||
: ITEM_RADIUS_SCALE_FACTOR) * availableSpace / 2f;
|
||||
mIconSize = intrinsicIconSize;
|
||||
mIsRtl = rtl;
|
||||
mBaselineIconScale = availableSpace / intrinsicIconSize;
|
||||
mNumFolderColumns = numFolderColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes positions for icons in Preview.
|
||||
*
|
||||
* @param index index of icon in folder
|
||||
* @param curNumItems current number of preview items
|
||||
* @param params params to update for icon
|
||||
*/
|
||||
public PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems,
|
||||
PreviewItemDrawingParams params) {
|
||||
float totalScale = scaleForItem(curNumItems);
|
||||
float totalScale = scaleForItem(curNumItems, 0);
|
||||
float transX;
|
||||
float transY;
|
||||
|
||||
@@ -72,12 +84,44 @@ public class ClippedFolderIconLayoutRule {
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes positions for icons in folder as part of spring animation. Here both preview icons
|
||||
* and the rest of the content icons are animated along the same grid.
|
||||
*
|
||||
* @param index index of icon in folder
|
||||
* @param numItemsInPage current number of items in page
|
||||
* @param params params to update for icon
|
||||
*/
|
||||
public PreviewItemDrawingParams computeSpringAnimationItemParams(int index, int numItemsInPage,
|
||||
int page, PreviewItemDrawingParams params) {
|
||||
float totalScale = scaleForItem(numItemsInPage, page);
|
||||
float transX;
|
||||
float transY;
|
||||
|
||||
if (numItemsInPage <= MAX_NUM_ITEMS_IN_PREVIEW) {
|
||||
getPosition(index, numItemsInPage, mTmpPoint);
|
||||
} else {
|
||||
getGridPosition(index / mNumFolderColumns, index % mNumFolderColumns, mTmpPoint);
|
||||
}
|
||||
|
||||
transX = mTmpPoint[0];
|
||||
transY = mTmpPoint[1];
|
||||
|
||||
if (params == null) {
|
||||
params = new PreviewItemDrawingParams(transX, transY, totalScale);
|
||||
} else {
|
||||
params.update(transX, transY, totalScale);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds a grid based on the positioning of the items when there are
|
||||
* {@link #MAX_NUM_ITEMS_IN_PREVIEW} in the preview.
|
||||
*
|
||||
* Positions in the grid: 0 1 // 0 is row 0, col 1
|
||||
* 2 3 // 3 is row 1, col 1`
|
||||
* 2 3 // 3 is row 1, col 1`
|
||||
*/
|
||||
private void getGridPosition(int row, int col, float[] result) {
|
||||
// We use position 0 and 3 to calculate the x and y distances between items.
|
||||
@@ -123,13 +167,13 @@ public class ClippedFolderIconLayoutRule {
|
||||
|
||||
float radius = getRadius(curNumItems);
|
||||
double theta = theta0 + index * (2 * Math.PI / curNumItems) * direction;
|
||||
float halfIconSize = (mIconSize * scaleForItem(curNumItems)) / 2;
|
||||
float halfIconSize = (mIconSize * scaleForItem(curNumItems, 0)) / 2;
|
||||
|
||||
// Map the location along the circle, and offset the coordinates to represent the center
|
||||
// of the icon, and to be based from the top / left of the preview area. The y component
|
||||
// is inverted to match the coordinate system.
|
||||
result[0] = mAvailableSpace / 2 + (float) (radius * Math.cos(theta) / 2) - halfIconSize;
|
||||
result[1] = mAvailableSpace / 2 + (float) (- radius * Math.sin(theta) / 2) - halfIconSize;
|
||||
result[1] = mAvailableSpace / 2 + (float) (-radius * Math.sin(theta) / 2) - halfIconSize;
|
||||
}
|
||||
|
||||
private float getRadius(int numItems) {
|
||||
@@ -145,9 +189,17 @@ public class ClippedFolderIconLayoutRule {
|
||||
}
|
||||
}
|
||||
|
||||
public float scaleForItem(int numItems) {
|
||||
/**
|
||||
* Calculate Scale for Preview Icons based on current page and number of items in page.
|
||||
* @param numItems number of items in page
|
||||
* @param page current page of Folder
|
||||
* @return scale for icons in Folder
|
||||
*/
|
||||
public float scaleForItem(int numItems, int page) {
|
||||
float scale;
|
||||
if (numItems <= 3) {
|
||||
if (page > 0) {
|
||||
scale = MIN_SCALE;
|
||||
} else if (numItems <= 3) {
|
||||
scale = MAX_SCALE;
|
||||
} else {
|
||||
scale = MIN_SCALE;
|
||||
|
||||
@@ -76,6 +76,7 @@ import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.DragSource;
|
||||
import com.android.launcher3.DropTarget;
|
||||
import com.android.launcher3.ExtendedEditText;
|
||||
import com.android.launcher3.Flags;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.OnAlarmListener;
|
||||
import com.android.launcher3.R;
|
||||
@@ -88,6 +89,8 @@ import com.android.launcher3.compat.AccessibilityManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.dragndrop.DragController.DragListener;
|
||||
import com.android.launcher3.dragndrop.DragOptions;
|
||||
import com.android.launcher3.graphics.ShapeDelegate;
|
||||
import com.android.launcher3.graphics.ThemeManager;
|
||||
import com.android.launcher3.logger.LauncherAtom.FromState;
|
||||
import com.android.launcher3.logger.LauncherAtom.ToState;
|
||||
import com.android.launcher3.logging.StatsLogManager;
|
||||
@@ -192,6 +195,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
// use mActivityContext.
|
||||
protected LauncherDelegate mLauncherDelegate;
|
||||
protected final ActivityContext mActivityContext;
|
||||
protected FolderAnimationCreator mOpenCloseAnimationManager;
|
||||
|
||||
public FolderInfo mInfo;
|
||||
private CharSequence mFromTitle;
|
||||
@@ -534,6 +538,17 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
replaceFolderWithFinalItem();
|
||||
}
|
||||
});
|
||||
boolean shouldUseSpringMotion = Flags.enableLauncherIconShapes()
|
||||
&& Flags.enableExpressiveFolderExpansion();
|
||||
if (shouldUseSpringMotion) {
|
||||
ShapeDelegate shapeDelegate =
|
||||
ThemeManager.INSTANCE.get(mActivityContext.asContext()).getFolderShape();
|
||||
mOpenCloseAnimationManager = new FolderAnimationSpringBuilderManager(
|
||||
this, shapeDelegate, mLauncherDelegate
|
||||
);
|
||||
} else {
|
||||
mOpenCloseAnimationManager = new FolderAnimationManager(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void reapplyItemInfo() {
|
||||
@@ -718,9 +733,10 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
cancelRunningAnimations();
|
||||
Log.d("b/383526431", "animateOpen: content child count after cancelling"
|
||||
+ " animation: " + mContent.getTotalChildCount());
|
||||
FolderAnimationManager fam = new FolderAnimationManager(this, true /* isOpening */);
|
||||
AnimatorSet anim = fam.getAnimator();
|
||||
anim.addListener(new AnimatorListenerAdapter() {
|
||||
|
||||
AnimatorSet animatorSet = mOpenCloseAnimationManager.createAnimatorSet(true);
|
||||
|
||||
animatorSet.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
mFolderIcon.setIconVisible(false);
|
||||
@@ -751,7 +767,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
// Do not update the flag if we are in drag mode. The flag will be updated, when we
|
||||
// actually drop the icon.
|
||||
final boolean updateAnimationFlag = !mIsDragInProgress;
|
||||
anim.addListener(new AnimatorListenerAdapter() {
|
||||
animatorSet.addListener(new AnimatorListenerAdapter() {
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
@Override
|
||||
@@ -777,12 +793,14 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
// b/282158620 because setCurrentPlayTime() below will start animator, we need to register
|
||||
// {@link AnimatorListener} before it so that {@link AnimatorListener#onAnimationStart} can
|
||||
// be called to register mCurrentAnimator, which will be used to cancel animator
|
||||
addAnimationStartListeners(anim);
|
||||
addAnimationStartListeners(animatorSet);
|
||||
// Because t=0 has the folder match the folder icon, we can skip the
|
||||
// first frame and have the same movement one frame earlier.
|
||||
Log.d("b/311077782", "Folder.animateOpen");
|
||||
anim.setCurrentPlayTime(Math.min(getSingleFrameMs(getContext()), anim.getTotalDuration()));
|
||||
anim.start();
|
||||
animatorSet.setCurrentPlayTime(Math.min(
|
||||
getSingleFrameMs(getContext()), animatorSet.getTotalDuration()));
|
||||
animatorSet.start();
|
||||
|
||||
|
||||
// Make sure the folder picks up the last drag move even if the finger doesn't move.
|
||||
if (mActivityContext.getDragController().isDragging()) {
|
||||
@@ -873,8 +891,9 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
mContent.snapToPageImmediately(mContent.getDestinationPage());
|
||||
|
||||
cancelRunningAnimations();
|
||||
AnimatorSet a = new FolderAnimationManager(this, false /* isOpening */).getAnimator();
|
||||
a.addListener(new AnimatorListenerAdapter() {
|
||||
AnimatorSet animatorSet = mOpenCloseAnimationManager.createAnimatorSet(false);
|
||||
|
||||
animatorSet.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
setWindowInsetsAnimationCallback(null);
|
||||
@@ -891,8 +910,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
mIsAnimatingClosed = false;
|
||||
}
|
||||
});
|
||||
addAnimationStartListeners(a);
|
||||
a.start();
|
||||
addAnimationStartListeners(animatorSet);
|
||||
animatorSet.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1841,7 +1860,6 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
mFolderName = value;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
FolderNameEditText getFolderName() {
|
||||
return mFolderName;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.folder
|
||||
|
||||
import android.animation.AnimatorSet
|
||||
|
||||
interface FolderAnimationCreator {
|
||||
fun createAnimatorSet(isOpening: Boolean): AnimatorSet
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.folder
|
||||
|
||||
import android.graphics.Rect
|
||||
import android.view.View
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.Utilities
|
||||
import com.android.launcher3.folder.FolderAnimationSpringBuilderManager.Companion.getBubbleTextView
|
||||
import com.android.launcher3.folder.FolderAnimationSpringBuilderManager.Companion.getPreviewIconsOnPage
|
||||
import com.android.launcher3.views.BaseDragLayer
|
||||
|
||||
/** Position and Scale values for animating opened/closed [Folder] */
|
||||
data class FolderAnimationData(
|
||||
/** is folder opening or closing */
|
||||
val isOpening: Boolean,
|
||||
/** scale to set folder to */
|
||||
val startScale: Float,
|
||||
/** ratio of folder scale to drag layer scale */
|
||||
val folderScale: Float,
|
||||
/** x distance to translate folder */
|
||||
val xDistance: Float,
|
||||
/** y distance to translate folder */
|
||||
val yDistance: Float,
|
||||
/** change in content area height from scaling */
|
||||
val contentHeightDifference: Float,
|
||||
/** change in preview background radius from scaling */
|
||||
val folderRadiusDifference: Int,
|
||||
/** initial scale of folder icon before animation */
|
||||
val initialFolderScale: Float,
|
||||
/** initial size of preview background before animation */
|
||||
val initialFolderSize: Float,
|
||||
/** initial x offset of folder content */
|
||||
val previewOffsetX: Int,
|
||||
/** scaled offset X for folder preview */
|
||||
val scaledPreviewOffsetX: Int,
|
||||
/** initial y padding of folder content */
|
||||
val contentOffsetY: Int,
|
||||
/** default duration */
|
||||
val defaultDuration: Int,
|
||||
) {
|
||||
|
||||
companion object Factory {
|
||||
fun Folder.getAnimationData(isOpening: Boolean): FolderAnimationData {
|
||||
/** Calculates all values required for Folder Animators. */
|
||||
// Position and Scale values
|
||||
val layoutParams = layoutParams as BaseDragLayer.LayoutParams
|
||||
val previewBackground = folderIcon.mBackground
|
||||
|
||||
// Get items in Preview and their scaling
|
||||
val itemsInPreview: List<View> = getPreviewIconsOnPage(this, 0)
|
||||
val previewScale: Float = folderIcon.layoutRule.scaleForItem(itemsInPreview.size, 0)
|
||||
val previewSize: Float = folderIcon.layoutRule.iconSize * previewScale
|
||||
|
||||
// Get scale and position of FolderIcon relative to DragLayer
|
||||
val folderIconWorkspacePosition = Rect()
|
||||
val scaleRelativeToDragLayer: Float =
|
||||
mActivityContext.dragLayer.getDescendantRectRelativeToSelf(
|
||||
folderIcon,
|
||||
folderIconWorkspacePosition,
|
||||
)
|
||||
val scaledFolderRadius: Int = previewBackground.scaledRadius
|
||||
val baseIconSize: Float = getBubbleTextView(itemsInPreview[0]).iconSize.toFloat()
|
||||
val initialFolderSize = (scaledFolderRadius * 2) * scaleRelativeToDragLayer
|
||||
val initialFolderScale = previewSize / baseIconSize * scaleRelativeToDragLayer
|
||||
|
||||
// Get offsets for Previews and Content
|
||||
val initialPreviewItemOffsetX =
|
||||
if (Utilities.isRtl(context.resources)) {
|
||||
(layoutParams.width * initialFolderScale - initialFolderSize).toInt()
|
||||
} else 0
|
||||
val contentOffsetX = (content.paddingLeft * initialFolderScale).toInt()
|
||||
val contentOffsetY = (content.paddingTop * initialFolderScale).toInt()
|
||||
|
||||
// Get initial position of folder
|
||||
val initialX =
|
||||
((folderIconWorkspacePosition.left +
|
||||
paddingLeft +
|
||||
Math.round(previewBackground.offsetX * scaleRelativeToDragLayer)) -
|
||||
contentOffsetX -
|
||||
initialPreviewItemOffsetX)
|
||||
val initialY =
|
||||
((folderIconWorkspacePosition.top +
|
||||
paddingTop +
|
||||
Math.round(previewBackground.offsetY * scaleRelativeToDragLayer)) -
|
||||
contentOffsetY)
|
||||
|
||||
// Get scaled height of content and radius of background
|
||||
val scaledContentHeight = contentAreaHeight.toFloat() * initialFolderScale
|
||||
val contentHeightDifference = contentAreaHeight.toFloat() - scaledContentHeight
|
||||
val folderRadiusDifference = previewBackground.scaledRadius - previewBackground.radius
|
||||
/**
|
||||
* Background can have a scaled radius in drag and drop mode, so we need to add the
|
||||
* difference to keep the preview items centered.
|
||||
*/
|
||||
return FolderAnimationData(
|
||||
isOpening = isOpening,
|
||||
startScale = if (isOpening) initialFolderScale else 1f,
|
||||
folderScale = initialFolderScale / scaleRelativeToDragLayer,
|
||||
xDistance = (initialX - layoutParams.x).toFloat(),
|
||||
yDistance = (initialY - layoutParams.y).toFloat(),
|
||||
contentHeightDifference = contentHeightDifference,
|
||||
folderRadiusDifference = folderRadiusDifference,
|
||||
initialFolderScale = initialFolderScale,
|
||||
initialFolderSize = initialFolderSize,
|
||||
previewOffsetX = initialPreviewItemOffsetX + contentOffsetX,
|
||||
scaledPreviewOffsetX =
|
||||
(initialPreviewItemOffsetX / scaleRelativeToDragLayer).toInt() +
|
||||
folderRadiusDifference,
|
||||
contentOffsetY = contentOffsetY,
|
||||
defaultDuration =
|
||||
content.resources.getInteger(R.integer.config_materialFolderExpandDuration),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,8 @@ import android.view.View;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.CellLayout;
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
@@ -60,7 +62,7 @@ import java.util.List;
|
||||
* ie. When the user taps on the FolderIcon, we immediately hide the FolderIcon and show the Folder
|
||||
* in its place before starting the animation.
|
||||
*/
|
||||
public class FolderAnimationManager {
|
||||
public class FolderAnimationManager implements FolderAnimationCreator {
|
||||
|
||||
private static final float EXTRA_FOLDER_REVEAL_RADIUS_PERCENTAGE = 0.125F;
|
||||
private static final int FOLDER_NAME_ALPHA_DURATION = 32;
|
||||
@@ -75,7 +77,7 @@ public class FolderAnimationManager {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private final boolean mIsOpening;
|
||||
private boolean mIsOpening;
|
||||
|
||||
private final int mDuration;
|
||||
private final int mDelay;
|
||||
@@ -92,7 +94,7 @@ public class FolderAnimationManager {
|
||||
|
||||
private DeviceProfile mDeviceProfile;
|
||||
|
||||
public FolderAnimationManager(Folder folder, boolean isOpening) {
|
||||
public FolderAnimationManager(Folder folder) {
|
||||
mFolder = folder;
|
||||
mContent = folder.mContent;
|
||||
mFolderBackground = (GradientDrawable) mFolder.getBackground();
|
||||
@@ -104,7 +106,7 @@ public class FolderAnimationManager {
|
||||
mDeviceProfile = folder.mActivityContext.getDeviceProfile();
|
||||
mPreviewVerifier = createFolderGridOrganizer(mDeviceProfile);
|
||||
|
||||
mIsOpening = isOpening;
|
||||
mIsOpening = true;
|
||||
|
||||
Resources res = mContent.getResources();
|
||||
mDuration = res.getInteger(R.integer.config_materialFolderExpandDuration);
|
||||
@@ -130,7 +132,10 @@ public class FolderAnimationManager {
|
||||
/**
|
||||
* Prepares the Folder for animating between open / closed states.
|
||||
*/
|
||||
public AnimatorSet getAnimator() {
|
||||
@NonNull
|
||||
@Override
|
||||
public AnimatorSet createAnimatorSet(boolean isOpening) {
|
||||
mIsOpening = isOpening;
|
||||
final BaseDragLayer.LayoutParams lp =
|
||||
(BaseDragLayer.LayoutParams) mFolder.getLayoutParams();
|
||||
mFolderIcon.getPreviewItemManager().recomputePreviewDrawingParams();
|
||||
@@ -145,7 +150,7 @@ public class FolderAnimationManager {
|
||||
float initialSize = (scaledRadius * 2) * scaleRelativeToDragLayer;
|
||||
|
||||
// Match size/scale of icons in the preview
|
||||
float previewScale = rule.scaleForItem(itemsInPreview.size());
|
||||
float previewScale = rule.scaleForItem(itemsInPreview.size(), 0);
|
||||
float previewSize = rule.getIconSize() * previewScale;
|
||||
float baseIconSize = getBubbleTextView(itemsInPreview.get(0)).getIconSize();
|
||||
float initialScale = previewSize / baseIconSize * scaleRelativeToDragLayer;
|
||||
@@ -385,7 +390,7 @@ public class FolderAnimationManager {
|
||||
cwc.setupLp(v);
|
||||
|
||||
// Match scale of icons in the preview of the items on the first page.
|
||||
float previewScale = rule.scaleForItem(numItemsInFirstPagePreview);
|
||||
float previewScale = rule.scaleForItem(numItemsInFirstPagePreview, 0);
|
||||
float previewSize = rule.getIconSize() * previewScale;
|
||||
float baseIconSize = getBubbleTextView(v).getIconSize();
|
||||
float iconScale = previewSize / baseIconSize;
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.folder
|
||||
|
||||
import android.animation.AnimatorSet
|
||||
import android.view.View
|
||||
import com.android.launcher3.BubbleTextView
|
||||
import com.android.launcher3.Hotseat
|
||||
import com.android.launcher3.Workspace
|
||||
import com.android.launcher3.apppairs.AppPairIcon
|
||||
import com.android.launcher3.folder.ClipRevealData.Factory.getClipRevealData
|
||||
import com.android.launcher3.folder.FolderAnimationData.Factory.getAnimationData
|
||||
import com.android.launcher3.folder.FolderGridOrganizer.createFolderGridOrganizer
|
||||
import com.android.launcher3.folder.IconAnimationData.Factory.getIconAnimationDataList
|
||||
import com.android.launcher3.graphics.ShapeDelegate
|
||||
|
||||
/**
|
||||
* Manages the opening and closing animations for a [Folder].
|
||||
*
|
||||
* All of the animations are done in the Folder. ie. When the user taps on the FolderIcon, we
|
||||
* immediately hide the FolderIcon and show the Folder in its place before starting the animation.
|
||||
*
|
||||
* @param folder the [Folder] to animate open or closed
|
||||
* @param isOpening whether we are opening or closing the [Folder]
|
||||
*/
|
||||
class FolderAnimationSpringBuilderManager(
|
||||
private val folder: Folder,
|
||||
private val shapeDelegate: ShapeDelegate,
|
||||
private val launcherDelegate: LauncherDelegate,
|
||||
) : FolderAnimationCreator {
|
||||
override fun createAnimatorSet(isOpening: Boolean): AnimatorSet {
|
||||
resetLauncherScale(launcherDelegate.launcher?.workspace, launcherDelegate.launcher?.hotseat)
|
||||
val folderAnimData: FolderAnimationData = folder.getAnimationData(isOpening)
|
||||
val clipRevealData: ClipRevealData = folder.getClipRevealData(shapeDelegate, folderAnimData)
|
||||
val iconAnimData: List<IconAnimationData> = folder.getIconAnimationDataList(folderAnimData)
|
||||
return FolderSpringAnimatorSet.build(
|
||||
folder = folder,
|
||||
launcherDelegate = launcherDelegate,
|
||||
folderAnimData = folderAnimData,
|
||||
clipRevealData = clipRevealData,
|
||||
iconAnimData = iconAnimData,
|
||||
)
|
||||
.animatorSet
|
||||
}
|
||||
|
||||
// Folders can exist outside of Launcher (Ex. Transient Taskbar)
|
||||
// So we only apply Launcher effects when we have a Launcher.
|
||||
// We need to reset these values before calculating folder positioning.
|
||||
private fun resetLauncherScale(workspace: Workspace<*>?, hotseat: Hotseat?) {
|
||||
if (hotseat == null || workspace == null) return
|
||||
// Used to match the translation of the scaling between hotseat and workspace.
|
||||
workspace.setPivotToScaleWithSelf(hotseat)
|
||||
// Since we scale down workspace/hotseat when opening folder,
|
||||
// need to have initial values to find starting folder icon location
|
||||
workspace.scaleX = 1f
|
||||
workspace.scaleY = 1f
|
||||
hotseat.scaleX = 1f
|
||||
hotseat.scaleY = 1f
|
||||
}
|
||||
|
||||
companion object {
|
||||
/** Returns the list of "preview items" on {@param page}. */
|
||||
fun getPreviewIconsOnPage(folder: Folder, page: Int): List<View> {
|
||||
return createFolderGridOrganizer(folder.mActivityContext.deviceProfile)
|
||||
.setFolderInfo(folder.mInfo)
|
||||
.previewItemsForPage(page, folder.iconsInReadingOrder)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the [BubbleTextView] from an icon. In some cases the BubbleTextView is the whole
|
||||
* icon itself, while in others it is contained within the view and only serves to store the
|
||||
* title text.
|
||||
*/
|
||||
fun getBubbleTextView(v: View): BubbleTextView {
|
||||
return if (v is AppPairIcon) v.titleTextView else (v as BubbleTextView)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.folder
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.AnimatorListenerAdapter
|
||||
import com.android.launcher3.CellLayout
|
||||
|
||||
class FolderOpenCloseAnimationListener(val folder: Folder, val isOpening: Boolean) :
|
||||
AnimatorListenerAdapter() {
|
||||
// Because {@link #onAnimationStart} and {@link #onAnimationEnd} callbacks are sent to
|
||||
// message queue and executed on separate frame, we should save states in
|
||||
// {@link #onAnimationStart} instead of before creating animator, so that cancelling
|
||||
// animation A and restarting animation B allows A to reset states in
|
||||
// {@link #onAnimationEnd} before B reads new UI state from {@link #onAnimationStart}.
|
||||
|
||||
private var cellLayout: CellLayout? = null
|
||||
private var folderClipChildren = false
|
||||
private var folderClipToPadding = false
|
||||
private var contentClipChildren = false
|
||||
private var contentClipToPadding = false
|
||||
private var cellLayoutClipChildren = false
|
||||
private var cellLayoutClipPadding = false
|
||||
|
||||
override fun onAnimationStart(animator: Animator) {
|
||||
super.onAnimationStart(animator)
|
||||
with(folder) {
|
||||
folderClipChildren = clipChildren
|
||||
folderClipToPadding = clipToPadding
|
||||
contentClipChildren = content.clipChildren
|
||||
contentClipToPadding = content.clipToPadding
|
||||
cellLayout = content.currentCellLayout
|
||||
cellLayoutClipChildren = cellLayout?.clipChildren ?: false
|
||||
cellLayoutClipPadding = cellLayout?.clipToPadding ?: false
|
||||
|
||||
clipChildren = false
|
||||
clipToPadding = false
|
||||
content.clipChildren = false
|
||||
content.clipToPadding = false
|
||||
cellLayout?.clipChildren = false
|
||||
cellLayout?.clipToPadding = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
super.onAnimationEnd(animation)
|
||||
with(folder) {
|
||||
translationX = 0.0f
|
||||
translationY = 0.0f
|
||||
translationZ = 0.0f
|
||||
content.scaleX = 1f
|
||||
content.scaleY = 1f
|
||||
mFooter.scaleX = 1f
|
||||
mFooter.scaleY = 1f
|
||||
mFooter.translationX = 0f
|
||||
folderName.alpha = 1f
|
||||
content.setClipPath(null)
|
||||
setClipPath(null)
|
||||
clipChildren = folderClipChildren
|
||||
clipToPadding = folderClipToPadding
|
||||
content.clipChildren = contentClipChildren
|
||||
content.clipToPadding = contentClipToPadding
|
||||
cellLayout?.clipChildren = cellLayoutClipChildren
|
||||
cellLayout?.clipToPadding = cellLayoutClipPadding
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.folder
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.AnimatorListenerAdapter
|
||||
import android.graphics.Color
|
||||
import com.android.launcher3.views.ScrimView
|
||||
|
||||
class FolderScrimAnimationListener(val scrimView: ScrimView?, val isOpening: Boolean) :
|
||||
AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
super.onAnimationEnd(animation)
|
||||
if (!isOpening) {
|
||||
scrimView?.alpha = 1f
|
||||
scrimView?.setBackgroundColor(Color.TRANSPARENT)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAnimationCancel(animation: Animator) {
|
||||
super.onAnimationCancel(animation)
|
||||
if (!isOpening) {
|
||||
scrimView?.alpha = 1f
|
||||
scrimView?.setBackgroundColor(Color.TRANSPARENT)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,504 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.folder
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.AnimatorListenerAdapter
|
||||
import android.animation.AnimatorSet
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.util.FloatProperty
|
||||
import android.util.Property
|
||||
import android.view.View
|
||||
import androidx.dynamicanimation.animation.DynamicAnimation.MIN_VISIBLE_CHANGE_ALPHA
|
||||
import androidx.dynamicanimation.animation.DynamicAnimation.MIN_VISIBLE_CHANGE_PIXELS
|
||||
import androidx.dynamicanimation.animation.DynamicAnimation.MIN_VISIBLE_CHANGE_SCALE
|
||||
import com.android.launcher3.BubbleTextView
|
||||
import com.android.launcher3.LauncherAnimUtils
|
||||
import com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.Utilities.isDarkTheme
|
||||
import com.android.launcher3.anim.SpringAnimationBuilder
|
||||
import com.android.launcher3.apppairs.AppPairIcon
|
||||
import com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_ITEMS_IN_PREVIEW
|
||||
import com.android.launcher3.util.Themes
|
||||
|
||||
/** Holder for Animators created from [FolderAnimationSpringBuilderManager] */
|
||||
class FolderSpringAnimatorSet(val animatorSet: AnimatorSet) {
|
||||
|
||||
fun start() {
|
||||
animatorSet.start()
|
||||
}
|
||||
|
||||
companion object Factory {
|
||||
private const val LAUNCHER_SCALE = 0.975f
|
||||
private const val FOLDER_NAME_ALPHA_DURATION = 32
|
||||
private const val LARGE_FOLDER_FOOTER_DURATION = 128
|
||||
private const val STIFFNESS_SHAPE_POSITION = 380f
|
||||
private const val DAMPING_SHAPE_POSITION = 0.8f
|
||||
private const val STIFFNESS_ALPHA = 1600f
|
||||
private const val DAMPING_ALPHA = 0.9f
|
||||
private const val STIFFNESS_LAUNCHER_SCRIM = 380f
|
||||
private const val DAMPING_LAUNCHER_SCRIM = 0.98f
|
||||
|
||||
/**
|
||||
* Factory method to take data calculated from [FolderAnimationSpringBuilderManager], and
|
||||
* create a [FolderSpringAnimatorSet] with [SpringAnimationBuilder].
|
||||
*/
|
||||
fun build(
|
||||
folder: Folder,
|
||||
launcherDelegate: LauncherDelegate,
|
||||
folderAnimData: FolderAnimationData,
|
||||
clipRevealData: ClipRevealData,
|
||||
iconAnimData: List<IconAnimationData>,
|
||||
): FolderSpringAnimatorSet {
|
||||
val animatorSet = AnimatorSet()
|
||||
setupFolder(folder, folderAnimData)
|
||||
addFolderScaleAndTranslateAnimators(folder, animatorSet, folderAnimData)
|
||||
addClipRevealAnimators(folder, animatorSet, clipRevealData)
|
||||
addAlphaAndColorAnimators(folder, animatorSet, folderAnimData)
|
||||
addScrimAnimators(
|
||||
folder.context,
|
||||
animatorSet,
|
||||
folderAnimData.isOpening,
|
||||
launcherDelegate,
|
||||
)
|
||||
iconAnimData.forEach { addContentIconAnimators(folder.context, animatorSet, it) }
|
||||
return FolderSpringAnimatorSet(animatorSet)
|
||||
}
|
||||
|
||||
private fun playSpringAnimation(
|
||||
context: Context,
|
||||
animatorSet: AnimatorSet,
|
||||
isOpening: Boolean,
|
||||
startDelay: Int,
|
||||
stiffness: Float,
|
||||
damping: Float,
|
||||
startValue: Float,
|
||||
endValue: Float,
|
||||
minVisibleChange: Float,
|
||||
property: Property<View, Float>,
|
||||
view: View,
|
||||
) {
|
||||
val animatorBuilder =
|
||||
SpringAnimationBuilder(context)
|
||||
.setStiffness(stiffness)
|
||||
.setDampingRatio(damping)
|
||||
.setStartValue(if (isOpening) startValue else endValue)
|
||||
.setEndValue(if (isOpening) endValue else startValue)
|
||||
.setMinimumVisibleChange(minVisibleChange)
|
||||
|
||||
val animator =
|
||||
animatorBuilder.build(view, property as FloatProperty<View>).apply {
|
||||
setStartDelay(startDelay.toLong())
|
||||
}
|
||||
animatorSet.play(animator)
|
||||
}
|
||||
|
||||
private fun setupFolder(folder: Folder, folderAnimationData: FolderAnimationData) {
|
||||
folder.folderIcon.previewItemManager.recomputePreviewDrawingParams()
|
||||
folder.apply {
|
||||
pivotX = 0f
|
||||
pivotY = 0f
|
||||
}
|
||||
folder.content.apply {
|
||||
scaleX = folderAnimationData.startScale
|
||||
scaleY = folderAnimationData.startScale
|
||||
pivotX = 0f
|
||||
pivotY = 0f
|
||||
}
|
||||
folder.mFooter.apply {
|
||||
scaleX = folderAnimationData.startScale
|
||||
scaleY = folderAnimationData.startScale
|
||||
pivotX = 0f
|
||||
pivotY = 0f
|
||||
}
|
||||
}
|
||||
|
||||
private fun addFolderScaleAndTranslateAnimators(
|
||||
folder: Folder,
|
||||
animatorSet: AnimatorSet,
|
||||
animationData: FolderAnimationData,
|
||||
) {
|
||||
val isOpening = animationData.isOpening
|
||||
playSpringAnimation(
|
||||
context = folder.context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = 0,
|
||||
stiffness = STIFFNESS_SHAPE_POSITION,
|
||||
damping = DAMPING_SHAPE_POSITION,
|
||||
startValue = animationData.xDistance,
|
||||
endValue = 0f,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_PIXELS,
|
||||
property = View.TRANSLATION_X,
|
||||
view = folder,
|
||||
)
|
||||
playSpringAnimation(
|
||||
context = folder.context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = 0,
|
||||
stiffness = STIFFNESS_SHAPE_POSITION,
|
||||
damping = DAMPING_SHAPE_POSITION,
|
||||
startValue = animationData.yDistance,
|
||||
endValue = 0f,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_PIXELS,
|
||||
property = View.TRANSLATION_Y,
|
||||
view = folder,
|
||||
)
|
||||
playSpringAnimation(
|
||||
context = folder.context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = 0,
|
||||
stiffness = STIFFNESS_SHAPE_POSITION,
|
||||
damping = DAMPING_SHAPE_POSITION,
|
||||
startValue = animationData.initialFolderScale,
|
||||
endValue = 1f,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_SCALE,
|
||||
property = SCALE_PROPERTY,
|
||||
view = folder.content,
|
||||
)
|
||||
playSpringAnimation(
|
||||
context = folder.context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = 0,
|
||||
stiffness = STIFFNESS_SHAPE_POSITION,
|
||||
damping = DAMPING_SHAPE_POSITION,
|
||||
startValue = animationData.initialFolderScale,
|
||||
endValue = 1f,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_SCALE,
|
||||
property = SCALE_PROPERTY,
|
||||
view = folder.mFooter,
|
||||
)
|
||||
// Translate the footer so that it tracks the bottom of the content.
|
||||
playSpringAnimation(
|
||||
context = folder.context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = 0,
|
||||
stiffness = STIFFNESS_SHAPE_POSITION,
|
||||
damping = DAMPING_SHAPE_POSITION,
|
||||
startValue = -(animationData.contentHeightDifference),
|
||||
endValue = 0f,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_PIXELS,
|
||||
property = View.TRANSLATION_Y,
|
||||
view = folder.mFooter,
|
||||
)
|
||||
|
||||
// Animate the elevation midway so that the shadow is not noticeable in the background.
|
||||
val midDuration = animationData.defaultDuration / 2
|
||||
playSpringAnimation(
|
||||
context = folder.context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = if (animationData.isOpening) midDuration else 0,
|
||||
stiffness = STIFFNESS_SHAPE_POSITION,
|
||||
damping = DAMPING_SHAPE_POSITION,
|
||||
startValue = -folder.elevation,
|
||||
endValue = 0f,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_PIXELS,
|
||||
property = View.TRANSLATION_Z,
|
||||
view = folder,
|
||||
)
|
||||
// store clip variables
|
||||
animatorSet.addListener(
|
||||
FolderOpenCloseAnimationListener(folder, animationData.isOpening)
|
||||
)
|
||||
}
|
||||
|
||||
private fun addAlphaAndColorAnimators(
|
||||
folder: Folder,
|
||||
animatorSet: AnimatorSet,
|
||||
animationData: FolderAnimationData,
|
||||
) {
|
||||
with(folder) {
|
||||
val folderBackground = folder.background as GradientDrawable
|
||||
// Set up the Folder background.
|
||||
val isOpening = animationData.isOpening
|
||||
val initialColor = Themes.getAttrColor(context, R.attr.folderPreviewColor)
|
||||
val finalColor = Themes.getAttrColor(context, R.attr.folderBackgroundColor)
|
||||
folderBackground.mutate()
|
||||
folderBackground.setColor(if (isOpening) initialColor else finalColor)
|
||||
// TODO: convert to spring animation?
|
||||
animatorSet.play(
|
||||
ObjectAnimator.ofArgb(
|
||||
folderBackground,
|
||||
"color",
|
||||
if (isOpening) initialColor else finalColor,
|
||||
if (isOpening) finalColor else initialColor,
|
||||
)
|
||||
.apply { duration = animationData.defaultDuration.toLong() }
|
||||
)
|
||||
|
||||
val footerAlphaDuration: Int
|
||||
var footerStartDelay = 0
|
||||
val isLargeFolder = folder.itemCount > MAX_NUM_ITEMS_IN_PREVIEW
|
||||
if (isLargeFolder) {
|
||||
if (isOpening) {
|
||||
folder.mFooter.alpha = 0f
|
||||
footerAlphaDuration = LARGE_FOLDER_FOOTER_DURATION
|
||||
footerStartDelay = animationData.defaultDuration - footerAlphaDuration
|
||||
}
|
||||
}
|
||||
|
||||
playSpringAnimation(
|
||||
context = folder.context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = if (animationData.isOpening) footerStartDelay else 0,
|
||||
stiffness = STIFFNESS_ALPHA,
|
||||
damping = DAMPING_ALPHA,
|
||||
startValue = 0f,
|
||||
endValue = 1f,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_ALPHA,
|
||||
property = View.ALPHA,
|
||||
view = mFooter,
|
||||
)
|
||||
// Fade in the folder name, as the text can overlap the icons when grid size is
|
||||
// small.
|
||||
folder.folderName.alpha = if (animationData.isOpening) 0f else 1f
|
||||
playSpringAnimation(
|
||||
context = folder.context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = if (animationData.isOpening) FOLDER_NAME_ALPHA_DURATION else 0,
|
||||
stiffness = STIFFNESS_ALPHA,
|
||||
damping = DAMPING_ALPHA,
|
||||
startValue = 0f,
|
||||
endValue = 1f,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_ALPHA,
|
||||
property = View.ALPHA,
|
||||
view = folderName,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addClipRevealAnimators(
|
||||
folder: Folder,
|
||||
animatorSet: AnimatorSet,
|
||||
revealData: ClipRevealData,
|
||||
) {
|
||||
with(revealData) {
|
||||
// Create reveal animator for the folder background
|
||||
animatorSet.play(
|
||||
shapeDelegate.createRevealAnimator(
|
||||
folder,
|
||||
backgroundStartRect,
|
||||
backgroundEndRect,
|
||||
finalRadius,
|
||||
!isOpening,
|
||||
)
|
||||
)
|
||||
// animated contents of folder with the folder background
|
||||
animatorSet.play(
|
||||
shapeDelegate.createRevealAnimator(
|
||||
folder.content,
|
||||
contentStart,
|
||||
contentEnd,
|
||||
finalRadius,
|
||||
!isOpening,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addScrimAnimators(
|
||||
context: Context,
|
||||
animatorSet: AnimatorSet,
|
||||
isOpening: Boolean,
|
||||
launcherDelegate: LauncherDelegate,
|
||||
) {
|
||||
val launcher = launcherDelegate.launcher ?: return
|
||||
val scrimView = launcher.scrimView
|
||||
val workspace = launcher.workspace
|
||||
val hotseat = launcher.hotseat
|
||||
val finalScrimAlpha = if (isDarkTheme(context)) 0.32f else 0.2f
|
||||
scrimView.setBackgroundColor(Color.BLACK)
|
||||
playSpringAnimation(
|
||||
context = context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = 0,
|
||||
stiffness = STIFFNESS_LAUNCHER_SCRIM,
|
||||
damping = DAMPING_LAUNCHER_SCRIM,
|
||||
startValue = 0f,
|
||||
endValue = finalScrimAlpha,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_ALPHA,
|
||||
property = LauncherAnimUtils.VIEW_ALPHA,
|
||||
view = scrimView,
|
||||
)
|
||||
playSpringAnimation(
|
||||
context = context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = 0,
|
||||
stiffness = STIFFNESS_LAUNCHER_SCRIM,
|
||||
damping = DAMPING_LAUNCHER_SCRIM,
|
||||
startValue = 1f,
|
||||
endValue = LAUNCHER_SCALE,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_SCALE,
|
||||
property = SCALE_PROPERTY,
|
||||
view = workspace,
|
||||
)
|
||||
playSpringAnimation(
|
||||
context = context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = 0,
|
||||
stiffness = STIFFNESS_LAUNCHER_SCRIM,
|
||||
damping = DAMPING_LAUNCHER_SCRIM,
|
||||
startValue = 1f,
|
||||
endValue = LAUNCHER_SCALE,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_SCALE,
|
||||
property = SCALE_PROPERTY,
|
||||
view = hotseat,
|
||||
)
|
||||
animatorSet.addListener(FolderScrimAnimationListener(scrimView, isOpening))
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the [BubbleTextView] from an icon. In some cases the BubbleTextView is the whole
|
||||
* icon itself, while in others it is contained within the view and only serves to store the
|
||||
* title text.
|
||||
*/
|
||||
private fun getBubbleTextView(v: View): BubbleTextView {
|
||||
return if (v is AppPairIcon) v.titleTextView else (v as BubbleTextView)
|
||||
}
|
||||
|
||||
private fun addContentIconAnimators(
|
||||
context: Context,
|
||||
animatorSet: AnimatorSet,
|
||||
iconData: IconAnimationData,
|
||||
) {
|
||||
with(iconData) {
|
||||
val titleText = getBubbleTextView(icon)
|
||||
if (isOpening) {
|
||||
titleText.setTextVisibility(false)
|
||||
}
|
||||
val anim =
|
||||
titleText.createTextAlphaAnimator(isOpening).apply {
|
||||
startDelay = (if (isOpening) iconDelay + 100 else iconDelay).toLong()
|
||||
}
|
||||
animatorSet.play(anim)
|
||||
if (!itemsInPreview.contains(icon)) {
|
||||
playSpringAnimation(
|
||||
context = context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = iconDelay,
|
||||
stiffness = STIFFNESS_ALPHA,
|
||||
damping = DAMPING_ALPHA,
|
||||
startValue = 0f,
|
||||
endValue = 1f,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_ALPHA,
|
||||
property = View.ALPHA,
|
||||
view = icon,
|
||||
)
|
||||
}
|
||||
playSpringAnimation(
|
||||
context = context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = iconDelay,
|
||||
stiffness = STIFFNESS_SHAPE_POSITION,
|
||||
damping = DAMPING_SHAPE_POSITION,
|
||||
startValue = xDistance,
|
||||
endValue = 0f,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_PIXELS,
|
||||
property = View.TRANSLATION_X,
|
||||
view = icon,
|
||||
)
|
||||
playSpringAnimation(
|
||||
context = context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = iconDelay,
|
||||
stiffness = STIFFNESS_SHAPE_POSITION,
|
||||
damping = DAMPING_SHAPE_POSITION,
|
||||
startValue = yDistance,
|
||||
endValue = 0f,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_PIXELS,
|
||||
property = View.TRANSLATION_Y,
|
||||
view = icon,
|
||||
)
|
||||
playSpringAnimation(
|
||||
context = context,
|
||||
animatorSet = animatorSet,
|
||||
isOpening = isOpening,
|
||||
startDelay = iconDelay,
|
||||
stiffness = STIFFNESS_SHAPE_POSITION,
|
||||
damping = DAMPING_SHAPE_POSITION,
|
||||
startValue = initialIconScale,
|
||||
endValue = 1f,
|
||||
minVisibleChange = MIN_VISIBLE_CHANGE_SCALE,
|
||||
property = SCALE_PROPERTY,
|
||||
view = icon,
|
||||
)
|
||||
animatorSet.addListener(
|
||||
getIconAnimatorListener(
|
||||
icon = icon,
|
||||
xDistance = xDistance,
|
||||
yDistance = yDistance,
|
||||
initialScale = initialIconScale,
|
||||
itemsInPreview = itemsInPreview,
|
||||
isOpening = isOpening,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getIconAnimatorListener(
|
||||
icon: View,
|
||||
xDistance: Float,
|
||||
yDistance: Float,
|
||||
initialScale: Float,
|
||||
itemsInPreview: List<View>,
|
||||
isOpening: Boolean,
|
||||
) =
|
||||
object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationStart(animation: Animator) {
|
||||
super.onAnimationStart(animation)
|
||||
// Necessary to initialize values here because of the start delay.
|
||||
if (isOpening) {
|
||||
icon.translationX = xDistance
|
||||
icon.translationY = yDistance
|
||||
icon.scaleX = initialScale
|
||||
icon.scaleY = initialScale
|
||||
if (!itemsInPreview.contains(icon)) {
|
||||
icon.alpha = 0f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
super.onAnimationEnd(animation)
|
||||
icon.translationX = 0.0f
|
||||
icon.translationY = 0.0f
|
||||
icon.scaleX = 1f
|
||||
icon.scaleY = 1f
|
||||
if (!itemsInPreview.contains(icon)) {
|
||||
icon.alpha = 1f
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.folder
|
||||
|
||||
import android.view.View
|
||||
import com.android.launcher3.celllayout.CellLayoutLayoutParams
|
||||
import com.android.launcher3.folder.ClippedFolderIconLayoutRule.MAX_NUM_ITEMS_IN_PREVIEW
|
||||
import com.android.launcher3.folder.FolderAnimationSpringBuilderManager.Companion.getBubbleTextView
|
||||
import com.android.launcher3.folder.FolderAnimationSpringBuilderManager.Companion.getPreviewIconsOnPage
|
||||
|
||||
/** Animation Values for animating icons inside Folder Content */
|
||||
data class IconAnimationData(
|
||||
/** icon in folder content to animate */
|
||||
val icon: View,
|
||||
/** delay for animating this icon */
|
||||
val iconDelay: Int,
|
||||
/** icons to display in Folder Preview */
|
||||
val itemsInPreview: List<View>,
|
||||
/** x distance to translate this icon */
|
||||
val xDistance: Float,
|
||||
/** y distance to translate this icon */
|
||||
val yDistance: Float,
|
||||
/** initial scale of this icon when folder is closed */
|
||||
val initialIconScale: Float,
|
||||
/** if folder is opening or closing */
|
||||
val isOpening: Boolean,
|
||||
) {
|
||||
|
||||
companion object Factory {
|
||||
private const val ICON_DELAY_INCREMENT = 5
|
||||
|
||||
/**
|
||||
* Animates the icons within the folder. Icons start at the Preview Icon scale and then are
|
||||
* translated and scaled to the final folder content icon size. Their animations are also
|
||||
* delayed one by one from top left to bottom right.
|
||||
*/
|
||||
fun Folder.getIconAnimationDataList(
|
||||
folderAnimationData: FolderAnimationData
|
||||
): List<IconAnimationData> {
|
||||
val isOpening = folderAnimationData.isOpening
|
||||
// current page data
|
||||
val page = content.currentPage
|
||||
val folderItemsOnPage = getItemsOnPage(page)
|
||||
val numItemsOnPage = folderItemsOnPage.size
|
||||
// layout and preview data
|
||||
val itemsInPreview = getPreviewIconsOnPage(this, page)
|
||||
val shortcutsAndWidgets = content.getPageAt(0)?.shortcutsAndWidgets
|
||||
val mTmpParams = PreviewItemDrawingParams(0f, 0f, 0f)
|
||||
val layoutRule = folderIcon.layoutRule
|
||||
|
||||
// We delay the animation of each icon from top left to bottom right
|
||||
var iconDelay = if (isOpening) 0 else (numItemsOnPage * ICON_DELAY_INCREMENT)
|
||||
val iconDataList = mutableListOf<IconAnimationData>()
|
||||
|
||||
for (i in 0..<numItemsOnPage) {
|
||||
val currentIcon = folderItemsOnPage[i]
|
||||
// Calculate the final values in the LayoutParams.
|
||||
val iconLayoutParams = currentIcon.layoutParams as CellLayoutLayoutParams
|
||||
iconLayoutParams.isLockedToGrid = true
|
||||
shortcutsAndWidgets?.setupLp(currentIcon)
|
||||
|
||||
// Match scale of icons in the preview of the items on the first page.
|
||||
val previewIconScale = layoutRule.scaleForItem(numItemsOnPage, page)
|
||||
val previewIconSize = layoutRule.iconSize * previewIconScale
|
||||
val baseIconSize = getBubbleTextView(currentIcon).iconSize.toFloat()
|
||||
val iconScale = previewIconSize / baseIconSize
|
||||
|
||||
// Scale when folder closed
|
||||
val initialIconScale = iconScale / folderAnimationData.folderScale
|
||||
// Scale when folder open
|
||||
val finalIconScale = 1f
|
||||
// Scale to start with in Animation
|
||||
val startScale = if (isOpening) initialIconScale else finalIconScale
|
||||
currentIcon.scaleX = startScale
|
||||
currentIcon.scaleY = startScale
|
||||
|
||||
val pageLayoutCount =
|
||||
if (numItemsOnPage < MAX_NUM_ITEMS_IN_PREVIEW && page > 0) {
|
||||
// If not on first page, we don't want preview items to position in a
|
||||
// circle.
|
||||
MAX_NUM_ITEMS_IN_PREVIEW
|
||||
} else {
|
||||
numItemsOnPage
|
||||
}
|
||||
// Match positions of the icons in the folder with their positions in the preview
|
||||
layoutRule.computeSpringAnimationItemParams(i, pageLayoutCount, page, mTmpParams)
|
||||
|
||||
// The PreviewLayoutRule assumes that the icon size takes up the entire width so we
|
||||
// offset by the actual size.
|
||||
val iconOffsetX = ((iconLayoutParams.width - baseIconSize) * iconScale).toInt() / 2
|
||||
|
||||
// Calculate positions for each icon
|
||||
val iconPositionX =
|
||||
((mTmpParams.transX - iconOffsetX + folderAnimationData.scaledPreviewOffsetX) /
|
||||
folderAnimationData.folderScale)
|
||||
.toInt()
|
||||
val paddingTop = currentIcon.paddingTop * iconScale
|
||||
val iconPositionY =
|
||||
((mTmpParams.transY + folderAnimationData.folderRadiusDifference - paddingTop) /
|
||||
folderAnimationData.folderScale)
|
||||
.toInt()
|
||||
val xDistance = (iconPositionX - iconLayoutParams.x).toFloat()
|
||||
val yDistance = (iconPositionY - iconLayoutParams.y).toFloat()
|
||||
|
||||
iconDataList.add(
|
||||
IconAnimationData(
|
||||
icon = currentIcon,
|
||||
iconDelay = iconDelay,
|
||||
itemsInPreview = itemsInPreview,
|
||||
xDistance = xDistance,
|
||||
yDistance = yDistance,
|
||||
initialIconScale = initialIconScale,
|
||||
isOpening = isOpening,
|
||||
)
|
||||
)
|
||||
if (isOpening) {
|
||||
iconDelay += ICON_DELAY_INCREMENT
|
||||
} else {
|
||||
iconDelay -= ICON_DELAY_INCREMENT
|
||||
}
|
||||
}
|
||||
return iconDataList
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,8 +159,11 @@ public class PreviewItemManager {
|
||||
|
||||
mIcon.mBackground.setup(mIcon.getContext(), mIcon.mActivity, mIcon, mTotalWidth,
|
||||
mIcon.getPaddingTop());
|
||||
mIcon.mPreviewLayoutRule.init(mIcon.mBackground.previewSize, mIntrinsicIconSize,
|
||||
Utilities.isRtl(mIcon.getResources()));
|
||||
mIcon.mPreviewLayoutRule.init(
|
||||
mIcon.mBackground.previewSize, mIntrinsicIconSize,
|
||||
Utilities.isRtl(mIcon.getResources()),
|
||||
mIcon.mActivity.getDeviceProfile().numFolderColumns
|
||||
);
|
||||
updatePreviewItems(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,13 @@ import android.graphics.RectF
|
||||
import android.graphics.Region
|
||||
import android.graphics.drawable.AdaptiveIconDrawable
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.util.FloatProperty
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.ViewOutlineProvider
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.core.graphics.PathParser
|
||||
import androidx.dynamicanimation.animation.DynamicAnimation.MIN_VISIBLE_CHANGE_SCALE
|
||||
import androidx.graphics.shapes.CornerRounding
|
||||
import androidx.graphics.shapes.Morph
|
||||
import androidx.graphics.shapes.RoundedPolygon
|
||||
@@ -42,6 +44,8 @@ import androidx.graphics.shapes.SvgPathParser
|
||||
import androidx.graphics.shapes.rectangle
|
||||
import androidx.graphics.shapes.toPath
|
||||
import androidx.graphics.shapes.transformed
|
||||
import com.android.launcher3.Flags
|
||||
import com.android.launcher3.anim.SpringAnimationBuilder
|
||||
import com.android.launcher3.icons.GraphicsUtils
|
||||
import com.android.launcher3.views.ClipPathView
|
||||
|
||||
@@ -127,19 +131,25 @@ interface ShapeDelegate {
|
||||
isReversed: Boolean,
|
||||
): ValueAnimator where T : View, T : ClipPathView {
|
||||
val startRadius = (startRect.width() / 2f) * radiusRatio
|
||||
return ClipAnimBuilder(target) { progress, path ->
|
||||
val radius = (1 - progress) * startRadius + progress * endRadius
|
||||
path.addRoundRect(
|
||||
(1 - progress) * startRect.left + progress * endRect.left,
|
||||
(1 - progress) * startRect.top + progress * endRect.top,
|
||||
(1 - progress) * startRect.right + progress * endRect.right,
|
||||
(1 - progress) * startRect.bottom + progress * endRect.bottom,
|
||||
radius,
|
||||
radius,
|
||||
Path.Direction.CW,
|
||||
)
|
||||
}
|
||||
.toAnim(isReversed)
|
||||
val pathProvider = { progress: Float, path: Path ->
|
||||
val radius = (1 - progress) * startRadius + progress * endRadius
|
||||
path.addRoundRect(
|
||||
(1 - progress) * startRect.left + progress * endRect.left,
|
||||
(1 - progress) * startRect.top + progress * endRect.top,
|
||||
(1 - progress) * startRect.right + progress * endRect.right,
|
||||
(1 - progress) * startRect.bottom + progress * endRect.bottom,
|
||||
radius,
|
||||
radius,
|
||||
Path.Direction.CW,
|
||||
)
|
||||
}
|
||||
val shouldUseSpringAnimation =
|
||||
Flags.enableLauncherIconShapes() && Flags.enableExpressiveFolderExpansion()
|
||||
return if (shouldUseSpringAnimation) {
|
||||
ClipSpringAnimBuilder(target, pathProvider).toAnim(isReversed)
|
||||
} else {
|
||||
ClipAnimBuilder(target, pathProvider).toAnim(isReversed)
|
||||
}
|
||||
}
|
||||
|
||||
override fun equals(other: Any?) =
|
||||
@@ -222,8 +232,13 @@ interface ShapeDelegate {
|
||||
cornerR = endRadius,
|
||||
),
|
||||
)
|
||||
|
||||
return ClipAnimBuilder(target, morph::toPath).toAnim(isReversed)
|
||||
val shouldUseSpringAnimation =
|
||||
Flags.enableLauncherIconShapes() && Flags.enableExpressiveFolderExpansion()
|
||||
return if (shouldUseSpringAnimation) {
|
||||
ClipSpringAnimBuilder(target, morph::toPath).toAnim(isReversed)
|
||||
} else {
|
||||
ClipAnimBuilder(target, morph::toPath).toAnim(isReversed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,11 +278,66 @@ interface ShapeDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private class ClipSpringAnimBuilder<T>(val target: T, val pathProvider: (Float, Path) -> Unit) :
|
||||
AnimatorListenerAdapter() where T : View, T : ClipPathView {
|
||||
|
||||
private var oldOutlineProvider: ViewOutlineProvider? = null
|
||||
val path = Path()
|
||||
private val animatorBuilder = SpringAnimationBuilder(target.context)
|
||||
private val progressProperty =
|
||||
object : FloatProperty<ClipSpringAnimBuilder<T>>("progress") {
|
||||
override fun setValue(obj: ClipSpringAnimBuilder<T>, value: Float) {
|
||||
// Don't want to go below 0 or above 1 for progress.
|
||||
val clampedValue = minOf(maxOf(value, 0f), 1f)
|
||||
path.reset()
|
||||
pathProvider.invoke(clampedValue, path)
|
||||
target.setClipPath(path)
|
||||
}
|
||||
|
||||
override fun get(obj: ClipSpringAnimBuilder<T>): Float {
|
||||
return 0f
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAnimationStart(animation: Animator) {
|
||||
target.apply {
|
||||
oldOutlineProvider = outlineProvider
|
||||
outlineProvider = null
|
||||
translationZ = -target.elevation
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
target.apply {
|
||||
translationZ = 0f
|
||||
outlineProvider = oldOutlineProvider
|
||||
}
|
||||
}
|
||||
|
||||
fun toAnim(isReversed: Boolean): ValueAnimator {
|
||||
val mStartValue = if (isReversed) 1f else 0f
|
||||
val mEndValue = if (isReversed) 0f else 1f
|
||||
pathProvider.invoke(mStartValue, path)
|
||||
target.setClipPath(path)
|
||||
val animator =
|
||||
animatorBuilder
|
||||
.setStiffness(SPRING_STIFFNESS_SHAPE_POSITION)
|
||||
.setDampingRatio(SPRING_DAMPING_SHAPE_POSITION)
|
||||
.setStartValue(mStartValue)
|
||||
.setEndValue(mEndValue)
|
||||
.setMinimumVisibleChange(MIN_VISIBLE_CHANGE_SCALE)
|
||||
.build(this, progressProperty)
|
||||
animator.addListener(this)
|
||||
return animator
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "IconShape"
|
||||
const val DEFAULT_PATH_SIZE = 100f
|
||||
const val AREA_CALC_SIZE = 1000
|
||||
private const val SPRING_STIFFNESS_SHAPE_POSITION = 380f
|
||||
private const val SPRING_DAMPING_SHAPE_POSITION = 0.8f
|
||||
// .1% error margin
|
||||
const val AREA_DIFF_THRESHOLD = AREA_CALC_SIZE * AREA_CALC_SIZE / 1000
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.BuildConfig;
|
||||
import com.android.launcher3.Flags;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.dagger.LauncherAppSingleton;
|
||||
@@ -52,6 +53,10 @@ import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.model.data.CollectionInfo;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
import com.android.launcher3.model.repository.HomeScreenRepository;
|
||||
import com.android.launcher3.model.repository.HomeScreenRepository.WorkspaceData.ChangeEvent.AddEvent;
|
||||
import com.android.launcher3.model.repository.HomeScreenRepository.WorkspaceData.ChangeEvent.RemoveEvent;
|
||||
import com.android.launcher3.model.repository.HomeScreenRepository.WorkspaceData.ChangeEvent.UpdateEvent;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.shortcuts.ShortcutKey;
|
||||
import com.android.launcher3.shortcuts.ShortcutRequest;
|
||||
@@ -69,6 +74,7 @@ import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -81,6 +87,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
|
||||
/**
|
||||
* All the data stored in-memory and managed by the LauncherModel
|
||||
@@ -119,6 +126,9 @@ public class BgDataModel {
|
||||
*/
|
||||
public final StringCache stringCache = new StringCache();
|
||||
|
||||
@Nullable
|
||||
private final HomeScreenRepository mRepo;
|
||||
|
||||
/**
|
||||
* Id when the model was last bound
|
||||
*/
|
||||
@@ -132,8 +142,9 @@ public class BgDataModel {
|
||||
&& !enableSmartspaceRemovalToggle();
|
||||
|
||||
@Inject
|
||||
public BgDataModel(WidgetsModel widgetsModel) {
|
||||
public BgDataModel(WidgetsModel widgetsModel, Provider<HomeScreenRepository> homeDataProvider) {
|
||||
this.widgetsModel = widgetsModel;
|
||||
mRepo = Flags.modelRepository() ? homeDataProvider.get() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,13 +199,19 @@ public class BgDataModel {
|
||||
removeItem(context, Arrays.asList(items));
|
||||
}
|
||||
|
||||
public synchronized void removeItem(Context context, List<? extends ItemInfo> items) {
|
||||
public synchronized void removeItem(Context context, Collection<? extends ItemInfo> items) {
|
||||
removeItem(context, items, null);
|
||||
}
|
||||
|
||||
public synchronized void removeItem(Context context, Collection<? extends ItemInfo> items,
|
||||
@Nullable Object owner) {
|
||||
if (BuildConfig.IS_STUDIO_BUILD) {
|
||||
items.stream()
|
||||
.filter(item -> item.itemType == ITEM_TYPE_FOLDER
|
||||
|| item.itemType == ITEM_TYPE_APP_PAIR)
|
||||
.forEach(item -> itemsIdMap.stream()
|
||||
.filter(info -> info.container == item.id)
|
||||
.filter(info -> !items.contains(info))
|
||||
// We are deleting a collection which still contains items that
|
||||
// think they are contained by that collection.
|
||||
.forEach(info -> Log.e(TAG,
|
||||
@@ -205,13 +222,25 @@ public class BgDataModel {
|
||||
items.forEach(item -> itemsIdMap.remove(item.id));
|
||||
items.stream().map(info -> info.user).distinct().forEach(
|
||||
user -> updateShortcutPinnedState(context, user));
|
||||
if (Flags.modelRepository() && mRepo != null) {
|
||||
mRepo.dispatchChange(this, new RemoveEvent(new ArrayList<>(items), owner));
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addItem(Context context, ItemInfo item, boolean newItem) {
|
||||
addItem(context, item, newItem, null);
|
||||
}
|
||||
|
||||
public synchronized void addItem(Context context, ItemInfo item, boolean newItem,
|
||||
@Nullable Object owner) {
|
||||
itemsIdMap.put(item.id, item);
|
||||
if (newItem && item.itemType == ITEM_TYPE_DEEP_SHORTCUT) {
|
||||
updateShortcutPinnedState(context, item.user);
|
||||
}
|
||||
if (Flags.modelRepository() && mRepo != null) {
|
||||
mRepo.dispatchChange(this, new AddEvent(Collections.singletonList(item), owner));
|
||||
}
|
||||
|
||||
if (BuildConfig.IS_DEBUG_DEVICE
|
||||
&& newItem
|
||||
&& item.container != CONTAINER_DESKTOP
|
||||
@@ -222,6 +251,16 @@ public class BgDataModel {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void updateItems(List<ItemInfo> items, @Nullable Object owner) {
|
||||
if (Flags.modelRepository() && mRepo != null) {
|
||||
mRepo.dispatchChange(this, new UpdateEvent(items, owner));
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void dataLoadComplete() {
|
||||
if (Flags.modelRepository() && mRepo != null) mRepo.onNewBind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the deep shortcuts state in system to match out internal model, pinning any missing
|
||||
* shortcuts and unpinning any extra shortcuts.
|
||||
|
||||
@@ -528,6 +528,8 @@ public class LoaderTask implements Runnable {
|
||||
processAppPairItems();
|
||||
|
||||
c.commitRestoredItems();
|
||||
|
||||
mBgDataModel.dataLoadComplete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,8 @@ constructor(
|
||||
if (workspaceUpdates.isNotEmpty()) {
|
||||
scheduleCallbackTask { it.bindItemsUpdated(workspaceUpdates) }
|
||||
}
|
||||
// TODO: Probably duplicate call, verify and remove?
|
||||
dataModel.updateItems(allUpdates.toList(), null)
|
||||
|
||||
// Bind extra items if any
|
||||
allUpdates
|
||||
|
||||
@@ -255,7 +255,7 @@ public class ModelWriter {
|
||||
mModel.getModelDbController().insert(writer.getValues(mContext));
|
||||
synchronized (mBgDataModel) {
|
||||
checkItemInfoLocked(item.id, item, stackTrace);
|
||||
mBgDataModel.addItem(mContext, item, true);
|
||||
mBgDataModel.addItem(mContext, item, true, mOwner);
|
||||
verifier.verifyModel();
|
||||
}
|
||||
}).executeOnModelThread();
|
||||
@@ -292,9 +292,9 @@ public class ModelWriter {
|
||||
enqueueDeleteRunnable(newModelTask(() -> {
|
||||
for (ItemInfo item : items) {
|
||||
mModel.getModelDbController().delete(itemIdMatch(item.id), null);
|
||||
mBgDataModel.removeItem(mContext, item);
|
||||
verifier.verifyModel();
|
||||
}
|
||||
mBgDataModel.removeItem(mContext, items, mOwner);
|
||||
verifier.verifyModel();
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -308,12 +308,13 @@ public class ModelWriter {
|
||||
enqueueDeleteRunnable(newModelTask(() -> {
|
||||
mModel.getModelDbController().delete(
|
||||
Favorites.CONTAINER + "=" + info.id, null);
|
||||
mBgDataModel.removeItem(mContext, info.getContents());
|
||||
info.getContents().clear();
|
||||
|
||||
mModel.getModelDbController().delete(
|
||||
Favorites._ID + "=" + info.id, null);
|
||||
mBgDataModel.removeItem(mContext, info);
|
||||
|
||||
List<ItemInfo> itemsToDelete = new ArrayList<>(info.getContents());
|
||||
itemsToDelete.add(info);
|
||||
mBgDataModel.removeItem(mContext, itemsToDelete, mOwner);
|
||||
verifier.verifyModel();
|
||||
}));
|
||||
}
|
||||
@@ -412,6 +413,7 @@ public class ModelWriter {
|
||||
mModel.getModelDbController().update(
|
||||
mWriter.get().getValues(mContext), itemIdMatch(mItemId), null);
|
||||
updateItemArrays(mItem, mItemId);
|
||||
mBgDataModel.updateItems(Collections.singletonList(mItem), mOwner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,6 +438,7 @@ public class ModelWriter {
|
||||
updateItemArrays(item, itemId);
|
||||
}
|
||||
t.commit();
|
||||
mBgDataModel.updateItems(mItems, mOwner);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.model.repository
|
||||
|
||||
import com.android.launcher3.dagger.LauncherAppSingleton
|
||||
import com.android.launcher3.model.BgDataModel
|
||||
import com.android.launcher3.model.data.ItemInfo
|
||||
import com.android.launcher3.model.repository.HomeScreenRepository.WorkspaceData.ChangeEvent
|
||||
import com.android.launcher3.util.Executors
|
||||
import com.android.launcher3.util.IntSparseArrayMap
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import java.util.function.Consumer
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
|
||||
/**
|
||||
* Repository for the home screen data.
|
||||
*
|
||||
* This class is responsible for holding the current state of the home screen and providing a way to
|
||||
* listen for changes to the data.
|
||||
*/
|
||||
@LauncherAppSingleton
|
||||
class HomeScreenRepository @Inject constructor() {
|
||||
|
||||
/**
|
||||
* Represents the current home screen data model. There are two ways this can change:
|
||||
* 1) The model can be replaced completely with a new data, which can be observed using the
|
||||
* state flow.
|
||||
* 2) Changes can be made to the existing data, the diff can be observed using
|
||||
* [WorkspaceData.updates]
|
||||
*/
|
||||
val workspaceStateFlow = MutableStateFlow(WorkspaceData(IntSparseArrayMap()))
|
||||
|
||||
class WorkspaceData(var itemsIdMap: IntSparseArrayMap<ItemInfo>) {
|
||||
|
||||
val scope = MainScope()
|
||||
|
||||
internal val updateListeners = CopyOnWriteArrayList<Consumer<ChangeEvent>>()
|
||||
|
||||
val updates =
|
||||
callbackFlow<ChangeEvent> {
|
||||
val listener = Consumer<ChangeEvent> { trySend(it) }
|
||||
updateListeners.add(listener)
|
||||
awaitClose { updateListeners.remove(listener) }
|
||||
}
|
||||
|
||||
/** Represents a change being made to the existing workspace data */
|
||||
sealed interface ChangeEvent {
|
||||
// The items being changed
|
||||
val items: List<ItemInfo>
|
||||
|
||||
// The source of the change. If its user driven, it will point to the UI component where
|
||||
// the user is interacting or null if the change was made as a result of some system
|
||||
// event. Clients can use this to exclude self-made changes.
|
||||
val owner: Any?
|
||||
|
||||
/** New items were added to the model */
|
||||
data class AddEvent(override val items: List<ItemInfo>, override val owner: Any?) :
|
||||
ChangeEvent
|
||||
|
||||
/** Some properties of existing items changed */
|
||||
data class UpdateEvent(override val items: List<ItemInfo>, override val owner: Any?) :
|
||||
ChangeEvent
|
||||
|
||||
/** Some items were removed from the model */
|
||||
data class RemoveEvent(override val items: List<ItemInfo>, override val owner: Any?) :
|
||||
ChangeEvent
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to notify that the model data was completely replaced. This is only meant to be used by
|
||||
* the model, clients should just rely on the events provided by the StateFlow
|
||||
*/
|
||||
fun onNewBind(model: BgDataModel) {
|
||||
val items = model.itemsIdMap.clone()
|
||||
|
||||
Executors.MAIN_EXECUTOR.execute {
|
||||
workspaceStateFlow.value.scope.cancel()
|
||||
workspaceStateFlow.value = WorkspaceData(items)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to notify a particular change to the workspace data. This is only meant to be used by
|
||||
* the model, clients should just rely on the events provided by the StateFlow
|
||||
*/
|
||||
fun dispatchChange(model: BgDataModel, event: ChangeEvent) {
|
||||
val items = model.itemsIdMap.clone()
|
||||
Executors.MAIN_EXECUTOR.execute {
|
||||
workspaceStateFlow.value.itemsIdMap = items
|
||||
workspaceStateFlow.value.updateListeners.forEach { it.accept(event) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ class ShortcutsChangedTaskTest {
|
||||
private val mockTaskController: ModelTaskController = mock()
|
||||
private val mockAllApps: AllAppsList = mock()
|
||||
private val mockIconCache: IconCache = mock()
|
||||
private val bgDataModel = BgDataModel(mock())
|
||||
private val bgDataModel = BgDataModel(mock(), mock())
|
||||
|
||||
private val expectedWai =
|
||||
WorkspaceItemInfo().apply {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.launcher3.tapl;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.multiuser.Flags;
|
||||
|
||||
import androidx.test.uiautomator.UiObject2;
|
||||
|
||||
@@ -26,6 +27,7 @@ import androidx.test.uiautomator.UiObject2;
|
||||
public class PrivateSpaceContainer {
|
||||
private static final String PS_HEADER_RES_ID = "ps_header_layout";
|
||||
private static final String INSTALL_APP_TITLE = "Install";
|
||||
private static final String ADD_APP_TITLE = "Add";
|
||||
private static final String DIVIDER_RES_ID = "private_space_divider";
|
||||
|
||||
private final LauncherInstrumentation mLauncher;
|
||||
@@ -62,7 +64,8 @@ public class PrivateSpaceContainer {
|
||||
|
||||
// Assert Install App Item is present in view.
|
||||
private void verifyInstallAppButtonIsPresent() {
|
||||
mAppList.getAppIcon(INSTALL_APP_TITLE);
|
||||
mAppList.getAppIcon(Flags.enableMovingContentIntoPrivateSpace() ? ADD_APP_TITLE :
|
||||
INSTALL_APP_TITLE);
|
||||
}
|
||||
|
||||
// Assert Install App Item is not present in view.
|
||||
|
||||
Reference in new issue
Block a user