| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view; |
| 18 |
|
| 19 |
import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 20 |
|
| 21 |
import android.annotation.IntDef; |
| 22 |
import android.annotation.NonNull; |
| 23 |
import android.annotation.Nullable; |
| 24 |
import android.annotation.SuppressLint; |
| 25 |
import android.os.Parcel; |
| 26 |
import android.os.Parcelable; |
| 27 |
|
| 28 |
import java.lang.annotation.Retention; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
@SuppressLint("ParcelNotFinal") |
| 40 |
public abstract class VerifiedInputEvent implements Parcelable { |
| 41 |
private static final String TAG = "VerifiedInputEvent"; |
| 42 |
|
| 43 |
|
| 44 |
protected static final int VERIFIED_KEY = 1; |
| 45 |
|
| 46 |
protected static final int VERIFIED_MOTION = 2; |
| 47 |
|
| 48 |
|
| 49 |
@Retention(SOURCE) |
| 50 |
@IntDef(prefix = "VERIFIED", value = {VERIFIED_KEY, VERIFIED_MOTION}) |
| 51 |
public @interface VerifiedInputEventType {}; |
| 52 |
|
| 53 |
@VerifiedInputEventType |
| 54 |
private int mType; |
| 55 |
|
| 56 |
private int mDeviceId; |
| 57 |
private long mEventTimeNanos; |
| 58 |
private int mSource; |
| 59 |
private int mDisplayId; |
| 60 |
|
| 61 |
|
| 62 |
protected VerifiedInputEvent(int type, int deviceId, long eventTimeNanos, int source, |
| 63 |
int displayId) { |
| 64 |
mType = type; |
| 65 |
mDeviceId = deviceId; |
| 66 |
mEventTimeNanos = eventTimeNanos; |
| 67 |
mSource = source; |
| 68 |
mDisplayId = displayId; |
| 69 |
} |
| 70 |
|
| 71 |
protected VerifiedInputEvent(@NonNull Parcel in, int expectedType) { |
| 72 |
mType = in.readInt(); |
| 73 |
if (mType != expectedType) { |
| 74 |
throw new IllegalArgumentException("Unexpected input event type token in parcel."); |
| 75 |
} |
| 76 |
mDeviceId = in.readInt(); |
| 77 |
mEventTimeNanos = in.readLong(); |
| 78 |
mSource = in.readInt(); |
| 79 |
mDisplayId = in.readInt(); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public int getDeviceId() { |
| 88 |
return mDeviceId; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
@SuppressLint("MethodNameUnits") |
| 98 |
public long getEventTimeNanos() { |
| 99 |
return mEventTimeNanos; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public int getSource() { |
| 108 |
return mSource; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public int getDisplayId() { |
| 117 |
return mDisplayId; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
@Override |
| 122 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 123 |
dest.writeInt(mType); |
| 124 |
dest.writeInt(mDeviceId); |
| 125 |
dest.writeLong(mEventTimeNanos); |
| 126 |
dest.writeInt(mSource); |
| 127 |
dest.writeInt(mDisplayId); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
@Override |
| 132 |
public int describeContents() { |
| 133 |
return 0; |
| 134 |
} |
| 135 |
|
| 136 |
private static int peekInt(@NonNull Parcel parcel) { |
| 137 |
final int initialDataPosition = parcel.dataPosition(); |
| 138 |
int data = parcel.readInt(); |
| 139 |
parcel.setDataPosition(initialDataPosition); |
| 140 |
return data; |
| 141 |
} |
| 142 |
|
| 143 |
public static final @NonNull Parcelable.Creator<VerifiedInputEvent> CREATOR = |
| 144 |
new Parcelable.Creator<VerifiedInputEvent>() { |
| 145 |
@Override |
| 146 |
public VerifiedInputEvent[] newArray(int size) { |
| 147 |
return new VerifiedInputEvent[size]; |
| 148 |
} |
| 149 |
|
| 150 |
@Override |
| 151 |
public VerifiedInputEvent createFromParcel(@NonNull Parcel in) { |
| 152 |
final int type = peekInt(in); |
| 153 |
if (type == VERIFIED_KEY) { |
| 154 |
return VerifiedKeyEvent.CREATOR.createFromParcel(in); |
| 155 |
} else if (type == VERIFIED_MOTION) { |
| 156 |
return VerifiedMotionEvent.CREATOR.createFromParcel(in); |
| 157 |
} |
| 158 |
throw new IllegalArgumentException("Unexpected input event type in parcel."); |
| 159 |
} |
| 160 |
}; |
| 161 |
|
| 162 |
@Override |
| 163 |
public boolean equals(@Nullable Object o) { |
| 164 |
if (this == o) return true; |
| 165 |
if (o == null || getClass() != o.getClass()) return false; |
| 166 |
@SuppressWarnings("unchecked") |
| 167 |
VerifiedInputEvent that = (VerifiedInputEvent) o; |
| 168 |
return mType == that.mType |
| 169 |
&& getDeviceId() == that.getDeviceId() |
| 170 |
&& getEventTimeNanos() == that.getEventTimeNanos() |
| 171 |
&& getSource() == that.getSource() |
| 172 |
&& getDisplayId() == that.getDisplayId(); |
| 173 |
} |
| 174 |
|
| 175 |
@Override |
| 176 |
public int hashCode() { |
| 177 |
int _hash = 1; |
| 178 |
_hash = 31 * _hash + mType; |
| 179 |
_hash = 31 * _hash + getDeviceId(); |
| 180 |
_hash = 31 * _hash + Long.hashCode(getEventTimeNanos()); |
| 181 |
_hash = 31 * _hash + getSource(); |
| 182 |
_hash = 31 * _hash + getDisplayId(); |
| 183 |
return _hash; |
| 184 |
} |
| 185 |
} |