| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.controls; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 22 |
import android.annotation.SuppressLint; |
| 23 |
import android.app.PendingIntent; |
| 24 |
import android.content.Intent; |
| 25 |
import android.content.res.ColorStateList; |
| 26 |
import android.graphics.drawable.Icon; |
| 27 |
import android.os.Parcel; |
| 28 |
import android.os.Parcelable; |
| 29 |
import android.service.controls.actions.ControlAction; |
| 30 |
import android.service.controls.templates.ControlTemplate; |
| 31 |
import android.service.controls.templates.ControlTemplateWrapper; |
| 32 |
import android.util.Log; |
| 33 |
|
| 34 |
import com.android.internal.util.Preconditions; |
| 35 |
|
| 36 |
import java.lang.annotation.Retention; |
| 37 |
import java.lang.annotation.RetentionPolicy; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public final class Control implements Parcelable { |
| 60 |
private static final String TAG = "Control"; |
| 61 |
|
| 62 |
private static final int NUM_STATUS = 5; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
@Retention(RetentionPolicy.SOURCE) |
| 67 |
@IntDef({ |
| 68 |
STATUS_UNKNOWN, |
| 69 |
STATUS_OK, |
| 70 |
STATUS_NOT_FOUND, |
| 71 |
STATUS_ERROR, |
| 72 |
STATUS_DISABLED, |
| 73 |
}) |
| 74 |
public @interface Status {}; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public static final int STATUS_UNKNOWN = 0; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public static final int STATUS_OK = 1; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public static final int STATUS_NOT_FOUND = 2; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
public static final int STATUS_ERROR = 3; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public static final int STATUS_DISABLED = 4; |
| 109 |
|
| 110 |
private final @NonNull String mControlId; |
| 111 |
private final @DeviceTypes.DeviceType int mDeviceType; |
| 112 |
private final @NonNull CharSequence mTitle; |
| 113 |
private final @NonNull CharSequence mSubtitle; |
| 114 |
private final @Nullable CharSequence mStructure; |
| 115 |
private final @Nullable CharSequence mZone; |
| 116 |
private final @NonNull PendingIntent mAppIntent; |
| 117 |
|
| 118 |
private final @Nullable Icon mCustomIcon; |
| 119 |
private final @Nullable ColorStateList mCustomColor; |
| 120 |
|
| 121 |
private final @Status int mStatus; |
| 122 |
private final @NonNull ControlTemplate mControlTemplate; |
| 123 |
private final @NonNull CharSequence mStatusText; |
| 124 |
private final boolean mAuthRequired; |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
Control(@NonNull String controlId, |
| 145 |
@DeviceTypes.DeviceType int deviceType, |
| 146 |
@NonNull CharSequence title, |
| 147 |
@NonNull CharSequence subtitle, |
| 148 |
@Nullable CharSequence structure, |
| 149 |
@Nullable CharSequence zone, |
| 150 |
@NonNull PendingIntent appIntent, |
| 151 |
@Nullable Icon customIcon, |
| 152 |
@Nullable ColorStateList customColor, |
| 153 |
@Status int status, |
| 154 |
@NonNull ControlTemplate controlTemplate, |
| 155 |
@NonNull CharSequence statusText, |
| 156 |
boolean authRequired) { |
| 157 |
Preconditions.checkNotNull(controlId); |
| 158 |
Preconditions.checkNotNull(title); |
| 159 |
Preconditions.checkNotNull(subtitle); |
| 160 |
Preconditions.checkNotNull(appIntent); |
| 161 |
Preconditions.checkNotNull(controlTemplate); |
| 162 |
Preconditions.checkNotNull(statusText); |
| 163 |
mControlId = controlId; |
| 164 |
if (!DeviceTypes.validDeviceType(deviceType)) { |
| 165 |
Log.e(TAG, "Invalid device type:" + deviceType); |
| 166 |
mDeviceType = DeviceTypes.TYPE_UNKNOWN; |
| 167 |
} else { |
| 168 |
mDeviceType = deviceType; |
| 169 |
} |
| 170 |
mTitle = title; |
| 171 |
mSubtitle = subtitle; |
| 172 |
mStructure = structure; |
| 173 |
mZone = zone; |
| 174 |
mAppIntent = appIntent; |
| 175 |
|
| 176 |
mCustomColor = customColor; |
| 177 |
mCustomIcon = customIcon; |
| 178 |
|
| 179 |
if (status < 0 || status >= NUM_STATUS) { |
| 180 |
mStatus = STATUS_UNKNOWN; |
| 181 |
Log.e(TAG, "Status unknown:" + status); |
| 182 |
} else { |
| 183 |
mStatus = status; |
| 184 |
} |
| 185 |
mControlTemplate = controlTemplate; |
| 186 |
mStatusText = statusText; |
| 187 |
mAuthRequired = authRequired; |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
Control(Parcel in) { |
| 195 |
mControlId = in.readString(); |
| 196 |
mDeviceType = in.readInt(); |
| 197 |
mTitle = in.readCharSequence(); |
| 198 |
mSubtitle = in.readCharSequence(); |
| 199 |
if (in.readByte() == (byte) 1) { |
| 200 |
mStructure = in.readCharSequence(); |
| 201 |
} else { |
| 202 |
mStructure = null; |
| 203 |
} |
| 204 |
if (in.readByte() == (byte) 1) { |
| 205 |
mZone = in.readCharSequence(); |
| 206 |
} else { |
| 207 |
mZone = null; |
| 208 |
} |
| 209 |
mAppIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 210 |
|
| 211 |
if (in.readByte() == (byte) 1) { |
| 212 |
mCustomIcon = Icon.CREATOR.createFromParcel(in); |
| 213 |
} else { |
| 214 |
mCustomIcon = null; |
| 215 |
} |
| 216 |
|
| 217 |
if (in.readByte() == (byte) 1) { |
| 218 |
mCustomColor = ColorStateList.CREATOR.createFromParcel(in); |
| 219 |
} else { |
| 220 |
mCustomColor = null; |
| 221 |
} |
| 222 |
|
| 223 |
mStatus = in.readInt(); |
| 224 |
ControlTemplateWrapper wrapper = ControlTemplateWrapper.CREATOR.createFromParcel(in); |
| 225 |
mControlTemplate = wrapper.getWrappedTemplate(); |
| 226 |
mStatusText = in.readCharSequence(); |
| 227 |
mAuthRequired = in.readBoolean(); |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
@NonNull |
| 234 |
public String getControlId() { |
| 235 |
return mControlId; |
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
@DeviceTypes.DeviceType |
| 244 |
public int getDeviceType() { |
| 245 |
return mDeviceType; |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
@NonNull |
| 252 |
public CharSequence getTitle() { |
| 253 |
return mTitle; |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
@NonNull |
| 260 |
public CharSequence getSubtitle() { |
| 261 |
return mSubtitle; |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
@Nullable |
| 272 |
public CharSequence getStructure() { |
| 273 |
return mStructure; |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
@Nullable |
| 283 |
public CharSequence getZone() { |
| 284 |
return mZone; |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
@NonNull |
| 291 |
public PendingIntent getAppIntent() { |
| 292 |
return mAppIntent; |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
@Nullable |
| 302 |
public Icon getCustomIcon() { |
| 303 |
return mCustomIcon; |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
@Nullable |
| 314 |
public ColorStateList getCustomColor() { |
| 315 |
return mCustomColor; |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
@Status |
| 323 |
public int getStatus() { |
| 324 |
return mStatus; |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
@NonNull |
| 332 |
public ControlTemplate getControlTemplate() { |
| 333 |
return mControlTemplate; |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
@NonNull |
| 341 |
public CharSequence getStatusText() { |
| 342 |
return mStatusText; |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
public boolean isAuthRequired() { |
| 349 |
return mAuthRequired; |
| 350 |
} |
| 351 |
|
| 352 |
@Override |
| 353 |
public int describeContents() { |
| 354 |
return 0; |
| 355 |
} |
| 356 |
|
| 357 |
@Override |
| 358 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 359 |
dest.writeString(mControlId); |
| 360 |
dest.writeInt(mDeviceType); |
| 361 |
dest.writeCharSequence(mTitle); |
| 362 |
dest.writeCharSequence(mSubtitle); |
| 363 |
if (mStructure != null) { |
| 364 |
dest.writeByte((byte) 1); |
| 365 |
dest.writeCharSequence(mStructure); |
| 366 |
} else { |
| 367 |
dest.writeByte((byte) 0); |
| 368 |
} |
| 369 |
if (mZone != null) { |
| 370 |
dest.writeByte((byte) 1); |
| 371 |
dest.writeCharSequence(mZone); |
| 372 |
} else { |
| 373 |
dest.writeByte((byte) 0); |
| 374 |
} |
| 375 |
mAppIntent.writeToParcel(dest, flags); |
| 376 |
if (mCustomIcon != null) { |
| 377 |
dest.writeByte((byte) 1); |
| 378 |
mCustomIcon.writeToParcel(dest, flags); |
| 379 |
} else { |
| 380 |
dest.writeByte((byte) 0); |
| 381 |
} |
| 382 |
if (mCustomColor != null) { |
| 383 |
dest.writeByte((byte) 1); |
| 384 |
mCustomColor.writeToParcel(dest, flags); |
| 385 |
} else { |
| 386 |
dest.writeByte((byte) 0); |
| 387 |
} |
| 388 |
|
| 389 |
dest.writeInt(mStatus); |
| 390 |
new ControlTemplateWrapper(mControlTemplate).writeToParcel(dest, flags); |
| 391 |
dest.writeCharSequence(mStatusText); |
| 392 |
dest.writeBoolean(mAuthRequired); |
| 393 |
} |
| 394 |
|
| 395 |
public static final @NonNull Creator<Control> CREATOR = new Creator<Control>() { |
| 396 |
@Override |
| 397 |
public Control createFromParcel(@NonNull Parcel source) { |
| 398 |
return new Control(source); |
| 399 |
} |
| 400 |
|
| 401 |
@Override |
| 402 |
public Control[] newArray(int size) { |
| 403 |
return new Control[size]; |
| 404 |
} |
| 405 |
}; |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
@SuppressLint("MutableBareField") |
| 430 |
public static final class StatelessBuilder { |
| 431 |
private static final String TAG = "StatelessBuilder"; |
| 432 |
private @NonNull String mControlId; |
| 433 |
private @DeviceTypes.DeviceType int mDeviceType = DeviceTypes.TYPE_UNKNOWN; |
| 434 |
private @NonNull CharSequence mTitle = ""; |
| 435 |
private @NonNull CharSequence mSubtitle = ""; |
| 436 |
private @Nullable CharSequence mStructure; |
| 437 |
private @Nullable CharSequence mZone; |
| 438 |
private @NonNull PendingIntent mAppIntent; |
| 439 |
private @Nullable Icon mCustomIcon; |
| 440 |
private @Nullable ColorStateList mCustomColor; |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
public StatelessBuilder(@NonNull String controlId, |
| 447 |
@NonNull PendingIntent appIntent) { |
| 448 |
Preconditions.checkNotNull(controlId); |
| 449 |
Preconditions.checkNotNull(appIntent); |
| 450 |
mControlId = controlId; |
| 451 |
mAppIntent = appIntent; |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
public StatelessBuilder(@NonNull Control control) { |
| 460 |
Preconditions.checkNotNull(control); |
| 461 |
mControlId = control.mControlId; |
| 462 |
mDeviceType = control.mDeviceType; |
| 463 |
mTitle = control.mTitle; |
| 464 |
mSubtitle = control.mSubtitle; |
| 465 |
mStructure = control.mStructure; |
| 466 |
mZone = control.mZone; |
| 467 |
mAppIntent = control.mAppIntent; |
| 468 |
mCustomIcon = control.mCustomIcon; |
| 469 |
mCustomColor = control.mCustomColor; |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
@NonNull |
| 477 |
public StatelessBuilder setControlId(@NonNull String controlId) { |
| 478 |
Preconditions.checkNotNull(controlId); |
| 479 |
mControlId = controlId; |
| 480 |
return this; |
| 481 |
} |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
@NonNull |
| 489 |
public StatelessBuilder setDeviceType(@DeviceTypes.DeviceType int deviceType) { |
| 490 |
if (!DeviceTypes.validDeviceType(deviceType)) { |
| 491 |
Log.e(TAG, "Invalid device type:" + deviceType); |
| 492 |
mDeviceType = DeviceTypes.TYPE_UNKNOWN; |
| 493 |
} else { |
| 494 |
mDeviceType = deviceType; |
| 495 |
} |
| 496 |
return this; |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
@NonNull |
| 504 |
public StatelessBuilder setTitle(@NonNull CharSequence title) { |
| 505 |
Preconditions.checkNotNull(title); |
| 506 |
mTitle = title; |
| 507 |
return this; |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
@NonNull |
| 516 |
public StatelessBuilder setSubtitle(@NonNull CharSequence subtitle) { |
| 517 |
Preconditions.checkNotNull(subtitle); |
| 518 |
mSubtitle = subtitle; |
| 519 |
return this; |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
@NonNull |
| 531 |
public StatelessBuilder setStructure(@Nullable CharSequence structure) { |
| 532 |
mStructure = structure; |
| 533 |
return this; |
| 534 |
} |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
@NonNull |
| 544 |
public StatelessBuilder setZone(@Nullable CharSequence zone) { |
| 545 |
mZone = zone; |
| 546 |
return this; |
| 547 |
} |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
@NonNull |
| 554 |
public StatelessBuilder setAppIntent(@NonNull PendingIntent appIntent) { |
| 555 |
Preconditions.checkNotNull(appIntent); |
| 556 |
mAppIntent = appIntent; |
| 557 |
return this; |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
@NonNull |
| 568 |
public StatelessBuilder setCustomIcon(@Nullable Icon customIcon) { |
| 569 |
mCustomIcon = customIcon; |
| 570 |
return this; |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
@NonNull |
| 582 |
public StatelessBuilder setCustomColor(@Nullable ColorStateList customColor) { |
| 583 |
mCustomColor = customColor; |
| 584 |
return this; |
| 585 |
} |
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
@NonNull |
| 591 |
public Control build() { |
| 592 |
return new Control(mControlId, |
| 593 |
mDeviceType, |
| 594 |
mTitle, |
| 595 |
mSubtitle, |
| 596 |
mStructure, |
| 597 |
mZone, |
| 598 |
mAppIntent, |
| 599 |
mCustomIcon, |
| 600 |
mCustomColor, |
| 601 |
STATUS_UNKNOWN, |
| 602 |
ControlTemplate.NO_TEMPLATE, |
| 603 |
"", |
| 604 |
true ); |
| 605 |
} |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
public static final class StatefulBuilder { |
| 630 |
private static final String TAG = "StatefulBuilder"; |
| 631 |
private @NonNull String mControlId; |
| 632 |
private @DeviceTypes.DeviceType int mDeviceType = DeviceTypes.TYPE_UNKNOWN; |
| 633 |
private @NonNull CharSequence mTitle = ""; |
| 634 |
private @NonNull CharSequence mSubtitle = ""; |
| 635 |
private @Nullable CharSequence mStructure; |
| 636 |
private @Nullable CharSequence mZone; |
| 637 |
private @NonNull PendingIntent mAppIntent; |
| 638 |
private @Nullable Icon mCustomIcon; |
| 639 |
private @Nullable ColorStateList mCustomColor; |
| 640 |
private @Status int mStatus = STATUS_UNKNOWN; |
| 641 |
private @NonNull ControlTemplate mControlTemplate = ControlTemplate.NO_TEMPLATE; |
| 642 |
private @NonNull CharSequence mStatusText = ""; |
| 643 |
private boolean mAuthRequired = true; |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
public StatefulBuilder(@NonNull String controlId, |
| 650 |
@NonNull PendingIntent appIntent) { |
| 651 |
Preconditions.checkNotNull(controlId); |
| 652 |
Preconditions.checkNotNull(appIntent); |
| 653 |
mControlId = controlId; |
| 654 |
mAppIntent = appIntent; |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
public StatefulBuilder(@NonNull Control control) { |
| 663 |
Preconditions.checkNotNull(control); |
| 664 |
mControlId = control.mControlId; |
| 665 |
mDeviceType = control.mDeviceType; |
| 666 |
mTitle = control.mTitle; |
| 667 |
mSubtitle = control.mSubtitle; |
| 668 |
mStructure = control.mStructure; |
| 669 |
mZone = control.mZone; |
| 670 |
mAppIntent = control.mAppIntent; |
| 671 |
mCustomIcon = control.mCustomIcon; |
| 672 |
mCustomColor = control.mCustomColor; |
| 673 |
mStatus = control.mStatus; |
| 674 |
mControlTemplate = control.mControlTemplate; |
| 675 |
mStatusText = control.mStatusText; |
| 676 |
mAuthRequired = control.mAuthRequired; |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
@NonNull |
| 684 |
public StatefulBuilder setControlId(@NonNull String controlId) { |
| 685 |
Preconditions.checkNotNull(controlId); |
| 686 |
mControlId = controlId; |
| 687 |
return this; |
| 688 |
} |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
@NonNull |
| 696 |
public StatefulBuilder setDeviceType(@DeviceTypes.DeviceType int deviceType) { |
| 697 |
if (!DeviceTypes.validDeviceType(deviceType)) { |
| 698 |
Log.e(TAG, "Invalid device type:" + deviceType); |
| 699 |
mDeviceType = DeviceTypes.TYPE_UNKNOWN; |
| 700 |
} else { |
| 701 |
mDeviceType = deviceType; |
| 702 |
} |
| 703 |
return this; |
| 704 |
} |
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
@NonNull |
| 711 |
public StatefulBuilder setTitle(@NonNull CharSequence title) { |
| 712 |
Preconditions.checkNotNull(title); |
| 713 |
mTitle = title; |
| 714 |
return this; |
| 715 |
} |
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
@NonNull |
| 723 |
public StatefulBuilder setSubtitle(@NonNull CharSequence subtitle) { |
| 724 |
Preconditions.checkNotNull(subtitle); |
| 725 |
mSubtitle = subtitle; |
| 726 |
return this; |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
@NonNull |
| 738 |
public StatefulBuilder setStructure(@Nullable CharSequence structure) { |
| 739 |
mStructure = structure; |
| 740 |
return this; |
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
@NonNull |
| 751 |
public StatefulBuilder setZone(@Nullable CharSequence zone) { |
| 752 |
mZone = zone; |
| 753 |
return this; |
| 754 |
} |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
@NonNull |
| 761 |
public StatefulBuilder setAppIntent(@NonNull PendingIntent appIntent) { |
| 762 |
Preconditions.checkNotNull(appIntent); |
| 763 |
mAppIntent = appIntent; |
| 764 |
return this; |
| 765 |
} |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
@NonNull |
| 775 |
public StatefulBuilder setCustomIcon(@Nullable Icon customIcon) { |
| 776 |
mCustomIcon = customIcon; |
| 777 |
return this; |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
@NonNull |
| 789 |
public StatefulBuilder setCustomColor(@Nullable ColorStateList customColor) { |
| 790 |
mCustomColor = customColor; |
| 791 |
return this; |
| 792 |
} |
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
@NonNull |
| 800 |
public StatefulBuilder setStatus(@Status int status) { |
| 801 |
if (status < 0 || status >= NUM_STATUS) { |
| 802 |
mStatus = STATUS_UNKNOWN; |
| 803 |
Log.e(TAG, "Status unknown:" + status); |
| 804 |
} else { |
| 805 |
mStatus = status; |
| 806 |
} |
| 807 |
return this; |
| 808 |
} |
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
@NonNull |
| 824 |
public StatefulBuilder setControlTemplate(@NonNull ControlTemplate controlTemplate) { |
| 825 |
Preconditions.checkNotNull(controlTemplate); |
| 826 |
mControlTemplate = controlTemplate; |
| 827 |
return this; |
| 828 |
} |
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
@NonNull |
| 836 |
public StatefulBuilder setStatusText(@NonNull CharSequence statusText) { |
| 837 |
Preconditions.checkNotNull(statusText); |
| 838 |
mStatusText = statusText; |
| 839 |
return this; |
| 840 |
} |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
@NonNull |
| 848 |
public StatefulBuilder setAuthRequired(boolean authRequired) { |
| 849 |
mAuthRequired = authRequired; |
| 850 |
return this; |
| 851 |
} |
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
@NonNull |
| 857 |
public Control build() { |
| 858 |
return new Control(mControlId, |
| 859 |
mDeviceType, |
| 860 |
mTitle, |
| 861 |
mSubtitle, |
| 862 |
mStructure, |
| 863 |
mZone, |
| 864 |
mAppIntent, |
| 865 |
mCustomIcon, |
| 866 |
mCustomColor, |
| 867 |
mStatus, |
| 868 |
mControlTemplate, |
| 869 |
mStatusText, |
| 870 |
mAuthRequired); |
| 871 |
} |
| 872 |
} |
| 873 |
} |