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 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 19 | import android.content.ContentValues; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 20 | import android.content.Context; |
Winson Chung | be36516 | 2012-05-07 10:34:12 -0700 | [diff] [blame] | 21 | import android.content.Intent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 22 | import android.graphics.Bitmap; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 23 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 24 | import com.android.launcher3.compat.UserHandleCompat; |
| 25 | import com.android.launcher3.compat.UserManagerCompat; |
| 26 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 27 | /** |
| 28 | * Represents an item in the launcher. |
| 29 | */ |
Mathew Inwood | 72fbec1 | 2013-11-19 15:45:07 +0000 | [diff] [blame] | 30 | public class ItemInfo { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Intent extra to store the profile. Format: UserHandle |
| 34 | */ |
Tony Wickham | bfbf7f9 | 2016-05-19 11:19:39 -0700 | [diff] [blame] | 35 | public static final String EXTRA_PROFILE = "profile"; |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 36 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 37 | public static final int NO_ID = -1; |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 38 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 39 | /** |
| 40 | * The id in the settings database for this item |
| 41 | */ |
Anjali Koppal | e3e646e | 2014-03-17 09:34:39 -0700 | [diff] [blame] | 42 | public long id = NO_ID; |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 43 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 44 | /** |
| 45 | * One of {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION}, |
| 46 | * {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT}, |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 47 | * {@link LauncherSettings.Favorites#ITEM_TYPE_FOLDER}, or |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 48 | * {@link LauncherSettings.Favorites#ITEM_TYPE_APPWIDGET}. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 49 | */ |
Anjali Koppal | e3e646e | 2014-03-17 09:34:39 -0700 | [diff] [blame] | 50 | public int itemType; |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 51 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 52 | /** |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 53 | * The id of the container that holds this item. For the desktop, this will be |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 54 | * {@link LauncherSettings.Favorites#CONTAINER_DESKTOP}. For the all applications folder it |
| 55 | * will be {@link #NO_ID} (since it is not stored in the settings DB). For user folders |
| 56 | * it will be the id of the folder. |
| 57 | */ |
Anjali Koppal | e3e646e | 2014-03-17 09:34:39 -0700 | [diff] [blame] | 58 | public long container = NO_ID; |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 59 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 60 | /** |
| 61 | * Iindicates the screen in which the shortcut appears. |
| 62 | */ |
Anjali Koppal | e3e646e | 2014-03-17 09:34:39 -0700 | [diff] [blame] | 63 | public long screenId = -1; |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 64 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 65 | /** |
| 66 | * Indicates the X position of the associated cell. |
| 67 | */ |
Anjali Koppal | e3e646e | 2014-03-17 09:34:39 -0700 | [diff] [blame] | 68 | public int cellX = -1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * Indicates the Y position of the associated cell. |
| 72 | */ |
Anjali Koppal | e3e646e | 2014-03-17 09:34:39 -0700 | [diff] [blame] | 73 | public int cellY = -1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Indicates the X cell span. |
| 77 | */ |
Anjali Koppal | e3e646e | 2014-03-17 09:34:39 -0700 | [diff] [blame] | 78 | public int spanX = 1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * Indicates the Y cell span. |
| 82 | */ |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 83 | public int spanY = 1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 84 | |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 85 | /** |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 86 | * Indicates the minimum X cell span. |
| 87 | */ |
Anjali Koppal | e3e646e | 2014-03-17 09:34:39 -0700 | [diff] [blame] | 88 | public int minSpanX = 1; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * Indicates the minimum Y cell span. |
| 92 | */ |
Anjali Koppal | e3e646e | 2014-03-17 09:34:39 -0700 | [diff] [blame] | 93 | public int minSpanY = 1; |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 94 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 95 | /** |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 96 | * Indicates the position in an ordered list. |
| 97 | */ |
| 98 | public int rank = 0; |
| 99 | |
| 100 | /** |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 101 | * Title of the item |
| 102 | */ |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 103 | public CharSequence title; |
Romain Guy | 73b979d | 2009-06-09 12:57:21 -0700 | [diff] [blame] | 104 | |
Patrick Dubroy | bbaa75c | 2011-03-08 18:47:40 -0800 | [diff] [blame] | 105 | /** |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 106 | * Content description of the item. |
| 107 | */ |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 108 | public CharSequence contentDescription; |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 109 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 110 | public UserHandleCompat user; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 111 | |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 112 | public ItemInfo() { |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 113 | user = UserHandleCompat.myUserHandle(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 116 | ItemInfo(ItemInfo info) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 117 | copyFrom(info); |
| 118 | // tempdebug: |
| 119 | LauncherModel.checkItemInfo(this); |
| 120 | } |
| 121 | |
| 122 | public void copyFrom(ItemInfo info) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 123 | id = info.id; |
| 124 | cellX = info.cellX; |
| 125 | cellY = info.cellY; |
| 126 | spanX = info.spanX; |
| 127 | spanY = info.spanY; |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 128 | rank = info.rank; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 129 | screenId = info.screenId; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 130 | itemType = info.itemType; |
| 131 | container = info.container; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 132 | user = info.user; |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 133 | contentDescription = info.contentDescription; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Anjali Koppal | e3e646e | 2014-03-17 09:34:39 -0700 | [diff] [blame] | 136 | public Intent getIntent() { |
Vadim Tryshev | d6c8e7e | 2015-07-08 13:40:14 -0700 | [diff] [blame] | 137 | return null; |
Winson Chung | 997a923 | 2013-07-24 15:33:46 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 140 | public void writeToValues(ContentValues values) { |
| 141 | values.put(LauncherSettings.Favorites.ITEM_TYPE, itemType); |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 142 | values.put(LauncherSettings.Favorites.CONTAINER, container); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 143 | values.put(LauncherSettings.Favorites.SCREEN, screenId); |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 144 | values.put(LauncherSettings.Favorites.CELLX, cellX); |
| 145 | values.put(LauncherSettings.Favorites.CELLY, cellY); |
| 146 | values.put(LauncherSettings.Favorites.SPANX, spanX); |
| 147 | values.put(LauncherSettings.Favorites.SPANY, spanY); |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 148 | values.put(LauncherSettings.Favorites.RANK, rank); |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | public void readFromValues(ContentValues values) { |
| 152 | itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE); |
| 153 | container = values.getAsLong(LauncherSettings.Favorites.CONTAINER); |
| 154 | screenId = values.getAsLong(LauncherSettings.Favorites.SCREEN); |
Sunny Goyal | de51d1d | 2015-08-31 11:47:03 -0700 | [diff] [blame] | 155 | cellX = values.getAsInteger(LauncherSettings.Favorites.CELLX); |
| 156 | cellY = values.getAsInteger(LauncherSettings.Favorites.CELLY); |
| 157 | spanX = values.getAsInteger(LauncherSettings.Favorites.SPANX); |
| 158 | spanY = values.getAsInteger(LauncherSettings.Favorites.SPANY); |
| 159 | rank = values.getAsInteger(LauncherSettings.Favorites.RANK); |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Write the fields of this item to the DB |
| 164 | * |
| 165 | * @param context A context object to use for getting UserManagerCompat |
| 166 | * @param values |
| 167 | */ |
| 168 | void onAddToDatabase(Context context, ContentValues values) { |
| 169 | writeToValues(values); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 170 | long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user); |
| 171 | values.put(LauncherSettings.Favorites.PROFILE_ID, serialNumber); |
Adrian Roos | 8f3f683 | 2014-04-28 15:45:52 +0200 | [diff] [blame] | 172 | |
| 173 | if (screenId == Workspace.EXTRA_EMPTY_SCREEN_ID) { |
| 174 | // We should never persist an item on the extra empty screen. |
| 175 | throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID"); |
| 176 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | static void writeBitmap(ContentValues values, Bitmap bitmap) { |
| 180 | if (bitmap != null) { |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 181 | byte[] data = Utilities.flattenBitmap(bitmap); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 182 | values.put(LauncherSettings.Favorites.ICON, data); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 183 | } |
| 184 | } |
Adam Cohen | 4eac29a | 2011-07-11 17:53:37 -0700 | [diff] [blame] | 185 | |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 186 | @Override |
| 187 | public String toString() { |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 188 | return "Item(id=" + this.id + " type=" + this.itemType + " container=" + this.container |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 189 | + " screen=" + screenId + " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 190 | + " spanY=" + spanY + " user=" + user + ")"; |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 191 | } |
Kenny Guy | 44cba69 | 2016-01-21 19:50:02 +0000 | [diff] [blame] | 192 | |
| 193 | /** |
| 194 | * Whether this item is disabled. |
| 195 | */ |
| 196 | public boolean isDisabled() { |
| 197 | return false; |
| 198 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 199 | } |