1 /* 2 * 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.systemui.animation; 18 19 import android.annotation.FloatRange; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.graphics.Rect; 23 import android.view.SurfaceControl; 24 25 import java.util.concurrent.Executor; 26 27 /** 28 * An interface representing an UI component on the display. 29 * @hide 30 */ 31 public interface UIComponent { 32 33 /** Get the current alpha of this UI. */ getAlpha()34 float getAlpha(); 35 36 /** Check if this UI is visible. */ isVisible()37 boolean isVisible(); 38 39 /** Get the bounds of this UI in its display. */ 40 @NonNull getBounds()41 Rect getBounds(); 42 43 /** Create a new {@link Transaction} that can update this UI. */ 44 @NonNull newTransaction()45 Transaction newTransaction(); 46 47 /** 48 * A transaction class for updating {@link UIComponent}. 49 * 50 * @param <T> the subtype of {@link UIComponent} that this {@link Transaction} can handle. 51 * @hide 52 */ 53 interface Transaction<T extends UIComponent> { 54 /** Update alpha of an UI. Execution will be delayed until {@link #commit()} is called. */ setAlpha(@onNull T ui, @FloatRange(from = 0.0, to = 1.0) float alpha)55 Transaction setAlpha(@NonNull T ui, @FloatRange(from = 0.0, to = 1.0) float alpha); 56 57 /** 58 * Update visibility of an UI. Execution will be delayed until {@link #commit()} is called. 59 */ 60 @NonNull setVisible(@onNull T ui, boolean visible)61 Transaction setVisible(@NonNull T ui, boolean visible); 62 63 /** Update bounds of an UI. Execution will be delayed until {@link #commit()} is called. */ 64 @NonNull setBounds(@onNull T ui, @NonNull Rect bounds)65 Transaction setBounds(@NonNull T ui, @NonNull Rect bounds); 66 67 /** 68 * Attach a ui to the transition leash. Execution will be delayed until {@link #commit()} is 69 * called. 70 */ 71 @NonNull attachToTransitionLeash( @onNull T ui, @NonNull SurfaceControl transitionLeash, int w, int h)72 Transaction attachToTransitionLeash( 73 @NonNull T ui, @NonNull SurfaceControl transitionLeash, int w, int h); 74 75 /** 76 * Detach a ui from the transition leash. Execution will be delayed until {@link #commit} is 77 * called. 78 */ 79 @NonNull detachFromTransitionLeash( @onNull T ui, @NonNull Executor executor, @Nullable Runnable onDone)80 Transaction detachFromTransitionLeash( 81 @NonNull T ui, @NonNull Executor executor, @Nullable Runnable onDone); 82 83 /** Commit any pending changes added to this transaction. */ commit()84 void commit(); 85 } 86 } 87