Debian Codegraph @

core/java/android/view/PrivacyIndicatorBounds.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
17 package android.view;
18
19 import static android.view.Surface.ROTATION_0;
20
21 import android.annotation.NonNull;
22 import android.annotation.Nullable;
23 import android.graphics.Rect;
24 import android.os.Parcelable;
25
26 import com.android.internal.util.ArrayUtils;
27 import com.android.internal.util.DataClass;
28
29 /**
30 * A class which manages the bounds of the privacy indicator
31 *
32 * @hide
33 */
34 @DataClass(
35 genEqualsHashCode = true,
36 genConstructor = false,
37 genAidl = false,
38 genGetters = false
39 )
40 public class PrivacyIndicatorBounds implements Parcelable {
41
42 private final @NonNull Rect[] mStaticBounds;
43 private final int mRotation;
44
45 public PrivacyIndicatorBounds() {
46 mStaticBounds = new Rect[4];
47 mRotation = ROTATION_0;
48 }
49
50 public PrivacyIndicatorBounds(@NonNull Rect[] staticBounds, @Surface.Rotation int rotation) {
51 mStaticBounds = staticBounds;
52 mRotation = rotation;
53 }
54
55 /**
56 * Return a PrivacyIndicatorBounds with updated static bounds
57 */
58 public PrivacyIndicatorBounds updateStaticBounds(@NonNull Rect[] staticPositions) {
59 return new PrivacyIndicatorBounds(staticPositions, mRotation);
60 }
61
62 /**
63 * Update the bounds of the indicator for a specific rotation, or ROTATION_0, if the provided
64 * rotation integer isn't found
65 */
66 public PrivacyIndicatorBounds updateBoundsForRotation(@Nullable Rect bounds,
67 @Surface.Rotation int rotation) {
68 if (rotation >= mStaticBounds.length || rotation < 0) {
69 return this;
70 }
71 Rect[] newBounds = ArrayUtils.cloneOrNull(mStaticBounds);
72 newBounds[rotation] = bounds;
73 return updateStaticBounds(newBounds);
74 }
75
76 /**
77 * Return an inset PrivacyIndicatorBounds
78 */
79 public PrivacyIndicatorBounds inset(int insetLeft, int insetTop, int insetRight,
80 int insetBottom) {
81 if (insetLeft == 0 && insetTop == 0 && insetRight == 0 && insetBottom == 0) {
82 return this;
83 }
84 Rect[] insetStaticBounds = new Rect[mStaticBounds.length];
85 for (int i = 0; i < mStaticBounds.length; i++) {
86 insetStaticBounds[i] =
87 insetRect(mStaticBounds[i], insetLeft, insetTop, insetRight, insetBottom);
88 }
89 return updateStaticBounds(insetStaticBounds);
90 }
91
92 private static Rect insetRect(Rect orig, int insetLeft, int insetTop, int insetRight,
93 int insetBottom) {
94 if (orig == null) {
95 return null;
96 }
97 int left = Math.max(0, orig.left - insetLeft);
98 int top = Math.max(0, orig.top - insetTop);
99 int right = Math.max(left, orig.right - insetRight);
100 int bottom = Math.max(top, orig.bottom - insetBottom);
101 return new Rect(left, top, right, bottom);
102 }
103
104 /**
105 * Return a PrivacyIndicatorBounds with the static position rotated.
106 */
107 public PrivacyIndicatorBounds rotate(@Surface.Rotation int rotation) {
108 if (rotation == ROTATION_0) {
109 return this;
110 }
111 return new PrivacyIndicatorBounds(mStaticBounds, rotation);
112 }
113
114 /**
115 * Returns a scaled PrivacyIndicatorBounds
116 */
117 public PrivacyIndicatorBounds scale(float scale) {
118 if (scale == 1f) {
119 return this;
120 }
121
122 Rect[] scaledStaticPos = new Rect[mStaticBounds.length];
123 for (int i = 0; i < mStaticBounds.length; i++) {
124 scaledStaticPos[i] = scaleRect(mStaticBounds[i], scale);
125 }
126 return new PrivacyIndicatorBounds(scaledStaticPos, mRotation);
127 }
128
129 private static Rect scaleRect(Rect orig, float scale) {
130 if (orig == null) {
131 return null;
132 }
133
134 Rect newRect = new Rect(orig);
135 newRect.scale(scale);
136 return newRect;
137 }
138
139 public Rect getStaticPrivacyIndicatorBounds() {
140 return mStaticBounds[mRotation];
141 }
142
143 @Override
144 public String toString() {
145 return "PrivacyIndicatorBounds {static bounds=" + getStaticPrivacyIndicatorBounds()
146 + " rotation=" + mRotation + "}";
147 }
148
149
150
151 // Code below generated by codegen v1.0.23.
152 //
153 // DO NOT MODIFY!
154 // CHECKSTYLE:OFF Generated code
155 //
156 // To regenerate run:
157 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/view/PrivacyIndicatorBounds.java
158 //
159 // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
160 // Settings > Editor > Code Style > Formatter Control
161 //@formatter:off
162
163
164 @Override
165 @DataClass.Generated.Member
166 public boolean equals(@Nullable Object o) {
167 // You can override field equality logic by defining either of the methods like:
168 // boolean fieldNameEquals(PrivacyIndicatorBounds other) { ... }
169 // boolean fieldNameEquals(FieldType otherValue) { ... }
170
171 if (this == o) return true;
172 if (o == null || getClass() != o.getClass()) return false;
173 @SuppressWarnings("unchecked")
174 PrivacyIndicatorBounds that = (PrivacyIndicatorBounds) o;
175 //noinspection PointlessBooleanExpression
176 return true
177 && java.util.Arrays.equals(mStaticBounds, that.mStaticBounds)
178 && mRotation == that.mRotation;
179 }
180
181 @Override
182 @DataClass.Generated.Member
183 public int hashCode() {
184 // You can override field hashCode logic by defining methods like:
185 // int fieldNameHashCode() { ... }
186
187 int _hash = 1;
188 _hash = 31 * _hash + java.util.Arrays.hashCode(mStaticBounds);
189 _hash = 31 * _hash + mRotation;
190 return _hash;
191 }
192
193 @Override
194 @DataClass.Generated.Member
195 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
196 // You can override field parcelling by defining methods like:
197 // void parcelFieldName(Parcel dest, int flags) { ... }
198
199 dest.writeTypedArray(mStaticBounds, flags);
200 dest.writeInt(mRotation);
201 }
202
203 @Override
204 @DataClass.Generated.Member
205 public int describeContents() { return 0; }
206
207 /** @hide */
208 @SuppressWarnings({"unchecked", "RedundantCast"})
209 @DataClass.Generated.Member
210 protected PrivacyIndicatorBounds(@NonNull android.os.Parcel in) {
211 // You can override field unparcelling by defining methods like:
212 // static FieldType unparcelFieldName(Parcel in) { ... }
213
214 Rect[] staticBounds = (Rect[]) in.createTypedArray(Rect.CREATOR);
215 int rotation = in.readInt();
216
217 this.mStaticBounds = staticBounds;
218 com.android.internal.util.AnnotationValidations.validate(
219 NonNull.class, null, mStaticBounds);
220 this.mRotation = rotation;
221
222 // onConstructed(); // You can define this method to get a callback
223 }
224
225 @DataClass.Generated.Member
226 public static final @NonNull Parcelable.Creator<PrivacyIndicatorBounds> CREATOR
227 = new Parcelable.Creator<PrivacyIndicatorBounds>() {
228 @Override
229 public PrivacyIndicatorBounds[] newArray(int size) {
230 return new PrivacyIndicatorBounds[size];
231 }
232
233 @Override
234 public PrivacyIndicatorBounds createFromParcel(@NonNull android.os.Parcel in) {
235 return new PrivacyIndicatorBounds(in);
236 }
237 };
238
239 @DataClass.Generated(
240 time = 1621526273838L,
241 codegenVersion = "1.0.23",
242 sourceFile = "frameworks/base/core/java/android/view/PrivacyIndicatorBounds.java",
243 inputSignatures = "private final @android.annotation.NonNull android.graphics.Rect[] mStaticBounds\nprivate final int mRotation\npublic android.view.PrivacyIndicatorBounds updateStaticBounds(android.graphics.Rect[])\npublic android.view.PrivacyIndicatorBounds updateBoundsForRotation(android.graphics.Rect,int)\npublic android.view.PrivacyIndicatorBounds inset(int,int,int,int)\nprivate static android.graphics.Rect insetRect(android.graphics.Rect,int,int,int,int)\npublic android.view.PrivacyIndicatorBounds rotate(int)\npublic android.view.PrivacyIndicatorBounds scale(float)\nprivate static android.graphics.Rect scaleRect(android.graphics.Rect,float)\npublic android.graphics.Rect getStaticPrivacyIndicatorBounds()\npublic @java.lang.Override java.lang.String toString()\nclass PrivacyIndicatorBounds extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genConstructor=false, genAidl=false, genGetters=false)")
244 @Deprecated
245 private void __metadata() {}
246
247
248 //@formatter:on
249 // End of generated code
250
251 }