2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.dashboard;
19 import android.content.Intent;
20 import android.content.res.Resources;
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;
27 import java.util.ArrayList;
30 * Description of a single dashboard tile that the user can select.
32 public class DashboardTile implements Parcelable {
34 * Default value for {@link com.android.settings.dashboard.DashboardTile#id DashboardTile.id}
35 * indicating that no identifier value is set. All other values (including those below -1)
38 public static final long TILE_ID_UNDEFINED = -1;
41 * Identifier for this tile, to correlate with a new list when
42 * it is updated. The default value is
43 * {@link com.android.settings.dashboard.DashboardTile#TILE_ID_UNDEFINED}, meaning no id.
44 * @attr ref android.R.styleable#PreferenceHeader_id
46 public long id = TILE_ID_UNDEFINED;
49 * Resource ID of title of the tile that is shown to the user.
50 * @attr ref android.R.styleable#PreferenceHeader_title
55 * Title of the tile that is shown to the user.
56 * @attr ref android.R.styleable#PreferenceHeader_title
58 public CharSequence title;
61 * Resource ID of optional summary describing what this tile controls.
62 * @attr ref android.R.styleable#PreferenceHeader_summary
64 public int summaryRes;
67 * Optional summary describing what this tile controls.
68 * @attr ref android.R.styleable#PreferenceHeader_summary
70 public CharSequence summary;
73 * Optional icon resource to show for this tile.
74 * @attr ref android.R.styleable#PreferenceHeader_icon
79 * Optional package to pull the icon resource from.
81 public String iconPkg;
84 * Optional location of a class which implements GenericSwitchTile
85 * to be displayed on the dashboard.
86 * @attr ref R.styleable#DashbaordTile_switchClass
88 public String switchControl;
91 * Full class name of the fragment to display when this tile is
93 * @attr ref android.R.styleable#PreferenceHeader_fragment
95 public String fragment;
98 * Optional arguments to supply to the fragment when it is
101 public Bundle fragmentArguments;
104 * Intent to launch when the preference is selected.
106 public Intent intent;
109 * Optional list of user handles which the intent should be launched on.
111 public ArrayList<UserHandle> userHandle = new ArrayList<>();
114 * Optional additional data for use by subclasses of the activity
116 public Bundle extras;
118 public DashboardTile() {
123 * Return the currently set title. If {@link #titleRes} is set,
124 * this resource is loaded from <var>res</var> and returned. Otherwise
125 * {@link #title} is returned.
127 public CharSequence getTitle(Resources res) {
129 return res.getText(titleRes);
135 * Return the currently set summary. If {@link #summaryRes} is set,
136 * this resource is loaded from <var>res</var> and returned. Otherwise
137 * {@link #summary} is returned.
139 public CharSequence getSummary(Resources res) {
140 if (summaryRes != 0) {
141 return res.getText(summaryRes);
147 public int describeContents() {
152 public void writeToParcel(Parcel dest, int flags) {
154 dest.writeInt(titleRes);
155 TextUtils.writeToParcel(title, dest, flags);
156 dest.writeInt(summaryRes);
157 TextUtils.writeToParcel(summary, dest, flags);
158 dest.writeInt(iconRes);
159 dest.writeString(iconPkg);
160 dest.writeString(fragment);
161 dest.writeBundle(fragmentArguments);
162 if (intent != null) {
164 intent.writeToParcel(dest, flags);
168 final int N = userHandle.size();
170 for (int i = 0; i < N; i++) {
171 userHandle.get(i).writeToParcel(dest, flags);
173 dest.writeBundle(extras);
174 if (switchControl != null) {
176 dest.writeString(switchControl);
182 public void readFromParcel(Parcel in) {
184 titleRes = in.readInt();
185 title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
186 summaryRes = in.readInt();
187 summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
188 iconRes = in.readInt();
189 iconPkg = in.readString();
190 fragment = in.readString();
191 fragmentArguments = in.readBundle();
192 if (in.readInt() != 0) {
193 intent = Intent.CREATOR.createFromParcel(in);
195 final int N = in.readInt();
196 for (int i = 0; i < N; i++) {
197 userHandle.add(UserHandle.CREATOR.createFromParcel(in));
199 extras = in.readBundle();
200 if (in.readInt() != 0) {
201 switchControl = in.readString();
205 DashboardTile(Parcel in) {
209 public static final Creator<DashboardTile> CREATOR = new Creator<DashboardTile>() {
210 public DashboardTile createFromParcel(Parcel source) {
211 return new DashboardTile(source);
213 public DashboardTile[] newArray(int size) {
214 return new DashboardTile[size];