• 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 com.android.launcher3;
18 
19 import android.content.ContentResolver;
20 import android.database.sqlite.SQLiteDatabase;
21 import android.net.Uri;
22 import android.os.Bundle;
23 import android.provider.BaseColumns;
24 
25 /**
26  * Settings related utilities.
27  */
28 public class LauncherSettings {
29     /** Columns required on table staht will be subject to backup and restore. */
30     static interface ChangeLogColumns extends BaseColumns {
31         /**
32          * The time of the last update to this row.
33          * <P>Type: INTEGER</P>
34          */
35         public static final String MODIFIED = "modified";
36     }
37 
38     static public interface BaseLauncherColumns extends ChangeLogColumns {
39         /**
40          * Descriptive name of the gesture that can be displayed to the user.
41          * <P>Type: TEXT</P>
42          */
43         public static final String TITLE = "title";
44 
45         /**
46          * The Intent URL of the gesture, describing what it points to. This
47          * value is given to {@link android.content.Intent#parseUri(String, int)} to create
48          * an Intent that can be launched.
49          * <P>Type: TEXT</P>
50          */
51         public static final String INTENT = "intent";
52 
53         /**
54          * The type of the gesture
55          *
56          * <P>Type: INTEGER</P>
57          */
58         public static final String ITEM_TYPE = "itemType";
59 
60         /**
61          * The gesture is an application
62          */
63         public static final int ITEM_TYPE_APPLICATION = 0;
64 
65         /**
66          * The gesture is an application created shortcut
67          */
68         public static final int ITEM_TYPE_SHORTCUT = 1;
69 
70         /**
71          * The icon package name in Intent.ShortcutIconResource
72          * <P>Type: TEXT</P>
73          */
74         public static final String ICON_PACKAGE = "iconPackage";
75 
76         /**
77          * The icon resource name in Intent.ShortcutIconResource
78          * <P>Type: TEXT</P>
79          */
80         public static final String ICON_RESOURCE = "iconResource";
81 
82         /**
83          * The custom icon bitmap.
84          * <P>Type: BLOB</P>
85          */
86         public static final String ICON = "icon";
87     }
88 
89     /**
90      * Workspace Screens.
91      *
92      * Tracks the order of workspace screens.
93      */
94     public static final class WorkspaceScreens implements ChangeLogColumns {
95 
96         public static final String TABLE_NAME = "workspaceScreens";
97 
98         /**
99          * The content:// style URL for this table
100          */
101         public static final Uri CONTENT_URI = Uri.parse("content://" +
102                 LauncherProvider.AUTHORITY + "/" + TABLE_NAME);
103 
104         /**
105          * The rank of this screen -- ie. how it is ordered relative to the other screens.
106          * <P>Type: INTEGER</P>
107          */
108         public static final String SCREEN_RANK = "screenRank";
109     }
110 
111     /**
112      * Favorites.
113      */
114     public static final class Favorites implements BaseLauncherColumns {
115 
116         public static final String TABLE_NAME = "favorites";
117 
118         /**
119          * The content:// style URL for this table
120          */
121         public static final Uri CONTENT_URI = Uri.parse("content://" +
122                 LauncherProvider.AUTHORITY + "/" + TABLE_NAME);
123 
124         /**
125          * The content:// style URL for a given row, identified by its id.
126          *
127          * @param id The row id.
128          *
129          * @return The unique content URL for the specified row.
130          */
getContentUri(long id)131         public static Uri getContentUri(long id) {
132             return Uri.parse("content://" + LauncherProvider.AUTHORITY +
133                     "/" + TABLE_NAME + "/" + id);
134         }
135 
136         /**
137          * The container holding the favorite
138          * <P>Type: INTEGER</P>
139          */
140         public static final String CONTAINER = "container";
141 
142         /**
143          * The icon is a resource identified by a package name and an integer id.
144          */
145         public static final int CONTAINER_DESKTOP = -100;
146         public static final int CONTAINER_HOTSEAT = -101;
147 
containerToString(int container)148         static final String containerToString(int container) {
149             switch (container) {
150                 case CONTAINER_DESKTOP: return "desktop";
151                 case CONTAINER_HOTSEAT: return "hotseat";
152                 default: return String.valueOf(container);
153             }
154         }
155 
itemTypeToString(int type)156         static final String itemTypeToString(int type) {
157             switch(type) {
158                 case ITEM_TYPE_APPLICATION: return "APP";
159                 case ITEM_TYPE_SHORTCUT: return "SHORTCUT";
160                 case ITEM_TYPE_FOLDER: return "FOLDER";
161                 case ITEM_TYPE_APPWIDGET: return "WIDGET";
162                 case ITEM_TYPE_CUSTOM_APPWIDGET: return "CUSTOMWIDGET";
163                 case ITEM_TYPE_DEEP_SHORTCUT: return "DEEPSHORTCUT";
164                 default: return String.valueOf(type);
165             }
166         }
167 
168         /**
169          * The screen holding the favorite (if container is CONTAINER_DESKTOP)
170          * <P>Type: INTEGER</P>
171          */
172         public static final String SCREEN = "screen";
173 
174         /**
175          * The X coordinate of the cell holding the favorite
176          * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT)
177          * <P>Type: INTEGER</P>
178          */
179         public static final String CELLX = "cellX";
180 
181         /**
182          * The Y coordinate of the cell holding the favorite
183          * (if container is CONTAINER_DESKTOP)
184          * <P>Type: INTEGER</P>
185          */
186         public static final String CELLY = "cellY";
187 
188         /**
189          * The X span of the cell holding the favorite
190          * <P>Type: INTEGER</P>
191          */
192         public static final String SPANX = "spanX";
193 
194         /**
195          * The Y span of the cell holding the favorite
196          * <P>Type: INTEGER</P>
197          */
198         public static final String SPANY = "spanY";
199 
200         /**
201          * The profile id of the item in the cell.
202          * <P>
203          * Type: INTEGER
204          * </P>
205          */
206         public static final String PROFILE_ID = "profileId";
207 
208         /**
209          * The favorite is a user created folder
210          */
211         public static final int ITEM_TYPE_FOLDER = 2;
212 
213         /**
214          * The favorite is a widget
215          */
216         public static final int ITEM_TYPE_APPWIDGET = 4;
217 
218         /**
219          * The favorite is a custom widget provided by the launcher
220          */
221         public static final int ITEM_TYPE_CUSTOM_APPWIDGET = 5;
222 
223         /**
224          * The gesture is an application created deep shortcut
225          */
226         public static final int ITEM_TYPE_DEEP_SHORTCUT = 6;
227 
228         /**
229          * The appWidgetId of the widget
230          *
231          * <P>Type: INTEGER</P>
232          */
233         public static final String APPWIDGET_ID = "appWidgetId";
234 
235         /**
236          * The ComponentName of the widget provider
237          *
238          * <P>Type: STRING</P>
239          */
240         public static final String APPWIDGET_PROVIDER = "appWidgetProvider";
241 
242         /**
243          * Boolean indicating that his item was restored and not yet successfully bound.
244          * <P>Type: INTEGER</P>
245          */
246         public static final String RESTORED = "restored";
247 
248         /**
249          * Indicates the position of the item inside an auto-arranged view like folder or hotseat.
250          * <p>Type: INTEGER</p>
251          */
252         public static final String RANK = "rank";
253 
254         /**
255          * Stores general flag based options for {@link ItemInfo}s.
256          * <p>Type: INTEGER</p>
257          */
258         public static final String OPTIONS = "options";
259 
addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional)260         public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) {
261             String ifNotExists = optional ? " IF NOT EXISTS " : "";
262             db.execSQL("CREATE TABLE " + ifNotExists + TABLE_NAME + " (" +
263                     "_id INTEGER PRIMARY KEY," +
264                     "title TEXT," +
265                     "intent TEXT," +
266                     "container INTEGER," +
267                     "screen INTEGER," +
268                     "cellX INTEGER," +
269                     "cellY INTEGER," +
270                     "spanX INTEGER," +
271                     "spanY INTEGER," +
272                     "itemType INTEGER," +
273                     "appWidgetId INTEGER NOT NULL DEFAULT -1," +
274                     "iconPackage TEXT," +
275                     "iconResource TEXT," +
276                     "icon BLOB," +
277                     "appWidgetProvider TEXT," +
278                     "modified INTEGER NOT NULL DEFAULT 0," +
279                     "restored INTEGER NOT NULL DEFAULT 0," +
280                     "profileId INTEGER DEFAULT " + myProfileId + "," +
281                     "rank INTEGER NOT NULL DEFAULT 0," +
282                     "options INTEGER NOT NULL DEFAULT 0" +
283                     ");");
284         }
285     }
286 
287     /**
288      * Launcher settings
289      */
290     public static final class Settings {
291 
292         public static final Uri CONTENT_URI = Uri.parse("content://" +
293                 LauncherProvider.AUTHORITY + "/settings");
294 
295         public static final String METHOD_CLEAR_EMPTY_DB_FLAG = "clear_empty_db_flag";
296         public static final String METHOD_WAS_EMPTY_DB_CREATED = "get_empty_db_flag";
297 
298         public static final String METHOD_DELETE_EMPTY_FOLDERS = "delete_empty_folders";
299 
300         public static final String METHOD_NEW_ITEM_ID = "generate_new_item_id";
301         public static final String METHOD_NEW_SCREEN_ID = "generate_new_screen_id";
302 
303         public static final String METHOD_CREATE_EMPTY_DB = "create_empty_db";
304 
305         public static final String METHOD_LOAD_DEFAULT_FAVORITES = "load_default_favorites";
306 
307         public static final String METHOD_REMOVE_GHOST_WIDGETS = "remove_ghost_widgets";
308 
309         public static final String EXTRA_VALUE = "value";
310 
call(ContentResolver cr, String method)311         public static Bundle call(ContentResolver cr, String method) {
312             return cr.call(CONTENT_URI, method, null, null);
313         }
314     }
315 }
316