blob: f519145c4aa8d577cf9e6251fbb62090578a573f [file] [log] [blame]
Sunny Goyal54e91342018-11-14 11:59:02 -08001/*
2 * Copyright (C) 2018 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 */
16package android.app.prediction;
17
18import android.annotation.IntDef;
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.SystemApi;
Winson Chung5208cbe2019-01-11 20:51:46 -080022import android.annotation.TestApi;
Sunny Goyal54e91342018-11-14 11:59:02 -080023import android.os.Parcel;
24import android.os.Parcelable;
25
26import java.lang.annotation.Retention;
27import java.lang.annotation.RetentionPolicy;
28
29/**
30 * A representation of an app target event.
Mehdi Alizadeh2f4b64a2019-03-13 21:58:58 -070031 *
Sunny Goyal54e91342018-11-14 11:59:02 -080032 * @hide
33 */
34@SystemApi
Winson Chung5208cbe2019-01-11 20:51:46 -080035@TestApi
Sunny Goyal54e91342018-11-14 11:59:02 -080036public final class AppTargetEvent implements Parcelable {
37
38 /**
39 * @hide
40 */
Shashwat Razdan842d4ee2019-11-22 15:42:29 -080041 @IntDef({ACTION_LAUNCH, ACTION_DISMISS, ACTION_PIN, ACTION_UNPIN})
Sunny Goyal54e91342018-11-14 11:59:02 -080042 @Retention(RetentionPolicy.SOURCE)
43 public @interface ActionType {}
44
45 /**
46 * Event type constant indicating an app target has been launched.
47 */
48 public static final int ACTION_LAUNCH = 1;
49
50 /**
51 * Event type constant indicating an app target has been dismissed.
52 */
53 public static final int ACTION_DISMISS = 2;
54
55 /**
56 * Event type constant indicating an app target has been pinned.
57 */
58 public static final int ACTION_PIN = 3;
59
Shashwat Razdan842d4ee2019-11-22 15:42:29 -080060 /**
61 * Event type constant indicating an app target has been un-pinned.
62 */
63 public static final int ACTION_UNPIN = 4;
64
Sunny Goyal54e91342018-11-14 11:59:02 -080065 private final AppTarget mTarget;
66 private final String mLocation;
67 private final int mAction;
68
69 private AppTargetEvent(@Nullable AppTarget target, @Nullable String location,
70 @ActionType int actionType) {
71 mTarget = target;
72 mLocation = location;
73 mAction = actionType;
74 }
75
76 private AppTargetEvent(Parcel parcel) {
77 mTarget = parcel.readParcelable(null);
78 mLocation = parcel.readString();
79 mAction = parcel.readInt();
80 }
81
82 /**
83 * Returns the app target.
84 */
85 @Nullable
86 public AppTarget getTarget() {
87 return mTarget;
88 }
89
90 /**
91 * Returns the launch location.
92 */
Mehdi Alizadeh387c7cb2019-03-05 16:36:08 -080093 @Nullable
Sunny Goyal54e91342018-11-14 11:59:02 -080094 public String getLaunchLocation() {
95 return mLocation;
96 }
97
98 /**
99 * Returns the action type.
100 */
Mehdi Alizadeh387c7cb2019-03-05 16:36:08 -0800101 public @ActionType int getAction() {
Sunny Goyal54e91342018-11-14 11:59:02 -0800102 return mAction;
103 }
104
105 @Override
Aurimas Liutikas4d1699d2019-08-28 13:01:05 -0700106 public boolean equals(@Nullable Object o) {
Winson Chung5208cbe2019-01-11 20:51:46 -0800107 if (!getClass().equals(o != null ? o.getClass() : null)) return false;
108
109 AppTargetEvent other = (AppTargetEvent) o;
110 return mTarget.equals(other.mTarget)
111 && mLocation.equals(other.mLocation)
112 && mAction == other.mAction;
113 }
114
115 @Override
Sunny Goyal54e91342018-11-14 11:59:02 -0800116 public int describeContents() {
117 return 0;
118 }
119
120 @Override
121 public void writeToParcel(Parcel dest, int flags) {
122 dest.writeParcelable(mTarget, 0);
123 dest.writeString(mLocation);
124 dest.writeInt(mAction);
125 }
126
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700127 public static final @android.annotation.NonNull Creator<AppTargetEvent> CREATOR =
Sunny Goyal54e91342018-11-14 11:59:02 -0800128 new Creator<AppTargetEvent>() {
129 public AppTargetEvent createFromParcel(Parcel parcel) {
130 return new AppTargetEvent(parcel);
131 }
132
133 public AppTargetEvent[] newArray(int size) {
134 return new AppTargetEvent[size];
135 }
136 };
137
138 /**
139 * A builder for app target events.
Mehdi Alizadeh2f4b64a2019-03-13 21:58:58 -0700140 *
Sunny Goyal54e91342018-11-14 11:59:02 -0800141 * @hide
142 */
143 @SystemApi
Winson Chung5208cbe2019-01-11 20:51:46 -0800144 @TestApi
Sunny Goyal54e91342018-11-14 11:59:02 -0800145 public static final class Builder {
146 private AppTarget mTarget;
147 private String mLocation;
148 private @ActionType int mAction;
149
Mehdi Alizadeh2f4b64a2019-03-13 21:58:58 -0700150 /**
151 * @param target The app target that is associated with this event.
152 * @param actionType The event type, which is one of the values in {@link ActionType}.
153 */
Sunny Goyal54e91342018-11-14 11:59:02 -0800154 public Builder(@Nullable AppTarget target, @ActionType int actionType) {
155 mTarget = target;
156 mAction = actionType;
157 }
158
159 /**
160 * Sets the launch location.
161 */
Mehdi Alizadeh387c7cb2019-03-05 16:36:08 -0800162 @NonNull
163 public Builder setLaunchLocation(@Nullable String location) {
Sunny Goyal54e91342018-11-14 11:59:02 -0800164 mLocation = location;
165 return this;
166 }
167
168 /**
169 * Builds a new event instance.
170 */
Mehdi Alizadeh387c7cb2019-03-05 16:36:08 -0800171 @NonNull
Sunny Goyal54e91342018-11-14 11:59:02 -0800172 public AppTargetEvent build() {
173 return new AppTargetEvent(mTarget, mLocation, mAction);
174 }
175 }
176}