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 com.android.systemui.wm; 18 19 import static android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE; 20 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.os.Handler; 24 import android.os.IBinder; 25 import android.view.InsetsController; 26 import android.view.SurfaceControl; 27 import android.view.SyncRtSurfaceTransactionApplier; 28 import android.view.WindowInsets; 29 import android.view.WindowInsetsAnimation; 30 import android.view.WindowInsetsController; 31 import android.view.inputmethod.ImeTracker; 32 import android.view.inputmethod.InputMethodManager; 33 34 import java.util.List; 35 import java.util.function.Consumer; 36 37 /** 38 * Implements {@link InsetsController.Host} for usage by 39 * {@link DisplaySystemBarsController.PerDisplay} instances in {@link DisplaySystemBarsController}. 40 * @hide 41 */ 42 public class DisplaySystemBarsInsetsControllerHost implements InsetsController.Host { 43 44 private static final String TAG = DisplaySystemBarsInsetsControllerHost.class.getSimpleName(); 45 46 private final Handler mHandler; 47 private final float[] mTmpFloat9 = new float[9]; 48 private final Consumer<Integer> mRequestedVisibleTypesCallback; 49 private final InputMethodManager mInputMethodManager; 50 DisplaySystemBarsInsetsControllerHost(Handler handler, Consumer<Integer> requestedVisibleTypesCallback, InputMethodManager inputMethodManager)51 public DisplaySystemBarsInsetsControllerHost(Handler handler, 52 Consumer<Integer> requestedVisibleTypesCallback, 53 InputMethodManager inputMethodManager) { 54 mHandler = handler; 55 mRequestedVisibleTypesCallback = requestedVisibleTypesCallback; 56 mInputMethodManager = inputMethodManager; 57 } 58 59 @Override getHandler()60 public Handler getHandler() { 61 return mHandler; 62 } 63 64 @Override notifyInsetsChanged()65 public void notifyInsetsChanged() { 66 // no-op 67 } 68 69 @Override dispatchWindowInsetsAnimationPrepare(@onNull WindowInsetsAnimation animation)70 public void dispatchWindowInsetsAnimationPrepare(@NonNull WindowInsetsAnimation animation) { 71 // no-op 72 } 73 74 @Override dispatchWindowInsetsAnimationStart( @onNull WindowInsetsAnimation animation, @NonNull WindowInsetsAnimation.Bounds bounds)75 public WindowInsetsAnimation.Bounds dispatchWindowInsetsAnimationStart( 76 @NonNull WindowInsetsAnimation animation, 77 @NonNull WindowInsetsAnimation.Bounds bounds) { 78 return null; 79 } 80 81 @Override dispatchWindowInsetsAnimationProgress(@onNull WindowInsets insets, @NonNull List<WindowInsetsAnimation> runningAnimations)82 public WindowInsets dispatchWindowInsetsAnimationProgress(@NonNull WindowInsets insets, 83 @NonNull List<WindowInsetsAnimation> runningAnimations) { 84 return null; 85 } 86 87 @Override dispatchWindowInsetsAnimationEnd(@onNull WindowInsetsAnimation animation)88 public void dispatchWindowInsetsAnimationEnd(@NonNull WindowInsetsAnimation animation) { 89 // no-op 90 } 91 92 @Override applySurfaceParams(final SyncRtSurfaceTransactionApplier.SurfaceParams... params)93 public void applySurfaceParams(final SyncRtSurfaceTransactionApplier.SurfaceParams... params) { 94 for (int i = params.length - 1; i >= 0; i--) { 95 SyncRtSurfaceTransactionApplier.applyParams( 96 new SurfaceControl.Transaction(), params[i], mTmpFloat9); 97 } 98 99 } 100 101 @Override updateRequestedVisibleTypes(@indowInsets.Type.InsetsType int types, @Nullable ImeTracker.Token statsToken)102 public void updateRequestedVisibleTypes(@WindowInsets.Type.InsetsType int types, 103 @Nullable ImeTracker.Token statsToken) { 104 mRequestedVisibleTypesCallback.accept(types); 105 } 106 107 @Override hasAnimationCallbacks()108 public boolean hasAnimationCallbacks() { 109 return false; 110 } 111 112 @Override setSystemBarsAppearance( @indowInsetsController.Appearance int appearance, @WindowInsetsController.Appearance int mask)113 public void setSystemBarsAppearance( 114 @WindowInsetsController.Appearance int appearance, 115 @WindowInsetsController.Appearance int mask) { 116 // no-op 117 } 118 119 @Override getSystemBarsAppearance()120 public @WindowInsetsController.Appearance int getSystemBarsAppearance() { 121 return 0; 122 } 123 124 @Override setSystemBarsBehavior(@indowInsetsController.Behavior int behavior)125 public void setSystemBarsBehavior(@WindowInsetsController.Behavior int behavior) { 126 // no-op 127 } 128 129 @Override getSystemBarsBehavior()130 public @WindowInsetsController.Behavior int getSystemBarsBehavior() { 131 return BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE; 132 } 133 134 @Override releaseSurfaceControlFromRt(SurfaceControl surfaceControl)135 public void releaseSurfaceControlFromRt(SurfaceControl surfaceControl) { 136 surfaceControl.release(); 137 } 138 139 @Override addOnPreDrawRunnable(Runnable r)140 public void addOnPreDrawRunnable(Runnable r) { 141 mHandler.post(r); 142 } 143 144 @Override postInsetsAnimationCallback(Runnable r)145 public void postInsetsAnimationCallback(Runnable r) { 146 mHandler.post(r); 147 } 148 149 @Override getInputMethodManager()150 public InputMethodManager getInputMethodManager() { 151 return mInputMethodManager; 152 } 153 154 @Override getRootViewTitle()155 public String getRootViewTitle() { 156 return null; 157 } 158 159 @Override dipToPx(int dips)160 public int dipToPx(int dips) { 161 return 0; 162 } 163 164 @Override getWindowToken()165 public IBinder getWindowToken() { 166 return null; 167 } 168 } 169