1 /* <lambda>null2 * Copyright (C) 2024 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.wm.shell.compatui.api 18 19 import android.content.Context 20 import android.graphics.Point 21 import android.view.View 22 import android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 23 import android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL 24 import com.android.internal.protolog.ProtoLog 25 import com.android.wm.shell.protolog.ShellProtoLogGroup 26 27 /** 28 * Defines the predicates to invoke for understanding if a component can be created or destroyed. 29 */ 30 class CompatUILifecyclePredicates( 31 // Predicate evaluating to true if the component needs to be created 32 val creationPredicate: (CompatUIInfo, CompatUISharedState) -> Boolean, 33 // Predicate evaluating to true if the component needs to be destroyed 34 val removalPredicate: ( 35 CompatUIInfo, 36 CompatUISharedState, 37 CompatUIComponentState? 38 ) -> Boolean, 39 // Builder for the initial state of the component 40 val stateBuilder: ( 41 CompatUIInfo, 42 CompatUISharedState 43 ) -> CompatUIComponentState? = { _, _ -> null } 44 ) 45 46 /** 47 * Layout configuration 48 */ 49 data class CompatUILayout( 50 val zOrder: Int = 0, 51 val layoutParamFlags: Int = FLAG_NOT_FOCUSABLE or FLAG_NOT_TOUCH_MODAL, 52 val viewBuilder: (Context, CompatUIInfo, CompatUIComponentState?) -> View, 53 val viewBinder: ( 54 View, 55 CompatUIInfo, 56 CompatUISharedState, 57 CompatUIComponentState? _null58 ) -> Unit = { _, _, _, _ -> }, 59 val positionFactory: ( 60 View, 61 CompatUIInfo, 62 CompatUISharedState, 63 CompatUIComponentState? 64 ) -> Point, <lambda>null65 val viewReleaser: () -> Unit = {} 66 ) 67 68 /** 69 * Describes each compat ui component to the framework. 70 */ 71 class CompatUISpec( strnull72 val log: (String) -> Unit = { str -> ProtoLog.v(ShellProtoLogGroup.WM_SHELL_COMPAT_UI, str) }, 73 // Unique name for the component. It's used for debug and for generating the 74 // unique component identifier in the system. 75 val name: String, 76 // The lifecycle definition 77 val lifecycle: CompatUILifecyclePredicates, 78 // The layout definition 79 val layout: CompatUILayout 80 ) 81