Merge "Replace use of java.util.HashMap with android.util.ArrayMap in AutoInstallsLayout, DefaultLayoutParser, ImportDataTask classes." into ub-launcher3-dorval-polish

This commit is contained in:
Rajeev Kumar 2017-06-13 17:42:52 +00:00 committed by Android (Google) Code Review
commit 7847d10f38
3 changed files with 38 additions and 46 deletions

View File

@ -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<String, TagParser> tagParserMap = getLayoutElementsMap();
ArrayMap<String, TagParser> 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<String, TagParser> tagParserMap,
ArrayList<Long> screenIds)
throws XmlPullParserException, IOException {
XmlResourceParser parser,
ArrayMap<String, TagParser> tagParserMap,
ArrayList<Long> 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<String, TagParser> getFolderElementsMap() {
HashMap<String, TagParser> parsers = new HashMap<String, TagParser>();
protected ArrayMap<String, TagParser> getFolderElementsMap() {
ArrayMap<String, TagParser> 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<String, TagParser> getLayoutElementsMap() {
HashMap<String, TagParser> parsers = new HashMap<String, TagParser>();
protected ArrayMap<String, TagParser> getLayoutElementsMap() {
ArrayMap<String, TagParser> 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<String, TagParser> mFolderElements;
private final ArrayMap<String, TagParser> mFolderElements;
public FolderParser() {
this(getFolderElementsMap());
}
public FolderParser(HashMap<String, TagParser> elements) {
public FolderParser(ArrayMap<String, TagParser> elements) {
mFolderElements = elements;
}
@ -561,7 +558,7 @@ public class AutoInstallsLayout {
}
final ContentValues myValues = new ContentValues(mValues);
ArrayList<Long> folderItems = new ArrayList<Long>();
ArrayList<Long> 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);

View File

@ -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<String, TagParser> getFolderElementsMap() {
protected ArrayMap<String, TagParser> getFolderElementsMap() {
return getFolderElementsMap(mSourceRes);
}
@Thunk HashMap<String, TagParser> getFolderElementsMap(Resources res) {
HashMap<String, TagParser> parsers = new HashMap<String, TagParser>();
@Thunk ArrayMap<String, TagParser> getFolderElementsMap(Resources res) {
ArrayMap<String, TagParser> parsers = new ArrayMap<>();
parsers.put(TAG_FAVORITE, new AppShortcutWithUriParser());
parsers.put(TAG_SHORTCUT, new UriShortcutParser(res));
return parsers;
}
@Override
protected HashMap<String, TagParser> getLayoutElementsMap() {
HashMap<String, TagParser> parsers = new HashMap<String, TagParser>();
protected ArrayMap<String, TagParser> getLayoutElementsMap() {
ArrayMap<String, TagParser> parsers = new ArrayMap<>();
parsers.put(TAG_FAVORITE, new AppShortcutWithUriParser());
parsers.put(TAG_APPWIDGET, new AppWidgetParser());
parsers.put(TAG_SHORTCUT, new UriShortcutParser(mSourceRes));

View File

@ -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<String, TagParser> getLayoutElementsMap() {
protected ArrayMap<String, TagParser> getLayoutElementsMap() {
// Only allow shortcut parsers
HashMap<String, TagParser> parsers = new HashMap<String, TagParser>();
ArrayMap<String, TagParser> 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<String> mExisitingApps;
private final HashSet<String> mExistingApps;
private final LongArrayMap<Object> mExistingItems;
private final ArrayList<ContentProviderOperation> mOutOps;
private final int mRequiredSize;
@ -416,7 +414,7 @@ public class ImportDataTask {
HotseatParserCallback(
HashSet<String> existingApps, LongArrayMap<Object> existingItems,
ArrayList<ContentProviderOperation> 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;