Search in sources :

Example 1 with LongSparseArray

use of androidx.collection.LongSparseArray in project kdeconnect-android by KDE.

the class ExtendedFragmentAdapter method getFragments.

protected LongSparseArray<Fragment> getFragments() {
    try {
        Field fragmentsField = FragmentStateAdapter.class.getDeclaredField("mFragments");
        fragmentsField.setAccessible(true);
        Object fieldData = fragmentsField.get(this);
        if (fieldData instanceof LongSparseArray) {
            // noinspection unchecked
            return (LongSparseArray<Fragment>) fieldData;
        }
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Field(java.lang.reflect.Field) LongSparseArray(androidx.collection.LongSparseArray)

Example 2 with LongSparseArray

use of androidx.collection.LongSparseArray in project android-maps-utils by googlemaps.

the class HeatmapTileProvider method getMaxValue.

/**
 * 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;
}
Also used : LongSparseArray(androidx.collection.LongSparseArray) Point(com.google.maps.android.geometry.Point)

Example 3 with LongSparseArray

use of androidx.collection.LongSparseArray in project android-maps-utils by googlemaps.

the class GridBasedAlgorithm method getClusters.

@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;
}
Also used : LongSparseArray(androidx.collection.LongSparseArray) Cluster(com.google.maps.android.clustering.Cluster) Point(com.google.maps.android.geometry.Point) SphericalMercatorProjection(com.google.maps.android.projection.SphericalMercatorProjection) HashSet(java.util.HashSet)

Example 4 with LongSparseArray

use of androidx.collection.LongSparseArray in project AndroidUtilCode by Blankj.

the class ObjectUtilsTest method isEmpty.

@Test
public void isEmpty() {
    StringBuilder sb = new StringBuilder("");
    StringBuilder sb1 = new StringBuilder(" ");
    String string = "";
    String string1 = " ";
    int[][] arr = new int[][] {};
    LinkedList<Integer> list = new LinkedList<>();
    HashMap<String, Integer> map = new HashMap<>();
    SimpleArrayMap<String, Integer> sam = new SimpleArrayMap<>();
    SparseArray<String> sa = new SparseArray<>();
    SparseBooleanArray sba = new SparseBooleanArray();
    SparseIntArray sia = new SparseIntArray();
    SparseLongArray sla = new SparseLongArray();
    LongSparseArray<String> lsa = new LongSparseArray<>();
    android.util.LongSparseArray<String> lsaV4 = new android.util.LongSparseArray<>();
    assertTrue(ObjectUtils.isEmpty(sb));
    assertFalse(ObjectUtils.isEmpty(sb1));
    assertTrue(ObjectUtils.isEmpty(string));
    assertFalse(ObjectUtils.isEmpty(string1));
    assertTrue(ObjectUtils.isEmpty(arr));
    assertTrue(ObjectUtils.isEmpty(list));
    assertTrue(ObjectUtils.isEmpty(map));
    assertTrue(ObjectUtils.isEmpty(sam));
    assertTrue(ObjectUtils.isEmpty(sa));
    assertTrue(ObjectUtils.isEmpty(sba));
    assertTrue(ObjectUtils.isEmpty(sia));
    assertTrue(ObjectUtils.isEmpty(sla));
    assertTrue(ObjectUtils.isEmpty(lsa));
    assertTrue(ObjectUtils.isEmpty(lsaV4));
    assertTrue(!ObjectUtils.isNotEmpty(sb));
    assertFalse(!ObjectUtils.isNotEmpty(sb1));
    assertTrue(!ObjectUtils.isNotEmpty(string));
    assertFalse(!ObjectUtils.isNotEmpty(string1));
    assertTrue(!ObjectUtils.isNotEmpty(arr));
    assertTrue(!ObjectUtils.isNotEmpty(list));
    assertTrue(!ObjectUtils.isNotEmpty(map));
    assertTrue(!ObjectUtils.isNotEmpty(sam));
    assertTrue(!ObjectUtils.isNotEmpty(sa));
    assertTrue(!ObjectUtils.isNotEmpty(sba));
    assertTrue(!ObjectUtils.isNotEmpty(sia));
    assertTrue(!ObjectUtils.isNotEmpty(sla));
    assertTrue(!ObjectUtils.isNotEmpty(lsa));
    assertTrue(!ObjectUtils.isNotEmpty(lsaV4));
}
Also used : LongSparseArray(androidx.collection.LongSparseArray) HashMap(java.util.HashMap) SimpleArrayMap(androidx.collection.SimpleArrayMap) SparseLongArray(android.util.SparseLongArray) LinkedList(java.util.LinkedList) SparseArray(android.util.SparseArray) LongSparseArray(androidx.collection.LongSparseArray) SparseIntArray(android.util.SparseIntArray) SparseBooleanArray(android.util.SparseBooleanArray) Test(org.junit.Test)

Example 5 with LongSparseArray

use of androidx.collection.LongSparseArray in project lottie-android by airbnb.

the class LottieCompositionMoshiParser method parse.

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, 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;
}
Also used : LongSparseArray(androidx.collection.LongSparseArray) Rect(android.graphics.Rect) HashMap(java.util.HashMap) LottieImageAsset(com.airbnb.lottie.LottieImageAsset) ArrayList(java.util.ArrayList) Marker(com.airbnb.lottie.model.Marker) Layer(com.airbnb.lottie.model.layer.Layer) Font(com.airbnb.lottie.model.Font) FontCharacter(com.airbnb.lottie.model.FontCharacter) ArrayList(java.util.ArrayList) List(java.util.List) LottieComposition(com.airbnb.lottie.LottieComposition) SparseArrayCompat(androidx.collection.SparseArrayCompat)

Aggregations

LongSparseArray (androidx.collection.LongSparseArray)6 LottieImageAsset (com.airbnb.lottie.LottieImageAsset)2 Layer (com.airbnb.lottie.model.layer.Layer)2 Point (com.google.maps.android.geometry.Point)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Rect (android.graphics.Rect)1 SparseArray (android.util.SparseArray)1 SparseBooleanArray (android.util.SparseBooleanArray)1 SparseIntArray (android.util.SparseIntArray)1 SparseLongArray (android.util.SparseLongArray)1 SimpleArrayMap (androidx.collection.SimpleArrayMap)1 SparseArrayCompat (androidx.collection.SparseArrayCompat)1 LottieComposition (com.airbnb.lottie.LottieComposition)1 Font (com.airbnb.lottie.model.Font)1 FontCharacter (com.airbnb.lottie.model.FontCharacter)1 Marker (com.airbnb.lottie.model.Marker)1 Cluster (com.google.maps.android.clustering.Cluster)1 SphericalMercatorProjection (com.google.maps.android.projection.SphericalMercatorProjection)1 Field (java.lang.reflect.Field)1