| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.smartspace.uitemplatedata; |
| 18 |
|
| 19 |
|
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 22 |
import android.annotation.SuppressLint; |
| 23 |
import android.annotation.SystemApi; |
| 24 |
import android.app.PendingIntent; |
| 25 |
import android.app.smartspace.SmartspaceUtils; |
| 26 |
import android.content.Intent; |
| 27 |
import android.os.Bundle; |
| 28 |
import android.os.Parcel; |
| 29 |
import android.os.Parcelable; |
| 30 |
import android.os.UserHandle; |
| 31 |
import android.text.TextUtils; |
| 32 |
|
| 33 |
import java.util.Objects; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
@SystemApi |
| 45 |
public final class TapAction implements Parcelable { |
| 46 |
|
| 47 |
|
| 48 |
@Nullable |
| 49 |
private final CharSequence mId; |
| 50 |
|
| 51 |
@Nullable |
| 52 |
private final Intent mIntent; |
| 53 |
|
| 54 |
@Nullable |
| 55 |
private final PendingIntent mPendingIntent; |
| 56 |
|
| 57 |
@Nullable |
| 58 |
private final UserHandle mUserHandle; |
| 59 |
|
| 60 |
@Nullable |
| 61 |
private final Bundle mExtras; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
private final boolean mShouldShowOnLockscreen; |
| 68 |
|
| 69 |
TapAction(@NonNull Parcel in) { |
| 70 |
mId = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 71 |
mIntent = in.readTypedObject(Intent.CREATOR); |
| 72 |
mPendingIntent = in.readTypedObject(PendingIntent.CREATOR); |
| 73 |
mUserHandle = in.readTypedObject(UserHandle.CREATOR); |
| 74 |
mExtras = in.readBundle(); |
| 75 |
mShouldShowOnLockscreen = in.readBoolean(); |
| 76 |
} |
| 77 |
|
| 78 |
private TapAction(@Nullable CharSequence id, @Nullable Intent intent, |
| 79 |
@Nullable PendingIntent pendingIntent, @Nullable UserHandle userHandle, |
| 80 |
@Nullable Bundle extras, boolean shouldShowOnLockscreen) { |
| 81 |
mId = id; |
| 82 |
mIntent = intent; |
| 83 |
mPendingIntent = pendingIntent; |
| 84 |
mUserHandle = userHandle; |
| 85 |
mExtras = extras; |
| 86 |
mShouldShowOnLockscreen = shouldShowOnLockscreen; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
@Nullable |
| 91 |
public CharSequence getId() { |
| 92 |
return mId; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
@SuppressLint("IntentBuilderName") |
| 97 |
@Nullable |
| 98 |
public Intent getIntent() { |
| 99 |
return mIntent; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
@Nullable |
| 104 |
public PendingIntent getPendingIntent() { |
| 105 |
return mPendingIntent; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
@Nullable |
| 110 |
public UserHandle getUserHandle() { |
| 111 |
return mUserHandle; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
@Nullable |
| 116 |
@SuppressLint("NullableCollection") |
| 117 |
public Bundle getExtras() { |
| 118 |
return mExtras; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
public boolean shouldShowOnLockscreen() { |
| 126 |
return mShouldShowOnLockscreen; |
| 127 |
} |
| 128 |
|
| 129 |
@Override |
| 130 |
public void writeToParcel(@NonNull Parcel out, int flags) { |
| 131 |
TextUtils.writeToParcel(mId, out, flags); |
| 132 |
out.writeTypedObject(mIntent, flags); |
| 133 |
out.writeTypedObject(mPendingIntent, flags); |
| 134 |
out.writeTypedObject(mUserHandle, flags); |
| 135 |
out.writeBundle(mExtras); |
| 136 |
out.writeBoolean(mShouldShowOnLockscreen); |
| 137 |
} |
| 138 |
|
| 139 |
@Override |
| 140 |
public int describeContents() { |
| 141 |
return 0; |
| 142 |
} |
| 143 |
|
| 144 |
@NonNull |
| 145 |
public static final Creator<TapAction> CREATOR = new Creator<TapAction>() { |
| 146 |
@Override |
| 147 |
public TapAction createFromParcel(Parcel in) { |
| 148 |
return new TapAction(in); |
| 149 |
} |
| 150 |
|
| 151 |
@Override |
| 152 |
public TapAction[] newArray(int size) { |
| 153 |
return new TapAction[size]; |
| 154 |
} |
| 155 |
}; |
| 156 |
|
| 157 |
@Override |
| 158 |
public boolean equals(Object o) { |
| 159 |
if (this == o) return true; |
| 160 |
if (!(o instanceof TapAction)) return false; |
| 161 |
TapAction that = (TapAction) o; |
| 162 |
return SmartspaceUtils.isEqual(mId, that.mId); |
| 163 |
} |
| 164 |
|
| 165 |
@Override |
| 166 |
public int hashCode() { |
| 167 |
return Objects.hash(mId); |
| 168 |
} |
| 169 |
|
| 170 |
@Override |
| 171 |
public String toString() { |
| 172 |
return "SmartspaceTapAction{" |
| 173 |
+ "mId=" + mId |
| 174 |
+ "mIntent=" + mIntent |
| 175 |
+ ", mPendingIntent=" + mPendingIntent |
| 176 |
+ ", mUserHandle=" + mUserHandle |
| 177 |
+ ", mExtras=" + mExtras |
| 178 |
+ ", mShouldShowOnLockscreen=" + mShouldShowOnLockscreen |
| 179 |
+ '}'; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
@SystemApi |
| 188 |
public static final class Builder { |
| 189 |
|
| 190 |
private CharSequence mId; |
| 191 |
private Intent mIntent; |
| 192 |
private PendingIntent mPendingIntent; |
| 193 |
private UserHandle mUserHandle; |
| 194 |
private Bundle mExtras; |
| 195 |
private boolean mShouldShowOnLockScreen; |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
public Builder(@NonNull CharSequence id) { |
| 203 |
mId = Objects.requireNonNull(id); |
| 204 |
mShouldShowOnLockScreen = false; |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
@NonNull |
| 211 |
public Builder setIntent(@NonNull Intent intent) { |
| 212 |
mIntent = intent; |
| 213 |
return this; |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
@NonNull |
| 220 |
public Builder setPendingIntent(@NonNull PendingIntent pendingIntent) { |
| 221 |
mPendingIntent = pendingIntent; |
| 222 |
return this; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
@NonNull |
| 229 |
@SuppressLint("UserHandleName") |
| 230 |
public Builder setUserHandle(@Nullable UserHandle userHandle) { |
| 231 |
mUserHandle = userHandle; |
| 232 |
return this; |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
@NonNull |
| 239 |
public Builder setExtras(@NonNull Bundle extras) { |
| 240 |
mExtras = extras; |
| 241 |
return this; |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
@NonNull |
| 249 |
public Builder setShouldShowOnLockscreen(@NonNull boolean shouldShowOnLockScreen) { |
| 250 |
mShouldShowOnLockScreen = shouldShowOnLockScreen; |
| 251 |
return this; |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
@NonNull |
| 260 |
public TapAction build() { |
| 261 |
if (mIntent == null && mPendingIntent == null && mExtras == null) { |
| 262 |
throw new IllegalStateException("Please assign at least 1 valid tap field"); |
| 263 |
} |
| 264 |
return new TapAction(mId, mIntent, mPendingIntent, mUserHandle, mExtras, |
| 265 |
mShouldShowOnLockScreen); |
| 266 |
} |
| 267 |
} |
| 268 |
} |