1 /* 2 * Copyright (C) 2020 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 android.view; 18 19 import android.annotation.Nullable; 20 import android.util.SparseArray; 21 import android.util.proto.ProtoOutputStream; 22 import android.view.InsetsController.AnimationType; 23 import android.view.InsetsController.LayoutInsetsDuringAnimation; 24 import android.view.WindowInsets.Type.InsetsType; 25 import android.view.inputmethod.ImeTracker; 26 27 /** 28 * Interface representing a runner for an insets animation. 29 * 30 * @hide 31 */ 32 public interface InsetsAnimationControlRunner { 33 34 /** 35 * @return The {@link InsetsType} the animation of this runner controls. 36 */ getTypes()37 @InsetsType int getTypes(); 38 39 /** 40 * @return The {@link InsetsType} the animation of this runner is controlling. This can be 41 * changed if a control is revoked. 42 */ getControllingTypes()43 @InsetsType int getControllingTypes(); 44 45 /** 46 * Notifies {@link InsetsType types} of control are getting revoked. 47 */ notifyControlRevoked(@nsetsType int types)48 void notifyControlRevoked(@InsetsType int types); 49 50 /** 51 * Updates the surface positions of the controls owned by this runner if there is any. 52 * 53 * @param controls An array of {@link InsetsSourceControl} that the caller newly receives. 54 */ updateSurfacePosition(SparseArray<InsetsSourceControl> controls)55 void updateSurfacePosition(SparseArray<InsetsSourceControl> controls); 56 57 /** 58 * Returns {@code true} if this runner will keep playing the animation and updating the surface. 59 * {@code false} otherwise. 60 */ willUpdateSurface()61 boolean willUpdateSurface(); 62 63 /** 64 * Cancels the animation. 65 */ cancel()66 void cancel(); 67 68 /** 69 * @return The animation this runner is running. 70 */ getAnimation()71 WindowInsetsAnimation getAnimation(); 72 73 /** 74 * @return Whether {@link #getTypes()} contains a specific {@link InsetsType}. 75 */ controlsType(@nsetsType int type)76 default boolean controlsType(@InsetsType int type) { 77 return (getTypes() & type) != 0; 78 } 79 80 /** 81 * @return The animation type this runner is running. 82 */ getAnimationType()83 @AnimationType int getAnimationType(); 84 85 /** 86 * @return The {@link SurfaceParamsApplier} this runner is using. 87 */ getSurfaceParamsApplier()88 SurfaceParamsApplier getSurfaceParamsApplier(); 89 90 /** 91 * @return The token tracking the current IME request or {@code null} otherwise. 92 */ 93 @Nullable getStatsToken()94 ImeTracker.Token getStatsToken(); 95 96 /** 97 * Updates the desired layout insets during the animation. 98 * 99 * @param layoutInsetsDuringAnimation Whether the insets should be shown or hidden 100 */ updateLayoutInsetsDuringAnimation( @ayoutInsetsDuringAnimation int layoutInsetsDuringAnimation)101 void updateLayoutInsetsDuringAnimation( 102 @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation); 103 104 /** 105 * 106 * Export the state of classes that implement this interface into a protocol buffer 107 * output stream. 108 * 109 * @param proto Stream to write the state to 110 * @param fieldId FieldId of the implementation class 111 */ dumpDebug(ProtoOutputStream proto, long fieldId)112 void dumpDebug(ProtoOutputStream proto, long fieldId); 113 114 /** 115 * Interface applying given surface operations. 116 */ 117 interface SurfaceParamsApplier { 118 119 SurfaceParamsApplier DEFAULT = params -> { 120 final SurfaceControl.Transaction t = new SurfaceControl.Transaction(); 121 for (int i = params.length - 1; i >= 0; i--) { 122 SyncRtSurfaceTransactionApplier.applyParams(t, params[i], new float[9]); 123 } 124 t.apply(); 125 t.close(); 126 }; 127 128 /** 129 * Apply the new params to the surface. 130 * 131 * @param params The {@link SyncRtSurfaceTransactionApplier.SurfaceParams} to apply. 132 */ applySurfaceParams(SyncRtSurfaceTransactionApplier.SurfaceParams... params)133 void applySurfaceParams(SyncRtSurfaceTransactionApplier.SurfaceParams... params); 134 135 } 136 } 137