| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package android.app.prediction; |
| 17 |
|
| 18 |
import android.annotation.IntRange; |
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.annotation.SystemApi; |
| 22 |
import android.content.Context; |
| 23 |
import android.os.Bundle; |
| 24 |
import android.os.Parcel; |
| 25 |
import android.os.Parcelable; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
@SystemApi |
| 34 |
public final class AppPredictionContext implements Parcelable { |
| 35 |
|
| 36 |
private final int mPredictedTargetCount; |
| 37 |
@NonNull |
| 38 |
private final String mUiSurface; |
| 39 |
@NonNull |
| 40 |
private final String mPackageName; |
| 41 |
@Nullable |
| 42 |
private final Bundle mExtras; |
| 43 |
|
| 44 |
private AppPredictionContext(@NonNull String uiSurface, int numPredictedTargets, |
| 45 |
@NonNull String packageName, @Nullable Bundle extras) { |
| 46 |
mUiSurface = uiSurface; |
| 47 |
mPredictedTargetCount = numPredictedTargets; |
| 48 |
mPackageName = packageName; |
| 49 |
mExtras = extras; |
| 50 |
} |
| 51 |
|
| 52 |
private AppPredictionContext(@NonNull Parcel parcel) { |
| 53 |
mUiSurface = parcel.readString(); |
| 54 |
mPredictedTargetCount = parcel.readInt(); |
| 55 |
mPackageName = parcel.readString(); |
| 56 |
mExtras = parcel.readBundle(); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
@NonNull |
| 63 |
public String getUiSurface() { |
| 64 |
return mUiSurface; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public @IntRange(from = 0) int getPredictedTargetCount() { |
| 71 |
return mPredictedTargetCount; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
@NonNull |
| 78 |
public String getPackageName() { |
| 79 |
return mPackageName; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
@Nullable |
| 86 |
public Bundle getExtras() { |
| 87 |
return mExtras; |
| 88 |
} |
| 89 |
|
| 90 |
@Override |
| 91 |
public boolean equals(@Nullable Object o) { |
| 92 |
if (o == this) return true; |
| 93 |
if (!getClass().equals(o != null ? o.getClass() : null)) return false; |
| 94 |
|
| 95 |
AppPredictionContext other = (AppPredictionContext) o; |
| 96 |
return mPredictedTargetCount == other.mPredictedTargetCount |
| 97 |
&& mUiSurface.equals(other.mUiSurface) |
| 98 |
&& mPackageName.equals(other.mPackageName); |
| 99 |
} |
| 100 |
|
| 101 |
@Override |
| 102 |
public int describeContents() { |
| 103 |
return 0; |
| 104 |
} |
| 105 |
|
| 106 |
@Override |
| 107 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 108 |
dest.writeString(mUiSurface); |
| 109 |
dest.writeInt(mPredictedTargetCount); |
| 110 |
dest.writeString(mPackageName); |
| 111 |
dest.writeBundle(mExtras); |
| 112 |
} |
| 113 |
|
| 114 |
public static final @android.annotation.NonNull Parcelable.Creator<AppPredictionContext> CREATOR = |
| 115 |
new Parcelable.Creator<AppPredictionContext>() { |
| 116 |
public AppPredictionContext createFromParcel(Parcel parcel) { |
| 117 |
return new AppPredictionContext(parcel); |
| 118 |
} |
| 119 |
|
| 120 |
public AppPredictionContext[] newArray(int size) { |
| 121 |
return new AppPredictionContext[size]; |
| 122 |
} |
| 123 |
}; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
@SystemApi |
| 130 |
public static final class Builder { |
| 131 |
|
| 132 |
@NonNull |
| 133 |
private final String mPackageName; |
| 134 |
|
| 135 |
private int mPredictedTargetCount; |
| 136 |
@Nullable |
| 137 |
private String mUiSurface; |
| 138 |
@Nullable |
| 139 |
private Bundle mExtras; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
@SystemApi |
| 147 |
public Builder(@NonNull Context context) { |
| 148 |
mPackageName = context.getPackageName(); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
@NonNull |
| 156 |
public Builder setPredictedTargetCount(@IntRange(from = 0) int predictedTargetCount) { |
| 157 |
mPredictedTargetCount = predictedTargetCount; |
| 158 |
return this; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
@NonNull |
| 165 |
public Builder setUiSurface(@NonNull String uiSurface) { |
| 166 |
mUiSurface = uiSurface; |
| 167 |
return this; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
@NonNull |
| 174 |
public Builder setExtras(@Nullable Bundle extras) { |
| 175 |
mExtras = extras; |
| 176 |
return this; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
@NonNull |
| 183 |
public AppPredictionContext build() { |
| 184 |
return new AppPredictionContext(mUiSurface, mPredictedTargetCount, mPackageName, |
| 185 |
mExtras); |
| 186 |
} |
| 187 |
} |
| 188 |
} |