Example usage for android.support.v4.util LongSparseArray get

List of usage examples for android.support.v4.util LongSparseArray get

Introduction

In this page you can find the example usage for android.support.v4.util LongSparseArray get.

Prototype

public E get(long j) 

Source Link

Usage

From source file:ru.orangesoftware.financisto2.model.Budget.java

private static String createProjectsWhere(Budget b, LongSparseArray<Project> projects) {
    long[] ids = MyEntity.splitIds(b.projects);
    if (ids != null) {
        StringBuilder sb = new StringBuilder();
        boolean f = false;
        for (long id : ids) {
            Project p = projects.get(id);
            if (p != null) {
                if (f) {
                    sb.append(" OR ");
                }/*from  w  ww  .  java  2  s  . c  o m*/
                sb.append(BlotterFilter.PROJECT_ID).append("=").append(p.id);
                f = true;
            }
        }
        if (f) {
            return sb.toString();
        }
    }
    return null;
}

From source file:ru.orangesoftware.financisto2.model.Budget.java

private static String createCategoriesWhere(Budget b, LongSparseArray<Category> categories) {
    long[] ids = MyEntity.splitIds(b.categories);
    if (ids != null) {
        StringBuilder sb = new StringBuilder();
        boolean f = false;
        for (long id : ids) {
            Category c = categories.get(id);
            if (c != null) {
                if (f) {
                    sb.append(" OR ");
                }//from   w w w.j  a  v  a 2s.  c  o m
                if (b.includeSubcategories) {
                    sb.append("(").append(BlotterFilter.CATEGORY_LEFT).append(" BETWEEN ").append(c.left)
                            .append(" AND ").append(c.right).append(")");
                } else {
                    sb.append(BlotterFilter.CATEGORY_ID).append("=").append(c.id);
                }
                f = true;
            }
        }
        if (f) {
            return sb.toString();
        }
    }
    return null;
}

From source file:ru.orangesoftware.financisto2.model.CategoryTreeNavigator.java

public void selectCategory(long selectedCategoryId) {
    LongSparseArray<Category> map = CategoryTree.asDeepMap(categories);
    Category selectedCategory = map.get(selectedCategoryId);
    if (selectedCategory != null) {
        Stack<Long> path = new Stack<Long>();
        Category parent = selectedCategory.parent;
        while (parent != null) {
            path.push(parent.id);//from  w ww  . j av  a2s  .  c o m
            parent = parent.parent;
        }
        while (!path.isEmpty()) {
            navigateTo(path.pop());
        }
        this.selectedCategoryId = selectedCategoryId;
    }
}

From source file:ru.orangesoftware.financisto2.db.BudgetsTotalCalculator.java

private <T extends MyEntity> String getChecked(LongSparseArray<T> entities, String s) {
    long[] ids = MyEntity.splitIds(s);
    if (ids == null) {
        return null;
    }/*from  ww w . j  a va  2 s.c  o m*/
    if (ids.length == 1) {
        MyEntity e = entities.get(ids[0]);
        if (e == null) {
            return null;
        } else {
            return e.title;
        }
    } else {
        StringBuilder sb = new StringBuilder();
        for (long id : ids) {
            MyEntity e = entities.get(id);
            if (e != null) {
                if (sb.length() > 0) {
                    sb.append(",");
                }
                sb.append(e.title);
            }
        }
        if (sb.length() == 0) {
            return null;
        } else {
            return sb.toString();
        }
    }
}

From source file:android.content.res.VectorResources.java

private Drawable getCachedDrawable(LongSparseArray<WeakReference<Drawable.ConstantState>> drawableCache,
        long key) {
    synchronized (mAccessLock) {
        WeakReference<Drawable.ConstantState> wr = drawableCache.get(key);
        if (wr != null) { // we have the key
            Drawable.ConstantState entry = wr.get();
            if (entry != null) {
                //Log.i(TAG, "Returning cached drawable @ #" +
                //        Integer.toHexString(((Integer)key).intValue())
                //        + " in " + this + ": " + entry);
                return entry.newDrawable(this);
            } else { // our entry has been purged
                drawableCache.delete(key);
            }/*ww  w.ja  va 2 s .  c  o m*/
        }
    }
    return null;
}

From source file:com.example.amapdemo.heatmap.HeatmapTileProvider.java

/**
 * 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//from w w w .  j av  a  2  s.  c  o  m
 * @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;
}

From source file:nz.ac.otago.psyanlab.common.model.util.LongSparseArrayGsonAdapter.java

@Override
public LongSparseArray<T> read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();//from  www. j ava 2 s.  co m
        return null;
    }
    LongSparseArray<Object> temp = mGson.fromJson(in, mTypeOfLongSparseArrayOfObject);
    LongSparseArray<T> result = new LongSparseArray<T>(temp.size());
    long key;
    JsonElement tElement;
    for (int i = 0; i < temp.size(); i++) {
        key = temp.keyAt(i);
        tElement = mGson.toJsonTree(temp.get(key), new TypeToken<T>() {
        }.getType());
        result.put(key, mGson.fromJson(tElement, mTClazz));
    }
    return result;
}

From source file:com.example.martin.maps.clustering.algo.GridBasedAlgorithm.java

@Override
public Set<? extends Cluster<T>> getClusters(double zoom) {
    long numCells = (long) Math.ceil(256 * Math.pow(2, zoom) / GRID_SIZE);
    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);//  www  .  j ava  2  s  .c  om
            }
            cluster.add(item);
        }
    }

    return clusters;
}

From source file:com.amap.api.maps2d.heatmaps.HeatmapTileProvider.java

/**
 * Calculate a reasonable maximum intensity value to map to maximum color
 * intensity//from  w  w  w.  j  ava2  s .  c om
 * 
 * @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(final Collection<WeightedLatLng> points, final Bounds bounds, final int radius,
        final int screenDim) {
    // Approximate scale as if entire heatmap is on the screen
    // ie scale dimensions to larger of width or height (screenDim)
    final double minX = bounds.minX;
    final double maxX = bounds.maxX;
    final double minY = bounds.minY;
    final double maxY = bounds.maxY;
    final double boundsDim = maxX - minX > maxY - minY ? maxX - minX : maxY - minY;

    // Number of buckets: have diameter sized buckets
    final int nBuckets = (int) (screenDim / (2 * radius) + 0.5);
    // Scaling factor to convert width in terms of point distance, to which
    // bucket
    final double scale = nBuckets / boundsDim;

    // Make buckets
    // Use a sparse array - use LongSparseArray just in case
    final 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 (final WeightedLatLng l : points) {
        x = l.getPoint().x;
        y = l.getPoint().y;

        final int xBucket = (int) ((x - minX) * scale);
        final 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;
}

From source file:com.kaliturin.blacklist.fragments.GetContactsFragment.java

@Override
protected void addContacts(List<Contact> contacts, LongSparseArray<ContactNumber> singleContactNumbers) {
    // prepare returning arguments - data of the chosen contacts
    ArrayList<String> names = new ArrayList<>();
    ArrayList<String> numbers = new ArrayList<>();
    ArrayList<Integer> types = new ArrayList<>();
    for (Contact contact : contacts) {
        ContactNumber contactNumber = singleContactNumbers.get(contact.id);
        if (contactNumber != null) {
            // add single number of the contact
            names.add(contact.name);//from w  ww  .  jav a 2  s .  c  o  m
            numbers.add(contactNumber.number);
            types.add(contactNumber.type);
        } else {
            // all numbers of the contact
            for (ContactNumber _contactNumber : contact.numbers) {
                names.add(contact.name);
                numbers.add(_contactNumber.number);
                types.add(_contactNumber.type);
            }
        }
    }

    // return arguments
    Intent intent = new Intent();
    intent.putStringArrayListExtra(CONTACT_NAMES, names);
    intent.putStringArrayListExtra(CONTACT_NUMBERS, numbers);
    intent.putIntegerArrayListExtra(CONTACT_NUMBER_TYPES, types);
    getActivity().setResult(Activity.RESULT_OK, intent);
    getActivity().finish();
}