| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package android.app.prediction; |
| 17 |
|
| 18 |
import android.annotation.IntDef; |
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.annotation.SystemApi; |
| 22 |
import android.os.Parcel; |
| 23 |
import android.os.Parcelable; |
| 24 |
|
| 25 |
import java.lang.annotation.Retention; |
| 26 |
import java.lang.annotation.RetentionPolicy; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
@SystemApi |
| 34 |
public final class AppTargetEvent implements Parcelable { |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
@IntDef({ACTION_LAUNCH, ACTION_DISMISS, ACTION_PIN, ACTION_UNPIN}) |
| 40 |
@Retention(RetentionPolicy.SOURCE) |
| 41 |
public @interface ActionType {} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public static final int ACTION_LAUNCH = 1; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public static final int ACTION_DISMISS = 2; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public static final int ACTION_PIN = 3; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public static final int ACTION_UNPIN = 4; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public static final int ACTION_UNDISMISS = 5; |
| 67 |
|
| 68 |
private final AppTarget mTarget; |
| 69 |
private final String mLocation; |
| 70 |
private final int mAction; |
| 71 |
|
| 72 |
private AppTargetEvent(@Nullable AppTarget target, @Nullable String location, |
| 73 |
@ActionType int actionType) { |
| 74 |
mTarget = target; |
| 75 |
mLocation = location; |
| 76 |
mAction = actionType; |
| 77 |
} |
| 78 |
|
| 79 |
private AppTargetEvent(Parcel parcel) { |
| 80 |
mTarget = parcel.readParcelable(null, android.app.prediction.AppTarget.class); |
| 81 |
mLocation = parcel.readString(); |
| 82 |
mAction = parcel.readInt(); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
@Nullable |
| 89 |
public AppTarget getTarget() { |
| 90 |
return mTarget; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
@Nullable |
| 97 |
public String getLaunchLocation() { |
| 98 |
return mLocation; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public @ActionType int getAction() { |
| 105 |
return mAction; |
| 106 |
} |
| 107 |
|
| 108 |
@Override |
| 109 |
public boolean equals(@Nullable Object o) { |
| 110 |
if (!getClass().equals(o != null ? o.getClass() : null)) return false; |
| 111 |
|
| 112 |
AppTargetEvent other = (AppTargetEvent) o; |
| 113 |
return mTarget.equals(other.mTarget) |
| 114 |
&& mLocation.equals(other.mLocation) |
| 115 |
&& mAction == other.mAction; |
| 116 |
} |
| 117 |
|
| 118 |
@Override |
| 119 |
public int describeContents() { |
| 120 |
return 0; |
| 121 |
} |
| 122 |
|
| 123 |
@Override |
| 124 |
public void writeToParcel(Parcel dest, int flags) { |
| 125 |
dest.writeParcelable(mTarget, 0); |
| 126 |
dest.writeString(mLocation); |
| 127 |
dest.writeInt(mAction); |
| 128 |
} |
| 129 |
|
| 130 |
public static final @android.annotation.NonNull Creator<AppTargetEvent> CREATOR = |
| 131 |
new Creator<AppTargetEvent>() { |
| 132 |
public AppTargetEvent createFromParcel(Parcel parcel) { |
| 133 |
return new AppTargetEvent(parcel); |
| 134 |
} |
| 135 |
|
| 136 |
public AppTargetEvent[] newArray(int size) { |
| 137 |
return new AppTargetEvent[size]; |
| 138 |
} |
| 139 |
}; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
@SystemApi |
| 147 |
public static final class Builder { |
| 148 |
private AppTarget mTarget; |
| 149 |
private String mLocation; |
| 150 |
private @ActionType int mAction; |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
public Builder(@Nullable AppTarget target, @ActionType int actionType) { |
| 157 |
mTarget = target; |
| 158 |
mAction = actionType; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
@NonNull |
| 165 |
public Builder setLaunchLocation(@Nullable String location) { |
| 166 |
mLocation = location; |
| 167 |
return this; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
@NonNull |
| 174 |
public AppTargetEvent build() { |
| 175 |
return new AppTargetEvent(mTarget, mLocation, mAction); |
| 176 |
} |
| 177 |
} |
| 178 |
} |