下面列出了android.util.SparseIntArray#append ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static int getKeyIndexLocked(int key, SparseIntArray keyToIndexMap,
MemoryIntArray backingStore) throws IOException {
int index = keyToIndexMap.get(key, -1);
if (index < 0) {
index = findNextEmptyIndex(backingStore);
if (index >= 0) {
backingStore.set(index, 1);
keyToIndexMap.append(key, index);
if (DEBUG) {
Slog.i(LOG_TAG, "Allocated index:" + index + " for key:"
+ SettingsProvider.keyToString(key));
}
} else {
Slog.e(LOG_TAG, "Could not allocate generation index");
}
}
return index;
}
private void readSparseIntArrayInternal(SparseIntArray outVal, int N) {
while (N > 0) {
int key = readInt();
int value = readInt();
outVal.append(key, value);
N--;
}
}
public AppsRecyclerViewAdapter(List<App> appList, BaldActivity activity, AppsActivity.ChangeAppListener changeAppListener, RecyclerView caller) {
this.caller = caller;
this.activity = activity;
this.layoutInflater = LayoutInflater.from(activity);
selectedDrawable = ContextCompat.getDrawable(activity, R.drawable.btn_selected);
elevation =
TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
16,
activity.getResources().getDisplayMetrics());
this.changeAppListener = changeAppListener;
this.appsOneGrid = BPrefs.get(activity).getBoolean(BPrefs.APPS_ONE_GRID_KEY, BPrefs.APPS_ONE_GRID_DEFAULT_VALUE);
letterToPosition = new SparseIntArray();
dataList = new ArrayList<>((int) (appList.size() * 1.5));
String lastChar = "";
String disChar;
for (int i = 0; i < appList.size(); i++) {
disChar = appList.get(i).getLabel().substring(0, 1).toUpperCase();
if (!appsOneGrid && !disChar.equals(lastChar)) {
dataList.add(new AppStickyHeader(disChar));
letterToPosition.append(disChar.charAt(0), dataList.size() - 1);
}
dataList.add(appList.get(i));
lastChar = disChar;
}
final TypedValue typedValue = new TypedValue();
Resources.Theme theme = activity.getTheme();
theme.resolveAttribute(R.attr.bald_text_on_selected, typedValue, true);
textColorOnSelected = typedValue.data;
theme.resolveAttribute(R.attr.bald_text_on_background, typedValue, true);
textColorOnBackground = typedValue.data;
}
private int[] sortOrdersIntoReorderedIndices(int childCount, List<Order> orders,
SparseIntArray orderCache) {
Collections.sort(orders);
orderCache.clear();
int[] reorderedIndices = new int[childCount];
int i = 0;
for (Order order : orders) {
reorderedIndices[i] = order.index;
orderCache.append(order.index, order.order);
i++;
}
return reorderedIndices;
}
public UserPagerAdapter(Activity context, User user, FragmentManager fm) {
super(fm);
mActivity = context;
mUser = user;
mArray = new SparseIntArray(6);
mId = User.getUserId(mUser.path);
int key = 0;
if (user.getUpvoted() > 0) {
mArray.append(key, UPVOTED);
key++;
}
if (user.getCreated() > 0) {
mArray.append(key, CREATED);
key++;
}
if (user.getShowcased() > 0) {
mArray.append(key, SHOWCASED);
key++;
}
if (user.getCollections() > 0) {
mArray.append(key, COLLECTIONS);
key++;
}
if (user.getFollowers() > 0) {
mArray.append(key, FOLLOWERS);
key++;
}
if (user.getFollowing() > 0) {
mArray.append(key, FOLLOWING);
key++;
}
}
SparseIntArray countAvailableAttributesPerType(List<Attribute> attributeFilter) {
// Get Content filtered by current selection
long[] filteredContent = selectFilteredContent(attributeFilter, false);
// Get available attributes of the resulting content list
QueryBuilder<Attribute> query = store.boxFor(Attribute.class).query();
if (filteredContent.length > 0)
query.link(Attribute_.contents).in(Content_.id, filteredContent).in(Content_.status, libraryStatus);
else
query.link(Attribute_.contents).in(Content_.status, libraryStatus);
List<Attribute> attributes = query.build().find();
SparseIntArray result = new SparseIntArray();
// SELECT field, COUNT(*) GROUP BY (field) is not implemented in ObjectBox v2.3.1
// (see https://github.com/objectbox/objectbox-java/issues/422)
// => Group by and count have to be done manually (thanks God Stream exists !)
// Group and count by type
Map<AttributeType, List<Attribute>> map = Stream.of(attributes).collect(Collectors.groupingBy(Attribute::getType));
for (Map.Entry<AttributeType, List<Attribute>> entry : map.entrySet()) {
AttributeType t = entry.getKey();
int size = (null == entry.getValue()) ? 0 : entry.getValue().size();
result.append(t.getCode(), size);
}
return result;
}
private static SparseIntArray makeBucketSizeArray(int... params) {
Preconditions.checkArgument(params.length % 2 == 0);
final SparseIntArray bucketSizes = new SparseIntArray();
for (int i = 0; i < params.length; i += 2) {
bucketSizes.append(params[i], params[i + 1]);
}
return bucketSizes;
}
MainViewAdapter(AppCompatActivity activity) {
this.activity = activity;
setHasStableIds(true);
PopupMenu p = new PopupMenu(activity, null);
Menu menu = p.getMenu();
activity.getMenuInflater().inflate(R.menu.main_activity_screens, menu);
positionToId = new SparseIntArray(menu.size());
for (int i = 0; i < menu.size(); i++) {
positionToId.append(i, menu.getItem(i).getItemId());
}
}
private static void copyArrayInto(SparseIntArray source, SparseIntArray destination) {
destination.clear();
for (int i = 0; i < source.size(); i++) {
destination.append(source.keyAt(i), source.valueAt(i));
}
}