blob: 4919074ec252ededc57eb6d43f51cc568cd99024 [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
Jorim Jaggia12ea562019-01-07 17:47:47 +010019import android.annotation.Nullable;
Jorim Jaggib6030952018-10-23 18:31:52 +020020import android.graphics.Point;
21import android.os.Parcel;
22import android.os.Parcelable;
23import android.view.InsetsState.InternalInsetType;
24
25/**
26 * Represents a parcelable object to allow controlling a single {@link InsetsSource}.
27 * @hide
28 */
29public class InsetsSourceControl implements Parcelable {
30
31 private final @InternalInsetType int mType;
Jorim Jaggia12ea562019-01-07 17:47:47 +010032 private final @Nullable SurfaceControl mLeash;
Tarandeep Singh215929b2019-01-11 18:24:37 -080033 private final Point mSurfacePosition;
Jorim Jaggib6030952018-10-23 18:31:52 +020034
Jorim Jaggia12ea562019-01-07 17:47:47 +010035 public InsetsSourceControl(@InternalInsetType int type, @Nullable SurfaceControl leash,
Tarandeep Singh215929b2019-01-11 18:24:37 -080036 Point surfacePosition) {
Jorim Jaggib6030952018-10-23 18:31:52 +020037 mType = type;
38 mLeash = leash;
Tarandeep Singh215929b2019-01-11 18:24:37 -080039 mSurfacePosition = surfacePosition;
Jorim Jaggib6030952018-10-23 18:31:52 +020040 }
41
42 public int getType() {
43 return mType;
44 }
45
Jorim Jaggia12ea562019-01-07 17:47:47 +010046 /**
47 * Gets the leash for controlling insets source. If the system is controlling the insets source,
48 * for example, transient bars, the client will receive fake controls without leash in it.
49 *
50 * @return the leash.
51 */
52 public @Nullable SurfaceControl getLeash() {
Jorim Jaggib6030952018-10-23 18:31:52 +020053 return mLeash;
54 }
55
56 public InsetsSourceControl(Parcel in) {
57 mType = in.readInt();
58 mLeash = in.readParcelable(null /* loader */);
Tarandeep Singh215929b2019-01-11 18:24:37 -080059 mSurfacePosition = in.readParcelable(null /* loader */);
60 }
61
62 public boolean setSurfacePosition(int left, int top) {
63 if (mSurfacePosition.equals(left, top)) {
64 return false;
65 }
66 mSurfacePosition.set(left, top);
67 return true;
68 }
69
70 public Point getSurfacePosition() {
71 return mSurfacePosition;
Jorim Jaggib6030952018-10-23 18:31:52 +020072 }
73
74 @Override
75 public int describeContents() {
76 return 0;
77 }
78
79 @Override
80 public void writeToParcel(Parcel dest, int flags) {
81 dest.writeInt(mType);
82 dest.writeParcelable(mLeash, 0 /* flags*/);
Tarandeep Singh215929b2019-01-11 18:24:37 -080083 dest.writeParcelable(mSurfacePosition, 0 /* flags*/);
Jorim Jaggib6030952018-10-23 18:31:52 +020084 }
85
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070086 public static final @android.annotation.NonNull Creator<InsetsSourceControl> CREATOR
Jorim Jaggib6030952018-10-23 18:31:52 +020087 = new Creator<InsetsSourceControl>() {
88 public InsetsSourceControl createFromParcel(Parcel in) {
89 return new InsetsSourceControl(in);
90 }
91
92 public InsetsSourceControl[] newArray(int size) {
93 return new InsetsSourceControl[size];
94 }
95 };
96}