| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.people; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 22 |
import android.graphics.drawable.Icon; |
| 23 |
import android.os.Parcel; |
| 24 |
import android.os.Parcelable; |
| 25 |
|
| 26 |
import java.lang.annotation.Retention; |
| 27 |
import java.lang.annotation.RetentionPolicy; |
| 28 |
import java.util.Objects; |
| 29 |
|
| 30 |
public final class ConversationStatus implements Parcelable { |
| 31 |
private static final String TAG = "ConversationStatus"; |
| 32 |
|
| 33 |
|
| 34 |
@IntDef(prefix = { "ACTIVITY_" }, value = { |
| 35 |
ACTIVITY_OTHER, |
| 36 |
ACTIVITY_BIRTHDAY, |
| 37 |
ACTIVITY_ANNIVERSARY, |
| 38 |
ACTIVITY_NEW_STORY, |
| 39 |
ACTIVITY_AUDIO, |
| 40 |
ACTIVITY_VIDEO, |
| 41 |
ACTIVITY_GAME, |
| 42 |
ACTIVITY_LOCATION, |
| 43 |
ACTIVITY_UPCOMING_BIRTHDAY |
| 44 |
}) |
| 45 |
@Retention(RetentionPolicy.SOURCE) |
| 46 |
public @interface ActivityType {} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public static final int ACTIVITY_OTHER = 0; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public static final int ACTIVITY_BIRTHDAY = 1; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public static final int ACTIVITY_ANNIVERSARY = 2; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public static final int ACTIVITY_NEW_STORY = 3; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public static final int ACTIVITY_AUDIO = 4; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public static final int ACTIVITY_VIDEO = 5; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public static final int ACTIVITY_GAME = 6; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public static final int ACTIVITY_LOCATION = 7; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public static final int ACTIVITY_UPCOMING_BIRTHDAY = 8; |
| 89 |
|
| 90 |
|
| 91 |
@IntDef(prefix = { "AVAILABILITY_" }, value = { |
| 92 |
AVAILABILITY_UNKNOWN, |
| 93 |
AVAILABILITY_AVAILABLE, |
| 94 |
AVAILABILITY_BUSY, |
| 95 |
AVAILABILITY_OFFLINE |
| 96 |
}) |
| 97 |
@Retention(RetentionPolicy.SOURCE) |
| 98 |
public @interface Availability {} |
| 99 |
|
| 100 |
public static final int AVAILABILITY_UNKNOWN = -1; |
| 101 |
public static final int AVAILABILITY_AVAILABLE = 0; |
| 102 |
public static final int AVAILABILITY_BUSY = 1; |
| 103 |
public static final int AVAILABILITY_OFFLINE = 2; |
| 104 |
|
| 105 |
private final String mId; |
| 106 |
private final int mActivity; |
| 107 |
|
| 108 |
private int mAvailability; |
| 109 |
private CharSequence mDescription; |
| 110 |
private Icon mIcon; |
| 111 |
private long mStartTimeMs; |
| 112 |
private long mEndTimeMs; |
| 113 |
|
| 114 |
private ConversationStatus(Builder b) { |
| 115 |
mId = b.mId; |
| 116 |
mActivity = b.mActivity; |
| 117 |
mAvailability = b.mAvailability; |
| 118 |
mDescription = b.mDescription; |
| 119 |
mIcon = b.mIcon; |
| 120 |
mStartTimeMs = b.mStartTimeMs; |
| 121 |
mEndTimeMs = b.mEndTimeMs; |
| 122 |
} |
| 123 |
|
| 124 |
private ConversationStatus(Parcel p) { |
| 125 |
mId = p.readString(); |
| 126 |
mActivity = p.readInt(); |
| 127 |
mAvailability = p.readInt(); |
| 128 |
mDescription = p.readCharSequence(); |
| 129 |
mIcon = p.readParcelable(Icon.class.getClassLoader(), android.graphics.drawable.Icon.class); |
| 130 |
mStartTimeMs = p.readLong(); |
| 131 |
mEndTimeMs = p.readLong(); |
| 132 |
} |
| 133 |
|
| 134 |
@Override |
| 135 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 136 |
dest.writeString(mId); |
| 137 |
dest.writeInt(mActivity); |
| 138 |
dest.writeInt(mAvailability); |
| 139 |
dest.writeCharSequence(mDescription); |
| 140 |
dest.writeParcelable(mIcon, flags); |
| 141 |
dest.writeLong(mStartTimeMs); |
| 142 |
dest.writeLong(mEndTimeMs); |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
public @NonNull String getId() { |
| 149 |
return mId; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
public @ActivityType int getActivity() { |
| 156 |
return mActivity; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public @Availability int getAvailability() { |
| 164 |
return mAvailability; |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
public @Nullable CharSequence getDescription() { |
| 171 |
return mDescription; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
public @Nullable Icon getIcon() { |
| 178 |
return mIcon; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
public long getStartTimeMillis() { |
| 185 |
return mStartTimeMs; |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
public long getEndTimeMillis() { |
| 192 |
return mEndTimeMs; |
| 193 |
} |
| 194 |
|
| 195 |
@Override |
| 196 |
public boolean equals(Object o) { |
| 197 |
if (this == o) return true; |
| 198 |
if (o == null || getClass() != o.getClass()) return false; |
| 199 |
ConversationStatus that = (ConversationStatus) o; |
| 200 |
return mActivity == that.mActivity && |
| 201 |
mAvailability == that.mAvailability && |
| 202 |
mStartTimeMs == that.mStartTimeMs && |
| 203 |
mEndTimeMs == that.mEndTimeMs && |
| 204 |
mId.equals(that.mId) && |
| 205 |
Objects.equals(mDescription, that.mDescription) && |
| 206 |
Objects.equals(mIcon, that.mIcon); |
| 207 |
} |
| 208 |
|
| 209 |
@Override |
| 210 |
public int hashCode() { |
| 211 |
return Objects.hash(mId, mActivity, mAvailability, mDescription, mIcon, mStartTimeMs, |
| 212 |
mEndTimeMs); |
| 213 |
} |
| 214 |
|
| 215 |
@Override |
| 216 |
public String toString() { |
| 217 |
return "ConversationStatus{" + |
| 218 |
"mId='" + mId + '\'' + |
| 219 |
", mActivity=" + mActivity + |
| 220 |
", mAvailability=" + mAvailability + |
| 221 |
", mDescription=" + mDescription + |
| 222 |
", mIcon=" + mIcon + |
| 223 |
", mStartTimeMs=" + mStartTimeMs + |
| 224 |
", mEndTimeMs=" + mEndTimeMs + |
| 225 |
'}'; |
| 226 |
} |
| 227 |
|
| 228 |
@Override |
| 229 |
public int describeContents() { |
| 230 |
return 0; |
| 231 |
} |
| 232 |
|
| 233 |
public static final @NonNull Creator<ConversationStatus> CREATOR |
| 234 |
= new Creator<ConversationStatus>() { |
| 235 |
public ConversationStatus createFromParcel(Parcel source) { |
| 236 |
return new ConversationStatus(source); |
| 237 |
} |
| 238 |
|
| 239 |
public ConversationStatus[] newArray(int size) { |
| 240 |
return new ConversationStatus[size]; |
| 241 |
} |
| 242 |
}; |
| 243 |
|
| 244 |
public static final class Builder { |
| 245 |
final String mId; |
| 246 |
final int mActivity; |
| 247 |
int mAvailability = AVAILABILITY_UNKNOWN; |
| 248 |
CharSequence mDescription; |
| 249 |
Icon mIcon; |
| 250 |
long mStartTimeMs = -1; |
| 251 |
long mEndTimeMs = -1; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
public Builder(@NonNull String id, @ActivityType @NonNull int activity) { |
| 260 |
mId = id; |
| 261 |
mActivity = activity; |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
public @NonNull Builder setAvailability(@Availability int availability) { |
| 270 |
mAvailability = availability; |
| 271 |
return this; |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
public @NonNull Builder setDescription(@Nullable CharSequence description) { |
| 281 |
mDescription = description; |
| 282 |
return this; |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
public @NonNull Builder setIcon(@Nullable Icon icon) { |
| 292 |
mIcon = icon; |
| 293 |
return this; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
public @NonNull Builder setStartTimeMillis(long startTimeMs) { |
| 300 |
mStartTimeMs = startTimeMs; |
| 301 |
return this; |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
public @NonNull Builder setEndTimeMillis(long endTimeMs) { |
| 311 |
mEndTimeMs = endTimeMs; |
| 312 |
return this; |
| 313 |
} |
| 314 |
|
| 315 |
public @NonNull ConversationStatus build() { |
| 316 |
return new ConversationStatus(this); |
| 317 |
} |
| 318 |
} |
| 319 |
} |