1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.shared.system; 18 19 import android.util.ArrayMap; 20 import android.view.RemoteAnimationTarget; 21 import android.view.SurfaceControl; 22 import android.window.TransitionInfo; 23 import android.window.TransitionInfo.Change; 24 25 import com.android.wm.shell.util.TransitionUtil; 26 27 import java.util.ArrayList; 28 import java.util.function.Predicate; 29 30 /** 31 * Some utility methods for creating {@link RemoteAnimationTarget} instances. 32 */ 33 public class RemoteAnimationTargetCompat { 34 35 /** 36 * Represents a TransitionInfo object as an array of old-style app targets 37 * 38 * @param leashMap Temporary map of change leash -> launcher leash. Is an output, so should be 39 * populated by this function. If null, it is ignored. 40 */ wrapApps(TransitionInfo info, SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap)41 public static RemoteAnimationTarget[] wrapApps(TransitionInfo info, 42 SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap) { 43 return wrap(info, t, leashMap, new TransitionUtil.LeafTaskFilter()); 44 } 45 46 /** 47 * Represents a TransitionInfo object as an array of old-style non-app targets 48 * 49 * @param wallpapers If true, this will return wallpaper targets; otherwise it returns 50 * non-wallpaper targets. 51 * @param leashMap Temporary map of change leash -> launcher leash. Is an output, so should be 52 * populated by this function. If null, it is ignored. 53 */ wrapNonApps(TransitionInfo info, boolean wallpapers, SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap)54 public static RemoteAnimationTarget[] wrapNonApps(TransitionInfo info, boolean wallpapers, 55 SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap) { 56 return wrap(info, t, leashMap, (change) -> (wallpapers 57 ? TransitionUtil.isWallpaper(change) : TransitionUtil.isNonApp(change))); 58 } 59 wrap(TransitionInfo info, SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap, Predicate<Change> filter)60 private static RemoteAnimationTarget[] wrap(TransitionInfo info, 61 SurfaceControl.Transaction t, ArrayMap<SurfaceControl, SurfaceControl> leashMap, 62 Predicate<Change> filter) { 63 final ArrayList<RemoteAnimationTarget> out = new ArrayList<>(); 64 for (int i = 0; i < info.getChanges().size(); i++) { 65 TransitionInfo.Change change = info.getChanges().get(i); 66 if (TransitionUtil.isOrderOnly(change)) continue; 67 if (filter.test(change)) { 68 out.add(TransitionUtil.newTarget( 69 change, info.getChanges().size() - i, info, t, leashMap)); 70 } 71 } 72 return out.toArray(new RemoteAnimationTarget[out.size()]); 73 } 74 } 75