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

The following examples show how to use android.util.SparseArray#remove() . 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 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 2
Source File: Recycler.java    From UltimateAndroid 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 3
Source File: UltimateRecyclerviewViewHolder.java    From UltimateRecyclerView with Apache License 2.0 6 votes vote down vote up
private View retrieveFromCache(int parentId, int id) {
    SparseArray<View> sparseArrayViewsParent = mSparseSparseArrayView.get(parentId);
    if (sparseArrayViewsParent != null) {
        View viewRetrieve = sparseArrayViewsParent.get(id);
        if (viewRetrieve == null) {
            // dead reference
            sparseArrayViewsParent.remove(id);
        } else {
            return viewRetrieve;
        }
    }
    if (parentId == 0) {
        return retrieveFromCache(id);
    } else {
        return null;
    }
}
 
Example 4
Source File: RecycleBin.java    From salvage 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: Recycler.java    From AndroidAnimationExercise 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 6
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 7
Source File: RecycleBin.java    From Noyze 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: RecycleBin.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * Makes sure that the size of scrapViews does not exceed the size of activeViews.
 * (This can happen if an adapter does not recycle its views).
 */
private void pruneScrapViews() {
    final int maxViews = activeViews.length;
    final int viewTypeCount = this.viewTypeCount;
    final SparseArray<View>[] scrapViews = this.scrapViews;
    for (int i = 0; i < viewTypeCount; ++i) {
        final SparseArray<View> scrapPile = scrapViews[i];
        int size = scrapPile.size();
        final int extras = size - maxViews;
        size--;
        for (int j = 0; j < extras; j++) {
            scrapPile.remove(scrapPile.keyAt(size--));
        }
    }
}
 
Example 9
Source File: ChatUsersActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void removeParticipants(int userId) {
    boolean updated = false;
    for (int a = 0; a < 3; a++) {
        SparseArray<TLObject> map;
        ArrayList<TLObject> arrayList;
        if (a == 0) {
            map = contactsMap;
            arrayList = contacts;
        } else if (a == 1) {
            map = botsMap;
            arrayList = bots;
        } else {
            map = participantsMap;
            arrayList = participants;
        }
        TLObject p = map.get(userId);
        if (p != null) {
            map.remove(userId);
            arrayList.remove(p);
            updated = true;
        }
    }
    if (updated) {
        updateRows();
        listViewAdapter.notifyDataSetChanged();
    }
    if (listView.getAdapter() == searchListViewAdapter) {
        searchListViewAdapter.removeUserId(userId);
    }
}
 
Example 10
Source File: RecycleBin.java    From the-tech-frontier-app with MIT License 5 votes vote down vote up
/**
 * Makes sure that the size of scrapViews does not exceed the size of activeViews.
 * (This can happen if an adapter does not recycle its views).
 */
private void pruneScrapViews() {
  final int maxViews = activeViews.length;
  final int viewTypeCount = this.viewTypeCount;
  final SparseArray<View>[] scrapViews = this.scrapViews;
  for (int i = 0; i < viewTypeCount; ++i) {
    final SparseArray<View> scrapPile = scrapViews[i];
    int size = scrapPile.size();
    final int extras = size - maxViews;
    size--;
    for (int j = 0; j < extras; j++) {
      scrapPile.remove(scrapPile.keyAt(size--));
    }
  }
}
 
Example 11
Source File: WindowCache.java    From FloatUtil with MIT License 5 votes vote down vote up
/**
 * Remove the window corresponding to the id from the {@link #sWindows}
 * cache.
 * 
 * @param id
 *            The id representing the window.
 * @param cls
 *            The class of the implementation of the window.
 */
public void removeCache(int id, Class<? extends Context> cls) {
	SparseArray<Window> l2 = sWindows.get(cls);
	if (l2 != null) {
		l2.remove(id);
		if (l2.size() == 0) {
			sWindows.remove(cls);
		}
	}
}
 
Example 12
Source File: AppOpsService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void setAudioRestriction(int code, int usage, int uid, int mode,
        String[] exceptionPackages) {
    enforceManageAppOpsModes(Binder.getCallingPid(), Binder.getCallingUid(), uid);
    verifyIncomingUid(uid);
    verifyIncomingOp(code);
    synchronized (this) {
        SparseArray<Restriction> usageRestrictions = mAudioRestrictions.get(code);
        if (usageRestrictions == null) {
            usageRestrictions = new SparseArray<Restriction>();
            mAudioRestrictions.put(code, usageRestrictions);
        }
        usageRestrictions.remove(usage);
        if (mode != AppOpsManager.MODE_ALLOWED) {
            final Restriction r = new Restriction();
            r.mode = mode;
            if (exceptionPackages != null) {
                final int N = exceptionPackages.length;
                r.exceptionPackages = new ArraySet<String>(N);
                for (int i = 0; i < N; i++) {
                    final String pkg = exceptionPackages[i];
                    if (pkg != null) {
                        r.exceptionPackages.add(pkg.trim());
                    }
                }
            }
            usageRestrictions.put(usage, r);
        }
    }

    mHandler.sendMessage(PooledLambda.obtainMessage(
            AppOpsService::notifyWatchersOfChange, this, code, UID_ANY));
}
 
Example 13
Source File: TopBottomManager.java    From Shield with MIT License 5 votes vote down vote up
private void processBottomNode(SparseArray<TopBottomNodeInfo> lastBottomNodeList, SparseArray<TopBottomNodeInfo> newBottomArr, RecyclerView.LayoutManager layoutManager, int first, int last) {
    for (int i = 0; i < bottomNodeList.size(); i++) {
        ShieldDisplayNode node = bottomNodeList.valueAt(i);

        int pos = bottomNodeList.keyAt(i);

        if (node == null) {
            continue;
        }

        invalidateView(pos, node);

        if (node.view != null) {
            ViewGroup.LayoutParams lp = node.view.getLayoutParams();
            if (!(lp instanceof LinearLayout.LayoutParams)) {
                node.view.setLayoutParams(new LinearLayout.LayoutParams(lp.width, lp.height));
            }
        }
        TopBottomNodeInfo info = new TopBottomNodeInfo();
        info.position = pos;
        info.node = node;
        info.height = node.view.getMeasuredHeight();

        currentBottomNodeList.put(pos, info);
        lastBottomNodeList.remove(pos);
    }

}
 
Example 14
Source File: TopBottomManager.java    From Shield with MIT License 5 votes vote down vote up
private void processTopNode(SparseArray<TopBottomNodeInfo> lastTopNodeList, SparseArray<TopBottomNodeInfo> newTopArr, SparseArray<TopBottomNodeInfo> newEndingArr, RecyclerView.LayoutManager layoutManager, int first, int last) {
    for (int i = 0; i < topNodeList.size(); i++) {

        int pos = topNodeList.keyAt(i);

        ShieldDisplayNode node = topNodeList.valueAt(i);
        if (node == null) {
            continue;
        }

        InnerTopInfo innerTopInfo = node.innerTopInfo;
        if (innerTopInfo == null) {
            continue;
        }

        int line = innerTopInfo.offset;
        int startTop = getTopOrBottomPosition(TOP, layoutManager, innerTopInfo.startPos, first, last);
        int endBottom = getTopOrBottomPosition(BOTTOM, layoutManager, innerTopInfo.endPos, first, last);

        invalidateView(pos, node);

        TopBottomNodeInfo info = getTopNodeInfo(pos, node, line, endBottom);

        if (isTop(line, startTop, endBottom, node)) {
            if (isEnding(line, endBottom, info.height)) {
                if (info.state != TopState.ENDING) {
                    info.state = TopState.ENDING;
                    newEndingArr.put(pos, info);
                }
            } else {
                if (info.state != TopState.TOP) {
                    info.state = TopState.TOP;
                    newTopArr.put(pos, info);
                }
            }
            currentTopNodeList.put(pos, info);
            lastTopNodeList.remove(pos);
        }
    }
}
 
Example 15
Source File: CameraMetricsCollector.java    From Battery-Metrics with MIT License 5 votes vote down vote up
private static synchronized long stopRecord(int hash, SparseArray<Long> container) {
  long stopTimeMs = SystemClock.uptimeMillis();
  long totalTimeMs = 0;

  Long startTimeMs = container.get(hash);
  if (startTimeMs != null) {
    totalTimeMs = stopTimeMs - startTimeMs;
    container.remove(hash);
  } else {
    SystemMetricsLogger.wtf(
        TAG, "Stopped recording details for a camera that hasn't been added yet");
  }
  return totalTimeMs;
}
 
Example 16
Source File: Manager.java    From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * register a new device id or add feature to an already defined device
 * <p>the change will affect only the node discover after this call</p>
 * @param deviceId device type that will use the feature, it can be a new device id
 * @param features array of feature that we will add, the index of the feature will be used
 *                 as feature mask. the feature mask must have only one bit to 1
 * @throws InvalidFeatureBitMaskException throw when a feature is a position that is not a
 * power of 2
 */
public static void addFeatureToNode(byte deviceId,SparseArray<Class<? extends Feature>> features)
        throws InvalidFeatureBitMaskException {
    SparseArray<Class<? extends Feature>> updateMe;
    if(!sFeatureMapDecoder.containsKey(deviceId)){
        updateMe = BLENodeDefines.FeatureCharacteristics.DEFAULT_MASK_TO_FEATURE.clone();
        sFeatureMapDecoder.put(deviceId,updateMe);
    }else{
        updateMe = sFeatureMapDecoder.get(deviceId);
    }//if-else

    SparseArray<Class<? extends Feature>> addMe = features.clone();

    long mask=1;
    //we test all the 32bit of the feature mask
    for(int i=0; i<32; i++ ){
        Class<? extends Feature> featureClass = addMe.get((int)mask);
        if (featureClass != null) {
            updateMe.append((int) mask, featureClass);
            addMe.remove((int)mask);
        }
        mask=mask<<1;
    }//for

    if(addMe.size()!=0)
        throw new InvalidFeatureBitMaskException("Not all elements have a single bit in " +
                "as key");
}
 
Example 17
Source File: BackStackRecord.java    From letv with Apache License 2.0 5 votes vote down vote up
private void setLastIn(SparseArray<Fragment> firstOutFragments, SparseArray<Fragment> lastInFragments, Fragment fragment) {
    if (fragment != null) {
        int containerId = fragment.mContainerId;
        if (containerId != 0) {
            if (!fragment.isAdded()) {
                lastInFragments.put(containerId, fragment);
            }
            if (firstOutFragments.get(containerId) == fragment) {
                firstOutFragments.remove(containerId);
            }
        }
    }
}
 
Example 18
Source File: BackStackRecord.java    From letv with Apache License 2.0 5 votes vote down vote up
private static void setFirstOut(SparseArray<Fragment> firstOutFragments, SparseArray<Fragment> lastInFragments, Fragment fragment) {
    if (fragment != null) {
        int containerId = fragment.mContainerId;
        if (containerId != 0 && !fragment.isHidden()) {
            if (fragment.isAdded() && fragment.getView() != null && firstOutFragments.get(containerId) == null) {
                firstOutFragments.put(containerId, fragment);
            }
            if (lastInFragments.get(containerId) == fragment) {
                lastInFragments.remove(containerId);
            }
        }
    }
}
 
Example 19
Source File: RecycleBin.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * Makes sure that the size of scrapViews does not exceed the size of activeViews.
 * (This can happen if an adapter does not recycle its views).
 */
private void pruneScrapViews() {
    final int maxViews = activeViews.length;
    final int viewTypeCount = this.viewTypeCount;
    final SparseArray<View>[] scrapViews = this.scrapViews;
    for (int i = 0; i < viewTypeCount; ++i) {
        final SparseArray<View> scrapPile = scrapViews[i];
        int size = scrapPile.size();
        final int extras = size - maxViews;
        size--;
        for (int j = 0; j < extras; j++) {
            scrapPile.remove(scrapPile.keyAt(size--));
        }
    }
}
 
Example 20
Source File: EfficientCacheView.java    From EfficientAdapter with Apache License 2.0 3 votes vote down vote up
/**
 * Clear the cache for the view specify
 *
 * @param parentId the parent id of the view to remove (if the view was retrieve with this
 *                 parent id)
 * @param viewId   id of the view to remove from the cache
 */
public void clearViewCached(int parentId, int viewId) {
    SparseArray<View> sparseArrayViewsParent = mSparseSparseArrayView.get(parentId);
    if (sparseArrayViewsParent != null) {
        sparseArrayViewsParent.remove(viewId);
    }
}