下面列出了android.util.SparseIntArray#delete ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private boolean updateFirewallUidRuleLocked(int chain, int uid, int rule) {
synchronized (mRulesLock) {
SparseIntArray uidFirewallRules = getUidFirewallRulesLR(chain);
final int oldUidFirewallRule = uidFirewallRules.get(uid, FIREWALL_RULE_DEFAULT);
if (DBG) {
Slog.d(TAG, "oldRule = " + oldUidFirewallRule
+ ", newRule=" + rule + " for uid=" + uid + " on chain " + chain);
}
if (oldUidFirewallRule == rule) {
if (DBG) Slog.d(TAG, "!!!!! Skipping change");
// TODO: eventually consider throwing
return false;
}
String ruleName = getFirewallRuleName(chain, rule);
String oldRuleName = getFirewallRuleName(chain, oldUidFirewallRule);
if (rule == NetworkPolicyManager.FIREWALL_RULE_DEFAULT) {
uidFirewallRules.delete(uid);
} else {
uidFirewallRules.put(uid, rule);
}
return !ruleName.equals(oldRuleName);
}
}
private static void resetSlotForKeyLocked(int key, SparseIntArray keyToIndexMap,
MemoryIntArray backingStore) throws IOException {
final int index = keyToIndexMap.get(key, -1);
if (index >= 0) {
keyToIndexMap.delete(key);
backingStore.set(index, 0);
if (DEBUG) {
Slog.i(LOG_TAG, "Freed index:" + index + " for key:"
+ SettingsProvider.keyToString(key));
}
}
}
private void findLocations(Mat searchMat)
{
_locationValues.clear();
SparseIntArray areas = new SparseIntArray(4);
for(int i = 0; i < NUM_CODES; i++)
{
Mat mask = new Mat();
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
if(i == 2)
{
// combine the two ranges for red
Core.inRange(searchMat, LOWER_RED1, UPPER_RED1, mask);
Mat rmask2 = new Mat();
Core.inRange(searchMat, LOWER_RED2, UPPER_RED2, rmask2);
Core.bitwise_or(mask, rmask2, mask);
}
else
Core.inRange(searchMat, COLOR_BOUNDS[i][0], COLOR_BOUNDS[i][1], mask);
Imgproc.findContours(mask, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
for (int contIdx = 0; contIdx < contours.size(); contIdx++)
{
int area;
if ((area = (int)Imgproc.contourArea(contours.get(contIdx))) > 20)
{
Moments M = Imgproc.moments(contours.get(contIdx));
int cx = (int) (M.get_m10() / M.get_m00());
// if a colour band is split into multiple contours
// we take the largest and consider only its centroid
boolean shouldStoreLocation = true;
for(int locIdx = 0; locIdx < _locationValues.size(); locIdx++)
{
if(Math.abs(_locationValues.keyAt(locIdx) - cx) < 10)
{
if (areas.get(_locationValues.keyAt(locIdx)) > area)
{
shouldStoreLocation = false;
break;
}
else
{
_locationValues.delete(_locationValues.keyAt(locIdx));
areas.delete(_locationValues.keyAt(locIdx));
}
}
}
if(shouldStoreLocation)
{
areas.put(cx, area);
_locationValues.put(cx, i);
}
}
}
}
}