blob: 0779a3d206479aecde439013fb591d9f1c0ffa72 [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;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -080022import android.os.Process;
23import android.os.UserHandle;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080024
Sunny Goyal32f3dda2016-11-11 11:45:00 -080025import com.android.launcher3.util.ContentWriter;
Kenny Guyed131872014-04-30 03:02:21 +010026
The Android Open Source Project31dd5032009-03-03 19:32:27 -080027/**
28 * Represents an item in the launcher.
29 */
Mathew Inwood72fbec12013-11-19 15:45:07 +000030public class ItemInfo {
Kenny Guyed131872014-04-30 03:02:21 +010031
Hyunyoung Song3f471442015-04-08 19:01:34 -070032 public static final int NO_ID = -1;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070033
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034 /**
35 * The id in the settings database for this item
36 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070037 public long id = NO_ID;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070038
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039 /**
40 * One of {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
41 * {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
Adam Cohendf2cc412011-04-27 16:56:57 -070042 * {@link LauncherSettings.Favorites#ITEM_TYPE_FOLDER}, or
The Android Open Source Project7376fae2009-03-11 12:11:58 -070043 * {@link LauncherSettings.Favorites#ITEM_TYPE_APPWIDGET}.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080044 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070045 public int itemType;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070046
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047 /**
Sunny Goyalaa8ef112015-06-12 20:04:41 -070048 * 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 -080049 * {@link LauncherSettings.Favorites#CONTAINER_DESKTOP}. For the all applications folder it
50 * will be {@link #NO_ID} (since it is not stored in the settings DB). For user folders
51 * it will be the id of the folder.
52 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070053 public long container = NO_ID;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070054
The Android Open Source Project31dd5032009-03-03 19:32:27 -080055 /**
Hyunyoung Song0de01172016-10-05 16:27:48 -070056 * Indicates the screen in which the shortcut appears.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070058 public long screenId = -1;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070059
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060 /**
61 * Indicates the X position of the associated cell.
62 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070063 public int cellX = -1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064
65 /**
66 * Indicates the Y position of the associated cell.
67 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070068 public int cellY = -1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069
70 /**
71 * Indicates the X cell span.
72 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070073 public int spanX = 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080074
75 /**
76 * Indicates the Y cell span.
77 */
Hyunyoung Song3f471442015-04-08 19:01:34 -070078 public int spanY = 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080079
Romain Guy73b979d2009-06-09 12:57:21 -070080 /**
Adam Cohend41fbf52012-02-16 23:53:59 -080081 * Indicates the minimum X cell span.
82 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070083 public int minSpanX = 1;
Adam Cohend41fbf52012-02-16 23:53:59 -080084
85 /**
86 * Indicates the minimum Y cell span.
87 */
Anjali Koppale3e646e2014-03-17 09:34:39 -070088 public int minSpanY = 1;
Adam Cohen487f7dd2012-06-28 18:12:10 -070089
Adam Cohend41fbf52012-02-16 23:53:59 -080090 /**
Sunny Goyal08f72612015-01-05 13:41:43 -080091 * Indicates the position in an ordered list.
92 */
93 public int rank = 0;
94
95 /**
Adam Cohen487f7dd2012-06-28 18:12:10 -070096 * Title of the item
97 */
Hyunyoung Song3f471442015-04-08 19:01:34 -070098 public CharSequence title;
Romain Guy73b979d2009-06-09 12:57:21 -070099
Patrick Dubroybbaa75c2011-03-08 18:47:40 -0800100 /**
Kenny Guyc2bd8102014-06-30 12:30:31 +0100101 * Content description of the item.
102 */
Hyunyoung Song3f471442015-04-08 19:01:34 -0700103 public CharSequence contentDescription;
Kenny Guyc2bd8102014-06-30 12:30:31 +0100104
Sunny Goyal7c74e4a2016-12-15 15:53:17 -0800105 public UserHandle user;
Kenny Guyed131872014-04-30 03:02:21 +0100106
Hyunyoung Song3f471442015-04-08 19:01:34 -0700107 public ItemInfo() {
Sunny Goyal7c74e4a2016-12-15 15:53:17 -0800108 user = Process.myUserHandle();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800109 }
110
Michael Jurkac9d95c52011-08-29 14:03:34 -0700111 ItemInfo(ItemInfo info) {
Sunny Goyalff572272014-07-23 13:58:07 -0700112 copyFrom(info);
113 // tempdebug:
114 LauncherModel.checkItemInfo(this);
115 }
116
117 public void copyFrom(ItemInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800118 id = info.id;
119 cellX = info.cellX;
120 cellY = info.cellY;
121 spanX = info.spanX;
122 spanY = info.spanY;
Sunny Goyal08f72612015-01-05 13:41:43 -0800123 rank = info.rank;
Adam Cohendcd297f2013-06-18 13:13:40 -0700124 screenId = info.screenId;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125 itemType = info.itemType;
126 container = info.container;
Kenny Guyed131872014-04-30 03:02:21 +0100127 user = info.user;
Kenny Guyc2bd8102014-06-30 12:30:31 +0100128 contentDescription = info.contentDescription;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800129 }
130
Anjali Koppale3e646e2014-03-17 09:34:39 -0700131 public Intent getIntent() {
Vadim Tryshevd6c8e7e2015-07-08 13:40:14 -0700132 return null;
Winson Chung997a9232013-07-24 15:33:46 -0700133 }
134
Tony Wickham1bce7fd2016-04-28 17:39:03 -0700135 public ComponentName getTargetComponent() {
136 return getIntent() == null ? null : getIntent().getComponent();
137 }
138
Sunny Goyal32f3dda2016-11-11 11:45:00 -0800139 public void writeToValues(ContentWriter writer) {
140 writer.put(LauncherSettings.Favorites.ITEM_TYPE, itemType)
141 .put(LauncherSettings.Favorites.CONTAINER, container)
142 .put(LauncherSettings.Favorites.SCREEN, screenId)
143 .put(LauncherSettings.Favorites.CELLX, cellX)
144 .put(LauncherSettings.Favorites.CELLY, cellY)
145 .put(LauncherSettings.Favorites.SPANX, spanX)
146 .put(LauncherSettings.Favorites.SPANY, spanY)
147 .put(LauncherSettings.Favorites.RANK, rank);
Sunny Goyal756cd262015-08-20 12:33:21 -0700148 }
149
150 public void readFromValues(ContentValues values) {
151 itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE);
152 container = values.getAsLong(LauncherSettings.Favorites.CONTAINER);
153 screenId = values.getAsLong(LauncherSettings.Favorites.SCREEN);
Sunny Goyalde51d1d2015-08-31 11:47:03 -0700154 cellX = values.getAsInteger(LauncherSettings.Favorites.CELLX);
155 cellY = values.getAsInteger(LauncherSettings.Favorites.CELLY);
156 spanX = values.getAsInteger(LauncherSettings.Favorites.SPANX);
157 spanY = values.getAsInteger(LauncherSettings.Favorites.SPANY);
158 rank = values.getAsInteger(LauncherSettings.Favorites.RANK);
Sunny Goyal756cd262015-08-20 12:33:21 -0700159 }
160
161 /**
162 * Write the fields of this item to the DB
Sunny Goyal756cd262015-08-20 12:33:21 -0700163 */
Sunny Goyal658058b2017-01-21 01:33:02 -0800164 public void onAddToDatabase(ContentWriter writer) {
Adrian Roos8f3f6832014-04-28 15:45:52 +0200165 if (screenId == Workspace.EXTRA_EMPTY_SCREEN_ID) {
166 // We should never persist an item on the extra empty screen.
167 throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
168 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169
Sunny Goyal32f3dda2016-11-11 11:45:00 -0800170 writeToValues(writer);
171 writer.put(LauncherSettings.Favorites.PROFILE_ID, user);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800172 }
Adam Cohen4eac29a2011-07-11 17:53:37 -0700173
Daniel Sandler8802e962010-05-26 16:28:16 -0400174 @Override
Sunny Goyal1edab712016-09-01 10:55:20 -0700175 public final String toString() {
176 return getClass().getSimpleName() + "(" + dumpProperties() + ")";
177 }
178
179 protected String dumpProperties() {
180 return "id=" + id
181 + " type=" + itemType
182 + " container=" + container
183 + " screen=" + screenId
184 + " cellX=" + cellX
185 + " cellY=" + cellY
186 + " spanX=" + spanX
187 + " spanY=" + spanY
188 + " minSpanX=" + minSpanX
189 + " minSpanY=" + minSpanY
190 + " rank=" + rank
191 + " user=" + user
192 + " title=" + title;
Daniel Sandler8802e962010-05-26 16:28:16 -0400193 }
Kenny Guy44cba692016-01-21 19:50:02 +0000194
195 /**
196 * Whether this item is disabled.
197 */
198 public boolean isDisabled() {
199 return false;
200 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800201}