blob: 3e0ae4ffc6749fe70b703ec84285702cf72bb03d [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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 Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Tony Wickham1bce7fd2016-04-28 17:39:03 -070019import android.content.ComponentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080020import android.content.ContentValues;
Winson Chungbe365162012-05-07 10:34:12 -070021import android.content.Intent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080022
Kenny Guyed131872014-04-30 03:02:21 +010023import com.android.launcher3.compat.UserHandleCompat;
Sunny Goyal32f3dda2016-11-11 11:45:00 -080024import com.android.launcher3.util.ContentWriter;
Kenny Guyed131872014-04-30 03:02:21 +010025
The Android Open Source Project31dd5032009-03-03 19:32:27 -080026/**
27 * Represents an item in the launcher.
28 */
Mathew Inwood72fbec12013-11-19 15:45:07 +000029public class ItemInfo {
Kenny Guyed131872014-04-30 03:02:21 +010030
31 /**
32 * Intent extra to store the profile. Format: UserHandle
33 */
Tony Wickhambfbf7f92016-05-19 11:19:39 -070034 public static final String EXTRA_PROFILE = "profile";
Sunny Goyalaa8ef112015-06-12 20:04:41 -070035
Hyunyoung Song3f471442015-04-08 19:01:34 -070036 public static final int NO_ID = -1;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070037
The Android Open Source Project31dd5032009-03-03 19:32:27 -080038 /**
39 * The id in the settings database for this item
40 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070041 public long id = NO_ID;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070042
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043 /**
44 * One of {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
45 * {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
Adam Cohendf2cc412011-04-27 16:56:57 -070046 * {@link LauncherSettings.Favorites#ITEM_TYPE_FOLDER}, or
The Android Open Source Project7376fae2009-03-11 12:11:58 -070047 * {@link LauncherSettings.Favorites#ITEM_TYPE_APPWIDGET}.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070049 public int itemType;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070050
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051 /**
Sunny Goyalaa8ef112015-06-12 20:04:41 -070052 * The id of the container that holds this item. For the desktop, this will be
The Android Open Source Project31dd5032009-03-03 19:32:27 -080053 * {@link LauncherSettings.Favorites#CONTAINER_DESKTOP}. For the all applications folder it
54 * will be {@link #NO_ID} (since it is not stored in the settings DB). For user folders
55 * it will be the id of the folder.
56 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070057 public long container = NO_ID;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070058
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059 /**
Hyunyoung Song0de01172016-10-05 16:27:48 -070060 * Indicates the screen in which the shortcut appears.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080061 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070062 public long screenId = -1;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070063
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064 /**
65 * Indicates the X position of the associated cell.
66 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070067 public int cellX = -1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068
69 /**
70 * Indicates the Y position of the associated cell.
71 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070072 public int cellY = -1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073
74 /**
75 * Indicates the X cell span.
76 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070077 public int spanX = 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080078
79 /**
80 * Indicates the Y cell span.
81 */
Hyunyoung Song3f471442015-04-08 19:01:34 -070082 public int spanY = 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083
Romain Guy73b979d2009-06-09 12:57:21 -070084 /**
Adam Cohend41fbf52012-02-16 23:53:59 -080085 * Indicates the minimum X cell span.
86 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070087 public int minSpanX = 1;
Adam Cohend41fbf52012-02-16 23:53:59 -080088
89 /**
90 * Indicates the minimum Y cell span.
91 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070092 public int minSpanY = 1;
Adam Cohen487f7dd2012-06-28 18:12:10 -070093
Adam Cohend41fbf52012-02-16 23:53:59 -080094 /**
Sunny Goyal08f72612015-01-05 13:41:43 -080095 * Indicates the position in an ordered list.
96 */
97 public int rank = 0;
98
99 /**
Adam Cohen487f7dd2012-06-28 18:12:10 -0700100 * Title of the item
101 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700102 public CharSequence title;
Romain Guy73b979d2009-06-09 12:57:21 -0700103
Patrick Dubroybbaa75c2011-03-08 18:47:40 -0800104 /**
Kenny Guyc2bd8102014-06-30 12:30:31 +0100105 * Content description of the item.
106 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700107 public CharSequence contentDescription;
Kenny Guyc2bd8102014-06-30 12:30:31 +0100108
Hyunyoung Song3f471442015-04-08 19:01:34 -0700109 public UserHandleCompat user;
Kenny Guyed131872014-04-30 03:02:21 +0100110
Hyunyoung Song3f471442015-04-08 19:01:34 -0700111 public ItemInfo() {
Kenny Guyc2bd8102014-06-30 12:30:31 +0100112 user = UserHandleCompat.myUserHandle();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800113 }
114
Michael Jurkac9d95c52011-08-29 14:03:34 -0700115 ItemInfo(ItemInfo info) {
Sunny Goyalff572272014-07-23 13:58:07 -0700116 copyFrom(info);
117 // tempdebug:
118 LauncherModel.checkItemInfo(this);
119 }
120
121 public void copyFrom(ItemInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122 id = info.id;
123 cellX = info.cellX;
124 cellY = info.cellY;
125 spanX = info.spanX;
126 spanY = info.spanY;
Sunny Goyal08f72612015-01-05 13:41:43 -0800127 rank = info.rank;
Adam Cohendcd297f2013-06-18 13:13:40 -0700128 screenId = info.screenId;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800129 itemType = info.itemType;
130 container = info.container;
Kenny Guyed131872014-04-30 03:02:21 +0100131 user = info.user;
Kenny Guyc2bd8102014-06-30 12:30:31 +0100132 contentDescription = info.contentDescription;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133 }
134
Anjali Koppale3e646e2014-03-17 09:34:39 -0700135 public Intent getIntent() {
Vadim Tryshevd6c8e7e2015-07-08 13:40:14 -0700136 return null;
Winson Chung997a9232013-07-24 15:33:46 -0700137 }
138
Tony Wickham1bce7fd2016-04-28 17:39:03 -0700139 public ComponentName getTargetComponent() {
140 return getIntent() == null ? null : getIntent().getComponent();
141 }
142
Sunny Goyal32f3dda2016-11-11 11:45:00 -0800143 public void writeToValues(ContentWriter writer) {
144 writer.put(LauncherSettings.Favorites.ITEM_TYPE, itemType)
145 .put(LauncherSettings.Favorites.CONTAINER, container)
146 .put(LauncherSettings.Favorites.SCREEN, screenId)
147 .put(LauncherSettings.Favorites.CELLX, cellX)
148 .put(LauncherSettings.Favorites.CELLY, cellY)
149 .put(LauncherSettings.Favorites.SPANX, spanX)
150 .put(LauncherSettings.Favorites.SPANY, spanY)
151 .put(LauncherSettings.Favorites.RANK, rank);
Sunny Goyal756cd262015-08-20 12:33:21 -0700152 }
153
154 public void readFromValues(ContentValues values) {
155 itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE);
156 container = values.getAsLong(LauncherSettings.Favorites.CONTAINER);
157 screenId = values.getAsLong(LauncherSettings.Favorites.SCREEN);
Sunny Goyalde51d1d2015-08-31 11:47:03 -0700158 cellX = values.getAsInteger(LauncherSettings.Favorites.CELLX);
159 cellY = values.getAsInteger(LauncherSettings.Favorites.CELLY);
160 spanX = values.getAsInteger(LauncherSettings.Favorites.SPANX);
161 spanY = values.getAsInteger(LauncherSettings.Favorites.SPANY);
162 rank = values.getAsInteger(LauncherSettings.Favorites.RANK);
Sunny Goyal756cd262015-08-20 12:33:21 -0700163 }
164
165 /**
166 * Write the fields of this item to the DB
Sunny Goyal756cd262015-08-20 12:33:21 -0700167 */
Sunny Goyal32f3dda2016-11-11 11:45:00 -0800168 void onAddToDatabase(ContentWriter writer) {
Adrian Roos8f3f6832014-04-28 15:45:52 +0200169 if (screenId == Workspace.EXTRA_EMPTY_SCREEN_ID) {
170 // We should never persist an item on the extra empty screen.
171 throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
172 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
Sunny Goyal32f3dda2016-11-11 11:45:00 -0800174 writeToValues(writer);
175 writer.put(LauncherSettings.Favorites.PROFILE_ID, user);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176 }
Adam Cohen4eac29a2011-07-11 17:53:37 -0700177
Daniel Sandler8802e962010-05-26 16:28:16 -0400178 @Override
Sunny Goyal1edab712016-09-01 10:55:20 -0700179 public final String toString() {
180 return getClass().getSimpleName() + "(" + dumpProperties() + ")";
181 }
182
183 protected String dumpProperties() {
184 return "id=" + id
185 + " type=" + itemType
186 + " container=" + container
187 + " screen=" + screenId
188 + " cellX=" + cellX
189 + " cellY=" + cellY
190 + " spanX=" + spanX
191 + " spanY=" + spanY
192 + " minSpanX=" + minSpanX
193 + " minSpanY=" + minSpanY
194 + " rank=" + rank
195 + " user=" + user
196 + " title=" + title;
Daniel Sandler8802e962010-05-26 16:28:16 -0400197 }
Kenny Guy44cba692016-01-21 19:50:02 +0000198
199 /**
200 * Whether this item is disabled.
201 */
202 public boolean isDisabled() {
203 return false;
204 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205}