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