Search in sources :

Example 1 with ParcelableSparseArray

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;
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable) SparseArray(android.util.SparseArray) ParcelableSparseArray(com.google.android.material.internal.ParcelableSparseArray)

Example 2 with ParcelableSparseArray

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;
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable) ParcelableSparseArray(com.google.android.material.internal.ParcelableSparseArray)

Example 3 with ParcelableSparseArray

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;
}
Also used : SavedState(com.google.android.material.badge.BadgeDrawable.SavedState) ParcelableSparseArray(com.google.android.material.internal.ParcelableSparseArray) SparseArray(android.util.SparseArray) SavedState(com.google.android.material.badge.BadgeDrawable.SavedState) NonNull(androidx.annotation.NonNull)

Example 4 with ParcelableSparseArray

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;
}
Also used : ParcelableSparseArray(com.google.android.material.internal.ParcelableSparseArray) NonNull(androidx.annotation.NonNull)

Aggregations

ParcelableSparseArray (com.google.android.material.internal.ParcelableSparseArray)4 SparseArray (android.util.SparseArray)2 NonNull (androidx.annotation.NonNull)2 BadgeDrawable (com.google.android.material.badge.BadgeDrawable)2 SavedState (com.google.android.material.badge.BadgeDrawable.SavedState)1