Java Code Examples for androidx.collection.LongSparseArray#get()
The following examples show how to use
androidx.collection.LongSparseArray#get() .
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: SkinCompatDrawableManager.java From Android-skin-support with MIT License | 6 votes |
private Drawable getCachedDrawable(@NonNull final Context context, final long key) { synchronized (mDrawableCacheLock) { final LongSparseArray<WeakReference<ConstantState>> cache = mDrawableCaches.get(context); if (cache == null) { return null; } final WeakReference<ConstantState> wr = cache.get(key); if (wr != null) { // We have the key, and the secret ConstantState entry = wr.get(); if (entry != null) { return entry.newDrawable(context.getResources()); } else { // Our entry has been purged cache.delete(key); } } } return null; }
Example 2
Source File: GridBasedAlgorithm.java From android-maps-utils with Apache License 2.0 | 6 votes |
@Override public Set<? extends Cluster<T>> getClusters(float zoom) { long numCells = (long) Math.ceil(256 * Math.pow(2, zoom) / mGridSize); SphericalMercatorProjection proj = new SphericalMercatorProjection(numCells); HashSet<Cluster<T>> clusters = new HashSet<Cluster<T>>(); LongSparseArray<StaticCluster<T>> sparseArray = new LongSparseArray<StaticCluster<T>>(); synchronized (mItems) { for (T item : mItems) { Point p = proj.toPoint(item.getPosition()); long coord = getCoord(numCells, p.x, p.y); StaticCluster<T> cluster = sparseArray.get(coord); if (cluster == null) { cluster = new StaticCluster<T>(proj.toLatLng(new Point(Math.floor(p.x) + .5, Math.floor(p.y) + .5))); sparseArray.put(coord, cluster); clusters.add(cluster); } cluster.add(item); } } return clusters; }
Example 3
Source File: LollipopDrawablesCompat.java From Carbon with Apache License 2.0 | 5 votes |
private static Drawable getCachedDrawable(LongSparseArray<WeakReference<Drawable.ConstantState>> cache, long key, Resources res) { synchronized (mAccessLock) { WeakReference<Drawable.ConstantState> wr = cache.get(key); if (wr != null) { Drawable.ConstantState entry = wr.get(); if (entry != null) { return entry.newDrawable(res); } else { cache.delete(key); } } } return null; }
Example 4
Source File: CompositionLayer.java From lottie-android with Apache License 2.0 | 4 votes |
public CompositionLayer(LottieDrawable lottieDrawable, Layer layerModel, List<Layer> layerModels, LottieComposition composition) { super(lottieDrawable, layerModel); AnimatableFloatValue timeRemapping = layerModel.getTimeRemapping(); if (timeRemapping != null) { this.timeRemapping = timeRemapping.createAnimation(); addAnimation(this.timeRemapping); //noinspection ConstantConditions this.timeRemapping.addUpdateListener(this); } else { this.timeRemapping = null; } LongSparseArray<BaseLayer> layerMap = new LongSparseArray<>(composition.getLayers().size()); BaseLayer mattedLayer = null; for (int i = layerModels.size() - 1; i >= 0; i--) { Layer lm = layerModels.get(i); BaseLayer layer = BaseLayer.forModel(lm, lottieDrawable, composition); if (layer == null) { continue; } layerMap.put(layer.getLayerModel().getId(), layer); if (mattedLayer != null) { mattedLayer.setMatteLayer(layer); mattedLayer = null; } else { layers.add(0, layer); switch (lm.getMatteType()) { case ADD: case INVERT: mattedLayer = layer; break; } } } for (int i = 0; i < layerMap.size(); i++) { long key = layerMap.keyAt(i); BaseLayer layerView = layerMap.get(key); // This shouldn't happen but it appears as if sometimes on pre-lollipop devices when // compiled with d8, layerView is null sometimes. // https://github.com/airbnb/lottie-android/issues/524 if (layerView == null) { continue; } BaseLayer parentLayer = layerMap.get(layerView.getLayerModel().getParentId()); if (parentLayer != null) { layerView.setParentLayer(parentLayer); } } }
Example 5
Source File: HeatmapTileProvider.java From android-maps-utils with Apache License 2.0 | 4 votes |
/** * Calculate a reasonable maximum intensity value to map to maximum color intensity * * @param points Collection of LatLngs to put into buckets * @param bounds Bucket boundaries * @param radius radius of convolution * @param screenDim larger dimension of screen in pixels (for scale) * @return Approximate max value */ static double getMaxValue(Collection<WeightedLatLng> points, Bounds bounds, int radius, int screenDim) { // Approximate scale as if entire heatmap is on the screen // ie scale dimensions to larger of width or height (screenDim) double minX = bounds.minX; double maxX = bounds.maxX; double minY = bounds.minY; double maxY = bounds.maxY; double boundsDim = (maxX - minX > maxY - minY) ? maxX - minX : maxY - minY; // Number of buckets: have diameter sized buckets int nBuckets = (int) (screenDim / (2 * radius) + 0.5); // Scaling factor to convert width in terms of point distance, to which bucket double scale = nBuckets / boundsDim; // Make buckets // Use a sparse array - use LongSparseArray just in case LongSparseArray<LongSparseArray<Double>> buckets = new LongSparseArray<LongSparseArray<Double>>(); //double[][] buckets = new double[nBuckets][nBuckets]; // Assign into buckets + find max value as we go along double x, y; double max = 0; for (WeightedLatLng l : points) { x = l.getPoint().x; y = l.getPoint().y; int xBucket = (int) ((x - minX) * scale); int yBucket = (int) ((y - minY) * scale); // Check if x bucket exists, if not make it LongSparseArray<Double> column = buckets.get(xBucket); if (column == null) { column = new LongSparseArray<Double>(); buckets.put(xBucket, column); } // Check if there is already a y value there Double value = column.get(yBucket); if (value == null) { value = 0.0; } value += l.getIntensity(); // Yes, do need to update it, despite it being a Double. column.put(yBucket, value); if (value > max) max = value; } return max; }