| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view; |
| 18 |
|
| 19 |
import static android.graphics.PointProto.X; |
| 20 |
import static android.graphics.PointProto.Y; |
| 21 |
import static android.view.InsetsSourceControlProto.LEASH; |
| 22 |
import static android.view.InsetsSourceControlProto.POSITION; |
| 23 |
import static android.view.InsetsSourceControlProto.TYPE; |
| 24 |
|
| 25 |
import android.annotation.Nullable; |
| 26 |
import android.graphics.Insets; |
| 27 |
import android.graphics.Point; |
| 28 |
import android.os.Parcel; |
| 29 |
import android.os.Parcelable; |
| 30 |
import android.util.proto.ProtoOutputStream; |
| 31 |
import android.view.InsetsState.InternalInsetsType; |
| 32 |
|
| 33 |
import java.io.PrintWriter; |
| 34 |
import java.util.Objects; |
| 35 |
import java.util.function.Consumer; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class InsetsSourceControl implements Parcelable { |
| 42 |
|
| 43 |
private final @InternalInsetsType int mType; |
| 44 |
private final @Nullable SurfaceControl mLeash; |
| 45 |
private final boolean mInitiallyVisible; |
| 46 |
private final Point mSurfacePosition; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
private Insets mInsetsHint; |
| 51 |
|
| 52 |
private boolean mSkipAnimationOnce; |
| 53 |
private int mParcelableFlags; |
| 54 |
|
| 55 |
public InsetsSourceControl(@InternalInsetsType int type, @Nullable SurfaceControl leash, |
| 56 |
boolean initiallyVisible, Point surfacePosition, Insets insetsHint) { |
| 57 |
mType = type; |
| 58 |
mLeash = leash; |
| 59 |
mInitiallyVisible = initiallyVisible; |
| 60 |
mSurfacePosition = surfacePosition; |
| 61 |
mInsetsHint = insetsHint; |
| 62 |
} |
| 63 |
|
| 64 |
public InsetsSourceControl(InsetsSourceControl other) { |
| 65 |
mType = other.mType; |
| 66 |
if (other.mLeash != null) { |
| 67 |
mLeash = new SurfaceControl(other.mLeash, "InsetsSourceControl"); |
| 68 |
} else { |
| 69 |
mLeash = null; |
| 70 |
} |
| 71 |
mInitiallyVisible = other.mInitiallyVisible; |
| 72 |
mSurfacePosition = new Point(other.mSurfacePosition); |
| 73 |
mInsetsHint = other.mInsetsHint; |
| 74 |
mSkipAnimationOnce = other.getAndClearSkipAnimationOnce(); |
| 75 |
} |
| 76 |
|
| 77 |
public InsetsSourceControl(Parcel in) { |
| 78 |
mType = in.readInt(); |
| 79 |
mLeash = in.readTypedObject(SurfaceControl.CREATOR); |
| 80 |
mInitiallyVisible = in.readBoolean(); |
| 81 |
mSurfacePosition = in.readTypedObject(Point.CREATOR); |
| 82 |
mInsetsHint = in.readTypedObject(Insets.CREATOR); |
| 83 |
mSkipAnimationOnce = in.readBoolean(); |
| 84 |
} |
| 85 |
|
| 86 |
public int getType() { |
| 87 |
return mType; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public @Nullable SurfaceControl getLeash() { |
| 97 |
return mLeash; |
| 98 |
} |
| 99 |
|
| 100 |
public boolean isInitiallyVisible() { |
| 101 |
return mInitiallyVisible; |
| 102 |
} |
| 103 |
|
| 104 |
public boolean setSurfacePosition(int left, int top) { |
| 105 |
if (mSurfacePosition.equals(left, top)) { |
| 106 |
return false; |
| 107 |
} |
| 108 |
mSurfacePosition.set(left, top); |
| 109 |
return true; |
| 110 |
} |
| 111 |
|
| 112 |
public Point getSurfacePosition() { |
| 113 |
return mSurfacePosition; |
| 114 |
} |
| 115 |
|
| 116 |
public void setInsetsHint(Insets insets) { |
| 117 |
mInsetsHint = insets; |
| 118 |
} |
| 119 |
|
| 120 |
public void setInsetsHint(int left, int top, int right, int bottom) { |
| 121 |
mInsetsHint = Insets.of(left, top, right, bottom); |
| 122 |
} |
| 123 |
|
| 124 |
public Insets getInsetsHint() { |
| 125 |
return mInsetsHint; |
| 126 |
} |
| 127 |
|
| 128 |
public void setSkipAnimationOnce(boolean skipAnimation) { |
| 129 |
mSkipAnimationOnce = skipAnimation; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
public boolean getAndClearSkipAnimationOnce() { |
| 140 |
final boolean result = mSkipAnimationOnce; |
| 141 |
mSkipAnimationOnce = false; |
| 142 |
return result; |
| 143 |
} |
| 144 |
|
| 145 |
public void setParcelableFlags(int parcelableFlags) { |
| 146 |
mParcelableFlags = parcelableFlags; |
| 147 |
} |
| 148 |
|
| 149 |
@Override |
| 150 |
public int describeContents() { |
| 151 |
return 0; |
| 152 |
} |
| 153 |
|
| 154 |
@Override |
| 155 |
public void writeToParcel(Parcel dest, int flags) { |
| 156 |
dest.writeInt(mType); |
| 157 |
dest.writeTypedObject(mLeash, mParcelableFlags); |
| 158 |
dest.writeBoolean(mInitiallyVisible); |
| 159 |
dest.writeTypedObject(mSurfacePosition, mParcelableFlags); |
| 160 |
dest.writeTypedObject(mInsetsHint, mParcelableFlags); |
| 161 |
dest.writeBoolean(mSkipAnimationOnce); |
| 162 |
} |
| 163 |
|
| 164 |
public void release(Consumer<SurfaceControl> surfaceReleaseConsumer) { |
| 165 |
if (mLeash != null) { |
| 166 |
surfaceReleaseConsumer.accept(mLeash); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
@Override |
| 171 |
public boolean equals(@Nullable Object o) { |
| 172 |
if (this == o) { |
| 173 |
return true; |
| 174 |
} |
| 175 |
if (o == null || getClass() != o.getClass()) { |
| 176 |
return false; |
| 177 |
} |
| 178 |
final InsetsSourceControl that = (InsetsSourceControl) o; |
| 179 |
final SurfaceControl thatLeash = that.mLeash; |
| 180 |
return mType == that.mType |
| 181 |
&& ((mLeash == thatLeash) |
| 182 |
|| (mLeash != null && thatLeash != null && mLeash.isSameSurface(thatLeash))) |
| 183 |
&& mInitiallyVisible == that.mInitiallyVisible |
| 184 |
&& mSurfacePosition.equals(that.mSurfacePosition) |
| 185 |
&& mInsetsHint.equals(that.mInsetsHint) |
| 186 |
&& mSkipAnimationOnce == that.mSkipAnimationOnce; |
| 187 |
} |
| 188 |
|
| 189 |
@Override |
| 190 |
public int hashCode() { |
| 191 |
return Objects.hash(mType, mLeash, mInitiallyVisible, mSurfacePosition, mInsetsHint, |
| 192 |
mSkipAnimationOnce); |
| 193 |
} |
| 194 |
|
| 195 |
@Override |
| 196 |
public String toString() { |
| 197 |
return "InsetsSourceControl: {" |
| 198 |
+ "type=" + InsetsState.typeToString(mType) |
| 199 |
+ ", mSurfacePosition=" + mSurfacePosition |
| 200 |
+ ", mInsetsHint=" + mInsetsHint |
| 201 |
+ "}"; |
| 202 |
} |
| 203 |
|
| 204 |
public void dump(String prefix, PrintWriter pw) { |
| 205 |
pw.print(prefix); |
| 206 |
pw.print("InsetsSourceControl type="); pw.print(InsetsState.typeToString(mType)); |
| 207 |
pw.print(" mLeash="); pw.print(mLeash); |
| 208 |
pw.print(" mInitiallyVisible="); pw.print(mInitiallyVisible); |
| 209 |
pw.print(" mSurfacePosition="); pw.print(mSurfacePosition); |
| 210 |
pw.print(" mInsetsHint="); pw.print(mInsetsHint); |
| 211 |
pw.print(" mSkipAnimationOnce="); pw.print(mSkipAnimationOnce); |
| 212 |
pw.println(); |
| 213 |
} |
| 214 |
|
| 215 |
public static final @android.annotation.NonNull Creator<InsetsSourceControl> CREATOR |
| 216 |
= new Creator<InsetsSourceControl>() { |
| 217 |
public InsetsSourceControl createFromParcel(Parcel in) { |
| 218 |
return new InsetsSourceControl(in); |
| 219 |
} |
| 220 |
|
| 221 |
public InsetsSourceControl[] newArray(int size) { |
| 222 |
return new InsetsSourceControl[size]; |
| 223 |
} |
| 224 |
}; |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
public void dumpDebug(ProtoOutputStream proto, long fieldId) { |
| 233 |
final long token = proto.start(fieldId); |
| 234 |
proto.write(TYPE, InsetsState.typeToString(mType)); |
| 235 |
|
| 236 |
final long surfaceToken = proto.start(POSITION); |
| 237 |
proto.write(X, mSurfacePosition.x); |
| 238 |
proto.write(Y, mSurfacePosition.y); |
| 239 |
proto.end(surfaceToken); |
| 240 |
|
| 241 |
if (mLeash != null) { |
| 242 |
mLeash.dumpDebug(proto, LEASH); |
| 243 |
} |
| 244 |
proto.end(token); |
| 245 |
} |
| 246 |
} |