Moving predicted apps callbacks to use ComponentKey.

Bug: 21270185

Change-Id: If2d9dd77235e7a96de96a1a5441a589ef8a72a7f
This commit is contained in:
Winson Chung committed 2015-06-18 12:39:24 -07:00
1 parent 01d4053436
commit 6b1c73f50a
6 files changed
+57 -20

No files matched your search

@@ -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;