• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settingslib.drawer;
18 
19 import android.content.Intent;
20 import android.graphics.drawable.Icon;
21 import android.os.Bundle;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 import android.os.UserHandle;
25 import android.text.TextUtils;
26 
27 import java.util.ArrayList;
28 
29 /**
30  * Description of a single dashboard tile that the user can select.
31  */
32 public class Tile implements Parcelable {
33 
34     /**
35      * Title of the tile that is shown to the user.
36      * @attr ref android.R.styleable#PreferenceHeader_title
37      */
38     public CharSequence title;
39 
40     /**
41      * Optional summary describing what this tile controls.
42      * @attr ref android.R.styleable#PreferenceHeader_summary
43      */
44     public CharSequence summary;
45 
46     /**
47      * Optional icon to show for this tile.
48      * @attr ref android.R.styleable#PreferenceHeader_icon
49      */
50     public Icon icon;
51 
52     /**
53      * Intent to launch when the preference is selected.
54      */
55     public Intent intent;
56 
57     /**
58      * Optional list of user handles which the intent should be launched on.
59      */
60     public ArrayList<UserHandle> userHandle = new ArrayList<>();
61 
62     /**
63      * Optional additional data for use by subclasses of the activity
64      */
65     public Bundle extras;
66 
67     /**
68      * Category in which the tile should be placed.
69      */
70     public String category;
71 
72     /**
73      * Priority of the intent filter that created this tile, used for display ordering.
74      */
75     public int priority;
76 
77     /**
78      * The metaData from the activity that defines this tile.
79      */
80     public Bundle metaData;
81 
82     /**
83      * Optional key to use for this tile.
84      */
85     public String key;
86 
Tile()87     public Tile() {
88         // Empty
89     }
90 
91     @Override
describeContents()92     public int describeContents() {
93         return 0;
94     }
95 
96     @Override
writeToParcel(Parcel dest, int flags)97     public void writeToParcel(Parcel dest, int flags) {
98         TextUtils.writeToParcel(title, dest, flags);
99         TextUtils.writeToParcel(summary, dest, flags);
100         if (icon != null) {
101             dest.writeByte((byte) 1);
102             icon.writeToParcel(dest, flags);
103         } else {
104             dest.writeByte((byte) 0);
105         }
106         if (intent != null) {
107             dest.writeByte((byte) 1);
108             intent.writeToParcel(dest, flags);
109         } else {
110             dest.writeByte((byte) 0);
111         }
112         final int N = userHandle.size();
113         dest.writeInt(N);
114         for (int i = 0; i < N; i++) {
115             userHandle.get(i).writeToParcel(dest, flags);
116         }
117         dest.writeBundle(extras);
118         dest.writeString(category);
119         dest.writeInt(priority);
120         dest.writeBundle(metaData);
121         dest.writeString(key);
122     }
123 
readFromParcel(Parcel in)124     public void readFromParcel(Parcel in) {
125         title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
126         summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
127         if (in.readByte() != 0) {
128             icon = Icon.CREATOR.createFromParcel(in);
129         }
130         if (in.readByte() != 0) {
131             intent = Intent.CREATOR.createFromParcel(in);
132         }
133         final int N = in.readInt();
134         for (int i = 0; i < N; i++) {
135             userHandle.add(UserHandle.CREATOR.createFromParcel(in));
136         }
137         extras = in.readBundle();
138         category = in.readString();
139         priority = in.readInt();
140         metaData = in.readBundle();
141         key = in.readString();
142     }
143 
Tile(Parcel in)144     Tile(Parcel in) {
145         readFromParcel(in);
146     }
147 
148     public static final Creator<Tile> CREATOR = new Creator<Tile>() {
149         public Tile createFromParcel(Parcel source) {
150             return new Tile(source);
151         }
152         public Tile[] newArray(int size) {
153             return new Tile[size];
154         }
155     };
156 }
157