Add support for sticky placeholders am: b777d3581c
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16169736 Change-Id: Ifafdb32ba32de01702b75db6b9abcef6d305f754
This commit is contained in:
@@ -84,6 +84,13 @@ class SplitContainer {
|
|||||||
return shouldFinishSecondaryWithPrimary || isPlaceholderContainer;
|
return shouldFinishSecondaryWithPrimary || isPlaceholderContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean isStickyPlaceholderRule(@NonNull SplitRule splitRule) {
|
||||||
|
if (!(splitRule instanceof SplitPlaceholderRule)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return ((SplitPlaceholderRule) splitRule).isSticky();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SplitContainer{"
|
return "SplitContainer{"
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package androidx.window.extensions.embedding;
|
package androidx.window.extensions.embedding;
|
||||||
|
|
||||||
|
import static androidx.window.extensions.embedding.SplitContainer.isStickyPlaceholderRule;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@@ -460,6 +462,11 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isStickyPlaceholderRule(splitContainer.getSplitRule())) {
|
||||||
|
// The placeholder should remain after it was first shown.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (mPresenter.shouldShowSideBySide(splitContainer)) {
|
if (mPresenter.shouldShowSideBySide(splitContainer)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -643,6 +650,46 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the associated container should be destroyed together with a finishing
|
||||||
|
* container. There is a case when primary containers for placeholders should be retained
|
||||||
|
* despite the rule configuration to finish primary with secondary - if they are marked as
|
||||||
|
* 'sticky' and the placeholder was finished when fully overlapping the primary container.
|
||||||
|
* @return {@code true} if the associated container should be retained (and not be finished).
|
||||||
|
*/
|
||||||
|
boolean shouldRetainAssociatedContainer(@NonNull TaskFragmentContainer finishingContainer,
|
||||||
|
@NonNull TaskFragmentContainer associatedContainer) {
|
||||||
|
SplitContainer splitContainer = getActiveSplitForContainers(associatedContainer,
|
||||||
|
finishingContainer);
|
||||||
|
if (splitContainer == null) {
|
||||||
|
// Containers are not in the same split, no need to retain.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isStickyPlaceholderRule(splitContainer.getSplitRule())) {
|
||||||
|
// Currently only the containers associated with sticky placeholders can be retained.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When sticky placeholder is stacked on top of the main container it should not cause the
|
||||||
|
// destruction of the primary one.
|
||||||
|
return !mPresenter.shouldShowSideBySide(splitContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see #shouldRetainAssociatedContainer(TaskFragmentContainer, TaskFragmentContainer)
|
||||||
|
*/
|
||||||
|
boolean shouldRetainAssociatedActivity(@NonNull TaskFragmentContainer finishingContainer,
|
||||||
|
@NonNull Activity associatedActivity) {
|
||||||
|
TaskFragmentContainer associatedContainer = getContainerWithActivity(
|
||||||
|
associatedActivity.getActivityToken());
|
||||||
|
if (associatedContainer == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return shouldRetainAssociatedContainer(finishingContainer, associatedContainer);
|
||||||
|
}
|
||||||
|
|
||||||
private final class LifecycleCallbacks implements ActivityLifecycleCallbacks {
|
private final class LifecycleCallbacks implements ActivityLifecycleCallbacks {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -228,6 +228,9 @@ class TaskFragmentContainer {
|
|||||||
|
|
||||||
// Finish dependent containers
|
// Finish dependent containers
|
||||||
for (TaskFragmentContainer container : mContainersToFinishOnExit) {
|
for (TaskFragmentContainer container : mContainersToFinishOnExit) {
|
||||||
|
if (controller.shouldRetainAssociatedContainer(this, container)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
container.finish(true /* shouldFinishDependent */, presenter,
|
container.finish(true /* shouldFinishDependent */, presenter,
|
||||||
wct, controller);
|
wct, controller);
|
||||||
}
|
}
|
||||||
@@ -235,6 +238,9 @@ class TaskFragmentContainer {
|
|||||||
|
|
||||||
// Finish associated activities
|
// Finish associated activities
|
||||||
for (Activity activity : mActivitiesToFinishOnExit) {
|
for (Activity activity : mActivitiesToFinishOnExit) {
|
||||||
|
if (controller.shouldRetainAssociatedActivity(this, activity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
activity.finish();
|
activity.finish();
|
||||||
}
|
}
|
||||||
mActivitiesToFinishOnExit.clear();
|
mActivitiesToFinishOnExit.clear();
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user