| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 26 |
|
| 27 |
|
| 28 |
public class SplitBounds implements Parcelable { |
| 29 |
public final Rect leftTopBounds; |
| 30 |
public final Rect rightBottomBounds; |
| 31 |
|
| 32 |
public final Rect visualDividerBounds; |
| 33 |
|
| 34 |
public final float topTaskPercent; |
| 35 |
public final float leftTaskPercent; |
| 36 |
public final float dividerWidthPercent; |
| 37 |
public final float dividerHeightPercent; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 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 |
|
| 57 |
this.visualDividerBounds = new Rect(leftTopBounds.left, leftTopBounds.bottom, |
| 58 |
leftTopBounds.right, rightBottomBounds.top); |
| 59 |
appsStackedVertically = true; |
| 60 |
} else { |
| 61 |
|
| 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 |
|
| 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 |
} |