summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/util/ComponentKey.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/util/ComponentKey.java')
-rw-r--r--src/com/android/launcher3/util/ComponentKey.java29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/com/android/launcher3/util/ComponentKey.java b/src/com/android/launcher3/util/ComponentKey.java
index 7a7ed4a4f..6a7df4318 100644
--- a/src/com/android/launcher3/util/ComponentKey.java
+++ b/src/com/android/launcher3/util/ComponentKey.java
@@ -19,6 +19,7 @@ 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,9 +39,33 @@ 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) {
- // Do nothing
- throw new UnsupportedOperationException();
+ 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