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.inputmethodservice.InputMethodService; 20 import android.view.InsetsState; 21 import android.view.InsetsState.InternalInsetsType; 22 import android.view.WindowInsets.Type.InsetsType; 23 24 /** 25 * Generalization of an object that can control insets state. 26 */ 27 interface InsetsControlTarget { 28 29 /** 30 * Notifies the control target that the insets control has changed. 31 */ notifyInsetsControlChanged()32 default void notifyInsetsControlChanged() { 33 }; 34 35 /** 36 * @return {@link WindowState} of this target, if any. 37 */ getWindow()38 default WindowState getWindow() { 39 return null; 40 } 41 42 /** 43 * @return The requested visibility of this target. 44 */ getRequestedVisibility(@nternalInsetsType int type)45 default boolean getRequestedVisibility(@InternalInsetsType int type) { 46 return InsetsState.getDefaultVisibility(type); 47 } 48 49 /** 50 * Instructs the control target to show inset sources. 51 * 52 * @param types to specify which types of insets source window should be shown. 53 * @param fromIme {@code true} if IME show request originated from {@link InputMethodService}. 54 */ showInsets(@nsetsType int types, boolean fromIme)55 default void showInsets(@InsetsType int types, boolean fromIme) { 56 } 57 58 /** 59 * Instructs the control target to hide inset sources. 60 * 61 * @param types to specify which types of insets source window should be hidden. 62 * @param fromIme {@code true} if IME hide request originated from {@link InputMethodService}. 63 */ hideInsets(@nsetsType int types, boolean fromIme)64 default void hideInsets(@InsetsType int types, boolean fromIme) { 65 } 66 67 /** 68 * Returns {@code true} if the control target allows the system to show transient windows. 69 */ canShowTransient()70 default boolean canShowTransient() { 71 return false; 72 } 73 74 /** Returns {@code target.getWindow()}, or null if {@code target} is {@code null}. */ asWindowOrNull(InsetsControlTarget target)75 static WindowState asWindowOrNull(InsetsControlTarget target) { 76 return target != null ? target.getWindow() : null; 77 } 78 } 79