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.server.wm; 18 19 import android.annotation.Nullable; 20 import android.inputmethodservice.InputMethodService; 21 import android.view.WindowInsets; 22 import android.view.WindowInsets.Type.InsetsType; 23 import android.view.inputmethod.ImeTracker; 24 25 /** 26 * Generalization of an object that can control insets state. 27 */ 28 interface InsetsControlTarget { 29 30 /** 31 * Notifies the control target that the insets control has changed. 32 */ notifyInsetsControlChanged()33 default void notifyInsetsControlChanged() { 34 }; 35 36 /** 37 * @return {@link WindowState} of this target, if any. 38 */ getWindow()39 default WindowState getWindow() { 40 return null; 41 } 42 43 /** 44 * @return {@code true} if any of the {@link InsetsType} is requested visible by this target. 45 */ isRequestedVisible(@nsetsType int types)46 default boolean isRequestedVisible(@InsetsType int types) { 47 return (WindowInsets.Type.defaultVisible() & types) != 0; 48 } 49 50 /** 51 * @return {@link InsetsType}s which are requested visible by this target. 52 */ getRequestedVisibleTypes()53 default @InsetsType int getRequestedVisibleTypes() { 54 return WindowInsets.Type.defaultVisible(); 55 } 56 57 /** 58 * Instructs the control target to show inset sources. 59 * 60 * @param types to specify which types of insets source window should be shown. 61 * @param fromIme {@code true} if IME show request originated from {@link InputMethodService}. 62 * @param statsToken the token tracking the current IME show request or {@code null} otherwise. 63 */ showInsets(@nsetsType int types, boolean fromIme, @Nullable ImeTracker.Token statsToken)64 default void showInsets(@InsetsType int types, boolean fromIme, 65 @Nullable ImeTracker.Token statsToken) { 66 } 67 68 /** 69 * Instructs the control target to hide inset sources. 70 * 71 * @param types to specify which types of insets source window should be hidden. 72 * @param fromIme {@code true} if IME hide request originated from {@link InputMethodService}. 73 * @param statsToken the token tracking the current IME hide request or {@code null} otherwise. 74 */ hideInsets(@nsetsType int types, boolean fromIme, @Nullable ImeTracker.Token statsToken)75 default void hideInsets(@InsetsType int types, boolean fromIme, 76 @Nullable ImeTracker.Token statsToken) { 77 } 78 79 /** 80 * Returns {@code true} if the control target allows the system to show transient windows. 81 */ canShowTransient()82 default boolean canShowTransient() { 83 return false; 84 } 85 86 /** Returns {@code target.getWindow()}, or null if {@code target} is {@code null}. */ asWindowOrNull(InsetsControlTarget target)87 static WindowState asWindowOrNull(InsetsControlTarget target) { 88 return target != null ? target.getWindow() : null; 89 } 90 } 91