blob: 26ff0c17da2e723eccfea513f25d2124f3e7677d [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 */
41 @IntDef({ACTION_LAUNCH, ACTION_DISMISS, ACTION_PIN})
42 @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
60 private final AppTarget mTarget;
61 private final String mLocation;
62 private final int mAction;
63
64 private AppTargetEvent(@Nullable AppTarget target, @Nullable String location,
65 @ActionType int actionType) {
66 mTarget = target;
67 mLocation = location;
68 mAction = actionType;
69 }
70
71 private AppTargetEvent(Parcel parcel) {
72 mTarget = parcel.readParcelable(null);
73 mLocation = parcel.readString();
74 mAction = parcel.readInt();
75 }
76
77 /**
78 * Returns the app target.
79 */
80 @Nullable
81 public AppTarget getTarget() {
82 return mTarget;
83 }
84
85 /**
86 * Returns the launch location.
87 */
Mehdi Alizadeh387c7cb2019-03-05 16:36:08 -080088 @Nullable
Sunny Goyal54e91342018-11-14 11:59:02 -080089 public String getLaunchLocation() {
90 return mLocation;
91 }
92
93 /**
94 * Returns the action type.
95 */
Mehdi Alizadeh387c7cb2019-03-05 16:36:08 -080096 public @ActionType int getAction() {
Sunny Goyal54e91342018-11-14 11:59:02 -080097 return mAction;
98 }
99
100 @Override
Aurimas Liutikas4d1699d2019-08-28 13:01:05 -0700101 public boolean equals(@Nullable Object o) {
Winson Chung5208cbe2019-01-11 20:51:46 -0800102 if (!getClass().equals(o != null ? o.getClass() : null)) return false;
103
104 AppTargetEvent other = (AppTargetEvent) o;
105 return mTarget.equals(other.mTarget)
106 && mLocation.equals(other.mLocation)
107 && mAction == other.mAction;
108 }
109
110 @Override
Sunny Goyal54e91342018-11-14 11:59:02 -0800111 public int describeContents() {
112 return 0;
113 }
114
115 @Override
116 public void writeToParcel(Parcel dest, int flags) {
117 dest.writeParcelable(mTarget, 0);
118 dest.writeString(mLocation);
119 dest.writeInt(mAction);
120 }
121
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700122 public static final @android.annotation.NonNull Creator<AppTargetEvent> CREATOR =
Sunny Goyal54e91342018-11-14 11:59:02 -0800123 new Creator<AppTargetEvent>() {
124 public AppTargetEvent createFromParcel(Parcel parcel) {
125 return new AppTargetEvent(parcel);
126 }
127
128 public AppTargetEvent[] newArray(int size) {
129 return new AppTargetEvent[size];
130 }
131 };
132
133 /**
134 * A builder for app target events.
Mehdi Alizadeh2f4b64a2019-03-13 21:58:58 -0700135 *
Sunny Goyal54e91342018-11-14 11:59:02 -0800136 * @hide
137 */
138 @SystemApi
Winson Chung5208cbe2019-01-11 20:51:46 -0800139 @TestApi
Sunny Goyal54e91342018-11-14 11:59:02 -0800140 public static final class Builder {
141 private AppTarget mTarget;
142 private String mLocation;
143 private @ActionType int mAction;
144
Mehdi Alizadeh2f4b64a2019-03-13 21:58:58 -0700145 /**
146 * @param target The app target that is associated with this event.
147 * @param actionType The event type, which is one of the values in {@link ActionType}.
148 */
Sunny Goyal54e91342018-11-14 11:59:02 -0800149 public Builder(@Nullable AppTarget target, @ActionType int actionType) {
150 mTarget = target;
151 mAction = actionType;
152 }
153
154 /**
155 * Sets the launch location.
156 */
Mehdi Alizadeh387c7cb2019-03-05 16:36:08 -0800157 @NonNull
158 public Builder setLaunchLocation(@Nullable String location) {
Sunny Goyal54e91342018-11-14 11:59:02 -0800159 mLocation = location;
160 return this;
161 }
162
163 /**
164 * Builds a new event instance.
165 */
Mehdi Alizadeh387c7cb2019-03-05 16:36:08 -0800166 @NonNull
Sunny Goyal54e91342018-11-14 11:59:02 -0800167 public AppTargetEvent build() {
168 return new AppTargetEvent(mTarget, mLocation, mAction);
169 }
170 }
171}