blob: 4940981748a8beda8b485b8625db7692b843c7dc [file] [log] [blame]
Jorim Jaggib6030952018-10-23 18:31:52 +02001/*
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
17package android.view;
18
19import android.graphics.Point;
20import android.os.Parcel;
21import android.os.Parcelable;
22import android.view.InsetsState.InternalInsetType;
23
24/**
25 * Represents a parcelable object to allow controlling a single {@link InsetsSource}.
26 * @hide
27 */
28public class InsetsSourceControl implements Parcelable {
29
30 private final @InternalInsetType int mType;
31 private final SurfaceControl mLeash;
Tarandeep Singh215929b2019-01-11 18:24:37 -080032 private final Point mSurfacePosition;
Jorim Jaggib6030952018-10-23 18:31:52 +020033
Tarandeep Singh215929b2019-01-11 18:24:37 -080034 public InsetsSourceControl(@InternalInsetType int type, SurfaceControl leash,
35 Point surfacePosition) {
Jorim Jaggib6030952018-10-23 18:31:52 +020036 mType = type;
37 mLeash = leash;
Tarandeep Singh215929b2019-01-11 18:24:37 -080038 mSurfacePosition = surfacePosition;
Jorim Jaggib6030952018-10-23 18:31:52 +020039 }
40
41 public int getType() {
42 return mType;
43 }
44
45 public SurfaceControl getLeash() {
46 return mLeash;
47 }
48
49 public InsetsSourceControl(Parcel in) {
50 mType = in.readInt();
51 mLeash = in.readParcelable(null /* loader */);
Tarandeep Singh215929b2019-01-11 18:24:37 -080052 mSurfacePosition = in.readParcelable(null /* loader */);
53 }
54
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
63 public Point getSurfacePosition() {
64 return mSurfacePosition;
Jorim Jaggib6030952018-10-23 18:31:52 +020065 }
66
67 @Override
68 public int describeContents() {
69 return 0;
70 }
71
72 @Override
73 public void writeToParcel(Parcel dest, int flags) {
74 dest.writeInt(mType);
75 dest.writeParcelable(mLeash, 0 /* flags*/);
Tarandeep Singh215929b2019-01-11 18:24:37 -080076 dest.writeParcelable(mSurfacePosition, 0 /* flags*/);
Jorim Jaggib6030952018-10-23 18:31:52 +020077 }
78
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070079 public static final @android.annotation.NonNull Creator<InsetsSourceControl> CREATOR
Jorim Jaggib6030952018-10-23 18:31:52 +020080 = 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}