Java Code Examples for android.util.SparseIntArray#valueAt()
The following examples show how to use
android.util.SparseIntArray#valueAt() .
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: ActivityMetricsLogger.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Notifies the tracker that the app transition is starting. * * @param windowingModeToReason A map from windowing mode to a reason integer, which must be on * of ActivityTaskManagerInternal.APP_TRANSITION_* reasons. */ void notifyTransitionStarting(SparseIntArray windowingModeToReason, long timestamp) { if (!isAnyTransitionActive() || mLoggedTransitionStarting) { return; } if (DEBUG_METRICS) Slog.i(TAG, "notifyTransitionStarting"); mCurrentTransitionDelayMs = calculateDelay(timestamp); mLoggedTransitionStarting = true; for (int index = windowingModeToReason.size() - 1; index >= 0; index--) { final int windowingMode = windowingModeToReason.keyAt(index); final WindowingModeTransitionInfo info = mWindowingModeTransitionInfo.get( windowingMode); if (info == null) { continue; } info.reason = windowingModeToReason.valueAt(index); } if (allWindowsDrawn()) { reset(false /* abort */, null /* WindowingModeTransitionInfo */); } }
Example 2
Source File: ResizeHeightPostCallback.java From android-common-utils with Apache License 2.0 | 6 votes |
/** * @param lm the LayoutManager of LayoutManager * @param heightMap the height map , key is position,value is the height of position * @return the new height of RecyclerView */ protected int calculateHeight(RecyclerView.LayoutManager lm, SparseIntArray heightMap){ int spanCount = 1; if(lm instanceof GridLayoutManager){ spanCount = ((GridLayoutManager) lm).getSpanCount(); }else if(lm instanceof StaggeredGridLayoutManager){ spanCount = ((StaggeredGridLayoutManager) lm).getSpanCount(); } final int mapSize = heightMap.size(); int total = 0; for(int i = 0 ,size = mapSize % spanCount == 0 ? mapSize / spanCount: mapSize /spanCount + 1; i < size ; i++){ total = total + heightMap.valueAt(i); } return total; }
Example 3
Source File: BasePool.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example 4
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 5
Source File: CpuFrequencyMetrics.java From Battery-Metrics with MIT License | 6 votes |
/** * Based off {@link java.util.AbstractMap#equals} -- with simplifications because we're guaranteed * sparse int arrays with no nullable values or casts. * * <p>TODO Make this a utility method, along with hashcode. */ public static boolean sparseIntArrayEquals(SparseIntArray a, SparseIntArray b) { if (a == b) { return true; } int aSize = a.size(); if (aSize != b.size()) { return false; } // Sparse int arrays keep a sorted list of values: which means equality can just walk through // both arrays to check. for (int i = 0; i < aSize; i++) { if (a.keyAt(i) != b.keyAt(i) || a.valueAt(i) != b.valueAt(i)) { return false; } } return true; }
Example 6
Source File: SubGroupAdapter.java From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) { if (mGroupedKeyModels.size() > 0) { final int keyIndex = mGroupedKeyModels.keyAt(position); holder.groupItemContainer.setTag(keyIndex); final ApplicationKey key = mMeshNetwork.getAppKey(keyIndex); holder.mGroupAppKeyTitle.setText(key.getName()); final SparseIntArray groupedModels = mGroupedKeyModels.valueAt(position); holder.mGroupGrid.setRowCount(1); //Remove all child views to avoid duplicating holder.mGroupGrid.removeAllViews(); for (int i = 0; i < groupedModels.size(); i++) { final int modelId = groupedModels.keyAt(i); final int count = groupedModels.valueAt(i); inflateView(holder, keyIndex, modelId, count, i); } } }
Example 7
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; }
Example 8
Source File: CpuFrequencyMetrics.java From Battery-Metrics with MIT License | 5 votes |
/** * Subtracts b from the current value while being aware of core restarts. * * <p>Cpu clusters can be switched on and off as required by some devices: in those cases, the * measured frequency can go <em>down</em> across snapshots legally. * * <p>If the time in state for any core appears to have reduced, we can infer that the core was * switched off and restarted. In that case, a better approximation is the current value of the * snapshot instead of a meaningless subtraction. * * <p>Some tests make this behavior more explicit: {@see CpuFrequencyMetricsTest#testDiff} and * {@see CpuFrequencyMetricsTest#testDiffWithCoreReset} for expected behavior. */ @Override public CpuFrequencyMetrics diff( @Nullable CpuFrequencyMetrics b, @Nullable CpuFrequencyMetrics output) { if (output == null) { output = new CpuFrequencyMetrics(); } if (b == null) { output.set(this); } else { for (int i = 0; i < timeInStateS.length; i++) { SparseIntArray aCore = timeInStateS[i]; SparseIntArray bCore = b.timeInStateS[i]; SparseIntArray outputCore = output.timeInStateS[i]; boolean hasCoreReset = false; for (int j = 0, size = aCore.size(); j < size && !hasCoreReset; j++) { int frequency = aCore.keyAt(j); int difference = aCore.valueAt(j) - bCore.get(frequency, 0); if (difference < 0) { hasCoreReset = true; break; } outputCore.put(frequency, difference); } if (hasCoreReset) { copyArrayInto(aCore, outputCore); } } } return output; }
Example 9
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 10
Source File: CpuFrequencyMetrics.java From Battery-Metrics with MIT License | 5 votes |
/** Based off {@link AbstractMap#hashCode()}: returns the sum of the hashcodes of the entries. */ @Override public int hashCode() { int hash = 0; for (int i = 0; i < timeInStateS.length; i++) { SparseIntArray array = timeInStateS[i]; for (int j = 0, size = timeInStateS[i].size(); j < size; j++) { // hash of an integer is the integer itself - see {@link Integers#hashCode} hash += array.keyAt(j) ^ array.valueAt(j); } } return hash; }
Example 11
Source File: Binder.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Dump per uid binder proxy counts to the logcat. */ private void dumpPerUidProxyCounts() { SparseIntArray counts = BinderInternal.nGetBinderProxyPerUidCounts(); if (counts.size() == 0) return; Log.d(Binder.TAG, "Per Uid Binder Proxy Counts:"); for (int i = 0; i < counts.size(); i++) { final int uid = counts.keyAt(i); final int binderCount = counts.valueAt(i); Log.d(Binder.TAG, "UID : " + uid + " count = " + binderCount); } }
Example 12
Source File: GenericThemeEntry.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
private static boolean sparseIntArrayEquals(SparseIntArray a, SparseIntArray b) { if (a == b) return true; if (a == null) return b == null; if (b == null) return false; int size = a.size(); if (size != b.size()) return false; for (int i=0; i<size; ++i) { if (a.keyAt(i) != b.keyAt(i)) return false; if (a.valueAt(i) != b.valueAt(i)) return false; } return true; }
Example 13
Source File: CustomThemeHelper.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
public static boolean resolveAttribute(int attrId, TypedValue outValue) { SparseIntArray customAttrs = currentAttrs; if (customAttrs == null) return false; int index = customAttrs.indexOfKey(attrId); if (index < 0) return false; outValue.type = TypedValue.TYPE_INT_COLOR_ARGB8; outValue.data = customAttrs.valueAt(index); return true; }
Example 14
Source File: PriorityBlockingAggregatorQueue.java From tilt-game-android with MIT License | 5 votes |
@Override public String toString() { final ReentrantLock lock = this.mLock; lock.lock(); try { final StringBuilder stringBuilder = new StringBuilder(); if (this.mQueues.size() > 0) { final SparseArray<IList<T>> queues = this.mQueues; final SparseIntArray queueCapacities = this.mQueueCapacities; stringBuilder.append(" [\n"); final int queueCount = queues.size(); for (int i = 0; i < queueCount; i++) { final int priority = queues.keyAt(i); final IList<T> queue = queues.valueAt(i); final int queueCapacity = queueCapacities.valueAt(i); final int queueSize = queue.size(); stringBuilder.append("\tPriority: ").append(priority).append(" (Capacity: ").append(queueSize).append('/').append(queueCapacity).append("): "); stringBuilder.append(queue.toString()); if (i < (queueCount - 1)) { stringBuilder.append(','); } stringBuilder.append('\n'); } stringBuilder.append(']'); } return stringBuilder.toString(); } finally { lock.unlock(); } }
Example 15
Source File: IpConnectivityEventBuilder.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static Pair[] toPairArray(SparseIntArray counts) { final int s = counts.size(); Pair[] pairs = new Pair[s]; for (int i = 0; i < s; i++) { Pair p = new Pair(); p.key = counts.keyAt(i); p.value = counts.valueAt(i); pairs[i] = p; } return pairs; }
Example 16
Source File: BasePool.java From fresco with MIT License | 5 votes |
/** * 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 legacyInitBuckets(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, mPoolParams.fixBucketsReinitialization)); } mAllowNewBuckets = false; } else { mAllowNewBuckets = true; } }
Example 17
Source File: BasePool.java From fresco with MIT License | 5 votes |
/** * Clears and fills {@code mBuckets} with buckets * * @param bucketSizes bucket size to bucket's max length */ private void fillBuckets(SparseIntArray bucketSizes) { mBuckets.clear(); for (int i = 0; i < bucketSizes.size(); ++i) { final int bucketSize = bucketSizes.keyAt(i); final int maxLength = bucketSizes.valueAt(i); mBuckets.put( bucketSize, new Bucket<V>( getSizeInBytes(bucketSize), maxLength, 0, mPoolParams.fixBucketsReinitialization)); } }
Example 18
Source File: RecyclerObjectPool.java From Storm with Apache License 2.0 | 5 votes |
protected void moveItems(int fromPosition, int toPosition, int count) { final SparseIntArray positions = getPositions(); int index; int value; for (int i = fromPosition, delta = 0; i < fromPosition + count; i++, delta++) { index = positions.indexOfKey(i); if (index >= 0) { value = positions.valueAt(index); positions.removeAt(index); positions.put(toPosition + delta, value); } } }