Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit efb7e842 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

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
parent f307b603
Loading
Loading
Loading
Loading
+28 −29
Original line number Diff line number Diff line
@@ -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) {
+3 −3
Original line number Diff line number Diff line
@@ -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;
+10 −10
Original line number Diff line number Diff line
@@ -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();

+5 −5
Original line number Diff line number Diff line
@@ -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);
+16 −15
Original line number Diff line number Diff line
@@ -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;

Loading