Java Code Examples for android.util.SparseIntArray#get()
The following examples show how to use
android.util.SparseIntArray#get() .
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: AdUnitRelativeLayout.java From unity-ads-android with Apache License 2.0 | 6 votes |
public SparseArray<SparseArray<AdUnitMotionEvent>> getEvents(SparseArray<ArrayList<Integer>> requestedInfos) { SparseIntArray countTable = new SparseIntArray(); SparseArray<SparseArray<AdUnitMotionEvent>> returnData = new SparseArray<>(); synchronized (_motionEvents) { for (AdUnitMotionEvent currentEvent : _motionEvents) { ArrayList<Integer> currentRequestedInfos = requestedInfos.get(currentEvent.getAction()); if (currentRequestedInfos != null) { int currentRequestedInfoIndex = currentRequestedInfos.get(0); if (countTable.get(currentEvent.getAction(), 0) == currentRequestedInfoIndex) { if (returnData.get(currentEvent.getAction()) == null) { returnData.put(currentEvent.getAction(), new SparseArray<AdUnitMotionEvent>()); } returnData.get(currentEvent.getAction()).put(currentRequestedInfoIndex, currentEvent); currentRequestedInfos.remove(0); } countTable.put(currentEvent.getAction(), countTable.get(currentEvent.getAction()) + 1); } } } return returnData; }
Example 2
Source File: GenerationRegistry.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
private static int getKeyIndexLocked(int key, SparseIntArray keyToIndexMap, MemoryIntArray backingStore) throws IOException { int index = keyToIndexMap.get(key, -1); if (index < 0) { index = findNextEmptyIndex(backingStore); if (index >= 0) { backingStore.set(index, 1); keyToIndexMap.append(key, index); if (DEBUG) { Slog.i(LOG_TAG, "Allocated index:" + index + " for key:" + SettingsProvider.keyToString(key)); } } else { Slog.e(LOG_TAG, "Could not allocate generation index"); } } return index; }
Example 3
Source File: ExifInterface.java From Camera2 with Apache License 2.0 | 6 votes |
protected int[] getTagDefinitionsForTagId(short tagId) { int[] ifds = IfdData.getIfds(); int[] defs = new int[ifds.length]; int counter = 0; SparseIntArray infos = getTagInfo(); for (int i : ifds) { int def = defineTag(i, tagId); if (infos.get(def) != DEFINITION_NULL) { defs[counter++] = def; } } if (counter == 0) { return null; } return Arrays.copyOfRange(defs, 0, counter); }
Example 4
Source File: GenerationRegistry.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
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 5
Source File: SdlRouterServiceTests.java From sdl_java_suite with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test router service correctly picks up Hash ID from start service ACK (prior to V5) */ public void testStartSessionAckHashId() { if (Looper.myLooper() == null) { Looper.prepare(); } Method method; try { SdlRouterService sdlRouterService = new SdlRouterService(); initFields(sdlRouterService); addDummyRegisteredApp(sdlRouterService, "12345", sessionId); // create packet and invoke sendPacketToRegisteredApp int hashId = 0x123456; byte[] payload = new byte[]{0x00, 0x12, 0x34, 0x56}; SdlPacket packet = new SdlPacket(4, false, SdlPacket.FRAME_TYPE_CONTROL, SdlPacket.SERVICE_TYPE_RPC, SdlPacket.FRAME_INFO_START_SERVICE_ACK, sessionId, payload.length, 2, payload); packet.setTransportRecord(new TransportRecord(TransportType.BLUETOOTH,null)); method = sdlRouterService.getClass().getDeclaredMethod("sendPacketToRegisteredApp", SdlPacket.class); method.setAccessible(true); Boolean success = (Boolean) method.invoke(sdlRouterService, packet); Assert.assertTrue(success); // verify hash id map contains the correct ID Field field = sdlRouterService.getClass().getDeclaredField("sessionHashIdMap"); field.setAccessible(true); SparseIntArray sessionHashIdMap = (SparseIntArray)field.get(sdlRouterService); Assert.assertTrue(sessionHashIdMap.indexOfKey(sessionId) >= 0); int value = sessionHashIdMap.get(sessionId, -1); Assert.assertEquals(hashId, value); } catch (Exception e) { Assert.fail("Exception in sendPacketToRegisteredApp, " + e); } }
Example 6
Source File: ThemeAdapter.java From cannonball-android with Apache License 2.0 | 5 votes |
private void setUpItemsDrawableId(int[] itemsDrawableId, Theme[] objects) { final Random random = new Random(); int index = 0; for (Theme theme : objects) { final SparseIntArray drawables = theme.getImageList(); final int randomIndex = random.nextInt(drawables.size()) + 1; itemsDrawableId[index] = drawables.get(randomIndex); index++; } }
Example 7
Source File: BgdService2.java From Huochexing12306 with Apache License 2.0 | 5 votes |
private TargetInfo getTargetInfo(){ mBgdBInfo.setTrain_date(mCurrMInfo.getStart_time()); mBgdBInfo.setFrom_station(mCurrMInfo .getFrom_station_telecode()); mBgdBInfo.setTo_station(mCurrMInfo.getTo_station_telecode()); mBgdBInfo.setPurpose_codes(mCurrMInfo.getPurpose_codes()); A6Info<List<QueryLeftNewInfo>> a6Info = A6Util.queryTickets(mBgdBInfo); if (a6Info == null || a6Info.getData() == null){ return null; } for (QueryLeftNewInfo qlnInfo : a6Info.getDataObject()) { QueryLeftNewDTOInfo qlndInfo = qlnInfo .getQueryLeftNewDTO(); int trainIndex = mCurrMInfo.getLstTrainNames().indexOf(qlndInfo.getStation_train_code()); if (trainIndex != -1 && mCurrMInfo.getSelectedTrainsNames()[trainIndex]){ SeatHelper sHelper = new SeatHelper(qlndInfo); SparseIntArray saNums = sHelper .getSeatReferenceNums(); int num = mCurrMInfo.getLstPNativeIndexes().size(); for (int i = 0; i < mCurrMInfo.getLstSeatTypes() .size(); i++) { Integer seatType = mCurrMInfo.getLstSeatTypes() .get(i); Integer seatNum = saNums.get(seatType); if (seatNum != null && (seatNum >= num)) { TargetInfo tInfo = new TargetInfo(); tInfo.setQlnInfo(qlnInfo); tInfo.setSeatHelper(sHelper); tInfo.setSeatType(seatType); tInfo.setNum(num); return tInfo; } } } } return null; }
Example 8
Source File: TagColorUtil.java From DoraemonKit with Apache License 2.0 | 5 votes |
public static int getTextColor(Context context, int level, boolean expand) { SparseIntArray map = expand ? TEXT_COLOR_EXPAND : TEXT_COLOR; Integer result = map.get(level); if (result == null) { result = map.get(Log.VERBOSE); } return ContextCompat.getColor(context, result); }
Example 9
Source File: SearchActivity.java From Hentoid with Apache License 2.0 | 5 votes |
/** * Update the text of a given attribute type button based on the given SparseIntArray and relevant type(s) * * @param button Button whose text to update * @param attrCount Entry count in every attribute type (key = attribute type code; value = count) * @param types Type(s) to fetch the count for */ private void updateAttributeTypeButton(@NonNull final TextView button, @NonNull final SparseIntArray attrCount, AttributeType... types) { if (0 == types.length) return; int count = 0; for (AttributeType type : types) count += attrCount.get(type.getCode(), 0); button.setText(format("%s (%s)", Helper.capitalizeString(types[0].getDisplayName()), count)); button.setEnabled(count > 0); }
Example 10
Source File: ThemeAdapter.java From cannonball-android with Apache License 2.0 | 5 votes |
private void setUpItemsDrawableId(int[] itemsDrawableId, Theme[] objects) { final Random random = new Random(); int index = 0; for (Theme theme : objects) { final SparseIntArray drawables = theme.getImageList(); final int randomIndex = random.nextInt(drawables.size()) + 1; itemsDrawableId[index] = drawables.get(randomIndex); index++; } }
Example 11
Source File: NumberEffect.java From Android-RTEditor with Apache License 2.0 | 4 votes |
@Override public synchronized void applyToSelection(RTEditText editor, Selection selectedParagraphs, Boolean enable) { final Spannable str = editor.getText(); mSpans2Process.clear(); int lineNr = 1; SparseIntArray indentations = new SparseIntArray(); SparseIntArray numbers = new SparseIntArray(); // a manual for loop is faster than the for-each loop for an ArrayList: // see https://developer.android.com/training/articles/perf-tips.html#Loops ArrayList<Paragraph> paragraphs = editor.getParagraphs(); for (int i = 0, size = paragraphs.size(); i < size; i++) { Paragraph paragraph = paragraphs.get(i); /* * We need to know the indentation for each paragraph to be able * to determine which paragraphs belong together (same indentation) */ int currentIndentation = 0; List<RTSpan<Integer>> indentationSpans = Effects.INDENTATION.getSpans(str, paragraph, SpanCollectMode.EXACT); if (! indentationSpans.isEmpty()) { for (RTSpan<Integer> span : indentationSpans) { currentIndentation += span.getValue(); } } indentations.put(lineNr, currentIndentation); // find existing NumberSpans and add them to mSpans2Process to be removed List<RTSpan<Boolean>> existingSpans = getSpans(str, paragraph, SpanCollectMode.SPAN_FLAGS); mSpans2Process.removeSpans(existingSpans, paragraph); /* * If the paragraph is selected then we sure have a number */ boolean hasExistingSpans = ! existingSpans.isEmpty(); boolean hasNumber = paragraph.isSelected(selectedParagraphs) ? enable : hasExistingSpans; /* * If we have a number then apply a new span */ if (hasNumber) { // let's determine the number for this paragraph int nr = 1; for (int line = 1; line < lineNr; line++) { int indentation = indentations.get(line); int number = numbers.get(line); if (indentation < currentIndentation) { // 1) less indentation -> number 1 nr = 1; } else if (indentation == currentIndentation) { // 2) same indentation + no numbering -> number 1 // 3) same indentation + numbering -> increment number nr = number == 0 ? 1 : number + 1; } } numbers.put(lineNr, nr); int margin = Helper.getLeadingMarging(); NumberSpan numberSpan = new NumberSpan(nr++, margin, paragraph.isEmpty(), paragraph.isFirst(), paragraph.isLast()); mSpans2Process.addSpan(numberSpan, paragraph); // if the paragraph has bullet spans, then remove them Effects.BULLET.findSpans2Remove(str, paragraph, mSpans2Process); } lineNr++; } // add or remove spans mSpans2Process.process(str); }
Example 12
Source File: BorderUtil.java From ucar-weex-core with Apache License 2.0 | 4 votes |
static int fetchFromSparseArray(@Nullable SparseIntArray array, int position, int fallback) { return array == null ? fallback : array.get(position, array.get(Spacing.ALL)); }
Example 13
Source File: DashMediaPeriod.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private static int[][] getGroupedAdaptationSetIndices(List<AdaptationSet> adaptationSets) { int adaptationSetCount = adaptationSets.size(); SparseIntArray idToIndexMap = new SparseIntArray(adaptationSetCount); for (int i = 0; i < adaptationSetCount; i++) { idToIndexMap.put(adaptationSets.get(i).id, i); } int[][] groupedAdaptationSetIndices = new int[adaptationSetCount][]; boolean[] adaptationSetUsedFlags = new boolean[adaptationSetCount]; int groupCount = 0; for (int i = 0; i < adaptationSetCount; i++) { if (adaptationSetUsedFlags[i]) { // This adaptation set has already been included in a group. continue; } adaptationSetUsedFlags[i] = true; Descriptor adaptationSetSwitchingProperty = findAdaptationSetSwitchingProperty( adaptationSets.get(i).supplementalProperties); if (adaptationSetSwitchingProperty == null) { groupedAdaptationSetIndices[groupCount++] = new int[] {i}; } else { String[] extraAdaptationSetIds = Util.split(adaptationSetSwitchingProperty.value, ","); int[] adaptationSetIndices = new int[1 + extraAdaptationSetIds.length]; adaptationSetIndices[0] = i; int outputIndex = 1; for (int j = 0; j < extraAdaptationSetIds.length; j++) { int extraIndex = idToIndexMap.get( Integer.parseInt(extraAdaptationSetIds[j]), /* valueIfKeyNotFound= */ -1); if (extraIndex != -1) { adaptationSetUsedFlags[extraIndex] = true; adaptationSetIndices[outputIndex] = extraIndex; outputIndex++; } } if (outputIndex < adaptationSetIndices.length) { adaptationSetIndices = Arrays.copyOf(adaptationSetIndices, outputIndex); } groupedAdaptationSetIndices[groupCount++] = adaptationSetIndices; } } return groupCount < adaptationSetCount ? Arrays.copyOf(groupedAdaptationSetIndices, groupCount) : groupedAdaptationSetIndices; }
Example 14
Source File: ExifInterface.java From Camera2 with Apache License 2.0 | 4 votes |
/** * Creates a new tag definition in this ExifInterface object for a given TID * and default IFD. Creating a definition with the same TID and default IFD * as a previous definition will override it. * * @param tagId the TID for the tag. * @param defaultIfd the default IFD for the tag. * @param tagType the type of the tag (see {@link ExifTag#getDataType()}). * @param defaultComponentCount the number of elements of this tag's type in * the tags value. * @param allowedIfds the IFD's this tag is allowed to be put in. * @return the defined tag constant (e.g. {@link #TAG_IMAGE_WIDTH}) or * {@link #TAG_NULL} if the definition could not be made. */ public int setTagDefinition(short tagId, int defaultIfd, short tagType, short defaultComponentCount, int[] allowedIfds) { if (sBannedDefines.contains(tagId)) { return TAG_NULL; } if (ExifTag.isValidType(tagType) && ExifTag.isValidIfd(defaultIfd)) { int tagDef = defineTag(defaultIfd, tagId); if (tagDef == TAG_NULL) { return TAG_NULL; } int[] otherDefs = getTagDefinitionsForTagId(tagId); SparseIntArray infos = getTagInfo(); // Make sure defaultIfd is in allowedIfds boolean defaultCheck = false; for (int i : allowedIfds) { if (defaultIfd == i) { defaultCheck = true; } if (!ExifTag.isValidIfd(i)) { return TAG_NULL; } } if (!defaultCheck) { return TAG_NULL; } int ifdFlags = getFlagsFromAllowedIfds(allowedIfds); // Make sure no identical tags can exist in allowedIfds if (otherDefs != null) { for (int def : otherDefs) { int tagInfo = infos.get(def); int allowedFlags = getAllowedIfdFlagsFromInfo(tagInfo); if ((ifdFlags & allowedFlags) != 0) { return TAG_NULL; } } } getTagInfo().put(tagDef, ifdFlags << 24 | (tagType << 16) | defaultComponentCount); return tagDef; } return TAG_NULL; }
Example 15
Source File: DashMediaPeriod.java From MediaSDK with Apache License 2.0 | 4 votes |
private static int[][] getGroupedAdaptationSetIndices(List<AdaptationSet> adaptationSets) { int adaptationSetCount = adaptationSets.size(); SparseIntArray idToIndexMap = new SparseIntArray(adaptationSetCount); for (int i = 0; i < adaptationSetCount; i++) { idToIndexMap.put(adaptationSets.get(i).id, i); } int[][] groupedAdaptationSetIndices = new int[adaptationSetCount][]; boolean[] adaptationSetUsedFlags = new boolean[adaptationSetCount]; int groupCount = 0; for (int i = 0; i < adaptationSetCount; i++) { if (adaptationSetUsedFlags[i]) { // This adaptation set has already been included in a group. continue; } adaptationSetUsedFlags[i] = true; Descriptor adaptationSetSwitchingProperty = findAdaptationSetSwitchingProperty( adaptationSets.get(i).supplementalProperties); if (adaptationSetSwitchingProperty == null) { groupedAdaptationSetIndices[groupCount++] = new int[] {i}; } else { String[] extraAdaptationSetIds = Util.split(adaptationSetSwitchingProperty.value, ","); int[] adaptationSetIndices = new int[1 + extraAdaptationSetIds.length]; adaptationSetIndices[0] = i; int outputIndex = 1; for (String adaptationSetId : extraAdaptationSetIds) { int extraIndex = idToIndexMap.get(Integer.parseInt(adaptationSetId), /* valueIfKeyNotFound= */ -1); if (extraIndex != -1) { adaptationSetUsedFlags[extraIndex] = true; adaptationSetIndices[outputIndex] = extraIndex; outputIndex++; } } if (outputIndex < adaptationSetIndices.length) { adaptationSetIndices = Arrays.copyOf(adaptationSetIndices, outputIndex); } groupedAdaptationSetIndices[groupCount++] = adaptationSetIndices; } } return groupCount < adaptationSetCount ? Arrays.copyOf(groupedAdaptationSetIndices, groupCount) : groupedAdaptationSetIndices; }
Example 16
Source File: ExifInterface.java From TurboLauncher with Apache License 2.0 | 4 votes |
/** * Creates a new tag definition in this ExifInterface object for a given TID * and default IFD. Creating a definition with the same TID and default IFD * as a previous definition will override it. * * @param tagId the TID for the tag. * @param defaultIfd the default IFD for the tag. * @param tagType the type of the tag (see {@link ExifTag#getDataType()}). * @param defaultComponentCount the number of elements of this tag's type in * the tags value. * @param allowedIfds the IFD's this tag is allowed to be put in. * @return the defined tag constant (e.g. {@link #TAG_IMAGE_WIDTH}) or * {@link #TAG_NULL} if the definition could not be made. */ public int setTagDefinition(short tagId, int defaultIfd, short tagType, short defaultComponentCount, int[] allowedIfds) { if (sBannedDefines.contains(tagId)) { return TAG_NULL; } if (ExifTag.isValidType(tagType) && ExifTag.isValidIfd(defaultIfd)) { int tagDef = defineTag(defaultIfd, tagId); if (tagDef == TAG_NULL) { return TAG_NULL; } int[] otherDefs = getTagDefinitionsForTagId(tagId); SparseIntArray infos = getTagInfo(); // Make sure defaultIfd is in allowedIfds boolean defaultCheck = false; for (int i : allowedIfds) { if (defaultIfd == i) { defaultCheck = true; } if (!ExifTag.isValidIfd(i)) { return TAG_NULL; } } if (!defaultCheck) { return TAG_NULL; } int ifdFlags = getFlagsFromAllowedIfds(allowedIfds); // Make sure no identical tags can exist in allowedIfds if (otherDefs != null) { for (int def : otherDefs) { int tagInfo = infos.get(def); int allowedFlags = getAllowedIfdFlagsFromInfo(tagInfo); if ((ifdFlags & allowedFlags) != 0) { return TAG_NULL; } } } getTagInfo().put(tagDef, ifdFlags << 24 | (tagType << 16) | defaultComponentCount); return tagDef; } return TAG_NULL; }
Example 17
Source File: NumberEffect.java From memoir with Apache License 2.0 | 4 votes |
@Override public synchronized void applyToSelection(RTEditText editor, Selection selectedParagraphs, Boolean enable) { final Spannable str = editor.getText(); mSpans2Process.clear(); int lineNr = 1; SparseIntArray indentations = new SparseIntArray(); SparseIntArray numbers = new SparseIntArray(); for (Paragraph paragraph : editor.getParagraphs()) { /* * We need to know the indentation for each paragraph to be able * to determine which paragraphs belong together (same indentation) */ int currentIndentation = 0; List<RTSpan<Integer>> indentationSpans = Effects.INDENTATION.getSpans(str, paragraph, SpanCollectMode.EXACT); if (! indentationSpans.isEmpty()) { for (RTSpan<Integer> span : indentationSpans) { currentIndentation += span.getValue(); } } indentations.put(lineNr, currentIndentation); // find existing NumberSpans and add them to mSpans2Process to be removed List<RTSpan<Boolean>> existingSpans = getSpans(str, paragraph, SpanCollectMode.SPAN_FLAGS); mSpans2Process.removeSpans(existingSpans, paragraph); /* * If the paragraph is selected then we sure have a number */ boolean hasExistingSpans = ! existingSpans.isEmpty(); boolean hasNumber = paragraph.isSelected(selectedParagraphs) ? enable : hasExistingSpans; /* * If we have a number then apply a new span */ if (hasNumber) { // let's determine the number for this paragraph int nr = 1; for (int line = 1; line < lineNr; line++) { int indentation = indentations.get(line); int number = numbers.get(line); if (indentation < currentIndentation) { // 1) less indentation -> number 1 nr = 1; } else if (indentation == currentIndentation) { // 2) same indentation + no numbering -> number 1 // 3) same indentation + numbering -> increment number nr = number == 0 ? 1 : number + 1; } } numbers.put(lineNr, nr); int margin = Helper.getLeadingMarging(); NumberSpan numberSpan = new NumberSpan(nr++, margin, paragraph.isEmpty(), paragraph.isFirst(), paragraph.isLast()); mSpans2Process.addSpan(numberSpan, paragraph); // if the paragraph has bullet spans, then remove them Effects.BULLET.findSpans2Remove(str, paragraph, mSpans2Process); } lineNr++; } // add or remove spans mSpans2Process.process(str); }
Example 18
Source File: NumberEffect.java From memoir with Apache License 2.0 | 4 votes |
@Override public synchronized void applyToSelection(RTEditText editor, Selection selectedParagraphs, Boolean enable) { final Spannable str = editor.getText(); mSpans2Process.clear(); int lineNr = 1; SparseIntArray indentations = new SparseIntArray(); SparseIntArray numbers = new SparseIntArray(); for (Paragraph paragraph : editor.getParagraphs()) { /* * We need to know the indentation for each paragraph to be able * to determine which paragraphs belong together (same indentation) */ int currentIndentation = 0; List<RTSpan<Integer>> indentationSpans = Effects.INDENTATION.getSpans(str, paragraph, SpanCollectMode.EXACT); if (! indentationSpans.isEmpty()) { for (RTSpan<Integer> span : indentationSpans) { currentIndentation += span.getValue(); } } indentations.put(lineNr, currentIndentation); // find existing NumberSpans and add them to mSpans2Process to be removed List<RTSpan<Boolean>> existingSpans = getSpans(str, paragraph, SpanCollectMode.SPAN_FLAGS); mSpans2Process.removeSpans(existingSpans, paragraph); /* * If the paragraph is selected then we sure have a number */ boolean hasExistingSpans = ! existingSpans.isEmpty(); boolean hasNumber = paragraph.isSelected(selectedParagraphs) ? enable : hasExistingSpans; /* * If we have a number then apply a new span */ if (hasNumber) { // let's determine the number for this paragraph int nr = 1; for (int line = 1; line < lineNr; line++) { int indentation = indentations.get(line); int number = numbers.get(line); if (indentation < currentIndentation) { // 1) less indentation -> number 1 nr = 1; } else if (indentation == currentIndentation) { // 2) same indentation + no numbering -> number 1 // 3) same indentation + numbering -> increment number nr = number == 0 ? 1 : number + 1; } } numbers.put(lineNr, nr); int margin = Helper.getLeadingMarging(); NumberSpan numberSpan = new NumberSpan(nr++, margin, paragraph.isEmpty(), paragraph.isFirst(), paragraph.isLast()); mSpans2Process.addSpan(numberSpan, paragraph); // if the paragraph has bullet spans, then remove them Effects.BULLET.findSpans2Remove(str, paragraph, mSpans2Process); } lineNr++; } // add or remove spans mSpans2Process.process(str); }
Example 19
Source File: WakeupStats.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private static void increment(SparseIntArray counters, int key) { int newcount = counters.get(key, 0) + 1; counters.put(key, newcount); }
Example 20
Source File: ExifInterface.java From LB-Launcher with Apache License 2.0 | 4 votes |
/** * Creates a new tag definition in this ExifInterface object for a given TID * and default IFD. Creating a definition with the same TID and default IFD * as a previous definition will override it. * * @param tagId the TID for the tag. * @param defaultIfd the default IFD for the tag. * @param tagType the type of the tag (see {@link ExifTag#getDataType()}). * @param defaultComponentCount the number of elements of this tag's type in * the tags value. * @param allowedIfds the IFD's this tag is allowed to be put in. * @return the defined tag constant (e.g. {@link #TAG_IMAGE_WIDTH}) or * {@link #TAG_NULL} if the definition could not be made. */ public int setTagDefinition(short tagId, int defaultIfd, short tagType, short defaultComponentCount, int[] allowedIfds) { if (sBannedDefines.contains(tagId)) { return TAG_NULL; } if (ExifTag.isValidType(tagType) && ExifTag.isValidIfd(defaultIfd)) { int tagDef = defineTag(defaultIfd, tagId); if (tagDef == TAG_NULL) { return TAG_NULL; } int[] otherDefs = getTagDefinitionsForTagId(tagId); SparseIntArray infos = getTagInfo(); // Make sure defaultIfd is in allowedIfds boolean defaultCheck = false; for (int i : allowedIfds) { if (defaultIfd == i) { defaultCheck = true; } if (!ExifTag.isValidIfd(i)) { return TAG_NULL; } } if (!defaultCheck) { return TAG_NULL; } int ifdFlags = getFlagsFromAllowedIfds(allowedIfds); // Make sure no identical tags can exist in allowedIfds if (otherDefs != null) { for (int def : otherDefs) { int tagInfo = infos.get(def); int allowedFlags = getAllowedIfdFlagsFromInfo(tagInfo); if ((ifdFlags & allowedFlags) != 0) { return TAG_NULL; } } } getTagInfo().put(tagDef, ifdFlags << 24 | (tagType << 16) | defaultComponentCount); return tagDef; } return TAG_NULL; }