2009-03-03 19:32:27 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-05 22:57:57 -04:00
|
|
|
package com.android.launcher3;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2016-04-28 17:39:03 -07:00
|
|
|
import android.content.ComponentName;
|
2009-03-03 19:32:27 -08:00
|
|
|
import android.content.ContentValues;
|
2012-05-07 10:34:12 -07:00
|
|
|
import android.content.Intent;
|
2016-12-15 15:53:17 -08:00
|
|
|
import android.os.Process;
|
|
|
|
|
import android.os.UserHandle;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2016-11-11 11:45:00 -08:00
|
|
|
import com.android.launcher3.util.ContentWriter;
|
2014-04-30 03:02:21 +01:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
|
|
|
|
* Represents an item in the launcher.
|
|
|
|
|
*/
|
2013-11-19 15:45:07 +00:00
|
|
|
public class ItemInfo {
|
2014-04-30 03:02:21 +01:00
|
|
|
|
2015-04-08 19:01:34 -07:00
|
|
|
public static final int NO_ID = -1;
|
2015-06-12 20:04:41 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
|
|
|
|
* The id in the settings database for this item
|
|
|
|
|
*/
|
2014-03-17 09:34:39 -07:00
|
|
|
public long id = NO_ID;
|
2015-06-12 20:04:41 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
|
|
|
|
* One of {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
|
|
|
|
|
* {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
|
2017-02-06 10:46:24 -08:00
|
|
|
* {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT}
|
|
|
|
|
* {@link LauncherSettings.Favorites#ITEM_TYPE_FOLDER},
|
|
|
|
|
* {@link LauncherSettings.Favorites#ITEM_TYPE_APPWIDGET} or
|
|
|
|
|
* {@link LauncherSettings.Favorites#ITEM_TYPE_CUSTOM_APPWIDGET}.
|
2009-03-03 19:32:27 -08:00
|
|
|
*/
|
2014-03-17 09:34:39 -07:00
|
|
|
public int itemType;
|
2015-06-12 20:04:41 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
2015-06-12 20:04:41 -07:00
|
|
|
* The id of the container that holds this item. For the desktop, this will be
|
2009-03-03 19:32:27 -08:00
|
|
|
* {@link LauncherSettings.Favorites#CONTAINER_DESKTOP}. For the all applications folder it
|
|
|
|
|
* will be {@link #NO_ID} (since it is not stored in the settings DB). For user folders
|
|
|
|
|
* it will be the id of the folder.
|
|
|
|
|
*/
|
2014-03-17 09:34:39 -07:00
|
|
|
public long container = NO_ID;
|
2015-06-12 20:04:41 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
2017-02-06 10:46:24 -08:00
|
|
|
* Indicates the screen in which the shortcut appears if the container types is
|
|
|
|
|
* {@link LauncherSettings.Favorites#CONTAINER_DESKTOP}. (i.e., ignore if the container type is
|
|
|
|
|
* {@link LauncherSettings.Favorites#CONTAINER_HOTSEAT})
|
2009-03-03 19:32:27 -08:00
|
|
|
*/
|
2014-03-17 09:34:39 -07:00
|
|
|
public long screenId = -1;
|
2015-06-12 20:04:41 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
|
|
|
|
* Indicates the X position of the associated cell.
|
|
|
|
|
*/
|
2014-03-17 09:34:39 -07:00
|
|
|
public int cellX = -1;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates the Y position of the associated cell.
|
|
|
|
|
*/
|
2014-03-17 09:34:39 -07:00
|
|
|
public int cellY = -1;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates the X cell span.
|
|
|
|
|
*/
|
2014-03-17 09:34:39 -07:00
|
|
|
public int spanX = 1;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates the Y cell span.
|
|
|
|
|
*/
|
2015-04-08 19:01:34 -07:00
|
|
|
public int spanY = 1;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2012-02-16 23:53:59 -08:00
|
|
|
/**
|
|
|
|
|
* Indicates the minimum X cell span.
|
|
|
|
|
*/
|
2014-03-17 09:34:39 -07:00
|
|
|
public int minSpanX = 1;
|
2012-02-16 23:53:59 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates the minimum Y cell span.
|
|
|
|
|
*/
|
2014-03-17 09:34:39 -07:00
|
|
|
public int minSpanY = 1;
|
2012-06-28 18:12:10 -07:00
|
|
|
|
2015-01-05 13:41:43 -08:00
|
|
|
/**
|
|
|
|
|
* Indicates the position in an ordered list.
|
|
|
|
|
*/
|
|
|
|
|
public int rank = 0;
|
|
|
|
|
|
2009-06-09 12:57:21 -07:00
|
|
|
/**
|
2012-06-28 18:12:10 -07:00
|
|
|
* Title of the item
|
2009-06-09 12:57:21 -07:00
|
|
|
*/
|
2015-04-08 19:01:34 -07:00
|
|
|
public CharSequence title;
|
2009-06-09 12:57:21 -07:00
|
|
|
|
2014-06-30 12:30:31 +01:00
|
|
|
/**
|
|
|
|
|
* Content description of the item.
|
|
|
|
|
*/
|
2015-04-08 19:01:34 -07:00
|
|
|
public CharSequence contentDescription;
|
2014-06-30 12:30:31 +01:00
|
|
|
|
2016-12-15 15:53:17 -08:00
|
|
|
public UserHandle user;
|
2014-04-30 03:02:21 +01:00
|
|
|
|
2015-04-08 19:01:34 -07:00
|
|
|
public ItemInfo() {
|
2016-12-15 15:53:17 -08:00
|
|
|
user = Process.myUserHandle();
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
2011-08-29 14:03:34 -07:00
|
|
|
ItemInfo(ItemInfo info) {
|
2014-07-23 13:58:07 -07:00
|
|
|
copyFrom(info);
|
|
|
|
|
// tempdebug:
|
|
|
|
|
LauncherModel.checkItemInfo(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void copyFrom(ItemInfo info) {
|
2009-03-03 19:32:27 -08:00
|
|
|
id = info.id;
|
|
|
|
|
cellX = info.cellX;
|
|
|
|
|
cellY = info.cellY;
|
|
|
|
|
spanX = info.spanX;
|
|
|
|
|
spanY = info.spanY;
|
2015-01-05 13:41:43 -08:00
|
|
|
rank = info.rank;
|
2013-06-18 13:13:40 -07:00
|
|
|
screenId = info.screenId;
|
2009-03-03 19:32:27 -08:00
|
|
|
itemType = info.itemType;
|
|
|
|
|
container = info.container;
|
2014-04-30 03:02:21 +01:00
|
|
|
user = info.user;
|
2014-06-30 12:30:31 +01:00
|
|
|
contentDescription = info.contentDescription;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
2014-03-17 09:34:39 -07:00
|
|
|
public Intent getIntent() {
|
2015-07-08 13:40:14 -07:00
|
|
|
return null;
|
2013-07-24 15:33:46 -07:00
|
|
|
}
|
|
|
|
|
|
2016-04-28 17:39:03 -07:00
|
|
|
public ComponentName getTargetComponent() {
|
2017-07-06 06:16:01 -07:00
|
|
|
Intent intent = getIntent();
|
2017-08-08 16:26:18 -07:00
|
|
|
if (intent != null) {
|
|
|
|
|
return intent.getComponent();
|
|
|
|
|
} else {
|
2017-07-06 06:16:01 -07:00
|
|
|
return null;
|
|
|
|
|
}
|
2016-04-28 17:39:03 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-11 11:45:00 -08:00
|
|
|
public void writeToValues(ContentWriter writer) {
|
|
|
|
|
writer.put(LauncherSettings.Favorites.ITEM_TYPE, itemType)
|
|
|
|
|
.put(LauncherSettings.Favorites.CONTAINER, container)
|
|
|
|
|
.put(LauncherSettings.Favorites.SCREEN, screenId)
|
|
|
|
|
.put(LauncherSettings.Favorites.CELLX, cellX)
|
|
|
|
|
.put(LauncherSettings.Favorites.CELLY, cellY)
|
|
|
|
|
.put(LauncherSettings.Favorites.SPANX, spanX)
|
|
|
|
|
.put(LauncherSettings.Favorites.SPANY, spanY)
|
|
|
|
|
.put(LauncherSettings.Favorites.RANK, rank);
|
2015-08-20 12:33:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void readFromValues(ContentValues values) {
|
|
|
|
|
itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE);
|
|
|
|
|
container = values.getAsLong(LauncherSettings.Favorites.CONTAINER);
|
|
|
|
|
screenId = values.getAsLong(LauncherSettings.Favorites.SCREEN);
|
2015-08-31 11:47:03 -07:00
|
|
|
cellX = values.getAsInteger(LauncherSettings.Favorites.CELLX);
|
|
|
|
|
cellY = values.getAsInteger(LauncherSettings.Favorites.CELLY);
|
|
|
|
|
spanX = values.getAsInteger(LauncherSettings.Favorites.SPANX);
|
|
|
|
|
spanY = values.getAsInteger(LauncherSettings.Favorites.SPANY);
|
|
|
|
|
rank = values.getAsInteger(LauncherSettings.Favorites.RANK);
|
2015-08-20 12:33:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write the fields of this item to the DB
|
|
|
|
|
*/
|
2017-01-21 01:33:02 -08:00
|
|
|
public void onAddToDatabase(ContentWriter writer) {
|
2014-04-28 15:45:52 +02:00
|
|
|
if (screenId == Workspace.EXTRA_EMPTY_SCREEN_ID) {
|
|
|
|
|
// We should never persist an item on the extra empty screen.
|
|
|
|
|
throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID");
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2016-11-11 11:45:00 -08:00
|
|
|
writeToValues(writer);
|
|
|
|
|
writer.put(LauncherSettings.Favorites.PROFILE_ID, user);
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
2011-07-11 17:53:37 -07:00
|
|
|
|
2010-05-26 16:28:16 -04:00
|
|
|
@Override
|
2016-09-01 10:55:20 -07:00
|
|
|
public final String toString() {
|
|
|
|
|
return getClass().getSimpleName() + "(" + dumpProperties() + ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected String dumpProperties() {
|
|
|
|
|
return "id=" + id
|
2017-02-06 10:46:24 -08:00
|
|
|
+ " type=" + LauncherSettings.Favorites.itemTypeToString(itemType)
|
|
|
|
|
+ " container=" + LauncherSettings.Favorites.containerToString((int)container)
|
2016-09-01 10:55:20 -07:00
|
|
|
+ " screen=" + screenId
|
2017-02-06 10:46:24 -08:00
|
|
|
+ " cell(" + cellX + "," + cellY + ")"
|
|
|
|
|
+ " span(" + spanX + "," + spanY + ")"
|
|
|
|
|
+ " minSpan(" + minSpanX + "," + minSpanY + ")"
|
2016-09-01 10:55:20 -07:00
|
|
|
+ " rank=" + rank
|
|
|
|
|
+ " user=" + user
|
|
|
|
|
+ " title=" + title;
|
2010-05-26 16:28:16 -04:00
|
|
|
}
|
2016-01-21 19:50:02 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether this item is disabled.
|
|
|
|
|
*/
|
|
|
|
|
public boolean isDisabled() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|