private static SparseArrayCompat<WeakReference<Interpolator>> pathInterpolatorCache() { if (pathInterpolatorCache == null) { pathInterpolatorCache = new SparseArrayCompat<>(); } return pathInterpolatorCache; }
/** * Adds an {@link AdapterDelegate}. * <b>This method automatically assign internally the view type integer by using the next * unused</b> * <p> * Internally calls {@link #addDelegate(int, boolean, AdapterDelegate)} with * allowReplacingDelegate = false as parameter. * * @param delegate the delegate to add * @return self * @throws NullPointerException if passed delegate is null * @see #addDelegate(int, AdapterDelegate) * @see #addDelegate(int, boolean, AdapterDelegate) */ public AdapterDelegatesManager<T> addDelegate(@NonNull AdapterDelegate<T> delegate) { // algorithm could be improved since there could be holes, // but it's very unlikely that we reach Integer.MAX_VALUE and run out of unused indexes int viewType = delegates.size(); while (delegates.get(viewType) != null) { viewType++; if (viewType == FALLBACK_DELEGATE_VIEW_TYPE) { throw new IllegalArgumentException( "Oops, we are very close to Integer.MAX_VALUE. It seems that there are no more free and unused view type integers left to add another AdapterDelegate."); } } return addDelegate(viewType, false, delegate); }
/** * Must be called from {@link RecyclerView.Adapter#getItemViewType(int)}. Internally it scans all * the registered {@link AdapterDelegate} and picks the right one to return the ViewType integer. * * @param items Adapter's data source * @param position the position in adapters data source * @return the ViewType (integer). Returns {@link #FALLBACK_DELEGATE_VIEW_TYPE} in case that the * fallback adapter delegate should be used * @throws NullPointerException if no {@link AdapterDelegate} has been found that is * responsible for the given data element in data set (No {@link AdapterDelegate} for the given * ViewType) * @throws NullPointerException if items is null */ public int getItemViewType(@NonNull T items, int position) { if (items == null) { throw new NullPointerException("Items datasource is null!"); } int delegatesCount = delegates.size(); for (int i = 0; i < delegatesCount; i++) { AdapterDelegate<T> delegate = delegates.valueAt(i); if (delegate.isForViewType(items, position)) { return delegates.keyAt(i); } } if (fallbackDelegate != null) { return FALLBACK_DELEGATE_VIEW_TYPE; } throw new NullPointerException( "No AdapterDelegate added that matches position=" + position + " in data source"); }
@Nullable private static WeakReference<Interpolator> getInterpolator(int hash) { // This must be synchronized because get and put isn't thread safe because // SparseArrayCompat has to create new sized arrays sometimes. synchronized (KeyframeParser.class) { return pathInterpolatorCache().get(hash); } }
private static void putInterpolator(int hash, WeakReference<Interpolator> interpolator) { // This must be synchronized because get and put isn't thread safe because // SparseArrayCompat has to create new sized arrays sometimes. synchronized (KeyframeParser.class) { pathInterpolatorCache.put(hash, interpolator); } }
public boolean useTextGlyphs() { return textDelegate == null && composition.getCharacters().size() > 0; }
private void handleCheck(ExportViewHolder holder, boolean change) { int pos = holder.getAdapterPosition(); if (holder.checkBox.isChecked()) { mCheckedApps.delete(pos); } else { mCheckedApps.put(pos, appInfos.get(pos)); } if (change) { holder.checkBox.setOnCheckedChangeListener(null); holder.checkBox.setChecked(isChecked(pos)); holder.checkBox.setOnCheckedChangeListener(this); } }
ExportAdapter(List<AppInfo> appInfos) { this.appInfos = appInfos; if (appInfos != null) { int i = 0; for (AppInfo appInfo : appInfos) { mCheckedApps.append(i, appInfo); i++; } } }
/** * Get the {@link AdapterDelegate} associated with the given view type integer * * @param viewType The view type integer we want to retrieve the associated * delegate for. * @return The {@link AdapterDelegate} associated with the view type param if it exists, * the fallback delegate otherwise if it is set or returns <code>null</code> if no delegate is * associated to this viewType (and no fallback has been set). */ @Nullable public AdapterDelegate<T> getDelegateForViewType(int viewType) { return delegates.get(viewType, fallbackDelegate); }
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(); } }
manager.addDelegate(d1); Assert.assertTrue(manager.delegates.get(0) == d1); Assert.assertEquals(0, manager.getViewType(d1)); Assert.fail("Replacing delegate should fail"); } catch (IllegalArgumentException e) { Assert.assertTrue(manager.delegates.get(0) == d1); Assert.assertEquals(0, manager.getViewType(d1)); Assert.assertEquals(1, manager.delegates.size()); Assert.assertTrue(manager.delegates.get(0) == d2); Assert.assertEquals(0, manager.getViewType(d2)); Assert.assertEquals(-1, manager.getViewType(d1)); Assert.assertTrue(manager.delegates.get(0) == d2); Assert.assertEquals(1, manager.delegates.size()); Assert.assertNull(manager.delegates.get(0)); Assert.assertEquals(0, manager.delegates.size()); Assert.assertEquals(-1, manager.getViewType(d2));
private float getTotalTextWidthForGlyphs( DocumentData documentData, Font font, float fontScale, float parentScale) { float totalWidth = 0; for (int i = 0; i < documentData.text.length(); i++) { char c = documentData.text.charAt(i); int characterHash = FontCharacter.hashFor(c, font.getFamily(), font.getStyle()); FontCharacter character = composition.getCharacters().get(characterHash); if (character == null) { continue; } totalWidth += character.getWidth() * fontScale * Utils.dpScale() * parentScale; } return totalWidth; }
@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)); return composition; }
@Override @NonNull public Fragment getItem(int position) { Fragment fragment = mFragments.get(position); if (fragment == null) { switch (position) { case 0: fragment = new ExportFragment(); fragment.setArguments(new Bundle(getIntent().getExtras())); break; case 1: fragment = new ImportFragment(); break; } if (fragment != null) { mFragments.put(position, fragment); } } return fragment; }
private void drawTextGlyphs( DocumentData documentData, Matrix parentMatrix, Font font, Canvas canvas) { float fontScale = (float) documentData.size / 100f; float parentScale = Utils.getScale(parentMatrix); float totalTextWidth = getTotalTextWidthForGlyphs(documentData, font, fontScale, parentScale); applyJustification(documentData.justification, canvas, totalTextWidth); String text = documentData.text; for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); int characterHash = FontCharacter.hashFor(c, font.getFamily(), font.getStyle()); FontCharacter character = composition.getCharacters().get(characterHash); if (character == null) { // Something is wrong. Potentially, they didn't export the text as a glyph. continue; } drawCharacterAsGlyph(character, parentMatrix, fontScale, documentData, canvas); float tx = (float) character.getWidth() * fontScale * Utils.dpScale() * parentScale; // Add tracking float tracking = documentData.tracking / 10f; if (trackingAnimation != null) { tracking += trackingAnimation.getValue(); } tx += tracking * parentScale; canvas.translate(tx, 0); } }
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)); return composition; }
Map<String, LottieImageAsset> images = new HashMap<>(); Map<String, Font> fonts = new HashMap<>(); SparseArrayCompat<FontCharacter> characters = new SparseArrayCompat<>();