Example usage for android.util SparseArray indexOfKey

List of usage examples for android.util SparseArray indexOfKey

Introduction

In this page you can find the example usage for android.util SparseArray indexOfKey.

Prototype

public int indexOfKey(int key) 

Source Link

Document

Returns the index for which #keyAt would return the specified key, or a negative number if the specified key is not mapped.

Usage

From source file:com.ruesga.rview.misc.NotificationsHelper.java

@SuppressWarnings("Convert2streamapi")
public static void recreateNotifications(Context ctx) {
    List<NotificationEntity> entities = NotificationEntity.getAllNotifications(ctx, true, true);
    SparseArray<Account> notifications = new SparseArray<>();
    for (NotificationEntity entity : entities) {
        if (notifications.indexOfKey(entity.mGroupId) < 0) {
            notifications.put(entity.mGroupId, ModelHelper.getAccountFromHash(ctx, entity.mAccountId));
        }/*from   ww w .  j  a va 2s  .co m*/
    }

    int count = notifications.size();
    for (int i = 0; i < count; i++) {
        int groupId = notifications.keyAt(i);
        Account account = notifications.valueAt(i);
        dismissNotification(ctx, groupId);
        createNotification(ctx, account, groupId, false);
    }
}

From source file:com.sonymobile.androidapp.gridcomputing.fragments.ReportChartFragment.java

/**
 * Creates a line data set to plot the chart.
 * @param setPosition this dataset position.
 * @param label The label of the data set.
 * @param array The sparse array containing the data to plot.
 * @param startValue the value at which the x axis starts.
 * @return a dataset ready to plot.// w w w  . jav  a  2s . c  o  m
 */
private LineDataSet getData(final int setPosition, final String label, final SparseArray<Double> array,
        final int startValue) {
    final List<Entry> values = new ArrayList<>();

    final int startIndex = startValue == 0 ? 0 : array.indexOfKey(startValue);

    for (int i = startIndex; i < array.size(); i++) {
        int key = array.keyAt(i);
        int xValue = startValue == 0 ? key : values.size() + startValue;
        values.add(new Entry(xValue, array.get(key).floatValue()));
    }
    for (int i = 0; i < startIndex; i++) {
        try {
            int key = array.keyAt(i);
            int xValue = startValue == 0 ? key : values.size() + startValue;
            values.add(new Entry(xValue, array.get(key).floatValue()));
        } catch (Exception e) {
            Log.e("Entry at index " + i + " does not exist");
        }
    }

    LineDataSet d = new LineDataSet(values, label);
    d.setLineWidth(2.5f);
    d.setCircleRadius(4f);
    d.setDrawValues(false);

    int color = CHART_COLORS[setPosition];
    d.setColor(color);
    d.setCircleColor(color);
    d.setDrawFilled(true);
    return d;
}

From source file:com.blestep.sportsbracelet.view.TimelineChartView.java

private float computeOffsetForPosition(int position) {
    final SparseArray<Object[]> data;
    synchronized (mLock) {
        data = mData;//from   w  ww.  ja va  2  s  .c  o m
    }
    final int index = data.indexOfKey(position);
    if (index >= 0) {
        final int size = data.size();
        return (mBarWidth * (size - index - 1));
    }
    return -1;
}