• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
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.annotation.TestApi;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 
29 /**
30  * A representation of an app target event.
31  *
32  * @hide
33  */
34 @SystemApi
35 @TestApi
36 public 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 
AppTargetEvent(@ullable AppTarget target, @Nullable String location, @ActionType int actionType)64     private AppTargetEvent(@Nullable AppTarget target, @Nullable String location,
65             @ActionType int actionType) {
66         mTarget = target;
67         mLocation = location;
68         mAction = actionType;
69     }
70 
AppTargetEvent(Parcel parcel)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
getTarget()81     public AppTarget getTarget() {
82         return mTarget;
83     }
84 
85     /**
86      * Returns the launch location.
87      */
88     @Nullable
getLaunchLocation()89     public String getLaunchLocation() {
90         return mLocation;
91     }
92 
93     /**
94      * Returns the action type.
95      */
getAction()96     public @ActionType int getAction() {
97         return mAction;
98     }
99 
100     @Override
equals(Object o)101     public boolean equals(Object o) {
102         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
describeContents()111     public int describeContents() {
112         return 0;
113     }
114 
115     @Override
writeToParcel(Parcel dest, int flags)116     public void writeToParcel(Parcel dest, int flags) {
117         dest.writeParcelable(mTarget, 0);
118         dest.writeString(mLocation);
119         dest.writeInt(mAction);
120     }
121 
122     public static final @android.annotation.NonNull Creator<AppTargetEvent> CREATOR =
123             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.
135      *
136      * @hide
137      */
138     @SystemApi
139     @TestApi
140     public static final class Builder {
141         private AppTarget mTarget;
142         private String mLocation;
143         private @ActionType int mAction;
144 
145         /**
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          */
Builder(@ullable AppTarget target, @ActionType int actionType)149         public Builder(@Nullable AppTarget target, @ActionType int actionType) {
150             mTarget = target;
151             mAction = actionType;
152         }
153 
154         /**
155          * Sets the launch location.
156          */
157         @NonNull
setLaunchLocation(@ullable String location)158         public Builder setLaunchLocation(@Nullable String location) {
159             mLocation = location;
160             return this;
161         }
162 
163         /**
164          * Builds a new event instance.
165          */
166         @NonNull
build()167         public AppTargetEvent build() {
168             return new AppTargetEvent(mTarget, mLocation, mAction);
169         }
170     }
171 }
172