Merge "Apply right animation type on translucent window containers." into tm-dev

This commit is contained in:
Issei Suzuki
2022-03-07 11:46:47 +00:00
committed by Android (Google) Code Review
4 changed files with 97 additions and 8 deletions

View File

@@ -312,9 +312,9 @@ public class TransitionAnimation {
/** Load animation by attribute Id from android package. */
@Nullable
public Animation loadDefaultAnimationAttr(int animAttr) {
public Animation loadDefaultAnimationAttr(int animAttr, boolean translucent) {
return loadAnimationAttr(DEFAULT_PACKAGE, mDefaultWindowAnimationStyleResId, animAttr,
false /* translucent */);
translucent);
}
@Nullable

View File

@@ -408,7 +408,8 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
|| type == TRANSIT_CLOSE
|| type == TRANSIT_TO_FRONT
|| type == TRANSIT_TO_BACK;
if (isOpenOrCloseTransition) {
final boolean isTranslucent = (change.getFlags() & FLAG_TRANSLUCENT) != 0;
if (isOpenOrCloseTransition && !isTranslucent) {
// Use the overview background as the background for the animation
final Context uiContext = ActivityThread.currentActivityThread()
.getSystemUiContext();
@@ -729,14 +730,17 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
? R.styleable.WindowAnimation_wallpaperCloseEnterAnimation
: R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
} else if (type == TRANSIT_OPEN) {
if (isTask) {
// We will translucent open animation for translucent activities and tasks. Choose
// WindowAnimation_activityOpenEnterAnimation and set translucent here, then
// TransitionAnimation loads appropriate animation later.
if ((changeFlags & FLAG_TRANSLUCENT) != 0 && enter) {
translucent = true;
}
if (isTask && !translucent) {
animAttr = enter
? R.styleable.WindowAnimation_taskOpenEnterAnimation
: R.styleable.WindowAnimation_taskOpenExitAnimation;
} else {
if ((changeFlags & FLAG_TRANSLUCENT) != 0 && enter) {
translucent = true;
}
animAttr = enter
? R.styleable.WindowAnimation_activityOpenEnterAnimation
: R.styleable.WindowAnimation_activityOpenExitAnimation;
@@ -770,7 +774,7 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
.loadAnimationAttr(options.getPackageName(), options.getAnimations(),
animAttr, translucent);
} else {
a = mTransitionAnimation.loadDefaultAnimationAttr(animAttr);
a = mTransitionAnimation.loadDefaultAnimationAttr(animAttr, translucent);
}
}
}

View File

@@ -1526,6 +1526,9 @@ class Transition extends Binder implements BLASTSyncEngine.TransactionReadyListe
if (task != null && task.voiceSession != null) {
flags |= FLAG_IS_VOICE_INTERACTION;
}
if (task != null && task.isTranslucent(null)) {
flags |= FLAG_TRANSLUCENT;
}
final ActivityRecord record = wc.asActivityRecord();
if (record != null) {
if (record.mUseTransferredAnimation) {

View File

@@ -32,6 +32,7 @@ import static android.view.WindowManager.TRANSIT_OPEN;
import static android.view.WindowManager.TRANSIT_TO_BACK;
import static android.window.TransitionInfo.FLAG_IS_WALLPAPER;
import static android.window.TransitionInfo.FLAG_SHOW_WALLPAPER;
import static android.window.TransitionInfo.FLAG_TRANSLUCENT;
import static android.window.TransitionInfo.isIndependent;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
@@ -328,6 +329,7 @@ public class TransitionTests extends WindowTestsBase {
final ActivityRecord act = createActivityRecord(tasks[i]);
// alternate so that the transition doesn't get promoted to the display area
act.mVisibleRequested = (i % 2) == 0; // starts invisible
act.visibleIgnoringKeyguard = (i % 2) == 0;
if (i == showWallpaperTask) {
doReturn(true).when(act).showWallpaper();
}
@@ -489,6 +491,86 @@ public class TransitionTests extends WindowTestsBase {
info.getChange(openInChangeTask.mRemoteToken.toWindowContainerToken()), info));
}
@Test
public void testOpenOpaqueTask() {
final Transition transition = createTestTransition(TRANSIT_OPEN);
ArrayMap<WindowContainer, Transition.ChangeInfo> changes = transition.mChanges;
ArraySet<WindowContainer> participants = transition.mParticipants;
final Task newTask = createTask(mDisplayContent);
doReturn(false).when(newTask).isTranslucent(any());
final Task oldTask = createTask(mDisplayContent);
doReturn(false).when(oldTask).isTranslucent(any());
final ActivityRecord closing = createActivityRecord(oldTask);
closing.setOccludesParent(true);
final ActivityRecord opening = createActivityRecord(newTask);
opening.setOccludesParent(false);
// Start states.
changes.put(newTask, new Transition.ChangeInfo(false /* vis */, true /* exChg */));
changes.put(oldTask, new Transition.ChangeInfo(true /* vis */, false /* exChg */));
changes.put(opening, new Transition.ChangeInfo(false /* vis */, true /* exChg */));
changes.put(closing, new Transition.ChangeInfo(true /* vis */, false /* exChg */));
fillChangeMap(changes, newTask);
// End states.
closing.mVisibleRequested = true;
opening.mVisibleRequested = true;
final int transit = transition.mType;
int flags = 0;
// Check basic both tasks participating
participants.add(oldTask);
participants.add(newTask);
ArrayList<WindowContainer> targets = Transition.calculateTargets(participants, changes);
TransitionInfo info = Transition.calculateTransitionInfo(transit, flags, targets, changes);
assertEquals(2, info.getChanges().size());
assertEquals(transit, info.getType());
assertTrue((info.getChanges().get(0).getFlags() & FLAG_TRANSLUCENT) == 0);
assertTrue((info.getChanges().get(1).getFlags() & FLAG_TRANSLUCENT) == 0);
}
@Test
public void testOpenTranslucentTask() {
final Transition transition = createTestTransition(TRANSIT_OPEN);
ArrayMap<WindowContainer, Transition.ChangeInfo> changes = transition.mChanges;
ArraySet<WindowContainer> participants = transition.mParticipants;
final Task newTask = createTask(mDisplayContent);
doReturn(true).when(newTask).isTranslucent(any());
final Task oldTask = createTask(mDisplayContent);
doReturn(false).when(oldTask).isTranslucent(any());
final ActivityRecord closing = createActivityRecord(oldTask);
closing.setOccludesParent(true);
final ActivityRecord opening = createActivityRecord(newTask);
opening.setOccludesParent(false);
// Start states.
changes.put(newTask, new Transition.ChangeInfo(false /* vis */, true /* exChg */));
changes.put(oldTask, new Transition.ChangeInfo(true /* vis */, false /* exChg */));
changes.put(opening, new Transition.ChangeInfo(false /* vis */, true /* exChg */));
changes.put(closing, new Transition.ChangeInfo(true /* vis */, false /* exChg */));
fillChangeMap(changes, newTask);
// End states.
closing.mVisibleRequested = true;
opening.mVisibleRequested = true;
final int transit = transition.mType;
int flags = 0;
// Check basic both tasks participating
participants.add(oldTask);
participants.add(newTask);
ArrayList<WindowContainer> targets = Transition.calculateTargets(participants, changes);
TransitionInfo info = Transition.calculateTransitionInfo(transit, flags, targets, changes);
assertEquals(2, info.getChanges().size());
assertEquals(transit, info.getType());
assertTrue((info.getChanges().get(0).getFlags() & FLAG_TRANSLUCENT) != 0);
assertTrue((info.getChanges().get(1).getFlags() & FLAG_TRANSLUCENT) == 0);
}
@Test
public void testTimeout() {
final TransitionController controller = new TransitionController(mAtm,