Loading libs/WindowManager/Jetpack/src/androidx/window/extensions/organizer/SplitController.java +22 −23 Original line number Diff line number Diff line Loading @@ -99,39 +99,38 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen @Override public void onTaskFragmentAppeared(@NonNull TaskFragmentAppearedInfo taskFragmentAppearedInfo) { for (TaskFragmentContainer container : mContainers) { if (container.getTaskFragmentToken().equals( taskFragmentAppearedInfo.getTaskFragmentInfo().getFragmentToken())) { container.setInfo(taskFragmentAppearedInfo.getTaskFragmentInfo()); TaskFragmentContainer container = getContainer( taskFragmentAppearedInfo.getTaskFragmentInfo().getFragmentToken()); if (container == null) { return; } } container.setInfo(taskFragmentAppearedInfo.getTaskFragmentInfo()); } @Override public void onTaskFragmentInfoChanged(@NonNull TaskFragmentInfo taskFragmentInfo) { for (TaskFragmentContainer container : mContainers) { if (container.getTaskFragmentToken().equals(taskFragmentInfo.getFragmentToken())) { container.setInfo(taskFragmentInfo); TaskFragmentContainer container = getContainer(taskFragmentInfo.getFragmentToken()); if (container == null) { return; } container.setInfo(taskFragmentInfo); if (taskFragmentInfo.isEmpty()) { cleanupContainer(container, true /* shouldFinishDependent */); updateCallbackIfNecessary(); } return; } } } @Override public void onTaskFragmentVanished(@NonNull TaskFragmentInfo taskFragmentInfo) { for (TaskFragmentContainer container : mContainers) { if (container.getTaskFragmentToken().equals(taskFragmentInfo.getFragmentToken())) { cleanupContainer(container, true /* shouldFinishDependent */); updateCallbackIfNecessary(); TaskFragmentContainer container = getContainer(taskFragmentInfo.getFragmentToken()); if (container == null) { return; } } cleanupContainer(container, true /* shouldFinishDependent */); updateCallbackIfNecessary(); } @Override Loading Loading @@ -480,7 +479,7 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen } @Nullable private TaskFragmentContainer getContainer(@NonNull IBinder fragmentToken) { TaskFragmentContainer getContainer(@NonNull IBinder fragmentToken) { for (TaskFragmentContainer container : mContainers) { if (container.getTaskFragmentToken().equals(fragmentToken)) { return container; Loading libs/WindowManager/Jetpack/src/androidx/window/extensions/organizer/SplitPresenter.java +27 −4 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.Intent; import android.content.res.Configuration; import android.graphics.Rect; import android.os.Bundle; import android.os.IBinder; import android.window.TaskFragmentCreationParams; import android.window.WindowContainerTransaction; Loading Loading @@ -98,8 +99,6 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { final Rect parentBounds = getParentContainerBounds(primaryActivity); final Rect primaryRectBounds = getBoundsForPosition(POSITION_LEFT, parentBounds, rule); final Rect secondaryRectBounds = getBoundsForPosition(POSITION_RIGHT, parentBounds, rule); TaskFragmentContainer primaryContainer = mController.getContainerWithActivity( primaryActivity.getActivityToken()); if (primaryContainer == null) { Loading @@ -115,10 +114,13 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { wct.reparentActivityToTaskFragment(primaryContainer.getTaskFragmentToken(), primaryActivity.getActivityToken()); primaryContainer.setLastRequestedBounds(primaryRectBounds); } else { resizeTaskFragmentIfRegistered(wct, primaryContainer, primaryRectBounds); } final Rect secondaryRectBounds = getBoundsForPosition(POSITION_RIGHT, parentBounds, rule); TaskFragmentContainer secondaryContainer = mController.getContainerWithActivity( secondaryActivity.getActivityToken()); if (secondaryContainer == null || secondaryContainer == primaryContainer) { Loading @@ -134,6 +136,8 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { wct.reparentActivityToTaskFragment(secondaryContainer.getTaskFragmentToken(), secondaryActivity.getActivityToken()); secondaryContainer.setLastRequestedBounds(secondaryRectBounds); } else { resizeTaskFragmentIfRegistered(wct, secondaryContainer, secondaryRectBounds); } Loading Loading @@ -177,6 +181,9 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { activityIntent, activityOptions); primaryContainer.setLastRequestedBounds(primaryRectBounds); secondaryContainer.setLastRequestedBounds(secondaryRectBounds); // TODO(b/190433398): The primary container and the secondary container should also be set // as adjacent (WCT#setAdjacentRoots) to make activities behind invisible. Loading @@ -199,7 +206,6 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { final Rect primaryRectBounds = getBoundsForPosition(POSITION_LEFT, parentBounds, rule); final Rect secondaryRectBounds = getBoundsForPosition(POSITION_RIGHT, parentBounds, rule); // TODO(b/190433398): Check if the bounds actually changed. // If the task fragments are not registered yet, the positions will be updated after they // are created again. resizeTaskFragmentIfRegistered(wct, splitContainer.getPrimaryContainer(), Loading @@ -219,10 +225,27 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { if (container.getInfo() == null) { return; } // TODO(b/190433398): Check if the bounds actually changed. resizeTaskFragment(wct, container.getTaskFragmentToken(), bounds); } @Override void resizeTaskFragment(@NonNull WindowContainerTransaction wct, @NonNull IBinder fragmentToken, @Nullable Rect bounds) { TaskFragmentContainer container = mController.getContainer(fragmentToken); if (container == null) { throw new IllegalStateException( "Resizing a task fragment that is not registered with controller."); } if (container.areLastRequestedBoundsEqual(bounds)) { // Return early if the provided bounds were already requested return; } container.setLastRequestedBounds(bounds); super.resizeTaskFragment(wct, fragmentToken, bounds); } boolean shouldShowSideBySide(@NonNull SplitContainer splitContainer) { final Rect parentBounds = getParentContainerBounds(splitContainer.getPrimaryContainer()); return shouldShowSideBySide(parentBounds, splitContainer.getSplitPairRule()); Loading libs/WindowManager/Jetpack/src/androidx/window/extensions/organizer/TaskFragmentContainer.java +25 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.app.Activity; import android.app.ActivityThread; import android.graphics.Rect; import android.os.Binder; import android.os.IBinder; import android.window.TaskFragmentInfo; Loading Loading @@ -59,6 +60,11 @@ class TaskFragmentContainer { /** Indicates whether the container was cleaned up after the last activity was removed. */ private boolean mIsFinished; /** * Bounds that were requested last via {@link android.window.WindowContainerTransaction}. */ private final Rect mLastRequestedBounds = new Rect(); /** * Creates a container with an existing activity that will be re-parented to it in a window * container transaction. Loading Loading @@ -199,4 +205,23 @@ class TaskFragmentContainer { boolean isFinished() { return mIsFinished; } /** * Checks if last requested bounds are equal to the provided value. */ boolean areLastRequestedBoundsEqual(@Nullable Rect bounds) { return (bounds == null && mLastRequestedBounds.isEmpty()) || mLastRequestedBounds.equals(bounds); } /** * Updates the last requested bounds. */ void setLastRequestedBounds(@Nullable Rect bounds) { if (bounds == null) { mLastRequestedBounds.setEmpty(); } else { mLastRequestedBounds.set(bounds); } } } Loading
libs/WindowManager/Jetpack/src/androidx/window/extensions/organizer/SplitController.java +22 −23 Original line number Diff line number Diff line Loading @@ -99,39 +99,38 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen @Override public void onTaskFragmentAppeared(@NonNull TaskFragmentAppearedInfo taskFragmentAppearedInfo) { for (TaskFragmentContainer container : mContainers) { if (container.getTaskFragmentToken().equals( taskFragmentAppearedInfo.getTaskFragmentInfo().getFragmentToken())) { container.setInfo(taskFragmentAppearedInfo.getTaskFragmentInfo()); TaskFragmentContainer container = getContainer( taskFragmentAppearedInfo.getTaskFragmentInfo().getFragmentToken()); if (container == null) { return; } } container.setInfo(taskFragmentAppearedInfo.getTaskFragmentInfo()); } @Override public void onTaskFragmentInfoChanged(@NonNull TaskFragmentInfo taskFragmentInfo) { for (TaskFragmentContainer container : mContainers) { if (container.getTaskFragmentToken().equals(taskFragmentInfo.getFragmentToken())) { container.setInfo(taskFragmentInfo); TaskFragmentContainer container = getContainer(taskFragmentInfo.getFragmentToken()); if (container == null) { return; } container.setInfo(taskFragmentInfo); if (taskFragmentInfo.isEmpty()) { cleanupContainer(container, true /* shouldFinishDependent */); updateCallbackIfNecessary(); } return; } } } @Override public void onTaskFragmentVanished(@NonNull TaskFragmentInfo taskFragmentInfo) { for (TaskFragmentContainer container : mContainers) { if (container.getTaskFragmentToken().equals(taskFragmentInfo.getFragmentToken())) { cleanupContainer(container, true /* shouldFinishDependent */); updateCallbackIfNecessary(); TaskFragmentContainer container = getContainer(taskFragmentInfo.getFragmentToken()); if (container == null) { return; } } cleanupContainer(container, true /* shouldFinishDependent */); updateCallbackIfNecessary(); } @Override Loading Loading @@ -480,7 +479,7 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen } @Nullable private TaskFragmentContainer getContainer(@NonNull IBinder fragmentToken) { TaskFragmentContainer getContainer(@NonNull IBinder fragmentToken) { for (TaskFragmentContainer container : mContainers) { if (container.getTaskFragmentToken().equals(fragmentToken)) { return container; Loading
libs/WindowManager/Jetpack/src/androidx/window/extensions/organizer/SplitPresenter.java +27 −4 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.Intent; import android.content.res.Configuration; import android.graphics.Rect; import android.os.Bundle; import android.os.IBinder; import android.window.TaskFragmentCreationParams; import android.window.WindowContainerTransaction; Loading Loading @@ -98,8 +99,6 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { final Rect parentBounds = getParentContainerBounds(primaryActivity); final Rect primaryRectBounds = getBoundsForPosition(POSITION_LEFT, parentBounds, rule); final Rect secondaryRectBounds = getBoundsForPosition(POSITION_RIGHT, parentBounds, rule); TaskFragmentContainer primaryContainer = mController.getContainerWithActivity( primaryActivity.getActivityToken()); if (primaryContainer == null) { Loading @@ -115,10 +114,13 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { wct.reparentActivityToTaskFragment(primaryContainer.getTaskFragmentToken(), primaryActivity.getActivityToken()); primaryContainer.setLastRequestedBounds(primaryRectBounds); } else { resizeTaskFragmentIfRegistered(wct, primaryContainer, primaryRectBounds); } final Rect secondaryRectBounds = getBoundsForPosition(POSITION_RIGHT, parentBounds, rule); TaskFragmentContainer secondaryContainer = mController.getContainerWithActivity( secondaryActivity.getActivityToken()); if (secondaryContainer == null || secondaryContainer == primaryContainer) { Loading @@ -134,6 +136,8 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { wct.reparentActivityToTaskFragment(secondaryContainer.getTaskFragmentToken(), secondaryActivity.getActivityToken()); secondaryContainer.setLastRequestedBounds(secondaryRectBounds); } else { resizeTaskFragmentIfRegistered(wct, secondaryContainer, secondaryRectBounds); } Loading Loading @@ -177,6 +181,9 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { activityIntent, activityOptions); primaryContainer.setLastRequestedBounds(primaryRectBounds); secondaryContainer.setLastRequestedBounds(secondaryRectBounds); // TODO(b/190433398): The primary container and the secondary container should also be set // as adjacent (WCT#setAdjacentRoots) to make activities behind invisible. Loading @@ -199,7 +206,6 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { final Rect primaryRectBounds = getBoundsForPosition(POSITION_LEFT, parentBounds, rule); final Rect secondaryRectBounds = getBoundsForPosition(POSITION_RIGHT, parentBounds, rule); // TODO(b/190433398): Check if the bounds actually changed. // If the task fragments are not registered yet, the positions will be updated after they // are created again. resizeTaskFragmentIfRegistered(wct, splitContainer.getPrimaryContainer(), Loading @@ -219,10 +225,27 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { if (container.getInfo() == null) { return; } // TODO(b/190433398): Check if the bounds actually changed. resizeTaskFragment(wct, container.getTaskFragmentToken(), bounds); } @Override void resizeTaskFragment(@NonNull WindowContainerTransaction wct, @NonNull IBinder fragmentToken, @Nullable Rect bounds) { TaskFragmentContainer container = mController.getContainer(fragmentToken); if (container == null) { throw new IllegalStateException( "Resizing a task fragment that is not registered with controller."); } if (container.areLastRequestedBoundsEqual(bounds)) { // Return early if the provided bounds were already requested return; } container.setLastRequestedBounds(bounds); super.resizeTaskFragment(wct, fragmentToken, bounds); } boolean shouldShowSideBySide(@NonNull SplitContainer splitContainer) { final Rect parentBounds = getParentContainerBounds(splitContainer.getPrimaryContainer()); return shouldShowSideBySide(parentBounds, splitContainer.getSplitPairRule()); Loading
libs/WindowManager/Jetpack/src/androidx/window/extensions/organizer/TaskFragmentContainer.java +25 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.app.Activity; import android.app.ActivityThread; import android.graphics.Rect; import android.os.Binder; import android.os.IBinder; import android.window.TaskFragmentInfo; Loading Loading @@ -59,6 +60,11 @@ class TaskFragmentContainer { /** Indicates whether the container was cleaned up after the last activity was removed. */ private boolean mIsFinished; /** * Bounds that were requested last via {@link android.window.WindowContainerTransaction}. */ private final Rect mLastRequestedBounds = new Rect(); /** * Creates a container with an existing activity that will be re-parented to it in a window * container transaction. Loading Loading @@ -199,4 +205,23 @@ class TaskFragmentContainer { boolean isFinished() { return mIsFinished; } /** * Checks if last requested bounds are equal to the provided value. */ boolean areLastRequestedBoundsEqual(@Nullable Rect bounds) { return (bounds == null && mLastRequestedBounds.isEmpty()) || mLastRequestedBounds.equals(bounds); } /** * Updates the last requested bounds. */ void setLastRequestedBounds(@Nullable Rect bounds) { if (bounds == null) { mLastRequestedBounds.setEmpty(); } else { mLastRequestedBounds.set(bounds); } } }