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