androidx.collection.SparseArrayCompat Java Examples
The following examples show how to use
androidx.collection.SparseArrayCompat.
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: ComponentHostUtils.java From litho with Apache License 2.0 | 6 votes |
/** * Moves an item from oldIndex to newIndex. The item is taken from scrapitems if an item exists in * scrapItems at oldPosition. Otherwise the item is taken from items. This assumes that there is * no item at newIndex for the items array. If that's the case {@link * ComponentHostUtils#scrapItemAt(int, SparseArrayCompat, SparseArrayCompat)} has to be called * before invoking this. */ static <T> void moveItem( int oldIndex, int newIndex, SparseArrayCompat<T> items, SparseArrayCompat<T> scrapItems) { T itemToMove; if (existsScrapItemAt(oldIndex, scrapItems)) { // Before moving the item from items we need to check whether an old item has been put in // the scrapItems array. If there is an item at oldIndex there, it means that in // items at position oldIndex there's now something else and the correct item to move to // newIndex is instead in the scrapItems SparseArray. itemToMove = scrapItems.get(oldIndex); scrapItems.remove(oldIndex); } else { itemToMove = items.get(oldIndex); items.remove(oldIndex); } items.put(newIndex, itemToMove); }
Example #2
Source File: BaseTaskViewDescriptor.java From opentasks with Apache License 2.0 | 6 votes |
protected <T extends View> T getView(View view, int viewId) { SparseArrayCompat<View> viewHolder = (SparseArrayCompat<View>) view.getTag(); if (viewHolder == null) { viewHolder = new SparseArrayCompat<View>(); view.setTag(viewHolder); } View res = viewHolder.get(viewId); if (res == null) { res = view.findViewById(viewId); viewHolder.put(viewId, res); } return (T) res; }
Example #3
Source File: LottieComposition.java From lottie-android with Apache License 2.0 | 6 votes |
@RestrictTo(RestrictTo.Scope.LIBRARY) public void init(Rect bounds, float startFrame, float endFrame, float frameRate, List<Layer> layers, LongSparseArray<Layer> layerMap, Map<String, List<Layer>> precomps, Map<String, LottieImageAsset> images, SparseArrayCompat<FontCharacter> characters, Map<String, Font> fonts, List<Marker> markers) { this.bounds = bounds; this.startFrame = startFrame; this.endFrame = endFrame; this.frameRate = frameRate; this.layers = layers; this.layerMap = layerMap; this.precomps = precomps; this.images = images; this.characters = characters; this.fonts = fonts; this.markers = markers; }
Example #4
Source File: LottieValueAnimatorUnitTest.java From lottie-android with Apache License 2.0 | 5 votes |
private LottieComposition createComposition(int startFrame, int endFrame) { LottieComposition composition = new LottieComposition(); composition.init(new Rect(), startFrame, endFrame, 1000, new ArrayList<Layer>(), new LongSparseArray<Layer>(0), new HashMap<String, List<Layer>>(0), new HashMap<String, LottieImageAsset>(0), new SparseArrayCompat<FontCharacter>(0), new HashMap<String, Font>(0), new ArrayList<Marker>()); return composition; }
Example #5
Source File: LottieCompositionMoshiParser.java From lottie-android with Apache License 2.0 | 5 votes |
private static void parseChars( JsonReader reader, LottieComposition composition, SparseArrayCompat<FontCharacter> characters) throws IOException { reader.beginArray(); while (reader.hasNext()) { FontCharacter character = FontCharacterParser.parse(reader, composition); characters.put(character.hashCode(), character); } reader.endArray(); }
Example #6
Source File: ExportFragment.java From AppOpsX with MIT License | 5 votes |
private void export() { SparseArrayCompat<AppInfo> checkedApps = adapter.getCheckedApps(); final int size = checkedApps.size(); AppInfo[] appInfos = new AppInfo[size]; for (int i = 0; i < size; i++) { appInfos[i] = checkedApps.valueAt(i); } mPresenter.export(appInfos); }
Example #7
Source File: ComponentHostUtils.java From litho with Apache License 2.0 | 5 votes |
/** * Takes the item at position index from items and puts it into scrapItems. If no such item exists * the invocation of this method will have no effect. */ static <T> void scrapItemAt( int index, SparseArrayCompat<T> items, SparseArrayCompat<T> scrapItems) { if (items == null || scrapItems == null) { return; } final T value = items.get(index); if (value != null) { scrapItems.put(index, value); } }
Example #8
Source File: TreeDiffingTest.java From litho with Apache License 2.0 | 5 votes |
@Test public void testComponentHostMoveItemPartial() { ComponentHost hostHolder = new ComponentHost(mContext); MountItem mountItem = mock(MountItem.class); when(mountItem.getRenderTreeNode()).thenReturn(createNode(Column.create(mContext).build())); MountItem mountItem1 = mock(MountItem.class); when(mountItem1.getRenderTreeNode()).thenReturn(createNode(Column.create(mContext).build())); MountItem mountItem2 = mock(MountItem.class); when(mountItem2.getRenderTreeNode()).thenReturn(createNode(Column.create(mContext).build())); hostHolder.mount(0, mountItem, new Rect()); hostHolder.mount(1, mountItem1, new Rect()); hostHolder.mount(2, mountItem2, new Rect()); assertThat(mountItem).isEqualTo(hostHolder.getMountItemAt(0)); assertThat(mountItem1).isEqualTo(hostHolder.getMountItemAt(1)); assertThat(mountItem2).isEqualTo(hostHolder.getMountItemAt(2)); hostHolder.moveItem(mountItem2, 2, 0); assertThat(mountItem2).isEqualTo(hostHolder.getMountItemAt(0)); assertThat(mountItem1).isEqualTo(hostHolder.getMountItemAt(1)); assertThat(1) .isEqualTo( ((SparseArrayCompat<MountItem>) getInternalState(hostHolder, "mScrapMountItemsArray")) .size()); hostHolder.unmount(0, mountItem); assertThat(2) .isEqualTo( ((SparseArrayCompat<MountItem>) getInternalState(hostHolder, "mMountItems")).size()); assertThat((Object) getInternalState(hostHolder, "mScrapMountItemsArray")).isNull(); }
Example #9
Source File: LottieDrawableTest.java From lottie-android with Apache License 2.0 | 5 votes |
@SuppressWarnings("SameParameterValue") private LottieComposition createComposition(int startFrame, int endFrame) { LottieComposition composition = new LottieComposition(); composition.init(new Rect(), startFrame, endFrame, 1000, new ArrayList<Layer>(), new LongSparseArray<Layer>(0), new HashMap<String, List<Layer>>(0), new HashMap<String, LottieImageAsset>(0), new SparseArrayCompat<FontCharacter>(0), new HashMap<String, Font>(0), new ArrayList<Marker>()); return composition; }
Example #10
Source File: MrNotification.java From BaseProject with Apache License 2.0 | 5 votes |
/** * 调用系统通知管理者向系统发送 一条通知 * 注:如果同时指定tag,和notifyId,则如果要取消该通知,需要也同时指定tag和notifyId * @param tag 通知的tag * @param notifyId 通知的id * @param notification 通知对象 * @return notifyId */ public int send(@Nullable String tag, int notifyId,@NonNull Notification notification) { if (notifyManager != null) { notifyManager.notify(tag,notifyId,notification); } if (notifiesIdMapTags == null) { notifiesIdMapTags = new SparseArrayCompat<>(); } notifiesIdMapTags.put(notifyId,tag); theLastNotificationId = notifyId; return notifyId; }
Example #11
Source File: ComponentHost.java From litho with Apache License 2.0 | 5 votes |
public ComponentHost(ComponentContext context, AttributeSet attrs) { super(context.getAndroidContext(), attrs); setWillNotDraw(false); setChildrenDrawingOrderEnabled(true); refreshAccessibilityDelegatesIfNeeded(isAccessibilityEnabled(context.getAndroidContext())); mMountItems = new SparseArrayCompat<>(); mViewMountItems = new SparseArrayCompat<>(); mDrawableMountItems = new SparseArrayCompat<>(); mDisappearingItems = new ArrayList<>(); }
Example #12
Source File: ComponentHostUtils.java From litho with Apache License 2.0 | 5 votes |
static List<?> extractContent(SparseArrayCompat<MountItem> items) { final int size = items.size(); if (size == 1) { return Collections.singletonList(items.valueAt(0).getContent()); } final List<Object> content = new ArrayList<>(size); for (int i = 0; i < size; i++) { content.add(items.valueAt(i).getContent()); } return content; }
Example #13
Source File: ComponentHostUtils.java From litho with Apache License 2.0 | 5 votes |
/** * Remove the item at given {@param index}. The item is removed from {@param scrapItems} if the * item exists there at given index, otherwise it is removed from {@param items}. */ static <T> void removeItem( int index, SparseArrayCompat<T> items, SparseArrayCompat<T> scrapItems) { if (existsScrapItemAt(index, scrapItems)) { scrapItems.remove(index); } else { items.remove(index); } }
Example #14
Source File: FragmentStatePagerItemAdapter.java From SmartTabLayout with Apache License 2.0 | 4 votes |
public FragmentStatePagerItemAdapter(FragmentManager fm, FragmentPagerItems pages) { super(fm); this.pages = pages; this.holder = new SparseArrayCompat<>(pages.size()); }
Example #15
Source File: FragmentPagerItemAdapter.java From SmartTabLayout with Apache License 2.0 | 4 votes |
public FragmentPagerItemAdapter(FragmentManager fm, FragmentPagerItems pages) { super(fm); this.pages = pages; this.holder = new SparseArrayCompat<>(pages.size()); }
Example #16
Source File: EventHandlersController.java From litho with Apache License 2.0 | 4 votes |
@VisibleForTesting public SparseArrayCompat<EventHandler> getEventHandlers() { return mEventHandlers; }
Example #17
Source File: ViewPagerItemAdapter.java From SmartTabLayout with Apache License 2.0 | 4 votes |
public ViewPagerItemAdapter(ViewPagerItems pages) { this.pages = pages; this.holder = new SparseArrayCompat<>(pages.size()); this.inflater = LayoutInflater.from(pages.getContext()); }
Example #18
Source File: LottieComposition.java From lottie-android with Apache License 2.0 | 4 votes |
public SparseArrayCompat<FontCharacter> getCharacters() { return characters; }
Example #19
Source File: ComponentHostUtils.java From litho with Apache License 2.0 | 4 votes |
/** Returns true if scrapItems is not null and contains an item with key index. */ static <T> boolean existsScrapItemAt(int index, SparseArrayCompat<T> scrapItems) { return scrapItems != null && scrapItems.get(index) != null; }
Example #20
Source File: LottieCompositionParser.java From lottie-android with Apache License 2.0 | 4 votes |
public static LottieComposition parse(JsonReader reader) throws IOException { float scale = Utils.dpScale(); float startFrame = 0f; float endFrame = 0f; float frameRate = 0f; final LongSparseArray<Layer> layerMap = new LongSparseArray<>(); final List<Layer> layers = new ArrayList<>(); int width = 0; int height = 0; Map<String, List<Layer>> precomps = new HashMap<>(); Map<String, LottieImageAsset> images = new HashMap<>(); Map<String, Font> fonts = new HashMap<>(); List<Marker> markers = new ArrayList<>(); SparseArrayCompat<FontCharacter> characters = new SparseArrayCompat<>(); LottieComposition composition = new LottieComposition(); reader.beginObject(); while (reader.hasNext()) { switch (reader.selectName(NAMES)) { case 0: width = reader.nextInt(); break; case 1: height = reader.nextInt(); break; case 2: startFrame = (float) reader.nextDouble(); break; case 3: endFrame = (float) reader.nextDouble() - 0.01f; break; case 4: frameRate = (float) reader.nextDouble(); break; case 5: String version = reader.nextString(); String[] versions = version.split("\\."); int majorVersion = Integer.parseInt(versions[0]); int minorVersion = Integer.parseInt(versions[1]); int patchVersion = Integer.parseInt(versions[2]); if (!Utils.isAtLeastVersion(majorVersion, minorVersion, patchVersion, 4, 4, 0)) { composition.addWarning("Lottie only supports bodymovin >= 4.4.0"); } break; case 6: parseLayers(reader, composition, layers, layerMap); default: reader.skipValue(); } } int scaledWidth = (int) (width * scale); int scaledHeight = (int) (height * scale); Rect bounds = new Rect(0, 0, scaledWidth, scaledHeight); composition.init(bounds, startFrame, endFrame, frameRate, layers, layerMap, precomps, images, characters, fonts, markers); return composition; }
Example #21
Source File: KeyframeParser.java From lottie-android with Apache License 2.0 | 4 votes |
private static SparseArrayCompat<WeakReference<Interpolator>> pathInterpolatorCache() { if (pathInterpolatorCache == null) { pathInterpolatorCache = new SparseArrayCompat<>(); } return pathInterpolatorCache; }
Example #22
Source File: LottieCompositionMoshiParser.java From lottie-android with Apache License 2.0 | 4 votes |
public static LottieComposition parse(JsonReader reader) throws IOException { float scale = Utils.dpScale(); float startFrame = 0f; float endFrame = 0f; float frameRate = 0f; final LongSparseArray<Layer> layerMap = new LongSparseArray<>(); final List<Layer> layers = new ArrayList<>(); int width = 0; int height = 0; Map<String, List<Layer>> precomps = new HashMap<>(); Map<String, LottieImageAsset> images = new HashMap<>(); Map<String, Font> fonts = new HashMap<>(); List<Marker> markers = new ArrayList<>(); SparseArrayCompat<FontCharacter> characters = new SparseArrayCompat<>(); LottieComposition composition = new LottieComposition(); reader.beginObject(); while (reader.hasNext()) { switch (reader.selectName(NAMES)) { case 0: width = reader.nextInt(); break; case 1: height = reader.nextInt(); break; case 2: startFrame = (float) reader.nextDouble(); break; case 3: endFrame = (float) reader.nextDouble() - 0.01f; break; case 4: frameRate = (float) reader.nextDouble(); break; case 5: String version = reader.nextString(); String[] versions = version.split("\\."); int majorVersion = Integer.parseInt(versions[0]); int minorVersion = Integer.parseInt(versions[1]); int patchVersion = Integer.parseInt(versions[2]); if (!Utils.isAtLeastVersion(majorVersion, minorVersion, patchVersion, 4, 4, 0)) { composition.addWarning("Lottie only supports bodymovin >= 4.4.0"); } break; case 6: parseLayers(reader, composition, layers, layerMap); break; case 7: parseAssets(reader, composition, precomps, images); break; case 8: parseFonts(reader, fonts); break; case 9: parseChars(reader, composition, characters); break; case 10: parseMarkers(reader, composition, markers); break; default: reader.skipName(); reader.skipValue(); } } int scaledWidth = (int) (width * scale); int scaledHeight = (int) (height * scale); Rect bounds = new Rect(0, 0, scaledWidth, scaledHeight); composition.init(bounds, startFrame, endFrame, frameRate, layers, layerMap, precomps, images, characters, fonts, markers); return composition; }
Example #23
Source File: ExportAdapter.java From AppOpsX with MIT License | 4 votes |
SparseArrayCompat<AppInfo> getCheckedApps() { return mCheckedApps; }
Example #24
Source File: ComponentHostTest.java From litho with Apache License 2.0 | 4 votes |
private MountItem getDrawableMountItemAt(int index) throws Exception { SparseArrayCompat drawableItems = Whitebox.getInternalState(mHost, "mDrawableMountItems"); return Whitebox.invokeMethod(drawableItems, "valueAt", index); }
Example #25
Source File: ComponentHostTest.java From litho with Apache License 2.0 | 4 votes |
private int getDrawableItemsSize() throws Exception { SparseArrayCompat drawableItems = Whitebox.getInternalState(mHost, "mDrawableMountItems"); return Whitebox.invokeMethod(drawableItems, "size"); }
Example #26
Source File: ComponentHost.java From litho with Apache License 2.0 | 4 votes |
private void ensureScrapDrawableMountItemsArray() { if (mScrapDrawableMountItems == null) { mScrapDrawableMountItems = new SparseArrayCompat<>(SCRAP_ARRAY_INITIAL_SIZE); } }
Example #27
Source File: ComponentHost.java From litho with Apache License 2.0 | 4 votes |
private void ensureScrapMountItemsArray() { if (mScrapMountItemsArray == null) { mScrapMountItemsArray = new SparseArrayCompat<>(SCRAP_ARRAY_INITIAL_SIZE); } }
Example #28
Source File: ComponentHost.java From litho with Apache License 2.0 | 4 votes |
private void ensureScrapViewMountItemsArray() { if (mScrapViewMountItemsArray == null) { mScrapViewMountItemsArray = new SparseArrayCompat<>(SCRAP_ARRAY_INITIAL_SIZE); } }
Example #29
Source File: ComponentHost.java From litho with Apache License 2.0 | 4 votes |
private void ensureDrawableMountItems() { if (mDrawableMountItems == null) { mDrawableMountItems = new SparseArrayCompat<>(); } }
Example #30
Source File: ComponentHost.java From litho with Apache License 2.0 | 4 votes |
private void ensureViewMountItems() { if (mViewMountItems == null) { mViewMountItems = new SparseArrayCompat<>(); } }