| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.display; |
| 18 |
|
| 19 |
import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 20 |
|
| 21 |
import android.annotation.IntDef; |
| 22 |
import android.annotation.Nullable; |
| 23 |
import android.graphics.Rect; |
| 24 |
import android.text.TextUtils; |
| 25 |
|
| 26 |
import java.lang.annotation.Retention; |
| 27 |
import java.util.Objects; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public final class DisplayViewport { |
| 40 |
|
| 41 |
|
| 42 |
public static final int VIEWPORT_INTERNAL = 1; |
| 43 |
public static final int VIEWPORT_EXTERNAL = 2; |
| 44 |
public static final int VIEWPORT_VIRTUAL = 3; |
| 45 |
@IntDef(prefix = { "VIEWPORT_" }, value = { |
| 46 |
VIEWPORT_INTERNAL, VIEWPORT_EXTERNAL, VIEWPORT_VIRTUAL}) |
| 47 |
@Retention(SOURCE) |
| 48 |
public @interface ViewportType {}; |
| 49 |
|
| 50 |
|
| 51 |
public boolean valid; |
| 52 |
|
| 53 |
|
| 54 |
public boolean isActive; |
| 55 |
|
| 56 |
|
| 57 |
public int displayId; |
| 58 |
|
| 59 |
|
| 60 |
public int orientation; |
| 61 |
|
| 62 |
|
| 63 |
public final Rect logicalFrame = new Rect(); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public final Rect physicalFrame = new Rect(); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public int deviceWidth; |
| 74 |
public int deviceHeight; |
| 75 |
|
| 76 |
|
| 77 |
public String uniqueId; |
| 78 |
|
| 79 |
|
| 80 |
public @Nullable Integer physicalPort; |
| 81 |
|
| 82 |
public @ViewportType int type; |
| 83 |
|
| 84 |
public void copyFrom(DisplayViewport viewport) { |
| 85 |
valid = viewport.valid; |
| 86 |
isActive = viewport.isActive; |
| 87 |
displayId = viewport.displayId; |
| 88 |
orientation = viewport.orientation; |
| 89 |
logicalFrame.set(viewport.logicalFrame); |
| 90 |
physicalFrame.set(viewport.physicalFrame); |
| 91 |
deviceWidth = viewport.deviceWidth; |
| 92 |
deviceHeight = viewport.deviceHeight; |
| 93 |
uniqueId = viewport.uniqueId; |
| 94 |
physicalPort = viewport.physicalPort; |
| 95 |
type = viewport.type; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public DisplayViewport makeCopy() { |
| 102 |
DisplayViewport dv = new DisplayViewport(); |
| 103 |
dv.copyFrom(this); |
| 104 |
return dv; |
| 105 |
} |
| 106 |
|
| 107 |
@Override |
| 108 |
public boolean equals(@Nullable Object o) { |
| 109 |
if (o == this) { |
| 110 |
return true; |
| 111 |
} |
| 112 |
|
| 113 |
if (!(o instanceof DisplayViewport)) { |
| 114 |
return false; |
| 115 |
} |
| 116 |
|
| 117 |
DisplayViewport other = (DisplayViewport) o; |
| 118 |
return valid == other.valid |
| 119 |
&& isActive == other.isActive |
| 120 |
&& displayId == other.displayId |
| 121 |
&& orientation == other.orientation |
| 122 |
&& logicalFrame.equals(other.logicalFrame) |
| 123 |
&& physicalFrame.equals(other.physicalFrame) |
| 124 |
&& deviceWidth == other.deviceWidth |
| 125 |
&& deviceHeight == other.deviceHeight |
| 126 |
&& TextUtils.equals(uniqueId, other.uniqueId) |
| 127 |
&& Objects.equals(physicalPort, other.physicalPort) |
| 128 |
&& type == other.type; |
| 129 |
} |
| 130 |
|
| 131 |
@Override |
| 132 |
public int hashCode() { |
| 133 |
final int prime = 31; |
| 134 |
int result = 1; |
| 135 |
result += prime * result + (valid ? 1 : 0); |
| 136 |
result += prime * result + (isActive ? 1 : 0); |
| 137 |
result += prime * result + displayId; |
| 138 |
result += prime * result + orientation; |
| 139 |
result += prime * result + logicalFrame.hashCode(); |
| 140 |
result += prime * result + physicalFrame.hashCode(); |
| 141 |
result += prime * result + deviceWidth; |
| 142 |
result += prime * result + deviceHeight; |
| 143 |
result += prime * result + uniqueId.hashCode(); |
| 144 |
if (physicalPort != null) { |
| 145 |
result += prime * result + physicalPort.hashCode(); |
| 146 |
} |
| 147 |
result += prime * result + type; |
| 148 |
return result; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
@Override |
| 153 |
public String toString() { |
| 154 |
return "DisplayViewport{type=" + typeToString(type) |
| 155 |
+ ", valid=" + valid |
| 156 |
+ ", isActive=" + isActive |
| 157 |
+ ", displayId=" + displayId |
| 158 |
+ ", uniqueId='" + uniqueId + "'" |
| 159 |
+ ", physicalPort=" + physicalPort |
| 160 |
+ ", orientation=" + orientation |
| 161 |
+ ", logicalFrame=" + logicalFrame |
| 162 |
+ ", physicalFrame=" + physicalFrame |
| 163 |
+ ", deviceWidth=" + deviceWidth |
| 164 |
+ ", deviceHeight=" + deviceHeight |
| 165 |
+ "}"; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
public static String typeToString(@ViewportType int viewportType) { |
| 172 |
switch (viewportType) { |
| 173 |
case VIEWPORT_INTERNAL: |
| 174 |
return "INTERNAL"; |
| 175 |
case VIEWPORT_EXTERNAL: |
| 176 |
return "EXTERNAL"; |
| 177 |
case VIEWPORT_VIRTUAL: |
| 178 |
return "VIRTUAL"; |
| 179 |
default: |
| 180 |
return "UNKNOWN (" + viewportType + ")"; |
| 181 |
} |
| 182 |
} |
| 183 |
} |