Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 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; |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 32 | private final Point mSurfacePosition; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 33 | |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 34 | public InsetsSourceControl(@InternalInsetType int type, SurfaceControl leash, |
| 35 | Point surfacePosition) { |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 36 | mType = type; |
| 37 | mLeash = leash; |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 38 | mSurfacePosition = surfacePosition; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 39 | } |
| 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 Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 52 | 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 Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 65 | } |
| 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 Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 76 | dest.writeParcelable(mSurfacePosition, 0 /* flags*/); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | public static final 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 | } |