Merge "Do not override animation when the parent bounds doesn't support split" into sc-v2-dev
This commit is contained in:
@@ -79,22 +79,23 @@ class JetpackTaskFragmentOrganizer extends TaskFragmentOrganizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerOrganizer() {
|
public void unregisterOrganizer() {
|
||||||
if (mAnimationController != null) {
|
stopOverrideSplitAnimation();
|
||||||
throw new IllegalStateException("Must unregister the organizer before re-register.");
|
mAnimationController = null;
|
||||||
|
super.unregisterOrganizer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void startOverrideSplitAnimation() {
|
||||||
|
if (mAnimationController == null) {
|
||||||
|
mAnimationController = new TaskFragmentAnimationController(this);
|
||||||
}
|
}
|
||||||
super.registerOrganizer();
|
|
||||||
mAnimationController = new TaskFragmentAnimationController(this);
|
|
||||||
mAnimationController.registerRemoteAnimations();
|
mAnimationController.registerRemoteAnimations();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
void stopOverrideSplitAnimation() {
|
||||||
public void unregisterOrganizer() {
|
|
||||||
if (mAnimationController != null) {
|
if (mAnimationController != null) {
|
||||||
mAnimationController.unregisterRemoteAnimations();
|
mAnimationController.unregisterRemoteAnimations();
|
||||||
mAnimationController = null;
|
|
||||||
}
|
}
|
||||||
super.unregisterOrganizer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import android.app.Instrumentation;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@@ -63,6 +64,9 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
|||||||
private @NonNull Consumer<List<SplitInfo>> mEmbeddingCallback;
|
private @NonNull Consumer<List<SplitInfo>> mEmbeddingCallback;
|
||||||
private final List<SplitInfo> mLastReportedSplitStates = new ArrayList<>();
|
private final List<SplitInfo> mLastReportedSplitStates = new ArrayList<>();
|
||||||
|
|
||||||
|
// We currently only support split activity embedding within the one root Task.
|
||||||
|
private final Rect mParentBounds = new Rect();
|
||||||
|
|
||||||
public SplitController() {
|
public SplitController() {
|
||||||
mPresenter = new SplitPresenter(new MainThreadExecutor(), this);
|
mPresenter = new SplitPresenter(new MainThreadExecutor(), this);
|
||||||
ActivityThread activityThread = ActivityThread.currentActivityThread();
|
ActivityThread activityThread = ActivityThread.currentActivityThread();
|
||||||
@@ -79,6 +83,7 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
|||||||
public void setEmbeddingRules(@NonNull Set<EmbeddingRule> rules) {
|
public void setEmbeddingRules(@NonNull Set<EmbeddingRule> rules) {
|
||||||
mSplitRules.clear();
|
mSplitRules.clear();
|
||||||
mSplitRules.addAll(rules);
|
mSplitRules.addAll(rules);
|
||||||
|
updateAnimationOverride();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -158,6 +163,7 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
|||||||
@Override
|
@Override
|
||||||
public void onTaskFragmentParentInfoChanged(@NonNull IBinder fragmentToken,
|
public void onTaskFragmentParentInfoChanged(@NonNull IBinder fragmentToken,
|
||||||
@NonNull Configuration parentConfig) {
|
@NonNull Configuration parentConfig) {
|
||||||
|
onParentBoundsMayChange(parentConfig.windowConfiguration.getBounds());
|
||||||
TaskFragmentContainer container = getContainer(fragmentToken);
|
TaskFragmentContainer container = getContainer(fragmentToken);
|
||||||
if (container != null) {
|
if (container != null) {
|
||||||
mPresenter.updateContainer(container);
|
mPresenter.updateContainer(container);
|
||||||
@@ -165,6 +171,51 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onParentBoundsMayChange(Activity activity) {
|
||||||
|
if (activity.isFinishing()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
onParentBoundsMayChange(mPresenter.getParentContainerBounds(activity));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onParentBoundsMayChange(Rect parentBounds) {
|
||||||
|
if (!parentBounds.isEmpty() && !mParentBounds.equals(parentBounds)) {
|
||||||
|
mParentBounds.set(parentBounds);
|
||||||
|
updateAnimationOverride();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates if we should override transition animation. We only want to override if the Task
|
||||||
|
* bounds is large enough for at least one split rule.
|
||||||
|
*/
|
||||||
|
private void updateAnimationOverride() {
|
||||||
|
if (mParentBounds.isEmpty()) {
|
||||||
|
// We don't know about the parent bounds yet.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the parent container bounds can support any split rule.
|
||||||
|
boolean supportSplit = false;
|
||||||
|
for (EmbeddingRule rule : mSplitRules) {
|
||||||
|
if (!(rule instanceof SplitRule)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (mPresenter.shouldShowSideBySide(mParentBounds, (SplitRule) rule)) {
|
||||||
|
supportSplit = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We only want to override if it supports split.
|
||||||
|
if (supportSplit) {
|
||||||
|
mPresenter.startOverrideSplitAnimation();
|
||||||
|
} else {
|
||||||
|
mPresenter.stopOverrideSplitAnimation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void onActivityCreated(@NonNull Activity launchedActivity) {
|
void onActivityCreated(@NonNull Activity launchedActivity) {
|
||||||
handleActivityCreated(launchedActivity);
|
handleActivityCreated(launchedActivity);
|
||||||
updateCallbackIfNecessary();
|
updateCallbackIfNecessary();
|
||||||
@@ -180,6 +231,11 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
|||||||
final TaskFragmentContainer currentContainer = getContainerWithActivity(
|
final TaskFragmentContainer currentContainer = getContainerWithActivity(
|
||||||
launchedActivity.getActivityToken());
|
launchedActivity.getActivityToken());
|
||||||
|
|
||||||
|
if (currentContainer == null) {
|
||||||
|
// Initial check before any TaskFragment is created.
|
||||||
|
onParentBoundsMayChange(launchedActivity);
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the activity is configured to always be expanded.
|
// Check if the activity is configured to always be expanded.
|
||||||
if (shouldExpand(launchedActivity, null, splitRules)) {
|
if (shouldExpand(launchedActivity, null, splitRules)) {
|
||||||
if (shouldContainerBeExpanded(currentContainer)) {
|
if (shouldContainerBeExpanded(currentContainer)) {
|
||||||
@@ -257,6 +313,8 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
|||||||
// onTaskFragmentParentInfoChanged
|
// onTaskFragmentParentInfoChanged
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// The bounds of the container may have been changed.
|
||||||
|
onParentBoundsMayChange(activity);
|
||||||
|
|
||||||
// Check if activity requires a placeholder
|
// Check if activity requires a placeholder
|
||||||
launchPlaceholderIfNecessary(activity);
|
launchPlaceholderIfNecessary(activity);
|
||||||
|
|||||||
@@ -37,32 +37,42 @@ class TaskFragmentAnimationController {
|
|||||||
|
|
||||||
private final TaskFragmentOrganizer mOrganizer;
|
private final TaskFragmentOrganizer mOrganizer;
|
||||||
private final TaskFragmentAnimationRunner mRemoteRunner = new TaskFragmentAnimationRunner();
|
private final TaskFragmentAnimationRunner mRemoteRunner = new TaskFragmentAnimationRunner();
|
||||||
|
private final RemoteAnimationDefinition mDefinition;
|
||||||
|
private boolean mIsRegister;
|
||||||
|
|
||||||
TaskFragmentAnimationController(TaskFragmentOrganizer organizer) {
|
TaskFragmentAnimationController(TaskFragmentOrganizer organizer) {
|
||||||
mOrganizer = organizer;
|
mOrganizer = organizer;
|
||||||
|
mDefinition = new RemoteAnimationDefinition();
|
||||||
|
final RemoteAnimationAdapter animationAdapter =
|
||||||
|
new RemoteAnimationAdapter(mRemoteRunner, 0, 0, true /* changeNeedsSnapshot */);
|
||||||
|
mDefinition.addRemoteAnimation(TRANSIT_OLD_ACTIVITY_OPEN, animationAdapter);
|
||||||
|
mDefinition.addRemoteAnimation(TRANSIT_OLD_TASK_FRAGMENT_OPEN, animationAdapter);
|
||||||
|
mDefinition.addRemoteAnimation(TRANSIT_OLD_TASK_OPEN, animationAdapter);
|
||||||
|
mDefinition.addRemoteAnimation(TRANSIT_OLD_ACTIVITY_CLOSE, animationAdapter);
|
||||||
|
mDefinition.addRemoteAnimation(TRANSIT_OLD_TASK_FRAGMENT_CLOSE, animationAdapter);
|
||||||
|
mDefinition.addRemoteAnimation(TRANSIT_OLD_TASK_CLOSE, animationAdapter);
|
||||||
|
mDefinition.addRemoteAnimation(TRANSIT_OLD_TASK_FRAGMENT_CHANGE, animationAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerRemoteAnimations() {
|
void registerRemoteAnimations() {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.v(TAG, "registerRemoteAnimations");
|
Log.v(TAG, "registerRemoteAnimations");
|
||||||
}
|
}
|
||||||
final RemoteAnimationDefinition definition = new RemoteAnimationDefinition();
|
if (mIsRegister) {
|
||||||
final RemoteAnimationAdapter animationAdapter =
|
return;
|
||||||
new RemoteAnimationAdapter(mRemoteRunner, 0, 0, true /* changeNeedsSnapshot */);
|
}
|
||||||
definition.addRemoteAnimation(TRANSIT_OLD_ACTIVITY_OPEN, animationAdapter);
|
mOrganizer.registerRemoteAnimations(mDefinition);
|
||||||
definition.addRemoteAnimation(TRANSIT_OLD_TASK_FRAGMENT_OPEN, animationAdapter);
|
mIsRegister = true;
|
||||||
definition.addRemoteAnimation(TRANSIT_OLD_TASK_OPEN, animationAdapter);
|
|
||||||
definition.addRemoteAnimation(TRANSIT_OLD_ACTIVITY_CLOSE, animationAdapter);
|
|
||||||
definition.addRemoteAnimation(TRANSIT_OLD_TASK_FRAGMENT_CLOSE, animationAdapter);
|
|
||||||
definition.addRemoteAnimation(TRANSIT_OLD_TASK_CLOSE, animationAdapter);
|
|
||||||
definition.addRemoteAnimation(TRANSIT_OLD_TASK_FRAGMENT_CHANGE, animationAdapter);
|
|
||||||
mOrganizer.registerRemoteAnimations(definition);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void unregisterRemoteAnimations() {
|
void unregisterRemoteAnimations() {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.v(TAG, "unregisterRemoteAnimations");
|
Log.v(TAG, "unregisterRemoteAnimations");
|
||||||
}
|
}
|
||||||
|
if (!mIsRegister) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
mOrganizer.unregisterRemoteAnimations();
|
mOrganizer.unregisterRemoteAnimations();
|
||||||
|
mIsRegister = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user