Here are the examples of the java api class android.util.SparseIntArray taken from open source projects.
1. DefaultNativeMemoryChunkPoolParams#get()
Project: fresco
File: DefaultNativeMemoryChunkPoolParams.java
File: DefaultNativeMemoryChunkPoolParams.java
public static PoolParams get() { SparseIntArray DEFAULT_BUCKETS = new SparseIntArray(); DEFAULT_BUCKETS.put(1 * ByteConstants.KB, SMALL_BUCKET_LENGTH); DEFAULT_BUCKETS.put(2 * ByteConstants.KB, SMALL_BUCKET_LENGTH); DEFAULT_BUCKETS.put(4 * ByteConstants.KB, SMALL_BUCKET_LENGTH); DEFAULT_BUCKETS.put(8 * ByteConstants.KB, SMALL_BUCKET_LENGTH); DEFAULT_BUCKETS.put(16 * ByteConstants.KB, SMALL_BUCKET_LENGTH); DEFAULT_BUCKETS.put(32 * ByteConstants.KB, SMALL_BUCKET_LENGTH); DEFAULT_BUCKETS.put(64 * ByteConstants.KB, SMALL_BUCKET_LENGTH); DEFAULT_BUCKETS.put(128 * ByteConstants.KB, SMALL_BUCKET_LENGTH); DEFAULT_BUCKETS.put(256 * ByteConstants.KB, LARGE_BUCKET_LENGTH); DEFAULT_BUCKETS.put(512 * ByteConstants.KB, LARGE_BUCKET_LENGTH); DEFAULT_BUCKETS.put(1024 * ByteConstants.KB, LARGE_BUCKET_LENGTH); return new PoolParams(getMaxSizeSoftCap(), getMaxSizeHardCap(), DEFAULT_BUCKETS); }
2. MediaController2KitKat#generatePlaybackCompatSparse()
Project: AcDisplay
File: MediaController2KitKat.java
File: MediaController2KitKat.java
@NonNull static SparseIntArray generatePlaybackCompatSparse() { SparseIntArray sia = new SparseIntArray(); sia.put(RemoteControlClient.PLAYSTATE_BUFFERING, PlaybackStateCompat.STATE_BUFFERING); sia.put(RemoteControlClient.PLAYSTATE_PLAYING, PlaybackStateCompat.STATE_PLAYING); sia.put(RemoteControlClient.PLAYSTATE_PAUSED, PlaybackStateCompat.STATE_PAUSED); sia.put(RemoteControlClient.PLAYSTATE_ERROR, PlaybackStateCompat.STATE_ERROR); sia.put(RemoteControlClient.PLAYSTATE_REWINDING, PlaybackStateCompat.STATE_REWINDING); sia.put(RemoteControlClient.PLAYSTATE_FAST_FORWARDING, PlaybackStateCompat.STATE_FAST_FORWARDING); sia.put(RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS, PlaybackStateCompat.STATE_SKIPPING_TO_NEXT); sia.put(RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS, PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS); return sia; }
3. GsmAlphabet#countGsmSeptetsUsingTables()
Project: qksms
File: GsmAlphabet.java
File: GsmAlphabet.java
/** * Returns the count of 7-bit GSM alphabet characters needed * to represent this string, using the specified 7-bit language table * and extension table (0 for GSM default tables). * * @param s the Unicode string that will be encoded * @param use7bitOnly allow using space in place of unencodable character if true, * otherwise, return -1 if any characters are unencodable * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet * @param languageShiftTable the 7 bit single shift language table, or 0 for the default * GSM extension table * @return the septet count for s using the specified language tables, or -1 if any * characters are unencodable and use7bitOnly is false */ public static int countGsmSeptetsUsingTables(CharSequence s, boolean use7bitOnly, int languageTable, int languageShiftTable) { int count = 0; int sz = s.length(); SparseIntArray charToLanguageTable = sCharsToGsmTables[languageTable]; SparseIntArray charToShiftTable = sCharsToShiftTables[languageShiftTable]; for (int i = 0; i < sz; i++) { char c = s.charAt(i); if (c == GSM_EXTENDED_ESCAPE) { Log.w(TAG, "countGsmSeptets() string contains Escape character, skipping."); continue; } if (charToLanguageTable.get(c, -1) != -1) { count++; } else if (charToShiftTable.get(c, -1) != -1) { // escape + shift table index count += 2; } else if (use7bitOnly) { // encode as space count++; } else { // caller must check for this case return -1; } } return count; }
4. MediaGalleryEditFragment#mapIdsToCursorPositions()
Project: WordPress-Android
File: MediaGalleryEditFragment.java
File: MediaGalleryEditFragment.java
private SparseIntArray mapIdsToCursorPositions(Cursor cursor) { SparseIntArray positions = new SparseIntArray(); int size = mIds.size(); for (int i = 0; i < size; i++) { while (cursor.moveToNext()) { String mediaId = cursor.getString(cursor.getColumnIndex("mediaId")); if (mediaId.equals(mIds.get(i))) { positions.put(i, cursor.getPosition()); cursor.moveToPosition(-1); break; } } } return positions; }
5. MediaGalleryEditFragment#refreshGridView()
Project: WordPress-Android
File: MediaGalleryEditFragment.java
File: MediaGalleryEditFragment.java
private void refreshGridView() { if (WordPress.getCurrentBlog() == null) { return; } String blogId = String.valueOf(WordPress.getCurrentBlog().getLocalTableBlogId()); Cursor cursor = WordPress.wpDB.getMediaFiles(blogId, mIds); if (cursor == null) { mGridAdapter.changeCursor(null); return; } SparseIntArray positions = mapIdsToCursorPositions(cursor); mGridAdapter.swapCursor(new OrderedCursor(cursor, positions)); }
6. ExifInterface#getTagDefinitionsForTagId()
Project: qksms
File: ExifInterface.java
File: ExifInterface.java
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); }
7. FlexByteArrayPoolTest#setup()
Project: fresco
File: FlexByteArrayPoolTest.java
File: FlexByteArrayPoolTest.java
@Before public void setup() { SparseIntArray buckets = new SparseIntArray(); for (int i = MIN_BUFFER_SIZE; i <= MAX_BUFFER_SIZE; i *= 2) { buckets.put(i, 3); } mPool = new FlexByteArrayPool(mock(MemoryTrimmableRegistry.class), new PoolParams(Integer.MAX_VALUE, Integer.MAX_VALUE, buckets, MIN_BUFFER_SIZE, MAX_BUFFER_SIZE, 1)); mDelegatePool = mPool.mDelegatePool; }
8. BasePool#initBuckets()
Project: fresco
File: BasePool.java
File: BasePool.java
/** * Initialize the list of buckets. Get the bucket sizes (and bucket lengths) from the bucket * sizes provider * @param inUseCounts map of current buckets and their in use counts */ private synchronized void initBuckets(SparseIntArray inUseCounts) { Preconditions.checkNotNull(inUseCounts); // clear out all the buckets mBuckets.clear(); // create the new buckets final SparseIntArray bucketSizes = mPoolParams.bucketSizes; if (bucketSizes != null) { for (int i = 0; i < bucketSizes.size(); ++i) { final int bucketSize = bucketSizes.keyAt(i); final int maxLength = bucketSizes.valueAt(i); int bucketInUseCount = inUseCounts.get(bucketSize, 0); mBuckets.put(bucketSize, new Bucket<V>(getSizeInBytes(bucketSize), maxLength, bucketInUseCount)); } mAllowNewBuckets = false; } else { mAllowNewBuckets = true; } }
9. ExifInterface#getTagDefinitionsForTagId()
Project: cwac-camera
File: ExifInterface.java
File: ExifInterface.java
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); }
10. ExifInterface#getTagDefinitionsForTagId()
Project: cwac-cam2
File: ExifInterface.java
File: ExifInterface.java
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); }
11. FakeNativeMemoryChunkPool#getBucketSizes()
Project: fresco
File: FakeNativeMemoryChunkPool.java
File: FakeNativeMemoryChunkPool.java
private static SparseIntArray getBucketSizes() { final SparseIntArray bucketSizes = new SparseIntArray(); bucketSizes.put(4, 10); bucketSizes.put(8, 10); bucketSizes.put(16, 10); bucketSizes.put(32, 10); return bucketSizes; }
12. MainActivity#onCreate()
Project: LiquidFunPaint
File: MainActivity.java
File: MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Explicitly load all shared libraries for Android 4.1 (Jelly Bean) // Or we could get a crash from dependencies. System.loadLibrary("liquidfun"); System.loadLibrary("liquidfun_jni"); // Set the ToolBar layout setContentView(R.layout.tools_layout); mRootLayout = (RelativeLayout) findViewById(R.id.root); mColorMap = new SparseIntArray(); mPencilImageMap = new SparseIntArray(); mRigidImageMap = new SparseIntArray(); mWaterImageMap = new SparseIntArray(); mRigidColorPalette = new ArrayList<View>(); mWaterColorPalette = new ArrayList<View>(); String pencilPrefix = getString(R.string.pencil_prefix); String rigidPrefix = getString(R.string.rigid_prefix); String waterPrefix = getString(R.string.water_prefix); String rigidColorPrefix = getString(R.string.rigid_color_prefix); String waterColorPrefix = getString(R.string.water_color_prefix); Resources r = getResources(); // Look up all the different colors for (int i = 1; i <= r.getInteger(R.integer.num_colors); ++i) { // Get color palette for rigid/pencil tools // 1) Add color RGB values to mColorMap // 2) Add appropriate images for tool // 3) Add the color palette view to the color palette list int viewId = r.getIdentifier(rigidColorPrefix + i, "id", getPackageName()); mColorMap.append(viewId, getColor(rigidColorPrefix + i, "color")); mPencilImageMap.append(viewId, r.getIdentifier(pencilPrefix + i, "drawable", getPackageName())); mRigidImageMap.append(viewId, r.getIdentifier(rigidPrefix + i, "drawable", getPackageName())); mRigidColorPalette.add(findViewById(viewId)); // Get color palette for water tool // 1) Add color RGB values to mColorMap // 2) Add appropriate images for tool // 3) Add the color palette view to the color palette list viewId = r.getIdentifier(waterColorPrefix + i, "id", getPackageName()); mColorMap.append(viewId, getColor(waterColorPrefix + i, "color")); mWaterImageMap.append(viewId, r.getIdentifier(waterPrefix + i, "drawable", getPackageName())); mWaterColorPalette.add(findViewById(viewId)); } // Add the ending piece to both palettes int paletteEndViewId = r.getIdentifier(rigidColorPrefix + "end", "id", getPackageName()); mRigidColorPalette.add(findViewById(paletteEndViewId)); paletteEndViewId = r.getIdentifier(waterColorPrefix + "end", "id", getPackageName()); mWaterColorPalette.add(findViewById(paletteEndViewId)); // Set the restart button's listener findViewById(R.id.button_restart).setOnTouchListener(this); Renderer renderer = Renderer.getInstance(); Renderer.getInstance().init(this); mController = new Controller(this); // Set up the OpenGL WorldView mWorldView = (GLSurfaceView) findViewById(R.id.world); mWorldView.setEGLContextClientVersion(2); mWorldView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); mWorldView.getHolder().setFormat(PixelFormat.TRANSLUCENT); if (BuildConfig.DEBUG) { mWorldView.setDebugFlags(GLSurfaceView.DEBUG_LOG_GL_CALLS | GLSurfaceView.DEBUG_CHECK_GL_ERROR); } mWorldView.setOnTouchListener(this); // GLSurfaceView#setPreserveEGLContextOnPause() is added in API level 11 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setPreserveEGLContextOnPause(); } mWorldView.setRenderer(renderer); renderer.startSimulation(); // Set default tool colors Tool.getTool(ToolType.PENCIL).setColor(getColor(getString(R.string.default_pencil_color), "color")); Tool.getTool(ToolType.RIGID).setColor(getColor(getString(R.string.default_rigid_color), "color")); Tool.getTool(ToolType.WATER).setColor(getColor(getString(R.string.default_water_color), "color")); // Initialize the first selected tool mSelected = (ImageView) findViewById(R.id.water); onClickTool(mSelected); // Show the title view for 3 seconds LayoutInflater inflater = getLayoutInflater(); inflater.inflate(R.layout.title, mRootLayout); final View title = findViewById(R.id.title); Animation fadeOut = new AlphaAnimation(1, 0); fadeOut.setDuration(500); fadeOut.setStartOffset(3000); fadeOut.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { title.setVisibility(View.GONE); } }); title.setVisibility(View.VISIBLE); title.startAnimation(fadeOut); if (BuildConfig.DEBUG) { View fps = findViewById(R.id.fps); fps.setVisibility(View.VISIBLE); TextView versionView = (TextView) findViewById(R.id.version); try { sVersionName = "Version " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName; versionView.setText(sVersionName); } catch (NameNotFoundException e) { } } }
13. NativeMemoryChunkPoolTest#setup()
Project: fresco
File: NativeMemoryChunkPoolTest.java
File: NativeMemoryChunkPoolTest.java
@Before public void setup() { final SparseIntArray bucketSizes = new SparseIntArray(); bucketSizes.put(32, 2); bucketSizes.put(64, 1); bucketSizes.put(128, 1); mPool = new FakeNativeMemoryChunkPool(new PoolParams(128, bucketSizes)); }
14. GenericByteArrayPoolTest#setup()
Project: fresco
File: GenericByteArrayPoolTest.java
File: GenericByteArrayPoolTest.java
@Before public void setup() { final SparseIntArray bucketSizes = new SparseIntArray(); bucketSizes.put(32, 2); bucketSizes.put(64, 1); bucketSizes.put(128, 1); mPool = new GenericByteArrayPool(mock(MemoryTrimmableRegistry.class), new PoolParams(128, bucketSizes), mock(PoolStatsTracker.class)); }
15. MML#processRepeat()
Project: FlMML-for-Android
File: MML.java
File: MML.java
private void processRepeat() { long ltime = System.currentTimeMillis(); mString = new StringBuilder(mString.toString().toLowerCase()); Log.v("MML.time", "processRepeat()->toLowercase():" + (System.currentTimeMillis() - ltime) + "ms"); begin(); SparseIntArray repeat = new SparseIntArray(); SparseIntArray origin = new SparseIntArray(); SparseIntArray start = new SparseIntArray(); SparseIntArray last = new SparseIntArray(); int nest = -1; int length = mString.length(); StringBuilder replaced = new StringBuilder(); while (mLetter < length) { char c = mString.charAt(mLetter++); switch(c) { case '/': if (getChar() == ':') { next(); origin.append(++nest, mLetter - 2); repeat.append(nest, getUInt(2)); start.append(nest, mLetter); last.append(nest, -1); } else if (nest >= 0) { mLetter--; last.append(nest, mLetter); mString.deleteCharAt(mLetter); length--; } break; case ':': if (getChar() == '/' && nest >= 0) { next(); int offset = origin.get(nest); int repeatnum = repeat.get(nest); boolean haslast = last.get(nest) >= 0; if (repeatnum > 0) { String contents = FlMMLUtil.substring(mString, start.get(nest), mLetter - 2); int contentslen = mLetter - 2 - start.get(nest); int lastlen = last.get(nest) - start.get(nest); int addedlen = !haslast ? repeatnum * contentslen : (repeatnum - 1) * contentslen + lastlen; replaced.setLength(0); for (int i = 0; i < repeatnum; i++) { if (i < repeatnum - 1 || !haslast) { replaced.append(contents); } else { replaced.append(mString, start.get(nest), last.get(nest)); } } mString.replace(offset, mLetter, replaced.toString()); offset += addedlen; length += offset - mLetter; } else { mString.delete(offset, mLetter); length -= mLetter - offset; } mLetter = offset; nest--; } } } if (nest >= 0) warning(MWarning.UNCLOSED_REPEAT, ""); }
16. SimpleTest#testSparseIntArray()
Project: unmock-plugin
File: SimpleTest.java
File: SimpleTest.java
@Test public void testSparseIntArray() { SparseIntArray sia = new SparseIntArray(); sia.put(12, 999); sia.put(99, 12); assertEquals(999, sia.get(12)); }
17. SimpleTest#testSparseIntArray()
Project: unmock-plugin
File: SimpleTest.java
File: SimpleTest.java
@Test public void testSparseIntArray() { SparseIntArray sia = new SparseIntArray(); sia.put(12, 999); sia.put(99, 12); assertEquals(999, sia.get(12)); }
18. GsmAlphabet#findGsmSeptetLimitIndex()
Project: qksms
File: GsmAlphabet.java
File: GsmAlphabet.java
/** * Returns the index into <code>s</code> of the first character * after <code>limit</code> septets have been reached, starting at * index <code>start</code>. This is used when dividing messages * into units within the SMS message size limit. * * @param s source string * @param start index of where to start counting septets * @param limit maximum septets to include, * e.g. <code>MAX_USER_DATA_SEPTETS</code> * @param langTable the 7 bit character table to use (0 for default GSM 7-bit alphabet) * @param langShiftTable the 7 bit shift table to use (0 for default GSM extension table) * @return index of first character that won't fit, or the length * of the entire string if everything fits */ public static int findGsmSeptetLimitIndex(String s, int start, int limit, int langTable, int langShiftTable) { int accumulator = 0; int size = s.length(); SparseIntArray charToLangTable = sCharsToGsmTables[langTable]; SparseIntArray charToLangShiftTable = sCharsToShiftTables[langShiftTable]; for (int i = start; i < size; i++) { int encodedSeptet = charToLangTable.get(s.charAt(i), -1); if (encodedSeptet == -1) { encodedSeptet = charToLangShiftTable.get(s.charAt(i), -1); if (encodedSeptet == -1) { // char not found, assume we're replacing with space accumulator++; } else { // escape character + shift table index accumulator += 2; } } else { accumulator++; } if (accumulator > limit) { return i; } } return size; }
19. GsmAlphabet#stringToGsm8BitUnpackedField()
Project: qksms
File: GsmAlphabet.java
File: GsmAlphabet.java
/** * Write a String into a GSM 8-bit unpacked field of * Field is padded with 0xff's, string is truncated if necessary * * @param s the string to encode * @param dest the destination byte array * @param offset the starting offset for the encoded string * @param length the maximum number of bytes to write */ public static void stringToGsm8BitUnpackedField(String s, byte dest[], int offset, int length) { int outByteIndex = offset; SparseIntArray charToLanguageTable = sCharsToGsmTables[0]; SparseIntArray charToShiftTable = sCharsToShiftTables[0]; // Septets are stored in byte-aligned octets for (int i = 0, sz = s.length(); i < sz && (outByteIndex - offset) < length; i++) { char c = s.charAt(i); int v = charToLanguageTable.get(c, -1); if (v == -1) { v = charToShiftTable.get(c, -1); if (v == -1) { // fall back to ASCII space v = charToLanguageTable.get(' ', ' '); } else { // make sure we can fit an escaped char if (!(outByteIndex + 1 - offset < length)) { break; } dest[outByteIndex++] = GSM_EXTENDED_ESCAPE; } } dest[outByteIndex++] = (byte) v; } // pad with 0xff's while ((outByteIndex - offset) < length) { dest[outByteIndex++] = (byte) 0xff; } }
20. GsmAlphabet#stringToGsm7BitPacked()
Project: qksms
File: GsmAlphabet.java
File: GsmAlphabet.java
/** * Converts a String into a byte array containing * the 7-bit packed GSM Alphabet representation of the string. * <p/> * Byte 0 in the returned byte array is the count of septets used * The returned byte array is the minimum size required to store * the packed septets. The returned array cannot contain more than 255 * septets. * * @param data the text to convert to septets * @param startingSeptetOffset the number of padding septets to put before * the character data at the beginning of the array * @param throwException If true, throws EncodeException on invalid char. * If false, replaces unencodable char with GSM alphabet space char. * @param languageTable the 7 bit language table, or 0 for the default GSM alphabet * @param languageShiftTable the 7 bit single shift language table, or 0 for the default * GSM extension table * @return the encoded message * @throws EncodeException if String is too large to encode */ public static byte[] stringToGsm7BitPacked(String data, int startingSeptetOffset, boolean throwException, int languageTable, int languageShiftTable) throws EncodeException { int dataLen = data.length(); int septetCount = countGsmSeptetsUsingTables(data, !throwException, languageTable, languageShiftTable); if (septetCount == -1) { throw new EncodeException("countGsmSeptetsUsingTables(): unencodable char"); } septetCount += startingSeptetOffset; if (septetCount > 255) { throw new EncodeException("Payload cannot exceed 255 septets"); } int byteCount = ((septetCount * 7) + 7) / 8; // Include space for one byte length prefix. byte[] ret = new byte[byteCount + 1]; SparseIntArray charToLanguageTable = sCharsToGsmTables[languageTable]; SparseIntArray charToShiftTable = sCharsToShiftTables[languageShiftTable]; for (int i = 0, septets = startingSeptetOffset, bitOffset = startingSeptetOffset * 7; i < dataLen && septets < septetCount; i++, bitOffset += 7) { char c = data.charAt(i); int v = charToLanguageTable.get(c, -1); if (v == -1) { // Lookup the extended char. v = charToShiftTable.get(c, -1); if (v == -1) { if (throwException) { throw new EncodeException("stringToGsm7BitPacked(): unencodable char"); } else { // should return ASCII space v = charToLanguageTable.get(' ', ' '); } } else { packSmsChar(ret, bitOffset, GSM_EXTENDED_ESCAPE); bitOffset += 7; septets++; } } packSmsChar(ret, bitOffset, v); septets++; } // Validated by check above. ret[0] = (byte) (septetCount); return ret; }
21. DefaultByteArrayPoolParams#get()
Project: fresco
File: DefaultByteArrayPoolParams.java
File: DefaultByteArrayPoolParams.java
/** * Get default {@link PoolParams}. */ public static PoolParams get() { // This pool supports only one bucket size: DEFAULT_IO_BUFFER_SIZE SparseIntArray defaultBuckets = new SparseIntArray(); defaultBuckets.put(DEFAULT_IO_BUFFER_SIZE, DEFAULT_BUCKET_SIZE); return new PoolParams(MAX_SIZE_SOFT_CAP, MAX_SIZE_HARD_CAP, defaultBuckets); }
22. NumberEffect#applyToSelection()
Project: Android-RTEditor
File: NumberEffect.java
File: NumberEffect.java
@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); }
23. ObservableListView#init()
Project: WayHoo
File: ObservableListView.java
File: ObservableListView.java
private void init() { mChildrenHeights = new SparseIntArray(); super.setOnScrollListener(mScrollListener); }
24. ObservableGridView#init()
Project: WayHoo
File: ObservableGridView.java
File: ObservableGridView.java
private void init() { mChildrenHeights = new SparseIntArray(); super.setOnScrollListener(mScrollListener); }
25. ExifInterface#getTagDefinitionForTag()
Project: qksms
File: ExifInterface.java
File: ExifInterface.java
protected int getTagDefinitionForTag(short tagId, short type, int count, int ifd) { int[] defs = getTagDefinitionsForTagId(tagId); if (defs == null) { return TAG_NULL; } SparseIntArray infos = getTagInfo(); int ret = TAG_NULL; for (int i : defs) { int info = infos.get(i); short def_type = getTypeFromInfo(info); int def_count = getComponentCountFromInfo(info); int[] def_ifds = getAllowedIfdsFromInfo(info); boolean valid_ifd = false; for (int j : def_ifds) { if (j == ifd) { valid_ifd = true; break; } } if (valid_ifd && type == def_type && (count == def_count || def_count == ExifTag.SIZE_UNDEFINED)) { ret = i; break; } } return ret; }
26. BasePoolTest#makeBucketSizeArray()
Project: fresco
File: BasePoolTest.java
File: BasePoolTest.java
private static SparseIntArray makeBucketSizeArray(int... params) { Preconditions.checkArgument(params.length % 2 == 0); final SparseIntArray bucketSizes = new SparseIntArray(); for (int i = 0; i < params.length; i += 2) { bucketSizes.append(params[i], params[i + 1]); } return bucketSizes; }
27. DefaultFlexByteArrayPoolParams#generateBuckets()
Project: fresco
File: DefaultFlexByteArrayPoolParams.java
File: DefaultFlexByteArrayPoolParams.java
public static SparseIntArray generateBuckets(int min, int max, int numThreads) { SparseIntArray buckets = new SparseIntArray(); for (int i = min; i <= max; i *= 2) { buckets.put(i, numThreads); } return buckets; }
28. BasePool#trimToNothing()
Project: fresco
File: BasePool.java
File: BasePool.java
/** * Gets rid of all free values in the pool * At the end of this method, mFreeSpace will be zero (reflecting that there are no more free * values in the pool). mUsedSpace will however not be reset, since that's a reflection of the * values that were allocated via the pool, but are in use elsewhere */ @VisibleForTesting void trimToNothing() { final List<Bucket<V>> bucketsToTrim = new ArrayList<>(mBuckets.size()); final SparseIntArray inUseCounts = new SparseIntArray(); synchronized (this) { for (int i = 0; i < mBuckets.size(); ++i) { final Bucket<V> bucket = mBuckets.valueAt(i); if (bucket.getFreeListSize() > 0) { bucketsToTrim.add(bucket); } inUseCounts.put(mBuckets.keyAt(i), bucket.getInUseCount()); } // reinitialize the buckets initBuckets(inUseCounts); // free up the stats mFree.reset(); logStats(); } // the pool parameters 'may' have changed. onParamsChanged(); // This is true even for a concurrent trim() call for (int i = 0; i < bucketsToTrim.size(); ++i) { final Bucket<V> bucket = bucketsToTrim.get(i); while (true) { // what happens if we run into an exception during the recycle. I'm going to ignore // these exceptions for now, and let the GC handle the rest of the to-be-recycled-bitmaps // in its usual fashion V item = bucket.pop(); if (item == null) { break; } free(item); } } }
29. AdapterUtil#adjustPosition()
Project: FastAdapter
File: AdapterUtil.java
File: AdapterUtil.java
/** * internal method to handle the selections if items are added / removed * * @param positions the positions map which should be adjusted * @param startPosition the global index of the first element modified * @param endPosition the global index up to which the modification changed the indices (should be MAX_INT if we check til the end) * @param adjustBy the value by which the data was shifted * @return the adjusted map */ public static SparseIntArray adjustPosition(SparseIntArray positions, int startPosition, int endPosition, int adjustBy) { SparseIntArray newPositions = new SparseIntArray(); int length = positions.size(); for (int i = 0; i < length; i++) { int position = positions.keyAt(i); //if our current position is not within the bounds to check for we can add it if (position < startPosition || position > endPosition) { newPositions.put(position, positions.valueAt(i)); } else if (adjustBy > 0) { //if we added items and we are within the bounds we can simply add the adjustBy to our entry newPositions.put(position + adjustBy, positions.valueAt(i)); } else if (adjustBy < 0) { //adjustBy is negative in this case if (position > startPosition + adjustBy && position <= startPosition) { //we are within the removed items range we don't add this item anymore ; } else { //otherwise we adjust our position newPositions.put(position + adjustBy, positions.valueAt(i)); } } } return newPositions; }
30. ExifInterface#getTagDefinitionForTag()
Project: cwac-camera
File: ExifInterface.java
File: ExifInterface.java
protected int getTagDefinitionForTag(short tagId, short type, int count, int ifd) { int[] defs = getTagDefinitionsForTagId(tagId); if (defs == null) { return TAG_NULL; } SparseIntArray infos = getTagInfo(); int ret = TAG_NULL; for (int i : defs) { int info = infos.get(i); short def_type = getTypeFromInfo(info); int def_count = getComponentCountFromInfo(info); int[] def_ifds = getAllowedIfdsFromInfo(info); boolean valid_ifd = false; for (int j : def_ifds) { if (j == ifd) { valid_ifd = true; break; } } if (valid_ifd && type == def_type && (count == def_count || def_count == ExifTag.SIZE_UNDEFINED)) { ret = i; break; } } return ret; }
31. ExifInterface#getTagDefinitionForTag()
Project: cwac-cam2
File: ExifInterface.java
File: ExifInterface.java
protected int getTagDefinitionForTag(short tagId, short type, int count, int ifd) { int[] defs = getTagDefinitionsForTagId(tagId); if (defs == null) { return TAG_NULL; } SparseIntArray infos = getTagInfo(); int ret = TAG_NULL; for (int i : defs) { int info = infos.get(i); short def_type = getTypeFromInfo(info); int def_count = getComponentCountFromInfo(info); int[] def_ifds = getAllowedIfdsFromInfo(info); boolean valid_ifd = false; for (int j : def_ifds) { if (j == ifd) { valid_ifd = true; break; } } if (valid_ifd && type == def_type && (count == def_count || def_count == ExifTag.SIZE_UNDEFINED)) { ret = i; break; } } return ret; }
32. RuntimePermissionsActivity#onCreate()
Project: Android-Runtime-Permissions
File: RuntimePermissionsActivity.java
File: RuntimePermissionsActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mErrorString = new SparseIntArray(); }
33. RobotoTextAppearanceSpan#textAttrsIndexes()
Project: Android-RobotoTextView
File: RobotoTextAppearanceSpan.java
File: RobotoTextAppearanceSpan.java
private SparseIntArray textAttrsIndexes() { SparseIntArray indexes = new SparseIntArray(TEXT_ATTRS.length); for (int i = 0; i < TEXT_ATTRS.length; i++) { indexes.put(TEXT_ATTRS[i], i); } return indexes; }
34. ObservableRecyclerView#init()
Project: Android-ObservableScrollView
File: ObservableRecyclerView.java
File: ObservableRecyclerView.java
private void init() { mChildrenHeights = new SparseIntArray(); checkLibraryVersion(); }
35. ObservableListView#init()
Project: Android-ObservableScrollView
File: ObservableListView.java
File: ObservableListView.java
private void init() { mChildrenHeights = new SparseIntArray(); super.setOnScrollListener(mScrollListener); }
36. ObservableGridView#init()
Project: Android-ObservableScrollView
File: ObservableGridView.java
File: ObservableGridView.java
private void init() { mChildrenHeights = new SparseIntArray(); mHeaderViewInfos = new ArrayList<>(); mFooterViewInfos = new ArrayList<>(); super.setClipChildren(false); super.setOnScrollListener(mScrollListener); }