blob: e248ba016dd8160d70499d4061507755629b2651 [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 {
Sunny Goyalc5939392018-12-07 11:43:47 -080029
30 /**
31 * Favorites.
32 */
33 public static final class Favorites implements BaseColumns {
Chris Wren1ada10d2013-09-13 18:01:38 -040034 /**
35 * The time of the last update to this row.
36 * <P>Type: INTEGER</P>
37 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070038 public static final String MODIFIED = "modified";
Chris Wren1ada10d2013-09-13 18:01:38 -040039
Romain Guy73b979d2009-06-09 12:57:21 -070040 /**
41 * Descriptive name of the gesture that can be displayed to the user.
42 * <P>Type: TEXT</P>
43 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070044 public static final String TITLE = "title";
Romain Guy73b979d2009-06-09 12:57:21 -070045
46 /**
47 * The Intent URL of the gesture, describing what it points to. This
Romain Guy1ce1a242009-06-23 17:34:54 -070048 * value is given to {@link android.content.Intent#parseUri(String, int)} to create
Romain Guy73b979d2009-06-09 12:57:21 -070049 * an Intent that can be launched.
50 * <P>Type: TEXT</P>
51 */
Sunny Goyal18b640c2015-04-17 09:24:01 -070052 public static final String INTENT = "intent";
Romain Guy73b979d2009-06-09 12:57:21 -070053
54 /**
55 * The type of the gesture
56 *
57 * <P>Type: INTEGER</P>
58 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070059 public static final String ITEM_TYPE = "itemType";
Romain Guy73b979d2009-06-09 12:57:21 -070060
61 /**
62 * The gesture is an application
63 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070064 public static final int ITEM_TYPE_APPLICATION = 0;
Romain Guy73b979d2009-06-09 12:57:21 -070065
66 /**
67 * The gesture is an application created shortcut
68 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070069 public static final int ITEM_TYPE_SHORTCUT = 1;
Romain Guy73b979d2009-06-09 12:57:21 -070070
71 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070072 * The icon package name in Intent.ShortcutIconResource
Romain Guy73b979d2009-06-09 12:57:21 -070073 * <P>Type: TEXT</P>
74 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070075 public static final String ICON_PACKAGE = "iconPackage";
Romain Guy73b979d2009-06-09 12:57:21 -070076
77 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070078 * The icon resource name in Intent.ShortcutIconResource
Romain Guy73b979d2009-06-09 12:57:21 -070079 * <P>Type: TEXT</P>
80 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070081 public static final String ICON_RESOURCE = "iconResource";
Romain Guy73b979d2009-06-09 12:57:21 -070082
83 /**
Sunny Goyaleb4b7992016-04-21 14:30:18 -070084 * The custom icon bitmap.
Romain Guy73b979d2009-06-09 12:57:21 -070085 * <P>Type: BLOB</P>
86 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -070087 public static final String ICON = "icon";
Sunny Goyal18b640c2015-04-17 09:24:01 -070088
89 public static final String TABLE_NAME = "favorites";
90
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091 /**
Sunny Goyal161a2142018-10-29 14:02:20 -070092 * Backup table created when when the favorites table is modified during grid migration
93 */
94 public static final String BACKUP_TABLE_NAME = "favorites_bakup";
95
96 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097 * The content:// style URL for this table
98 */
Sunny Goyal18b640c2015-04-17 09:24:01 -070099 public static final Uri CONTENT_URI = Uri.parse("content://" +
Sunny Goyal3d706ad2017-03-06 16:56:39 -0800100 LauncherProvider.AUTHORITY + "/" + TABLE_NAME);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800101
102 /**
103 * The content:// style URL for a given row, identified by its id.
104 *
105 * @param id The row id.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800106 *
107 * @return The unique content URL for the specified row.
108 */
Sunny Goyalefb7e842018-10-04 15:11:00 -0700109 public static Uri getContentUri(int id) {
Sunny Goyal3d706ad2017-03-06 16:56:39 -0800110 return Uri.parse("content://" + LauncherProvider.AUTHORITY +
Sunny Goyal18b640c2015-04-17 09:24:01 -0700111 "/" + TABLE_NAME + "/" + id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800112 }
113
114 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115 * The container holding the favorite
116 * <P>Type: INTEGER</P>
117 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700118 public static final String CONTAINER = "container";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800119
120 /**
121 * The icon is a resource identified by a package name and an integer id.
122 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700123 public static final int CONTAINER_DESKTOP = -100;
124 public static final int CONTAINER_HOTSEAT = -101;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125
Dan Sandlerab5fa3a2014-03-06 23:48:04 -0500126 static final String containerToString(int container) {
127 switch (container) {
128 case CONTAINER_DESKTOP: return "desktop";
129 case CONTAINER_HOTSEAT: return "hotseat";
130 default: return String.valueOf(container);
131 }
132 }
133
Hyunyoung Song86160f52017-02-06 10:46:24 -0800134 static final String itemTypeToString(int type) {
135 switch(type) {
136 case ITEM_TYPE_APPLICATION: return "APP";
137 case ITEM_TYPE_SHORTCUT: return "SHORTCUT";
138 case ITEM_TYPE_FOLDER: return "FOLDER";
139 case ITEM_TYPE_APPWIDGET: return "WIDGET";
140 case ITEM_TYPE_CUSTOM_APPWIDGET: return "CUSTOMWIDGET";
141 case ITEM_TYPE_DEEP_SHORTCUT: return "DEEPSHORTCUT";
142 default: return String.valueOf(type);
143 }
144 }
145
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146 /**
147 * The screen holding the favorite (if container is CONTAINER_DESKTOP)
148 * <P>Type: INTEGER</P>
149 */
Sunny Goyal18b640c2015-04-17 09:24:01 -0700150 public static final String SCREEN = "screen";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151
152 /**
153 * The X coordinate of the cell holding the favorite
Adam Cohenc51934b2011-07-26 21:07:43 -0700154 * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT)
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800155 * <P>Type: INTEGER</P>
156 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700157 public static final String CELLX = "cellX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158
159 /**
160 * The Y coordinate of the cell holding the favorite
161 * (if container is CONTAINER_DESKTOP)
162 * <P>Type: INTEGER</P>
163 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700164 public static final String CELLY = "cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165
166 /**
167 * The X span of the cell holding the favorite
168 * <P>Type: INTEGER</P>
169 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700170 public static final String SPANX = "spanX";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800171
172 /**
173 * The Y span of the cell holding the favorite
174 * <P>Type: INTEGER</P>
175 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700176 public static final String SPANY = "spanY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800177
178 /**
Kenny Guyed131872014-04-30 03:02:21 +0100179 * The profile id of the item in the cell.
180 * <P>
181 * Type: INTEGER
182 * </P>
183 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700184 public static final String PROFILE_ID = "profileId";
Kenny Guyed131872014-04-30 03:02:21 +0100185
186 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187 * The favorite is a user created folder
188 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700189 public static final int ITEM_TYPE_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190
191 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700192 * The favorite is a widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800193 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700194 public static final int ITEM_TYPE_APPWIDGET = 4;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195
196 /**
Adam Cohen59400422014-03-05 18:07:04 -0800197 * The favorite is a custom widget provided by the launcher
198 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700199 public static final int ITEM_TYPE_CUSTOM_APPWIDGET = 5;
Adam Cohen59400422014-03-05 18:07:04 -0800200
201 /**
Tony Wickhambfbf7f92016-05-19 11:19:39 -0700202 * The gesture is an application created deep shortcut
203 */
204 public static final int ITEM_TYPE_DEEP_SHORTCUT = 6;
205
206 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700207 * The appWidgetId of the widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800208 *
209 * <P>Type: INTEGER</P>
210 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700211 public static final String APPWIDGET_ID = "appWidgetId";
Chris Wrend5e66bf2013-09-16 14:02:29 -0400212
213 /**
214 * The ComponentName of the widget provider
215 *
216 * <P>Type: STRING</P>
217 */
218 public static final String APPWIDGET_PROVIDER = "appWidgetProvider";
Chris Wrenf4d08112014-01-16 18:13:56 -0500219
220 /**
221 * Boolean indicating that his item was restored and not yet successfully bound.
222 * <P>Type: INTEGER</P>
223 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700224 public static final String RESTORED = "restored";
Sunny Goyal08f72612015-01-05 13:41:43 -0800225
226 /**
227 * Indicates the position of the item inside an auto-arranged view like folder or hotseat.
228 * <p>Type: INTEGER</p>
229 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700230 public static final String RANK = "rank";
Sunny Goyal5d85c442015-03-10 13:14:47 -0700231
232 /**
233 * Stores general flag based options for {@link ItemInfo}s.
234 * <p>Type: INTEGER</p>
235 */
Sunny Goyal2fb2f0b2015-06-22 13:57:26 -0700236 public static final String OPTIONS = "options";
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700237
238 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) {
Sunny Goyal161a2142018-10-29 14:02:20 -0700239 addTableToDb(db, myProfileId, optional, TABLE_NAME);
240 }
241
242 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional,
243 String tableName) {
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700244 String ifNotExists = optional ? " IF NOT EXISTS " : "";
Sunny Goyal161a2142018-10-29 14:02:20 -0700245 db.execSQL("CREATE TABLE " + ifNotExists + tableName + " (" +
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700246 "_id INTEGER PRIMARY KEY," +
247 "title TEXT," +
248 "intent TEXT," +
249 "container INTEGER," +
250 "screen INTEGER," +
251 "cellX INTEGER," +
252 "cellY INTEGER," +
253 "spanX INTEGER," +
254 "spanY INTEGER," +
255 "itemType INTEGER," +
256 "appWidgetId INTEGER NOT NULL DEFAULT -1," +
Sunny Goyalc190dbf2016-05-05 14:37:05 -0700257 "iconPackage TEXT," +
258 "iconResource TEXT," +
259 "icon BLOB," +
260 "appWidgetProvider TEXT," +
261 "modified INTEGER NOT NULL DEFAULT 0," +
262 "restored INTEGER NOT NULL DEFAULT 0," +
263 "profileId INTEGER DEFAULT " + myProfileId + "," +
264 "rank INTEGER NOT NULL DEFAULT 0," +
265 "options INTEGER NOT NULL DEFAULT 0" +
266 ");");
267 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800268 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700269
270 /**
271 * Launcher settings
272 */
273 public static final class Settings {
274
275 public static final Uri CONTENT_URI = Uri.parse("content://" +
Sunny Goyal3d706ad2017-03-06 16:56:39 -0800276 LauncherProvider.AUTHORITY + "/settings");
Sunny Goyal7779d622015-06-11 16:18:39 -0700277
Sunny Goyald2497482015-09-22 18:24:19 -0700278 public static final String METHOD_CLEAR_EMPTY_DB_FLAG = "clear_empty_db_flag";
Sunny Goyala5c8a9e2016-07-08 08:32:44 -0700279 public static final String METHOD_WAS_EMPTY_DB_CREATED = "get_empty_db_flag";
Sunny Goyald2497482015-09-22 18:24:19 -0700280
281 public static final String METHOD_DELETE_EMPTY_FOLDERS = "delete_empty_folders";
Sunny Goyald2497482015-09-22 18:24:19 -0700282
283 public static final String METHOD_NEW_ITEM_ID = "generate_new_item_id";
284 public static final String METHOD_NEW_SCREEN_ID = "generate_new_screen_id";
285
286 public static final String METHOD_CREATE_EMPTY_DB = "create_empty_db";
Sunny Goyald2497482015-09-22 18:24:19 -0700287
288 public static final String METHOD_LOAD_DEFAULT_FAVORITES = "load_default_favorites";
Sunny Goyal7779d622015-06-11 16:18:39 -0700289
Sunny Goyal55fddc82017-04-06 15:02:52 -0700290 public static final String METHOD_REMOVE_GHOST_WIDGETS = "remove_ghost_widgets";
291
Sunny Goyal161a2142018-10-29 14:02:20 -0700292 public static final String METHOD_NEW_TRANSACTION = "new_db_transaction";
293
294 public static final String METHOD_REFRESH_BACKUP_TABLE = "refresh_backup_table";
295
Sunny Goyal7779d622015-06-11 16:18:39 -0700296 public static final String EXTRA_VALUE = "value";
Sunny Goyald2497482015-09-22 18:24:19 -0700297
298 public static Bundle call(ContentResolver cr, String method) {
299 return cr.call(CONTENT_URI, method, null, null);
300 }
Sunny Goyal7779d622015-06-11 16:18:39 -0700301 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800302}