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.onMultiWindowModeChanged] is dispatched to a [OnMultiWindowModeChangedProvider]. 25 */ 26 public class MultiWindowModeChangedInfo( 27 /** 28 * Gets the new multi-window mode. 29 * 30 * @return True if the activity is in multi-window mode. 31 */ 32 public val isInMultiWindowMode: Boolean, 33 ) { 34 @RequiresApi(26) private var newConfiguration: Configuration? = null 35 36 /** 37 * Construct an instance that contains the new multi-window mode and the new configuration with 38 * the new multi-window mode applied. 39 * 40 * @param isInMultiWindowMode True if the activity is in multi-window mode. 41 * @param newConfig The new configuration of the activity with the state {@param 42 * isInMultiWindowMode}. 43 */ 44 @RequiresApi(26) 45 public constructor( 46 isInMultiWindowMode: Boolean, 47 newConfig: Configuration 48 ) : this(isInMultiWindowMode) { 49 this.newConfiguration = newConfig 50 } 51 52 @get:RequiresApi(26) 53 public val newConfig: Configuration 54 /** 55 * Gets the new [Configuration] of the with activity with the state [isInMultiWindowMode] 56 * applied. 57 * 58 * Note that this is only valid on devices that are running API 26 59 * ([android.os.Build.VERSION_CODES.O]) or higher. 60 * 61 * @return The new configuration of the activity with the state [isInMultiWindowMode]. 62 * @throws IllegalStateException if the new [Configuration] is not available (i.e., you are 63 * running on a device less that [android.os.Build.VERSION_CODES.O] which is when this 64 * information first became available). 65 */ 66 get() { <lambda>null67 return checkNotNull(newConfiguration) { 68 "MultiWindowModeChangedInfo must be constructed " + 69 "with the constructor that takes a Configuration to access the newConfig. " + 70 "Are you running on an API 26 or higher device that makes this " + 71 "information available?" 72 } 73 } 74 } 75