1 /*
2  * Copyright (C) 2018 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 android.view;
18 
19 import android.graphics.Point;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 import android.view.InsetsState.InternalInsetType;
23 
24 /**
25  * Represents a parcelable object to allow controlling a single {@link InsetsSource}.
26  * @hide
27  */
28 public class InsetsSourceControl implements Parcelable {
29 
30     private final @InternalInsetType int mType;
31     private final SurfaceControl mLeash;
32     private final Point mSurfacePosition;
33 
InsetsSourceControl(@nternalInsetType int type, SurfaceControl leash, Point surfacePosition)34     public InsetsSourceControl(@InternalInsetType int type, SurfaceControl leash,
35             Point surfacePosition) {
36         mType = type;
37         mLeash = leash;
38         mSurfacePosition = surfacePosition;
39     }
40 
getType()41     public int getType() {
42         return mType;
43     }
44 
getLeash()45     public SurfaceControl getLeash() {
46         return mLeash;
47     }
48 
InsetsSourceControl(Parcel in)49     public InsetsSourceControl(Parcel in) {
50         mType = in.readInt();
51         mLeash = in.readParcelable(null /* loader */);
52         mSurfacePosition = in.readParcelable(null /* loader */);
53     }
54 
setSurfacePosition(int left, int top)55     public boolean setSurfacePosition(int left, int top) {
56         if (mSurfacePosition.equals(left, top)) {
57             return false;
58         }
59         mSurfacePosition.set(left, top);
60         return true;
61     }
62 
getSurfacePosition()63     public Point getSurfacePosition() {
64         return mSurfacePosition;
65     }
66 
67     @Override
describeContents()68     public int describeContents() {
69         return 0;
70     }
71 
72     @Override
writeToParcel(Parcel dest, int flags)73     public void writeToParcel(Parcel dest, int flags) {
74         dest.writeInt(mType);
75         dest.writeParcelable(mLeash, 0 /* flags*/);
76         dest.writeParcelable(mSurfacePosition, 0 /* flags*/);
77     }
78 
79     public static final @android.annotation.NonNull Creator<InsetsSourceControl> CREATOR
80             = new Creator<InsetsSourceControl>() {
81         public InsetsSourceControl createFromParcel(Parcel in) {
82             return new InsetsSourceControl(in);
83         }
84 
85         public InsetsSourceControl[] newArray(int size) {
86             return new InsetsSourceControl[size];
87         }
88     };
89 }
90