Add support for sticky placeholders am: b777d3581c am: 8f2a800d51
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16169736 Change-Id: I6d7b81d1351367f8f3a29072c198185aa55b6d62
This commit is contained in:
@@ -84,6 +84,13 @@ class SplitContainer {
|
||||
return shouldFinishSecondaryWithPrimary || isPlaceholderContainer;
|
||||
}
|
||||
|
||||
static boolean isStickyPlaceholderRule(@NonNull SplitRule splitRule) {
|
||||
if (!(splitRule instanceof SplitPlaceholderRule)) {
|
||||
return false;
|
||||
}
|
||||
return ((SplitPlaceholderRule) splitRule).isSticky();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SplitContainer{"
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package androidx.window.extensions.embedding;
|
||||
|
||||
import static androidx.window.extensions.embedding.SplitContainer.isStickyPlaceholderRule;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.Activity;
|
||||
@@ -460,6 +462,11 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isStickyPlaceholderRule(splitContainer.getSplitRule())) {
|
||||
// The placeholder should remain after it was first shown.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mPresenter.shouldShowSideBySide(splitContainer)) {
|
||||
return false;
|
||||
}
|
||||
@@ -643,6 +650,46 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
||||
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 {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -228,6 +228,9 @@ class TaskFragmentContainer {
|
||||
|
||||
// Finish dependent containers
|
||||
for (TaskFragmentContainer container : mContainersToFinishOnExit) {
|
||||
if (controller.shouldRetainAssociatedContainer(this, container)) {
|
||||
continue;
|
||||
}
|
||||
container.finish(true /* shouldFinishDependent */, presenter,
|
||||
wct, controller);
|
||||
}
|
||||
@@ -235,6 +238,9 @@ class TaskFragmentContainer {
|
||||
|
||||
// Finish associated activities
|
||||
for (Activity activity : mActivitiesToFinishOnExit) {
|
||||
if (controller.shouldRetainAssociatedActivity(this, activity)) {
|
||||
continue;
|
||||
}
|
||||
activity.finish();
|
||||
}
|
||||
mActivitiesToFinishOnExit.clear();
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user