Java Code Examples for com.android.internal.util.ArrayUtils#emptyArray()
The following examples show how to use
com.android.internal.util.ArrayUtils#emptyArray() .
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: SpannableStringBuilder.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Return an array of the spans of the specified type that overlap * the specified range of the buffer. The kind may be Object.class to get * a list of all the spans regardless of type. * * @param queryStart Start index. * @param queryEnd End index. * @param kind Class type to search for. * @param sortByInsertionOrder If true the results are sorted by the insertion order. * @param <T> * @return Array of the spans. Empty array if no results are found. * * @hide */ public <T> T[] getSpans(int queryStart, int queryEnd, @Nullable Class<T> kind, boolean sortByInsertionOrder) { if (kind == null) return (T[]) ArrayUtils.emptyArray(Object.class); if (mSpanCount == 0) return ArrayUtils.emptyArray(kind); int count = countSpans(queryStart, queryEnd, kind, treeRoot()); if (count == 0) { return ArrayUtils.emptyArray(kind); } // Safe conversion, but requires a suppressWarning T[] ret = (T[]) Array.newInstance(kind, count); final int[] prioSortBuffer = sortByInsertionOrder ? obtain(count) : EmptyArray.INT; final int[] orderSortBuffer = sortByInsertionOrder ? obtain(count) : EmptyArray.INT; getSpansRec(queryStart, queryEnd, kind, treeRoot(), ret, prioSortBuffer, orderSortBuffer, 0, sortByInsertionOrder); if (sortByInsertionOrder) { sort(ret, prioSortBuffer, orderSortBuffer); recycle(prioSortBuffer); recycle(orderSortBuffer); } return ret; }
Example 2
Source File: ContentResolver.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * @hide * Returns the package names of syncadapters that match a given user and authority. */ @TestApi public static String[] getSyncAdapterPackagesForAuthorityAsUser(String authority, @UserIdInt int userId) { try { return getContentService().getSyncAdapterPackagesForAuthorityAsUser(authority, userId); } catch (RemoteException e) { } return ArrayUtils.emptyArray(String.class); }
Example 3
Source File: PersistentDataStore.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public String[] getKeyboardLayouts(String inputDeviceDescriptor) { InputDeviceState state = getInputDeviceState(inputDeviceDescriptor, false); if (state == null) { return (String[])ArrayUtils.emptyArray(String.class); } return state.getKeyboardLayouts(); }
Example 4
Source File: PersistentDataStore.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
public String[] getKeyboardLayouts() { if (mKeyboardLayouts.isEmpty()) { return (String[])ArrayUtils.emptyArray(String.class); } return mKeyboardLayouts.toArray(new String[mKeyboardLayouts.size()]); }
Example 5
Source File: SpannableStringInternal.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
public <T> T[] getSpans(int queryStart, int queryEnd, Class<T> kind) { int count = 0; int spanCount = mSpanCount; Object[] spans = mSpans; int[] data = mSpanData; Object[] ret = null; Object ret1 = null; for (int i = 0; i < spanCount; i++) { int spanStart = data[i * COLUMNS + START]; int spanEnd = data[i * COLUMNS + END]; if (spanStart > queryEnd) { continue; } if (spanEnd < queryStart) { continue; } if (spanStart != spanEnd && queryStart != queryEnd) { if (spanStart == queryEnd) { continue; } if (spanEnd == queryStart) { continue; } } // verify span class as late as possible, since it is expensive if (kind != null && kind != Object.class && !kind.isInstance(spans[i])) { continue; } if (count == 0) { ret1 = spans[i]; count++; } else { if (count == 1) { ret = (Object[]) Array.newInstance(kind, spanCount - i + 1); ret[0] = ret1; } int prio = data[i * COLUMNS + FLAGS] & Spanned.SPAN_PRIORITY; if (prio != 0) { int j; for (j = 0; j < count; j++) { int p = getSpanFlags(ret[j]) & Spanned.SPAN_PRIORITY; if (prio > p) { break; } } System.arraycopy(ret, j, ret, j + 1, count - j); ret[j] = spans[i]; count++; } else { ret[count++] = spans[i]; } } } if (count == 0) { return (T[]) ArrayUtils.emptyArray(kind); } if (count == 1) { ret = (Object[]) Array.newInstance(kind, 1); ret[0] = ret1; return (T[]) ret; } if (count == ret.length) { return (T[]) ret; } Object[] nret = (Object[]) Array.newInstance(kind, count); System.arraycopy(ret, 0, nret, 0, count); return (T[]) nret; }
Example 6
Source File: SpellChecker.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private void createMisspelledSuggestionSpan(Editable editable, SuggestionsInfo suggestionsInfo, SpellCheckSpan spellCheckSpan, int offset, int length) { final int spellCheckSpanStart = editable.getSpanStart(spellCheckSpan); final int spellCheckSpanEnd = editable.getSpanEnd(spellCheckSpan); if (spellCheckSpanStart < 0 || spellCheckSpanEnd <= spellCheckSpanStart) return; // span was removed in the meantime final int start; final int end; if (offset != USE_SPAN_RANGE && length != USE_SPAN_RANGE) { start = spellCheckSpanStart + offset; end = start + length; } else { start = spellCheckSpanStart; end = spellCheckSpanEnd; } final int suggestionsCount = suggestionsInfo.getSuggestionsCount(); String[] suggestions; if (suggestionsCount > 0) { suggestions = new String[suggestionsCount]; for (int i = 0; i < suggestionsCount; i++) { suggestions[i] = suggestionsInfo.getSuggestionAt(i); } } else { suggestions = ArrayUtils.emptyArray(String.class); } SuggestionSpan suggestionSpan = new SuggestionSpan(mTextView.getContext(), suggestions, SuggestionSpan.FLAG_EASY_CORRECT | SuggestionSpan.FLAG_MISSPELLED); // TODO: Remove mIsSentenceSpellCheckSupported by extracting an interface // to share the logic of word level spell checker and sentence level spell checker if (mIsSentenceSpellCheckSupported) { final Long key = Long.valueOf(TextUtils.packRangeInLong(start, end)); final SuggestionSpan tempSuggestionSpan = mSuggestionSpanCache.get(key); if (tempSuggestionSpan != null) { if (DBG) { Log.i(TAG, "Cached span on the same position is cleard. " + editable.subSequence(start, end)); } editable.removeSpan(tempSuggestionSpan); } mSuggestionSpanCache.put(key, suggestionSpan); } editable.setSpan(suggestionSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mTextView.invalidateRegion(start, end, false /* No cursor involved */); }
Example 7
Source File: SpannableStringInternal.java From j2objc with Apache License 2.0 | 4 votes |
public <T> T[] getSpans(int queryStart, int queryEnd, Class<T> kind) { int count = 0; int spanCount = mSpanCount; Object[] spans = mSpans; int[] data = mSpanData; Object[] ret = null; Object ret1 = null; for (int i = 0; i < spanCount; i++) { if (kind != null && !kind.isInstance(spans[i])) { continue; } int spanStart = data[i * COLUMNS + START]; int spanEnd = data[i * COLUMNS + END]; if (spanStart > queryEnd) { continue; } if (spanEnd < queryStart) { continue; } if (spanStart != spanEnd && queryStart != queryEnd) { if (spanStart == queryEnd) { continue; } if (spanEnd == queryStart) { continue; } } if (count == 0) { ret1 = spans[i]; count++; } else { if (count == 1) { ret = (Object[]) Array.newInstance(kind, spanCount - i + 1); ret[0] = ret1; } int prio = data[i * COLUMNS + FLAGS] & Spanned.SPAN_PRIORITY; if (prio != 0) { int j; for (j = 0; j < count; j++) { int p = getSpanFlags(ret[j]) & Spanned.SPAN_PRIORITY; if (prio > p) { break; } } System.arraycopy(ret, j, ret, j + 1, count - j); ret[j] = spans[i]; count++; } else { ret[count++] = spans[i]; } } } if (count == 0) { return (T[]) ArrayUtils.emptyArray(kind); } if (count == 1) { ret = (Object[]) Array.newInstance(kind, 1); ret[0] = ret1; return (T[]) ret; } if (count == ret.length) { return (T[]) ret; } Object[] nret = (Object[]) Array.newInstance(kind, count); System.arraycopy(ret, 0, nret, 0, count); return (T[]) nret; }
Example 8
Source File: SpannableStringBuilder.java From j2objc with Apache License 2.0 | 4 votes |
/** * Return an array of the spans of the specified type that overlap * the specified range of the buffer. The kind may be Object.class to get * a list of all the spans regardless of type. */ @SuppressWarnings("unchecked") public <T> T[] getSpans(int queryStart, int queryEnd, Class<T> kind) { if (kind == null) return ArrayUtils.emptyArray(kind); int spanCount = mSpanCount; Object[] spans = mSpans; int[] starts = mSpanStarts; int[] ends = mSpanEnds; int[] flags = mSpanFlags; int gapstart = mGapStart; int gaplen = mGapLength; int count = 0; T[] ret = null; T ret1 = null; for (int i = 0; i < spanCount; i++) { int spanStart = starts[i]; if (spanStart > gapstart) { spanStart -= gaplen; } if (spanStart > queryEnd) { continue; } int spanEnd = ends[i]; if (spanEnd > gapstart) { spanEnd -= gaplen; } if (spanEnd < queryStart) { continue; } if (spanStart != spanEnd && queryStart != queryEnd) { if (spanStart == queryEnd) continue; if (spanEnd == queryStart) continue; } // Expensive test, should be performed after the previous tests if (!kind.isInstance(spans[i])) continue; if (count == 0) { // Safe conversion thanks to the isInstance test above ret1 = (T) spans[i]; count++; } else { if (count == 1) { // Safe conversion, but requires a suppressWarning ret = (T[]) Array.newInstance(kind, spanCount - i + 1); ret[0] = ret1; } int prio = flags[i] & SPAN_PRIORITY; if (prio != 0) { int j; for (j = 0; j < count; j++) { int p = getSpanFlags(ret[j]) & SPAN_PRIORITY; if (prio > p) { break; } } System.arraycopy(ret, j, ret, j + 1, count - j); // Safe conversion thanks to the isInstance test above ret[j] = (T) spans[i]; count++; } else { // Safe conversion thanks to the isInstance test above ret[count++] = (T) spans[i]; } } } if (count == 0) { return ArrayUtils.emptyArray(kind); } if (count == 1) { // Safe conversion, but requires a suppressWarning ret = (T[]) Array.newInstance(kind, 1); ret[0] = ret1; return ret; } if (count == ret.length) { return ret; } // Safe conversion, but requires a suppressWarning T[] nret = (T[]) Array.newInstance(kind, count); System.arraycopy(ret, 0, nret, 0, count); return nret; }
Example 9
Source File: Layout.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * Returns the same as <code>text.getSpans()</code>, except where * <code>start</code> and <code>end</code> are the same and are not * at the very beginning of the text, in which case an empty array * is returned instead. * <p> * This is needed because of the special case that <code>getSpans()</code> * on an empty range returns the spans adjacent to that range, which is * primarily for the sake of <code>TextWatchers</code> so they will get * notifications when text goes from empty to non-empty. But it also * has the unfortunate side effect that if the text ends with an empty * paragraph, that paragraph accidentally picks up the styles of the * preceding paragraph (even though those styles will not be picked up * by new text that is inserted into the empty paragraph). * <p> * The reason it just checks whether <code>start</code> and <code>end</code> * is the same is that the only time a line can contain 0 characters * is if it is the final paragraph of the Layout; otherwise any line will * contain at least one printing or newline character. The reason for the * additional check if <code>start</code> is greater than 0 is that * if the empty paragraph is the entire content of the buffer, paragraph * styles that are already applied to the buffer will apply to text that * is inserted into it. */ /* package */static <T> T[] getParagraphSpans(Spanned text, int start, int end, Class<T> type) { if (start == end && start > 0) { return ArrayUtils.emptyArray(type); } if(text instanceof SpannableStringBuilder) { return ((SpannableStringBuilder) text).getSpans(start, end, type, false); } else { return text.getSpans(start, end, type); } }