summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2015-06-18 21:10:41 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-18 21:10:41 +0000
commitd3800208aa8c4f5926502ccb8e49e13501b441c9 (patch)
treec8cfbbb455b7ff26e1d48fccea8e148b09fb6fd7 /src
parent230eade4a35d9dfe9b186da46e38ca05f0256a69 (diff)
parent6b1c73f50a99a215c923aa0caca8e63c593a4eb2 (diff)
downloadandroid_packages_apps_Trebuchet-d3800208aa8c4f5926502ccb8e49e13501b441c9.tar.gz
android_packages_apps_Trebuchet-d3800208aa8c4f5926502ccb8e49e13501b441c9.tar.bz2
android_packages_apps_Trebuchet-d3800208aa8c4f5926502ccb8e49e13501b441c9.zip
Merge "Moving predicted apps callbacks to use ComponentKey." into ub-launcher3-burnaby
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/Launcher.java5
-rw-r--r--src/com/android/launcher3/LauncherCallbacks.java3
-rw-r--r--src/com/android/launcher3/LauncherExtension.java3
-rw-r--r--src/com/android/launcher3/allapps/AllAppsContainerView.java2
-rw-r--r--src/com/android/launcher3/allapps/AlphabeticalAppsList.java32
-rw-r--r--src/com/android/launcher3/util/ComponentKey.java32
6 files changed, 57 insertions, 20 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 3596b71d2..a75a09af7 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -93,17 +93,16 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
-
import com.android.launcher3.DropTarget.DragObject;
import com.android.launcher3.PagedView.PageSwitchListener;
import com.android.launcher3.allapps.AllAppsContainerView;
-import com.android.launcher3.allapps.AllAppsSearchBarController;
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.LauncherActivityInfoCompat;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.model.WidgetsModel;
+import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.widget.PendingAddWidgetInfo;
@@ -3448,7 +3447,7 @@ public class Launcher extends Activity
*/
private void tryAndUpdatePredictedApps() {
if (mLauncherCallbacks != null) {
- List<ComponentName> apps = mLauncherCallbacks.getPredictedApps();
+ List<ComponentKey> apps = mLauncherCallbacks.getPredictedApps();
if (!apps.isEmpty()) {
mAppsView.setPredictedApps(apps);
}
diff --git a/src/com/android/launcher3/LauncherCallbacks.java b/src/com/android/launcher3/LauncherCallbacks.java
index e73275400..56db7747c 100644
--- a/src/com/android/launcher3/LauncherCallbacks.java
+++ b/src/com/android/launcher3/LauncherCallbacks.java
@@ -8,6 +8,7 @@ import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import com.android.launcher3.allapps.AllAppsSearchBarController;
+import com.android.launcher3.util.ComponentKey;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -92,7 +93,7 @@ public interface LauncherCallbacks {
public boolean overrideWallpaperDimensions();
public boolean isLauncherPreinstalled();
public AllAppsSearchBarController getAllAppsSearchBarController();
- public List<ComponentName> getPredictedApps();
+ public List<ComponentKey> getPredictedApps();
/**
* Returning true will immediately result in a call to {@link #setLauncherOverlayView(ViewGroup,
diff --git a/src/com/android/launcher3/LauncherExtension.java b/src/com/android/launcher3/LauncherExtension.java
index fafb070ec..857ec57a7 100644
--- a/src/com/android/launcher3/LauncherExtension.java
+++ b/src/com/android/launcher3/LauncherExtension.java
@@ -12,6 +12,7 @@ import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import com.android.launcher3.allapps.AllAppsSearchBarController;
+import com.android.launcher3.util.ComponentKey;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -253,7 +254,7 @@ public class LauncherExtension extends Launcher {
}
@Override
- public List<ComponentName> getPredictedApps() {
+ public List<ComponentKey> getPredictedApps() {
return new ArrayList<>();
}
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 0fbe8e962..d49a06b3a 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -207,7 +207,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
/**
* Sets the current set of predicted apps.
*/
- public void setPredictedApps(List<ComponentName> apps) {
+ public void setPredictedApps(List<ComponentKey> apps) {
mApps.setPredictedApps(apps);
}
diff --git a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
index b7b6ed7fc..aa73c74cf 100644
--- a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
+++ b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
@@ -15,14 +15,14 @@
*/
package com.android.launcher3.allapps;
-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.compat.UserHandleCompat;
import com.android.launcher3.model.AppNameComparator;
import com.android.launcher3.util.ComponentKey;
@@ -159,7 +159,7 @@ public class AlphabeticalAppsList {
// The set of sections that we allow fast-scrolling to (includes non-merged sections)
private List<FastScrollSectionInfo> mFastScrollerSections = new ArrayList<>();
// The set of predicted app component names
- private List<ComponentName> mPredictedAppComponents = new ArrayList<>();
+ private List<ComponentKey> mPredictedAppComponents = new ArrayList<>();
// 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
@@ -268,7 +268,7 @@ public class AlphabeticalAppsList {
* Sets the current set of predicted apps. Since this can be called before we get the full set
* of applications, we should merge the results only in onAppsUpdated() which is idempotent.
*/
- public void setPredictedApps(List<ComponentName> apps) {
+ public void setPredictedApps(List<ComponentKey> apps) {
mPredictedAppComponents.clear();
mPredictedAppComponents.addAll(apps);
onAppsUpdated();
@@ -386,21 +386,27 @@ public class AlphabeticalAppsList {
if (DEBUG_PREDICTIONS) {
if (mPredictedAppComponents.isEmpty() && !mApps.isEmpty()) {
- mPredictedAppComponents.add(mApps.get(0).componentName);
- mPredictedAppComponents.add(mApps.get(0).componentName);
- mPredictedAppComponents.add(mApps.get(0).componentName);
- mPredictedAppComponents.add(mApps.get(0).componentName);
+ mPredictedAppComponents.add(new ComponentKey(mApps.get(0).componentName,
+ UserHandleCompat.myUserHandle()));
+ mPredictedAppComponents.add(new ComponentKey(mApps.get(0).componentName,
+ UserHandleCompat.myUserHandle()));
+ mPredictedAppComponents.add(new ComponentKey(mApps.get(0).componentName,
+ UserHandleCompat.myUserHandle()));
+ mPredictedAppComponents.add(new ComponentKey(mApps.get(0).componentName,
+ UserHandleCompat.myUserHandle()));
}
}
// Process the predicted app components
mPredictedApps.clear();
if (mPredictedAppComponents != null && !mPredictedAppComponents.isEmpty() && !hasFilter()) {
- for (ComponentName cn : mPredictedAppComponents) {
- for (AppInfo info : mApps) {
- if (cn.equals(info.componentName)) {
- mPredictedApps.add(info);
- break;
+ for (ComponentKey ck : mPredictedAppComponents) {
+ AppInfo info = mComponentToAppMap.get(ck);
+ if (info != null) {
+ mPredictedApps.add(info);
+ } else {
+ if (LauncherAppState.isDogfoodBuild()) {
+ Log.e(TAG, "Predicted app not found: " + ck.flattenToString(mLauncher));
}
}
// Stop at the number of predicted apps
diff --git a/src/com/android/launcher3/util/ComponentKey.java b/src/com/android/launcher3/util/ComponentKey.java
index 0f17f009e..6a7df4318 100644
--- a/src/com/android/launcher3/util/ComponentKey.java
+++ b/src/com/android/launcher3/util/ComponentKey.java
@@ -17,8 +17,9 @@ package com.android.launcher3.util;
*/
import android.content.ComponentName;
-
+import android.content.Context;
import com.android.launcher3.compat.UserHandleCompat;
+import com.android.launcher3.compat.UserManagerCompat;
import java.util.Arrays;
@@ -38,6 +39,35 @@ public class ComponentKey {
}
+ /**
+ * Creates a new component key from an encoded component key string in the form of
+ * [flattenedComponentString#userId]. If the userId is not present, then it defaults
+ * to the current user.
+ */
+ public ComponentKey(Context context, String componentKeyStr) {
+ int userDelimiterIndex = componentKeyStr.indexOf("#");
+ if (userDelimiterIndex != -1) {
+ String componentStr = componentKeyStr.substring(0, userDelimiterIndex);
+ Long componentUser = Long.valueOf(componentKeyStr.substring(userDelimiterIndex + 1));
+ componentName = ComponentName.unflattenFromString(componentStr);
+ user = UserManagerCompat.getInstance(context)
+ .getUserForSerialNumber(componentUser.longValue());
+ } else {
+ // No user provided, default to the current user
+ componentName = ComponentName.unflattenFromString(componentKeyStr);
+ user = UserHandleCompat.myUserHandle();
+ }
+ mHashCode = Arrays.hashCode(new Object[] {componentName, user});
+ }
+
+ /**
+ * Encodes a component key as a string of the form [flattenedComponentString#userId].
+ */
+ public String flattenToString(Context context) {
+ return componentName.flattenToString() + "#" +
+ UserManagerCompat.getInstance(context).getSerialNumberForUser(user);
+ }
+
@Override
public int hashCode() {
return mHashCode;