Java Code Examples for androidx.collection.LongSparseArray#size()

The following examples show how to use androidx.collection.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: Profile.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
private String getValuesList(LongSparseArray<Double> array, LongSparseArray<Double> array2, DecimalFormat format, String units) {
    String retValue = "";

    for (Integer index = 0; index < array.size(); index++) {
        retValue += format_HH_MM((int) array.keyAt(index));
        retValue += "    ";
        retValue += format.format(array.valueAt(index));
        if (array2 != null) {
            retValue += " - ";
            retValue += format.format(array2.valueAt(index));
        }
        retValue += " " + units;
        if (index + 1 < array.size())
            retValue += "\n";
    }
    return retValue;
}
 
Example 2
Source File: MountStateRemountTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemountSameLayoutState() {
  final TestComponent component1 = create(mContext).build();
  final TestComponent component2 = create(mContext).build();
  final TestComponent component3 = create(mContext).build();
  final TestComponent component4 = create(mContext).build();

  final LithoView lithoView =
      mountComponent(
          mContext, Column.create(mContext).child(component1).child(component2).build());

  assertThat(component1.isMounted()).isTrue();
  assertThat(component2.isMounted()).isTrue();

  mountComponent(
      mContext, lithoView, Column.create(mContext).child(component3).child(component4).build());

  assertThat(component1.isMounted()).isTrue();
  assertThat(component2.isMounted()).isTrue();
  assertThat(component3.isMounted()).isFalse();
  assertThat(component4.isMounted()).isFalse();

  final MountState mountState = getInternalState(lithoView, "mMountState");
  final LongSparseArray<MountItem> indexToItemMap =
      getInternalState(mountState, "mIndexToItemMap");

  final List<Component> components = new ArrayList<>();
  for (int i = 0; i < indexToItemMap.size(); i++) {
    components.add(getLayoutOutput(indexToItemMap.valueAt(i)).getComponent());
  }

  assertThat(containsRef(components, component1)).isFalse();
  assertThat(containsRef(components, component2)).isFalse();
  assertThat(containsRef(components, component3)).isTrue();
  assertThat(containsRef(components, component4)).isTrue();
}
 
Example 3
Source File: Profile.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private void validate(LongSparseArray array) {
    if (array.size() == 0) {
        isValid = false;
        return;
    }
    for (int index = 0; index < array.size(); index++) {
        if (array.valueAt(index).equals(0d)) {
            isValid = false;
            return;
        }
    }
}
 
Example 4
Source File: Profile.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private double getValueToTime(LongSparseArray<Double> array, Integer timeAsSeconds) {
    Double lastValue = null;

    for (Integer index = 0; index < array.size(); index++) {
        long tas = array.keyAt(index);
        double value = array.valueAt(index);
        if (lastValue == null) lastValue = value;
        if (timeAsSeconds < tas) {
            break;
        }
        lastValue = value;
    }
    return lastValue;
}
 
Example 5
Source File: CompositionLayer.java    From lottie-android with Apache License 2.0 4 votes vote down vote up
public CompositionLayer(LottieDrawable lottieDrawable, Layer layerModel, List<Layer> layerModels,
    LottieComposition composition) {
  super(lottieDrawable, layerModel);

  AnimatableFloatValue timeRemapping = layerModel.getTimeRemapping();
  if (timeRemapping != null) {
    this.timeRemapping = timeRemapping.createAnimation();
    addAnimation(this.timeRemapping);
    //noinspection ConstantConditions
    this.timeRemapping.addUpdateListener(this);
  } else {
    this.timeRemapping = null;
  }

  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);
    if (layer == null) {
      continue;
    }
    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);
    // This shouldn't happen but it appears as if sometimes on pre-lollipop devices when
    // compiled with d8, layerView is null sometimes.
    // https://github.com/airbnb/lottie-android/issues/524
    if (layerView == null) {
      continue;
    }
    BaseLayer parentLayer = layerMap.get(layerView.getLayerModel().getParentId());
    if (parentLayer != null) {
      layerView.setParentLayer(parentLayer);
    }
  }
}