Java Code Examples for android.support.v4.util.LongSparseArray#size()

The following examples show how to use android.support.v4.util.LongSparseArray#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbsHListView.java    From Klyph with MIT License 6 votes vote down vote up
/**
 * Returns the set of checked items ids. The result is only valid if the choice mode has not been set to
 * {@link #CHOICE_MODE_NONE} and the adapter has stable IDs. ({@link ListAdapter#hasStableIds()} == {@code true})
 * 
 * @return A new array which contains the id of each checked item in the list.
 */
public long[] getCheckedItemIds() {
	if ( mChoiceMode == ListView.CHOICE_MODE_NONE || mCheckedIdStates == null || mAdapter == null ) {
		return new long[0];
	}

	final LongSparseArray<Integer> idStates = mCheckedIdStates;
	final int count = idStates.size();
	final long[] ids = new long[count];

	for ( int i = 0; i < count; i++ ) {
		ids[i] = idStates.keyAt( i );
	}

	return ids;
}
 
Example 2
Source File: Transition.java    From Transitions-Everywhere with Apache License 2.0 6 votes vote down vote up
/**
 * Match start/end values by Adapter item ID. Adds matched values to mStartValuesList
 * and mEndValuesList and removes them from unmatchedStart and unmatchedEnd, using
 * startItemIds and endItemIds as a guide for which Views have unique item IDs.
 */
private void matchItemIds(@NonNull ArrayMap<View, TransitionValues> unmatchedStart,
                          @NonNull ArrayMap<View, TransitionValues> unmatchedEnd,
                          @NonNull LongSparseArray<View> startItemIds,
                          @NonNull LongSparseArray<View> endItemIds) {
    int numStartIds = startItemIds.size();
    for (int i = 0; i < numStartIds; i++) {
        View startView = startItemIds.valueAt(i);
        if (startView != null && isValidTarget(startView)) {
            View endView = endItemIds.get(startItemIds.keyAt(i));
            if (endView != null && isValidTarget(endView)) {
                TransitionValues startValues = unmatchedStart.get(startView);
                TransitionValues endValues = unmatchedEnd.get(endView);
                if (startValues != null && endValues != null) {
                    mStartValuesList.add(startValues);
                    mEndValuesList.add(endValues);
                    unmatchedStart.remove(startView);
                    unmatchedEnd.remove(endView);
                }
            }
        }
    }
}
 
Example 3
Source File: CompositionLayer.java    From atlas with Apache License 2.0 5 votes vote down vote up
CompositionLayer(LottieDrawable lottieDrawable, Layer layerModel, List<Layer> layerModels,
    LottieComposition composition) {
  super(lottieDrawable, layerModel);

  LongSparseArray<BaseLayer> layerMap =
      new LongSparseArray<>(composition.getLayers().size());

  BaseLayer mattedLayer = null;
  for (int i = layerModels.size() - 1; i >= 0; i--) {
    Layer lm = layerModels.get(i);
    BaseLayer layer = BaseLayer.forModel(lm, lottieDrawable, composition);
    layerMap.put(layer.getLayerModel().getId(), layer);
    if (mattedLayer != null) {
      mattedLayer.setMatteLayer(layer);
      mattedLayer = null;
    } else {
      layers.add(0, layer);
      switch (lm.getMatteType()) {
        case Add:
        case Invert:
          mattedLayer = layer;
          break;
      }
    }
  }

  for (int i = 0; i < layerMap.size(); i++) {
    long key = layerMap.keyAt(i);
    BaseLayer layerView = layerMap.get(key);
    BaseLayer parentLayer = layerMap.get(layerView.getLayerModel().getParentId());
    if (parentLayer != null) {
      layerView.setParentLayer(parentLayer);
    }
  }
}
 
Example 4
Source File: AbsHListView.java    From letv with Apache License 2.0 5 votes vote down vote up
public long[] getCheckedItemIds() {
    if (this.mChoiceMode == 0 || this.mCheckedIdStates == null || this.mAdapter == null) {
        return new long[0];
    }
    LongSparseArray<Integer> idStates = this.mCheckedIdStates;
    int count = idStates.size();
    long[] ids = new long[count];
    for (int i = 0; i < count; i++) {
        ids[i] = idStates.keyAt(i);
    }
    return ids;
}
 
Example 5
Source File: SparseArrayUtils.java    From standardlib with Apache License 2.0 5 votes vote down vote up
public static <T> List<T> asList(LongSparseArray<T> sparseArray) {
    if (sparseArray == null) {
        return null;
    }

    ArrayList<T> list = new ArrayList<>(sparseArray.size());
    for (int i = 0; i < sparseArray.size(); i++) {
        list.add(sparseArray.valueAt(i));
    }
    return list;
}
 
Example 6
Source File: ObjectUtils.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
public static boolean isEmpty(final LongSparseArray obj) {
    return obj == null || obj.size() == 0;
}