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.os.Parcel; 23 import android.os.Parcelable; 24 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 28 /** 29 * A representation of an app target event. 30 * 31 * @hide 32 */ 33 @SystemApi 34 public final class AppTargetEvent implements Parcelable { 35 36 /** 37 * @hide 38 */ 39 @IntDef({ACTION_LAUNCH, ACTION_DISMISS, ACTION_PIN, ACTION_UNPIN}) 40 @Retention(RetentionPolicy.SOURCE) 41 public @interface ActionType {} 42 43 /** 44 * Event type constant indicating an app target has been launched. 45 */ 46 public static final int ACTION_LAUNCH = 1; 47 48 /** 49 * Event type constant indicating an app target has been dismissed. 50 */ 51 public static final int ACTION_DISMISS = 2; 52 53 /** 54 * Event type constant indicating an app target has been pinned. 55 */ 56 public static final int ACTION_PIN = 3; 57 58 /** 59 * Event type constant indicating an app target has been un-pinned. 60 */ 61 public static final int ACTION_UNPIN = 4; 62 63 /** 64 * Event type constant indicating an app target has been un-dismissed. 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 AppTargetEvent(@ullable AppTarget target, @Nullable String location, @ActionType int actionType)72 private AppTargetEvent(@Nullable AppTarget target, @Nullable String location, 73 @ActionType int actionType) { 74 mTarget = target; 75 mLocation = location; 76 mAction = actionType; 77 } 78 AppTargetEvent(Parcel parcel)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 * Returns the app target. 87 */ 88 @Nullable getTarget()89 public AppTarget getTarget() { 90 return mTarget; 91 } 92 93 /** 94 * Returns the launch location. 95 */ 96 @Nullable getLaunchLocation()97 public String getLaunchLocation() { 98 return mLocation; 99 } 100 101 /** 102 * Returns the action type. 103 */ getAction()104 public @ActionType int getAction() { 105 return mAction; 106 } 107 108 @Override equals(@ullable Object o)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 describeContents()119 public int describeContents() { 120 return 0; 121 } 122 123 @Override writeToParcel(Parcel dest, int flags)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 * A builder for app target events. 143 * 144 * @hide 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 * @param target The app target that is associated with this event. 154 * @param actionType The event type, which is one of the values in {@link ActionType}. 155 */ Builder(@ullable AppTarget target, @ActionType int actionType)156 public Builder(@Nullable AppTarget target, @ActionType int actionType) { 157 mTarget = target; 158 mAction = actionType; 159 } 160 161 /** 162 * Sets the launch location. 163 */ 164 @NonNull setLaunchLocation(@ullable String location)165 public Builder setLaunchLocation(@Nullable String location) { 166 mLocation = location; 167 return this; 168 } 169 170 /** 171 * Builds a new event instance. 172 */ 173 @NonNull build()174 public AppTargetEvent build() { 175 return new AppTargetEvent(mTarget, mLocation, mAction); 176 } 177 } 178 } 179