Java Code Examples for android.util.SparseArray#valueAt()

The following examples show how to use android.util.SparseArray#valueAt() . 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: RecycleBin.java    From AutoScrollViewPager with Apache License 2.0 6 votes vote down vote up
static View retrieveFromScrap(SparseArray<View> scrapViews, int position) {
  int size = scrapViews.size();
  if (size > 0) {
    // See if we still have a view for this position.
    for (int i = 0; i < size; i++) {
      int fromPosition = scrapViews.keyAt(i);
      View view = scrapViews.get(fromPosition);
      if (fromPosition == position) {
        scrapViews.remove(fromPosition);
        return view;
      }
    }
    int index = size - 1;
    View r = scrapViews.valueAt(index);
    scrapViews.remove(scrapViews.keyAt(index));
    return r;
  } else {
    return null;
  }
}
 
Example 2
Source File: FragmentedMp4Extractor.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link TrackBundle} whose fragment run has the earliest file position out of those
 * yet to be consumed, or null if all have been consumed.
 */
private static TrackBundle getNextFragmentRun(SparseArray<TrackBundle> trackBundles) {
  TrackBundle nextTrackBundle = null;
  long nextTrackRunOffset = Long.MAX_VALUE;

  int trackBundlesSize = trackBundles.size();
  for (int i = 0; i < trackBundlesSize; i++) {
    TrackBundle trackBundle = trackBundles.valueAt(i);
    if (trackBundle.currentTrackRunIndex == trackBundle.fragment.trunCount) {
      // This track fragment contains no more runs in the next mdat box.
    } else {
      long trunOffset = trackBundle.fragment.trunDataPosition[trackBundle.currentTrackRunIndex];
      if (trunOffset < nextTrackRunOffset) {
        nextTrackBundle = trackBundle;
        nextTrackRunOffset = trunOffset;
      }
    }
  }
  return nextTrackBundle;
}
 
Example 3
Source File: RecycleBin.java    From COCOFramework with Apache License 2.0 6 votes vote down vote up
static View retrieveFromScrap(SparseArray<View> scrapViews, int position) {
    int size = scrapViews.size();
    if (size > 0) {
        // See if we still have a view for this position.
        for (int i = 0; i < size; i++) {
            int fromPosition = scrapViews.keyAt(i);
            View view = scrapViews.get(fromPosition);
            if (fromPosition == position) {
                scrapViews.remove(fromPosition);
                return view;
            }
        }
        int index = size - 1;
        View r = scrapViews.valueAt(index);
        scrapViews.remove(scrapViews.keyAt(index));
        return r;
    } else {
        return null;
    }
}
 
Example 4
Source File: RecycleBin.java    From SprintNBA with Apache License 2.0 6 votes vote down vote up
static View retrieveFromScrap(SparseArray<View> scrapViews, int position) {
	int size = scrapViews.size();
	if (size > 0) {
		// See if we still have a view for this position.
		for (int i = 0; i < size; i++) {
			int fromPosition = scrapViews.keyAt(i);
			View view = scrapViews.get(fromPosition);
			if (fromPosition == position) {
				scrapViews.remove(fromPosition);
				return view;
			}
		}
		int index = size - 1;
		View r = scrapViews.valueAt(index);
		scrapViews.remove(scrapViews.keyAt(index));
		return r;
	} else {
		return null;
	}
}
 
Example 5
Source File: PaycheckFragment.java    From budget-envelopes with GNU General Public License v3.0 6 votes vote down vote up
private void recalcProgress() {
    mIncomeValue = mIncome.getCents();
    SparseArray<Long> deposites = mEnvelopes.getDeposites();
    int l = deposites.size();
    mSpentValue = 0;
    for (int i = 0; i != l; ++i) {
        mSpentValue += deposites.valueAt(i);
    }
    if (mIncomeValue != 0 && mSpentValue != 0) {
        double progress = ((double)mSpentValue)/mIncomeValue;
        mProgress.setProgress((int)(progress*100000));
        mProgress.setIndeterminate(mIncomeValue < mSpentValue);
    } else {
        mProgress.setProgress(0);
    }
    mProgress.setMax(100000);
    mSpent.setText(EditMoney.toMoney(mSpentValue));
    getActivity().invalidateOptionsMenu();
}
 
Example 6
Source File: Recycler.java    From android-FlipView with Apache License 2.0 6 votes vote down vote up
static Scrap retrieveFromScrap(SparseArray<Scrap> scrapViews, int position) {
	int size = scrapViews.size();
	if (size > 0) {
		// See if we still have a view for this position.
		Scrap result = scrapViews.get(position, null);
		if (result != null) {
			scrapViews.remove(position);
			return result;
		}
		int index = size - 1;
		result = scrapViews.valueAt(index);
		scrapViews.removeAt(index);
		result.valid = false;
		return result;
	}
	return null;
}
 
Example 7
Source File: RecycleBin.java    From tubatu-viewpager with Apache License 2.0 6 votes vote down vote up
static View retrieveFromScrap(SparseArray<View> scrapViews, int position) {
    int size = scrapViews.size();
    if (size > 0) {
        // See if we still have a view for this position.
        for (int i = 0; i < size; i++) {
            int fromPosition = scrapViews.keyAt(i);
            View view = scrapViews.get(fromPosition);
            if (fromPosition == position) {
                scrapViews.remove(fromPosition);
                return view;
            }
        }
        int index = size - 1;
        View r = scrapViews.valueAt(index);
        scrapViews.remove(scrapViews.keyAt(index));
        return r;
    } else {
        return null;
    }
}
 
Example 8
Source File: DynamicPropsManager.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
public void onValueChange(DynamicValue value) {
  final Set<Component> dependentComponents = mDependentComponents.get(value);

  for (Component component : dependentComponents) {
    final Object content = mContents.get(component);

    if (hasCommonDynamicPropsToBind(component)) {
      final SparseArray<DynamicValue<?>> commonDynamicProps = component.getCommonDynamicProps();

      for (int i = 0; i < commonDynamicProps.size(); i++) {
        if (commonDynamicProps.valueAt(i) == value) {
          bindCommonDynamicProp(commonDynamicProps.keyAt(i), value, (View) content);
        }
      }
    }

    final DynamicValue[] dynamicProps = component.getDynamicProps();
    for (int i = 0; i < dynamicProps.length; i++) {
      if (value == dynamicProps[i]) {
        component.bindDynamicProp(i, value.get(), content);
      }
    }
  }
}
 
Example 9
Source File: DefaultTrackSelector.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static void writeSelectionOverridesToParcel(
    Parcel dest, SparseArray<Map<TrackGroupArray, SelectionOverride>> selectionOverrides) {
  int renderersWithOverridesCount = selectionOverrides.size();
  dest.writeInt(renderersWithOverridesCount);
  for (int i = 0; i < renderersWithOverridesCount; i++) {
    int rendererIndex = selectionOverrides.keyAt(i);
    Map<TrackGroupArray, SelectionOverride> overrides = selectionOverrides.valueAt(i);
    int overrideCount = overrides.size();
    dest.writeInt(rendererIndex);
    dest.writeInt(overrideCount);
    for (Map.Entry<TrackGroupArray, SelectionOverride> override : overrides.entrySet()) {
      dest.writeParcelable(override.getKey(), /* parcelableFlags= */ 0);
      dest.writeParcelable(override.getValue(), /* parcelableFlags= */ 0);
    }
  }
}
 
Example 10
Source File: CPUFragment.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 6 votes vote down vote up
private void refreshCores(SparseArray<SwitchView> array, int[] freqs) {
    for (int i = 0; i < array.size(); i++) {
        SwitchView switchView = array.valueAt(i);
        if (switchView != null) {
            final int core = array.keyAt(i);
            int freq = freqs[core];

            String freqText = freq == 0 ? getString(R.string.offline) : (freq / 1000)
                    + getString(R.string.mhz);
            switchView.clearOnSwitchListener();
            switchView.setChecked(freq != 0);
            switchView.setSummary(getString(R.string.core, core + 1) + " - " + freqText);
            switchView.addOnSwitchListener((switchView1, isChecked) -> {
                if (core == 0) {
                    Utils.toast(R.string.no_offline_core, getActivity());
                } else {
                    mCPUFreq.onlineCpu(core, isChecked, true, getActivity());
                }
            });
        }
    }
}
 
Example 11
Source File: IcsAbsSpinner.java    From Libraries-for-Android-Developers with MIT License 5 votes vote down vote up
void clear() {
    final SparseArray<View> scrapHeap = mScrapHeap;
    final int count = scrapHeap.size();
    for (int i = 0; i < count; i++) {
        final View view = scrapHeap.valueAt(i);
        if (view != null) {
            removeDetachedView(view, true);
        }
    }
    scrapHeap.clear();
}
 
Example 12
Source File: OcrDetectorProcessor.java    From OCR-Reader with MIT License 5 votes vote down vote up
/**
 * Called by the detector to deliver detection results.
 * If your application called for it, this could be a place to check for
 * equivalent detections by tracking TextBlocks that are similar in location and content from
 * previous frames, or reduce noise by eliminating TextBlocks that have not persisted through
 * multiple detections.
 */
@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
    mGraphicOverlay.clear();
    SparseArray<TextBlock> items = detections.getDetectedItems();
    for (int i = 0; i < items.size(); ++i) {
        TextBlock item = items.valueAt(i);
        OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item);
        mGraphicOverlay.add(graphic);
    }
}
 
Example 13
Source File: MediaPlayer.java    From Vitamio with Apache License 2.0 5 votes vote down vote up
private void selectOrDeselectBandTrack(int index, boolean select) {
	if (mOutOfBandTracks != null) {
		SparseArray<MediaFormat> mediaSparse = mOutOfBandTracks.getTrackInfoArray();
		int trackIndex = mediaSparse.keyAt(0);
		MediaFormat mediaFormat = mediaSparse.valueAt(0);
  	if (index == trackIndex  && select) {
  		addTimedTextSource(mediaFormat.getString(MediaFormat.KEY_PATH));
  		return;
  	}
	}
	selectOrDeselectTrack(index, select);
}
 
Example 14
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static @Nullable TrackBundle getTrackBundle(
    SparseArray<TrackBundle> trackBundles, int trackId) {
  if (trackBundles.size() == 1) {
    // Ignore track id if there is only one track. This is either because we have a side-loaded
    // track (flag FLAG_SIDELOADED) or to cope with non-matching track indices (see
    // https://github.com/google/ExoPlayer/issues/4083).
    return trackBundles.valueAt(/* index= */ 0);
  }
  return trackBundles.get(trackId);
}
 
Example 15
Source File: USBMonitor.java    From AndroidUSBCamera with Apache License 2.0 5 votes vote down vote up
/**
 * Close device
 * This also close interfaces if they are opened in Java side
 */
public synchronized void close() {
	if (DEBUG) Log.i(TAG, "UsbControlBlock#close:");

	if (mConnection != null) {
		final int n = mInterfaces.size();
		for (int i = 0; i < n; i++) {
			final SparseArray<UsbInterface> intfs = mInterfaces.valueAt(i);
			if (intfs != null) {
				final int m = intfs.size();
				for (int j = 0; j < m; j++) {
					final UsbInterface intf = intfs.valueAt(j);
					mConnection.releaseInterface(intf);
				}
				intfs.clear();
			}
		}
		mInterfaces.clear();
		mConnection.close();
		mConnection = null;
		final USBMonitor monitor = mWeakMonitor.get();
		if (monitor != null) {
			if (monitor.mOnDeviceConnectListener != null) {
				monitor.mOnDeviceConnectListener.onDisconnect(mWeakDevice.get(), UsbControlBlock.this);
			}
			monitor.mCtrlBlocks.remove(getDevice());
		}
	}
}
 
Example 16
Source File: CompatForWebViewFactoryApi21.java    From Android-Plugin-Framework with MIT License 5 votes vote down vote up
private static boolean isAdded(SparseArray<String> packageIdentifiers, String packageName) {
    if (packageIdentifiers != null) {
        for (int i = 0; i < packageIdentifiers.size(); i++) {
            final String name = packageIdentifiers.valueAt(i);
            if (packageName.equals(name)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 17
Source File: MediaPlayer.java    From MyHearts with Apache License 2.0 5 votes vote down vote up
private void selectOrDeselectBandTrack(int index, boolean select) {
	if (mOutOfBandTracks != null) {
		SparseArray<MediaFormat> mediaSparse = mOutOfBandTracks.getTrackInfoArray();
		int trackIndex = mediaSparse.keyAt(0);
		MediaFormat mediaFormat = mediaSparse.valueAt(0);
  	if (index == trackIndex  && select) {
  		addTimedTextSource(mediaFormat.getString(MediaFormat.KEY_PATH));
  		return;
  	}
	}
	selectOrDeselectTrack(index, select);
}
 
Example 18
Source File: Recycler.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
void invalidateScraps() {
	for (SparseArray<Scrap> array : scraps) {
		for (int i = 0; i < array.size(); i++) {
			array.valueAt(i).valid = false;
		}
	}
}
 
Example 19
Source File: TopBottomLocationManager.java    From Shield with MIT License 5 votes vote down vote up
public void setBottomNodeList(SparseArray<ShieldDisplayNode> bottomNodeList) {
    this.bottomNodeList.clear();
    for (int i = 0; i < bottomNodeList.size(); i++) {
        if (bottomNodeList.valueAt(i) != null) {
            this.bottomNodeList.put(bottomNodeList.keyAt(i), bottomNodeList.valueAt(i));
        }
    }

    requestUpdate();
}
 
Example 20
Source File: IcsAbsSpinner.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
void clear() {
    final SparseArray<View> scrapHeap = mScrapHeap;
    final int count = scrapHeap.size();
    for (int i = 0; i < count; i++) {
        final View view = scrapHeap.valueAt(i);
        if (view != null) {
            removeDetachedView(view, true);
        }
    }
    scrapHeap.clear();
}