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 | |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 20 | import android.graphics.Point; |
| 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | import android.view.InsetsState.InternalInsetType; |
| 24 | |
| 25 | /** |
| 26 | * Represents a parcelable object to allow controlling a single {@link InsetsSource}. |
| 27 | * @hide |
| 28 | */ |
| 29 | public class InsetsSourceControl implements Parcelable { |
| 30 | |
| 31 | private final @InternalInsetType int mType; |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 32 | private final @Nullable SurfaceControl mLeash; |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 33 | private final Point mSurfacePosition; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 34 | |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 35 | public InsetsSourceControl(@InternalInsetType int type, @Nullable SurfaceControl leash, |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 36 | Point surfacePosition) { |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 37 | mType = type; |
| 38 | mLeash = leash; |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 39 | mSurfacePosition = surfacePosition; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | public int getType() { |
| 43 | return mType; |
| 44 | } |
| 45 | |
Jorim Jaggi | a12ea56 | 2019-01-07 17:47:47 +0100 | [diff] [blame] | 46 | /** |
| 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 Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 53 | return mLeash; |
| 54 | } |
| 55 | |
| 56 | public InsetsSourceControl(Parcel in) { |
| 57 | mType = in.readInt(); |
| 58 | mLeash = in.readParcelable(null /* loader */); |
Tarandeep Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 59 | 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 Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 72 | } |
| 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 Singh | 215929b | 2019-01-11 18:24:37 -0800 | [diff] [blame] | 83 | dest.writeParcelable(mSurfacePosition, 0 /* flags*/); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 86 | public static final @android.annotation.NonNull Creator<InsetsSourceControl> CREATOR |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 87 | = 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 | } |