1 /* 2 * Copyright (C) 2019 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.content.ComponentName; 20 import android.content.pm.ParceledListSlice; 21 import android.view.DisplayInfo; 22 import android.view.IPinnedStackController; 23 import android.view.IPinnedStackListener; 24 25 import java.util.ArrayList; 26 import java.util.List; 27 28 /** 29 * PinnedStackListener that simply forwards all calls to each listener added via 30 * {@link #addListener}. This is necessary since calling 31 * {@link com.android.server.wm.WindowManagerService#registerPinnedStackListener} replaces any 32 * previously set listener. 33 */ 34 public class PinnedStackListenerForwarder extends IPinnedStackListener.Stub { 35 private List<PinnedStackListener> mListeners = new ArrayList<>(); 36 37 /** Adds a listener to receive updates from the WindowManagerService. */ addListener(PinnedStackListener listener)38 public void addListener(PinnedStackListener listener) { 39 mListeners.add(listener); 40 } 41 42 /** Removes a listener so it will no longer receive updates from the WindowManagerService. */ removeListener(PinnedStackListener listener)43 public void removeListener(PinnedStackListener listener) { 44 mListeners.remove(listener); 45 } 46 47 @Override onListenerRegistered(IPinnedStackController controller)48 public void onListenerRegistered(IPinnedStackController controller) { 49 for (PinnedStackListener listener : mListeners) { 50 listener.onListenerRegistered(controller); 51 } 52 } 53 54 @Override onMovementBoundsChanged(boolean fromImeAdjustment)55 public void onMovementBoundsChanged(boolean fromImeAdjustment) { 56 for (PinnedStackListener listener : mListeners) { 57 listener.onMovementBoundsChanged(fromImeAdjustment); 58 } 59 } 60 61 @Override onImeVisibilityChanged(boolean imeVisible, int imeHeight)62 public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) { 63 for (PinnedStackListener listener : mListeners) { 64 listener.onImeVisibilityChanged(imeVisible, imeHeight); 65 } 66 } 67 68 @Override onActionsChanged(ParceledListSlice actions)69 public void onActionsChanged(ParceledListSlice actions) { 70 for (PinnedStackListener listener : mListeners) { 71 listener.onActionsChanged(actions); 72 } 73 } 74 75 @Override onActivityHidden(ComponentName componentName)76 public void onActivityHidden(ComponentName componentName) { 77 for (PinnedStackListener listener : mListeners) { 78 listener.onActivityHidden(componentName); 79 } 80 } 81 82 @Override onDisplayInfoChanged(DisplayInfo displayInfo)83 public void onDisplayInfoChanged(DisplayInfo displayInfo) { 84 for (PinnedStackListener listener : mListeners) { 85 listener.onDisplayInfoChanged(displayInfo); 86 } 87 } 88 89 @Override onConfigurationChanged()90 public void onConfigurationChanged() { 91 for (PinnedStackListener listener : mListeners) { 92 listener.onConfigurationChanged(); 93 } 94 } 95 96 @Override onAspectRatioChanged(float aspectRatio)97 public void onAspectRatioChanged(float aspectRatio) { 98 for (PinnedStackListener listener : mListeners) { 99 listener.onAspectRatioChanged(aspectRatio); 100 } 101 } 102 103 /** 104 * A counterpart of {@link IPinnedStackListener} with empty implementations. 105 * Subclasses can ignore those methods they do not intend to take action upon. 106 */ 107 public static class PinnedStackListener { onListenerRegistered(IPinnedStackController controller)108 public void onListenerRegistered(IPinnedStackController controller) {} 109 onMovementBoundsChanged(boolean fromImeAdjustment)110 public void onMovementBoundsChanged(boolean fromImeAdjustment) {} 111 onImeVisibilityChanged(boolean imeVisible, int imeHeight)112 public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) {} 113 onActionsChanged(ParceledListSlice actions)114 public void onActionsChanged(ParceledListSlice actions) {} 115 onActivityHidden(ComponentName componentName)116 public void onActivityHidden(ComponentName componentName) {} 117 onDisplayInfoChanged(DisplayInfo displayInfo)118 public void onDisplayInfoChanged(DisplayInfo displayInfo) {} 119 onConfigurationChanged()120 public void onConfigurationChanged() {} 121 onAspectRatioChanged(float aspectRatio)122 public void onAspectRatioChanged(float aspectRatio) {} 123 } 124 } 125