The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 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 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 19 | import android.content.ContentResolver; |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 20 | import android.database.sqlite.SQLiteDatabase; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 21 | import android.net.Uri; |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 22 | import android.os.Bundle; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 23 | import android.provider.BaseColumns; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Settings related utilities. |
| 27 | */ |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 28 | public class LauncherSettings { |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame^] | 29 | |
| 30 | /** |
| 31 | * Favorites. |
| 32 | */ |
| 33 | public static final class Favorites implements BaseColumns { |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 34 | /** |
| 35 | * The time of the last update to this row. |
| 36 | * <P>Type: INTEGER</P> |
| 37 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 38 | public static final String MODIFIED = "modified"; |
Chris Wren | 1ada10d | 2013-09-13 18:01:38 -0400 | [diff] [blame] | 39 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Descriptive name of the gesture that can be displayed to the user. |
| 42 | * <P>Type: TEXT</P> |
| 43 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 44 | public static final String TITLE = "title"; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * The Intent URL of the gesture, describing what it points to. This |
Romain Guy | 1ce1a24 | 2009-06-23 17:34:54 -0700 | [diff] [blame] | 48 | * value is given to {@link android.content.Intent#parseUri(String, int)} to create |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 49 | * an Intent that can be launched. |
| 50 | * <P>Type: TEXT</P> |
| 51 | */ |
Sunny Goyal | 18b640c | 2015-04-17 09:24:01 -0700 | [diff] [blame] | 52 | public static final String INTENT = "intent"; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * The type of the gesture |
| 56 | * |
| 57 | * <P>Type: INTEGER</P> |
| 58 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 59 | public static final String ITEM_TYPE = "itemType"; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * The gesture is an application |
| 63 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 64 | public static final int ITEM_TYPE_APPLICATION = 0; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * The gesture is an application created shortcut |
| 68 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 69 | public static final int ITEM_TYPE_SHORTCUT = 1; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 70 | |
| 71 | /** |
Sunny Goyal | eb4b799 | 2016-04-21 14:30:18 -0700 | [diff] [blame] | 72 | * The icon package name in Intent.ShortcutIconResource |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 73 | * <P>Type: TEXT</P> |
| 74 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 75 | public static final String ICON_PACKAGE = "iconPackage"; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 76 | |
| 77 | /** |
Sunny Goyal | eb4b799 | 2016-04-21 14:30:18 -0700 | [diff] [blame] | 78 | * The icon resource name in Intent.ShortcutIconResource |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 79 | * <P>Type: TEXT</P> |
| 80 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 81 | public static final String ICON_RESOURCE = "iconResource"; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
Sunny Goyal | eb4b799 | 2016-04-21 14:30:18 -0700 | [diff] [blame] | 84 | * The custom icon bitmap. |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 85 | * <P>Type: BLOB</P> |
| 86 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 87 | public static final String ICON = "icon"; |
Sunny Goyal | 18b640c | 2015-04-17 09:24:01 -0700 | [diff] [blame] | 88 | |
| 89 | public static final String TABLE_NAME = "favorites"; |
| 90 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 91 | /** |
| 92 | * The content:// style URL for this table |
| 93 | */ |
Sunny Goyal | 18b640c | 2015-04-17 09:24:01 -0700 | [diff] [blame] | 94 | public static final Uri CONTENT_URI = Uri.parse("content://" + |
Sunny Goyal | 3d706ad | 2017-03-06 16:56:39 -0800 | [diff] [blame] | 95 | LauncherProvider.AUTHORITY + "/" + TABLE_NAME); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * The content:// style URL for a given row, identified by its id. |
| 99 | * |
| 100 | * @param id The row id. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 101 | * |
| 102 | * @return The unique content URL for the specified row. |
| 103 | */ |
Sunny Goyal | efb7e84 | 2018-10-04 15:11:00 -0700 | [diff] [blame] | 104 | public static Uri getContentUri(int id) { |
Sunny Goyal | 3d706ad | 2017-03-06 16:56:39 -0800 | [diff] [blame] | 105 | return Uri.parse("content://" + LauncherProvider.AUTHORITY + |
Sunny Goyal | 18b640c | 2015-04-17 09:24:01 -0700 | [diff] [blame] | 106 | "/" + TABLE_NAME + "/" + id); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 110 | * The container holding the favorite |
| 111 | * <P>Type: INTEGER</P> |
| 112 | */ |
Sunny Goyal | 18b640c | 2015-04-17 09:24:01 -0700 | [diff] [blame] | 113 | public static final String CONTAINER = "container"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 114 | |
| 115 | /** |
| 116 | * The icon is a resource identified by a package name and an integer id. |
| 117 | */ |
Sunny Goyal | 18b640c | 2015-04-17 09:24:01 -0700 | [diff] [blame] | 118 | public static final int CONTAINER_DESKTOP = -100; |
| 119 | public static final int CONTAINER_HOTSEAT = -101; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 120 | |
Dan Sandler | ab5fa3a | 2014-03-06 23:48:04 -0500 | [diff] [blame] | 121 | static final String containerToString(int container) { |
| 122 | switch (container) { |
| 123 | case CONTAINER_DESKTOP: return "desktop"; |
| 124 | case CONTAINER_HOTSEAT: return "hotseat"; |
| 125 | default: return String.valueOf(container); |
| 126 | } |
| 127 | } |
| 128 | |
Hyunyoung Song | 86160f5 | 2017-02-06 10:46:24 -0800 | [diff] [blame] | 129 | static final String itemTypeToString(int type) { |
| 130 | switch(type) { |
| 131 | case ITEM_TYPE_APPLICATION: return "APP"; |
| 132 | case ITEM_TYPE_SHORTCUT: return "SHORTCUT"; |
| 133 | case ITEM_TYPE_FOLDER: return "FOLDER"; |
| 134 | case ITEM_TYPE_APPWIDGET: return "WIDGET"; |
| 135 | case ITEM_TYPE_CUSTOM_APPWIDGET: return "CUSTOMWIDGET"; |
| 136 | case ITEM_TYPE_DEEP_SHORTCUT: return "DEEPSHORTCUT"; |
| 137 | default: return String.valueOf(type); |
| 138 | } |
| 139 | } |
| 140 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 141 | /** |
| 142 | * The screen holding the favorite (if container is CONTAINER_DESKTOP) |
| 143 | * <P>Type: INTEGER</P> |
| 144 | */ |
Sunny Goyal | 18b640c | 2015-04-17 09:24:01 -0700 | [diff] [blame] | 145 | public static final String SCREEN = "screen"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * The X coordinate of the cell holding the favorite |
Adam Cohen | c51934b | 2011-07-26 21:07:43 -0700 | [diff] [blame] | 149 | * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT) |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 150 | * <P>Type: INTEGER</P> |
| 151 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 152 | public static final String CELLX = "cellX"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 153 | |
| 154 | /** |
| 155 | * The Y coordinate of the cell holding the favorite |
| 156 | * (if container is CONTAINER_DESKTOP) |
| 157 | * <P>Type: INTEGER</P> |
| 158 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 159 | public static final String CELLY = "cellY"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * The X span of the cell holding the favorite |
| 163 | * <P>Type: INTEGER</P> |
| 164 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 165 | public static final String SPANX = "spanX"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 166 | |
| 167 | /** |
| 168 | * The Y span of the cell holding the favorite |
| 169 | * <P>Type: INTEGER</P> |
| 170 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 171 | public static final String SPANY = "spanY"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 172 | |
| 173 | /** |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 174 | * The profile id of the item in the cell. |
| 175 | * <P> |
| 176 | * Type: INTEGER |
| 177 | * </P> |
| 178 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 179 | public static final String PROFILE_ID = "profileId"; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 180 | |
| 181 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 182 | * The favorite is a user created folder |
| 183 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 184 | public static final int ITEM_TYPE_FOLDER = 2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 185 | |
| 186 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 187 | * The favorite is a widget |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 188 | */ |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 189 | public static final int ITEM_TYPE_APPWIDGET = 4; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 190 | |
| 191 | /** |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 192 | * The favorite is a custom widget provided by the launcher |
| 193 | */ |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 194 | public static final int ITEM_TYPE_CUSTOM_APPWIDGET = 5; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 195 | |
| 196 | /** |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 197 | * The gesture is an application created deep shortcut |
| 198 | */ |
| 199 | public static final int ITEM_TYPE_DEEP_SHORTCUT = 6; |
| 200 | |
| 201 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 202 | * The appWidgetId of the widget |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 203 | * |
| 204 | * <P>Type: INTEGER</P> |
| 205 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 206 | public static final String APPWIDGET_ID = "appWidgetId"; |
Chris Wren | d5e66bf | 2013-09-16 14:02:29 -0400 | [diff] [blame] | 207 | |
| 208 | /** |
| 209 | * The ComponentName of the widget provider |
| 210 | * |
| 211 | * <P>Type: STRING</P> |
| 212 | */ |
| 213 | public static final String APPWIDGET_PROVIDER = "appWidgetProvider"; |
Chris Wren | f4d0811 | 2014-01-16 18:13:56 -0500 | [diff] [blame] | 214 | |
| 215 | /** |
| 216 | * Boolean indicating that his item was restored and not yet successfully bound. |
| 217 | * <P>Type: INTEGER</P> |
| 218 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 219 | public static final String RESTORED = "restored"; |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 220 | |
| 221 | /** |
| 222 | * Indicates the position of the item inside an auto-arranged view like folder or hotseat. |
| 223 | * <p>Type: INTEGER</p> |
| 224 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 225 | public static final String RANK = "rank"; |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * Stores general flag based options for {@link ItemInfo}s. |
| 229 | * <p>Type: INTEGER</p> |
| 230 | */ |
Sunny Goyal | 2fb2f0b | 2015-06-22 13:57:26 -0700 | [diff] [blame] | 231 | public static final String OPTIONS = "options"; |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 232 | |
| 233 | public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) { |
| 234 | String ifNotExists = optional ? " IF NOT EXISTS " : ""; |
| 235 | db.execSQL("CREATE TABLE " + ifNotExists + TABLE_NAME + " (" + |
| 236 | "_id INTEGER PRIMARY KEY," + |
| 237 | "title TEXT," + |
| 238 | "intent TEXT," + |
| 239 | "container INTEGER," + |
| 240 | "screen INTEGER," + |
| 241 | "cellX INTEGER," + |
| 242 | "cellY INTEGER," + |
| 243 | "spanX INTEGER," + |
| 244 | "spanY INTEGER," + |
| 245 | "itemType INTEGER," + |
| 246 | "appWidgetId INTEGER NOT NULL DEFAULT -1," + |
Sunny Goyal | c190dbf | 2016-05-05 14:37:05 -0700 | [diff] [blame] | 247 | "iconPackage TEXT," + |
| 248 | "iconResource TEXT," + |
| 249 | "icon BLOB," + |
| 250 | "appWidgetProvider TEXT," + |
| 251 | "modified INTEGER NOT NULL DEFAULT 0," + |
| 252 | "restored INTEGER NOT NULL DEFAULT 0," + |
| 253 | "profileId INTEGER DEFAULT " + myProfileId + "," + |
| 254 | "rank INTEGER NOT NULL DEFAULT 0," + |
| 255 | "options INTEGER NOT NULL DEFAULT 0" + |
| 256 | ");"); |
| 257 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 258 | } |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 259 | |
| 260 | /** |
| 261 | * Launcher settings |
| 262 | */ |
| 263 | public static final class Settings { |
| 264 | |
| 265 | public static final Uri CONTENT_URI = Uri.parse("content://" + |
Sunny Goyal | 3d706ad | 2017-03-06 16:56:39 -0800 | [diff] [blame] | 266 | LauncherProvider.AUTHORITY + "/settings"); |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 267 | |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 268 | public static final String METHOD_CLEAR_EMPTY_DB_FLAG = "clear_empty_db_flag"; |
Sunny Goyal | a5c8a9e | 2016-07-08 08:32:44 -0700 | [diff] [blame] | 269 | public static final String METHOD_WAS_EMPTY_DB_CREATED = "get_empty_db_flag"; |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 270 | |
| 271 | public static final String METHOD_DELETE_EMPTY_FOLDERS = "delete_empty_folders"; |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 272 | |
| 273 | public static final String METHOD_NEW_ITEM_ID = "generate_new_item_id"; |
| 274 | public static final String METHOD_NEW_SCREEN_ID = "generate_new_screen_id"; |
| 275 | |
| 276 | public static final String METHOD_CREATE_EMPTY_DB = "create_empty_db"; |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 277 | |
| 278 | public static final String METHOD_LOAD_DEFAULT_FAVORITES = "load_default_favorites"; |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 279 | |
Sunny Goyal | 55fddc8 | 2017-04-06 15:02:52 -0700 | [diff] [blame] | 280 | public static final String METHOD_REMOVE_GHOST_WIDGETS = "remove_ghost_widgets"; |
| 281 | |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 282 | public static final String EXTRA_VALUE = "value"; |
Sunny Goyal | d249748 | 2015-09-22 18:24:19 -0700 | [diff] [blame] | 283 | |
| 284 | public static Bundle call(ContentResolver cr, String method) { |
| 285 | return cr.call(CONTENT_URI, method, null, null); |
| 286 | } |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 287 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 288 | } |