use of com.google.android.material.badge.BadgeDrawable.SavedState in project sesl by OneUIProject.
the class BadgeUtils method createBadgeDrawablesFromSavedStates.
/**
* Given a map of int keys to {@link BadgeDrawable.SavedState SavedStates}, creates a parcelable
* map of int keys to {@link BadgeDrawable BadgeDrawbles}. Useful for state restoration.
*
* @param context Current context
* @param badgeStates A parcelable {@link SparseArray} that contains a map of int keys (e.g.
* menuItemId) to {@link BadgeDrawable.SavedState states}.
* @return A {@link SparseArray} that contains a map of int keys (e.g. menuItemId) to {@code
* BadgeDrawable BadgeDrawbles}.
*/
@NonNull
public static SparseArray<BadgeDrawable> createBadgeDrawablesFromSavedStates(Context context, @NonNull ParcelableSparseArray badgeStates) {
SparseArray<BadgeDrawable> badgeDrawables = new SparseArray<>(badgeStates.size());
for (int i = 0; i < badgeStates.size(); i++) {
int key = badgeStates.keyAt(i);
BadgeDrawable.SavedState savedState = (SavedState) badgeStates.valueAt(i);
if (savedState == null) {
throw new IllegalArgumentException("BadgeDrawable's savedState cannot be null");
}
BadgeDrawable badgeDrawable = BadgeDrawable.createFromSavedState(context, savedState);
badgeDrawables.put(key, badgeDrawable);
}
return badgeDrawables;
}
Aggregations