summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Fufa <sfufa@google.com>2020-04-16 21:17:44 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-04-16 21:17:44 +0000
commit75f2f6779670ec716c037c419bdf5f69b076786a (patch)
treecdf5719f018b25dbf47373148805c0419ecb6395
parentb277c5081de994d283b20bd5e63f7bfc95997b91 (diff)
parenta4c563c8cc9075f922541028b1d33e2ad5c1f186 (diff)
Allow ComponentKey creation from its string representation am: a4c563c8cc
Change-Id: Ifb92cdad7ccc7144a37c7bfc21f6ab09e8af8ede
-rw-r--r--iconloaderlib/src/com/android/launcher3/util/ComponentKey.java27
1 files changed, 26 insertions, 1 deletions
diff --git a/iconloaderlib/src/com/android/launcher3/util/ComponentKey.java b/iconloaderlib/src/com/android/launcher3/util/ComponentKey.java
index 34bed94..7145103 100644
--- a/iconloaderlib/src/com/android/launcher3/util/ComponentKey.java
+++ b/iconloaderlib/src/com/android/launcher3/util/ComponentKey.java
@@ -19,6 +19,9 @@ package com.android.launcher3.util;
import android.content.ComponentName;
import android.os.UserHandle;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
import java.util.Arrays;
public class ComponentKey {
@@ -54,6 +57,28 @@ public class ComponentKey {
*/
@Override
public String toString() {
- return componentName.flattenToString() + "#" + user;
+ return componentName.flattenToString() + "#" + user.hashCode();
+ }
+
+ /**
+ * Parses and returns ComponentKey objected from string representation
+ * Returns null if string is not properly formatted
+ */
+ @Nullable
+ public static ComponentKey fromString(@NonNull String str) {
+ int sep = str.indexOf('#');
+ if (sep < 0 || (sep + 1) >= str.length()) {
+ return null;
+ }
+ ComponentName componentName = ComponentName.unflattenFromString(str.substring(0, sep));
+ if (componentName == null) {
+ return null;
+ }
+ try {
+ return new ComponentKey(componentName,
+ UserHandle.getUserHandleForUid(Integer.parseInt(str.substring(sep + 1))));
+ } catch (NumberFormatException ex) {
+ return null;
+ }
}
} \ No newline at end of file