@Override public int getIndexOfPeriod(Object uid) { return uid instanceof Integer ? idsToIndex.get((int) uid, C.INDEX_UNSET) : C.INDEX_UNSET; }
/** * Called by CREATOR. */ private SavedState(Parcel in) { super(in); prevFirstVisiblePosition = in.readInt(); prevFirstVisibleChildHeight = in.readInt(); prevScrolledChildrenHeight = in.readInt(); prevScrollY = in.readInt(); scrollY = in.readInt(); childrenHeights = new SparseIntArray(); final int numOfChildren = in.readInt(); if (0 < numOfChildren) { for (int i = 0; i < numOfChildren; i++) { final int key = in.readInt(); final int value = in.readInt(); childrenHeights.put(key, value); } } }
/** Notify the {@link OnLoadCompleteListener}, if present, that the given resource was loaded. */ public void notifyResourceLoaded(int resId, boolean success) { boolean soundIsKnown = false; for (int resIdx = 0; resIdx < idToRes.size(); ++resIdx) { if (idToRes.valueAt(resIdx) == resId) { if (listener != null) { listener.onLoadComplete(realObject, idToRes.keyAt(resIdx), success ? 0 : 1); } soundIsKnown = true; } } if (!soundIsKnown) { throw new IllegalArgumentException("Unknown sound. You need to call load() first"); } }
private boolean idIsForResource(int soundId, int resId) { return idToRes.indexOfKey(soundId) >= 0 && idToRes.get(soundId) == resId; }
private void incrementExpandMapAfter(int position, int direction) { SparseIntArray newExpandMap = new SparseIntArray(); for (int i=0; i<expandMap.size(); i++) { int index = expandMap.keyAt(i); newExpandMap.put(index < position ? index : index + direction, 1); } expandMap = newExpandMap; }
int internalFacing = INTERNAL_FACINGS.get(mFacing); final String[] ids = mCameraManager.getCameraIdList(); if (ids.length == 0) { // No camera throw new NullPointerException("Unexpected state: LENS_FACING null"); for (int i = 0, count = INTERNAL_FACINGS.size(); i < count; i++) { if (INTERNAL_FACINGS.valueAt(i) == internal) { mFacing = INTERNAL_FACINGS.keyAt(i); return true;
public void testListViewSavedState() throws Throwable { Parcel parcel = Parcel.obtain(); ObservableListView.SavedState state1 = new ObservableListView.SavedState(AbsSavedState.EMPTY_STATE); state1.prevFirstVisiblePosition = 1; state1.prevFirstVisibleChildHeight = 2; state1.prevScrolledChildrenHeight = 3; state1.prevScrollY = 4; state1.scrollY = 5; state1.childrenHeights = new SparseIntArray(); state1.childrenHeights.put(0, 10); state1.childrenHeights.put(1, 20); state1.childrenHeights.put(2, 30); state1.writeToParcel(parcel, 0); parcel.setDataPosition(0); ObservableListView.SavedState state2 = ObservableListView.SavedState.CREATOR.createFromParcel(parcel); assertNotNull(state2); assertEquals(state1.prevFirstVisiblePosition, state2.prevFirstVisiblePosition); assertEquals(state1.prevFirstVisibleChildHeight, state2.prevFirstVisibleChildHeight); assertEquals(state1.prevScrolledChildrenHeight, state2.prevScrolledChildrenHeight); assertEquals(state1.prevScrollY, state2.prevScrollY); assertEquals(state1.scrollY, state2.scrollY); assertNotNull(state1.childrenHeights); assertEquals(3, state1.childrenHeights.size()); assertEquals(10, state1.childrenHeights.get(0)); assertEquals(20, state1.childrenHeights.get(1)); assertEquals(30, state1.childrenHeights.get(2)); }
/** * Returns the number of children of a given type {@code this} component has and then increments * it by 1. * * @param component the child component * @return the number of children of {@param component} type */ private int getChildCountAndIncrement(Component component) { if (mChildCounters == null) { mChildCounters = new SparseIntArray(); } final int typeId = component.getTypeId(); final int count = mChildCounters.get(typeId, 0); mChildCounters.put(typeId, count + 1); return count; }
/** * Add item height at position if doesn't already exist. */ public void add(int position, int height) { int currHeight = mMap.get(position, -1); if (currHeight != height) { if (currHeight == -1) { if (mMap.size() == mMaxSize) { // remove oldest entry mMap.delete(mOrder.remove(0)); } } else { // move position to newest slot mOrder.remove((Integer) position); } mMap.put(position, height); mOrder.add(position); } }
private void layoutByCoords() { final int count = Math.min(getChildCount(), cardsXCoords.size()); for (int i = 0; i < count; i++) { final View view = getChildAt(i); final int viewLeft = cardsXCoords.get(getPosition(view)); layoutDecorated(view, viewLeft, 0, viewLeft + cardWidth, getDecoratedBottom(view)); } cardsXCoords.clear(); }
int firstVisiblePosition = getFirstVisiblePosition(); for (int i = getFirstVisiblePosition(), j = 0; i <= getLastVisiblePosition(); i++, j++) { if (mChildrenHeights.indexOfKey(i) < 0 || getChildAt(j).getHeight() != mChildrenHeights.get(i)) { if (i % getNumColumnsCompat() == 0) { mChildrenHeights.put(i, getChildAt(j).getHeight()); if (firstVisiblePosition - mPrevFirstVisiblePosition != 1) { for (int i = firstVisiblePosition - 1; i > mPrevFirstVisiblePosition; i--) { if (0 < mChildrenHeights.indexOfKey(i)) { skippedChildrenHeight += mChildrenHeights.get(i); if (mPrevFirstVisiblePosition - firstVisiblePosition != 1) { for (int i = mPrevFirstVisiblePosition - 1; i > firstVisiblePosition; i--) { if (0 < mChildrenHeights.indexOfKey(i)) { skippedChildrenHeight += mChildrenHeights.get(i);
public static boolean isPortAvailable(int port) { boolean available = true; int available_code = mOpenPorts.get(port); if (available_code != 0) return available_code != 1; try { // attempt 3 times since proxy and server could be still releasing // their ports for (int i = 0; i < 3; i++) { Socket channel = new Socket(); InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(mNetwork.getLocalAddressAsString()), port); channel.connect(address, 200); available = !channel.isConnected(); channel.close(); if (available) break; Thread.sleep(200); } } catch (Exception e) { available = true; } mOpenPorts.put(port, available ? 2 : 1); return available; }
public int wrapItemViewType(int segment, int viewType) { final int packedSegments = (segment << 16) | ItemViewTypeComposer.extractSegmentPart(viewType); final int flattenSegments; final int index = mWrapSegmentMap.indexOfKey(packedSegments); if (index >= 0) { flattenSegments = mWrapSegmentMap.valueAt(index); } else { flattenSegments = mWrapSegmentMap.size() + 1; if (flattenSegments > ItemViewTypeComposer.MAX_SEGMENT) { throw new IllegalStateException("Failed to allocate a new wrapped view type."); } mWrapSegmentMap.put(packedSegments, flattenSegments); mUnwrapSegmentMap.put(flattenSegments, packedSegments); } return ItemViewTypeComposer.composeSegment(flattenSegments, viewType); }
/** Set the sim state for the given {@code slotIndex}. */ public void setSimState(int slotIndex, int state) { simStates.put(slotIndex, state); }
public PmtReader(int pid) { pmtScratch = new ParsableBitArray(new byte[5]); trackIdToReaderScratch = new SparseArray<>(); trackIdToPidScratch = new SparseIntArray(); this.pid = pid; }
/** * Records information about grouping in the list. * Should be called by the overridden {@link #addGroups} method. */ public void addGroup(int cursorPosition, int groupSize) { int lastIndex = mGroupMetadata.size() - 1; if (lastIndex < 0 || cursorPosition <= mGroupMetadata.keyAt(lastIndex)) { mGroupMetadata.put(cursorPosition, groupSize); } else { // Optimization to avoid binary search if adding groups in ascending cursor position. mGroupMetadata.append(cursorPosition, groupSize); } }