From 0590a4c0cec8095dc299f1cacfe27a98f11a83b5 Mon Sep 17 00:00:00 2001 From: Rajeev Kumar Date: Fri, 9 Jun 2017 16:02:25 -0700 Subject: [PATCH] Replace use of java.util.HashMap with android.util.ArrayMap in AutoInstallsLayout, DefaultLayoutParser, ImportDataTask classes. Change-Id: Idcf1f5f020132ddf43751067a38a64bfc088800e Bug: 62466540 (cherry picked from commit 26453a297b622011258dc6b32403ba6586f00996) --- .../android/launcher3/AutoInstallsLayout.java | 41 +++++++++---------- .../launcher3/DefaultLayoutParser.java | 19 ++++----- .../launcher3/provider/ImportDataTask.java | 24 +++++------ 3 files changed, 38 insertions(+), 46 deletions(-) diff --git a/src/com/android/launcher3/AutoInstallsLayout.java b/src/com/android/launcher3/AutoInstallsLayout.java index 98eb208eb2..d82579bf77 100644 --- a/src/com/android/launcher3/AutoInstallsLayout.java +++ b/src/com/android/launcher3/AutoInstallsLayout.java @@ -30,23 +30,20 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; +import android.util.ArrayMap; import android.util.Log; import android.util.Pair; import android.util.Patterns; - import com.android.launcher3.LauncherProvider.SqlArguments; import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.graphics.LauncherIcons; import com.android.launcher3.util.Thunk; - -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import java.util.Locale; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; /** * Layout parsing code for auto installs layout @@ -83,7 +80,7 @@ public class AutoInstallsLayout { // Try with grid size and hotseat count String layoutName = String.format(Locale.ENGLISH, FORMATTED_LAYOUT_RES_WITH_HOSTEAT, - (int) grid.numColumns, (int) grid.numRows, (int) grid.numHotseatIcons); + grid.numColumns, grid.numRows, grid.numHotseatIcons); int layoutId = targetRes.getIdentifier(layoutName, "xml", pkg); // Try with only grid size @@ -91,7 +88,7 @@ public class AutoInstallsLayout { Log.d(TAG, "Formatted layout: " + layoutName + " not found. Trying layout without hosteat"); layoutName = String.format(Locale.ENGLISH, FORMATTED_LAYOUT_RES, - (int) grid.numColumns, (int) grid.numRows); + grid.numColumns, grid.numRows); layoutId = targetRes.getIdentifier(layoutName, "xml", pkg); } @@ -209,7 +206,7 @@ public class AutoInstallsLayout { beginDocument(parser, mRootTag); final int depth = parser.getDepth(); int type; - HashMap tagParserMap = getLayoutElementsMap(); + ArrayMap tagParserMap = getLayoutElementsMap(); int count = 0; while (((type = parser.next()) != XmlPullParser.END_TAG || @@ -243,10 +240,10 @@ public class AutoInstallsLayout { * Parses the current node and returns the number of elements added. */ protected int parseAndAddNode( - XmlResourceParser parser, - HashMap tagParserMap, - ArrayList screenIds) - throws XmlPullParserException, IOException { + XmlResourceParser parser, + ArrayMap tagParserMap, + ArrayList screenIds) + throws XmlPullParserException, IOException { if (TAG_INCLUDE.equals(parser.getName())) { final int resId = getAttributeResourceValue(parser, ATTR_WORKSPACE, 0); @@ -303,16 +300,16 @@ public class AutoInstallsLayout { } } - protected HashMap getFolderElementsMap() { - HashMap parsers = new HashMap(); + protected ArrayMap getFolderElementsMap() { + ArrayMap parsers = new ArrayMap<>(); parsers.put(TAG_APP_ICON, new AppShortcutParser()); parsers.put(TAG_AUTO_INSTALL, new AutoInstallParser()); parsers.put(TAG_SHORTCUT, new ShortcutParser(mSourceRes)); return parsers; } - protected HashMap getLayoutElementsMap() { - HashMap parsers = new HashMap(); + protected ArrayMap getLayoutElementsMap() { + ArrayMap parsers = new ArrayMap<>(); parsers.put(TAG_APP_ICON, new AppShortcutParser()); parsers.put(TAG_AUTO_INSTALL, new AutoInstallParser()); parsers.put(TAG_FOLDER, new FolderParser()); @@ -528,13 +525,13 @@ public class AutoInstallsLayout { } protected class FolderParser implements TagParser { - private final HashMap mFolderElements; + private final ArrayMap mFolderElements; public FolderParser() { this(getFolderElementsMap()); } - public FolderParser(HashMap elements) { + public FolderParser(ArrayMap elements) { mFolderElements = elements; } @@ -561,7 +558,7 @@ public class AutoInstallsLayout { } final ContentValues myValues = new ContentValues(mValues); - ArrayList folderItems = new ArrayList(); + ArrayList folderItems = new ArrayList<>(); int type; int folderDepth = parser.getDepth(); @@ -617,7 +614,7 @@ public class AutoInstallsLayout { } } - protected static final void beginDocument(XmlPullParser parser, String firstElementName) + protected static void beginDocument(XmlPullParser parser, String firstElementName) throws XmlPullParserException, IOException { int type; while ((type = parser.next()) != XmlPullParser.START_TAG @@ -671,7 +668,7 @@ public class AutoInstallsLayout { return value; } - public static interface LayoutParserCallback { + public interface LayoutParserCallback { long generateNewItemId(); long insertAndCheck(SQLiteDatabase db, ContentValues values); diff --git a/src/com/android/launcher3/DefaultLayoutParser.java b/src/com/android/launcher3/DefaultLayoutParser.java index 05911ab7fa..1ec30ba68d 100644 --- a/src/com/android/launcher3/DefaultLayoutParser.java +++ b/src/com/android/launcher3/DefaultLayoutParser.java @@ -13,18 +13,15 @@ import android.content.res.Resources; import android.content.res.XmlResourceParser; import android.os.Bundle; import android.text.TextUtils; +import android.util.ArrayMap; import android.util.Log; - import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.util.Thunk; - -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - import java.io.IOException; import java.net.URISyntaxException; -import java.util.HashMap; import java.util.List; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; /** * Implements the layout parser with rules for internal layouts and partner layouts. @@ -55,20 +52,20 @@ public class DefaultLayoutParser extends AutoInstallsLayout { } @Override - protected HashMap getFolderElementsMap() { + protected ArrayMap getFolderElementsMap() { return getFolderElementsMap(mSourceRes); } - @Thunk HashMap getFolderElementsMap(Resources res) { - HashMap parsers = new HashMap(); + @Thunk ArrayMap getFolderElementsMap(Resources res) { + ArrayMap parsers = new ArrayMap<>(); parsers.put(TAG_FAVORITE, new AppShortcutWithUriParser()); parsers.put(TAG_SHORTCUT, new UriShortcutParser(res)); return parsers; } @Override - protected HashMap getLayoutElementsMap() { - HashMap parsers = new HashMap(); + protected ArrayMap getLayoutElementsMap() { + ArrayMap parsers = new ArrayMap<>(); parsers.put(TAG_FAVORITE, new AppShortcutWithUriParser()); parsers.put(TAG_APPWIDGET, new AppWidgetParser()); parsers.put(TAG_SHORTCUT, new UriShortcutParser(mSourceRes)); diff --git a/src/com/android/launcher3/provider/ImportDataTask.java b/src/com/android/launcher3/provider/ImportDataTask.java index 314f244170..b83d3c0cdf 100644 --- a/src/com/android/launcher3/provider/ImportDataTask.java +++ b/src/com/android/launcher3/provider/ImportDataTask.java @@ -31,9 +31,9 @@ import android.database.sqlite.SQLiteDatabase; 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 com.android.launcher3.AutoInstallsLayout.LayoutParserCallback; import com.android.launcher3.DefaultLayoutParser; import com.android.launcher3.LauncherAppState; @@ -51,10 +51,8 @@ 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 java.net.URISyntaxException; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; /** @@ -134,7 +132,7 @@ public class ImportDataTask { String profileId = Long.toString(UserManagerCompat.getInstance(mContext) .getSerialNumberForUser(Process.myUserHandle())); - boolean createEmptyRowOnFirstScreen = false; + boolean createEmptyRowOnFirstScreen; if (FeatureFlags.QSB_ON_FIRST_SCREEN) { try (Cursor c = mContext.getContentResolver().query(mOtherFavoritesUri, null, // get items on the first row of the first screen @@ -326,9 +324,9 @@ public class ImportDataTask { } } - private static final String getPackage(Intent intent) { + private static String getPackage(Intent intent) { return intent.getComponent() != null ? intent.getComponent().getPackageName() - : intent.getPackage(); + : intent.getPackage(); } /** @@ -378,7 +376,7 @@ public class ImportDataTask { return false; } - private static final int getMyHotseatLayoutId(Context context) { + private static int getMyHotseatLayoutId(Context context) { return LauncherAppState.getIDP(context).numHotseatIcons <= 5 ? R.xml.dw_phone_hotseat : R.xml.dw_tablet_hotseat; @@ -393,9 +391,9 @@ public class ImportDataTask { } @Override - protected HashMap getLayoutElementsMap() { + protected ArrayMap getLayoutElementsMap() { // Only allow shortcut parsers - HashMap parsers = new HashMap(); + ArrayMap parsers = new ArrayMap<>(); parsers.put(TAG_FAVORITE, new AppShortcutWithUriParser()); parsers.put(TAG_SHORTCUT, new UriShortcutParser(mSourceRes)); parsers.put(TAG_RESOLVE, new ResolveParser()); @@ -407,7 +405,7 @@ public class ImportDataTask { * {@link LayoutParserCallback} which adds items in empty hotseat spots. */ private static class HotseatParserCallback implements LayoutParserCallback { - private final HashSet mExisitingApps; + private final HashSet mExistingApps; private final LongArrayMap mExistingItems; private final ArrayList mOutOps; private final int mRequiredSize; @@ -416,7 +414,7 @@ public class ImportDataTask { HotseatParserCallback( HashSet existingApps, LongArrayMap existingItems, ArrayList outOps, int startItemId, int requiredSize) { - mExisitingApps = existingApps; + mExistingApps = existingApps; mExistingItems = existingItems; mOutOps = outOps; mRequiredSize = requiredSize; @@ -441,11 +439,11 @@ public class ImportDataTask { return 0; } String pkg = getPackage(intent); - if (pkg == null || mExisitingApps.contains(pkg)) { + if (pkg == null || mExistingApps.contains(pkg)) { // The item does not target an app or is already in hotseat. return 0; } - mExisitingApps.add(pkg); + mExistingApps.add(pkg); // find next vacant spot. long screen = 0;