Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 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; |
Winson Chung | 5208cbe | 2019-01-11 20:51:46 -0800 | [diff] [blame] | 22 | import android.annotation.TestApi; |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 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 | * @hide |
| 32 | */ |
| 33 | @SystemApi |
Winson Chung | 5208cbe | 2019-01-11 20:51:46 -0800 | [diff] [blame] | 34 | @TestApi |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 35 | public final class AppTargetEvent implements Parcelable { |
| 36 | |
| 37 | /** |
| 38 | * @hide |
| 39 | */ |
| 40 | @IntDef({ACTION_LAUNCH, ACTION_DISMISS, ACTION_PIN}) |
| 41 | @Retention(RetentionPolicy.SOURCE) |
| 42 | public @interface ActionType {} |
| 43 | |
| 44 | /** |
| 45 | * Event type constant indicating an app target has been launched. |
| 46 | */ |
| 47 | public static final int ACTION_LAUNCH = 1; |
| 48 | |
| 49 | /** |
| 50 | * Event type constant indicating an app target has been dismissed. |
| 51 | */ |
| 52 | public static final int ACTION_DISMISS = 2; |
| 53 | |
| 54 | /** |
| 55 | * Event type constant indicating an app target has been pinned. |
| 56 | */ |
| 57 | public static final int ACTION_PIN = 3; |
| 58 | |
| 59 | private final AppTarget mTarget; |
| 60 | private final String mLocation; |
| 61 | private final int mAction; |
| 62 | |
| 63 | private AppTargetEvent(@Nullable AppTarget target, @Nullable String location, |
| 64 | @ActionType int actionType) { |
| 65 | mTarget = target; |
| 66 | mLocation = location; |
| 67 | mAction = actionType; |
| 68 | } |
| 69 | |
| 70 | private AppTargetEvent(Parcel parcel) { |
| 71 | mTarget = parcel.readParcelable(null); |
| 72 | mLocation = parcel.readString(); |
| 73 | mAction = parcel.readInt(); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the app target. |
| 78 | */ |
| 79 | @Nullable |
| 80 | public AppTarget getTarget() { |
| 81 | return mTarget; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Returns the launch location. |
| 86 | */ |
| 87 | @NonNull |
| 88 | public String getLaunchLocation() { |
| 89 | return mLocation; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Returns the action type. |
| 94 | */ |
| 95 | @NonNull |
| 96 | public int getAction() { |
| 97 | return mAction; |
| 98 | } |
| 99 | |
| 100 | @Override |
Winson Chung | 5208cbe | 2019-01-11 20:51:46 -0800 | [diff] [blame] | 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 |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 111 | 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 | |
| 122 | /** |
| 123 | * @see Creator |
| 124 | */ |
| 125 | public static final Creator<AppTargetEvent> CREATOR = |
| 126 | new Creator<AppTargetEvent>() { |
| 127 | public AppTargetEvent createFromParcel(Parcel parcel) { |
| 128 | return new AppTargetEvent(parcel); |
| 129 | } |
| 130 | |
| 131 | public AppTargetEvent[] newArray(int size) { |
| 132 | return new AppTargetEvent[size]; |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | /** |
| 137 | * A builder for app target events. |
| 138 | * @hide |
| 139 | */ |
| 140 | @SystemApi |
Winson Chung | 5208cbe | 2019-01-11 20:51:46 -0800 | [diff] [blame] | 141 | @TestApi |
Sunny Goyal | 54e9134 | 2018-11-14 11:59:02 -0800 | [diff] [blame] | 142 | public static final class Builder { |
| 143 | private AppTarget mTarget; |
| 144 | private String mLocation; |
| 145 | private @ActionType int mAction; |
| 146 | |
| 147 | public Builder(@Nullable AppTarget target, @ActionType int actionType) { |
| 148 | mTarget = target; |
| 149 | mAction = actionType; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Sets the launch location. |
| 154 | */ |
| 155 | public Builder setLaunchLocation(String location) { |
| 156 | mLocation = location; |
| 157 | return this; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Builds a new event instance. |
| 162 | */ |
| 163 | public AppTargetEvent build() { |
| 164 | return new AppTargetEvent(mTarget, mLocation, mAction); |
| 165 | } |
| 166 | } |
| 167 | } |