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 import com.android.launcher3.model.data.ItemInfo; 26 27 /** 28 * Settings related utilities. 29 */ 30 public class LauncherSettings { 31 32 /** 33 * Types of animations. 34 */ 35 public static final class Animation { 36 /** 37 * The default animation for a given view/item info type. 38 */ 39 public static final int DEFAULT = 0; 40 /** 41 * An animation using the view's background. 42 */ 43 public static final int VIEW_BACKGROUND = 1; 44 /** 45 * The default animation for a given view/item info type, but without the splash icon. 46 */ 47 public static final int DEFAULT_NO_ICON = 2; 48 } 49 50 /** 51 * Favorites. 52 */ 53 public static final class Favorites implements BaseColumns { 54 /** 55 * The time of the last update to this row. 56 * <P>Type: INTEGER</P> 57 */ 58 public static final String MODIFIED = "modified"; 59 60 /** 61 * Descriptive name of the gesture that can be displayed to the user. 62 * <P>Type: TEXT</P> 63 */ 64 public static final String TITLE = "title"; 65 66 /** 67 * The Intent URL of the gesture, describing what it points to. This 68 * value is given to {@link android.content.Intent#parseUri(String, int)} to create 69 * an Intent that can be launched. 70 * <P>Type: TEXT</P> 71 */ 72 public static final String INTENT = "intent"; 73 74 /** 75 * The type of the gesture 76 * 77 * <P>Type: INTEGER</P> 78 */ 79 public static final String ITEM_TYPE = "itemType"; 80 81 /** 82 * The gesture is a package 83 */ 84 public static final int ITEM_TYPE_NON_ACTIONABLE = -1; 85 /** 86 * The gesture is an application 87 */ 88 public static final int ITEM_TYPE_APPLICATION = 0; 89 90 /** 91 * The gesture is an application created shortcut 92 */ 93 public static final int ITEM_TYPE_SHORTCUT = 1; 94 95 /** 96 * The favorite is a user created folder 97 */ 98 public static final int ITEM_TYPE_FOLDER = 2; 99 100 /** 101 * The favorite is a widget 102 */ 103 public static final int ITEM_TYPE_APPWIDGET = 4; 104 105 /** 106 * The favorite is a custom widget provided by the launcher 107 */ 108 public static final int ITEM_TYPE_CUSTOM_APPWIDGET = 5; 109 110 /** 111 * The gesture is an application created deep shortcut 112 */ 113 public static final int ITEM_TYPE_DEEP_SHORTCUT = 6; 114 115 116 // *** Below enum values are used for metrics purpose but not used in Favorites DB *** 117 118 /** 119 * Type of the item is recents task. 120 */ 121 public static final int ITEM_TYPE_TASK = 7; 122 123 /** 124 * The item is QSB 125 */ 126 public static final int ITEM_TYPE_QSB = 8; 127 128 /** 129 * The favorite is a search action 130 */ 131 public static final int ITEM_TYPE_SEARCH_ACTION = 9; 132 133 /** 134 * The icon package name in Intent.ShortcutIconResource 135 * <P>Type: TEXT</P> 136 */ 137 public static final String ICON_PACKAGE = "iconPackage"; 138 139 /** 140 * The icon resource name in Intent.ShortcutIconResource 141 * <P>Type: TEXT</P> 142 */ 143 public static final String ICON_RESOURCE = "iconResource"; 144 145 /** 146 * The custom icon bitmap. 147 * <P>Type: BLOB</P> 148 */ 149 public static final String ICON = "icon"; 150 151 public static final String TABLE_NAME = "favorites"; 152 153 /** 154 * Backup table created when the favorites table is modified during grid migration 155 */ 156 public static final String BACKUP_TABLE_NAME = "favorites_bakup"; 157 158 /** 159 * Backup table created when user hotseat is moved to workspace for hybrid hotseat 160 */ 161 public static final String HYBRID_HOTSEAT_BACKUP_TABLE = "hotseat_restore_backup"; 162 163 /** 164 * Temporary table used specifically for grid migrations during wallpaper preview 165 */ 166 public static final String PREVIEW_TABLE_NAME = "favorites_preview"; 167 168 /** 169 * Temporary table used specifically for multi-db grid migrations 170 */ 171 public static final String TMP_TABLE = "favorites_tmp"; 172 173 /** 174 * The content:// style URL for "favorites" table 175 */ 176 public static final Uri CONTENT_URI = Uri.parse("content://" 177 + LauncherProvider.AUTHORITY + "/" + TABLE_NAME); 178 179 /** 180 * The content:// style URL for "favorites_bakup" table 181 */ 182 public static final Uri BACKUP_CONTENT_URI = Uri.parse("content://" 183 + LauncherProvider.AUTHORITY + "/" + BACKUP_TABLE_NAME); 184 185 /** 186 * The content:// style URL for "favorites_preview" table 187 */ 188 public static final Uri PREVIEW_CONTENT_URI = Uri.parse("content://" 189 + LauncherProvider.AUTHORITY + "/" + PREVIEW_TABLE_NAME); 190 191 /** 192 * The content:// style URL for "favorites_tmp" table 193 */ 194 public static final Uri TMP_CONTENT_URI = Uri.parse("content://" 195 + LauncherProvider.AUTHORITY + "/" + TMP_TABLE); 196 197 /** 198 * The content:// style URL for a given row, identified by its id. 199 * 200 * @param id The row id. 201 * 202 * @return The unique content URL for the specified row. 203 */ getContentUri(int id)204 public static Uri getContentUri(int id) { 205 return Uri.parse("content://" + LauncherProvider.AUTHORITY 206 + "/" + TABLE_NAME + "/" + id); 207 } 208 209 /** 210 * The container holding the favorite 211 * <P>Type: INTEGER</P> 212 */ 213 public static final String CONTAINER = "container"; 214 215 /** 216 * The icon is a resource identified by a package name and an integer id. 217 */ 218 public static final int CONTAINER_DESKTOP = -100; 219 public static final int CONTAINER_HOTSEAT = -101; 220 public static final int CONTAINER_PREDICTION = -102; 221 public static final int CONTAINER_WIDGETS_PREDICTION = -111; 222 public static final int CONTAINER_HOTSEAT_PREDICTION = -103; 223 public static final int CONTAINER_ALL_APPS = -104; 224 public static final int CONTAINER_WIDGETS_TRAY = -105; 225 public static final int CONTAINER_BOTTOM_WIDGETS_TRAY = -112; 226 public static final int CONTAINER_PIN_WIDGETS = -113; 227 public static final int CONTAINER_WALLPAPERS = -114; 228 public static final int CONTAINER_SHORTCUTS = -107; 229 public static final int CONTAINER_SETTINGS = -108; 230 public static final int CONTAINER_TASKSWITCHER = -109; 231 232 // Represents any of the extended containers implemented in non-AOSP variants. 233 public static final int EXTENDED_CONTAINERS = -200; 234 235 public static final int CONTAINER_UNKNOWN = -1; 236 containerToString(int container)237 public static final String containerToString(int container) { 238 switch (container) { 239 case CONTAINER_DESKTOP: return "desktop"; 240 case CONTAINER_HOTSEAT: return "hotseat"; 241 case CONTAINER_PREDICTION: return "prediction"; 242 case CONTAINER_ALL_APPS: return "all_apps"; 243 case CONTAINER_WIDGETS_TRAY: return "widgets_tray"; 244 case CONTAINER_SHORTCUTS: return "shortcuts"; 245 default: return String.valueOf(container); 246 } 247 } 248 itemTypeToString(int type)249 public static final String itemTypeToString(int type) { 250 switch(type) { 251 case ITEM_TYPE_APPLICATION: return "APP"; 252 case ITEM_TYPE_SHORTCUT: return "SHORTCUT"; 253 case ITEM_TYPE_FOLDER: return "FOLDER"; 254 case ITEM_TYPE_APPWIDGET: return "WIDGET"; 255 case ITEM_TYPE_CUSTOM_APPWIDGET: return "CUSTOMWIDGET"; 256 case ITEM_TYPE_DEEP_SHORTCUT: return "DEEPSHORTCUT"; 257 case ITEM_TYPE_TASK: return "TASK"; 258 case ITEM_TYPE_QSB: return "QSB"; 259 default: return String.valueOf(type); 260 } 261 } 262 263 /** 264 * The screen holding the favorite (if container is CONTAINER_DESKTOP) 265 * <P>Type: INTEGER</P> 266 */ 267 public static final String SCREEN = "screen"; 268 269 /** 270 * The X coordinate of the cell holding the favorite 271 * (if container is CONTAINER_HOTSEAT or CONTAINER_HOTSEAT) 272 * <P>Type: INTEGER</P> 273 */ 274 public static final String CELLX = "cellX"; 275 276 /** 277 * The Y coordinate of the cell holding the favorite 278 * (if container is CONTAINER_DESKTOP) 279 * <P>Type: INTEGER</P> 280 */ 281 public static final String CELLY = "cellY"; 282 283 /** 284 * The X span of the cell holding the favorite 285 * <P>Type: INTEGER</P> 286 */ 287 public static final String SPANX = "spanX"; 288 289 /** 290 * The Y span of the cell holding the favorite 291 * <P>Type: INTEGER</P> 292 */ 293 public static final String SPANY = "spanY"; 294 295 /** 296 * The profile id of the item in the cell. 297 * <P> 298 * Type: INTEGER 299 * </P> 300 */ 301 public static final String PROFILE_ID = "profileId"; 302 303 /** 304 * The appWidgetId of the widget 305 * 306 * <P>Type: INTEGER</P> 307 */ 308 public static final String APPWIDGET_ID = "appWidgetId"; 309 310 /** 311 * The ComponentName of the widget provider 312 * 313 * <P>Type: STRING</P> 314 */ 315 public static final String APPWIDGET_PROVIDER = "appWidgetProvider"; 316 317 /** 318 * Boolean indicating that his item was restored and not yet successfully bound. 319 * <P>Type: INTEGER</P> 320 */ 321 public static final String RESTORED = "restored"; 322 323 /** 324 * Indicates the position of the item inside an auto-arranged view like folder or hotseat. 325 * <p>Type: INTEGER</p> 326 */ 327 public static final String RANK = "rank"; 328 329 /** 330 * Stores general flag based options for {@link ItemInfo}s. 331 * <p>Type: INTEGER</p> 332 */ 333 public static final String OPTIONS = "options"; 334 335 /** 336 * Stores the source container that the widget was added from. 337 * <p>Type: INTEGER</p> 338 */ 339 public static final String APPWIDGET_SOURCE = "appWidgetSource"; 340 addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional)341 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional) { 342 addTableToDb(db, myProfileId, optional, TABLE_NAME); 343 } 344 addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional, String tableName)345 public static void addTableToDb(SQLiteDatabase db, long myProfileId, boolean optional, 346 String tableName) { 347 String ifNotExists = optional ? " IF NOT EXISTS " : ""; 348 db.execSQL("CREATE TABLE " + ifNotExists + tableName + " (" + 349 "_id INTEGER PRIMARY KEY," + 350 "title TEXT," + 351 "intent TEXT," + 352 "container INTEGER," + 353 "screen INTEGER," + 354 "cellX INTEGER," + 355 "cellY INTEGER," + 356 "spanX INTEGER," + 357 "spanY INTEGER," + 358 "itemType INTEGER," + 359 "appWidgetId INTEGER NOT NULL DEFAULT -1," + 360 "iconPackage TEXT," + 361 "iconResource TEXT," + 362 "icon BLOB," + 363 "appWidgetProvider TEXT," + 364 "modified INTEGER NOT NULL DEFAULT 0," + 365 "restored INTEGER NOT NULL DEFAULT 0," + 366 "profileId INTEGER DEFAULT " + myProfileId + "," + 367 "rank INTEGER NOT NULL DEFAULT 0," + 368 "options INTEGER NOT NULL DEFAULT 0," + 369 APPWIDGET_SOURCE + " INTEGER NOT NULL DEFAULT " + CONTAINER_UNKNOWN + 370 ");"); 371 } 372 } 373 374 /** 375 * Launcher settings 376 */ 377 public static final class Settings { 378 379 public static final Uri CONTENT_URI = Uri.parse("content://" + 380 LauncherProvider.AUTHORITY + "/settings"); 381 382 public static final String METHOD_CLEAR_EMPTY_DB_FLAG = "clear_empty_db_flag"; 383 public static final String METHOD_WAS_EMPTY_DB_CREATED = "get_empty_db_flag"; 384 385 public static final String METHOD_DELETE_EMPTY_FOLDERS = "delete_empty_folders"; 386 387 public static final String METHOD_NEW_ITEM_ID = "generate_new_item_id"; 388 public static final String METHOD_NEW_SCREEN_ID = "generate_new_screen_id"; 389 390 public static final String METHOD_CREATE_EMPTY_DB = "create_empty_db"; 391 392 public static final String METHOD_SET_USE_TEST_WORKSPACE_LAYOUT_FLAG = 393 "set_use_test_workspace_layout_flag"; 394 public static final String ARG_DEFAULT_WORKSPACE_LAYOUT_TEST = "default_test_workspace"; 395 public static final String ARG_DEFAULT_WORKSPACE_LAYOUT_TEST2 = "default_test2_workspace"; 396 public static final String ARG_DEFAULT_WORKSPACE_LAYOUT_TAPL = "default_tapl_workspace"; 397 398 public static final String METHOD_CLEAR_USE_TEST_WORKSPACE_LAYOUT_FLAG = 399 "clear_use_test_workspace_layout_flag"; 400 401 public static final String METHOD_LOAD_DEFAULT_FAVORITES = "load_default_favorites"; 402 403 public static final String METHOD_REMOVE_GHOST_WIDGETS = "remove_ghost_widgets"; 404 405 public static final String METHOD_NEW_TRANSACTION = "new_db_transaction"; 406 407 public static final String METHOD_REFRESH_BACKUP_TABLE = "refresh_backup_table"; 408 409 public static final String METHOD_REFRESH_HOTSEAT_RESTORE_TABLE = "restore_hotseat_table"; 410 411 public static final String METHOD_RESTORE_BACKUP_TABLE = "restore_backup_table"; 412 413 public static final String METHOD_UPDATE_CURRENT_OPEN_HELPER = "update_current_open_helper"; 414 415 public static final String METHOD_PREP_FOR_PREVIEW = "prep_for_preview"; 416 417 public static final String METHOD_SWITCH_DATABASE = "switch_database"; 418 419 public static final String EXTRA_VALUE = "value"; 420 421 public static final String EXTRA_DB_NAME = "db_name"; 422 call(ContentResolver cr, String method)423 public static Bundle call(ContentResolver cr, String method) { 424 return call(cr, method, null /* arg */); 425 } 426 call(ContentResolver cr, String method, String arg)427 public static Bundle call(ContentResolver cr, String method, String arg) { 428 return call(cr, method, arg, null /* extras */); 429 } 430 call(ContentResolver cr, String method, String arg, Bundle extras)431 public static Bundle call(ContentResolver cr, String method, String arg, Bundle extras) { 432 return cr.call(CONTENT_URI, method, arg, extras); 433 } 434 } 435 } 436