blob: e450785c750a8eab3b38117877cad2f5ec961acc [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Sunny Goyald2497482015-09-22 18:24:19 -070019import android.content.ContentResolver;
Sunny Goyalc190dbf2016-05-05 14:37:05 -070020import android.database.sqlite.SQLiteDatabase;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080021import android.net.Uri;
Sunny Goyald2497482015-09-22 18:24:19 -070022import android.os.Bundle;
Adam Cohendf2cc412011-04-27 16:56:57 -070023import android.provider.BaseColumns;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080024
Sunny Goyal18b640c2015-04-17 09:24:01 -070025import com.android.launcher3.config.ProviderConfig;
26
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027/**
28 * Settings related utilities.
29 */
Hyunyoung Song3f471442015-04-08 19:01:34 -070030public class LauncherSettings {
Chris Wren1ada10d2013-09-13 18:01:38 -040031 /** Columns required on table staht will be subject to backup and restore. */
32 static interface ChangeLogColumns extends BaseColumns {
33 /**
34 * The time of the last update to this row.
35 * <P>Type: INTEGER</P>
36 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070037 public static final String MODIFIED = "modified";
Chris Wren1ada10d2013-09-13 18:01:38 -040038 }
39
Sunny Goyal81e44912017-01-14 15:05:14 -080040 static public interface BaseLauncherColumns extends ChangeLogColumns {
Romain Guy73b979d2009-06-09 12:57:21 -070041 /**
42 * Descriptive name of the gesture that can be displayed to the user.
43 * <P>Type: TEXT</P>
44 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070045 public static final String TITLE = "title";
Romain Guy73b979d2009-06-09 12:57:21 -070046
47 /**
48 * The Intent URL of the gesture, describing what it points to. This
Romain Guy1ce1a242009-06-23 17:34:54 -070049 * value is given to {@link android.content.Intent#parseUri(String, int)} to create
Romain Guy73b979d2009-06-09 12:57:21 -070050 * an Intent that can be launched.
51 * <P>Type: TEXT</P>
52 */
Sunny Goyal18b640c2015-04-17 09:24:01 -070053 public static final String INTENT = "intent";
Romain Guy73b979d2009-06-09 12:57:21 -070054
55 /**
56 * The type of the gesture
57 *
58 * <P>Type: INTEGER</P>
59 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070060 public static final String ITEM_TYPE = "itemType";
Romain Guy73b979d2009-06-09 12:57:21 -070061
62 /**
63 * The gesture is an application
64 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070065 public static final int ITEM_TYPE_APPLICATION = 0;
Romain Guy73b979d2009-06-09 12:57:21 -070066
67 /**
68 * The gesture is an application created shortcut
69 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070070 public static final int ITEM_TYPE_SHORTCUT = 1;
Romain Guy73b979d2009-06-09 12:57:21 -070071
72 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070073 * The icon package name in Intent.ShortcutIconResource
Romain Guy73b979d2009-06-09 12:57:21 -070074 * <P>Type: TEXT</P>
75 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070076 public static final String ICON_PACKAGE = "iconPackage";
Romain Guy73b979d2009-06-09 12:57:21 -070077
78 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070079 * The icon resource name in Intent.ShortcutIconResource
Romain Guy73b979d2009-06-09 12:57:21 -070080 * <P>Type: TEXT</P>
81 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070082 public static final String ICON_RESOURCE = "iconResource";
Romain Guy73b979d2009-06-09 12:57:21 -070083
84 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070085 * The custom icon bitmap.
Romain Guy73b979d2009-06-09 12:57:21 -070086 * <P>Type: BLOB</P>
87 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070088 public static final String ICON = "icon";
Romain Guy73b979d2009-06-09 12:57:21 -070089 }
90
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091 /**
Adam Cohendcd297f2013-06-18 13:13:40 -070092 * Workspace Screens.
93 *
94 * Tracks the order of workspace screens.
95 */
Sunny Goyal18b640c2015-04-17 09:24:01 -070096 public static final class WorkspaceScreens implements ChangeLogColumns {
97
98 public static final String TABLE_NAME = "workspaceScreens";
99
Adam Cohendcd297f2013-06-18 13:13:40 -0700100 /**
101 * The content:// style URL for this table
102 */
Sunny Goyalf076eae2016-01-11 12:25:10 -0800103 public static final Uri CONTENT_URI = Uri.parse("content://" +
Sunny Goyal18b640c2015-04-17 09:24:01 -0700104 ProviderConfig.AUTHORITY + "/" + TABLE_NAME);
Adam Cohendcd297f2013-06-18 13:13:40 -0700105
106 /**
107 * The rank of this screen -- ie. how it is ordered relative to the other screens.
108 * <P>Type: INTEGER</P>
109 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700110 public static final String SCREEN_RANK = "screenRank";
Adam Cohendcd297f2013-06-18 13:13:40 -0700111 }
112
113 /**
Bjorn Bringert93c45762009-12-16 13:19:47 +0000114 * Favorites.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700116 public static final class Favorites implements BaseLauncherColumns {
Sunny Goyal18b640c2015-04-17 09:24:01 -0700117
118 public static final String TABLE_NAME = "favorites";
119
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120 /**
121 * The content:// style URL for this table
122 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700123 public static final Uri CONTENT_URI = Uri.parse("content://" +
124 ProviderConfig.AUTHORITY + "/" + TABLE_NAME);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125
126 /**
127 * The content:// style URL for a given row, identified by its id.
128 *
129 * @param id The row id.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130 *
131 * @return The unique content URL for the specified row.
132 */
Sunny Goyale5bb7052015-07-27 14:36:07 -0700133 public static Uri getContentUri(long id) {
Sunny Goyal18b640c2015-04-17 09:24:01 -0700134 return Uri.parse("content://" + ProviderConfig.AUTHORITY +
135 "/" + TABLE_NAME + "/" + id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136 }
137
138 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139 * The container holding the favorite
140 * <P>Type: INTEGER</P>
141 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700142 public static final String CONTAINER = "container";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143
144 /**
145 * The icon is a resource identified by a package name and an integer id.
146 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700147 public static final int CONTAINER_DESKTOP = -100;
148 public static final int CONTAINER_HOTSEAT = -101;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500150 static final String containerToString(int container) {
151 switch (container) {
152 case CONTAINER_DESKTOP: return "desktop";
153 case CONTAINER_HOTSEAT: return "hotseat";
154 default: return String.valueOf(container);
155 }
156 }
157
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158 /**
159 * The screen holding the favorite (if container is CONTAINER_DESKTOP)
160 * <P>Type: INTEGER</P>
161 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700162 public static final String SCREEN = "screen";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163
164 /**
165 * The X coordinate of the cell holding the favorite
Adam Cohenc51934b2011-07-26 21:07:43 -0700166 * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800167 * <P>Type: INTEGER</P>
168 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700169 public static final String CELLX = "cellX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800170
171 /**
172 * The Y coordinate of the cell holding the favorite
173 * (if container is CONTAINER_DESKTOP)
174 * <P>Type: INTEGER</P>
175 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700176 public static final String CELLY = "cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177
178 /**
179 * The X span of the cell holding the favorite
180 * <P>Type: INTEGER</P>
181 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700182 public static final String SPANX = "spanX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183
184 /**
185 * The Y span of the cell holding the favorite
186 * <P>Type: INTEGER</P>
187 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700188 public static final String SPANY = "spanY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800189
190 /**
Kenny Guyed131872014-04-30 03:02:21 +0100191 * The profile id of the item in the cell.
192 * <P>
193 * Type: INTEGER
194 * </P>
195 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700196 public static final String PROFILE_ID = "profileId";
Kenny Guyed131872014-04-30 03:02:21 +0100197
198 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800199 * The favorite is a user created folder
200 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700201 public static final int ITEM_TYPE_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202
203 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700204 * The favorite is a widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700206 public static final int ITEM_TYPE_APPWIDGET = 4;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207
208 /**
Adam Cohen59400422014-03-05 18:07:04 -0800209 * The favorite is a custom widget provided by the launcher
210 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700211 public static final int ITEM_TYPE_CUSTOM_APPWIDGET = 5;
Adam Cohen59400422014-03-05 18:07:04 -0800212
213 /**
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700214 * The gesture is an application created deep shortcut
215 */
216 public static final int ITEM_TYPE_DEEP_SHORTCUT = 6;
217
218 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700219 * The appWidgetId of the widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220 *
221 * <P>Type: INTEGER</P>
222 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700223 public static final String APPWIDGET_ID = "appWidgetId";
Chris Wrend5e66bf2013-09-16 14:02:29 -0400224
225 /**
226 * The ComponentName of the widget provider
227 *
228 * <P>Type: STRING</P>
229 */
230 public static final String APPWIDGET_PROVIDER = "appWidgetProvider";
Chris Wrenf4d08112014-01-16 18:13:56 -0500231
232 /**
233 * Boolean indicating that his item was restored and not yet successfully bound.
234 * <P>Type: INTEGER</P>
235 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700236 public static final String RESTORED = "restored";
Sunny Goyal08f72612015-01-05 13:41:43 -0800237
238 /**
239 * Indicates the position of the item inside an auto-arranged view like folder or hotseat.
240 * <p>Type: INTEGER</p>
241 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700242 public static final String RANK = "rank";
Sunny Goyal5d85c442015-03-10 13:14:47 -0700243
244 /**
245 * Stores general flag based options for {@link ItemInfo}s.
246 * <p>Type: INTEGER</p>
247 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700248 public static final String OPTIONS = "options";
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700249
250 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) {
251 String ifNotExists = optional ? " IF NOT EXISTS " : "";
252 db.execSQL("CREATE TABLE " + ifNotExists + TABLE_NAME + " (" +
253 "_id INTEGER PRIMARY KEY," +
254 "title TEXT," +
255 "intent TEXT," +
256 "container INTEGER," +
257 "screen INTEGER," +
258 "cellX INTEGER," +
259 "cellY INTEGER," +
260 "spanX INTEGER," +
261 "spanY INTEGER," +
262 "itemType INTEGER," +
263 "appWidgetId INTEGER NOT NULL DEFAULT -1," +
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700264 "iconPackage TEXT," +
265 "iconResource TEXT," +
266 "icon BLOB," +
267 "appWidgetProvider TEXT," +
268 "modified INTEGER NOT NULL DEFAULT 0," +
269 "restored INTEGER NOT NULL DEFAULT 0," +
270 "profileId INTEGER DEFAULT " + myProfileId + "," +
271 "rank INTEGER NOT NULL DEFAULT 0," +
272 "options INTEGER NOT NULL DEFAULT 0" +
273 ");");
274 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800275 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700276
277 /**
278 * Launcher settings
279 */
280 public static final class Settings {
281
282 public static final Uri CONTENT_URI = Uri.parse("content://" +
283 ProviderConfig.AUTHORITY + "/settings");
284
Sunny Goyald2497482015-09-22 18:24:19 -0700285 public static final String METHOD_CLEAR_EMPTY_DB_FLAG = "clear_empty_db_flag";
Sunny Goyala5c8a9e2016-07-08 08:32:44 -0700286 public static final String METHOD_WAS_EMPTY_DB_CREATED = "get_empty_db_flag";
Sunny Goyald2497482015-09-22 18:24:19 -0700287
288 public static final String METHOD_DELETE_EMPTY_FOLDERS = "delete_empty_folders";
Sunny Goyald2497482015-09-22 18:24:19 -0700289
290 public static final String METHOD_NEW_ITEM_ID = "generate_new_item_id";
291 public static final String METHOD_NEW_SCREEN_ID = "generate_new_screen_id";
292
293 public static final String METHOD_CREATE_EMPTY_DB = "create_empty_db";
294 public static final String METHOD_DELETE_DB = "delete_db";
295
296 public static final String METHOD_LOAD_DEFAULT_FAVORITES = "load_default_favorites";
Sunny Goyal7779d622015-06-11 16:18:39 -0700297
Tony Wickham827cef22016-03-17 15:39:39 -0700298 public static final String METHOD_SET_EXTRACTED_COLORS_AND_WALLPAPER_ID =
299 "set_extracted_colors_and_wallpaper_id_setting";
300 public static final String EXTRA_EXTRACTED_COLORS = "extra_extractedColors";
301 public static final String EXTRA_WALLPAPER_ID = "extra_wallpaperId";
302
Sunny Goyal7779d622015-06-11 16:18:39 -0700303 public static final String EXTRA_VALUE = "value";
Sunny Goyald2497482015-09-22 18:24:19 -0700304
305 public static Bundle call(ContentResolver cr, String method) {
306 return cr.call(CONTENT_URI, method, null, null);
307 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700308 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800309}