Debian Codegraph @

libs/WindowManager/Shell/src/com/android/wm/shell/util/SplitBounds.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 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 package com.android.wm.shell.util;
17
18 import android.graphics.Rect;
19 import android.os.Parcel;
20 import android.os.Parcelable;
21
22 import java.util.Objects;
23
24 /**
25 * Container of various information needed to display split screen
26 * tasks/leashes/etc in Launcher
27 */
28 public class SplitBounds implements Parcelable {
29 public final Rect leftTopBounds;
30 public final Rect rightBottomBounds;
31 /** This rect represents the actual gap between the two apps */
32 public final Rect visualDividerBounds;
33 // This class is orientation-agnostic, so we compute both for later use
34 public final float topTaskPercent;
35 public final float leftTaskPercent;
36 public final float dividerWidthPercent;
37 public final float dividerHeightPercent;
38 /**
39 * If {@code true}, that means at the time of creation of this object, the
40 * split-screened apps were vertically stacked. This is useful in scenarios like
41 * rotation where the bounds won't change, but this variable can indicate what orientation
42 * the bounds were originally in
43 */
44 public final boolean appsStackedVertically;
45 public final int leftTopTaskId;
46 public final int rightBottomTaskId;
47
48 public SplitBounds(Rect leftTopBounds, Rect rightBottomBounds,
49 int leftTopTaskId, int rightBottomTaskId) {
50 this.leftTopBounds = leftTopBounds;
51 this.rightBottomBounds = rightBottomBounds;
52 this.leftTopTaskId = leftTopTaskId;
53 this.rightBottomTaskId = rightBottomTaskId;
54
55 if (rightBottomBounds.top > leftTopBounds.top) {
56 // vertical apps, horizontal divider
57 this.visualDividerBounds = new Rect(leftTopBounds.left, leftTopBounds.bottom,
58 leftTopBounds.right, rightBottomBounds.top);
59 appsStackedVertically = true;
60 } else {
61 // horizontal apps, vertical divider
62 this.visualDividerBounds = new Rect(leftTopBounds.right, leftTopBounds.top,
63 rightBottomBounds.left, leftTopBounds.bottom);
64 appsStackedVertically = false;
65 }
66
67 float totalWidth = rightBottomBounds.right - leftTopBounds.left;
68 float totalHeight = rightBottomBounds.bottom - leftTopBounds.top;
69 leftTaskPercent = leftTopBounds.width() / totalWidth;
70 topTaskPercent = leftTopBounds.height() / totalHeight;
71 dividerWidthPercent = visualDividerBounds.width() / totalWidth;
72 dividerHeightPercent = visualDividerBounds.height() / totalHeight;
73 }
74
75 public SplitBounds(Parcel parcel) {
76 leftTopBounds = parcel.readTypedObject(Rect.CREATOR);
77 rightBottomBounds = parcel.readTypedObject(Rect.CREATOR);
78 visualDividerBounds = parcel.readTypedObject(Rect.CREATOR);
79 topTaskPercent = parcel.readFloat();
80 leftTaskPercent = parcel.readFloat();
81 appsStackedVertically = parcel.readBoolean();
82 leftTopTaskId = parcel.readInt();
83 rightBottomTaskId = parcel.readInt();
84 dividerWidthPercent = parcel.readInt();
85 dividerHeightPercent = parcel.readInt();
86 }
87
88 @Override
89 public void writeToParcel(Parcel parcel, int flags) {
90 parcel.writeTypedObject(leftTopBounds, flags);
91 parcel.writeTypedObject(rightBottomBounds, flags);
92 parcel.writeTypedObject(visualDividerBounds, flags);
93 parcel.writeFloat(topTaskPercent);
94 parcel.writeFloat(leftTaskPercent);
95 parcel.writeBoolean(appsStackedVertically);
96 parcel.writeInt(leftTopTaskId);
97 parcel.writeInt(rightBottomTaskId);
98 parcel.writeFloat(dividerWidthPercent);
99 parcel.writeFloat(dividerHeightPercent);
100 }
101
102 @Override
103 public int describeContents() {
104 return 0;
105 }
106
107 @Override
108 public boolean equals(Object obj) {
109 if (!(obj instanceof SplitBounds)) {
110 return false;
111 }
112 // Only need to check the base fields (the other fields are derived from these)
113 final SplitBounds other = (SplitBounds) obj;
114 return Objects.equals(leftTopBounds, other.leftTopBounds)
115 && Objects.equals(rightBottomBounds, other.rightBottomBounds)
116 && leftTopTaskId == other.leftTopTaskId
117 && rightBottomTaskId == other.rightBottomTaskId;
118 }
119
120 @Override
121 public int hashCode() {
122 return Objects.hash(leftTopBounds, rightBottomBounds, leftTopTaskId, rightBottomTaskId);
123 }
124
125 @Override
126 public String toString() {
127 return "LeftTop: " + leftTopBounds + ", taskId: " + leftTopTaskId + "\n"
128 + "RightBottom: " + rightBottomBounds + ", taskId: " + rightBottomTaskId + "\n"
129 + "Divider: " + visualDividerBounds + "\n"
130 + "AppsVertical? " + appsStackedVertically;
131 }
132
133 public static final Creator<SplitBounds> CREATOR = new Creator<SplitBounds>() {
134 @Override
135 public SplitBounds createFromParcel(Parcel in) {
136 return new SplitBounds(in);
137 }
138
139 @Override
140 public SplitBounds[] newArray(int size) {
141 return new SplitBounds[size];
142 }
143 };
144 }