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

The following examples show how to use android.util.SparseArray#indexOfKey() . 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: DefaultTrackSelector.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private static boolean areSelectionOverridesEqual(
    SparseArray<Map<TrackGroupArray, @NullableType SelectionOverride>> first,
    SparseArray<Map<TrackGroupArray, @NullableType SelectionOverride>> second) {
  int firstSize = first.size();
  if (second.size() != firstSize) {
    return false;
  }
  for (int indexInFirst = 0; indexInFirst < firstSize; indexInFirst++) {
    int indexInSecond = second.indexOfKey(first.keyAt(indexInFirst));
    if (indexInSecond < 0
        || !areSelectionOverridesEqual(
            first.valueAt(indexInFirst), second.valueAt(indexInSecond))) {
      return false;
    }
  }
  return true;
}
 
Example 2
Source File: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private static boolean areSelectionOverridesEqual(
    SparseArray<Map<TrackGroupArray, SelectionOverride>> first,
    SparseArray<Map<TrackGroupArray, SelectionOverride>> second) {
  int firstSize = first.size();
  if (second.size() != firstSize) {
    return false;
  }
  for (int indexInFirst = 0; indexInFirst < firstSize; indexInFirst++) {
    int indexInSecond = second.indexOfKey(first.keyAt(indexInFirst));
    if (indexInSecond < 0
        || !areSelectionOverridesEqual(
            first.valueAt(indexInFirst), second.valueAt(indexInSecond))) {
      return false;
    }
  }
  return true;
}
 
Example 3
Source File: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private static boolean areSelectionOverridesEqual(
    SparseArray<Map<TrackGroupArray, SelectionOverride>> first,
    SparseArray<Map<TrackGroupArray, SelectionOverride>> second) {
  int firstSize = first.size();
  if (second.size() != firstSize) {
    return false;
  }
  for (int indexInFirst = 0; indexInFirst < firstSize; indexInFirst++) {
    int indexInSecond = second.indexOfKey(first.keyAt(indexInFirst));
    if (indexInSecond < 0
        || !areSelectionOverridesEqual(
            first.valueAt(indexInFirst), second.valueAt(indexInSecond))) {
      return false;
    }
  }
  return true;
}
 
Example 4
Source File: MilStdIconRenderer.java    From mil-sym-android with Apache License 2.0 6 votes vote down vote up
private ImageInfo renderTacticalMultipointIcon(String symbolID, SparseArray<String> attributes)
{
    Color lineColor = SymbolUtilities.getLineColorOfAffiliation(symbolID);
    if (attributes.indexOfKey(MilStdAttributes.LineColor) >= 0) {
        lineColor = new Color(attributes.get(MilStdAttributes.LineColor));
    }
    int size = RendererSettings.getInstance().getDefaultPixelSize();// 35;
    if (attributes.indexOfKey(MilStdAttributes.PixelSize) >= 0) {
        size = Integer.parseInt(attributes.get(MilStdAttributes.PixelSize));
    }

    int symStd = RendererSettings.getInstance().getSymbologyStandard();
    if (attributes.indexOfKey(MilStdAttributes.SymbologyStandard) >= 0) {
        symStd = Integer.parseInt(attributes.get(MilStdAttributes.SymbologyStandard));
    }

    ImageInfo ii = TacticalGraphicIconRenderer.getIcon(symbolID, size, lineColor, symStd);
    return ii;
}
 
Example 5
Source File: DefaultTrackSelector.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private static boolean areSelectionOverridesEqual(
    SparseArray<Map<TrackGroupArray, SelectionOverride>> first,
    SparseArray<Map<TrackGroupArray, SelectionOverride>> second) {
  int firstSize = first.size();
  if (second.size() != firstSize) {
    return false;
  }
  for (int indexInFirst = 0; indexInFirst < firstSize; indexInFirst++) {
    int indexInSecond = second.indexOfKey(first.keyAt(indexInFirst));
    if (indexInSecond < 0
        || !areSelectionOverridesEqual(
            first.valueAt(indexInFirst), second.valueAt(indexInSecond))) {
      return false;
    }
  }
  return true;
}
 
Example 6
Source File: AddContentApi.java    From ankihelper with GNU General Public License v3.0 5 votes vote down vote up
/** Add a NoteInfo object to the given duplicates SparseArray at the specified position */
protected void addNoteToDuplicatesArray(NoteInfo note, SparseArray<List<NoteInfo>> duplicates, int position) {
    int sparseArrayIndex = duplicates.indexOfKey(position);
    if (sparseArrayIndex < 0) {
        // No existing NoteInfo objects mapping to same key as the current note so add a new List
        List<NoteInfo> duplicatesForKey = new ArrayList<>();
        duplicatesForKey.add(note);
        duplicates.put(position, duplicatesForKey);
    } else { // Append note to existing list of duplicates for key
        duplicates.valueAt(sparseArrayIndex).add(note);
    }
}
 
Example 7
Source File: StorageDelegate.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Update tab entries based on metadata.
 * @param metadataBytes Metadata from last time Chrome was alive.
 * @param entryMap Map to fill with {@link DocumentTabModel.Entry}s about Tabs.
 * @param recentlyClosedTabIdList List to fill with IDs of recently closed tabs.
 */
private void updateTabEntriesFromMetadata(byte[] metadataBytes, SparseArray<Entry> entryMap,
        List<Integer> recentlyClosedTabIdList) {
    if (metadataBytes != null) {
        DocumentList list = null;
        try {
            list = MessageNano.mergeFrom(new DocumentList(), metadataBytes);
        } catch (IOException e) {
            Log.e(TAG, "I/O exception", e);
        }
        if (list == null) return;

        for (int i = 0; i < list.entries.length; i++) {
            DocumentEntry savedEntry = list.entries[i];
            int tabId = savedEntry.tabId;

            // If the tab ID isn't in the list, it must have been closed after Chrome died.
            if (entryMap.indexOfKey(tabId) < 0) {
                recentlyClosedTabIdList.add(tabId);
                continue;
            }

            // Restore information about the Tab.
            entryMap.get(tabId).canGoBack = savedEntry.canGoBack;
        }
    }
}
 
Example 8
Source File: StorageDelegate.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Update tab entries based on metadata.
 * @param metadataBytes Metadata from last time Chrome was alive.
 * @param entryMap Map to fill with {@link DocumentTabModel.Entry}s about Tabs.
 * @param recentlyClosedTabIdList List to fill with IDs of recently closed tabs.
 */
private void updateTabEntriesFromMetadata(byte[] metadataBytes, SparseArray<Entry> entryMap,
        List<Integer> recentlyClosedTabIdList) {
    if (metadataBytes != null) {
        DocumentList list = null;
        try {
            list = MessageNano.mergeFrom(new DocumentList(), metadataBytes);
        } catch (IOException e) {
            Log.e(TAG, "I/O exception", e);
        }
        if (list == null) return;

        for (int i = 0; i < list.entries.length; i++) {
            DocumentEntry savedEntry = list.entries[i];
            int tabId = savedEntry.tabId;

            // If the tab ID isn't in the list, it must have been closed after Chrome died.
            if (entryMap.indexOfKey(tabId) < 0) {
                recentlyClosedTabIdList.add(tabId);
                continue;
            }

            // Restore information about the Tab.
            entryMap.get(tabId).canGoBack = savedEntry.canGoBack;
        }
    }
}
 
Example 9
Source File: StorageDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Update tab entries based on metadata.
 * @param metadataBytes Metadata from last time Chrome was alive.
 * @param entryMap Map to fill with {@link DocumentTabModel.Entry}s about Tabs.
 * @param recentlyClosedTabIdList List to fill with IDs of recently closed tabs.
 */
private void updateTabEntriesFromMetadata(byte[] metadataBytes, SparseArray<Entry> entryMap,
        List<Integer> recentlyClosedTabIdList) {
    if (metadataBytes != null) {
        DocumentList list = null;
        try {
            list = MessageNano.mergeFrom(new DocumentList(), metadataBytes);
        } catch (IOException e) {
            Log.e(TAG, "I/O exception", e);
        }
        if (list == null) return;

        for (int i = 0; i < list.entries.length; i++) {
            DocumentEntry savedEntry = list.entries[i];
            int tabId = savedEntry.tabId;

            // If the tab ID isn't in the list, it must have been closed after Chrome died.
            if (entryMap.indexOfKey(tabId) < 0) {
                recentlyClosedTabIdList.add(tabId);
                continue;
            }

            // Restore information about the Tab.
            entryMap.get(tabId).canGoBack = savedEntry.canGoBack;
        }
    }
}
 
Example 10
Source File: DefaultTrackSelector.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static boolean areSelectionOverridesEqual(
    SparseArray<Map<TrackGroupArray, SelectionOverride>> first,
    SparseArray<Map<TrackGroupArray, SelectionOverride>> second) {
  int firstSize = first.size();
  if (second.size() != firstSize) {
    return false;
  }
  for (int indexInFirst = 0; indexInFirst < firstSize; indexInFirst++) {
    int indexInSecond = second.indexOfKey(first.keyAt(indexInFirst));
    if (indexInSecond < 0
        || !areSelectionOverridesEqual(
            first.valueAt(indexInFirst), second.valueAt(indexInSecond))) {
      return false;
    }
  }
  return true;
}
 
Example 11
Source File: JavaRendererUtilities.java    From mil-sym-android with Apache License 2.0 4 votes vote down vote up
/**
 * Checks symbolID and if the relevant modifiers are present
 *
 * @param symbolCode
 * @param modifiers
 * @return
 */
public static boolean is3dSymbol(String symbolCode, SparseArray<String> modifiers) {
    boolean returnValue = false;

    try {
        String symbolId = symbolCode.substring(4, 10);

        if (symbolId.equals("ACAI--") || // Airspace Coordination Area Irregular
                symbolId.equals("ACAR--") || // Airspace Coordination Area Rectangular
                symbolId.equals("ACAC--") || // Airspace Coordination Area Circular
                symbolId.equals("AKPC--") || // Kill box circular
                symbolId.equals("AKPR--") || // Kill box rectangular
                symbolId.equals("AKPI--") || // Kill box irregular
                symbolId.equals("ALC---") || // Air corridor
                symbolId.equals("ALM---") || // 
                symbolId.equals("ALS---") || // SAAFR
                symbolId.equals("ALU---") || // UAV
                symbolId.equals("ALL---") || // Low level transit route
                symbolId.equals("AAR---")
                || symbolId.equals("AAF---")
                || symbolId.equals("AAH---")
                || symbolId.equals("AAM---") || // MEZ
                symbolId.equals("AAML--") || // LOMEZ
                symbolId.equals("AAMH--")) {

            try {
                if (modifiers != null) {

                    // These guys store array values.  Put in appropriate data strucutre
                    // for MilStdSymbol.
                    if (modifiers.indexOfKey(ModifiersTG.X_ALTITUDE_DEPTH) >= 0) {
                        String[] altitudes = modifiers.get(ModifiersTG.X_ALTITUDE_DEPTH).split(",");
                        if (altitudes.length < 2) {
                            returnValue = false;
                        } else {
                            returnValue = true;
                        }
                    }

                }
            } catch (Exception exc) {
                System.err.println(exc.getMessage());
            }
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    return returnValue;
}
 
Example 12
Source File: ModifierRenderer.java    From mil-sym-android with Apache License 2.0 4 votes vote down vote up
public static boolean hasDisplayModifiers(String symbolID, SparseArray<String> modifiers)
{
    boolean hasModifiers = false;
    char scheme = symbolID.charAt(0);
    char status = symbolID.charAt(3);
    char affiliation = symbolID.charAt(1);
    if (scheme != 'W')
    {
        if (scheme != 'G' && (SymbolUtilities.isEMSNaturalEvent(symbolID) == false))
        {
            switch (status)
            {
                case 'C':
                case 'D':
                case 'X':
                case 'F':
                    hasModifiers = true;

                default:
                    break;
            }

            if ((symbolID.substring(10, 12).equals("--") == false && symbolID.substring(10, 12).equals("**") == false) || modifiers.indexOfKey(ModifiersUnits.Q_DIRECTION_OF_MOVEMENT) >= 0)
            {
                hasModifiers = true;
            }

            if(SymbolUtilities.isHQ(symbolID))
                hasModifiers = true;
        }
        else
        {
            if (SymbolUtilities.isNBC(symbolID) == true && modifiers.indexOfKey(ModifiersTG.Q_DIRECTION_OF_MOVEMENT) >= 0)
            {
                hasModifiers = true;
            }
        }

    }

    return hasModifiers;
}
 
Example 13
Source File: ModifierRenderer.java    From mil-sym-android with Apache License 2.0 4 votes vote down vote up
public static boolean hasTextModifiers(String symbolID, SparseArray<String> modifiers, SparseArray<String> attributes)
{

    int symStd = RS.getSymbologyStandard();
    if (attributes.indexOfKey(MilStdAttributes.SymbologyStandard) >= 0)
    {
        symStd = Integer.parseInt(attributes.get(MilStdAttributes.SymbologyStandard));
    }
    char scheme = symbolID.charAt(0);
    if(scheme == 'W')
    {
        if(symbolID.equals("WAS-WSF-LVP----") || //freezing level
                symbolID.equals("WAS-PHT---P----") || //tropopause high
                symbolID.equals("WAS-PLT---P----") || //tropopause low
                symbolID.equals("WAS-WST-LVP----")) ////tropopause level
            return true;
        else
            return false;
    }
    if (scheme == 'G')
    {
        String basic = SymbolUtilities.getBasicSymbolIDStrict(symbolID);
        SymbolDef sd = SymbolDefTable.getInstance().getSymbolDef(basic, symStd);
        String expr = "\\.";
        String mods[] = sd.getModifiers().split(expr);

        for(int lcv = 0; lcv < mods.length; lcv++)
        {
            if(modifiers.indexOfKey(ModifiersTG.getModifierKey(mods[lcv])) >= 0)
                return true;
        }
        return false;
    }
    else if (SymbolUtilities.isEMSNaturalEvent(symbolID) == false)
    {

        if (SymbolUtilities.getUnitAffiliationModifier(symbolID, symStd) != null)
        {
            return true;
        }

        if (SymbolUtilities.hasValidCountryCode(symbolID))
        {
            return true;
        }

        if (SymbolUtilities.isEMSNaturalEvent(symbolID))
        {
            return false;
        }

        if (modifiers.indexOfKey(ModifiersUnits.Q_DIRECTION_OF_MOVEMENT) >= 0)
        {
            if (modifiers.size() > 1)
            {
                return true;
            }
        }
        else if (modifiers.size() > 0)
        {
            return true;
        }
    }
    return false;
}
 
Example 14
Source File: MilStdIconRenderer.java    From mil-sym-android with Apache License 2.0 4 votes vote down vote up
public Boolean CanRender(String symbolID, SparseArray<String> modifiers, SparseArray<String> attributes)
{

    String message = null;
    String basicSymbolID = symbolID;
    basicSymbolID = SymbolUtilities.getBasicSymbolID(basicSymbolID);
    // ErrorLogger.LogMessage("TEST");

    int symStd = -1;
    String temp;
    if (attributes.indexOfKey(MilStdAttributes.SymbologyStandard) >= 0) {
        temp = attributes.get(MilStdAttributes.SymbologyStandard);
        if (SymbolUtilities.isNumber(temp)) {
            symStd = Integer.parseInt(temp);
        }
    }

    if (symStd < 0 || symStd > RendererSettings.Symbology_2525C) {
        symStd = RendererSettings.getInstance().getSymbologyStandard();
    }

    try {
        // message = "Cannot draw: " + symbolCode + " (" + basicSymbolID + ")";
        SymbolDefTable sdt = SymbolDefTable.getInstance();
        if (SymbolUtilities.isTacticalGraphic(basicSymbolID)) {

            SymbolDef sd = sdt.getSymbolDef(basicSymbolID, symStd);
            if (sd != null) {

                if (sd.getDrawCategory() == 8)// make sure we can find the character in the font.
                {
                    int index = -1;
                    index = SinglePointLookup.getInstance().getCharCodeFromSymbol(symbolID, symStd);
                    if (index > 0) {
                        return true;
                    } else {
                        message = "Bad font lookup for: " + symbolID + " (" + basicSymbolID + ")";
                    }
                } else // check with icon renderer for multipoints
                {
                    message = "Cannot draw: " + symbolID + " (" + basicSymbolID + ")";
                }

            } else {
                message = "Cannot draw symbolID: " + symbolID + " (" + basicSymbolID + ")";
            }
        } else {
            UnitDef ud = UnitDefTable.getInstance().getUnitDef(basicSymbolID, symStd);
            // UnitFontLookupInfo ufli = UnitFontLookup.getInstance().getLookupInfo(basicSymbolID,symStd);
            if (ud != null) {
                return true;
            } else {
                message = "JavaRenderer.CanRender() - Cannot draw symbolID: " + symbolID + " ("
                        + basicSymbolID + ")";
            }
        }

        if (message != null && !message.equals("")) {
            ErrorLogger.LogMessage(this.getClass().getName(), "CanRender()", message, Level.FINE);
            // System.err.println(message);
            // System.out.println("");
            // System.out.println("INFO: CanRender - " + message);
            // Exception foo = new Exception("Stack?");
            // foo.printStackTrace();
        }
    } catch (Exception exc) {
        ErrorLogger.LogException("MilStdIconRenderer", "CanRender", exc);
    }
    return false;
}
 
Example 15
Source File: MilStdIconRenderer.java    From mil-sym-android with Apache License 2.0 4 votes vote down vote up
public ImageInfo RenderIcon(String symbolID, SparseArray<String> modifiers,
        SparseArray<String> attributes)
{

    int symStd = 1;

    if (attributes != null && attributes.indexOfKey(MilStdAttributes.SymbologyStandard) >= 0) {
        symStd = Integer.parseInt(attributes.get(MilStdAttributes.SymbologyStandard));
    }

    ImageInfo temp = null;
    if (SymbolUtilities.isTacticalGraphic(symbolID)) {
        String basicSymbolID = SymbolUtilities.getBasicSymbolIDStrict(symbolID);
        SymbolDef sd = SymbolDefTable.getInstance().getSymbolDef(basicSymbolID, symStd);
        if (sd == null) {
            symbolID = SymbolUtilities.reconcileSymbolID(symbolID);
            basicSymbolID = SymbolUtilities.getBasicSymbolIDStrict(symbolID);
            sd = SymbolDefTable.getInstance().getSymbolDef(basicSymbolID, symStd);
        }

        if (sd != null) {
            if (sd.getDrawCategory() == SymbolDef.DRAW_CATEGORY_POINT) {
                temp = _SPR.RenderSP(symbolID, modifiers, attributes);
            } else {
                return renderTacticalMultipointIcon(symbolID, attributes);
            }
        } else {
            temp = _SPR.RenderUnit(symbolID, modifiers, attributes);
        }

    } else {
        temp = _SPR.RenderUnit(symbolID, modifiers, attributes);
        /*
         * if(RendererSettings.getInstance().getIconEngine() == RendererSettings.IconEngine_FONT) { temp =
         * _SPR.RenderUnit(symbolID, modifiers, attributes); } else { temp = _SPSVGR.RenderUnit(symbolID,
         * modifiers,attributes); }//
         */

    }

    return temp;
}