android.util.SparseIntArray Java Examples
The following examples show how to use
android.util.SparseIntArray.
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: StreamConfigurationMap.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** Get the list of publically visible output formats; does not include IMPL_DEFINED */ private int[] getPublicFormats(boolean output) { int[] formats = new int[getPublicFormatCount(output)]; int i = 0; SparseIntArray map = getFormatsMap(output); for (int j = 0; j < map.size(); j++) { int format = map.keyAt(j); formats[i++] = imageFormatToPublic(format); } if (output) { for (int j = 0; j < mDepthOutputFormats.size(); j++) { formats[i++] = depthFormatToPublic(mDepthOutputFormats.keyAt(j)); } } if (formats.length != i) { throw new AssertionError("Too few formats " + i + ", expected " + formats.length); } return formats; }
Example #2
Source File: NetworkManagementService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void syncFirewallChainLocked(int chain, String name) { SparseIntArray rules; synchronized (mRulesLock) { final SparseIntArray uidFirewallRules = getUidFirewallRulesLR(chain); // Make a copy of the current rules, and then clear them. This is because // setFirewallUidRuleInternal only pushes down rules to the native daemon if they // are different from the current rules stored in the mUidFirewall*Rules array for // the specified chain. If we don't clear the rules, setFirewallUidRuleInternal // will do nothing. rules = uidFirewallRules.clone(); uidFirewallRules.clear(); } if (rules.size() > 0) { // Now push the rules. setFirewallUidRuleInternal will push each of these down to the // native daemon, and also add them to the mUidFirewall*Rules array for the specified // chain. if (DBG) Slog.d(TAG, "Pushing " + rules.size() + " active firewall " + name + "UID rules"); for (int i = 0; i < rules.size(); i++) { setFirewallUidRuleLocked(chain, rules.keyAt(i), rules.valueAt(i)); } } }
Example #3
Source File: BidiInfoActivity.java From Tehreer-Android with Apache License 2.0 | 6 votes |
private void writeLineText(SpannableStringBuilder builder, BidiLine line) { SparseIntArray visualMap = new SparseIntArray(); int counter = 1; for (BidiRun bidiRun : line.getVisualRuns()) { visualMap.put(bidiRun.charStart, counter); counter++; } int runCount = visualMap.size(); if (runCount > 0) { appendText(builder, "Visual Order\n", spansSecondHeading()); for (int i = 0; i < runCount; i++) { int runIndex = visualMap.valueAt(i); appendText(builder, "<Run " + runIndex + ">", spansInlineHeading()); appendText(builder, " "); } appendText(builder, "\n\n"); } }
Example #4
Source File: AdUnitRelativeLayout.java From unity-ads-android with Apache License 2.0 | 6 votes |
public SparseIntArray getEventCount(ArrayList<Integer> eventTypes) { SparseIntArray returnArray = new SparseIntArray(); synchronized (_motionEvents) { for (AdUnitMotionEvent currentEvent : _motionEvents) { for (Integer currentType : eventTypes) { if (currentEvent.getAction() == currentType) { returnArray.put(currentType, returnArray.get(currentType, 0) + 1); break; } } } } return returnArray; }
Example #5
Source File: GridLayoutManager.java From Telegram with GNU General Public License v2.0 | 6 votes |
static int findFirstKeyLessThan(SparseIntArray cache, int position) { int lo = 0; int hi = cache.size() - 1; while (lo <= hi) { // Using unsigned shift here to divide by two because it is guaranteed to not // overflow. final int mid = (lo + hi) >>> 1; final int midVal = cache.keyAt(mid); if (midVal < position) { lo = mid + 1; } else { hi = mid - 1; } } int index = lo - 1; if (index >= 0 && index < cache.size()) { return cache.keyAt(index); } return -1; }
Example #6
Source File: TsExtractor.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * @param mode Mode for the extractor. One of {@link #MODE_MULTI_PMT}, {@link #MODE_SINGLE_PMT} * and {@link #MODE_HLS}. * @param timestampAdjuster A timestamp adjuster for offsetting and scaling sample timestamps. * @param payloadReaderFactory Factory for injecting a custom set of payload readers. */ public TsExtractor( @Mode int mode, TimestampAdjuster timestampAdjuster, TsPayloadReader.Factory payloadReaderFactory) { this.payloadReaderFactory = Assertions.checkNotNull(payloadReaderFactory); this.mode = mode; if (mode == MODE_SINGLE_PMT || mode == MODE_HLS) { timestampAdjusters = Collections.singletonList(timestampAdjuster); } else { timestampAdjusters = new ArrayList<>(); timestampAdjusters.add(timestampAdjuster); } tsPacketBuffer = new ParsableByteArray(new byte[BUFFER_SIZE], 0); trackIds = new SparseBooleanArray(); trackPids = new SparseBooleanArray(); tsPayloadReaders = new SparseArray<>(); continuityCounters = new SparseIntArray(); durationReader = new TsDurationReader(); pcrPid = -1; resetPayloadReaders(); }
Example #7
Source File: ContactAdapter.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
@Override public Object[] getSections() { positionOfSection = new SparseIntArray(); sectionOfPosition = new SparseIntArray(); int count = getCount(); list = new ArrayList<String>(); list.add(getContext().getString(R.string.search_header)); positionOfSection.put(0, 0); sectionOfPosition.put(0, 0); for (int i = 1; i < count; i++) { String letter = getItem(i).getHeader(); System.err.println("contactadapter getsection getHeader:" + letter + " name:" + getItem(i).getUsername()); int section = list.size() - 1; if (list.get(section) != null && !list.get(section).equals(letter)) { list.add(letter); section++; positionOfSection.put(section, i); } sectionOfPosition.put(i, section); } return list.toArray(new String[list.size()]); }
Example #8
Source File: BannerCell.java From Tangram-Android with MIT License | 6 votes |
public void setSpecialInterval(JSONObject jsonObject) { if (jsonObject != null) { this.mSpecialInterval = new SparseIntArray(); for (String key : jsonObject.keySet()) { try { int index = Integer.parseInt(key); int value = jsonObject.getIntValue(key); if (value > 0) { this.mSpecialInterval.put(index, value); } } catch (Exception e) { } } } }
Example #9
Source File: BannerCell.java From Tangram-Android with MIT License | 6 votes |
public void setSpecialInterval(JSONObject jsonObject) { if (jsonObject != null) { this.mSpecialInterval = new SparseIntArray(); Iterator<String> itr = jsonObject.keys(); while (itr.hasNext()) { String key = itr.next(); try { int index = Integer.parseInt(key); int value = jsonObject.optInt(key); if (value > 0) { this.mSpecialInterval.put(index, value); } } catch (NumberFormatException e) { } } } }
Example #10
Source File: FlexByteArrayPoolTest.java From fresco with MIT License | 6 votes |
@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; }
Example #11
Source File: SavedStateScrolling.java From UltimateRecyclerView with Apache License 2.0 | 6 votes |
/** * Called by CREATOR. * * @param in na */ public SavedStateScrolling(Parcel in) { // Parcel 'in' has its parent(RecyclerView)'s saved state. // To restore it, class loader that loaded RecyclerView is required. Parcelable superState = in.readParcelable(RecyclerView.class.getClassLoader()); this.superState = superState != null ? superState : EMPTY_STATE; prevFirstVisiblePosition = in.readInt(); prevFirstVisibleChildHeight = in.readInt(); prevScrolledChildrenHeight = in.readInt(); prevScrollY = in.readInt(); scrollY = in.readInt(); childrenHeights = new SparseIntArray(); final int numOfChildren = in.readInt(); if (0 < numOfChildren) { for (int i = 0; i < numOfChildren; i++) { final int key = in.readInt(); final int value = in.readInt(); childrenHeights.put(key, value); } } }
Example #12
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 #13
Source File: FlexboxHelper.java From Collection-Android with MIT License | 6 votes |
/** * Returns if any of the children's {@link FlexItem#getOrder()} attributes are * changed from the last measurement. * * @return {@code true} if changed from the last measurement, {@code false} otherwise. */ boolean isOrderChangedFromLastMeasurement(SparseIntArray orderCache) { int childCount = mFlexContainer.getFlexItemCount(); if (orderCache.size() != childCount) { return true; } for (int i = 0; i < childCount; i++) { View view = mFlexContainer.getFlexItemAt(i); if (view == null) { continue; } FlexItem flexItem = (FlexItem) view.getLayoutParams(); if (flexItem.getOrder() != orderCache.get(i)) { return true; } } return false; }
Example #14
Source File: KeyMapper.java From J2ME-Loader with Apache License 2.0 | 6 votes |
public static void saveArrayPref(SharedPreferencesContainer container, SparseIntArray intArray) { JSONArray json = new JSONArray(); StringBuilder data = new StringBuilder().append("["); for (int i = 0; i < intArray.size(); i++) { data.append("{") .append("\"key\": ") .append(intArray.keyAt(i)).append(",") .append("\"value\": ") .append(intArray.valueAt(i)) .append("},"); json.put(data); } data.deleteCharAt(data.length() - 1); data.append("]"); container.putString(PREF_KEY, intArray.size() == 0 ? null : data.toString()); container.apply(); }
Example #15
Source File: BottomNavigationViewEx.java From playa with MIT License | 5 votes |
MyOnNavigationItemSelectedListener(ViewPager viewPager, BottomNavigationViewEx bnve, boolean smoothScroll, OnNavigationItemSelectedListener listener) { this.viewPagerRef = new WeakReference<>(viewPager); this.listener = listener; this.smoothScroll = smoothScroll; // create items Menu menu = bnve.getMenu(); int size = menu.size(); items = new SparseIntArray(size); for (int i = 0; i < size; i++) { int itemId = menu.getItem(i).getItemId(); items.put(itemId, i); } }
Example #16
Source File: ResourcesManager.java From MultiTypeRecyclerViewAdapter with Apache License 2.0 | 5 votes |
private void registerLevel(int level) { LevelManager typesManager = mLevelManagerMap.get(level); final SparseIntArray typeRes = typesManager.typeRes; final int size = typeRes.size(); for (int i = 0; i < size; i++) { final int type = typeRes.keyAt(i); final int layoutResId = typeRes.valueAt(i); if (layoutResId == 0) { throw new RuntimeException(String.format(Locale.getDefault(), "are you sure register the layoutResId of level = %d?", type)); } mLevelMap.put(type, level); mLayoutMap.put(type, layoutResId); } mAttrMap.put(level, new AttrEntity(typesManager.minSize, typesManager.isFolded)); final int headerResId = typesManager.headerResId; if (headerResId != 0) { final int headerType = level - RecyclerViewAdapterHelper.HEADER_TYPE_DIFFER; mLevelMap.put(headerType, level); mLayoutMap.put(headerType, headerResId); } final int footerResId = typesManager.footerResId; if (footerResId != 0) { final int footerType = level - RecyclerViewAdapterHelper.FOOTER_TYPE_DIFFER; mLevelMap.put(footerType, level); mLayoutMap.put(footerType, footerResId); } }
Example #17
Source File: DefaultByteArrayPoolParams.java From fresco with MIT License | 5 votes |
/** 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); }
Example #18
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 #19
Source File: BaseAdapter.java From MvpRoute with Apache License 2.0 | 5 votes |
public BaseAdapter(Collection<T> data, @LayoutRes int layout, OnItemClickListener<V> listener) { this.data = new ArrayList<>(); if (data != null) { this.data.addAll(data); } this.layouts = layout; this.listener = listener; spLayout = new SparseIntArray(); spLayout.put(TYPE_NOMAL, this.layouts); headerList.addChangeListener(this); }
Example #20
Source File: GenericByteArrayPool.java From fresco with MIT License | 5 votes |
/** * Creates a new instance of the GenericByteArrayPool class * * @param memoryTrimmableRegistry the memory manager to register with * @param poolParams provider for pool parameters * @param poolStatsTracker */ public GenericByteArrayPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker) { super(memoryTrimmableRegistry, poolParams, poolStatsTracker); final SparseIntArray bucketSizes = poolParams.bucketSizes; mBucketSizes = new int[bucketSizes.size()]; for (int i = 0; i < bucketSizes.size(); ++i) { mBucketSizes[i] = bucketSizes.keyAt(i); } initialize(); }
Example #21
Source File: BufferMemoryChunkPoolTest.java From fresco with MIT License | 5 votes |
@Before public void setup() { final SparseIntArray bucketSizes = new SparseIntArray(); bucketSizes.put(32, 2); bucketSizes.put(64, 1); bucketSizes.put(128, 1); mPool = new FakeBufferMemoryChunkPool(new PoolParams(128, bucketSizes)); }
Example #22
Source File: WrapAdapter.java From RecyclerViewTools with Apache License 2.0 | 5 votes |
private static View findViewByType(int viewType, List<View> views, SparseIntArray hashToType) { for (int i = 0, size = views.size(); i < size; i++) { View v = views.get(i); int thisViewType = hashToType.get(v.hashCode()); if (thisViewType == viewType) { return v; } } return null; }
Example #23
Source File: SimpleTest.java From unmock-plugin with Apache License 2.0 | 5 votes |
@Test public void testSparseIntArray() { SparseIntArray sia = new SparseIntArray(); sia.put(12, 999); sia.put(99, 12); assertEquals(999, sia.get(12)); }
Example #24
Source File: NativeMemoryChunkPoolTest.java From fresco with MIT License | 5 votes |
@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)); }
Example #25
Source File: BannerView.java From Tangram-Android with MIT License | 5 votes |
public void setAutoScroll(int intervalInMillis, SparseIntArray intervalArray) { if (0 == intervalInMillis) { return; } if (timer != null) { disableAutoScroll(); } timer = new TimerHandler(this, intervalInMillis); timer.setSpecialInterval(intervalArray); startTimer(); }
Example #26
Source File: AccountSpinnerAdapter.java From PADListener with GNU General Public License v2.0 | 5 votes |
public AccountSpinnerAdapter(Context context, List<PADHerderAccountModel> accounts) { super(context, android.R.layout.simple_spinner_item); final List<String> labels = new ArrayList<String>(); accountIdsByPosition = new SparseIntArray(); int i = 0 ; for(final PADHerderAccountModel account : accounts) { labels.add(account.getLogin()); accountIdsByPosition.put(i, account.getAccountId()); i++; } super.addAll(labels); }
Example #27
Source File: RecyclerListView.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private void cleanupCache() { sectionCache = new SparseIntArray(); sectionPositionCache = new SparseIntArray(); sectionCountCache = new SparseIntArray(); count = -1; sectionCount = -1; }
Example #28
Source File: RxDataTool.java From RxTools-master with Apache License 2.0 | 5 votes |
/** * 判断对象是否为空 * * @param obj 对象 * @return {@code true}: 为空<br>{@code false}: 不为空 */ public static boolean isEmpty(Object obj) { if (obj == null) { return true; } if (obj instanceof String && obj.toString().length() == 0) { return true; } if (obj.getClass().isArray() && Array.getLength(obj) == 0) { return true; } if (obj instanceof Collection && ((Collection) obj).isEmpty()) { return true; } if (obj instanceof Map && ((Map) obj).isEmpty()) { return true; } if (obj instanceof SparseArray && ((SparseArray) obj).size() == 0) { return true; } if (obj instanceof SparseBooleanArray && ((SparseBooleanArray) obj).size() == 0) { return true; } if (obj instanceof SparseIntArray && ((SparseIntArray) obj).size() == 0) { return true; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (obj instanceof SparseLongArray && ((SparseLongArray) obj).size() == 0) { return true; } } return false; }
Example #29
Source File: GameBoardView.java From tedroid with Apache License 2.0 | 5 votes |
/** Inicializa los sonidos a reproducir. */ private void setUpSounds() { if (isSoundEnabled()) { soundPool = new SoundPool(6, AudioManager.STREAM_MUSIC, 0); soundPoolMap = new SparseIntArray(6); soundPoolMap.put(DROP_SOUND, soundPool.load(getContext(), R.raw.on_drop, 1)); soundPoolMap.put(GAME_OVER_SOUND, soundPool.load(getContext(), R.raw.on_game_over, 1)); soundPoolMap.put(LEVEL_UP_SOUND, soundPool.load(getContext(), R.raw.on_level_up, 1)); soundPoolMap.put(LINE_CLEAR_SOUND, soundPool.load(getContext(), R.raw.on_line_clear, 1)); soundPoolMap.put(PAUSE_SOUND, soundPool.load(getContext(), R.raw.on_pause, 1)); soundPoolMap.put(ROTATE_SOUND, soundPool.load(getContext(), R.raw.on_rotate, 1)); } }
Example #30
Source File: TrainSchListAty.java From Huochexing12306 with Apache License 2.0 | 5 votes |
private List<Map<String, String>> getTicketTrains() { List<Map<String, String>> lstTicketTrains = new ArrayList<Map<String, String>>(); List<Integer> lstTemp = new ArrayList<Integer>(); TrainHelper tHelper = new TrainHelper(); SparseIntArray saTrainSpeeds = tHelper.getTrainSpeeds(); for (int i = 0; i < mLstInfos.size(); i++) { QueryLeftNewDTOInfo qldInfo = mLstInfos.get(i) .getQueryLeftNewDTO(); if (!lstTemp.contains(qldInfo.getSpeed_index()) || qldInfo.isHasPreferentialPrice()){ if (!qldInfo.isHasPreferentialPrice()){ lstTemp.add(qldInfo.getSpeed_index()); } Map<String, String> map = new HashMap<String, String>(); map.put(TT.TRAIN_NO, qldInfo.getTrain_no()); String strName = ""; for(int j=0; j<saTrainSpeeds.size(); j++){ if (saTrainSpeeds.valueAt(j) == qldInfo.getSpeed_index()){ strName = tHelper.getTrainNames().get(saTrainSpeeds.keyAt(j)); break; } } map.put(TT.TRAIN_CLASS_NAME, qldInfo.isHasPreferentialPrice()? ("<font color='#ff8c00'>[折]</font>"+qldInfo.getStation_train_code()):strName); map.put(TT.FROM_STATION_NO, qldInfo.getFrom_station_no()); map.put(TT.TO_STATION_NO, qldInfo.getTo_station_no()); map.put(TT.SEAT_TYPES, qldInfo.getSeat_types()); lstTicketTrains.add(map); } } return lstTicketTrains; }