| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package android.view.contentcapture; |
| 17 |
|
| 18 |
import android.annotation.IntDef; |
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.content.LocusId; |
| 22 |
import android.os.Parcel; |
| 23 |
import android.os.Parcelable; |
| 24 |
import android.util.DebugUtils; |
| 25 |
|
| 26 |
import java.lang.annotation.Retention; |
| 27 |
import java.lang.annotation.RetentionPolicy; |
| 28 |
import java.util.Objects; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public final class ContentCaptureCondition implements Parcelable { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public static final int FLAG_IS_REGEX = 0x2; |
| 42 |
|
| 43 |
|
| 44 |
@IntDef(prefix = { "FLAG" }, flag = true, value = { |
| 45 |
FLAG_IS_REGEX |
| 46 |
}) |
| 47 |
@Retention(RetentionPolicy.SOURCE) |
| 48 |
@interface Flags {} |
| 49 |
|
| 50 |
private final @NonNull LocusId mLocusId; |
| 51 |
private final @Flags int mFlags; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public ContentCaptureCondition(@NonNull LocusId locusId, @Flags int flags) { |
| 63 |
this.mLocusId = Objects.requireNonNull(locusId); |
| 64 |
this.mFlags = flags; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
@NonNull |
| 71 |
public LocusId getLocusId() { |
| 72 |
return mLocusId; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public @Flags int getFlags() { |
| 81 |
return mFlags; |
| 82 |
} |
| 83 |
|
| 84 |
@Override |
| 85 |
public int hashCode() { |
| 86 |
final int prime = 31; |
| 87 |
int result = 1; |
| 88 |
result = prime * result + mFlags; |
| 89 |
result = prime * result + ((mLocusId == null) ? 0 : mLocusId.hashCode()); |
| 90 |
return result; |
| 91 |
} |
| 92 |
|
| 93 |
@Override |
| 94 |
public boolean equals(@Nullable Object obj) { |
| 95 |
if (this == obj) return true; |
| 96 |
if (obj == null) return false; |
| 97 |
if (getClass() != obj.getClass()) return false; |
| 98 |
final ContentCaptureCondition other = (ContentCaptureCondition) obj; |
| 99 |
if (mFlags != other.mFlags) return false; |
| 100 |
if (mLocusId == null) { |
| 101 |
if (other.mLocusId != null) return false; |
| 102 |
} else { |
| 103 |
if (!mLocusId.equals(other.mLocusId)) return false; |
| 104 |
} |
| 105 |
return true; |
| 106 |
} |
| 107 |
|
| 108 |
@Override |
| 109 |
public String toString() { |
| 110 |
final StringBuilder string = new StringBuilder(mLocusId.toString()); |
| 111 |
if (mFlags != 0) { |
| 112 |
string |
| 113 |
.append(" (") |
| 114 |
.append(DebugUtils.flagsToString(ContentCaptureCondition.class, "FLAG_", mFlags)) |
| 115 |
.append(')'); |
| 116 |
} |
| 117 |
return string.toString(); |
| 118 |
} |
| 119 |
|
| 120 |
@Override |
| 121 |
public int describeContents() { |
| 122 |
return 0; |
| 123 |
} |
| 124 |
|
| 125 |
@Override |
| 126 |
public void writeToParcel(@NonNull Parcel parcel, int flags) { |
| 127 |
parcel.writeParcelable(mLocusId, flags); |
| 128 |
parcel.writeInt(mFlags); |
| 129 |
} |
| 130 |
|
| 131 |
public static final @NonNull Parcelable.Creator<ContentCaptureCondition> CREATOR = |
| 132 |
new Parcelable.Creator<ContentCaptureCondition>() { |
| 133 |
|
| 134 |
@Override |
| 135 |
public ContentCaptureCondition createFromParcel(@NonNull Parcel parcel) { |
| 136 |
return new ContentCaptureCondition(parcel.readParcelable(null, android.content.LocusId.class), |
| 137 |
parcel.readInt()); |
| 138 |
} |
| 139 |
|
| 140 |
@Override |
| 141 |
public ContentCaptureCondition[] newArray(int size) { |
| 142 |
return new ContentCaptureCondition[size]; |
| 143 |
} |
| 144 |
}; |
| 145 |
} |