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