blob: c0c22a325a69a74b57d124a851086024e8388988 [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;
Kenny Guyed131872014-04-30 03:02:21 +010021import android.content.Context;
Winson Chungbe365162012-05-07 10:34:12 -070022import android.content.Intent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080023import android.graphics.Bitmap;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080024
Kenny Guyed131872014-04-30 03:02:21 +010025import com.android.launcher3.compat.UserHandleCompat;
26import com.android.launcher3.compat.UserManagerCompat;
27
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028/**
29 * Represents an item in the launcher.
30 */
Mathew Inwood72fbec12013-11-19 15:45:07 +000031public class ItemInfo {
Kenny Guyed131872014-04-30 03:02:21 +010032
33 /**
34 * Intent extra to store the profile. Format: UserHandle
35 */
Tony Wickhambfbf7f92016-05-19 11:19:39 -070036 public static final String EXTRA_PROFILE = "profile";
Sunny Goyalaa8ef112015-06-12 20:04:41 -070037
Hyunyoung Song3f471442015-04-08 19:01:34 -070038 public static final int NO_ID = -1;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070039
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040 /**
41 * The id in the settings database for this item
42 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070043 public long id = NO_ID;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070044
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045 /**
46 * One of {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
47 * {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
Adam Cohendf2cc412011-04-27 16:56:57 -070048 * {@link LauncherSettings.Favorites#ITEM_TYPE_FOLDER}, or
The Android Open Source Project7376fae2009-03-11 12:11:58 -070049 * {@link LauncherSettings.Favorites#ITEM_TYPE_APPWIDGET}.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070051 public int itemType;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070052
The Android Open Source Project31dd5032009-03-03 19:32:27 -080053 /**
Sunny Goyalaa8ef112015-06-12 20:04:41 -070054 * 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 -080055 * {@link LauncherSettings.Favorites#CONTAINER_DESKTOP}. For the all applications folder it
56 * will be {@link #NO_ID} (since it is not stored in the settings DB). For user folders
57 * it will be the id of the folder.
58 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070059 public long container = NO_ID;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070060
The Android Open Source Project31dd5032009-03-03 19:32:27 -080061 /**
62 * Iindicates the screen in which the shortcut appears.
63 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070064 public long screenId = -1;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070065
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066 /**
67 * Indicates the X position of the associated cell.
68 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070069 public int cellX = -1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070
71 /**
72 * Indicates the Y position of the associated cell.
73 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070074 public int cellY = -1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080075
76 /**
77 * Indicates the X cell span.
78 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070079 public int spanX = 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080080
81 /**
82 * Indicates the Y cell span.
83 */
Hyunyoung Song3f471442015-04-08 19:01:34 -070084 public int spanY = 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080085
Romain Guy73b979d2009-06-09 12:57:21 -070086 /**
Adam Cohend41fbf52012-02-16 23:53:59 -080087 * Indicates the minimum X cell span.
88 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070089 public int minSpanX = 1;
Adam Cohend41fbf52012-02-16 23:53:59 -080090
91 /**
92 * Indicates the minimum Y cell span.
93 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070094 public int minSpanY = 1;
Adam Cohen487f7dd2012-06-28 18:12:10 -070095
Adam Cohend41fbf52012-02-16 23:53:59 -080096 /**
Sunny Goyal08f72612015-01-05 13:41:43 -080097 * Indicates the position in an ordered list.
98 */
99 public int rank = 0;
100
101 /**
Adam Cohen487f7dd2012-06-28 18:12:10 -0700102 * Title of the item
103 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700104 public CharSequence title;
Romain Guy73b979d2009-06-09 12:57:21 -0700105
Patrick Dubroybbaa75c2011-03-08 18:47:40 -0800106 /**
Kenny Guyc2bd8102014-06-30 12:30:31 +0100107 * Content description of the item.
108 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700109 public CharSequence contentDescription;
Kenny Guyc2bd8102014-06-30 12:30:31 +0100110
Hyunyoung Song3f471442015-04-08 19:01:34 -0700111 public UserHandleCompat user;
Kenny Guyed131872014-04-30 03:02:21 +0100112
Hyunyoung Song3f471442015-04-08 19:01:34 -0700113 public ItemInfo() {
Kenny Guyc2bd8102014-06-30 12:30:31 +0100114 user = UserHandleCompat.myUserHandle();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115 }
116
Michael Jurkac9d95c52011-08-29 14:03:34 -0700117 ItemInfo(ItemInfo info) {
Sunny Goyalff572272014-07-23 13:58:07 -0700118 copyFrom(info);
119 // tempdebug:
120 LauncherModel.checkItemInfo(this);
121 }
122
123 public void copyFrom(ItemInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124 id = info.id;
125 cellX = info.cellX;
126 cellY = info.cellY;
127 spanX = info.spanX;
128 spanY = info.spanY;
Sunny Goyal08f72612015-01-05 13:41:43 -0800129 rank = info.rank;
Adam Cohendcd297f2013-06-18 13:13:40 -0700130 screenId = info.screenId;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131 itemType = info.itemType;
132 container = info.container;
Kenny Guyed131872014-04-30 03:02:21 +0100133 user = info.user;
Kenny Guyc2bd8102014-06-30 12:30:31 +0100134 contentDescription = info.contentDescription;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 }
136
Anjali Koppale3e646e2014-03-17 09:34:39 -0700137 public Intent getIntent() {
Vadim Tryshevd6c8e7e2015-07-08 13:40:14 -0700138 return null;
Winson Chung997a9232013-07-24 15:33:46 -0700139 }
140
Tony Wickham1bce7fd2016-04-28 17:39:03 -0700141 public ComponentName getTargetComponent() {
142 return getIntent() == null ? null : getIntent().getComponent();
143 }
144
Sunny Goyal756cd262015-08-20 12:33:21 -0700145 public void writeToValues(ContentValues values) {
146 values.put(LauncherSettings.Favorites.ITEM_TYPE, itemType);
Adam Cohen487f7dd2012-06-28 18:12:10 -0700147 values.put(LauncherSettings.Favorites.CONTAINER, container);
Adam Cohendcd297f2013-06-18 13:13:40 -0700148 values.put(LauncherSettings.Favorites.SCREEN, screenId);
Adam Cohen487f7dd2012-06-28 18:12:10 -0700149 values.put(LauncherSettings.Favorites.CELLX, cellX);
150 values.put(LauncherSettings.Favorites.CELLY, cellY);
151 values.put(LauncherSettings.Favorites.SPANX, spanX);
152 values.put(LauncherSettings.Favorites.SPANY, spanY);
Sunny Goyal08f72612015-01-05 13:41:43 -0800153 values.put(LauncherSettings.Favorites.RANK, rank);
Sunny Goyal756cd262015-08-20 12:33:21 -0700154 }
155
156 public void readFromValues(ContentValues values) {
157 itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE);
158 container = values.getAsLong(LauncherSettings.Favorites.CONTAINER);
159 screenId = values.getAsLong(LauncherSettings.Favorites.SCREEN);
Sunny Goyalde51d1d2015-08-31 11:47:03 -0700160 cellX = values.getAsInteger(LauncherSettings.Favorites.CELLX);
161 cellY = values.getAsInteger(LauncherSettings.Favorites.CELLY);
162 spanX = values.getAsInteger(LauncherSettings.Favorites.SPANX);
163 spanY = values.getAsInteger(LauncherSettings.Favorites.SPANY);
164 rank = values.getAsInteger(LauncherSettings.Favorites.RANK);
Sunny Goyal756cd262015-08-20 12:33:21 -0700165 }
166
167 /**
168 * Write the fields of this item to the DB
169 *
170 * @param context A context object to use for getting UserManagerCompat
171 * @param values
172 */
173 void onAddToDatabase(Context context, ContentValues values) {
174 writeToValues(values);
Kenny Guyed131872014-04-30 03:02:21 +0100175 long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user);
176 values.put(LauncherSettings.Favorites.PROFILE_ID, serialNumber);
Adrian Roos8f3f6832014-04-28 15:45:52 +0200177
178 if (screenId == Workspace.EXTRA_EMPTY_SCREEN_ID) {
179 // We should never persist an item on the extra empty screen.
180 throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
181 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182 }
183
184 static void writeBitmap(ContentValues values, Bitmap bitmap) {
185 if (bitmap != null) {
Sunny Goyal5b0e6692015-03-19 14:31:19 -0700186 byte[] data = Utilities.flattenBitmap(bitmap);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800187 values.put(LauncherSettings.Favorites.ICON, data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188 }
189 }
Adam Cohen4eac29a2011-07-11 17:53:37 -0700190
Daniel Sandler8802e962010-05-26 16:28:16 -0400191 @Override
Sunny Goyal1edab712016-09-01 10:55:20 -0700192 public final String toString() {
193 return getClass().getSimpleName() + "(" + dumpProperties() + ")";
194 }
195
196 protected String dumpProperties() {
197 return "id=" + id
198 + " type=" + itemType
199 + " container=" + container
200 + " screen=" + screenId
201 + " cellX=" + cellX
202 + " cellY=" + cellY
203 + " spanX=" + spanX
204 + " spanY=" + spanY
205 + " minSpanX=" + minSpanX
206 + " minSpanY=" + minSpanY
207 + " rank=" + rank
208 + " user=" + user
209 + " title=" + title;
Daniel Sandler8802e962010-05-26 16:28:16 -0400210 }
Kenny Guy44cba692016-01-21 19:50:02 +0000211
212 /**
213 * Whether this item is disabled.
214 */
215 public boolean isDisabled() {
216 return false;
217 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218}