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