Java Code Examples for android.util.SparseIntArray#delete()

The following examples show how to use android.util.SparseIntArray#delete() . 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: NetworkManagementService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: GenerationRegistry.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
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));
        }
    }
}
 
Example 3
Source File: ResistorImageProcessor.java    From ResistorScanner with MIT License 4 votes vote down vote up
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);
                }
            }
        }
    }
}