• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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 android.provider;
18 
19 import android.annotation.SdkConstant;
20 
21 /**
22  * <p>A LiveFolder is a special folder whose content is provided by a
23  * {@link android.content.ContentProvider}. To create a live folder, two components
24  * are required:</p>
25  * <ul>
26  *  <li>An activity that can respond to the intent action {@link #ACTION_CREATE_LIVE_FOLDER}. The
27  *  activity is responsible for creating the live folder.</li>
28  *  <li>A {@link android.content.ContentProvider} to provide the live folder items.</li>
29  * </ul>
30  *
31  * <h3>Lifecycle</h3>
32  * <p>When a user wants to create a live folder, the system looks for all activities with the
33  * intent filter action {@link #ACTION_CREATE_LIVE_FOLDER} and presents the list to the user.
34  * When the user chooses one of the activities, the activity is invoked with the
35  * {@link #ACTION_CREATE_LIVE_FOLDER} action. The activity then creates the live folder and
36  * passes it back to the system by setting it as an
37  * {@link android.app.Activity#setResult(int, android.content.Intent) activity result}. The
38  * live folder is described by a content provider URI, a name, an icon and a display mode.
39  * Finally, when the user opens the live folder, the system queries the content provider
40  * to retrieve the folder's content.</p>
41  *
42  * <h3>Setting up the live folder activity</h3>
43  * <p>The following code sample shows how to write an activity that creates a live folder:</p>
44  * <pre>
45  * public static class MyLiveFolder extends Activity {
46  *     public static final Uri CONTENT_URI = Uri.parse("content://my.app/live");
47  *
48  *     protected void onCreate(Bundle savedInstanceState) {
49  *         super.onCreate(savedInstanceState);
50  *
51  *         final Intent intent = getIntent();
52  *         final String action = intent.getAction();
53  *
54  *         if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
55  *             setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI, "My LiveFolder",
56  *                     R.drawable.ic_launcher_contacts_phones));
57  *         } else {
58  *             setResult(RESULT_CANCELED);
59  *         }
60  *
61  *         finish();
62  *     }
63  *
64  *     private static Intent createLiveFolder(Context context, Uri uri, String name,
65  *             int icon) {
66  *
67  *         final Intent intent = new Intent();
68  *
69  *         intent.setData(uri);
70  *         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, name);
71  *         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,
72  *                 Intent.ShortcutIconResource.fromContext(context, icon));
73  *         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST);
74  *
75  *         return intent;
76  *     }
77  * }
78  * </pre>
79  * <p>The live folder is described by an {@link android.content.Intent} as follows:</p>
80  * <table border="2" width="85%" align="center" frame="hsides" rules="rows">
81  *     <thead>
82  *     <tr><th>Component</th> <th>Type</th> <th>Description</th> <th>Required</th></tr>
83  *     </thead>
84  *
85  *     <tbody>
86  *     <tr><th>URI</th>
87  *         <td>URI</td>
88  *         <td>The ContentProvider URI</td>
89  *         <td align="center">Yes</td>
90  *     </tr>
91  *     <tr><th>{@link #EXTRA_LIVE_FOLDER_NAME}</th>
92  *         <td>Extra String</td>
93  *         <td>The name of the live folder</td>
94  *         <td align="center">Yes</td>
95  *     </tr>
96  *     <tr><th>{@link #EXTRA_LIVE_FOLDER_ICON}</th>
97  *         <td>Extra {@link android.content.Intent.ShortcutIconResource}</td>
98  *         <td>The icon of the live folder</td>
99  *         <td align="center">Yes</td>
100  *     </tr>
101  *     <tr><th>{@link #EXTRA_LIVE_FOLDER_DISPLAY_MODE}</th>
102  *         <td>Extra int</td>
103  *         <td>The display mode of the live folder. The value must be either
104  *         {@link #DISPLAY_MODE_GRID} or {@link #DISPLAY_MODE_LIST}.</td>
105  *         <td align="center">Yes</td>
106  *     </tr>
107  *     <tr><th>{@link #EXTRA_LIVE_FOLDER_BASE_INTENT}</th>
108  *         <td>Extra Intent</td>
109  *         <td>When the user clicks an item inside a live folder, the system will either fire
110  *         the intent associated with that item or, if present, the live folder's base intent
111  *         with the id of the item appended to the base intent's URI.</td>
112  *         <td align="center">No</td>
113  *     </tr>
114  *     </tbody>
115  * </table>
116  *
117  * <h3>Setting up the content provider</h3>
118  * <p>The live folder's content provider must, upon query, return a {@link android.database.Cursor}
119  * whose columns match the following names:</p>
120  * <table border="2" width="85%" align="center" frame="hsides" rules="rows">
121  *     <thead>
122  *     <tr><th>Column</th> <th>Type</th> <th>Description</th> <th>Required</th></tr>
123  *     </thead>
124  *
125  *     <tbody>
126  *     <tr><th>{@link #NAME}</th>
127  *         <td>String</td>
128  *         <td>The name of the item</td>
129  *         <td align="center">Yes</td>
130  *     </tr>
131  *     <tr><th>{@link #DESCRIPTION}</th>
132  *         <td>String</td>
133  *         <td>The description of the item. The description is ignored when the live folder's
134  *         display mode is {@link #DISPLAY_MODE_GRID}.</td>
135  *         <td align="center">No</td>
136  *     </tr>
137  *     <tr><th>{@link #INTENT}</th>
138  *         <td>{@link android.content.Intent}</td>
139  *         <td>The intent to fire when the item is clicked. Ignored when the live folder defines
140  *         a base intent.</td>
141  *         <td align="center">No</td>
142  *     </tr>
143  *     <tr><th>{@link #ICON_BITMAP}</th>
144  *         <td>Bitmap</td>
145  *         <td>The icon for the item. When this column value is not null, the values for the
146  *         columns {@link #ICON_PACKAGE} and {@link #ICON_RESOURCE} must be null.</td>
147  *         <td align="center">No</td>
148  *     </tr>
149  *     <tr><th>{@link #ICON_PACKAGE}</th>
150  *         <td>String</td>
151  *         <td>The package of the item's icon. When this value is not null, the value for the
152  *         column {@link #ICON_RESOURCE} must be specified and the value for the column
153  *         {@link #ICON_BITMAP} must be null.</td>
154  *         <td align="center">No</td>
155  *     </tr>
156  *     <tr><th>{@link #ICON_RESOURCE}</th>
157  *         <td>String</td>
158  *         <td>The resource name of the item's icon. When this value is not null, the value for the
159  *         column {@link #ICON_PACKAGE} must be specified and the value for the column
160  *         {@link #ICON_BITMAP} must be null.</td>
161  *         <td align="center">No</td>
162  *     </tr>
163  *     </tbody>
164  * </table>
165  */
166 public final class LiveFolders implements BaseColumns {
167     /**
168      * <p>Content provider column.</p>
169      * <p>Name of the live folder item.</p>
170      * <p>Required.</p>
171      * <p>Type: String.</p>
172      */
173     public static final String NAME = "name";
174 
175     /**
176      * <p>Content provider column.</p>
177      * <p>Description of the live folder item. This value is ignored if the
178      * live folder's display mode is {@link LiveFolders#DISPLAY_MODE_GRID}.</p>
179      * <p>Optional.</p>
180      * <p>Type: String.</p>
181      *
182      * @see LiveFolders#EXTRA_LIVE_FOLDER_DISPLAY_MODE
183      */
184     public static final String DESCRIPTION = "description";
185 
186     /**
187      * <p>Content provider column.</p>
188      * <p>Intent of the live folder item.</p>
189      * <p>Optional if the live folder has a base intent.</p>
190      * <p>Type: {@link android.content.Intent}.</p>
191      *
192      * @see LiveFolders#EXTRA_LIVE_FOLDER_BASE_INTENT
193      */
194     public static final String INTENT = "intent";
195 
196     /**
197      * <p>Content provider column.</p>
198      * <p>Icon of the live folder item, as a custom bitmap.</p>
199      * <p>Optional.</p>
200      * <p>Type: {@link android.graphics.Bitmap}.</p>
201      */
202     public static final String ICON_BITMAP = "icon_bitmap";
203 
204     /**
205      * <p>Content provider column.</p>
206      * <p>Package where to find the icon of the live folder item. This value can be
207      * obtained easily using
208      * {@link android.content.Intent.ShortcutIconResource#fromContext(android.content.Context, int)}.</p>
209      * <p>Optional.</p>
210      * <p>Type: String.</p>
211      *
212      * @see #ICON_RESOURCE
213      * @see android.content.Intent.ShortcutIconResource
214      */
215     public static final String ICON_PACKAGE = "icon_package";
216 
217     /**
218      * <p>Content provider column.</p>
219      * <p>Resource name of the live folder item. This value can be obtained easily using
220      * {@link android.content.Intent.ShortcutIconResource#fromContext(android.content.Context, int)}.</p>
221      * <p>Optional.</p>
222      * <p>Type: String.</p>
223      *
224      * @see #ICON_PACKAGE
225      * @see android.content.Intent.ShortcutIconResource
226      */
227     public static final String ICON_RESOURCE = "icon_resource";
228 
229     /**
230      * Displays a live folder's content in a grid.
231      *
232      * @see LiveFolders#EXTRA_LIVE_FOLDER_DISPLAY_MODE
233      */
234     public static final int DISPLAY_MODE_GRID = 0x1;
235 
236     /**
237      * Displays a live folder's content in a list.
238      *
239      * @see LiveFolders#EXTRA_LIVE_FOLDER_DISPLAY_MODE
240      */
241     public static final int DISPLAY_MODE_LIST = 0x2;
242 
243     /**
244      * The name of the extra used to define the name of a live folder.
245      *
246      * @see #ACTION_CREATE_LIVE_FOLDER
247      */
248     public static final String EXTRA_LIVE_FOLDER_NAME = "android.intent.extra.livefolder.NAME";
249 
250     /**
251      * The name of the extra used to define the icon of a live folder.
252      *
253      * @see #ACTION_CREATE_LIVE_FOLDER
254      */
255     public static final String EXTRA_LIVE_FOLDER_ICON = "android.intent.extra.livefolder.ICON";
256 
257     /**
258      * The name of the extra used to define the display mode of a live folder.
259      *
260      * @see #ACTION_CREATE_LIVE_FOLDER
261      * @see #DISPLAY_MODE_GRID
262      * @see #DISPLAY_MODE_LIST
263      */
264     public static final String EXTRA_LIVE_FOLDER_DISPLAY_MODE =
265             "android.intent.extra.livefolder.DISPLAY_MODE";
266 
267     /**
268      * The name of the extra used to define the base Intent of a live folder.
269      *
270      * @see #ACTION_CREATE_LIVE_FOLDER
271      */
272     public static final String EXTRA_LIVE_FOLDER_BASE_INTENT =
273             "android.intent.extra.livefolder.BASE_INTENT";
274 
275     /**
276      * Activity Action: Creates a live folder.
277      * <p>Input: Nothing.</p>
278      * <p>Output: An Intent representing the live folder. The intent must contain four
279      * extras: EXTRA_LIVE_FOLDER_NAME (value: String),
280      * EXTRA_LIVE_FOLDER_ICON (value: ShortcutIconResource),
281      * EXTRA_LIVE_FOLDER_URI (value: String) and
282      * EXTRA_LIVE_FOLDER_DISPLAY_MODE (value: int). The Intent can optionnally contain
283      * EXTRA_LIVE_FOLDER_BASE_INTENT (value: Intent).</p>
284      *
285      * @see #EXTRA_LIVE_FOLDER_NAME
286      * @see #EXTRA_LIVE_FOLDER_ICON
287      * @see #EXTRA_LIVE_FOLDER_DISPLAY_MODE
288      * @see #EXTRA_LIVE_FOLDER_BASE_INTENT
289      * @see android.content.Intent.ShortcutIconResource
290      */
291     @SdkConstant(SdkConstant.SdkConstantType.ACTIVITY_INTENT_ACTION)
292     public static final String ACTION_CREATE_LIVE_FOLDER =
293             "android.intent.action.CREATE_LIVE_FOLDER";
294 
LiveFolders()295     private LiveFolders() {
296     }
297 }
298