1 /*
2  * Copyright (C) 2021 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.shared.system.smartspace
18 
19 import android.graphics.Rect
20 import android.os.Parcel
21 import android.os.Parcelable
22 
23 /**
24  * Represents the state of a SmartSpace, including its location on screen and the index of the
25  * currently selected page. This object contains all of the information needed to synchronize two
26  * SmartSpace instances so that we can perform shared-element transitions between them.
27  */
28 class SmartspaceState() : Parcelable {
29     var boundsOnScreen: Rect = Rect()
30     var selectedPage = 0
31     var visibleOnScreen = false
32 
33     constructor(parcel: Parcel) : this() {
34         this.boundsOnScreen = parcel.readParcelable(Rect::javaClass.javaClass.classLoader) ?: Rect()
35         this.selectedPage = parcel.readInt()
36         this.visibleOnScreen = parcel.readBoolean()
37     }
38 
writeToParcelnull39     override fun writeToParcel(dest: Parcel, flags: Int) {
40         dest.writeParcelable(boundsOnScreen, 0)
41         dest.writeInt(selectedPage)
42         dest.writeBoolean(visibleOnScreen)
43     }
44 
describeContentsnull45     override fun describeContents(): Int {
46         return 0
47     }
48 
toStringnull49     override fun toString(): String {
50         return "boundsOnScreen: $boundsOnScreen, " +
51                 "selectedPage: $selectedPage, " +
52                 "visibleOnScreen: $visibleOnScreen"
53     }
54 
55     companion object CREATOR : Parcelable.Creator<SmartspaceState> {
createFromParcelnull56         override fun createFromParcel(parcel: Parcel): SmartspaceState {
57             return SmartspaceState(parcel)
58         }
59 
newArraynull60         override fun newArray(size: Int): Array<SmartspaceState?> {
61             return arrayOfNulls(size)
62         }
63     }
64 }