Example usage for android.util SparseArray remove

List of usage examples for android.util SparseArray remove

Introduction

In this page you can find the example usage for android.util SparseArray remove.

Prototype

public void remove(int key) 

Source Link

Document

Alias for #delete(int) .

Usage

From source file:android.support.v7.content.res.AppCompatResources.java

@Nullable
private static ColorStateList getCachedColorStateList(@NonNull Context context, @ColorRes int resId) {
    synchronized (sColorStateCacheLock) {
        final SparseArray<ColorStateListCacheEntry> entries = sColorStateCaches.get(context);
        if (entries != null && entries.size() > 0) {
            final ColorStateListCacheEntry entry = entries.get(resId);
            if (entry != null) {
                if (entry.configuration.equals(context.getResources().getConfiguration())) {
                    // If the current configuration matches the entry's, we can use it
                    return entry.value;
                } else {
                    // Otherwise we'll remove the entry
                    entries.remove(resId);
                }/*w  w w  .j av a 2  s .c  o  m*/
            }
        }
    }
    return null;
}

From source file:com.gh.bmd.jrt.android.v4.core.LoaderInvocation.java

/**
 * Destroys the loader with the specified ID.
 *
 * @param context  the context./*  w  w w .  j  av a 2  s .co  m*/
 * @param loaderId the loader ID.
 */
static void purgeLoader(@Nonnull final Object context, final int loaderId) {

    final SparseArray<WeakReference<RoutineLoaderCallbacks<?>>> callbackArray = sCallbackMap.get(context);

    if (callbackArray == null) {

        return;
    }

    final LoaderManager loaderManager;

    if (context instanceof FragmentActivity) {

        final FragmentActivity activity = (FragmentActivity) context;
        loaderManager = activity.getSupportLoaderManager();

    } else if (context instanceof Fragment) {

        final Fragment fragment = (Fragment) context;
        loaderManager = fragment.getLoaderManager();

    } else {

        throw new IllegalArgumentException("invalid context type: " + context.getClass().getCanonicalName());
    }

    int i = 0;

    while (i < callbackArray.size()) {

        final RoutineLoaderCallbacks<?> callbacks = callbackArray.valueAt(i).get();

        if (callbacks == null) {

            callbackArray.remove(callbackArray.keyAt(i));
            continue;
        }

        final RoutineLoader<?, ?> loader = callbacks.mLoader;

        if ((loaderId == callbackArray.keyAt(i)) && (loader.getInvocationCount() == 0)) {

            loaderManager.destroyLoader(loaderId);
            callbackArray.remove(loaderId);
            continue;
        }

        ++i;
    }

    if (callbackArray.size() == 0) {

        sCallbackMap.remove(context);
    }
}

From source file:com.gh.bmd.jrt.android.v4.core.LoaderInvocation.java

/**
 * Destroys the loader with the specified ID and the specified inputs.
 *
 * @param context  the context./*  w w w .  ja v a 2 s  .  c  om*/
 * @param loaderId the loader ID.
 * @param inputs   the invocation inputs.
 */
@SuppressWarnings("unchecked")
static void purgeLoader(@Nonnull final Object context, final int loaderId, @Nonnull final List<?> inputs) {

    final SparseArray<WeakReference<RoutineLoaderCallbacks<?>>> callbackArray = sCallbackMap.get(context);

    if (callbackArray == null) {

        return;
    }

    final LoaderManager loaderManager;

    if (context instanceof FragmentActivity) {

        final FragmentActivity activity = (FragmentActivity) context;
        loaderManager = activity.getSupportLoaderManager();

    } else if (context instanceof Fragment) {

        final Fragment fragment = (Fragment) context;
        loaderManager = fragment.getLoaderManager();

    } else {

        throw new IllegalArgumentException("invalid context type: " + context.getClass().getCanonicalName());
    }

    int i = 0;

    while (i < callbackArray.size()) {

        final RoutineLoaderCallbacks<?> callbacks = callbackArray.valueAt(i).get();

        if (callbacks == null) {

            callbackArray.remove(callbackArray.keyAt(i));
            continue;
        }

        final RoutineLoader<Object, Object> loader = (RoutineLoader<Object, Object>) callbacks.mLoader;

        if ((loader.getInvocationCount() == 0) && (loaderId == callbackArray.keyAt(i))
                && loader.areSameInputs(inputs)) {

            loaderManager.destroyLoader(loaderId);
            callbackArray.remove(loaderId);
            continue;
        }

        ++i;
    }

    if (callbackArray.size() == 0) {

        sCallbackMap.remove(context);
    }
}

From source file:com.gh.bmd.jrt.android.v4.core.LoaderInvocation.java

/**
 * Destroys all loaders with the specified invocation class.
 *
 * @param context         the context.//from  w w w .  ja v  a 2 s. com
 * @param loaderId        the loader ID.
 * @param invocationClass the invocation class.
 * @param invocationArgs  the invocation constructor arguments.
 */
static void purgeLoaders(@Nonnull final Object context, final int loaderId,
        @Nonnull final Class<?> invocationClass, @Nonnull final Object[] invocationArgs) {

    final SparseArray<WeakReference<RoutineLoaderCallbacks<?>>> callbackArray = sCallbackMap.get(context);

    if (callbackArray == null) {

        return;
    }

    final LoaderManager loaderManager;

    if (context instanceof FragmentActivity) {

        final FragmentActivity activity = (FragmentActivity) context;
        loaderManager = activity.getSupportLoaderManager();

    } else if (context instanceof Fragment) {

        final Fragment fragment = (Fragment) context;
        loaderManager = fragment.getLoaderManager();

    } else {

        throw new IllegalArgumentException("invalid context type: " + context.getClass().getCanonicalName());
    }

    int i = 0;

    while (i < callbackArray.size()) {

        final RoutineLoaderCallbacks<?> callbacks = callbackArray.valueAt(i).get();

        if (callbacks == null) {

            callbackArray.remove(callbackArray.keyAt(i));
            continue;
        }

        final RoutineLoader<?, ?> loader = callbacks.mLoader;

        if ((loader.getInvocationType() == invocationClass)
                && Arrays.equals(loader.getInvocationArgs(), invocationArgs)
                && (loader.getInvocationCount() == 0)) {

            final int id = callbackArray.keyAt(i);

            if ((loaderId == ContextRoutineBuilder.AUTO) || (loaderId == id)) {

                loaderManager.destroyLoader(id);
                callbackArray.remove(id);
                continue;
            }
        }

        ++i;
    }

    if (callbackArray.size() == 0) {

        sCallbackMap.remove(context);
    }
}

From source file:com.gh.bmd.jrt.android.v4.core.LoaderInvocation.java

/**
 * Destroys all loaders with the specified invocation class and the specified inputs.
 *
 * @param context         the context./*from   w  ww  . jav  a 2  s .c om*/
 * @param loaderId        the loader ID.
 * @param invocationClass the invocation class.
 * @param invocationArgs  the invocation constructor arguments.
 * @param inputs          the invocation inputs.
 */
@SuppressWarnings("unchecked")
static void purgeLoader(@Nonnull final Object context, final int loaderId,
        @Nonnull final Class<?> invocationClass, @Nonnull final Object[] invocationArgs,
        @Nonnull final List<?> inputs) {

    final SparseArray<WeakReference<RoutineLoaderCallbacks<?>>> callbackArray = sCallbackMap.get(context);

    if (callbackArray == null) {

        return;
    }

    final LoaderManager loaderManager;

    if (context instanceof FragmentActivity) {

        final FragmentActivity activity = (FragmentActivity) context;
        loaderManager = activity.getSupportLoaderManager();

    } else if (context instanceof Fragment) {

        final Fragment fragment = (Fragment) context;
        loaderManager = fragment.getLoaderManager();

    } else {

        throw new IllegalArgumentException("invalid context type: " + context.getClass().getCanonicalName());
    }

    int i = 0;

    while (i < callbackArray.size()) {

        final RoutineLoaderCallbacks<?> callbacks = callbackArray.valueAt(i).get();

        if (callbacks == null) {

            callbackArray.remove(callbackArray.keyAt(i));
            continue;
        }

        final RoutineLoader<Object, Object> loader = (RoutineLoader<Object, Object>) callbacks.mLoader;

        if ((loader.getInvocationType() == invocationClass)
                && Arrays.equals(loader.getInvocationArgs(), invocationArgs)
                && (loader.getInvocationCount() == 0)) {

            final int id = callbackArray.keyAt(i);

            if (((loaderId == ContextRoutineBuilder.AUTO) || (loaderId == id))
                    && loader.areSameInputs(inputs)) {

                loaderManager.destroyLoader(id);
                callbackArray.remove(id);
                continue;
            }
        }

        ++i;
    }

    if (callbackArray.size() == 0) {

        sCallbackMap.remove(context);
    }
}

From source file:fr.cph.chicago.core.fragment.NearbyFragment.java

private void hideStationsAndStopsIfNeeded(@NonNull final List<BusStop> busStops,
        @NonNull final SparseArray<Map<String, List<BusArrival>>> busArrivalsMap,
        @NonNull final List<Station> trainStations, @NonNull final SparseArray<TrainArrival> trainArrivals) {
    if (hideStationsStops && isAdded()) {
        final List<BusStop> busStopTmp = new ArrayList<>();
        for (final BusStop busStop : busStops) {
            if (busArrivalsMap.get(busStop.getId(), new ConcurrentHashMap<>()).size() == 0) {
                busArrivalsMap.remove(busStop.getId());
            } else {
                busStopTmp.add(busStop);
            }//from   ww  w. j  a  v a 2 s. co  m
        }
        busStops.clear();
        busStops.addAll(busStopTmp);

        final List<Station> trainStationTmp = new ArrayList<>();
        for (final Station station : trainStations) {
            if (trainArrivals.get(station.getId()) == null
                    || trainArrivals.get(station.getId()).getEtas().size() == 0) {
                trainArrivals.remove(station.getId());
            } else {
                trainStationTmp.add(station);
            }
        }
        trainStations.clear();
        trainStations.addAll(trainStationTmp);
    }
}

From source file:android.support.transition.TransitionPort.java

/**
 * This method, essentially a wrapper around all calls to createAnimator for all
 * possible target views, is called with the entire set of start/end
 * values. The implementation in Transition iterates through these lists
 * and calls {@link #createAnimator(ViewGroup, TransitionValues, TransitionValues)}
 * with each set of start/end values on this transition. The
 * TransitionSet subclass overrides this method and delegates it to
 * each of its children in succession.//from w  w  w.  ja v a  2 s .c  o  m
 *
 * @hide
 */
@RestrictTo(GROUP_ID)
protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues,
        TransitionValuesMaps endValues) {
    if (DBG) {
        Log.d(LOG_TAG, "createAnimators() for " + this);
    }
    ArrayMap<View, TransitionValues> endCopy = new ArrayMap<>(endValues.viewValues);
    SparseArray<TransitionValues> endIdCopy = new SparseArray<>(endValues.idValues.size());
    for (int i = 0; i < endValues.idValues.size(); ++i) {
        int id = endValues.idValues.keyAt(i);
        endIdCopy.put(id, endValues.idValues.valueAt(i));
    }
    LongSparseArray<TransitionValues> endItemIdCopy = new LongSparseArray<>(endValues.itemIdValues.size());
    for (int i = 0; i < endValues.itemIdValues.size(); ++i) {
        long id = endValues.itemIdValues.keyAt(i);
        endItemIdCopy.put(id, endValues.itemIdValues.valueAt(i));
    }
    // Walk through the start values, playing everything we find
    // Remove from the end set as we go
    ArrayList<TransitionValues> startValuesList = new ArrayList<>();
    ArrayList<TransitionValues> endValuesList = new ArrayList<>();
    for (View view : startValues.viewValues.keySet()) {
        TransitionValues start;
        TransitionValues end = null;
        boolean isInListView = false;
        if (view.getParent() instanceof ListView) {
            isInListView = true;
        }
        if (!isInListView) {
            int id = view.getId();
            start = startValues.viewValues.get(view) != null ? startValues.viewValues.get(view)
                    : startValues.idValues.get(id);
            if (endValues.viewValues.get(view) != null) {
                end = endValues.viewValues.get(view);
                endCopy.remove(view);
            } else if (id != View.NO_ID) {
                end = endValues.idValues.get(id);
                View removeView = null;
                for (View viewToRemove : endCopy.keySet()) {
                    if (viewToRemove.getId() == id) {
                        removeView = viewToRemove;
                    }
                }
                if (removeView != null) {
                    endCopy.remove(removeView);
                }
            }
            endIdCopy.remove(id);
            if (isValidTarget(view, id)) {
                startValuesList.add(start);
                endValuesList.add(end);
            }
        } else {
            ListView parent = (ListView) view.getParent();
            if (parent.getAdapter().hasStableIds()) {
                int position = parent.getPositionForView(view);
                long itemId = parent.getItemIdAtPosition(position);
                start = startValues.itemIdValues.get(itemId);
                endItemIdCopy.remove(itemId);
                // TODO: deal with targetIDs for itemIDs for ListView items
                startValuesList.add(start);
                endValuesList.add(end);
            }
        }
    }
    int startItemIdCopySize = startValues.itemIdValues.size();
    for (int i = 0; i < startItemIdCopySize; ++i) {
        long id = startValues.itemIdValues.keyAt(i);
        if (isValidTarget(null, id)) {
            TransitionValues start = startValues.itemIdValues.get(id);
            TransitionValues end = endValues.itemIdValues.get(id);
            endItemIdCopy.remove(id);
            startValuesList.add(start);
            endValuesList.add(end);
        }
    }
    // Now walk through the remains of the end set
    for (View view : endCopy.keySet()) {
        int id = view.getId();
        if (isValidTarget(view, id)) {
            TransitionValues start = startValues.viewValues.get(view) != null ? startValues.viewValues.get(view)
                    : startValues.idValues.get(id);
            TransitionValues end = endCopy.get(view);
            endIdCopy.remove(id);
            startValuesList.add(start);
            endValuesList.add(end);
        }
    }
    int endIdCopySize = endIdCopy.size();
    for (int i = 0; i < endIdCopySize; ++i) {
        int id = endIdCopy.keyAt(i);
        if (isValidTarget(null, id)) {
            TransitionValues start = startValues.idValues.get(id);
            TransitionValues end = endIdCopy.get(id);
            startValuesList.add(start);
            endValuesList.add(end);
        }
    }
    int endItemIdCopySize = endItemIdCopy.size();
    for (int i = 0; i < endItemIdCopySize; ++i) {
        long id = endItemIdCopy.keyAt(i);
        // TODO: Deal with targetIDs and itemIDs
        TransitionValues start = startValues.itemIdValues.get(id);
        TransitionValues end = endItemIdCopy.get(id);
        startValuesList.add(start);
        endValuesList.add(end);
    }
    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    for (int i = 0; i < startValuesList.size(); ++i) {
        TransitionValues start = startValuesList.get(i);
        TransitionValues end = endValuesList.get(i);
        // Only bother trying to animate with values that differ between start/end
        if (start != null || end != null) {
            if (start == null || !start.equals(end)) {
                if (DBG) {
                    View view = (end != null) ? end.view : start.view;
                    Log.d(LOG_TAG, "  differing start/end values for view " + view);
                    if (start == null || end == null) {
                        Log.d(LOG_TAG, "    "
                                + ((start == null) ? "start null, end non-null" : "start non-null, end null"));
                    } else {
                        for (String key : start.values.keySet()) {
                            Object startValue = start.values.get(key);
                            Object endValue = end.values.get(key);
                            if (startValue != endValue && !startValue.equals(endValue)) {
                                Log.d(LOG_TAG,
                                        "    " + key + ": start(" + startValue + "), end(" + endValue + ")");
                            }
                        }
                    }
                }
                // TODO: what to do about targetIds and itemIds?
                Animator animator = createAnimator(sceneRoot, start, end);
                if (animator != null) {
                    // Save animation info for future cancellation purposes
                    View view;
                    TransitionValues infoValues = null;
                    if (end != null) {
                        view = end.view;
                        String[] properties = getTransitionProperties();
                        if (view != null && properties != null && properties.length > 0) {
                            infoValues = new TransitionValues();
                            infoValues.view = view;
                            TransitionValues newValues = endValues.viewValues.get(view);
                            if (newValues != null) {
                                for (int j = 0; j < properties.length; ++j) {
                                    infoValues.values.put(properties[j], newValues.values.get(properties[j]));
                                }
                            }
                            int numExistingAnims = runningAnimators.size();
                            for (int j = 0; j < numExistingAnims; ++j) {
                                Animator anim = runningAnimators.keyAt(j);
                                AnimationInfo info = runningAnimators.get(anim);
                                if (info.values != null && info.view == view
                                        && ((info.name == null && getName() == null)
                                                || info.name.equals(getName()))) {
                                    if (info.values.equals(infoValues)) {
                                        // Favor the old animator
                                        animator = null;
                                        break;
                                    }
                                }
                            }
                        }
                    } else {
                        view = start.view;
                    }
                    if (animator != null) {
                        AnimationInfo info = new AnimationInfo(view, getName(),
                                WindowIdPort.getWindowId(sceneRoot), infoValues);
                        runningAnimators.put(animator, info);
                        mAnimators.add(animator);
                    }
                }
            }
        }
    }
}

From source file:android.support.transition.Transition.java

/**
 * This method, essentially a wrapper around all calls to createAnimator for all
 * possible target views, is called with the entire set of start/end
 * values. The implementation in Transition iterates through these lists
 * and calls {@link #createAnimator(android.view.ViewGroup, android.support.transition.TransitionValues, android.support.transition.TransitionValues)}
 * with each set of start/end values on this transition. The
 * TransitionSet subclass overrides this method and delegates it to
 * each of its children in succession./*w w  w  .  j a  v  a  2 s  . c  o m*/
 *
 * @hide
 */
protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues,
        TransitionValuesMaps endValues) {
    if (DBG) {
        Log.d(LOG_TAG, "createAnimators() for " + this);
    }
    ArrayMap<View, TransitionValues> endCopy = new ArrayMap<View, TransitionValues>(endValues.viewValues);
    SparseArray<TransitionValues> endIdCopy = new SparseArray<TransitionValues>(endValues.idValues.size());
    for (int i = 0; i < endValues.idValues.size(); ++i) {
        int id = endValues.idValues.keyAt(i);
        endIdCopy.put(id, endValues.idValues.valueAt(i));
    }
    LongSparseArray<TransitionValues> endItemIdCopy = new LongSparseArray<TransitionValues>(
            endValues.itemIdValues.size());
    for (int i = 0; i < endValues.itemIdValues.size(); ++i) {
        long id = endValues.itemIdValues.keyAt(i);
        endItemIdCopy.put(id, endValues.itemIdValues.valueAt(i));
    }
    // Walk through the start values, playing everything we find
    // Remove from the end set as we go
    ArrayList<TransitionValues> startValuesList = new ArrayList<TransitionValues>();
    ArrayList<TransitionValues> endValuesList = new ArrayList<TransitionValues>();
    for (View view : startValues.viewValues.keySet()) {
        TransitionValues start = null;
        TransitionValues end = null;
        boolean isInListView = false;
        if (view.getParent() instanceof ListView) {
            isInListView = true;
        }
        if (!isInListView) {
            int id = view.getId();
            start = startValues.viewValues.get(view) != null ? startValues.viewValues.get(view)
                    : startValues.idValues.get(id);
            if (endValues.viewValues.get(view) != null) {
                end = endValues.viewValues.get(view);
                endCopy.remove(view);
            } else if (id != View.NO_ID) {
                end = endValues.idValues.get(id);
                View removeView = null;
                for (View viewToRemove : endCopy.keySet()) {
                    if (viewToRemove.getId() == id) {
                        removeView = viewToRemove;
                    }
                }
                if (removeView != null) {
                    endCopy.remove(removeView);
                }
            }
            endIdCopy.remove(id);
            if (isValidTarget(view, id)) {
                startValuesList.add(start);
                endValuesList.add(end);
            }
        } else {
            ListView parent = (ListView) view.getParent();
            if (parent.getAdapter().hasStableIds()) {
                int position = parent.getPositionForView(view);
                long itemId = parent.getItemIdAtPosition(position);
                start = startValues.itemIdValues.get(itemId);
                endItemIdCopy.remove(itemId);
                // TODO: deal with targetIDs for itemIDs for ListView items
                startValuesList.add(start);
                endValuesList.add(end);
            }
        }
    }
    int startItemIdCopySize = startValues.itemIdValues.size();
    for (int i = 0; i < startItemIdCopySize; ++i) {
        long id = startValues.itemIdValues.keyAt(i);
        if (isValidTarget(null, id)) {
            TransitionValues start = startValues.itemIdValues.get(id);
            TransitionValues end = endValues.itemIdValues.get(id);
            endItemIdCopy.remove(id);
            startValuesList.add(start);
            endValuesList.add(end);
        }
    }
    // Now walk through the remains of the end set
    for (View view : endCopy.keySet()) {
        int id = view.getId();
        if (isValidTarget(view, id)) {
            TransitionValues start = startValues.viewValues.get(view) != null ? startValues.viewValues.get(view)
                    : startValues.idValues.get(id);
            TransitionValues end = endCopy.get(view);
            endIdCopy.remove(id);
            startValuesList.add(start);
            endValuesList.add(end);
        }
    }
    int endIdCopySize = endIdCopy.size();
    for (int i = 0; i < endIdCopySize; ++i) {
        int id = endIdCopy.keyAt(i);
        if (isValidTarget(null, id)) {
            TransitionValues start = startValues.idValues.get(id);
            TransitionValues end = endIdCopy.get(id);
            startValuesList.add(start);
            endValuesList.add(end);
        }
    }
    int endItemIdCopySize = endItemIdCopy.size();
    for (int i = 0; i < endItemIdCopySize; ++i) {
        long id = endItemIdCopy.keyAt(i);
        // TODO: Deal with targetIDs and itemIDs
        TransitionValues start = startValues.itemIdValues.get(id);
        TransitionValues end = endItemIdCopy.get(id);
        startValuesList.add(start);
        endValuesList.add(end);
    }
    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    for (int i = 0; i < startValuesList.size(); ++i) {
        TransitionValues start = startValuesList.get(i);
        TransitionValues end = endValuesList.get(i);
        // Only bother trying to animate with values that differ between start/end
        if (start != null || end != null) {
            if (start == null || !start.equals(end)) {
                if (DBG) {
                    View view = (end != null) ? end.view : start.view;
                    Log.d(LOG_TAG, "  differing start/end values for view " + view);
                    if (start == null || end == null) {
                        Log.d(LOG_TAG, "    "
                                + ((start == null) ? "start null, end non-null" : "start non-null, end null"));
                    } else {
                        for (String key : start.values.keySet()) {
                            Object startValue = start.values.get(key);
                            Object endValue = end.values.get(key);
                            if (startValue != endValue && !startValue.equals(endValue)) {
                                Log.d(LOG_TAG,
                                        "    " + key + ": start(" + startValue + "), end(" + endValue + ")");
                            }
                        }
                    }
                }
                // TODO: what to do about targetIds and itemIds?
                Animator animator = createAnimator(sceneRoot, start, end);
                if (animator != null) {
                    // Save animation info for future cancellation purposes
                    View view = null;
                    TransitionValues infoValues = null;
                    if (end != null) {
                        view = end.view;
                        String[] properties = getTransitionProperties();
                        if (view != null && properties != null && properties.length > 0) {
                            infoValues = new TransitionValues();
                            infoValues.view = view;
                            TransitionValues newValues = endValues.viewValues.get(view);
                            if (newValues != null) {
                                for (int j = 0; j < properties.length; ++j) {
                                    infoValues.values.put(properties[j], newValues.values.get(properties[j]));
                                }
                            }
                            int numExistingAnims = runningAnimators.size();
                            for (int j = 0; j < numExistingAnims; ++j) {
                                Animator anim = runningAnimators.keyAt(j);
                                AnimationInfo info = runningAnimators.get(anim);
                                if (info.values != null && info.view == view
                                        && ((info.name == null && getName() == null)
                                                || info.name.equals(getName()))) {
                                    if (info.values.equals(infoValues)) {
                                        // Favor the old animator
                                        animator = null;
                                        break;
                                    }
                                }
                            }
                        }
                    } else {
                        view = (start != null) ? start.view : null;
                    }
                    if (animator != null) {
                        AnimationInfo info = new AnimationInfo(view, getName(), infoValues);
                        runningAnimators.put(animator, info);
                        mAnimators.add(animator);
                    }
                }
            }
        }
    }
}