1 /* 2 * Copyright (C) 2023 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 androidx.window.extensions.area; 18 19 import android.app.Presentation; 20 import android.content.Context; 21 import android.view.Display; 22 import android.view.View; 23 24 import androidx.annotation.NonNull; 25 import androidx.window.extensions.core.util.function.Consumer; 26 27 /** 28 * {@link Presentation} object that is used to present extra content 29 * on the rear facing display when in a rear display presentation feature. 30 */ 31 class RearDisplayPresentation extends Presentation implements ExtensionWindowAreaPresentation { 32 33 @NonNull 34 private final Consumer<@WindowAreaComponent.WindowAreaSessionState Integer> mStateConsumer; 35 RearDisplayPresentation(@onNull Context outerContext, @NonNull Display display, @NonNull Consumer<@WindowAreaComponent.WindowAreaSessionState Integer> stateConsumer)36 RearDisplayPresentation(@NonNull Context outerContext, @NonNull Display display, 37 @NonNull Consumer<@WindowAreaComponent.WindowAreaSessionState Integer> stateConsumer) { 38 super(outerContext, display); 39 mStateConsumer = stateConsumer; 40 } 41 42 /** 43 * {@code mStateConsumer} is notified that their content is now visible when the 44 * {@link Presentation} object is started. There is no comparable callback for 45 * {@link WindowAreaComponent#SESSION_STATE_CONTENT_INVISIBLE} in {@link #onStop()} due to the 46 * timing of when a {@link android.hardware.devicestate.DeviceStateRequest} is cancelled 47 * ending rear display presentation mode happening before the {@link Presentation} is stopped. 48 */ 49 @Override onStart()50 protected void onStart() { 51 super.onStart(); 52 mStateConsumer.accept(WindowAreaComponent.SESSION_STATE_CONTENT_VISIBLE); 53 } 54 55 @NonNull 56 @Override getPresentationContext()57 public Context getPresentationContext() { 58 return getContext(); 59 } 60 61 @Override setPresentationView(View view)62 public void setPresentationView(View view) { 63 setContentView(view); 64 if (!isShowing()) { 65 show(); 66 } 67 } 68 } 69