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.wm.shell.compatui; 18 19 import android.annotation.NonNull; 20 21 import java.util.function.IntConsumer; 22 import java.util.function.IntSupplier; 23 24 /** Handle the visibility state of the Compat UI components. */ 25 public class CompatUIStatusManager { 26 27 private static final int COMPAT_UI_EDUCATION_UNDEFINED = -1; 28 public static final int COMPAT_UI_EDUCATION_HIDDEN = 0; 29 public static final int COMPAT_UI_EDUCATION_VISIBLE = 1; 30 31 @NonNull 32 private final IntConsumer mWriter; 33 @NonNull 34 private final IntSupplier mReader; 35 36 private int mCurrentValue = COMPAT_UI_EDUCATION_UNDEFINED; 37 CompatUIStatusManager(@onNull IntConsumer writer, @NonNull IntSupplier reader)38 public CompatUIStatusManager(@NonNull IntConsumer writer, @NonNull IntSupplier reader) { 39 mWriter = writer; 40 mReader = reader; 41 } 42 CompatUIStatusManager()43 public CompatUIStatusManager() { 44 this(i -> { 45 }, () -> COMPAT_UI_EDUCATION_HIDDEN); 46 } 47 onEducationShown()48 void onEducationShown() { 49 if (mCurrentValue != COMPAT_UI_EDUCATION_VISIBLE) { 50 mCurrentValue = COMPAT_UI_EDUCATION_VISIBLE; 51 mWriter.accept(mCurrentValue); 52 } 53 } 54 onEducationHidden()55 void onEducationHidden() { 56 if (mCurrentValue != COMPAT_UI_EDUCATION_HIDDEN) { 57 mCurrentValue = COMPAT_UI_EDUCATION_HIDDEN; 58 mWriter.accept(mCurrentValue); 59 } 60 } 61 isEducationVisible()62 boolean isEducationVisible() { 63 return getCurrentValue() == COMPAT_UI_EDUCATION_VISIBLE; 64 } 65 getCurrentValue()66 private int getCurrentValue() { 67 if (mCurrentValue == COMPAT_UI_EDUCATION_UNDEFINED) { 68 mCurrentValue = mReader.getAsInt(); 69 } 70 return mCurrentValue; 71 } 72 }