blob: 3f047f511b48c67fea62f0ad4b2d948044bb22d7 [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
25/**
26 * Settings related utilities.
27 */
Hyunyoung Song3f471442015-04-08 19:01:34 -070028public class LauncherSettings {
Chris Wren1ada10d2013-09-13 18:01:38 -040029 /** 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 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070035 public static final String MODIFIED = "modified";
Chris Wren1ada10d2013-09-13 18:01:38 -040036 }
37
Sunny Goyal81e44912017-01-14 15:05:14 -080038 static public interface BaseLauncherColumns extends ChangeLogColumns {
Romain Guy73b979d2009-06-09 12:57:21 -070039 /**
40 * Descriptive name of the gesture that can be displayed to the user.
41 * <P>Type: TEXT</P>
42 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070043 public static final String TITLE = "title";
Romain Guy73b979d2009-06-09 12:57:21 -070044
45 /**
46 * The Intent URL of the gesture, describing what it points to. This
Romain Guy1ce1a242009-06-23 17:34:54 -070047 * value is given to {@link android.content.Intent#parseUri(String, int)} to create
Romain Guy73b979d2009-06-09 12:57:21 -070048 * an Intent that can be launched.
49 * <P>Type: TEXT</P>
50 */
Sunny Goyal18b640c2015-04-17 09:24:01 -070051 public static final String INTENT = "intent";
Romain Guy73b979d2009-06-09 12:57:21 -070052
53 /**
54 * The type of the gesture
55 *
56 * <P>Type: INTEGER</P>
57 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070058 public static final String ITEM_TYPE = "itemType";
Romain Guy73b979d2009-06-09 12:57:21 -070059
60 /**
61 * The gesture is an application
62 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070063 public static final int ITEM_TYPE_APPLICATION = 0;
Romain Guy73b979d2009-06-09 12:57:21 -070064
65 /**
66 * The gesture is an application created shortcut
67 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070068 public static final int ITEM_TYPE_SHORTCUT = 1;
Romain Guy73b979d2009-06-09 12:57:21 -070069
70 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070071 * The icon package name in Intent.ShortcutIconResource
Romain Guy73b979d2009-06-09 12:57:21 -070072 * <P>Type: TEXT</P>
73 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070074 public static final String ICON_PACKAGE = "iconPackage";
Romain Guy73b979d2009-06-09 12:57:21 -070075
76 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070077 * The icon resource name in Intent.ShortcutIconResource
Romain Guy73b979d2009-06-09 12:57:21 -070078 * <P>Type: TEXT</P>
79 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070080 public static final String ICON_RESOURCE = "iconResource";
Romain Guy73b979d2009-06-09 12:57:21 -070081
82 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070083 * The custom icon bitmap.
Romain Guy73b979d2009-06-09 12:57:21 -070084 * <P>Type: BLOB</P>
85 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070086 public static final String ICON = "icon";
Romain Guy73b979d2009-06-09 12:57:21 -070087 }
88
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089 /**
Adam Cohendcd297f2013-06-18 13:13:40 -070090 * Workspace Screens.
91 *
92 * Tracks the order of workspace screens.
93 */
Sunny Goyal18b640c2015-04-17 09:24:01 -070094 public static final class WorkspaceScreens implements ChangeLogColumns {
95
96 public static final String TABLE_NAME = "workspaceScreens";
97
Adam Cohendcd297f2013-06-18 13:13:40 -070098 /**
99 * The content:// style URL for this table
100 */
Sunny Goyalf076eae2016-01-11 12:25:10 -0800101 public static final Uri CONTENT_URI = Uri.parse("content://" +
Sunny Goyal3d706ad2017-03-06 16:56:39 -0800102 LauncherProvider.AUTHORITY + "/" + TABLE_NAME);
Adam Cohendcd297f2013-06-18 13:13:40 -0700103
104 /**
105 * The rank of this screen -- ie. how it is ordered relative to the other screens.
106 * <P>Type: INTEGER</P>
107 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700108 public static final String SCREEN_RANK = "screenRank";
Adam Cohendcd297f2013-06-18 13:13:40 -0700109 }
110
111 /**
Bjorn Bringert93c45762009-12-16 13:19:47 +0000112 * Favorites.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800113 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700114 public static final class Favorites implements BaseLauncherColumns {
Sunny Goyal18b640c2015-04-17 09:24:01 -0700115
116 public static final String TABLE_NAME = "favorites";
117
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800118 /**
119 * The content:// style URL for this table
120 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700121 public static final Uri CONTENT_URI = Uri.parse("content://" +
Sunny Goyal3d706ad2017-03-06 16:56:39 -0800122 LauncherProvider.AUTHORITY + "/" + TABLE_NAME);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800123
124 /**
125 * The content:// style URL for a given row, identified by its id.
126 *
127 * @param id The row id.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128 *
129 * @return The unique content URL for the specified row.
130 */
Sunny Goyale5bb7052015-07-27 14:36:07 -0700131 public static Uri getContentUri(long id) {
Sunny Goyal3d706ad2017-03-06 16:56:39 -0800132 return Uri.parse("content://" + LauncherProvider.AUTHORITY +
Sunny Goyal18b640c2015-04-17 09:24:01 -0700133 "/" + TABLE_NAME + "/" + id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800134 }
135
136 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 * The container holding the favorite
138 * <P>Type: INTEGER</P>
139 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700140 public static final String CONTAINER = "container";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141
142 /**
143 * The icon is a resource identified by a package name and an integer id.
144 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700145 public static final int CONTAINER_DESKTOP = -100;
146 public static final int CONTAINER_HOTSEAT = -101;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500148 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
Hyunyoung Song86160f52017-02-06 10:46:24 -0800156 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
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800168 /**
169 * The screen holding the favorite (if container is CONTAINER_DESKTOP)
170 * <P>Type: INTEGER</P>
171 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700172 public static final String SCREEN = "screen";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
174 /**
175 * The X coordinate of the cell holding the favorite
Adam Cohenc51934b2011-07-26 21:07:43 -0700176 * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177 * <P>Type: INTEGER</P>
178 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700179 public static final String CELLX = "cellX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180
181 /**
182 * The Y coordinate of the cell holding the favorite
183 * (if container is CONTAINER_DESKTOP)
184 * <P>Type: INTEGER</P>
185 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700186 public static final String CELLY = "cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
188 /**
189 * The X span of the cell holding the favorite
190 * <P>Type: INTEGER</P>
191 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700192 public static final String SPANX = "spanX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800193
194 /**
195 * The Y span of the cell holding the favorite
196 * <P>Type: INTEGER</P>
197 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700198 public static final String SPANY = "spanY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800199
200 /**
Kenny Guyed131872014-04-30 03:02:21 +0100201 * The profile id of the item in the cell.
202 * <P>
203 * Type: INTEGER
204 * </P>
205 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700206 public static final String PROFILE_ID = "profileId";
Kenny Guyed131872014-04-30 03:02:21 +0100207
208 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800209 * The favorite is a user created folder
210 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700211 public static final int ITEM_TYPE_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212
213 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700214 * The favorite is a widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800215 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700216 public static final int ITEM_TYPE_APPWIDGET = 4;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800217
218 /**
Adam Cohen59400422014-03-05 18:07:04 -0800219 * The favorite is a custom widget provided by the launcher
220 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700221 public static final int ITEM_TYPE_CUSTOM_APPWIDGET = 5;
Adam Cohen59400422014-03-05 18:07:04 -0800222
223 /**
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700224 * The gesture is an application created deep shortcut
225 */
226 public static final int ITEM_TYPE_DEEP_SHORTCUT = 6;
227
228 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700229 * The appWidgetId of the widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800230 *
231 * <P>Type: INTEGER</P>
232 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700233 public static final String APPWIDGET_ID = "appWidgetId";
Chris Wrend5e66bf2013-09-16 14:02:29 -0400234
235 /**
236 * The ComponentName of the widget provider
237 *
238 * <P>Type: STRING</P>
239 */
240 public static final String APPWIDGET_PROVIDER = "appWidgetProvider";
Chris Wrenf4d08112014-01-16 18:13:56 -0500241
242 /**
243 * Boolean indicating that his item was restored and not yet successfully bound.
244 * <P>Type: INTEGER</P>
245 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700246 public static final String RESTORED = "restored";
Sunny Goyal08f72612015-01-05 13:41:43 -0800247
248 /**
249 * Indicates the position of the item inside an auto-arranged view like folder or hotseat.
250 * <p>Type: INTEGER</p>
251 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700252 public static final String RANK = "rank";
Sunny Goyal5d85c442015-03-10 13:14:47 -0700253
254 /**
255 * Stores general flag based options for {@link ItemInfo}s.
256 * <p>Type: INTEGER</p>
257 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700258 public static final String OPTIONS = "options";
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700259
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," +
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700274 "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 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800285 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700286
287 /**
288 * Launcher settings
289 */
290 public static final class Settings {
291
292 public static final Uri CONTENT_URI = Uri.parse("content://" +
Sunny Goyal3d706ad2017-03-06 16:56:39 -0800293 LauncherProvider.AUTHORITY + "/settings");
Sunny Goyal7779d622015-06-11 16:18:39 -0700294
Sunny Goyald2497482015-09-22 18:24:19 -0700295 public static final String METHOD_CLEAR_EMPTY_DB_FLAG = "clear_empty_db_flag";
Sunny Goyala5c8a9e2016-07-08 08:32:44 -0700296 public static final String METHOD_WAS_EMPTY_DB_CREATED = "get_empty_db_flag";
Sunny Goyald2497482015-09-22 18:24:19 -0700297
298 public static final String METHOD_DELETE_EMPTY_FOLDERS = "delete_empty_folders";
Sunny Goyald2497482015-09-22 18:24:19 -0700299
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";
Sunny Goyald2497482015-09-22 18:24:19 -0700304
305 public static final String METHOD_LOAD_DEFAULT_FAVORITES = "load_default_favorites";
Sunny Goyal7779d622015-06-11 16:18:39 -0700306
Tony Wickham827cef22016-03-17 15:39:39 -0700307 public static final String METHOD_SET_EXTRACTED_COLORS_AND_WALLPAPER_ID =
308 "set_extracted_colors_and_wallpaper_id_setting";
309 public static final String EXTRA_EXTRACTED_COLORS = "extra_extractedColors";
310 public static final String EXTRA_WALLPAPER_ID = "extra_wallpaperId";
311
Sunny Goyal7779d622015-06-11 16:18:39 -0700312 public static final String EXTRA_VALUE = "value";
Sunny Goyald2497482015-09-22 18:24:19 -0700313
314 public static Bundle call(ContentResolver cr, String method) {
315 return cr.call(CONTENT_URI, method, null, null);
316 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700317 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800318}