当前位置: 首页>>代码示例>>Java>>正文


Java SparseIntArray.keyAt方法代码示例

本文整理汇总了Java中android.util.SparseIntArray.keyAt方法的典型用法代码示例。如果您正苦于以下问题:Java SparseIntArray.keyAt方法的具体用法?Java SparseIntArray.keyAt怎么用?Java SparseIntArray.keyAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.util.SparseIntArray的用法示例。


在下文中一共展示了SparseIntArray.keyAt方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initBuckets

import android.util.SparseIntArray; //导入方法依赖的package包/类
/**
 * 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;
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:BasePool.java

示例2: getMaxAnswersId

import android.util.SparseIntArray; //导入方法依赖的package包/类
private int getMaxAnswersId() {
  int max = 0;
  int id = 0;

  SparseIntArray answers = new SparseIntArray();
  for (QA qa : socTest.getQa()) {
    int answer = qa.getAnswer();
    answers.put(answer, answers.get(answer, 0) + 1);
  }

  for (int i = 0; i < answers.size(); i++) {
    if (max < answers.valueAt(i)) {
      max = answers.valueAt(i);
      id = answers.keyAt(i);
    }
  }

  return id;
}
 
开发者ID:Komdosh,项目名称:SocEltech,代码行数:20,代码来源:TestViewActivity.java

示例3: binarySearch

import android.util.SparseIntArray; //导入方法依赖的package包/类
/**
 * Binary search for the closest value that's smaller than or equal to {@code value}, and
 * return the corresponding key.
 */
private static int binarySearch(SparseIntArray array, int value) {
    final int size = array.size();
    int lo = 0;
    int hi = size - 1;

    while (lo <= hi) {
        final int mid = (lo + hi) >>> 1;
        final int midVal = array.valueAt(mid);

        if (midVal < value) {
            lo = mid + 1;
        } else if (midVal > value) {
            hi = mid - 1;
        } else {
            return array.keyAt(mid);  // value found
        }
    }
    // Value not found. Return the last item before our search range, which is the closest
    // value smaller than the value we are looking for.
    return array.keyAt(lo - 1);
}
 
开发者ID:Trumeet,项目名称:SetupWizardLibCompat,代码行数:26,代码来源:ItemGroup.java

示例4: adjustPosition

import android.util.SparseIntArray; //导入方法依赖的package包/类
/**
 * 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();

    for (int i = 0, size = positions.size(); i < size; 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) {
            //if we removed items and we are within the bounds we have to check if the item was removed
            //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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:AdapterUtil.java

示例5: GenericByteArrayPool

import android.util.SparseIntArray; //导入方法依赖的package包/类
/**
 * 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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:GenericByteArrayPool.java

示例6: NativeMemoryChunkPool

import android.util.SparseIntArray; //导入方法依赖的package包/类
/**
 * Creates a new instance of the NativeMemoryChunkPool class
 * @param memoryTrimmableRegistry the memory manager to register with
 * @param poolParams provider for pool parameters
 * @param nativeMemoryChunkPoolStatsTracker
 */
public NativeMemoryChunkPool(
    MemoryTrimmableRegistry memoryTrimmableRegistry,
    PoolParams poolParams,
    PoolStatsTracker nativeMemoryChunkPoolStatsTracker) {
  super(memoryTrimmableRegistry, poolParams, nativeMemoryChunkPoolStatsTracker);
  SparseIntArray bucketSizes = poolParams.bucketSizes;
  mBucketSizes = new int[bucketSizes.size()];
  for (int i = 0; i < mBucketSizes.length; ++i) {
    mBucketSizes[i] = bucketSizes.keyAt(i);
  }
  initialize();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:NativeMemoryChunkPool.java

示例7: isRunning

import android.util.SparseIntArray; //导入方法依赖的package包/类
public static boolean isRunning(SparseIntArray status) {
    if (status == null) {
        return false;
    }
    int size = status.size();
    for (int i = 0; i < size; ++i) {
        int processState = status.keyAt(i);
        if (isProcess(processState)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:14,代码来源:BreventResponse.java

示例8: isService

import android.util.SparseIntArray; //导入方法依赖的package包/类
public static boolean isService(@NonNull SparseIntArray status) {
    int size = status.size();
    for (int i = 0; i < size; ++i) {
        int processState = status.keyAt(i);
        if (isService(processState)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:11,代码来源:BreventResponse.java

示例9: isSafe

import android.util.SparseIntArray; //导入方法依赖的package包/类
public static boolean isSafe(@NonNull SparseIntArray status) {
    int size = status.size();
    for (int i = 0; i < size; ++i) {
        int processState = status.keyAt(i);
        if (BreventResponse.isProcess(processState) && !HideApiOverride.isSafe(processState)) {
            return false;
        }
    }
    return true;
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:11,代码来源:BreventResponse.java

示例10: isForegroundService

import android.util.SparseIntArray; //导入方法依赖的package包/类
public static boolean isForegroundService(@NonNull SparseIntArray status) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        int size = status.size();
        for (int i = 0; i < size; ++i) {
            int processState = status.keyAt(i);
            if (HideApiOverride.isForegroundService(processState)) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:13,代码来源:BreventResponse.java

示例11: dropViews

import android.util.SparseIntArray; //导入方法依赖的package包/类
void dropViews(SparseIntArray viewsToDrop) {
  for (int i = 0, count = viewsToDrop.size(); i < count; i++) {
    int viewToDrop = viewsToDrop.keyAt(i);
    View view = null;
    if (viewToDrop > 0) {
      try {
        view = resolveView(viewToDrop);
        dropView(view);
      } catch (Exception e) {
        // the view is already dropped, nothing we can do
      }
    } else {
      // Root views are noted with a negative tag from StateBuilder.
      removeRootView(-viewToDrop);
    }

    int parentTag = viewsToDrop.valueAt(i);
    // this only happens for clipped, non-root views - clipped because there is no parent, and
    // not a root view (because we explicitly pass -1 for root views).
    if (parentTag > 0 && view != null && view.getParent() == null) {
      // this can only happen if the parent exists (if the parent were removed first, it'd also
      // remove the child, so trying to explicitly remove the child afterwards would crash at
      // the resolveView call above) - we also explicitly check for a null parent, implying that
      // we are either clipped (or that we already removed the child from its parent, in which
      // case this will essentially be a no-op).
      View parent = resolveView(parentTag);
      if (parent instanceof FlatViewGroup) {
        ((FlatViewGroup) parent).onViewDropped(view);
      }
    }
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:33,代码来源:FlatNativeViewHierarchyManager.java

示例12: restoreTab

import android.util.SparseIntArray; //导入方法依赖的package包/类
private void restoreTab(
        TabRestoreDetails tabToRestore, TabState tabState, boolean setAsActive) {
    // If we don't have enough information about the Tab, bail out.
    boolean isIncognito = isIncognitoTabBeingRestored(tabToRestore, tabState);
    if (tabState == null) {
        if (tabToRestore.isIncognito == null) {
            Log.w(TAG, "Failed to restore tab: not enough info about its type was available.");
            return;
        } else if (isIncognito) {
            Log.i(TAG, "Failed to restore Incognito tab: its TabState could not be restored.");
            return;
        }
    }

    TabModel model = mTabModelSelector.getModel(isIncognito);
    SparseIntArray restoredTabs = isIncognito ? mIncognitoTabsRestored : mNormalTabsRestored;
    int restoredIndex = 0;
    if (tabToRestore.fromMerge) {
        // Put any tabs being merged into this list at the end.
        restoredIndex = mTabModelSelector.getModel(isIncognito).getCount();
    } else if (restoredTabs.size() > 0
            && tabToRestore.originalIndex > restoredTabs.keyAt(restoredTabs.size() - 1)) {
        // If the tab's index is too large, restore it at the end of the list.
        restoredIndex = restoredTabs.size();
    } else {
         // Otherwise try to find the tab we should restore before, if any.
        for (int i = 0; i < restoredTabs.size(); i++) {
            if (restoredTabs.keyAt(i) > tabToRestore.originalIndex) {
                Tab nextTabByIndex = TabModelUtils.getTabById(model, restoredTabs.valueAt(i));
                restoredIndex = nextTabByIndex != null ? model.indexOf(nextTabByIndex) : -1;
                break;
            }
        }
    }

    int tabId = tabToRestore.id;
    if (tabState != null) {
        mTabCreatorManager.getTabCreator(isIncognito).createFrozenTab(
                tabState, tabToRestore.id, restoredIndex);
    } else {
        Log.w(TAG, "Failed to restore TabState; creating Tab with last known URL.");
        Tab fallbackTab = mTabCreatorManager.getTabCreator(isIncognito).createNewTab(
                new LoadUrlParams(tabToRestore.url), TabModel.TabLaunchType.FROM_RESTORE, null);
        tabId = fallbackTab.getId();
        model.moveTab(tabId, restoredIndex);
    }

    // If the tab is being restored from a merge and its index is 0, then the model being
    // merged into doesn't contain any tabs. Select the first tab to avoid having no tab
    // selected. TODO(twellington): The first tab will always be selected. Instead, the tab that
    // was selected in the other model before the merge should be selected after the merge.
    if (setAsActive || (tabToRestore.fromMerge && restoredIndex == 0)) {
        boolean wasIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();
        int selectedModelTabCount = mTabModelSelector.getCurrentModel().getCount();

        TabModelUtils.setIndex(model, TabModelUtils.getTabIndexById(model, tabId));
        boolean isIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();

        // Setting the index will cause the tab's model to be selected. Set it back to the model
        // that was selected before setting the index if the index is being set during a merge
        // unless the previously selected model is empty (e.g. showing the empty background
        // view on tablets).
        if (tabToRestore.fromMerge
                && wasIncognitoTabModelSelected != isIncognitoTabModelSelected
                && selectedModelTabCount != 0) {
            mTabModelSelector.selectModel(wasIncognitoTabModelSelected);
        }
    }
    restoredTabs.put(tabToRestore.originalIndex, tabId);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:71,代码来源:TabPersistentStore.java

示例13: getDescription

import android.util.SparseIntArray; //导入方法依赖的package包/类
public String getDescription(String packageName) {
    SparseIntArray status;
    synchronized (updateLock) {
        status = mProcesses.get(packageName);
    }
    if (status == null) {
        return null;
    }
    int cached = 0;
    int service = 0;
    int top = 0;
    int total = 0;

    int size = status.size();
    for (int i = 0; i < size; ++i) {
        int processState = status.keyAt(i);
        if (BreventResponse.isProcess(processState)) {
            total++;
            if (BreventResponse.isTop(processState)) {
                top++;
            } else if (BreventResponse.isService(processState)) {
                service++;
            } else if (BreventResponse.isCached(processState)) {
                cached++;
            }
        }
    }

    if (top == total) {
        return getString(R.string.process_all_top, top)
                + getResources().getQuantityString(R.plurals.process_process, top);
    } else if (service == total) {
        return getString(R.string.process_all_service, service)
                + getResources().getQuantityString(R.plurals.process_process, service);
    } else if (cached == total) {
        return getString(R.string.process_all_cached, cached)
                + getResources().getQuantityString(R.plurals.process_process, cached);
    } else if (top == 0 && service == 0 && cached == 0) {
        return getString(R.string.process_all_total, total)
                + getResources().getQuantityString(R.plurals.process_process, total);
    } else {
        StringBuilder sb = new StringBuilder();
        if (service > 0) {
            sb.append(getString(R.string.process_service, service));
            sb.append(", ");
        }
        if (total > 0) {
            sb.append(getString(R.string.process_total, total));
        }
        sb.append(getResources().getQuantityString(R.plurals.process_process, total));
        return sb.toString();
    }
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:54,代码来源:BreventActivity.java


注:本文中的android.util.SparseIntArray.keyAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。