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