summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2018-10-04 15:11:00 -0700
committerSunny Goyal <sunnygoyal@google.com>2018-10-08 14:52:39 -0700
commitefb7e84242e174f7bb1a994889742820d229935d (patch)
treecd2b22e3ec324ebb0f7589df0c21ea7e03c89064 /src
parentf307b6032e708ee22b6e477e6c81ba07eecd4d4f (diff)
downloadpackages_apps_Trebuchet-efb7e84242e174f7bb1a994889742820d229935d.tar.gz
packages_apps_Trebuchet-efb7e84242e174f7bb1a994889742820d229935d.tar.bz2
packages_apps_Trebuchet-efb7e84242e174f7bb1a994889742820d229935d.zip
Converting long item IDs to int
> Items ids were already being typecasted to int when being bound on the UI > Using a consistent type allow better use of platform data-structures > Adding IntArray and IntSet as a replacement for various Collection classes Change-Id: Id3c650ed2420c2bfca3bd7671d2b705b56112371
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/AutoInstallsLayout.java57
-rw-r--r--src/com/android/launcher3/CellLayout.java6
-rw-r--r--src/com/android/launcher3/DefaultLayoutParser.java20
-rw-r--r--src/com/android/launcher3/ItemInfo.java10
-rw-r--r--src/com/android/launcher3/Launcher.java31
-rw-r--r--src/com/android/launcher3/LauncherModel.java31
-rw-r--r--src/com/android/launcher3/LauncherProvider.java68
-rw-r--r--src/com/android/launcher3/LauncherSettings.java2
-rw-r--r--src/com/android/launcher3/Utilities.java12
-rw-r--r--src/com/android/launcher3/Workspace.java80
-rw-r--r--src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java17
-rw-r--r--src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java2
-rw-r--r--src/com/android/launcher3/compat/UserManagerCompatVL.java13
-rw-r--r--src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java2
-rw-r--r--src/com/android/launcher3/icons/IconCacheUpdateHandler.java3
-rw-r--r--src/com/android/launcher3/model/AddWorkspaceItemsTask.java32
-rw-r--r--src/com/android/launcher3/model/BgDataModel.java15
-rw-r--r--src/com/android/launcher3/model/GridSizeMigrationTask.java42
-rw-r--r--src/com/android/launcher3/model/LoaderCursor.java32
-rw-r--r--src/com/android/launcher3/model/LoaderResults.java32
-rw-r--r--src/com/android/launcher3/model/LoaderTask.java17
-rw-r--r--src/com/android/launcher3/model/ModelWriter.java22
-rw-r--r--src/com/android/launcher3/model/PackageUpdatedTask.java4
-rw-r--r--src/com/android/launcher3/notification/NotificationListener.java3
-rw-r--r--src/com/android/launcher3/provider/ImportDataTask.java37
-rw-r--r--src/com/android/launcher3/provider/LauncherDbUtils.java22
-rw-r--r--src/com/android/launcher3/provider/LossyScreenMigrationTask.java14
-rw-r--r--src/com/android/launcher3/provider/RestoreDbTask.java2
-rw-r--r--src/com/android/launcher3/util/IntArray.java236
-rw-r--r--src/com/android/launcher3/util/IntSet.java51
-rw-r--r--src/com/android/launcher3/util/IntSparseArrayMap.java (renamed from src/com/android/launcher3/util/LongArrayMap.java)12
-rw-r--r--src/com/android/launcher3/util/ItemInfoMatcher.java2
32 files changed, 611 insertions, 318 deletions
diff --git a/src/com/android/launcher3/AutoInstallsLayout.java b/src/com/android/launcher3/AutoInstallsLayout.java
index 4c34071a9..c7c1d6ac0 100644
--- a/src/com/android/launcher3/AutoInstallsLayout.java
+++ b/src/com/android/launcher3/AutoInstallsLayout.java
@@ -40,6 +40,7 @@ import android.util.Patterns;
import com.android.launcher3.LauncherProvider.SqlArguments;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.icons.LauncherIcons;
+import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.Thunk;
import org.xmlpull.v1.XmlPullParser;
@@ -163,7 +164,7 @@ public class AutoInstallsLayout {
private final int mRowCount;
private final int mColumnCount;
- private final long[] mTemp = new long[2];
+ private final int[] mTemp = new int[2];
@Thunk final ContentValues mValues;
protected final String mRootTag;
@@ -191,7 +192,7 @@ public class AutoInstallsLayout {
/**
* Loads the layout in the db and returns the number of entries added on the desktop.
*/
- public int loadLayout(SQLiteDatabase db, ArrayList<Long> screenIds) {
+ public int loadLayout(SQLiteDatabase db, IntArray screenIds) {
mDb = db;
try {
return parseLayout(mLayoutId, screenIds);
@@ -204,7 +205,7 @@ public class AutoInstallsLayout {
/**
* Parses the layout and returns the number of elements added on the homescreen.
*/
- protected int parseLayout(int layoutId, ArrayList<Long> screenIds)
+ protected int parseLayout(int layoutId, IntArray screenIds)
throws XmlPullParserException, IOException {
XmlResourceParser parser = mSourceRes.getXml(layoutId);
beginDocument(parser, mRootTag);
@@ -227,14 +228,14 @@ public class AutoInstallsLayout {
* Parses container and screenId attribute from the current tag, and puts it in the out.
* @param out array of size 2.
*/
- protected void parseContainerAndScreen(XmlResourceParser parser, long[] out) {
+ protected void parseContainerAndScreen(XmlResourceParser parser, int[] out) {
if (HOTSEAT_CONTAINER_NAME.equals(getAttributeValue(parser, ATTR_CONTAINER))) {
out[0] = Favorites.CONTAINER_HOTSEAT;
// Hack: hotseat items are stored using screen ids
- out[1] = Long.parseLong(getAttributeValue(parser, ATTR_RANK));
+ out[1] = Integer.parseInt(getAttributeValue(parser, ATTR_RANK));
} else {
out[0] = Favorites.CONTAINER_DESKTOP;
- out[1] = Long.parseLong(getAttributeValue(parser, ATTR_SCREEN));
+ out[1] = Integer.parseInt(getAttributeValue(parser, ATTR_SCREEN));
}
}
@@ -242,9 +243,7 @@ public class AutoInstallsLayout {
* Parses the current node and returns the number of elements added.
*/
protected int parseAndAddNode(
- XmlResourceParser parser,
- ArrayMap<String, TagParser> tagParserMap,
- ArrayList<Long> screenIds)
+ XmlResourceParser parser, ArrayMap<String, TagParser> tagParserMap, IntArray screenIds)
throws XmlPullParserException, IOException {
if (TAG_INCLUDE.equals(parser.getName())) {
@@ -259,8 +258,8 @@ public class AutoInstallsLayout {
mValues.clear();
parseContainerAndScreen(parser, mTemp);
- final long container = mTemp[0];
- final long screenId = mTemp[1];
+ final int container = mTemp[0];
+ final int screenId = mTemp[1];
mValues.put(Favorites.CONTAINER, container);
mValues.put(Favorites.SCREEN, screenId);
@@ -275,7 +274,7 @@ public class AutoInstallsLayout {
if (LOGD) Log.d(TAG, "Ignoring unknown element tag: " + parser.getName());
return 0;
}
- long newElementId = tagParser.parseAndAdd(parser);
+ int newElementId = tagParser.parseAndAdd(parser);
if (newElementId >= 0) {
// Keep track of the set of screens which need to be added to the db.
if (!screenIds.contains(screenId) &&
@@ -287,8 +286,8 @@ public class AutoInstallsLayout {
return 0;
}
- protected long addShortcut(String title, Intent intent, int type) {
- long id = mCallback.generateNewItemId();
+ protected int addShortcut(String title, Intent intent, int type) {
+ int id = mCallback.generateNewItemId();
mValues.put(Favorites.INTENT, intent.toUri(0));
mValues.put(Favorites.TITLE, title);
mValues.put(Favorites.ITEM_TYPE, type);
@@ -325,7 +324,7 @@ public class AutoInstallsLayout {
* Parses the tag and adds to the db
* @return the id of the row added or -1;
*/
- long parseAndAdd(XmlResourceParser parser)
+ int parseAndAdd(XmlResourceParser parser)
throws XmlPullParserException, IOException;
}
@@ -335,7 +334,7 @@ public class AutoInstallsLayout {
protected class AppShortcutParser implements TagParser {
@Override
- public long parseAndAdd(XmlResourceParser parser) {
+ public int parseAndAdd(XmlResourceParser parser) {
final String packageName = getAttributeValue(parser, ATTR_PACKAGE_NAME);
final String className = getAttributeValue(parser, ATTR_CLASS_NAME);
@@ -372,7 +371,7 @@ public class AutoInstallsLayout {
/**
* Helper method to allow extending the parser capabilities
*/
- protected long invalidPackageOrClass(XmlResourceParser parser) {
+ protected int invalidPackageOrClass(XmlResourceParser parser) {
Log.w(TAG, "Skipping invalid <favorite> with no component");
return -1;
}
@@ -384,7 +383,7 @@ public class AutoInstallsLayout {
protected class AutoInstallParser implements TagParser {
@Override
- public long parseAndAdd(XmlResourceParser parser) {
+ public int parseAndAdd(XmlResourceParser parser) {
final String packageName = getAttributeValue(parser, ATTR_PACKAGE_NAME);
final String className = getAttributeValue(parser, ATTR_CLASS_NAME);
if (TextUtils.isEmpty(packageName) || TextUtils.isEmpty(className)) {
@@ -415,7 +414,7 @@ public class AutoInstallsLayout {
}
@Override
- public long parseAndAdd(XmlResourceParser parser) {
+ public int parseAndAdd(XmlResourceParser parser) {
final int titleResId = getAttributeResourceValue(parser, ATTR_TITLE, 0);
final int iconId = getAttributeResourceValue(parser, ATTR_ICON, 0);
@@ -471,7 +470,7 @@ public class AutoInstallsLayout {
protected class PendingWidgetParser implements TagParser {
@Override
- public long parseAndAdd(XmlResourceParser parser)
+ public int parseAndAdd(XmlResourceParser parser)
throws XmlPullParserException, IOException {
final String packageName = getAttributeValue(parser, ATTR_PACKAGE_NAME);
final String className = getAttributeValue(parser, ATTR_CLASS_NAME);
@@ -510,7 +509,7 @@ public class AutoInstallsLayout {
return verifyAndInsert(new ComponentName(packageName, className), extras);
}
- protected long verifyAndInsert(ComponentName cn, Bundle extras) {
+ protected int verifyAndInsert(ComponentName cn, Bundle extras) {
mValues.put(Favorites.APPWIDGET_PROVIDER, cn.flattenToString());
mValues.put(Favorites.RESTORED,
LauncherAppWidgetInfo.FLAG_ID_NOT_VALID |
@@ -521,7 +520,7 @@ public class AutoInstallsLayout {
mValues.put(Favorites.INTENT, new Intent().putExtras(extras).toUri(0));
}
- long insertedId = mCallback.insertAndCheck(mDb, mValues);
+ int insertedId = mCallback.insertAndCheck(mDb, mValues);
if (insertedId < 0) {
return -1;
} else {
@@ -542,7 +541,7 @@ public class AutoInstallsLayout {
}
@Override
- public long parseAndAdd(XmlResourceParser parser)
+ public int parseAndAdd(XmlResourceParser parser)
throws XmlPullParserException, IOException {
final String title;
final int titleResId = getAttributeResourceValue(parser, ATTR_TITLE, 0);
@@ -557,14 +556,14 @@ public class AutoInstallsLayout {
mValues.put(Favorites.SPANX, 1);
mValues.put(Favorites.SPANY, 1);
mValues.put(Favorites._ID, mCallback.generateNewItemId());
- long folderId = mCallback.insertAndCheck(mDb, mValues);
+ int folderId = mCallback.insertAndCheck(mDb, mValues);
if (folderId < 0) {
if (LOGD) Log.e(TAG, "Unable to add folder");
return -1;
}
final ContentValues myValues = new ContentValues(mValues);
- ArrayList<Long> folderItems = new ArrayList<>();
+ IntArray folderItems = new IntArray();
int type;
int folderDepth = parser.getDepth();
@@ -580,7 +579,7 @@ public class AutoInstallsLayout {
TagParser tagParser = mFolderElements.get(parser.getName());
if (tagParser != null) {
- final long id = tagParser.parseAndAdd(parser);
+ final int id = tagParser.parseAndAdd(parser);
if (id >= 0) {
folderItems.add(id);
rank++;
@@ -590,7 +589,7 @@ public class AutoInstallsLayout {
}
}
- long addedId = folderId;
+ int addedId = folderId;
// We can only have folders with >= 2 items, so we need to remove the
// folder and clean up if less than 2 items were included, or some
@@ -675,9 +674,9 @@ public class AutoInstallsLayout {
}
public interface LayoutParserCallback {
- long generateNewItemId();
+ int generateNewItemId();
- long insertAndCheck(SQLiteDatabase db, ContentValues values);
+ int insertAndCheck(SQLiteDatabase db, ContentValues values);
}
@Thunk static void copyInteger(ContentValues from, ContentValues to, String key) {
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index a42238e5b..92404d4cd 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -2063,7 +2063,7 @@ public class CellLayout extends ViewGroup {
private void commitTempPlacement() {
mTmpOccupied.copyTo(mOccupied);
- long screenId = mLauncher.getWorkspace().getIdForScreen(this);
+ int screenId = mLauncher.getWorkspace().getIdForScreen(this);
int container = Favorites.CONTAINER_DESKTOP;
if (mContainerType == HOTSEAT) {
@@ -2688,8 +2688,8 @@ public class CellLayout extends ViewGroup {
// the CellLayout that was long clicked
public static final class CellInfo extends CellAndSpan {
public final View cell;
- final long screenId;
- final long container;
+ final int screenId;
+ final int container;
public CellInfo(View v, ItemInfo info) {
cellX = info.cellX;
diff --git a/src/com/android/launcher3/DefaultLayoutParser.java b/src/com/android/launcher3/DefaultLayoutParser.java
index 1ec30ba68..44830e8fe 100644
--- a/src/com/android/launcher3/DefaultLayoutParser.java
+++ b/src/com/android/launcher3/DefaultLayoutParser.java
@@ -76,13 +76,13 @@ public class DefaultLayoutParser extends AutoInstallsLayout {
}
@Override
- protected void parseContainerAndScreen(XmlResourceParser parser, long[] out) {
+ protected void parseContainerAndScreen(XmlResourceParser parser, int[] out) {
out[0] = LauncherSettings.Favorites.CONTAINER_DESKTOP;
String strContainer = getAttributeValue(parser, ATTR_CONTAINER);
if (strContainer != null) {
- out[0] = Long.valueOf(strContainer);
+ out[0] = Integer.parseInt(strContainer);
}
- out[1] = Long.parseLong(getAttributeValue(parser, ATTR_SCREEN));
+ out[1] = Integer.parseInt(getAttributeValue(parser, ATTR_SCREEN));
}
/**
@@ -91,7 +91,7 @@ public class DefaultLayoutParser extends AutoInstallsLayout {
public class AppShortcutWithUriParser extends AppShortcutParser {
@Override
- protected long invalidPackageOrClass(XmlResourceParser parser) {
+ protected int invalidPackageOrClass(XmlResourceParser parser) {
final String uri = getAttributeValue(parser, ATTR_URI);
if (TextUtils.isEmpty(uri)) {
Log.e(TAG, "Skipping invalid <favorite> with no component or uri");
@@ -205,11 +205,11 @@ public class DefaultLayoutParser extends AutoInstallsLayout {
private final AppShortcutWithUriParser mChildParser = new AppShortcutWithUriParser();
@Override
- public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
+ public int parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
IOException {
final int groupDepth = parser.getDepth();
int type;
- long addedId = -1;
+ int addedId = -1;
while ((type = parser.next()) != XmlPullParser.END_TAG ||
parser.getDepth() > groupDepth) {
if (type != XmlPullParser.START_TAG || addedId > -1) {
@@ -233,7 +233,7 @@ public class DefaultLayoutParser extends AutoInstallsLayout {
@Thunk class PartnerFolderParser implements TagParser {
@Override
- public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
+ public int parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
IOException {
// Folder contents come from an external XML resource
final Partner partner = Partner.get(mPackageManager);
@@ -259,7 +259,7 @@ public class DefaultLayoutParser extends AutoInstallsLayout {
@Thunk class MyFolderParser extends FolderParser {
@Override
- public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
+ public int parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
IOException {
final int resId = getAttributeResourceValue(parser, ATTR_FOLDER_ITEMS, 0);
if (resId != 0) {
@@ -277,7 +277,7 @@ public class DefaultLayoutParser extends AutoInstallsLayout {
protected class AppWidgetParser extends PendingWidgetParser {
@Override
- protected long verifyAndInsert(ComponentName cn, Bundle extras) {
+ protected int verifyAndInsert(ComponentName cn, Bundle extras) {
try {
mPackageManager.getReceiverInfo(cn, 0);
} catch (Exception e) {
@@ -293,7 +293,7 @@ public class DefaultLayoutParser extends AutoInstallsLayout {
}
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
- long insertedId = -1;
+ int insertedId = -1;
try {
int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
diff --git a/src/com/android/launcher3/ItemInfo.java b/src/com/android/launcher3/ItemInfo.java
index fa3253c67..bffdd724b 100644
--- a/src/com/android/launcher3/ItemInfo.java
+++ b/src/com/android/launcher3/ItemInfo.java
@@ -34,7 +34,7 @@ public class ItemInfo {
/**
* The id in the settings database for this item
*/
- public long id = NO_ID;
+ public int id = NO_ID;
/**
* One of {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
@@ -52,14 +52,14 @@ public class ItemInfo {
* 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.
*/
- public long container = NO_ID;
+ public int container = NO_ID;
/**
* 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})
*/
- public long screenId = -1;
+ public int screenId = -1;
/**
* Indicates the X position of the associated cell.
@@ -158,8 +158,8 @@ public class ItemInfo {
public void readFromValues(ContentValues values) {
itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE);
- container = values.getAsLong(LauncherSettings.Favorites.CONTAINER);
- screenId = values.getAsLong(LauncherSettings.Favorites.SCREEN);
+ container = values.getAsInteger(LauncherSettings.Favorites.CONTAINER);
+ screenId = values.getAsInteger(LauncherSettings.Favorites.SCREEN);
cellX = values.getAsInteger(LauncherSettings.Favorites.CELLX);
cellY = values.getAsInteger(LauncherSettings.Favorites.CELLY);
spanX = values.getAsInteger(LauncherSettings.Favorites.SPANX);
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 5eb568853..4b181d8d8 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -108,6 +108,7 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.ActivityResultInfo;
import com.android.launcher3.util.ComponentKey;
+import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.MultiHashMap;
import com.android.launcher3.util.MultiValueAlpha;
@@ -490,9 +491,9 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
* Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
* a configuration step, this allows the proper animations to run after other transitions.
*/
- private long completeAdd(
+ private int completeAdd(
int requestCode, Intent intent, int appWidgetId, PendingRequestArgs info) {
- long screenId = info.screenId;
+ int screenId = info.screenId;
if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
// When the screen id represents an actual screen (as opposed to a rank) we make sure
// that the drop page actually exists.
@@ -694,7 +695,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
* @param screenId the screen id to check
* @return the new screen, or screenId if it exists
*/
- private long ensurePendingDropLayoutExists(long screenId) {
+ private int ensurePendingDropLayoutExists(int screenId) {
CellLayout dropLayout = mWorkspace.getScreenWithId(screenId);
if (dropLayout == null) {
// it's possible that the add screen was removed because it was
@@ -974,7 +975,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
*
* @param data The intent describing the shortcut.
*/
- private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
+ private void completeAddShortcut(Intent data, int container, int screenId, int cellX,
int cellY, PendingRequestArgs args) {
if (args.getRequestCode() != REQUEST_CREATE_SHORTCUT
|| args.getPendingIntent().getComponent() == null) {
@@ -1050,7 +1051,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
}
}
- public FolderIcon findFolderIcon(final long folderIconId) {
+ public FolderIcon findFolderIcon(final int folderIconId) {
return (FolderIcon) mWorkspace.getHomescreenIconByItemId(folderIconId);
}
@@ -1413,7 +1414,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
}
}
- public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
+ public void addPendingItem(PendingAddItemInfo info, int container, int screenId,
int[] cell, int spanX, int spanY) {
info.container = container;
info.screenId = screenId;
@@ -1489,7 +1490,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
}
}
- FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
+ FolderIcon addFolder(CellLayout layout, int container, final int screenId, int cellX,
int cellY) {
final FolderInfo folderInfo = new FolderInfo();
folderInfo.title = getText(R.string.folder_name);
@@ -1650,7 +1651,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
/**
* Returns the CellLayout of the specified container at the specified screen.
*/
- public CellLayout getCellLayout(long container, long screenId) {
+ public CellLayout getCellLayout(int container, int screenId) {
if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
if (mHotseat != null) {
return mHotseat.getLayout();
@@ -1750,11 +1751,11 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
}
@Override
- public void bindScreens(ArrayList<Long> orderedScreenIds) {
+ public void bindScreens(IntArray orderedScreenIds) {
// Make sure the first screen is always at the start.
if (FeatureFlags.getInstance(this).isQsbOnFirstScreenEnabled() &&
orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
- orderedScreenIds.remove(Workspace.FIRST_SCREEN_ID);
+ orderedScreenIds.removeValue(Workspace.FIRST_SCREEN_ID);
orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID);
LauncherModel.updateWorkspaceScreenOrder(this, orderedScreenIds);
} else if (!FeatureFlags.getInstance(this).isQsbOnFirstScreenEnabled()
@@ -1770,10 +1771,10 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout();
}
- private void bindAddScreens(ArrayList<Long> orderedScreenIds) {
+ private void bindAddScreens(IntArray orderedScreenIds) {
int count = orderedScreenIds.size();
for (int i = 0; i < count; i++) {
- long screenId = orderedScreenIds.get(i);
+ int screenId = orderedScreenIds.get(i);
if (!FeatureFlags.getInstance(this).isQsbOnFirstScreenEnabled()
|| screenId != Workspace.FIRST_SCREEN_ID) {
// No need to bind the first screen, as its always bound.
@@ -1794,7 +1795,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
}
@Override
- public void bindAppsAdded(ArrayList<Long> newScreens, ArrayList<ItemInfo> addNotAnimated,
+ public void bindAppsAdded(IntArray newScreens, ArrayList<ItemInfo> addNotAnimated,
ArrayList<ItemInfo> addAnimated) {
// Add the new screens
if (newScreens != null) {
@@ -1825,7 +1826,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
final Collection<Animator> bounceAnims = new ArrayList<>();
final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
Workspace workspace = mWorkspace;
- long newItemsScreenId = -1;
+ int newItemsScreenId = -1;
int end = items.size();
for (int i = 0; i < end; i++) {
final ItemInfo item = items.get(i);
@@ -1898,7 +1899,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
AnimatorSet anim = new AnimatorSet();
anim.playTogether(bounceAnims);
- long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
+ int currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newItemsScreenId);
final Runnable startBounceAnimRunnable = anim::start;
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 5424d97bf..d571cf47d 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -55,6 +55,7 @@ import com.android.launcher3.provider.LauncherDbUtils;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.util.ComponentKey;
+import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.MultiHashMap;
import com.android.launcher3.util.PackageUserKey;
@@ -143,15 +144,14 @@ public class LauncherModel extends BroadcastReceiver
public void clearPendingBinds();
public void startBinding();
public void bindItems(List<ItemInfo> shortcuts, boolean forceAnimateIcons);
- public void bindScreens(ArrayList<Long> orderedScreenIds);
+ public void bindScreens(IntArray orderedScreenIds);
public void finishFirstPageBind(ViewOnDrawExecutor executor);
public void finishBindingItems(int currentScreen);
public void bindAllApplications(ArrayList<AppInfo> apps);
public void bindAppsAddedOrUpdated(ArrayList<AppInfo> apps);
public void preAddApps();
- public void bindAppsAdded(ArrayList<Long> newScreens,
- ArrayList<ItemInfo> addNotAnimated,
- ArrayList<ItemInfo> addAnimated);
+ public void bindAppsAdded(IntArray newScreens,
+ ArrayList<ItemInfo> addNotAnimated, ArrayList<ItemInfo> addAnimated);
public void bindPromiseAppProgressUpdated(PromiseAppInfo app);
public void bindShortcutsChanged(ArrayList<ShortcutInfo> updated, UserHandle user);
public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets);
@@ -211,7 +211,7 @@ public class LauncherModel extends BroadcastReceiver
}
static void checkItemInfoLocked(
- final long itemId, final ItemInfo item, StackTraceElement[] stackTrace) {
+ final int itemId, final ItemInfo item, StackTraceElement[] stackTrace) {
if (com.android.launcher3.Utilities.IS_RUNNING_IN_TEST_HARNESS
&& com.android.launcher3.Utilities.IS_DEBUG_DEVICE) {
android.util.Log.d("b/117332845",
@@ -255,7 +255,7 @@ public class LauncherModel extends BroadcastReceiver
static void checkItemInfo(final ItemInfo item) {
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
- final long itemId = item.id;
+ final int itemId = item.id;
Runnable r = new Runnable() {
public void run() {
synchronized (sBgDataModel) {
@@ -270,17 +270,16 @@ public class LauncherModel extends BroadcastReceiver
* Update the order of the workspace screens in the database. The array list contains
* a list of screen ids in the order that they should appear.
*/
- public static void updateWorkspaceScreenOrder(Context context, final ArrayList<Long> screens) {
- final ArrayList<Long> screensCopy = new ArrayList<Long>(screens);
+ public static void updateWorkspaceScreenOrder(Context context, IntArray screens) {
final ContentResolver cr = context.getContentResolver();
final Uri uri = LauncherSettings.WorkspaceScreens.CONTENT_URI;
- // Remove any negative screen ids -- these aren't persisted
- Iterator<Long> iter = screensCopy.iterator();
- while (iter.hasNext()) {
- long id = iter.next();
- if (id < 0) {
- iter.remove();
+ // Create a copy with only non-negative values
+ final IntArray screensCopy = new IntArray();
+ for (int i = 0; i < screens.size(); i++) {
+ int id = screens.get(i);
+ if (id >= 0) {
+ screensCopy.add(id);
}
}
@@ -293,7 +292,7 @@ public class LauncherModel extends BroadcastReceiver
int count = screensCopy.size();
for (int i = 0; i < count; i++) {
ContentValues v = new ContentValues();
- long screenId = screensCopy.get(i);
+ int screenId = screensCopy.get(i);
v.put(LauncherSettings.WorkspaceScreens._ID, screenId);
v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i);
ops.add(ContentProviderOperation.newInsert(uri).withValues(v).build());
@@ -516,7 +515,7 @@ public class LauncherModel extends BroadcastReceiver
/**
* Loads the workspace screen ids in an ordered list.
*/
- public static ArrayList<Long> loadWorkspaceScreensDb(Context context) {
+ public static IntArray loadWorkspaceScreensDb(Context context) {
final ContentResolver contentResolver = context.getContentResolver();
final Uri screensUri = LauncherSettings.WorkspaceScreens.CONTENT_URI;
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index ddb2721c3..a423a90f8 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -58,6 +58,8 @@ import com.android.launcher3.model.DbDowngradeHelper;
import com.android.launcher3.provider.LauncherDbUtils;
import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;
import com.android.launcher3.provider.RestoreDbTask;
+import com.android.launcher3.util.IntArray;
+import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.NoLocaleSQLiteHelper;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.Thunk;
@@ -67,6 +69,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
@@ -170,7 +173,7 @@ public class LauncherProvider extends ContentProvider {
return result;
}
- @Thunk static long dbInsertAndCheck(DatabaseHelper helper,
+ @Thunk static int dbInsertAndCheck(DatabaseHelper helper,
SQLiteDatabase db, String table, String nullColumnHack, ContentValues values) {
if (values == null) {
throw new RuntimeException("Error: attempting to insert null values");
@@ -179,7 +182,7 @@ public class LauncherProvider extends ContentProvider {
throw new RuntimeException("Error: attempting to add item without specifying an id");
}
helper.checkId(table, values);
- return db.insert(table, nullColumnHack, values);
+ return (int) db.insert(table, nullColumnHack, values);
}
private void reloadLauncherIfExternal() {
@@ -205,7 +208,7 @@ public class LauncherProvider extends ContentProvider {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
addModifiedTime(initialValues);
- final long rowId = dbInsertAndCheck(mOpenHelper, db, args.table, null, initialValues);
+ final int rowId = dbInsertAndCheck(mOpenHelper, db, args.table, null, initialValues);
if (rowId < 0) return null;
uri = ContentUris.withAppendedId(uri, rowId);
@@ -230,7 +233,7 @@ public class LauncherProvider extends ContentProvider {
private boolean initializeExternalAdd(ContentValues values) {
// 1. Ensure that externally added items have a valid item id
- long id = mOpenHelper.generateNewItemId();
+ int id = mOpenHelper.generateNewItemId();
values.put(LauncherSettings.Favorites._ID, id);
// 2. In the case of an app widget, and if no app widget id is specified, we
@@ -263,7 +266,7 @@ public class LauncherProvider extends ContentProvider {
}
// Add screen id if not present
- long screenId = values.getAsLong(LauncherSettings.Favorites.SCREEN);
+ int screenId = values.getAsInteger(LauncherSettings.Favorites.SCREEN);
SQLiteStatement stmp = null;
try {
stmp = mOpenHelper.getWritableDatabase().compileStatement(
@@ -369,17 +372,18 @@ public class LauncherProvider extends ContentProvider {
}
case LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS: {
Bundle result = new Bundle();
- result.putSerializable(LauncherSettings.Settings.EXTRA_VALUE, deleteEmptyFolders());
+ result.putIntArray(LauncherSettings.Settings.EXTRA_VALUE, deleteEmptyFolders()
+ .toArray());
return result;
}
case LauncherSettings.Settings.METHOD_NEW_ITEM_ID: {
Bundle result = new Bundle();
- result.putLong(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewItemId());
+ result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewItemId());
return result;
}
case LauncherSettings.Settings.METHOD_NEW_SCREEN_ID: {
Bundle result = new Bundle();
- result.putLong(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewScreenId());
+ result.putInt(LauncherSettings.Settings.EXTRA_VALUE, mOpenHelper.generateNewScreenId());
return result;
}
case LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB: {
@@ -402,8 +406,8 @@ public class LauncherProvider extends ContentProvider {
* Deletes any empty folder from the DB.
* @return Ids of deleted folders.
*/
- private ArrayList<Long> deleteEmptyFolders() {
- ArrayList<Long> folderIds = new ArrayList<>();
+ private IntArray deleteEmptyFolders() {
+ IntArray folderIds = new IntArray();
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
try (SQLiteTransaction t = new SQLiteTransaction(db)) {
// Select folders whose id do not match any container value.
@@ -542,8 +546,8 @@ public class LauncherProvider extends ContentProvider {
public static class DatabaseHelper extends NoLocaleSQLiteHelper implements LayoutParserCallback {
private final Handler mWidgetHostResetHandler;
private final Context mContext;
- private long mMaxItemId = -1;
- private long mMaxScreenId = -1;
+ private int mMaxItemId = -1;
+ private int mMaxScreenId = -1;
DatabaseHelper(Context context, Handler widgetHostResetHandler) {
this(context, widgetHostResetHandler, LauncherFiles.LAUNCHER_DB);
@@ -844,7 +848,7 @@ public class LauncherProvider extends ContentProvider {
Log.e(TAG, "getAppWidgetIds not supported", e);
return;
}
- final HashSet<Integer> validWidgets = new HashSet<>();
+ final IntSet validWidgets = new IntSet();
try (Cursor c = db.query(Favorites.TABLE_NAME,
new String[] {Favorites.APPWIDGET_ID },
"itemType=" + Favorites.ITEM_TYPE_APPWIDGET, null, null, null, null)) {
@@ -899,7 +903,7 @@ public class LauncherProvider extends ContentProvider {
continue;
}
- long id = c.getLong(idIndex);
+ int id = c.getInt(idIndex);
updateStmt.bindLong(1, id);
updateStmt.executeUpdateDelete();
}
@@ -914,15 +918,14 @@ public class LauncherProvider extends ContentProvider {
*/
public boolean recreateWorkspaceTable(SQLiteDatabase db) {
try (SQLiteTransaction t = new SQLiteTransaction(db)) {
- final ArrayList<Long> sortedIDs;
+ final IntArray sortedIDs;
try (Cursor c = db.query(WorkspaceScreens.TABLE_NAME,
new String[] {LauncherSettings.WorkspaceScreens._ID},
null, null, null, null,
LauncherSettings.WorkspaceScreens.SCREEN_RANK)) {
// Use LinkedHashSet so that ordering is preserved
- sortedIDs = new ArrayList<>(
- LauncherDbUtils.iterateCursor(c, 0, new LinkedHashSet<Long>()));
+ sortedIDs = LauncherDbUtils.getScreenIdsFromCursor(c);
}
db.execSQL("DROP TABLE IF EXISTS " + WorkspaceScreens.TABLE_NAME);
addWorkspacesTable(db, false);
@@ -937,7 +940,11 @@ public class LauncherProvider extends ContentProvider {
db.insertOrThrow(WorkspaceScreens.TABLE_NAME, null, values);
}
t.commit();
- mMaxScreenId = sortedIDs.isEmpty() ? 0 : Collections.max(sortedIDs);
+
+ mMaxScreenId = 0;
+ for (int i = 0; i < sortedIDs.size(); i++) {
+ mMaxScreenId = Math.max(mMaxScreenId, sortedIDs.get(i));
+ }
} catch (SQLException ex) {
// Old version remains, which means we wipe old data
Log.e(TAG, ex.getMessage(), ex);
@@ -997,7 +1004,7 @@ public class LauncherProvider extends ContentProvider {
// constructor is called, and we only pass a reference to LauncherProvider to LauncherApp
// after that point
@Override
- public long generateNewItemId() {
+ public int generateNewItemId() {
if (mMaxItemId < 0) {
throw new RuntimeException("Error: max item id was not initialized");
}
@@ -1010,12 +1017,12 @@ public class LauncherProvider extends ContentProvider {
}
@Override
- public long insertAndCheck(SQLiteDatabase db, ContentValues values) {
+ public int insertAndCheck(SQLiteDatabase db, ContentValues values) {
return dbInsertAndCheck(this, db, Favorites.TABLE_NAME, null, values);
}
public void checkId(String table, ContentValues values) {
- long id = values.getAsLong(LauncherSettings.BaseLauncherColumns._ID);
+ int id = values.getAsInteger(LauncherSettings.BaseLauncherColumns._ID);
if (WorkspaceScreens.TABLE_NAME.equals(table)) {
mMaxScreenId = Math.max(id, mMaxScreenId);
} else {
@@ -1023,7 +1030,7 @@ public class LauncherProvider extends ContentProvider {
}
}
- private long initializeMaxItemId(SQLiteDatabase db) {
+ private int initializeMaxItemId(SQLiteDatabase db) {
return getMaxId(db, Favorites.TABLE_NAME);
}
@@ -1032,7 +1039,7 @@ public class LauncherProvider extends ContentProvider {
// call the constructor from the worker thread; however, this doesn't extend until after the
// constructor is called, and we only pass a reference to LauncherProvider to LauncherApp
// after that point
- public long generateNewScreenId() {
+ public int generateNewScreenId() {
if (mMaxScreenId < 0) {
throw new RuntimeException("Error: max screen id was not initialized");
}
@@ -1040,20 +1047,21 @@ public class LauncherProvider extends ContentProvider {
return mMaxScreenId;
}
- private long initializeMaxScreenId(SQLiteDatabase db) {
+ private int initializeMaxScreenId(SQLiteDatabase db) {
return getMaxId(db, WorkspaceScreens.TABLE_NAME);
}
@Thunk int loadFavorites(SQLiteDatabase db, AutoInstallsLayout loader) {
- ArrayList<Long> screenIds = new ArrayList<Long>();
+ IntArray screenIds = new IntArray();
// TODO: Use multiple loaders with fall-back and transaction.
int count = loader.loadLayout(db, screenIds);
// Add the screens specified by the items above
- Collections.sort(screenIds);
+ int[] sortedScreenIds = screenIds.toArray();
+ Arrays.sort(sortedScreenIds);
int rank = 0;
ContentValues values = new ContentValues();
- for (Long id : screenIds) {
+ for (int id : sortedScreenIds) {
values.clear();
values.put(LauncherSettings.WorkspaceScreens._ID, id);
values.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, rank);
@@ -1075,12 +1083,12 @@ public class LauncherProvider extends ContentProvider {
/**
* @return the max _id in the provided table.
*/
- @Thunk static long getMaxId(SQLiteDatabase db, String table) {
+ @Thunk static int getMaxId(SQLiteDatabase db, String table) {
Cursor c = db.rawQuery("SELECT MAX(_id) FROM " + table, null);
// get the result
- long id = -1;
+ int id = -1;
if (c != null && c.moveToNext()) {
- id = c.getLong(0);
+ id = c.getInt(0);
}
if (c != null) {
c.close();
diff --git a/src/com/android/launcher3/LauncherSettings.java b/src/com/android/launcher3/LauncherSettings.java
index 3b337ef18..0b12b15f9 100644
--- a/src/com/android/launcher3/LauncherSettings.java
+++ b/src/com/android/launcher3/LauncherSettings.java
@@ -128,7 +128,7 @@ public class LauncherSettings {
*
* @return The unique content URL for the specified row.
*/
- public static Uri getContentUri(long id) {
+ public static Uri getContentUri(int id) {
return Uri.parse("content://" + LauncherProvider.AUTHORITY +
"/" + TABLE_NAME + "/" + id);
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 231c4b77e..d11cfcb0c 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -52,6 +52,7 @@ import android.view.View;
import android.view.animation.Interpolator;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.util.IntArray;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
@@ -456,8 +457,8 @@ public final class Utilities {
size, metrics));
}
- public static String createDbSelectionQuery(String columnName, Iterable<?> values) {
- return String.format(Locale.ENGLISH, "%s IN (%s)", columnName, TextUtils.join(", ", values));
+ public static String createDbSelectionQuery(String columnName, IntArray values) {
+ return String.format(Locale.ENGLISH, "%s IN (%s)", columnName, values.toConcatString());
}
public static boolean isBootCompleted() {
@@ -514,13 +515,6 @@ public final class Utilities {
return spanned;
}
- /**
- * Replacement for Long.compare() which was added in API level 19.
- */
- public static int longCompare(long lhs, long rhs) {
- return lhs < rhs ? -1 : (lhs == rhs ? 0 : 1);
- }
-
public static SharedPreferences getPrefs(Context context) {
return context.getSharedPreferences(
LauncherFiles.SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE);
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index df434837e..5e1c54cfb 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -28,7 +28,6 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.LayoutTransition;
import android.animation.ObjectAnimator;
-import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.SuppressLint;
@@ -85,8 +84,10 @@ import com.android.launcher3.touch.WorkspaceTouchListener;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
+import com.android.launcher3.util.IntArray;
+import com.android.launcher3.util.IntSparseArrayMap;
+import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.ItemInfoMatcher;
-import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.WallpaperOffsetInterpolator;
@@ -130,17 +131,17 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
private static final boolean MAP_RECURSE = true;
// The screen id used for the empty screen always present to the right.
- public static final long EXTRA_EMPTY_SCREEN_ID = -201;
+ public static final int EXTRA_EMPTY_SCREEN_ID = -201;
// The is the first screen. It is always present, even if its empty.
- public static final long FIRST_SCREEN_ID = 0;
+ public static final int FIRST_SCREEN_ID = 0;
private LayoutTransition mLayoutTransition;
@Thunk final WallpaperManager mWallpaperManager;
private ShortcutAndWidgetContainer mDragSourceInternal;
- @Thunk final LongArrayMap<CellLayout> mWorkspaceScreens = new LongArrayMap<>();
- @Thunk final ArrayList<Long> mScreenOrder = new ArrayList<>();
+ @Thunk final IntSparseArrayMap<CellLayout> mWorkspaceScreens = new IntSparseArrayMap<>();
+ @Thunk final IntArray mScreenOrder = new IntArray();
@Thunk Runnable mRemoveEmptyScreenRunnable;
@Thunk boolean mDeferRemoveExtraEmptyScreen = false;
@@ -227,7 +228,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
@Thunk int mLastReorderY = -1;
private SparseArray<Parcelable> mSavedStates;
- private final ArrayList<Integer> mRestoredPages = new ArrayList<>();
+ private final IntArray mRestoredPages = new IntArray();
private float mCurrentScale;
private float mTransitionProgress;
@@ -523,7 +524,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
enableLayoutTransitions();
}
- public void insertNewWorkspaceScreenBeforeEmptyScreen(long screenId) {
+ public void insertNewWorkspaceScreenBeforeEmptyScreen(int screenId) {
// Find the index to insert this view into. If the empty screen exists, then
// insert it before that.
int insertIndex = mScreenOrder.indexOf(EXTRA_EMPTY_SCREEN_ID);
@@ -533,11 +534,11 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
insertNewWorkspaceScreen(screenId, insertIndex);
}
- public void insertNewWorkspaceScreen(long screenId) {
+ public void insertNewWorkspaceScreen(int screenId) {
insertNewWorkspaceScreen(screenId, getChildCount());
}
- public CellLayout insertNewWorkspaceScreen(long screenId, int insertIndex) {
+ public CellLayout insertNewWorkspaceScreen(int screenId, int insertIndex) {
if (mWorkspaceScreens.containsKey(screenId)) {
throw new RuntimeException("Screen id " + screenId + " already exists!");
}
@@ -604,7 +605,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
}
if (hasExtraEmptyScreen() || mScreenOrder.size() == 0) return;
- long finalScreenId = mScreenOrder.get(mScreenOrder.size() - 1);
+ int finalScreenId = mScreenOrder.get(mScreenOrder.size() - 1);
CellLayout finalScreen = mWorkspaceScreens.get(finalScreenId);
@@ -612,7 +613,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
if (finalScreen.getShortcutsAndWidgets().getChildCount() == 0 &&
!finalScreen.isDropPending()) {
mWorkspaceScreens.remove(finalScreenId);
- mScreenOrder.remove(finalScreenId);
+ mScreenOrder.removeValue(finalScreenId);
// if this is the last screen, convert it to the empty screen
mWorkspaceScreens.put(EXTRA_EMPTY_SCREEN_ID, finalScreen);
@@ -678,7 +679,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
public void run() {
if (hasExtraEmptyScreen()) {
mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID);
- mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID);
+ mScreenOrder.removeValue(EXTRA_EMPTY_SCREEN_ID);
removeView(cl);
if (stripEmptyScreens) {
stripEmptyScreens();
@@ -710,7 +711,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
return mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) && getChildCount() > 1;
}
- public long commitExtraEmptyScreen() {
+ public int commitExtraEmptyScreen() {
if (mLauncher.isWorkspaceLoading()) {
// Invalid and dangerous operation if workspace is loading
return -1;
@@ -718,11 +719,11 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID);
mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID);
- mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID);
+ mScreenOrder.removeValue(EXTRA_EMPTY_SCREEN_ID);
- long newId = LauncherSettings.Settings.call(getContext().getContentResolver(),
+ int newId = LauncherSettings.Settings.call(getContext().getContentResolver(),
LauncherSettings.Settings.METHOD_NEW_SCREEN_ID)
- .getLong(LauncherSettings.Settings.EXTRA_VALUE);
+ .getInt(LauncherSettings.Settings.EXTRA_VALUE);
mWorkspaceScreens.put(newId, cl);
mScreenOrder.add(newId);
@@ -732,11 +733,11 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
return newId;
}
- public CellLayout getScreenWithId(long screenId) {
+ public CellLayout getScreenWithId(int screenId) {
return mWorkspaceScreens.get(screenId);
}
- public long getIdForScreen(CellLayout layout) {
+ public int getIdForScreen(CellLayout layout) {
int index = mWorkspaceScreens.indexOfValue(layout);
if (index != -1) {
return mWorkspaceScreens.keyAt(index);
@@ -744,18 +745,18 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
return -1;
}
- public int getPageIndexForScreenId(long screenId) {
+ public int getPageIndexForScreenId(int screenId) {
return indexOfChild(mWorkspaceScreens.get(screenId));
}
- public long getScreenIdForPageIndex(int index) {
+ public int getScreenIdForPageIndex(int index) {
if (0 <= index && index < mScreenOrder.size()) {
return mScreenOrder.get(index);
}
return -1;
}
- public ArrayList<Long> getScreenOrder() {
+ public IntArray getScreenOrder() {
return mScreenOrder;
}
@@ -772,10 +773,10 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
}
int currentPage = getNextPage();
- ArrayList<Long> removeScreens = new ArrayList<>();
+ IntArray removeScreens = new IntArray();
int total = mWorkspaceScreens.size();
for (int i = 0; i < total; i++) {
- long id = mWorkspaceScreens.keyAt(i);
+ int id = mWorkspaceScreens.keyAt(i);
CellLayout cl = mWorkspaceScreens.valueAt(i);
// FIRST_SCREEN_ID can never be removed.
boolean qsbFirstScreenEnabled =
@@ -793,10 +794,11 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
int minScreens = 1;
int pageShift = 0;
- for (Long id: removeScreens) {
+ for (int i = 0; i < removeScreens.size(); i++) {
+ int id = removeScreens.get(i);
CellLayout cl = mWorkspaceScreens.get(id);
mWorkspaceScreens.remove(id);
- mScreenOrder.remove(id);
+ mScreenOrder.removeValue(id);
if (getChildCount() > minScreens) {
if (indexOfChild(cl) < currentPage) {
@@ -845,7 +847,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
/**
* Adds the specified child in the specified screen based on the {@param info}
- * See {@link #addInScreen(View, long, long, int, int, int, int)}.
+ * See {@link #addInScreen(View, int, int, int, int, int, int)}.
*/
public void addInScreen(View child, ItemInfo info) {
addInScreen(child, info.container, info.screenId, info.cellX, info.cellY,
@@ -863,7 +865,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
* @param spanX The number of cells spanned horizontally by the child.
* @param spanY The number of cells spanned vertically by the child.
*/
- private void addInScreen(View child, long container, long screenId, int x, int y,
+ private void addInScreen(View child, int container, int screenId, int x, int y,
int spanX, int spanY) {
if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
if (getScreenWithId(screenId) == null) {
@@ -1677,7 +1679,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
}
}
- long screenId = getIdForScreen(dropTargetLayout);
+ int screenId = getIdForScreen(dropTargetLayout);
if (screenId == EXTRA_EMPTY_SCREEN_ID) {
commitExtraEmptyScreen();
}
@@ -1742,7 +1744,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
return false;
}
- boolean createUserFolderIfNecessary(View newView, long container, CellLayout target,
+ boolean createUserFolderIfNecessary(View newView, int container, CellLayout target,
int[] targetCell, float distance, boolean external, DragView dragView) {
if (distance > mMaxDistanceForFolderCreation) return false;
View v = target.getChildAt(targetCell[0], targetCell[1]);
@@ -1756,7 +1758,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
if (v == null || hasntMoved || !mCreateUserFolderOnDrop) return false;
mCreateUserFolderOnDrop = false;
- final long screenId = getIdForScreen(target);
+ final int screenId = getIdForScreen(target);
boolean aboveShortcut = (v.getTag() instanceof ShortcutInfo);
boolean willBecomeShortcut = (newView.getTag() instanceof ShortcutInfo);
@@ -1855,10 +1857,10 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
// Move internally
boolean hasMovedLayouts = (getParentCellLayoutForView(cell) != dropTargetLayout);
boolean hasMovedIntoHotseat = mLauncher.isHotseatLayout(dropTargetLayout);
- long container = hasMovedIntoHotseat ?
+ int container = hasMovedIntoHotseat ?
LauncherSettings.Favorites.CONTAINER_HOTSEAT :
LauncherSettings.Favorites.CONTAINER_DESKTOP;
- long screenId = (mTargetCell[0] < 0) ?
+ int screenId = (mTargetCell[0] < 0) ?
mDragInfo.screenId : getIdForScreen(dropTargetLayout);
int spanX = mDragInfo != null ? mDragInfo.spanX : 1;
int spanY = mDragInfo != null ? mDragInfo.spanY : 1;
@@ -2532,10 +2534,10 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
spanY = mDragInfo.spanY;
}
- final long container = mLauncher.isHotseatLayout(cellLayout) ?
+ final int container = mLauncher.isHotseatLayout(cellLayout) ?
LauncherSettings.Favorites.CONTAINER_HOTSEAT :
LauncherSettings.Favorites.CONTAINER_DESKTOP;
- final long screenId = getIdForScreen(cellLayout);
+ final int screenId = getIdForScreen(cellLayout);
if (!mLauncher.isHotseatLayout(cellLayout)
&& screenId != getScreenIdForPageIndex(mCurrentPage)
&& !mLauncher.isInState(SPRING_LOADED)) {
@@ -3008,7 +3010,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
return childrenLayouts;
}
- public View getHomescreenIconByItemId(final long id) {
+ public View getHomescreenIconByItemId(final int id) {
return getFirstMatch(new ItemOperator() {
@Override
@@ -3067,7 +3069,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
for (final CellLayout layoutParent: cellLayouts) {
final ViewGroup layout = layoutParent.getShortcutsAndWidgets();
- LongArrayMap<View> idToViewMap = new LongArrayMap<>();
+ IntSparseArrayMap<View> idToViewMap = new IntSparseArrayMap<>();
ArrayList<ItemInfo> items = new ArrayList<>();
for (int j = 0; j < layout.getChildCount(); j++) {
final View view = layout.getChildAt(j);
@@ -3155,7 +3157,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
void updateShortcuts(ArrayList<ShortcutInfo> shortcuts) {
int total = shortcuts.size();
final HashSet<ShortcutInfo> updates = new HashSet<>(total);
- final HashSet<Long> folderIds = new HashSet<>();
+ final IntSet folderIds = new IntSet();
for (int i = 0; i < total; i++) {
ShortcutInfo s = shortcuts.get(i);
@@ -3195,7 +3197,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
public void updateIconBadges(final Set<PackageUserKey> updatedBadges) {
final PackageUserKey packageUserKey = new PackageUserKey(null, null);
- final HashSet<Long> folderIds = new HashSet<>();
+ final IntSet folderIds = new IntSet();
mapOverItems(MAP_RECURSE, new ItemOperator() {
@Override
public boolean evaluate(ItemInfo info, View v) {
diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
index 81a0e1d5d..84edb3dac 100644
--- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
+++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
@@ -39,6 +39,7 @@ import com.android.launcher3.notification.NotificationListener;
import com.android.launcher3.popup.PopupContainerWithArrow;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.touch.ItemLongClickListener;
+import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.widget.LauncherAppWidgetHostView;
@@ -159,7 +160,7 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme
beginAccessibleDrag(host, item);
} else if (action == ADD_TO_WORKSPACE) {
final int[] coordinates = new int[2];
- final long screenId = findSpaceOnWorkspace(item, coordinates);
+ final int screenId = findSpaceOnWorkspace(item, coordinates);
mLauncher.getStateManager().goToState(NORMAL, true, new Runnable() {
@Override
@@ -191,7 +192,7 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme
folder.getInfo().remove(info, false);
final int[] coordinates = new int[2];
- final long screenId = findSpaceOnWorkspace(item, coordinates);
+ final int screenId = findSpaceOnWorkspace(item, coordinates);
mLauncher.getModelWriter().moveItemInDatabase(info,
LauncherSettings.Favorites.CONTAINER_DESKTOP,
screenId, coordinates[0], coordinates[1]);
@@ -210,7 +211,7 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme
});
} else if (action == RESIZE) {
final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
- final ArrayList<Integer> actions = getSupportedResizeActions(host, info);
+ final IntArray actions = getSupportedResizeActions(host, info);
CharSequence[] labels = new CharSequence[actions.size()];
for (int i = 0; i < actions.size(); i++) {
labels[i] = mLauncher.getText(actions.get(i));
@@ -242,8 +243,8 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme
return false;
}
- private ArrayList<Integer> getSupportedResizeActions(View host, LauncherAppWidgetInfo info) {
- ArrayList<Integer> actions = new ArrayList<>();
+ private IntArray getSupportedResizeActions(View host, LauncherAppWidgetInfo info) {
+ IntArray actions = new IntArray();
AppWidgetProviderInfo providerInfo = ((LauncherAppWidgetHostView) host).getAppWidgetInfo();
if (providerInfo == null) {
@@ -392,10 +393,10 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme
/**
* Find empty space on the workspace and returns the screenId.
*/
- protected long findSpaceOnWorkspace(ItemInfo info, int[] outCoordinates) {
+ protected int findSpaceOnWorkspace(ItemInfo info, int[] outCoordinates) {
Workspace workspace = mLauncher.getWorkspace();
- ArrayList<Long> workspaceScreens = workspace.getScreenOrder();
- long screenId;
+ IntArray workspaceScreens = workspace.getScreenOrder();
+ int screenId;
// First check if there is space on the current screen.
int screenIndex = workspace.getCurrentPage();
diff --git a/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java
index cfb052029..f37f70b4c 100644
--- a/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java
+++ b/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java
@@ -66,7 +66,7 @@ public class ShortcutMenuAccessibilityDelegate extends LauncherAccessibilityDele
}
final ShortcutInfo info = ((DeepShortcutView) host.getParent()).getFinalInfo();
final int[] coordinates = new int[2];
- final long screenId = findSpaceOnWorkspace(item, coordinates);
+ final int screenId = findSpaceOnWorkspace(item, coordinates);
Runnable onComplete = new Runnable() {
@Override
public void run() {
diff --git a/src/com/android/launcher3/compat/UserManagerCompatVL.java b/src/com/android/launcher3/compat/UserManagerCompatVL.java
index eec343849..ef7284226 100644
--- a/src/com/android/launcher3/compat/UserManagerCompatVL.java
+++ b/src/com/android/launcher3/compat/UserManagerCompatVL.java
@@ -17,32 +17,29 @@
package com.android.launcher3.compat;
import android.content.Context;
-import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.ArrayMap;
-import com.android.launcher3.util.LongArrayMap;
+import android.util.LongSparseArray;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class UserManagerCompatVL extends UserManagerCompat {
- private static final String USER_CREATION_TIME_KEY = "user_creation_time_";
protected final UserManager mUserManager;
private final PackageManager mPm;
- private final Context mContext;
- protected LongArrayMap<UserHandle> mUsers;
- // Create a separate reverse map as LongArrayMap.indexOfValue checks if objects are same
+ protected LongSparseArray<UserHandle> mUsers;
+ // Create a separate reverse map as LongSparseArray.indexOfValue checks if objects are same
// and not {@link Object#equals}
protected ArrayMap<UserHandle, Long> mUserToSerialMap;
UserManagerCompatVL(Context context) {
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
mPm = context.getPackageManager();
- mContext = context;
}
@Override
@@ -94,7 +91,7 @@ public class UserManagerCompatVL extends UserManagerCompat {
@Override
public void enableAndResetCache() {
synchronized (this) {
- mUsers = new LongArrayMap<>();
+ mUsers = new LongSparseArray<>();
mUserToSerialMap = new ArrayMap<>();
List<UserHandle> users = mUserManager.getUserProfiles();
if (users != null) {
diff --git a/src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java b/src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java
index 5576d9164..9f0d678bf 100644
--- a/src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java
+++ b/src/com/android/launcher3/dragndrop/FolderAdaptiveIcon.java
@@ -65,7 +65,7 @@ public class FolderAdaptiveIcon extends AdaptiveIconDrawable {
}
public static FolderAdaptiveIcon createFolderAdaptiveIcon(
- Launcher launcher, long folderId, Point dragViewSize) {
+ Launcher launcher, int folderId, Point dragViewSize) {
Preconditions.assertNonUiThread();
int margin = launcher.getResources()
.getDimensionPixelSize(R.dimen.blur_size_medium_outline);
diff --git a/src/com/android/launcher3/icons/IconCacheUpdateHandler.java b/src/com/android/launcher3/icons/IconCacheUpdateHandler.java
index 8b3af0104..07451b950 100644
--- a/src/com/android/launcher3/icons/IconCacheUpdateHandler.java
+++ b/src/com/android/launcher3/icons/IconCacheUpdateHandler.java
@@ -29,6 +29,7 @@ import android.util.SparseBooleanArray;
import com.android.launcher3.Utilities;
import com.android.launcher3.icons.BaseIconCache.IconDB;
+import com.android.launcher3.util.IntArray;
import java.util.ArrayList;
import java.util.Collections;
@@ -205,7 +206,7 @@ public class IconCacheUpdateHandler {
public void finish() {
// Commit all deletes
- ArrayList<Integer> deleteIds = new ArrayList<>();
+ IntArray deleteIds = new IntArray();
int count = mItemsToDelete.size();
for (int i = 0; i < count; i++) {
if (mItemsToDelete.valueAt(i)) {
diff --git a/src/com/android/launcher3/model/AddWorkspaceItemsTask.java b/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
index fefe07d9b..756d44e81 100644
--- a/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
+++ b/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
@@ -34,6 +34,8 @@ import com.android.launcher3.LauncherSettings;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.GridOccupancy;
+import com.android.launcher3.util.IntArray;
+
import java.util.ArrayList;
import java.util.List;
@@ -59,12 +61,12 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
Context context = app.getContext();
final ArrayList<ItemInfo> addedItemsFinal = new ArrayList<>();
- final ArrayList<Long> addedWorkspaceScreensFinal = new ArrayList<>();
+ final IntArray addedWorkspaceScreensFinal = new IntArray();
// Get the list of workspace screens. We need to append to this list and
// can not use sBgWorkspaceScreens because loadWorkspace() may not have been
// called.
- ArrayList<Long> workspaceScreens = LauncherModel.loadWorkspaceScreensDb(context);
+ IntArray workspaceScreens = LauncherModel.loadWorkspaceScreensDb(context);
synchronized(dataModel) {
List<ItemInfo> filteredItems = new ArrayList<>();
@@ -90,10 +92,9 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
for (ItemInfo item : filteredItems) {
// Find appropriate space for the item.
- Pair<Long, int[]> coords = findSpaceForItem(app, dataModel, workspaceScreens,
+ int[] coords = findSpaceForItem(app, dataModel, workspaceScreens,
addedWorkspaceScreensFinal, item.spanX, item.spanY);
- long screenId = coords.first;
- int[] cordinates = coords.second;
+ int screenId = coords[0];
ItemInfo itemInfo;
if (item instanceof ShortcutInfo || item instanceof FolderInfo ||
@@ -108,7 +109,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
// Add the shortcut to the db
getModelWriter().addItemToDatabase(itemInfo,
LauncherSettings.Favorites.CONTAINER_DESKTOP, screenId,
- cordinates[0], cordinates[1]);
+ coords[1], coords[2]);
// Save the ShortcutInfo for binding in the workspace
addedItemsFinal.add(itemInfo);
@@ -126,7 +127,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
final ArrayList<ItemInfo> addNotAnimated = new ArrayList<>();
if (!addedItemsFinal.isEmpty()) {
ItemInfo info = addedItemsFinal.get(addedItemsFinal.size() - 1);
- long lastScreenId = info.screenId;
+ int lastScreenId = info.screenId;
for (ItemInfo i : addedItemsFinal) {
if (i.screenId == lastScreenId) {
addAnimated.add(i);
@@ -142,7 +143,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
}
}
- protected void updateScreens(Context context, ArrayList<Long> workspaceScreens) {
+ protected void updateScreens(Context context, IntArray workspaceScreens) {
LauncherModel.updateWorkspaceScreenOrder(context, workspaceScreens);
}
@@ -204,13 +205,10 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
/**
* Find a position on the screen for the given size or adds a new screen.
- * @return screenId and the coordinates for the item.
+ * @return screenId and the coordinates for the item in an int array of size 3.
*/
- protected Pair<Long, int[]> findSpaceForItem(
- LauncherAppState app, BgDataModel dataModel,
- ArrayList<Long> workspaceScreens,
- ArrayList<Long> addedWorkspaceScreensFinal,
- int spanX, int spanY) {
+ protected int[] findSpaceForItem( LauncherAppState app, BgDataModel dataModel,
+ IntArray workspaceScreens, IntArray addedWorkspaceScreensFinal, int spanX, int spanY) {
LongSparseArray<ArrayList<ItemInfo>> screenItems = new LongSparseArray<>();
// Use sBgItemsIdMap as all the items are already loaded.
@@ -228,7 +226,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
}
// Find appropriate space for the item.
- long screenId = 0;
+ int screenId = 0;
int[] cordinates = new int[2];
boolean found = false;
@@ -258,7 +256,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
// Still no position found. Add a new screen to the end.
screenId = LauncherSettings.Settings.call(app.getContext().getContentResolver(),
LauncherSettings.Settings.METHOD_NEW_SCREEN_ID)
- .getLong(LauncherSettings.Settings.EXTRA_VALUE);
+ .getInt(LauncherSettings.Settings.EXTRA_VALUE);
// Save the screen id for binding in the workspace
workspaceScreens.add(screenId);
@@ -270,7 +268,7 @@ public class AddWorkspaceItemsTask extends BaseModelUpdateTask {
throw new RuntimeException("Can't find space to add the item");
}
}
- return Pair.create(screenId, cordinates);
+ return new int[] {screenId, cordinates[0], cordinates[1]};
}
private boolean findNextAvailableIconSpaceInScreen(
diff --git a/src/com/android/launcher3/model/BgDataModel.java b/src/com/android/launcher3/model/BgDataModel.java
index fff1e6991..81eefc4d8 100644
--- a/src/com/android/launcher3/model/BgDataModel.java
+++ b/src/com/android/launcher3/model/BgDataModel.java
@@ -36,7 +36,8 @@ import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.util.ComponentKey;
-import com.android.launcher3.util.LongArrayMap;
+import com.android.launcher3.util.IntArray;
+import com.android.launcher3.util.IntSparseArrayMap;
import com.android.launcher3.util.MultiHashMap;
import com.google.protobuf.nano.MessageNano;
@@ -62,7 +63,7 @@ public class BgDataModel {
* Map of all the ItemInfos (shortcuts, folders, and widgets) created by
* LauncherModel to their ids
*/
- public final LongArrayMap<ItemInfo> itemsIdMap = new LongArrayMap<>();
+ public final IntSparseArrayMap<ItemInfo> itemsIdMap = new IntSparseArrayMap<>();
/**
* List of all the folders and shortcuts directly on the home screen (no widgets
@@ -78,12 +79,12 @@ public class BgDataModel {
/**
* Map of id to FolderInfos of all the folders created by LauncherModel
*/
- public final LongArrayMap<FolderInfo> folders = new LongArrayMap<>();
+ public final IntSparseArrayMap<FolderInfo> folders = new IntSparseArrayMap<>();
/**
* Ordered list of workspace screens ids.
*/
- public final ArrayList<Long> workspaceScreens = new ArrayList<>();
+ public final IntArray workspaceScreens = new IntArray();
/**
* Map of ShortcutKey to the number of times it is pinned.
@@ -132,7 +133,7 @@ public class BgDataModel {
writer.println(prefix + "Data Model:");
writer.print(prefix + " ---- workspace screens: ");
for (int i = 0; i < workspaceScreens.size(); i++) {
- writer.print(" " + workspaceScreens.get(i).toString());
+ writer.print(" " + workspaceScreens.get(i));
}
writer.println();
writer.println(prefix + " ---- workspace items ");
@@ -169,7 +170,7 @@ public class BgDataModel {
// Add top parent nodes. (L1)
DumpTargetWrapper hotseat = new DumpTargetWrapper(ContainerType.HOTSEAT, 0);
- LongArrayMap<DumpTargetWrapper> workspaces = new LongArrayMap<>();
+ IntSparseArrayMap<DumpTargetWrapper> workspaces = new IntSparseArrayMap<>();
for (int i = 0; i < workspaceScreens.size(); i++) {
workspaces.put(workspaceScreens.get(i),
new DumpTargetWrapper(ContainerType.WORKSPACE, i));
@@ -346,7 +347,7 @@ public class BgDataModel {
* Return an existing FolderInfo object if we have encountered this ID previously,
* or make a new one.
*/
- public synchronized FolderInfo findOrMakeFolder(long id) {
+ public synchronized FolderInfo findOrMakeFolder(int id) {
// See if a placeholder was created for us already
FolderInfo folderInfo = folders.get(id);
if (folderInfo == null) {
diff --git a/src/com/android/launcher3/model/GridSizeMigrationTask.java b/src/com/android/launcher3/model/GridSizeMigrationTask.java
index fc3ca762c..0115fd9f9 100644
--- a/src/com/android/launcher3/model/GridSizeMigrationTask.java
+++ b/src/com/android/launcher3/model/GridSizeMigrationTask.java
@@ -11,7 +11,6 @@ import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Point;
import android.net.Uri;
-import android.text.TextUtils;
import android.util.Log;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfo;
@@ -27,7 +26,9 @@ import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.GridOccupancy;
-import com.android.launcher3.util.LongArrayMap;
+import com.android.launcher3.util.IntArray;
+import com.android.launcher3.util.IntSparseArrayMap;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -59,7 +60,7 @@ public class GridSizeMigrationTask {
private final InvariantDeviceProfile mIdp;
private final ContentValues mTempValues = new ContentValues();
- protected final ArrayList<Long> mEntryToRemove = new ArrayList<>();
+ protected final IntArray mEntryToRemove = new IntArray();
private final ArrayList<ContentProviderOperation> mUpdateOperations = new ArrayList<>();
protected final ArrayList<DbEntry> mCarryOver = new ArrayList<>();
private final HashSet<String> mValidPackages;
@@ -118,7 +119,7 @@ public class GridSizeMigrationTask {
if (!mEntryToRemove.isEmpty()) {
if (DEBUG) {
- Log.d(TAG, "Removing items: " + TextUtils.join(", ", mEntryToRemove));
+ Log.d(TAG, "Removing items: " + mEntryToRemove.toConcatString());
}
mContext.getContentResolver().delete(LauncherSettings.Favorites.CONTENT_URI,
Utilities.createDbSelectionQuery(
@@ -177,12 +178,13 @@ public class GridSizeMigrationTask {
* @return true if any DB change was made
*/
protected boolean migrateWorkspace() throws Exception {
- ArrayList<Long> allScreens = LauncherModel.loadWorkspaceScreensDb(mContext);
+ IntArray allScreens = LauncherModel.loadWorkspaceScreensDb(mContext);
if (allScreens.isEmpty()) {
throw new Exception("Unable to get workspace screens");
}
- for (long screenId : allScreens) {
+ for (int i = 0; i < allScreens.size(); i++) {
+ int screenId = allScreens.get(i);
if (DEBUG) {
Log.d(TAG, "Migrating " + screenId);
}
@@ -190,7 +192,7 @@ public class GridSizeMigrationTask {
}
if (!mCarryOver.isEmpty()) {
- LongArrayMap<DbEntry> itemMap = new LongArrayMap<>();
+ IntSparseArrayMap<DbEntry> itemMap = new IntSparseArrayMap<>();
for (DbEntry e : mCarryOver) {
itemMap.put(e.id, e);
}
@@ -205,10 +207,10 @@ public class GridSizeMigrationTask {
new GridOccupancy(mTrgX, mTrgY), deepCopy(mCarryOver), 0, true);
placement.find();
if (placement.finalPlacedItems.size() > 0) {
- long newScreenId = LauncherSettings.Settings.call(
+ int newScreenId = LauncherSettings.Settings.call(
mContext.getContentResolver(),
LauncherSettings.Settings.METHOD_NEW_SCREEN_ID)
- .getLong(LauncherSettings.Settings.EXTRA_VALUE);
+ .getInt(LauncherSettings.Settings.EXTRA_VALUE);
allScreens.add(newScreenId);
for (DbEntry item : placement.finalPlacedItems) {
@@ -230,7 +232,7 @@ public class GridSizeMigrationTask {
int count = allScreens.size();
for (int i = 0; i < count; i++) {
ContentValues v = new ContentValues();
- long screenId = allScreens.get(i);
+ int screenId = allScreens.get(i);
v.put(LauncherSettings.WorkspaceScreens._ID, screenId);
v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i);
mUpdateOperations.add(ContentProviderOperation.newInsert(uri).withValues(v).build());
@@ -249,7 +251,7 @@ public class GridSizeMigrationTask {
* 3) If all those items from the above list can be placed on this screen, place them
* (otherwise they are placed on a new screen).
*/
- protected void migrateScreen(long screenId) {
+ protected void migrateScreen(int screenId) {
// If we are migrating the first screen, do not touch the first row.
int startY =
(FeatureFlags.getInstance(mContext).isQsbOnFirstScreenEnabled()
@@ -304,7 +306,7 @@ public class GridSizeMigrationTask {
removedRow, removedCol, screenId));
}
- LongArrayMap<DbEntry> itemMap = new LongArrayMap<>();
+ IntSparseArrayMap<DbEntry> itemMap = new IntSparseArrayMap<>();
for (DbEntry e : deepCopy(items)) {
itemMap.put(e.id, e);
}
@@ -615,9 +617,9 @@ public class GridSizeMigrationTask {
ArrayList<DbEntry> entries = new ArrayList<>();
while (c.moveToNext()) {
DbEntry entry = new DbEntry();
- entry.id = c.getLong(indexId);
+ entry.id = c.getInt(indexId);
entry.itemType = c.getInt(indexItemType);
- entry.screenId = c.getLong(indexScreen);
+ entry.screenId = c.getInt(indexScreen);
if (entry.screenId >= mSrcHotseatSize) {
mEntryToRemove.add(entry.id);
@@ -663,7 +665,7 @@ public class GridSizeMigrationTask {
/**
* Loads entries for a particular screen id.
*/
- protected ArrayList<DbEntry> loadWorkspaceEntries(long screen) {
+ protected ArrayList<DbEntry> loadWorkspaceEntries(int screen) {
Cursor c = queryWorkspace(
new String[]{
Favorites._ID, // 0
@@ -691,7 +693,7 @@ public class GridSizeMigrationTask {
ArrayList<DbEntry> entries = new ArrayList<>();
while (c.moveToNext()) {
DbEntry entry = new DbEntry();
- entry.id = c.getLong(indexId);
+ entry.id = c.getInt(indexId);
entry.itemType = c.getInt(indexItemType);
entry.cellX = c.getInt(indexCellX);
entry.cellY = c.getInt(indexCellY);
@@ -764,7 +766,7 @@ public class GridSizeMigrationTask {
/**
* @return the number of valid items in the folder.
*/
- private int getFolderItemsCount(long folderId) {
+ private int getFolderItemsCount(int folderId) {
Cursor c = queryWorkspace(
new String[]{Favorites._ID, Favorites.INTENT},
Favorites.CONTAINER + " = " + folderId);
@@ -775,7 +777,7 @@ public class GridSizeMigrationTask {
verifyIntent(c.getString(1));
total++;
} catch (Exception e) {
- mEntryToRemove.add(c.getLong(0));
+ mEntryToRemove.add(c.getInt(0));
}
}
c.close();
@@ -970,7 +972,7 @@ public class GridSizeMigrationTask {
* Removes any broken item from the hotseat.
* @return a map with occupied hotseat position set to non-null value.
*/
- public static LongArrayMap<Object> removeBrokenHotseatItems(Context context) throws Exception {
+ public static IntSparseArrayMap<Object> removeBrokenHotseatItems(Context context) throws Exception {
GridSizeMigrationTask task = new GridSizeMigrationTask(
context, LauncherAppState.getIDP(context), getValidPackages(context),
Integer.MAX_VALUE, Integer.MAX_VALUE);
@@ -979,7 +981,7 @@ public class GridSizeMigrationTask {
ArrayList<DbEntry> items = task.loadHotseatEntries();
// Delete any entry marked for deletion by above load.
task.applyOperations();
- LongArrayMap<Object> positions = new LongArrayMap<>();
+ IntSparseArrayMap<Object> positions = new IntSparseArrayMap<>();
for (DbEntry item : items) {
positions.put(item.screenId, item);
}
diff --git a/src/com/android/launcher3/model/LoaderCursor.java b/src/com/android/launcher3/model/LoaderCursor.java
index 958e1de76..bb3a7606f 100644
--- a/src/com/android/launcher3/model/LoaderCursor.java
+++ b/src/com/android/launcher3/model/LoaderCursor.java
@@ -48,11 +48,11 @@ import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.util.ContentWriter;
import com.android.launcher3.util.GridOccupancy;
-import com.android.launcher3.util.LongArrayMap;
+import com.android.launcher3.util.IntArray;
+import com.android.launcher3.util.IntSparseArrayMap;
import java.net.URISyntaxException;
import java.security.InvalidParameterException;
-import java.util.ArrayList;
/**
* Extension of {@link Cursor} with utility methods for workspace loading.
@@ -68,9 +68,9 @@ public class LoaderCursor extends CursorWrapper {
private final IconCache mIconCache;
private final InvariantDeviceProfile mIDP;
- private final ArrayList<Long> itemsToRemove = new ArrayList<>();
- private final ArrayList<Long> restoredRows = new ArrayList<>();
- private final LongArrayMap<GridOccupancy> occupied = new LongArrayMap<>();
+ private final IntArray itemsToRemove = new IntArray();
+ private final IntArray restoredRows = new IntArray();
+ private final IntSparseArrayMap<GridOccupancy> occupied = new IntSparseArrayMap<>();
private final int iconPackageIndex;
private final int iconResourceIndex;
@@ -90,8 +90,8 @@ public class LoaderCursor extends CursorWrapper {
// Properties loaded per iteration
public long serialNumber;
public UserHandle user;
- public long id;
- public long container;
+ public int id;
+ public int container;
public int itemType;
public int restoreFlag;
@@ -126,7 +126,7 @@ public class LoaderCursor extends CursorWrapper {
// Load common properties.
itemType = getInt(itemTypeIndex);
container = getInt(containerIndex);
- id = getLong(idIndex);
+ id = getInt(idIndex);
serialNumber = getInt(profileIdIndex);
user = allUsers.get(serialNumber);
restoreFlag = getInt(restoredIndex);
@@ -293,7 +293,7 @@ public class LoaderCursor extends CursorWrapper {
*/
public ContentWriter updater() {
return new ContentWriter(mContext, new ContentWriter.CommitParams(
- BaseColumns._ID + "= ?", new String[]{Long.toString(id)}));
+ BaseColumns._ID + "= ?", new String[]{Integer.toString(id)}));
}
/**
@@ -383,11 +383,11 @@ public class LoaderCursor extends CursorWrapper {
/**
* check & update map of what's occupied; used to discard overlapping/invalid items
*/
- protected boolean checkItemPlacement(ItemInfo item, ArrayList<Long> workspaceScreens) {
- long containerIndex = item.screenId;
+ protected boolean checkItemPlacement(ItemInfo item, IntArray workspaceScreens) {
+ int containerIndex = item.screenId;
if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
final GridOccupancy hotseatOccupancy =
- occupied.get((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT);
+ occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT);
if (item.screenId >= mIDP.numHotseatIcons) {
Log.e(TAG, "Error loading shortcut " + item
@@ -404,17 +404,17 @@ public class LoaderCursor extends CursorWrapper {
+ item.cellY + ") already occupied");
return false;
} else {
- hotseatOccupancy.cells[(int) item.screenId][0] = true;
+ hotseatOccupancy.cells[item.screenId][0] = true;
return true;
}
} else {
final GridOccupancy occupancy = new GridOccupancy(mIDP.numHotseatIcons, 1);
- occupancy.cells[(int) item.screenId][0] = true;
- occupied.put((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT, occupancy);
+ occupancy.cells[item.screenId][0] = true;
+ occupied.put(LauncherSettings.Favorites.CONTAINER_HOTSEAT, occupancy);
return true;
}
} else if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
- if (!workspaceScreens.contains((Long) item.screenId)) {
+ if (!workspaceScreens.contains(item.screenId)) {
// The item has an invalid screen id.
return false;
}
diff --git a/src/com/android/launcher3/model/LoaderResults.java b/src/com/android/launcher3/model/LoaderResults.java
index 033e3f559..2c15df192 100644
--- a/src/com/android/launcher3/model/LoaderResults.java
+++ b/src/com/android/launcher3/model/LoaderResults.java
@@ -29,9 +29,10 @@ import com.android.launcher3.LauncherModel.Callbacks;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.PagedView;
-import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.ComponentKey;
+import com.android.launcher3.util.IntArray;
+import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.LooperIdleLock;
import com.android.launcher3.util.MultiHashMap;
import com.android.launcher3.util.ViewOnDrawExecutor;
@@ -52,7 +53,7 @@ import java.util.concurrent.Executor;
public class LoaderResults {
private static final String TAG = "LoaderResults";
- private static final long INVALID_SCREEN_ID = -1L;
+ private static final int INVALID_SCREEN_ID = -1;
private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons
private final Executor mUiExecutor;
@@ -92,7 +93,7 @@ public class LoaderResults {
// Save a copy of all the bg-thread collections
ArrayList<ItemInfo> workspaceItems = new ArrayList<>();
ArrayList<LauncherAppWidgetInfo> appWidgets = new ArrayList<>();
- final ArrayList<Long> orderedScreenIds = new ArrayList<>();
+ final IntArray orderedScreenIds = new IntArray();
synchronized (mBgDataModel) {
workspaceItems.addAll(mBgDataModel.workspaceItems);
@@ -112,7 +113,7 @@ public class LoaderResults {
currentScreen = currScreen;
}
final boolean validFirstPage = currentScreen >= 0;
- final long currentScreenId =
+ final int currentScreenId =
validFirstPage ? orderedScreenIds.get(currentScreen) : INVALID_SCREEN_ID;
// Separate the items that are on the current screen, and all the other remaining items
@@ -209,7 +210,7 @@ public class LoaderResults {
/** Filters the set of items who are directly or indirectly (via another container) on the
* specified screen. */
- public static <T extends ItemInfo> void filterCurrentWorkspaceItems(long currentScreenId,
+ public static <T extends ItemInfo> void filterCurrentWorkspaceItems(int currentScreenId,
ArrayList<T> allWorkspaceItems,
ArrayList<T> currentScreenItems,
ArrayList<T> otherScreenItems) {
@@ -225,13 +226,10 @@ public class LoaderResults {
// Order the set of items by their containers first, this allows use to walk through the
// list sequentially, build up a list of containers that are in the specified screen,
// as well as all items in those containers.
- Set<Long> itemsOnScreen = new HashSet<>();
- Collections.sort(allWorkspaceItems, new Comparator<ItemInfo>() {
- @Override
- public int compare(ItemInfo lhs, ItemInfo rhs) {
- return Utilities.longCompare(lhs.container, rhs.container);
- }
- });
+ IntSet itemsOnScreen = new IntSet();
+ Collections.sort(allWorkspaceItems,
+ (lhs, rhs) -> Integer.compare(lhs.container, rhs.container));
+
for (T info : allWorkspaceItems) {
if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
if (info.screenId == currentScreenId) {
@@ -267,15 +265,15 @@ public class LoaderResults {
// Within containers, order by their spatial position in that container
switch ((int) lhs.container) {
case LauncherSettings.Favorites.CONTAINER_DESKTOP: {
- long lr = (lhs.screenId * screenCellCount +
+ int lr = (lhs.screenId * screenCellCount +
lhs.cellY * screenCols + lhs.cellX);
- long rr = (rhs.screenId * screenCellCount +
+ int rr = (rhs.screenId * screenCellCount +
rhs.cellY * screenCols + rhs.cellX);
- return Utilities.longCompare(lr, rr);
+ return Integer.compare(lr, rr);
}
case LauncherSettings.Favorites.CONTAINER_HOTSEAT: {
// We currently use the screen id as the rank
- return Utilities.longCompare(lhs.screenId, rhs.screenId);
+ return Integer.compare(lhs.screenId, rhs.screenId);
}
default:
if (FeatureFlags.IS_DOGFOOD_BUILD) {
@@ -286,7 +284,7 @@ public class LoaderResults {
}
} else {
// Between containers, order by hotseat, desktop
- return Utilities.longCompare(lhs.container, rhs.container);
+ return Integer.compare(lhs.container, rhs.container);
}
}
});
diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java
index cb780382a..1ec7af2bb 100644
--- a/src/com/android/launcher3/model/LoaderTask.java
+++ b/src/com/android/launcher3/model/LoaderTask.java
@@ -70,6 +70,7 @@ import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.util.ComponentKey;
+import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.LooperIdleLock;
import com.android.launcher3.util.MultiHashMap;
import com.android.launcher3.util.PackageManagerHelper;
@@ -155,7 +156,7 @@ public class LoaderTask implements Runnable {
allItems.addAll(mBgDataModel.workspaceItems);
allItems.addAll(mBgDataModel.appWidgets);
}
- long firstScreen = mBgDataModel.workspaceScreens.isEmpty()
+ int firstScreen = mBgDataModel.workspaceScreens.isEmpty()
? -1 // In this case, we can still look at the items in the hotseat.
: mBgDataModel.workspaceScreens.get(0);
filterCurrentWorkspaceItems(firstScreen, allItems, firstScreenItems,
@@ -719,11 +720,11 @@ public class LoaderTask implements Runnable {
// Remove dead items
if (c.commitDeleted()) {
// Remove any empty folder
- ArrayList<Long> deletedFolderIds = (ArrayList<Long>) LauncherSettings.Settings
+ int[] deletedFolderIds = LauncherSettings.Settings
.call(contentResolver,
LauncherSettings.Settings.METHOD_DELETE_EMPTY_FOLDERS)
- .getSerializable(LauncherSettings.Settings.EXTRA_VALUE);
- for (long folderId : deletedFolderIds) {
+ .getIntArray(LauncherSettings.Settings.EXTRA_VALUE);
+ for (int folderId : deletedFolderIds) {
mBgDataModel.workspaceItems.remove(mBgDataModel.folders.get(folderId));
mBgDataModel.folders.remove(folderId);
mBgDataModel.itemsIdMap.remove(folderId);
@@ -778,18 +779,18 @@ public class LoaderTask implements Runnable {
}
// Remove any empty screens
- ArrayList<Long> unusedScreens = new ArrayList<>(mBgDataModel.workspaceScreens);
+ IntArray unusedScreens = mBgDataModel.workspaceScreens.clone();
for (ItemInfo item: mBgDataModel.itemsIdMap) {
- long screenId = item.screenId;
+ int screenId = item.screenId;
if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP &&
unusedScreens.contains(screenId)) {
- unusedScreens.remove(screenId);
+ unusedScreens.removeValue(screenId);
}
}
// If there are any empty screens remove them, and update.
if (unusedScreens.size() != 0) {
- mBgDataModel.workspaceScreens.removeAll(unusedScreens);
+ mBgDataModel.workspaceScreens.removeAllValues(unusedScreens);
LauncherModel.updateWorkspaceScreenOrder(context, mBgDataModel.workspaceScreens);
}
}
diff --git a/src/com/android/launcher3/model/ModelWriter.java b/src/com/android/launcher3/model/ModelWriter.java
index d81eb43fb..f7961d5d8 100644
--- a/src/com/android/launcher3/model/ModelWriter.java
+++ b/src/com/android/launcher3/model/ModelWriter.java
@@ -79,7 +79,7 @@ public class ModelWriter {
}
private void updateItemInfoProps(
- ItemInfo item, long container, long screenId, int cellX, int cellY) {
+ ItemInfo item, int container, int screenId, int cellX, int cellY) {
item.container = container;
item.cellX = cellX;
item.cellY = cellY;
@@ -98,7 +98,7 @@ public class ModelWriter {
* <container, screen, cellX, cellY>
*/
public void addOrMoveItemInDatabase(ItemInfo item,
- long container, long screenId, int cellX, int cellY) {
+ int container, int screenId, int cellX, int cellY) {
if (item.container == ItemInfo.NO_ID) {
// From all apps
addItemToDatabase(item, container, screenId, cellX, cellY);
@@ -108,7 +108,7 @@ public class ModelWriter {
}
}
- private void checkItemInfoLocked(long itemId, ItemInfo item, StackTraceElement[] stackTrace) {
+ private void checkItemInfoLocked(int itemId, ItemInfo item, StackTraceElement[] stackTrace) {
if (com.android.launcher3.Utilities.IS_RUNNING_IN_TEST_HARNESS
&& com.android.launcher3.Utilities.IS_DEBUG_DEVICE) {
android.util.Log.d("b/117332845",
@@ -154,7 +154,7 @@ public class ModelWriter {
* Move an item in the DB to a new <container, screen, cellX, cellY>
*/
public void moveItemInDatabase(final ItemInfo item,
- long container, long screenId, int cellX, int cellY) {
+ int container, int screenId, int cellX, int cellY) {
updateItemInfoProps(item, container, screenId, cellX, cellY);
final ContentWriter writer = new ContentWriter(mContext)
@@ -171,7 +171,7 @@ public class ModelWriter {
* Move items in the DB to a new <container, screen, cellX, cellY>. We assume that the
* cellX, cellY have already been updated on the ItemInfos.
*/
- public void moveItemsInDatabase(final ArrayList<ItemInfo> items, long container, int screen) {
+ public void moveItemsInDatabase(final ArrayList<ItemInfo> items, int container, int screen) {
ArrayList<ContentValues> contentValues = new ArrayList<>();
int count = items.size();
@@ -195,7 +195,7 @@ public class ModelWriter {
* Move and/or resize item in the DB to a new <container, screen, cellX, cellY, spanX, spanY>
*/
public void modifyItemInDatabase(final ItemInfo item,
- long container, long screenId, int cellX, int cellY, int spanX, int spanY) {
+ int container, int screenId, int cellX, int cellY, int spanX, int spanY) {
updateItemInfoProps(item, container, screenId, cellX, cellY);
item.spanX = spanX;
item.spanY = spanY;
@@ -226,14 +226,14 @@ public class ModelWriter {
* cellY fields of the item. Also assigns an ID to the item.
*/
public void addItemToDatabase(final ItemInfo item,
- long container, long screenId, int cellX, int cellY) {
+ int container, int screenId, int cellX, int cellY) {
updateItemInfoProps(item, container, screenId, cellX, cellY);
final ContentWriter writer = new ContentWriter(mContext);
final ContentResolver cr = mContext.getContentResolver();
item.onAddToDatabase(writer);
- item.id = Settings.call(cr, Settings.METHOD_NEW_ITEM_ID).getLong(Settings.EXTRA_VALUE);
+ item.id = Settings.call(cr, Settings.METHOD_NEW_ITEM_ID).getInt(Settings.EXTRA_VALUE);
writer.put(Favorites._ID, item.id);
ModelVerifier verifier = new ModelVerifier();
@@ -360,7 +360,7 @@ public class ModelWriter {
private class UpdateItemRunnable extends UpdateItemBaseRunnable {
private final ItemInfo mItem;
private final ContentWriter mWriter;
- private final long mItemId;
+ private final int mItemId;
UpdateItemRunnable(ItemInfo item, ContentWriter writer) {
if (com.android.launcher3.Utilities.IS_RUNNING_IN_TEST_HARNESS
@@ -396,7 +396,7 @@ public class ModelWriter {
int count = mItems.size();
for (int i = 0; i < count; i++) {
ItemInfo item = mItems.get(i);
- final long itemId = item.id;
+ final int itemId = item.id;
final Uri uri = Favorites.getContentUri(itemId);
ContentValues values = mValues.get(i);
@@ -419,7 +419,7 @@ public class ModelWriter {
mStackTrace = new Throwable().getStackTrace();
}
- protected void updateItemArrays(ItemInfo item, long itemId) {
+ protected void updateItemArrays(ItemInfo item, int itemId) {
// Lock on mBgLock *after* the db operation
synchronized (mBgDataModel) {
checkItemInfoLocked(itemId, item, mStackTrace);
diff --git a/src/com/android/launcher3/model/PackageUpdatedTask.java b/src/com/android/launcher3/model/PackageUpdatedTask.java
index c004e217b..201a63e11 100644
--- a/src/com/android/launcher3/model/PackageUpdatedTask.java
+++ b/src/com/android/launcher3/model/PackageUpdatedTask.java
@@ -44,8 +44,8 @@ import com.android.launcher3.logging.FileLog;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.util.FlagOp;
+import com.android.launcher3.util.IntSparseArrayMap;
import com.android.launcher3.util.ItemInfoMatcher;
-import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageUserKey;
@@ -171,7 +171,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
}
}
- final LongArrayMap<Boolean> removedShortcuts = new LongArrayMap<>();
+ final IntSparseArrayMap<Boolean> removedShortcuts = new IntSparseArrayMap<>();
// Update shortcut infos
if (mOp == OP_ADD || flagOp != FlagOp.NO_OP) {
diff --git a/src/com/android/launcher3/notification/NotificationListener.java b/src/com/android/launcher3/notification/NotificationListener.java
index 4c85c8b17..68cf7dec0 100644
--- a/src/com/android/launcher3/notification/NotificationListener.java
+++ b/src/com/android/launcher3/notification/NotificationListener.java
@@ -33,6 +33,7 @@ import android.util.Log;
import android.util.Pair;
import com.android.launcher3.LauncherModel;
+import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.SettingsObserver;
@@ -346,7 +347,7 @@ public class NotificationListener extends NotificationListenerService {
private List<StatusBarNotification> filterNotifications(
StatusBarNotification[] notifications) {
if (notifications == null) return null;
- Set<Integer> removedNotifications = new ArraySet<>();
+ IntSet removedNotifications = new IntSet();
for (int i = 0; i < notifications.length; i++) {
if (shouldBeFilteredOut(notifications[i])) {
removedNotifications.add(i);
diff --git a/src/com/android/launcher3/provider/ImportDataTask.java b/src/com/android/launcher3/provider/ImportDataTask.java
index 59c3c7217..4edd30f35 100644
--- a/src/com/android/launcher3/provider/ImportDataTask.java
+++ b/src/com/android/launcher3/provider/ImportDataTask.java
@@ -32,8 +32,9 @@ import android.net.Uri;
import android.os.Process;
import android.text.TextUtils;
import android.util.ArrayMap;
-import android.util.LongSparseArray;
import android.util.SparseBooleanArray;
+import android.util.SparseIntArray;
+
import com.android.launcher3.AutoInstallsLayout.LayoutParserCallback;
import com.android.launcher3.DefaultLayoutParser;
import com.android.launcher3.LauncherAppState;
@@ -50,7 +51,9 @@ import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.GridSizeMigrationTask;
-import com.android.launcher3.util.LongArrayMap;
+import com.android.launcher3.util.IntArray;
+import com.android.launcher3.util.IntSparseArrayMap;
+
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashSet;
@@ -85,7 +88,7 @@ public class ImportDataTask {
}
public boolean importWorkspace() throws Exception {
- ArrayList<Long> allScreens = LauncherDbUtils.getScreenIdsFromCursor(
+ IntArray allScreens = LauncherDbUtils.getScreenIdsFromCursor(
mContext.getContentResolver().query(mOtherScreensUri, null, null, null,
LauncherSettings.WorkspaceScreens.SCREEN_RANK));
FileLog.d(TAG, "Importing DB from " + mOtherFavoritesUri);
@@ -102,12 +105,12 @@ public class ImportDataTask {
// Build screen update
ArrayList<ContentProviderOperation> screenOps = new ArrayList<>();
int count = allScreens.size();
- LongSparseArray<Long> screenIdMap = new LongSparseArray<>(count);
+ SparseIntArray screenIdMap = new SparseIntArray(count);
for (int i = 0; i < count; i++) {
ContentValues v = new ContentValues();
v.put(LauncherSettings.WorkspaceScreens._ID, i);
v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i);
- screenIdMap.put(allScreens.get(i), (long) i);
+ screenIdMap.put(allScreens.get(i), i);
screenOps.add(ContentProviderOperation.newInsert(
LauncherSettings.WorkspaceScreens.CONTENT_URI).withValues(v).build());
}
@@ -128,7 +131,7 @@ public class ImportDataTask {
* 3) In the end fills any holes in hotseat with items from default hotseat layout.
*/
private void importWorkspaceItems(
- long firsetScreenId, LongSparseArray<Long> screenIdMap) throws Exception {
+ int firstScreenId, SparseIntArray screenIdMap) throws Exception {
String profileId = Long.toString(UserManagerCompat.getInstance(mContext)
.getSerialNumberForUser(Process.myUserHandle()));
@@ -137,7 +140,7 @@ public class ImportDataTask {
try (Cursor c = mContext.getContentResolver().query(mOtherFavoritesUri, null,
// get items on the first row of the first screen
"profileId = ? AND container = -100 AND screen = ? AND cellY = 0",
- new String[]{profileId, Long.toString(firsetScreenId)},
+ new String[]{profileId, Integer.toString(firstScreenId)},
null)) {
// First row of first screen is not empty
createEmptyRowOnFirstScreen = c.moveToNext();
@@ -190,7 +193,7 @@ public class ImportDataTask {
int type = c.getInt(itemTypeIndex);
int container = c.getInt(containerIndex);
- long screen = c.getLong(screenIndex);
+ int screen = c.getInt(screenIndex);
int cellX = c.getInt(cellXIndex);
int cellY = c.getInt(cellYIndex);
@@ -199,7 +202,7 @@ public class ImportDataTask {
switch (container) {
case Favorites.CONTAINER_DESKTOP: {
- Long newScreenId = screenIdMap.get(screen);
+ Integer newScreenId = screenIdMap.get(screen);
if (newScreenId == null) {
FileLog.d(TAG, String.format("Skipping item %d, type %d not on a valid screen %d", id, type, screen));
continue;
@@ -306,15 +309,15 @@ public class ImportDataTask {
insertOperations.clear();
}
- LongArrayMap<Object> hotseatItems = GridSizeMigrationTask.removeBrokenHotseatItems(mContext);
+ IntSparseArrayMap<Object> hotseatItems = GridSizeMigrationTask.removeBrokenHotseatItems(mContext);
int myHotseatCount = LauncherAppState.getIDP(mContext).numHotseatIcons;
if (hotseatItems.size() < myHotseatCount) {
// Insufficient hotseat items. Add a few more.
HotseatParserCallback parserCallback = new HotseatParserCallback(
hotseatTargetApps, hotseatItems, insertOperations, maxId + 1, myHotseatCount);
new HotseatLayoutParser(mContext,
- parserCallback).loadLayout(null, new ArrayList<Long>());
- mHotseatSize = (int) hotseatItems.keyAt(hotseatItems.size() - 1) + 1;
+ parserCallback).loadLayout(null, new IntArray());
+ mHotseatSize = hotseatItems.keyAt(hotseatItems.size() - 1) + 1;
if (!insertOperations.isEmpty()) {
mContext.getContentResolver().applyBatch(LauncherProvider.AUTHORITY,
@@ -405,13 +408,13 @@ public class ImportDataTask {
*/
private static class HotseatParserCallback implements LayoutParserCallback {
private final HashSet<String> mExistingApps;
- private final LongArrayMap<Object> mExistingItems;
+ private final IntSparseArrayMap<Object> mExistingItems;
private final ArrayList<ContentProviderOperation> mOutOps;
private final int mRequiredSize;
private int mStartItemId;
HotseatParserCallback(
- HashSet<String> existingApps, LongArrayMap<Object> existingItems,
+ HashSet<String> existingApps, IntSparseArrayMap<Object> existingItems,
ArrayList<ContentProviderOperation> outOps, int startItemId, int requiredSize) {
mExistingApps = existingApps;
mExistingItems = existingItems;
@@ -421,12 +424,12 @@ public class ImportDataTask {
}
@Override
- public long generateNewItemId() {
+ public int generateNewItemId() {
return mStartItemId++;
}
@Override
- public long insertAndCheck(SQLiteDatabase db, ContentValues values) {
+ public int insertAndCheck(SQLiteDatabase db, ContentValues values) {
if (mExistingItems.size() >= mRequiredSize) {
// No need to add more items.
return 0;
@@ -445,7 +448,7 @@ public class ImportDataTask {
mExistingApps.add(pkg);
// find next vacant spot.
- long screen = 0;
+ int screen = 0;
while (mExistingItems.get(screen) != null) {
screen++;
}
diff --git a/src/com/android/launcher3/provider/LauncherDbUtils.java b/src/com/android/launcher3/provider/LauncherDbUtils.java
index 74373d307..ab0703fed 100644
--- a/src/com/android/launcher3/provider/LauncherDbUtils.java
+++ b/src/com/android/launcher3/provider/LauncherDbUtils.java
@@ -26,6 +26,7 @@ import android.util.Log;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.LauncherSettings.WorkspaceScreens;
+import com.android.launcher3.util.IntArray;
import java.util.ArrayList;
import java.util.Collection;
@@ -47,7 +48,7 @@ public class LauncherDbUtils {
public static boolean prepareScreenZeroToHostQsb(Context context, SQLiteDatabase db) {
try (SQLiteTransaction t = new SQLiteTransaction(db)) {
// Get the existing screens
- ArrayList<Long> screenIds = getScreenIdsFromCursor(db.query(WorkspaceScreens.TABLE_NAME,
+ IntArray screenIds = getScreenIdsFromCursor(db.query(WorkspaceScreens.TABLE_NAME,
null, null, null, null, null, WorkspaceScreens.SCREEN_RANK));
if (screenIds.isEmpty()) {
@@ -57,10 +58,10 @@ public class LauncherDbUtils {
}
if (screenIds.get(0) != 0) {
// First screen is not 0, we need to rename screens
- if (screenIds.indexOf(0L) > -1) {
+ if (screenIds.contains(0)) {
// There is already a screen 0. First rename it to a different screen.
- long newScreenId = 1;
- while (screenIds.indexOf(newScreenId) > -1) newScreenId++;
+ int newScreenId = 1;
+ while (screenIds.contains(newScreenId)) newScreenId++;
renameScreen(db, 0, newScreenId);
}
@@ -86,8 +87,8 @@ public class LauncherDbUtils {
}
}
- private static void renameScreen(SQLiteDatabase db, long oldScreen, long newScreen) {
- String[] whereParams = new String[] { Long.toString(oldScreen) };
+ private static void renameScreen(SQLiteDatabase db, int oldScreen, int newScreen) {
+ String[] whereParams = new String[] { Integer.toString(oldScreen) };
ContentValues values = new ContentValues();
values.put(WorkspaceScreens._ID, newScreen);
@@ -101,19 +102,18 @@ public class LauncherDbUtils {
/**
* Parses the cursor containing workspace screens table and returns the list of screen IDs
*/
- public static ArrayList<Long> getScreenIdsFromCursor(Cursor sc) {
+ public static IntArray getScreenIdsFromCursor(Cursor sc) {
try {
return iterateCursor(sc,
- sc.getColumnIndexOrThrow(WorkspaceScreens._ID),
- new ArrayList<Long>());
+ sc.getColumnIndexOrThrow(WorkspaceScreens._ID), new IntArray());
} finally {
sc.close();
}
}
- public static <T extends Collection<Long>> T iterateCursor(Cursor c, int columnIndex, T out) {
+ public static IntArray iterateCursor(Cursor c, int columnIndex, IntArray out) {
while (c.moveToNext()) {
- out.add(c.getLong(columnIndex));
+ out.add(c.getInt(columnIndex));
}
return out;
}
diff --git a/src/com/android/launcher3/provider/LossyScreenMigrationTask.java b/src/com/android/launcher3/provider/LossyScreenMigrationTask.java
index 51890d194..9166b8358 100644
--- a/src/com/android/launcher3/provider/LossyScreenMigrationTask.java
+++ b/src/com/android/launcher3/provider/LossyScreenMigrationTask.java
@@ -27,7 +27,7 @@ import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.model.GridSizeMigrationTask;
-import com.android.launcher3.util.LongArrayMap;
+import com.android.launcher3.util.IntSparseArrayMap;
import java.util.ArrayList;
@@ -39,8 +39,8 @@ public class LossyScreenMigrationTask extends GridSizeMigrationTask {
private final SQLiteDatabase mDb;
- private final LongArrayMap<DbEntry> mOriginalItems;
- private final LongArrayMap<DbEntry> mUpdates;
+ private final IntSparseArrayMap<DbEntry> mOriginalItems;
+ private final IntSparseArrayMap<DbEntry> mUpdates;
protected LossyScreenMigrationTask(
Context context, InvariantDeviceProfile idp, SQLiteDatabase db) {
@@ -50,8 +50,8 @@ public class LossyScreenMigrationTask extends GridSizeMigrationTask {
new Point(idp.numColumns, idp.numRows));
mDb = db;
- mOriginalItems = new LongArrayMap<>();
- mUpdates = new LongArrayMap<>();
+ mOriginalItems = new IntSparseArrayMap<>();
+ mUpdates = new IntSparseArrayMap<>();
}
@Override
@@ -65,7 +65,7 @@ public class LossyScreenMigrationTask extends GridSizeMigrationTask {
}
@Override
- protected ArrayList<DbEntry> loadWorkspaceEntries(long screen) {
+ protected ArrayList<DbEntry> loadWorkspaceEntries(int screen) {
ArrayList<DbEntry> result = super.loadWorkspaceEntries(screen);
for (DbEntry entry : result) {
mOriginalItems.put(entry.id, entry.copy());
@@ -90,7 +90,7 @@ public class LossyScreenMigrationTask extends GridSizeMigrationTask {
tempValues.clear();
update.addToContentValues(tempValues);
mDb.update(Favorites.TABLE_NAME, tempValues, "_id = ?",
- new String[] {Long.toString(update.id)});
+ new String[] {Integer.toString(update.id)});
}
}
diff --git a/src/com/android/launcher3/provider/RestoreDbTask.java b/src/com/android/launcher3/provider/RestoreDbTask.java
index 523016008..17c66b4d9 100644
--- a/src/com/android/launcher3/provider/RestoreDbTask.java
+++ b/src/com/android/launcher3/provider/RestoreDbTask.java
@@ -92,7 +92,7 @@ public class RestoreDbTask {
new String[]{Integer.toString(Favorites.ITEM_TYPE_APPWIDGET)});
long myProfileId = helper.getDefaultUserSerial();
- if (Utilities.longCompare(oldProfileId, myProfileId) != 0) {
+ if (myProfileId != oldProfileId) {
FileLog.d(TAG, "Changing primary user id from " + oldProfileId + " to " + myProfileId);
migrateProfileId(db, myProfileId);
}
diff --git a/src/com/android/launcher3/util/IntArray.java b/src/com/android/launcher3/util/IntArray.java
new file mode 100644
index 000000000..b2fb32a6c
--- /dev/null
+++ b/src/com/android/launcher3/util/IntArray.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.launcher3.util;
+
+import java.util.Arrays;
+
+/**
+ * Copy of the platform hidden implementation of android.util.IntArray.
+ * Implements a growing array of int primitives.
+ */
+public class IntArray implements Cloneable {
+ private static final int MIN_CAPACITY_INCREMENT = 12;
+
+ private static final int[] EMPTY_INT = new int[0];
+
+ /* package private */ int[] mValues;
+ /* package private */ int mSize;
+
+ private IntArray(int[] array, int size) {
+ mValues = array;
+ mSize = size;
+ }
+
+ /**
+ * Creates an empty IntArray with the default initial capacity.
+ */
+ public IntArray() {
+ this(10);
+ }
+
+ /**
+ * Creates an empty IntArray with the specified initial capacity.
+ */
+ public IntArray(int initialCapacity) {
+ if (initialCapacity == 0) {
+ mValues = EMPTY_INT;
+ } else {
+ mValues = new int[initialCapacity];
+ }
+ mSize = 0;
+ }
+
+ /**
+ * Creates an IntArray wrapping the given primitive int array.
+ */
+ public static IntArray wrap(int... array) {
+ return new IntArray(array, array.length);
+ }
+
+ /**
+ * Appends the specified value to the end of this array.
+ */
+ public void add(int value) {
+ add(mSize, value);
+ }
+
+ /**
+ * Inserts a value at the specified position in this array. If the specified index is equal to
+ * the length of the array, the value is added at the end.
+ *
+ * @throws IndexOutOfBoundsException when index &lt; 0 || index &gt; size()
+ */
+ public void add(int index, int value) {
+ ensureCapacity(1);
+ int rightSegment = mSize - index;
+ mSize++;
+ checkBounds(mSize, index);
+
+ if (rightSegment != 0) {
+ // Move by 1 all values from the right of 'index'
+ System.arraycopy(mValues, index, mValues, index + 1, rightSegment);
+ }
+
+ mValues[index] = value;
+ }
+
+ /**
+ * Adds the values in the specified array to this array.
+ */
+ public void addAll(IntArray values) {
+ final int count = values.mSize;
+ ensureCapacity(count);
+
+ System.arraycopy(values.mValues, 0, mValues, mSize, count);
+ mSize += count;
+ }
+
+ /**
+ * Ensures capacity to append at least <code>count</code> values.
+ */
+ private void ensureCapacity(int count) {
+ final int currentSize = mSize;
+ final int minCapacity = currentSize + count;
+ if (minCapacity >= mValues.length) {
+ final int targetCap = currentSize + (currentSize < (MIN_CAPACITY_INCREMENT / 2) ?
+ MIN_CAPACITY_INCREMENT : currentSize >> 1);
+ final int newCapacity = targetCap > minCapacity ? targetCap : minCapacity;
+ final int[] newValues = new int[newCapacity];
+ System.arraycopy(mValues, 0, newValues, 0, currentSize);
+ mValues = newValues;
+ }
+ }
+
+ /**
+ * Removes all values from this array.
+ */
+ public void clear() {
+ mSize = 0;
+ }
+
+ @Override
+ public IntArray clone() {
+ return wrap(toArray());
+ }
+
+ /**
+ * Returns the value at the specified position in this array.
+ */
+ public int get(int index) {
+ checkBounds(mSize, index);
+ return mValues[index];
+ }
+
+ /**
+ * Sets the value at the specified position in this array.
+ */
+ public void set(int index, int value) {
+ checkBounds(mSize, index);
+ mValues[index] = value;
+ }
+
+ /**
+ * Returns the index of the first occurrence of the specified value in this
+ * array, or -1 if this array does not contain the value.
+ */
+ public int indexOf(int value) {
+ final int n = mSize;
+ for (int i = 0; i < n; i++) {
+ if (mValues[i] == value) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public boolean contains(int value) {
+ return indexOf(value) >= 0;
+ }
+
+ public boolean isEmpty() {
+ return mSize == 0;
+ }
+
+ /**
+ * Removes the value at the specified index from this array.
+ */
+ public void removeIndex(int index) {
+ checkBounds(mSize, index);
+ System.arraycopy(mValues, index + 1, mValues, index, mSize - index - 1);
+ mSize--;
+ }
+
+ /**
+ * Removes the values if it exists
+ */
+ public void removeValue(int value) {
+ int index = indexOf(value);
+ if (index >= 0) {
+ removeIndex(index);
+ }
+ }
+
+ /**
+ * Removes the values if it exists
+ */
+ public void removeAllValues(IntArray values) {
+ for (int i = 0; i < values.mSize; i++) {
+ removeValue(values.mValues[i]);
+ }
+ }
+
+ /**
+ * Returns the number of values in this array.
+ */
+ public int size() {
+ return mSize;
+ }
+
+ /**
+ * Returns a new array with the contents of this IntArray.
+ */
+ public int[] toArray() {
+ return mSize == 0 ? EMPTY_INT : Arrays.copyOf(mValues, mSize);
+ }
+
+ /**
+ * Returns a comma separate list of all values.
+ */
+ public String toConcatString() {
+ StringBuilder b = new StringBuilder();
+ for (int i = 0; i < mSize ; i++) {
+ if (i > 0) {
+ b.append(", ");
+ }
+ b.append(mValues[i]);
+ }
+ return b.toString();
+ }
+
+ /**
+ * Throws {@link ArrayIndexOutOfBoundsException} if the index is out of bounds.
+ *
+ * @param len length of the array. Must be non-negative
+ * @param index the index to check
+ * @throws ArrayIndexOutOfBoundsException if the {@code index} is out of bounds of the array
+ */
+ private static void checkBounds(int len, int index) {
+ if (index < 0 || len <= index) {
+ throw new ArrayIndexOutOfBoundsException("length=" + len + "; index=" + index);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/com/android/launcher3/util/IntSet.java b/src/com/android/launcher3/util/IntSet.java
new file mode 100644
index 000000000..63499b06d
--- /dev/null
+++ b/src/com/android/launcher3/util/IntSet.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+package com.android.launcher3.util;
+
+import java.util.Arrays;
+
+/**
+ * A wrapper over IntArray implementing a growing set of int primitives.
+ */
+public class IntSet {
+
+ final IntArray mArray = new IntArray();
+
+ /**
+ * Appends the specified value to the set if it does not exist.
+ */
+ public void add(int value) {
+ int index = Arrays.binarySearch(mArray.mValues, 0, mArray.mSize, value);
+ if (index < 0) {
+ mArray.add(-index - 1, value);
+ }
+ }
+
+ public boolean contains(int value) {
+ return Arrays.binarySearch(mArray.mValues, 0, mArray.mSize, value) >= 0;
+ }
+
+ public boolean isEmpty() {
+ return mArray.isEmpty();
+ }
+
+ /**
+ * Returns the number of values in this set.
+ */
+ public int size() {
+ return mArray.size();
+ }
+}
diff --git a/src/com/android/launcher3/util/LongArrayMap.java b/src/com/android/launcher3/util/IntSparseArrayMap.java
index a337e85bd..9d5391be0 100644
--- a/src/com/android/launcher3/util/LongArrayMap.java
+++ b/src/com/android/launcher3/util/IntSparseArrayMap.java
@@ -16,16 +16,16 @@
package com.android.launcher3.util;
-import android.util.LongSparseArray;
+import android.util.SparseArray;
import java.util.Iterator;
/**
- * Extension of {@link LongSparseArray} with some utility methods.
+ * Extension of {@link SparseArray} with some utility methods.
*/
-public class LongArrayMap<E> extends LongSparseArray<E> implements Iterable<E> {
+public class IntSparseArrayMap<E> extends SparseArray<E> implements Iterable<E> {
- public boolean containsKey(long key) {
+ public boolean containsKey(int key) {
return indexOfKey(key) >= 0;
}
@@ -34,8 +34,8 @@ public class LongArrayMap<E> extends LongSparseArray<E> implements Iterable<E> {
}
@Override
- public LongArrayMap<E> clone() {
- return (LongArrayMap<E>) super.clone();
+ public IntSparseArrayMap<E> clone() {
+ return (IntSparseArrayMap<E>) super.clone();
}
@Override
diff --git a/src/com/android/launcher3/util/ItemInfoMatcher.java b/src/com/android/launcher3/util/ItemInfoMatcher.java
index 19cf6c1e5..c3570fe45 100644
--- a/src/com/android/launcher3/util/ItemInfoMatcher.java
+++ b/src/com/android/launcher3/util/ItemInfoMatcher.java
@@ -105,7 +105,7 @@ public interface ItemInfoMatcher {
keys.contains(ShortcutKey.fromItemInfo(info));
}
- static ItemInfoMatcher ofItemIds(LongArrayMap<Boolean> ids, Boolean matchDefault) {
+ static ItemInfoMatcher ofItemIds(IntSparseArrayMap<Boolean> ids, Boolean matchDefault) {
return (info, cn) -> ids.get(info.id, matchDefault);
}
}