/
CustomTile.java
879 lines (780 loc) · 28.5 KB
/
CustomTile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
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
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
/**
* Copyright (c) 2015, The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cyanogenmod.app;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import cyanogenmod.os.Build;
import java.util.ArrayList;
/**
* A class that represents a quick settings tile
*
* <p>The {@link cyanogenmod.app.CustomTile.Builder} has been added to make it
* easier to construct CustomTiles.</p>
*/
public class CustomTile implements Parcelable {
private String resourcesPackageName = "";
/**
* An optional intent to execute when the custom tile entry is clicked. If
* this is an activity, it must include the
* {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
* that you take care of task management.
*
* This takes priority over the onClickUri.
**/
public PendingIntent onClick;
/**
* An optional settings intent to execute when the custom tile's detail is shown
* If this is an activity, it must include the
* {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
* that you take care of task management
*/
public Intent onSettingsClick;
/**
* An optional Uri to be parsed and broadcast on tile click, if an onClick pending intent
* is specified, it will take priority over the uri to be broadcasted.
**/
public Uri onClickUri;
/**
* A label specific to the quick settings tile to be created
*/
public String label;
/**
* A content description for the custom tile state
*/
public String contentDescription;
/**
* An icon to represent the custom tile
*/
public int icon;
/**
* An expanded style for when the CustomTile is clicked, can either be
* a {@link GridExpandedStyle} or a {@link ListExpandedStyle}
*/
public ExpandedStyle expandedStyle;
/**
* Boolean that forces the status bar panel to collapse when a user clicks on the
* {@link CustomTile}
* By default {@link #collapsePanel} is true
*/
public boolean collapsePanel = true;
/**
* Unflatten the CustomTile from a parcel.
*/
public CustomTile(Parcel parcel) {
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = parcel.readInt();
int parcelableSize = parcel.readInt();
int startPosition = parcel.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.APRICOT) {
if (parcel.readInt() != 0) {
this.onClick = PendingIntent.CREATOR.createFromParcel(parcel);
}
if (parcel.readInt() != 0) {
this.onSettingsClick = Intent.CREATOR.createFromParcel(parcel);
}
if (parcel.readInt() != 0) {
this.onClickUri = Uri.CREATOR.createFromParcel(parcel);
}
if (parcel.readInt() != 0) {
this.label = parcel.readString();
}
if (parcel.readInt() != 0) {
this.contentDescription = parcel.readString();
}
if (parcel.readInt() != 0) {
this.expandedStyle = ExpandedStyle.CREATOR.createFromParcel(parcel);
}
this.icon = parcel.readInt();
}
if (parcelableVersion >= Build.CM_VERSION_CODES.BOYSENBERRY) {
this.resourcesPackageName = parcel.readString();
this.collapsePanel = (parcel.readInt() == 1);
}
parcel.setDataPosition(startPosition + parcelableSize);
}
/**
* Constructs a CustomTile object with default values.
* You might want to consider using {@link cyanogenmod.app.CustomTile.Builder} instead.
*/
public CustomTile()
{
// Empty constructor
}
/** @hide **/
public String getResourcesPackageName() {
return resourcesPackageName;
}
@Override
public CustomTile clone() {
CustomTile that = new CustomTile();
cloneInto(that);
return that;
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
String NEW_LINE = System.getProperty("line.separator");
if (onClickUri != null) {
b.append("onClickUri=" + onClickUri.toString() + NEW_LINE);
}
if (onClick != null) {
b.append("onClick=" + onClick.toString() + NEW_LINE);
}
if (onSettingsClick != null) {
b.append("onSettingsClick=" + onSettingsClick.toString() + NEW_LINE);
}
if (!TextUtils.isEmpty(label)) {
b.append("label=" + label + NEW_LINE);
}
if (!TextUtils.isEmpty(contentDescription)) {
b.append("contentDescription=" + contentDescription + NEW_LINE);
}
if (expandedStyle != null) {
b.append("expandedStyle=" + expandedStyle + NEW_LINE);
}
b.append("icon=" + icon + NEW_LINE);
b.append("resourcesPackageName=" + resourcesPackageName + NEW_LINE);
b.append("collapsePanel=" + collapsePanel + NEW_LINE);
return b.toString();
}
/**
* Copy all of this into that
* @hide
*/
public void cloneInto(CustomTile that) {
that.resourcesPackageName = this.resourcesPackageName;
that.onClick = this.onClick;
that.onSettingsClick = this.onSettingsClick;
that.onClickUri = this.onClickUri;
that.label = this.label;
that.contentDescription = this.contentDescription;
that.expandedStyle = this.expandedStyle;
that.icon = this.icon;
that.collapsePanel = this.collapsePanel;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
out.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = out.dataPosition();
out.writeInt(0);
int startPosition = out.dataPosition();
// ==== APRICOT =====
if (onClick != null) {
out.writeInt(1);
onClick.writeToParcel(out, 0);
} else {
out.writeInt(0);
}
if (onSettingsClick != null) {
out.writeInt(1);
onSettingsClick.writeToParcel(out, 0);
} else {
out.writeInt(0);
}
if (onClickUri != null) {
out.writeInt(1);
onClickUri.writeToParcel(out, 0);
} else {
out.writeInt(0);
}
if (label != null) {
out.writeInt(1);
out.writeString(label);
} else {
out.writeInt(0);
}
if (contentDescription != null) {
out.writeInt(1);
out.writeString(contentDescription);
} else {
out.writeInt(0);
}
if (expandedStyle != null) {
out.writeInt(1);
expandedStyle.writeToParcel(out, 0);
} else {
out.writeInt(0);
}
out.writeInt(icon);
// ==== BOYSENBERRY =====
out.writeString(resourcesPackageName);
out.writeInt(collapsePanel ? 1 : 0);
// Go back and write size
int parcelableSize = out.dataPosition() - startPosition;
out.setDataPosition(sizePosition);
out.writeInt(parcelableSize);
out.setDataPosition(startPosition + parcelableSize);
}
/**
* An object that can apply an expanded view style to a {@link CustomTile.Builder}
* object.
*/
public static class ExpandedStyle implements Parcelable {
/**
* @hide
*/
public static final int NO_STYLE = -1;
/**
* Identifier for a grid style expanded view
*/
public static final int GRID_STYLE = 0;
/**
* Identifier for a list style expanded view
*/
public static final int LIST_STYLE = 1;
private ExpandedStyle() {
styleId = NO_STYLE;
}
private ExpandedItem[] expandedItems;
private int styleId;
private ExpandedStyle(Parcel parcel) {
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = parcel.readInt();
int parcelableSize = parcel.readInt();
int startPosition = parcel.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.APRICOT) {
if (parcel.readInt() != 0) {
expandedItems = parcel.createTypedArray(ExpandedItem.CREATOR);
}
styleId = parcel.readInt();
}
parcel.setDataPosition(startPosition + parcelableSize);
}
/**
* @hide
*/
public void setBuilder(Builder builder) {
if (builder != null) {
builder.setExpandedStyle(this);
}
}
/**
* @hide
*/
protected void internalSetExpandedItems(ArrayList<? extends ExpandedItem> items) {
expandedItems = new ExpandedItem[items.size()];
items.toArray(expandedItems);
}
/**
* @hide
*/
protected void internalStyleId(int id) {
styleId = id;
}
/**
* Retrieve the {@link ExpandedItem}s that have been set on this expanded style
* @return array of {@link ExpandedItem}
*/
public ExpandedItem[] getExpandedItems() {
return expandedItems;
}
/**
* Retrieve the style id associated with the {@link ExpandedStyle}
* @return id for style
*/
public int getStyle() {
return styleId;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
parcel.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = parcel.dataPosition();
parcel.writeInt(0);
int startPosition = parcel.dataPosition();
// ==== APRICOT ====
if (expandedItems != null) {
parcel.writeInt(1);
parcel.writeTypedArray(expandedItems, 0);
} else {
parcel.writeInt(0);
}
parcel.writeInt(styleId);
// Go back and write size
int parcelableSize = parcel.dataPosition() - startPosition;
parcel.setDataPosition(sizePosition);
parcel.writeInt(parcelableSize);
parcel.setDataPosition(startPosition + parcelableSize);
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
String NEW_LINE = System.getProperty("line.separator");
if (expandedItems != null) {
b.append("expandedItems= "+ NEW_LINE);
for (ExpandedItem item : expandedItems) {
b.append(" item=" + item.toString() + NEW_LINE);
}
}
b.append("styleId=" + styleId + NEW_LINE);
return b.toString();
}
/**
* Parcelable.Creator that instantiates ExpandedStyle objects
*/
public static final Creator<ExpandedStyle> CREATOR =
new Creator<ExpandedStyle>() {
public ExpandedStyle createFromParcel(Parcel in) {
return new ExpandedStyle(in);
}
@Override
public ExpandedStyle[] newArray(int size) {
return new ExpandedStyle[size];
}
};
}
/**
* An instance of {@link ExpandedStyle} that shows the {@link ExpandedGridItem}s in a
* non-scrollable grid.
*/
public static class GridExpandedStyle extends ExpandedStyle {
/**
* Constructs a GridExpandedStyle object with default values.
*/
public GridExpandedStyle() {
internalStyleId(GRID_STYLE);
}
/**
* Sets an {@link ArrayList} of {@link ExpandedGridItem}'s to be utilized by
* the PseudoGridView for presentation.
* @param expandedGridItems an array list of {@link ExpandedGridItem}'s
*/
public void setGridItems(ArrayList<ExpandedGridItem> expandedGridItems) {
internalSetExpandedItems(expandedGridItems);
}
}
/**
* An instance of {@link ExpandedStyle} that shows the {@link ExpandedListItem}'s in a
* scrollable ListView.
*/
public static class ListExpandedStyle extends ExpandedStyle {
/**
* Constructs a ListExpandedStyle object with default values.
*/
public ListExpandedStyle() {
internalStyleId(LIST_STYLE);
}
/**
* Sets an {@link ArrayList} of {@link ExpandedListItem}s to be utilized by
* the ListView for presentation.
* @param expandedListItems an array list of {@link ExpandedListItem}s
*/
public void setListItems(ArrayList<ExpandedListItem> expandedListItems) {
internalSetExpandedItems(expandedListItems);
}
}
/**
* A container object that is utilized by {@link ExpandedStyle} to show specific items in either
* a PseudoGridView or a ListView via {@link GridExpandedStyle} and {@link ListExpandedStyle}
*/
public static class ExpandedItem implements Parcelable {
/**
* A {@link PendingIntent} associated with the item.
* Triggers a {@link PendingIntent#send()} when the item is clicked.
*/
public PendingIntent onClickPendingIntent;
/**
* A drawable resource id associated with the {@link ExpandedItem}
*/
public int itemDrawableResourceId;
/**
* The title of the item
*/
public String itemTitle;
/**
* The summary associated with the item, may be null
*/
public String itemSummary = null;
private ExpandedItem() {
// Don't want to have this baseclass be instantiable
}
/**
* @hide
*/
protected void internalSetItemDrawable(int resourceId) {
itemDrawableResourceId = resourceId;
}
/**
* @hide
*/
protected void internalSetItemSummary(String resourceId) {
itemSummary = resourceId;
}
/**
* @hide
*/
protected void internalSetItemTitle(String title) {
itemTitle = title;
}
/**
* @hide
*/
protected void internalSetOnClickPendingIntent(PendingIntent pendingIntent) {
onClickPendingIntent = pendingIntent;
}
/**
* Unflatten the ExpandedItem from a parcel.
*/
protected ExpandedItem(Parcel parcel) {
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = parcel.readInt();
int parcelableSize = parcel.readInt();
int startPosition = parcel.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.APRICOT) {
if (parcel.readInt() != 0) {
onClickPendingIntent = PendingIntent.CREATOR.createFromParcel(parcel);
}
if (parcel.readInt() != 0) {
itemTitle = parcel.readString();
}
if (parcel.readInt() != 0) {
itemSummary = parcel.readString();
}
itemDrawableResourceId = parcel.readInt();
}
parcel.setDataPosition(startPosition + parcelableSize);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
out.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = out.dataPosition();
out.writeInt(0);
int startPosition = out.dataPosition();
if (onClickPendingIntent != null) {
out.writeInt(1);
onClickPendingIntent.writeToParcel(out, 0);
} else {
out.writeInt(0);
}
if (!TextUtils.isEmpty(itemTitle)) {
out.writeInt(1);
out.writeString(itemTitle);
} else {
out.writeInt(0);
}
if (!TextUtils.isEmpty(itemSummary)) {
out.writeInt(1);
out.writeString(itemSummary);
} else {
out.writeInt(0);
}
out.writeInt(itemDrawableResourceId);
// Go back and write size
int parcelableSize = out.dataPosition() - startPosition;
out.setDataPosition(sizePosition);
out.writeInt(parcelableSize);
out.setDataPosition(startPosition + parcelableSize);
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
String NEW_LINE = System.getProperty("line.separator");
if (onClickPendingIntent != null) {
b.append("onClickPendingIntent= " + onClickPendingIntent.toString() + NEW_LINE);
}
if (itemTitle != null) {
b.append("itemTitle= " + itemTitle.toString() + NEW_LINE);
}
if (itemSummary != null) {
b.append("itemSummary= " + itemSummary.toString() + NEW_LINE);
}
b.append("itemDrawableResourceId=" + itemDrawableResourceId + NEW_LINE);
return b.toString();
}
public static final Creator<ExpandedItem> CREATOR =
new Creator<ExpandedItem>() {
@Override
public ExpandedItem createFromParcel(Parcel in) {
return new ExpandedItem(in);
}
@Override
public ExpandedItem[] newArray(int size) {
return new ExpandedItem[size];
}
};
}
/**
* An instance of {@link ExpandedItem} to be utilized within a {@link GridExpandedStyle}
*/
public static class ExpandedGridItem extends ExpandedItem {
/**
* Constructor for the ExpandedGridItem
*/
public ExpandedGridItem() {
}
/**
* Sets the title for the {@link ExpandedGridItem}
* @param title a string title
*/
public void setExpandedGridItemTitle(String title) {
internalSetItemTitle(title);
}
/**
* Sets the {@link PendingIntent} associated with the {@link ExpandedGridItem}
* @param intent a pending intent to be triggered on click
*/
public void setExpandedGridItemOnClickIntent(PendingIntent intent) {
internalSetOnClickPendingIntent(intent);
}
/**
* Sets the drawable resource id associated with the {@link ExpandedGridItem}
* @param resourceId a resource id that maps to a drawable
*/
public void setExpandedGridItemDrawable(int resourceId) {
internalSetItemDrawable(resourceId);
}
}
/**
* An instance of {@link ExpandedItem} to be utilized within a {@link ListExpandedStyle}
*/
public static class ExpandedListItem extends ExpandedItem {
/**
* Constructor fot the ExpandedListItem
*/
public ExpandedListItem() {
}
/**
* Sets the title for the {@link ExpandedListItem}
* @param title a string title
*/
public void setExpandedListItemTitle(String title) {
internalSetItemTitle(title);
}
/**
* Sets the title for the {@link ExpandedListItem}
* @param summary a string summary
*/
public void setExpandedListItemSummary(String summary) {
internalSetItemSummary(summary);
}
/**
* Sets the {@link PendingIntent} associated with the {@link ExpandedListItem}
* @param intent a pending intent to be triggered on click
*/
public void setExpandedListItemOnClickIntent(PendingIntent intent) {
internalSetOnClickPendingIntent(intent);
}
/**
* Sets the drawable resource id associated with the {@link ExpandedListItem}
* @param resourceId a resource id that maps to a drawable
*/
public void setExpandedListItemDrawable(int resourceId) {
internalSetItemDrawable(resourceId);
}
}
/**
* Parcelable.Creator that instantiates CustomTile objects
*/
public static final Creator<CustomTile> CREATOR =
new Creator<CustomTile>() {
public CustomTile createFromParcel(Parcel in) {
return new CustomTile(in);
}
@Override
public CustomTile[] newArray(int size) {
return new CustomTile[size];
}
};
/**
* Builder class for {@link cyanogenmod.app.CustomTile} objects.
*
* Provides a convenient way to set the various fields of a {@link cyanogenmod.app.CustomTile}
*
* <p>Example:
*
* <pre class="prettyprint">
* CustomTile customTile = new CustomTile.Builder(mContext)
* .setLabel("custom label")
* .setContentDescription("custom description")
* .setOnClickIntent(pendingIntent)
* .setOnSettingsClickIntent(intent)
* .setOnClickUri(Uri.parse("custom uri"))
* .setIcon(R.drawable.ic_launcher)
* .build();
* </pre>
*/
public static class Builder {
private PendingIntent mOnClick;
private Intent mOnSettingsClick;
private Uri mOnClickUri;
private String mLabel;
private String mContentDescription;
private int mIcon;
private Context mContext;
private ExpandedStyle mExpandedStyle;
private boolean mCollapsePanel;
/**
* Constructs a new Builder with the defaults:
*/
public Builder(Context context) {
mContext = context;
}
/**
* Set the label for the custom tile
* @param label a string to be used for the custom tile label
* @return {@link cyanogenmod.app.CustomTile.Builder}
*/
public Builder setLabel(String label) {
mLabel = label;
return this;
}
/**
* Set the label for the custom tile
* @param id a string resource id to be used for the custom tile label
* @return {@link cyanogenmod.app.CustomTile.Builder}
*/
public Builder setLabel(int id) {
mLabel = mContext.getString(id);
return this;
}
/**
* Set the content description for the custom tile
* @param contentDescription a string to explain content
* @return {@link cyanogenmod.app.CustomTile.Builder}
*/
public Builder setContentDescription(String contentDescription) {
mContentDescription = contentDescription;
return this;
}
/**
* Set the content description for the custom tile
* @param id a string resource id to explain content
* @return {@link cyanogenmod.app.CustomTile.Builder}
*/
public Builder setContentDescription(int id) {
mContentDescription = mContext.getString(id);
return this;
}
/**
* Set a {@link android.app.PendingIntent} to be fired on custom tile click
* @param intent
* @return {@link cyanogenmod.app.CustomTile.Builder}
*/
public Builder setOnClickIntent(PendingIntent intent) {
mOnClick = intent;
return this;
}
/**
* Set a settings {@link android.content.Intent} to be fired on custom
* tile detail pane click
* @param intent
* @return {@link cyanogenmod.app.CustomTile.Builder}
*/
public Builder setOnSettingsClickIntent(Intent intent) {
mOnSettingsClick = intent;
return this;
}
/**
* Set a {@link android.net.Uri} to be broadcasted in an intent on custom tile click
* @param uri
* @return {@link cyanogenmod.app.CustomTile.Builder}
*/
public Builder setOnClickUri(Uri uri) {
mOnClickUri = uri;
return this;
}
/**
* Set an icon for the custom tile to be presented to the user
* @param drawableId
* @return {@link cyanogenmod.app.CustomTile.Builder}
*/
public Builder setIcon(int drawableId) {
mIcon = drawableId;
return this;
}
/**
* Set an {@link ExpandedStyle} to to be displayed when a user clicks the custom tile
* @param expandedStyle
* @return {@link cyanogenmod.app.CustomTile.Builder}
*/
public Builder setExpandedStyle(ExpandedStyle expandedStyle) {
if (mExpandedStyle != expandedStyle) {
mExpandedStyle = expandedStyle;
if (mExpandedStyle != null) {
expandedStyle.setBuilder(this);
}
}
return this;
}
/**
* Set whether or not the Statusbar Panel should be collapsed when an
* {@link #onClick} or {@link #onClickUri} event is fired.
* @param bool
* @return {@link cyanogenmod.app.CustomTile.Builder}
*/
public Builder shouldCollapsePanel(boolean bool) {
mCollapsePanel = bool;
return this;
}
/**
* Create a {@link cyanogenmod.app.CustomTile} object
* @return {@link cyanogenmod.app.CustomTile}
*/
public CustomTile build() {
CustomTile tile = new CustomTile();
tile.resourcesPackageName = mContext.getPackageName();
tile.onClick = mOnClick;
tile.onSettingsClick = mOnSettingsClick;
tile.onClickUri = mOnClickUri;
tile.label = mLabel;
tile.contentDescription = mContentDescription;
tile.expandedStyle = mExpandedStyle;
tile.icon = mIcon;
tile.collapsePanel = mCollapsePanel;
return tile;
}
}
}