android.util.SparseIntArray#valueAt ( )源码实例Demo

下面列出了android.util.SparseIntArray#valueAt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: ActivityMetricsLogger.java
/**
 * 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 */);
    }
}
 
@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);
        }
    }
}
 
源代码3 项目: Battery-Metrics   文件: CpuFrequencyMetrics.java
/**
 * 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;
}
 
源代码4 项目: Tehreer-Android   文件: BidiInfoActivity.java
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");
    }
}
 
源代码5 项目: FanXin-based-HuanXin   文件: 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;
  }
}
 
/**
 * @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;
}
 
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;
}
 
源代码8 项目: android_9.0.0_r45   文件: Binder.java
/**
 * 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);
    }
}
 
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);
    }
}
 
源代码10 项目: Huochexing12306   文件: TrainSchListAty.java
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;
}
 
源代码11 项目: Battery-Metrics   文件: CpuFrequencyMetrics.java
/**
 * 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;
}
 
源代码12 项目: Battery-Metrics   文件: CpuFrequencyMetrics.java
/** 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;
}
 
源代码13 项目: Overchan-Android   文件: GenericThemeEntry.java
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;
}
 
源代码14 项目: Overchan-Android   文件: CustomThemeHelper.java
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;
}
 
@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();
	}
}
 
源代码16 项目: fresco   文件: 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 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;
  }
}
 
源代码17 项目: fresco   文件: BasePool.java
/**
 * 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));
  }
}
 
源代码18 项目: Storm   文件: RecyclerObjectPool.java
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);
        }
    }
}