1 /* 2 * Copyright 2022 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 package androidx.core.app 17 18 import android.app.Activity 19 import android.content.res.Configuration 20 import androidx.annotation.RequiresApi 21 22 /** 23 * Class that encapsulates the information that is delivered when 24 * [Activity.onPictureInPictureModeChanged] is dispatched to a 25 * [OnPictureInPictureModeChangedProvider]. 26 */ 27 public class PictureInPictureModeChangedInfo( 28 /** 29 * Gets the new picture-in-picture mode. 30 * 31 * @return True if the activity is in picture-in-picture mode. 32 */ 33 public val isInPictureInPictureMode: Boolean 34 ) { 35 @RequiresApi(26) private var newConfiguration: Configuration? = null 36 37 /** 38 * Construct an instance that contains the new picture-in-picture mode and the new configuration 39 * with the new picture-in-picture mode applied. 40 * 41 * @param isInPictureInPictureMode True if the activity is in picture-in-picture mode. 42 * @param newConfig The new configuration of the activity with the state {@param 43 * isInPictureInPictureMode}. 44 */ 45 @RequiresApi(26) 46 public constructor( 47 isInPictureInPictureMode: Boolean, 48 newConfig: Configuration 49 ) : this(isInPictureInPictureMode) { 50 this.newConfiguration = newConfig 51 } 52 53 @get:RequiresApi(26) 54 public val newConfig: Configuration 55 /** 56 * Gets the new [Configuration] of the with activity with the state 57 * [isInPictureInPictureMode] applied. 58 * 59 * Note that this is only valid on devices that are running API 26 60 * ([android.os.Build.VERSION_CODES.O]) or higher. 61 * 62 * @return The new configuration of the activity with the state [isInPictureInPictureMode]. 63 * @throws IllegalStateException if the new [Configuration] is not available (i.e., you are 64 * running on a device less that [android.os.Build.VERSION_CODES.O] which is when this 65 * information first became available). 66 */ 67 get() { <lambda>null68 return checkNotNull(newConfiguration) { 69 "PictureInPictureModeChangedInfo must be constructed " + 70 "with the constructor that takes a Configuration to access the newConfig. " + 71 "Are you running on an API 26 or higher device that makes this " + 72 "information available?" 73 } 74 } 75 } 76