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