diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-02-01 17:57:13 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-02-01 17:57:13 +0000 |
commit | 985b5399ed852304812e9df6ee49a97b13ae61de (patch) | |
tree | 8c970ae5ad1ab741717dab255e3c6dbb5499a6c1 | |
parent | bf9459b8ed61f931a0e62c4d790694e0727f43b8 (diff) | |
parent | aae6fbb903f5546aab9175dde18dfddd3549a176 (diff) | |
download | android_packages_apps_Trebuchet-985b5399ed852304812e9df6ee49a97b13ae61de.tar.gz android_packages_apps_Trebuchet-985b5399ed852304812e9df6ee49a97b13ae61de.tar.bz2 android_packages_apps_Trebuchet-985b5399ed852304812e9df6ee49a97b13ae61de.zip |
Merge "Moving some utility methods around" into ub-launcher3-master
8 files changed, 38 insertions, 50 deletions
diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java index ea59fff72..5c5f5e4b3 100644 --- a/src/com/android/launcher3/InstallShortcutReceiver.java +++ b/src/com/android/launcher3/InstallShortcutReceiver.java @@ -57,6 +57,7 @@ import org.json.JSONStringer; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -172,7 +173,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver { Log.d(TAG, "APPS_PENDING_INSTALL: " + strings + ", removing packages: " + packageNames); } - if (Utilities.isEmpty(strings)) { + if (strings == null || ((Collection) strings).isEmpty()) { return; } Set<String> newStrings = new HashSet<>(strings); @@ -268,7 +269,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver { HashSet<ShortcutKey> result = new HashSet<>(); Set<String> strings = Utilities.getPrefs(context).getStringSet(APPS_PENDING_INSTALL, null); - if (Utilities.isEmpty(strings)) { + if (strings == null || ((Collection) strings).isEmpty()) { return result; } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index fc3af7e82..73fba4eb6 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -146,6 +146,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.function.Predicate; import androidx.annotation.Nullable; @@ -1118,7 +1119,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, } }; - public void updateNotificationDots(final Set<PackageUserKey> updatedDots) { + public void updateNotificationDots(Predicate<PackageUserKey> updatedDots) { mWorkspace.updateNotificationDots(updatedDots); mAppsView.getAppsStore().updateNotificationDots(updatedDots); diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index c847120b9..60dfbb7d4 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -57,8 +57,6 @@ import com.android.launcher3.util.IntArray; import java.io.Closeable; import java.io.IOException; import java.lang.reflect.Method; -import java.util.Collection; -import java.util.HashSet; import java.util.Locale; import java.util.concurrent.Executor; import java.util.concurrent.LinkedBlockingQueue; @@ -514,47 +512,12 @@ public final class Utilities { } } - /** - * Returns true if {@param original} contains all entries defined in {@param updates} and - * have the same value. - * The comparison uses {@link Object#equals(Object)} to compare the values. - */ - public static boolean containsAll(Bundle original, Bundle updates) { - for (String key : updates.keySet()) { - Object value1 = updates.get(key); - Object value2 = original.get(key); - if (value1 == null) { - if (value2 != null) { - return false; - } - } else if (!value1.equals(value2)) { - return false; - } - } - return true; - } - - /** Returns whether the collection is null or empty. */ - public static boolean isEmpty(Collection c) { - return c == null || c.isEmpty(); - } - public static boolean isBinderSizeError(Exception e) { return e.getCause() instanceof TransactionTooLargeException || e.getCause() instanceof DeadObjectException; } /** - * Returns a HashSet with a single element. We use this instead of Collections.singleton() - * because HashSet ensures all operations, such as remove, are supported. - */ - public static <T> HashSet<T> singletonHashSet(T elem) { - HashSet<T> hashSet = new HashSet<>(1); - hashSet.add(elem); - return hashSet; - } - - /** * Utility method to post a runnable on the handler, skipping the synchronization barriers. */ public static void postAsyncCallback(Handler handler, Runnable callback) { diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 3438a269f..2db6cd922 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -98,6 +98,7 @@ import com.android.launcher3.widget.PendingAppWidgetHostView; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; +import java.util.function.Predicate; /** * The workspace is a wide area with a wallpaper and a finite number of pages. @@ -3059,7 +3060,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator> }); } - public void updateNotificationDots(final Set<PackageUserKey> updatedDots) { + public void updateNotificationDots(Predicate<PackageUserKey> updatedDots) { final PackageUserKey packageUserKey = new PackageUserKey(null, null); final IntSet folderIds = new IntSet(); mapOverItems(MAP_RECURSE, new ItemOperator() { @@ -3067,7 +3068,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator> public boolean evaluate(ItemInfo info, View v) { if (info instanceof ShortcutInfo && v instanceof BubbleTextView) { if (!packageUserKey.updateFromItemInfo(info) - || updatedDots.contains(packageUserKey)) { + || updatedDots.test(packageUserKey)) { ((BubbleTextView) v).applyDotState(info, true /* animate */); folderIds.add(info.container); } diff --git a/src/com/android/launcher3/allapps/AllAppsStore.java b/src/com/android/launcher3/allapps/AllAppsStore.java index 52d7d28e8..8e7fec863 100644 --- a/src/com/android/launcher3/allapps/AllAppsStore.java +++ b/src/com/android/launcher3/allapps/AllAppsStore.java @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.List; import java.util.Set; import java.util.function.Consumer; +import java.util.function.Predicate; /** * A utility class to maintain the collection of all apps. @@ -122,11 +123,11 @@ public class AllAppsStore { mIconContainers.remove(container); } - public void updateNotificationDots(Set<PackageUserKey> updatedDots) { + public void updateNotificationDots(Predicate<PackageUserKey> updatedDots) { updateAllIcons((child) -> { if (child.getTag() instanceof ItemInfo) { ItemInfo info = (ItemInfo) child.getTag(); - if (mTempKey.updateFromItemInfo(info) && updatedDots.contains(mTempKey)) { + if (mTempKey.updateFromItemInfo(info) && updatedDots.test(mTempKey)) { child.applyDotState(info, true /* animate */); } } diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index 288d5687f..9b23f3f21 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -73,6 +73,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Predicate; /** * A container for shortcuts to deep links and notifications associated with an app. @@ -463,10 +464,10 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, /** * Updates the notification header if the original icon's dot updated. */ - public void updateNotificationHeader(Set<PackageUserKey> updatedDots) { + public void updateNotificationHeader(Predicate<PackageUserKey> updatedDots) { ItemInfo itemInfo = (ItemInfo) mOriginalIcon.getTag(); PackageUserKey packageUser = PackageUserKey.fromItemInfo(itemInfo); - if (updatedDots.contains(packageUser)) { + if (updatedDots.test(packageUser)) { updateNotificationHeader(); } } diff --git a/src/com/android/launcher3/popup/PopupDataProvider.java b/src/com/android/launcher3/popup/PopupDataProvider.java index 984a03df5..f4da858d1 100644 --- a/src/com/android/launcher3/popup/PopupDataProvider.java +++ b/src/com/android/launcher3/popup/PopupDataProvider.java @@ -85,7 +85,7 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan } } if (dotShouldBeRefreshed) { - mLauncher.updateNotificationDots(Utilities.singletonHashSet(postedPackageUserKey)); + mLauncher.updateNotificationDots(t -> postedPackageUserKey.equals(t)); } } @@ -97,7 +97,7 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan if (oldDotInfo.getNotificationKeys().size() == 0) { mPackageUserToDotInfos.remove(removedPackageUserKey); } - mLauncher.updateNotificationDots(Utilities.singletonHashSet(removedPackageUserKey)); + mLauncher.updateNotificationDots(t -> removedPackageUserKey.equals(t)); trimNotifications(mPackageUserToDotInfos); } } @@ -133,7 +133,7 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan } if (!updatedDots.isEmpty()) { - mLauncher.updateNotificationDots(updatedDots.keySet()); + mLauncher.updateNotificationDots(updatedDots::containsKey); } trimNotifications(updatedDots); } diff --git a/src/com/android/launcher3/qsb/QsbContainerView.java b/src/com/android/launcher3/qsb/QsbContainerView.java index 57a458b09..c2bae6d3f 100644 --- a/src/com/android/launcher3/qsb/QsbContainerView.java +++ b/src/com/android/launcher3/qsb/QsbContainerView.java @@ -159,7 +159,7 @@ public class QsbContainerView extends FrameLayout { mQsb.setId(R.id.qsb_widget); if (!isInPreviewMode()) { - if (!Utilities.containsAll(AppWidgetManager.getInstance(context) + if (!containsAll(AppWidgetManager.getInstance(context) .getAppWidgetOptions(widgetId), opts)) { mQsb.updateAppWidgetOptions(opts); } @@ -296,4 +296,24 @@ public class QsbContainerView extends FrameLayout { QsbWidgetHostView newView(Context context); } + + /** + * Returns true if {@param original} contains all entries defined in {@param updates} and + * have the same value. + * The comparison uses {@link Object#equals(Object)} to compare the values. + */ + private static boolean containsAll(Bundle original, Bundle updates) { + for (String key : updates.keySet()) { + Object value1 = updates.get(key); + Object value2 = original.get(key); + if (value1 == null) { + if (value2 != null) { + return false; + } + } else if (!value1.equals(value2)) { + return false; + } + } + return true; + } } |