OSDN Git Service

Merge tag 'android-6.0.1_r74' into HEAD
[android-x86/packages-apps-Settings.git] / src / com / android / settings / dashboard / DashboardTile.java
1 /*
2  * Copyright (C) 2014 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.settings.dashboard;
18
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;
26
27 import java.util.ArrayList;
28
29 /**
30  * Description of a single dashboard tile that the user can select.
31  */
32 public class DashboardTile implements Parcelable {
33     /**
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)
36      * are valid.
37      */
38     public static final long TILE_ID_UNDEFINED = -1;
39
40     /**
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
45      */
46     public long id = TILE_ID_UNDEFINED;
47
48     /**
49      * Resource ID of title of the tile that is shown to the user.
50      * @attr ref android.R.styleable#PreferenceHeader_title
51      */
52     public int titleRes;
53
54     /**
55      * Title of the tile that is shown to the user.
56      * @attr ref android.R.styleable#PreferenceHeader_title
57      */
58     public CharSequence title;
59
60     /**
61      * Resource ID of optional summary describing what this tile controls.
62      * @attr ref android.R.styleable#PreferenceHeader_summary
63      */
64     public int summaryRes;
65
66     /**
67      * Optional summary describing what this tile controls.
68      * @attr ref android.R.styleable#PreferenceHeader_summary
69      */
70     public CharSequence summary;
71
72     /**
73      * Optional icon resource to show for this tile.
74      * @attr ref android.R.styleable#PreferenceHeader_icon
75      */
76     public int iconRes;
77
78     /**
79      * Optional package to pull the icon resource from.
80      */
81     public String iconPkg;
82
83     /**
84      * Optional location of a class which implements GenericSwitchTile
85      * to be displayed on the dashboard.
86      * @attr ref R.styleable#DashbaordTile_switchClass
87      */
88     public String switchControl;
89
90     /**
91      * Full class name of the fragment to display when this tile is
92      * selected.
93      * @attr ref android.R.styleable#PreferenceHeader_fragment
94      */
95     public String fragment;
96
97     /**
98      * Optional arguments to supply to the fragment when it is
99      * instantiated.
100      */
101     public Bundle fragmentArguments;
102
103     /**
104      * Intent to launch when the preference is selected.
105      */
106     public Intent intent;
107
108     /**
109      * Optional list of user handles which the intent should be launched on.
110      */
111     public ArrayList<UserHandle> userHandle = new ArrayList<>();
112
113     /**
114      * Optional additional data for use by subclasses of the activity
115      */
116     public Bundle extras;
117
118     public DashboardTile() {
119         // Empty
120     }
121
122     /**
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.
126      */
127     public CharSequence getTitle(Resources res) {
128         if (titleRes != 0) {
129             return res.getText(titleRes);
130         }
131         return title;
132     }
133
134     /**
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.
138      */
139     public CharSequence getSummary(Resources res) {
140         if (summaryRes != 0) {
141             return res.getText(summaryRes);
142         }
143         return summary;
144     }
145
146     @Override
147     public int describeContents() {
148         return 0;
149     }
150
151     @Override
152     public void writeToParcel(Parcel dest, int flags) {
153         dest.writeLong(id);
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) {
163             dest.writeInt(1);
164             intent.writeToParcel(dest, flags);
165         } else {
166             dest.writeInt(0);
167         }
168         final int N = userHandle.size();
169         dest.writeInt(N);
170         for (int i = 0; i < N; i++) {
171             userHandle.get(i).writeToParcel(dest, flags);
172         }
173         dest.writeBundle(extras);
174         if (switchControl != null) {
175             dest.writeInt(1);
176             dest.writeString(switchControl);
177         } else {
178             dest.writeInt(0);
179         }
180     }
181
182     public void readFromParcel(Parcel in) {
183         id = in.readLong();
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);
194         }
195         final int N = in.readInt();
196         for (int i = 0; i < N; i++) {
197             userHandle.add(UserHandle.CREATOR.createFromParcel(in));
198         }
199         extras = in.readBundle();
200         if (in.readInt() != 0) {
201             switchControl = in.readString();
202         }
203     }
204
205     DashboardTile(Parcel in) {
206         readFromParcel(in);
207     }
208
209     public static final Creator<DashboardTile> CREATOR = new Creator<DashboardTile>() {
210         public DashboardTile createFromParcel(Parcel source) {
211             return new DashboardTile(source);
212         }
213         public DashboardTile[] newArray(int size) {
214             return new DashboardTile[size];
215         }
216     };
217 }