Moving some utility methods around
Change-Id: I8abca49a0dbf656212b21e0552502036a1619164
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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,46 +512,11 @@ 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.
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 */);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user