Loading src/com/android/launcher3/AppInfo.java +5 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.util.Log; import com.android.launcher3.compat.LauncherActivityInfoCompat; import com.android.launcher3.compat.UserHandleCompat; import com.android.launcher3.compat.UserManagerCompat; import com.android.launcher3.util.ComponentKey; import java.util.ArrayList; import java.util.Arrays; Loading Loading @@ -137,6 +138,10 @@ public class AppInfo extends ItemInfo { return new ShortcutInfo(this); } public ComponentKey toComponentKey() { return new ComponentKey(componentName, user); } public static Intent makeLaunchIntent(Context context, LauncherActivityInfoCompat info, UserHandleCompat user) { long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user); Loading src/com/android/launcher3/allapps/AllAppsContainerView.java +3 −1 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.widget.FrameLayout; import android.widget.LinearLayout; import com.android.launcher3.AppInfo; import com.android.launcher3.BaseContainerView; import com.android.launcher3.BubbleTextView; Loading @@ -56,6 +57,7 @@ import com.android.launcher3.R; import com.android.launcher3.Stats; import com.android.launcher3.Utilities; import com.android.launcher3.Workspace; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.Thunk; import java.nio.charset.Charset; Loading Loading @@ -763,7 +765,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc } @Override public void onSearchResult(String query, ArrayList<ComponentName> apps) { public void onSearchResult(String query, ArrayList<ComponentKey> apps) { if (apps != null) { if (apps.isEmpty()) { String formatStr = getResources().getString(R.string.all_apps_no_search_results); Loading src/com/android/launcher3/allapps/AllAppsSearchBarController.java +3 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ import android.graphics.Rect; import android.view.View; import android.view.ViewGroup; import com.android.launcher3.util.ComponentKey; import java.util.ArrayList; /** Loading Loading @@ -87,7 +89,7 @@ public abstract class AllAppsSearchBarController { * * @param apps sorted list of matching components or null if in case of failure. */ void onSearchResult(String query, ArrayList<ComponentName> apps); void onSearchResult(String query, ArrayList<ComponentKey> apps); /** * Called when the search results should be cleared. Loading src/com/android/launcher3/allapps/AlphabeticalAppsList.java +19 −64 Original line number Diff line number Diff line Loading @@ -19,12 +19,12 @@ import android.content.ComponentName; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.util.Log; import com.android.launcher3.AppInfo; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.compat.AlphabeticIndexCompat; import com.android.launcher3.model.AbstractUserComparator; import com.android.launcher3.model.AppNameComparator; import com.android.launcher3.util.ComponentKey; import java.util.ArrayList; import java.util.Collections; Loading Loading @@ -148,6 +148,8 @@ public class AlphabeticalAppsList { // The set of apps from the system not including predictions private final List<AppInfo> mApps = new ArrayList<>(); private final HashMap<ComponentKey, AppInfo> mComponentToAppMap = new HashMap<>(); // The set of filtered apps with the current filter private List<AppInfo> mFilteredApps = new ArrayList<>(); // The current set of adapter items Loading @@ -161,7 +163,7 @@ public class AlphabeticalAppsList { // The set of predicted apps resolved from the component names and the current set of apps private List<AppInfo> mPredictedApps = new ArrayList<>(); // The of ordered component names as a result of a search query private ArrayList<ComponentName> mSearchResults; private ArrayList<ComponentKey> mSearchResults; private HashMap<CharSequence, String> mCachedSectionNames = new HashMap<>(); private RecyclerView.Adapter mAdapter; private AlphabeticIndexCompat mIndexer; Loading Loading @@ -255,7 +257,7 @@ public class AlphabeticalAppsList { /** * Sets the sorted list of filtered components. */ public void setOrderedFilter(ArrayList<ComponentName> f) { public void setOrderedFilter(ArrayList<ComponentKey> f) { if (mSearchResults != f) { mSearchResults = f; updateAdapterItems(); Loading Loading @@ -283,33 +285,23 @@ public class AlphabeticalAppsList { * Sets the current set of apps. */ public void setApps(List<AppInfo> apps) { mApps.clear(); mApps.addAll(apps); onAppsUpdated(); mComponentToAppMap.clear(); addApps(apps); } /** * Adds new apps to the list. */ public void addApps(List<AppInfo> apps) { // We add it in place, in alphabetical order for (AppInfo info : apps) { mApps.add(info); } onAppsUpdated(); updateApps(apps); } /** * Updates existing apps in the list */ public void updateApps(List<AppInfo> apps) { for (AppInfo info : apps) { int index = mApps.indexOf(info); if (index != -1) { mApps.set(index, info); } else { mApps.add(info); } for (AppInfo app : apps) { mComponentToAppMap.put(app.toComponentKey(), app); } onAppsUpdated(); } Loading @@ -318,36 +310,19 @@ public class AlphabeticalAppsList { * Removes some apps from the list. */ public void removeApps(List<AppInfo> apps) { for (AppInfo info : apps) { int removeIndex = findAppByComponent(mApps, info); if (removeIndex != -1) { mApps.remove(removeIndex); } for (AppInfo app : apps) { mComponentToAppMap.remove(app.toComponentKey()); } onAppsUpdated(); } /** * Finds the index of an app given a target AppInfo. */ private int findAppByComponent(List<AppInfo> apps, AppInfo targetInfo) { ComponentName targetComponent = targetInfo.intent.getComponent(); int length = apps.size(); for (int i = 0; i < length; ++i) { AppInfo info = apps.get(i); if (info.user.equals(targetInfo.user) && info.intent.getComponent().equals(targetComponent)) { return i; } } return -1; } /** * Updates internals when the set of apps are updated. */ private void onAppsUpdated() { // Sort the list of apps mApps.clear(); mApps.addAll(mComponentToAppMap.values()); Collections.sort(mApps, mAppNameComparator.getAppInfoComparator()); // As a special case for some languages (currently only Simplified Chinese), we may need to Loading Loading @@ -494,33 +469,13 @@ public class AlphabeticalAppsList { return mApps; } int total = mSearchResults.size(); final HashMap<ComponentName, Integer> sortOrder = new HashMap<>(total); for (int i = 0; i < total; i++) { sortOrder.put(mSearchResults.get(i), i); } ArrayList<AppInfo> result = new ArrayList<>(); for (AppInfo info : mApps) { if (sortOrder.containsKey(info.componentName)) { result.add(info); } } Collections.sort(result, new AbstractUserComparator<AppInfo>( LauncherAppState.getInstance().getContext()) { @Override public int compare(AppInfo lhs, AppInfo rhs) { Integer indexA = sortOrder.get(lhs.componentName); int result = indexA.compareTo(sortOrder.get(rhs.componentName)); if (result == 0) { return super.compare(lhs, rhs); } else { return result; for (ComponentKey key : mSearchResults) { AppInfo match = mComponentToAppMap.get(key); if (match != null) { result.add(match); } } }); return result; } Loading src/com/android/launcher3/allapps/DefaultAppSearchAlgorithm.java +19 −16 Original line number Diff line number Diff line Loading @@ -15,9 +15,10 @@ */ package com.android.launcher3.allapps; import android.content.ComponentName; import android.os.Handler; import com.android.launcher3.AppInfo; import com.android.launcher3.util.ComponentKey; import java.util.ArrayList; import java.util.List; Loading Loading @@ -46,19 +47,7 @@ public class DefaultAppSearchAlgorithm { public void doSearch(final String query, final AllAppsSearchBarController.Callbacks callback) { // Do an intersection of the words in the query and each title, and filter out all the // apps that don't match all of the words in the query. final String queryTextLower = query.toLowerCase(); final String[] queryWords = SPLIT_PATTERN.split(queryTextLower); final ArrayList<ComponentName> result = new ArrayList<>(); int total = mApps.size(); for (int i = 0; i < total; i++) { AppInfo info = mApps.get(i); if (!result.contains(info.componentName) && matches(info, queryWords)) { result.add(info.componentName); } } final ArrayList<ComponentKey> result = getTitleMatchResult(query); mResultHandler.post(new Runnable() { @Override Loading @@ -68,7 +57,22 @@ public class DefaultAppSearchAlgorithm { }); } private boolean matches(AppInfo info, String[] queryWords) { protected ArrayList<ComponentKey> getTitleMatchResult(String query) { // Do an intersection of the words in the query and each title, and filter out all the // apps that don't match all of the words in the query. final String queryTextLower = query.toLowerCase(); final String[] queryWords = SPLIT_PATTERN.split(queryTextLower); final ArrayList<ComponentKey> result = new ArrayList<>(); for (AppInfo info : mApps) { if (matches(info, queryWords)) { result.add(info.toComponentKey()); } } return result; } protected boolean matches(AppInfo info, String[] queryWords) { String title = info.title.toString(); String[] words = SPLIT_PATTERN.split(title.toLowerCase()); for (int qi = 0; qi < queryWords.length; qi++) { Loading @@ -87,5 +91,4 @@ public class DefaultAppSearchAlgorithm { } return true; } } Loading
src/com/android/launcher3/AppInfo.java +5 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.util.Log; import com.android.launcher3.compat.LauncherActivityInfoCompat; import com.android.launcher3.compat.UserHandleCompat; import com.android.launcher3.compat.UserManagerCompat; import com.android.launcher3.util.ComponentKey; import java.util.ArrayList; import java.util.Arrays; Loading Loading @@ -137,6 +138,10 @@ public class AppInfo extends ItemInfo { return new ShortcutInfo(this); } public ComponentKey toComponentKey() { return new ComponentKey(componentName, user); } public static Intent makeLaunchIntent(Context context, LauncherActivityInfoCompat info, UserHandleCompat user) { long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user); Loading
src/com/android/launcher3/allapps/AllAppsContainerView.java +3 −1 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.widget.FrameLayout; import android.widget.LinearLayout; import com.android.launcher3.AppInfo; import com.android.launcher3.BaseContainerView; import com.android.launcher3.BubbleTextView; Loading @@ -56,6 +57,7 @@ import com.android.launcher3.R; import com.android.launcher3.Stats; import com.android.launcher3.Utilities; import com.android.launcher3.Workspace; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.Thunk; import java.nio.charset.Charset; Loading Loading @@ -763,7 +765,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc } @Override public void onSearchResult(String query, ArrayList<ComponentName> apps) { public void onSearchResult(String query, ArrayList<ComponentKey> apps) { if (apps != null) { if (apps.isEmpty()) { String formatStr = getResources().getString(R.string.all_apps_no_search_results); Loading
src/com/android/launcher3/allapps/AllAppsSearchBarController.java +3 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ import android.graphics.Rect; import android.view.View; import android.view.ViewGroup; import com.android.launcher3.util.ComponentKey; import java.util.ArrayList; /** Loading Loading @@ -87,7 +89,7 @@ public abstract class AllAppsSearchBarController { * * @param apps sorted list of matching components or null if in case of failure. */ void onSearchResult(String query, ArrayList<ComponentName> apps); void onSearchResult(String query, ArrayList<ComponentKey> apps); /** * Called when the search results should be cleared. Loading
src/com/android/launcher3/allapps/AlphabeticalAppsList.java +19 −64 Original line number Diff line number Diff line Loading @@ -19,12 +19,12 @@ import android.content.ComponentName; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.util.Log; import com.android.launcher3.AppInfo; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.compat.AlphabeticIndexCompat; import com.android.launcher3.model.AbstractUserComparator; import com.android.launcher3.model.AppNameComparator; import com.android.launcher3.util.ComponentKey; import java.util.ArrayList; import java.util.Collections; Loading Loading @@ -148,6 +148,8 @@ public class AlphabeticalAppsList { // The set of apps from the system not including predictions private final List<AppInfo> mApps = new ArrayList<>(); private final HashMap<ComponentKey, AppInfo> mComponentToAppMap = new HashMap<>(); // The set of filtered apps with the current filter private List<AppInfo> mFilteredApps = new ArrayList<>(); // The current set of adapter items Loading @@ -161,7 +163,7 @@ public class AlphabeticalAppsList { // The set of predicted apps resolved from the component names and the current set of apps private List<AppInfo> mPredictedApps = new ArrayList<>(); // The of ordered component names as a result of a search query private ArrayList<ComponentName> mSearchResults; private ArrayList<ComponentKey> mSearchResults; private HashMap<CharSequence, String> mCachedSectionNames = new HashMap<>(); private RecyclerView.Adapter mAdapter; private AlphabeticIndexCompat mIndexer; Loading Loading @@ -255,7 +257,7 @@ public class AlphabeticalAppsList { /** * Sets the sorted list of filtered components. */ public void setOrderedFilter(ArrayList<ComponentName> f) { public void setOrderedFilter(ArrayList<ComponentKey> f) { if (mSearchResults != f) { mSearchResults = f; updateAdapterItems(); Loading Loading @@ -283,33 +285,23 @@ public class AlphabeticalAppsList { * Sets the current set of apps. */ public void setApps(List<AppInfo> apps) { mApps.clear(); mApps.addAll(apps); onAppsUpdated(); mComponentToAppMap.clear(); addApps(apps); } /** * Adds new apps to the list. */ public void addApps(List<AppInfo> apps) { // We add it in place, in alphabetical order for (AppInfo info : apps) { mApps.add(info); } onAppsUpdated(); updateApps(apps); } /** * Updates existing apps in the list */ public void updateApps(List<AppInfo> apps) { for (AppInfo info : apps) { int index = mApps.indexOf(info); if (index != -1) { mApps.set(index, info); } else { mApps.add(info); } for (AppInfo app : apps) { mComponentToAppMap.put(app.toComponentKey(), app); } onAppsUpdated(); } Loading @@ -318,36 +310,19 @@ public class AlphabeticalAppsList { * Removes some apps from the list. */ public void removeApps(List<AppInfo> apps) { for (AppInfo info : apps) { int removeIndex = findAppByComponent(mApps, info); if (removeIndex != -1) { mApps.remove(removeIndex); } for (AppInfo app : apps) { mComponentToAppMap.remove(app.toComponentKey()); } onAppsUpdated(); } /** * Finds the index of an app given a target AppInfo. */ private int findAppByComponent(List<AppInfo> apps, AppInfo targetInfo) { ComponentName targetComponent = targetInfo.intent.getComponent(); int length = apps.size(); for (int i = 0; i < length; ++i) { AppInfo info = apps.get(i); if (info.user.equals(targetInfo.user) && info.intent.getComponent().equals(targetComponent)) { return i; } } return -1; } /** * Updates internals when the set of apps are updated. */ private void onAppsUpdated() { // Sort the list of apps mApps.clear(); mApps.addAll(mComponentToAppMap.values()); Collections.sort(mApps, mAppNameComparator.getAppInfoComparator()); // As a special case for some languages (currently only Simplified Chinese), we may need to Loading Loading @@ -494,33 +469,13 @@ public class AlphabeticalAppsList { return mApps; } int total = mSearchResults.size(); final HashMap<ComponentName, Integer> sortOrder = new HashMap<>(total); for (int i = 0; i < total; i++) { sortOrder.put(mSearchResults.get(i), i); } ArrayList<AppInfo> result = new ArrayList<>(); for (AppInfo info : mApps) { if (sortOrder.containsKey(info.componentName)) { result.add(info); } } Collections.sort(result, new AbstractUserComparator<AppInfo>( LauncherAppState.getInstance().getContext()) { @Override public int compare(AppInfo lhs, AppInfo rhs) { Integer indexA = sortOrder.get(lhs.componentName); int result = indexA.compareTo(sortOrder.get(rhs.componentName)); if (result == 0) { return super.compare(lhs, rhs); } else { return result; for (ComponentKey key : mSearchResults) { AppInfo match = mComponentToAppMap.get(key); if (match != null) { result.add(match); } } }); return result; } Loading
src/com/android/launcher3/allapps/DefaultAppSearchAlgorithm.java +19 −16 Original line number Diff line number Diff line Loading @@ -15,9 +15,10 @@ */ package com.android.launcher3.allapps; import android.content.ComponentName; import android.os.Handler; import com.android.launcher3.AppInfo; import com.android.launcher3.util.ComponentKey; import java.util.ArrayList; import java.util.List; Loading Loading @@ -46,19 +47,7 @@ public class DefaultAppSearchAlgorithm { public void doSearch(final String query, final AllAppsSearchBarController.Callbacks callback) { // Do an intersection of the words in the query and each title, and filter out all the // apps that don't match all of the words in the query. final String queryTextLower = query.toLowerCase(); final String[] queryWords = SPLIT_PATTERN.split(queryTextLower); final ArrayList<ComponentName> result = new ArrayList<>(); int total = mApps.size(); for (int i = 0; i < total; i++) { AppInfo info = mApps.get(i); if (!result.contains(info.componentName) && matches(info, queryWords)) { result.add(info.componentName); } } final ArrayList<ComponentKey> result = getTitleMatchResult(query); mResultHandler.post(new Runnable() { @Override Loading @@ -68,7 +57,22 @@ public class DefaultAppSearchAlgorithm { }); } private boolean matches(AppInfo info, String[] queryWords) { protected ArrayList<ComponentKey> getTitleMatchResult(String query) { // Do an intersection of the words in the query and each title, and filter out all the // apps that don't match all of the words in the query. final String queryTextLower = query.toLowerCase(); final String[] queryWords = SPLIT_PATTERN.split(queryTextLower); final ArrayList<ComponentKey> result = new ArrayList<>(); for (AppInfo info : mApps) { if (matches(info, queryWords)) { result.add(info.toComponentKey()); } } return result; } protected boolean matches(AppInfo info, String[] queryWords) { String title = info.title.toString(); String[] words = SPLIT_PATTERN.split(title.toLowerCase()); for (int qi = 0; qi < queryWords.length; qi++) { Loading @@ -87,5 +91,4 @@ public class DefaultAppSearchAlgorithm { } return true; } }