Example usage for android.util SparseIntArray put

List of usage examples for android.util SparseIntArray put

Introduction

In this page you can find the example usage for android.util SparseIntArray put.

Prototype

public void put(int key, int value) 

Source Link

Document

Adds a mapping from the specified key to the specified value, replacing the previous mapping from the specified key if there was one.

Usage

From source file:Main.java

public static SparseIntArray readCountArray(Cursor cursor) {

    SparseIntArray countMap = new SparseIntArray();
    while (cursor.moveToNext()) {
        countMap.put(cursor.getInt(ID_INDEX), cursor.getInt(TASK_COUNT_INDEX));
    }//from w  w  w. j av  a 2 s  .  c  o  m
    return countMap;
}

From source file:Main.java

public static SparseIntArray getWeekRepeatition(Integer repeatition) {
    SparseIntArray map = new SparseIntArray();
    if (repeatition == null)
        return null;
    for (int i = 0; i < WEEK_DAY_TOTAL; i++) {
        if ((repeatition & (1 << i)) > 0) {
            map.put(i, 1);
        } else {/* w ww .j a  v  a  2s  .co m*/
            map.put(i, 0);
        }
    }
    return map;
}

From source file:com.achep.acdisplay.services.media.MediaController2KitKat.java

@NonNull
static SparseIntArray generatePlaybackCompatSparse() {
    SparseIntArray sia = new SparseIntArray();
    sia.put(RemoteControlClient.PLAYSTATE_BUFFERING, PlaybackStateCompat.STATE_BUFFERING);
    sia.put(RemoteControlClient.PLAYSTATE_PLAYING, PlaybackStateCompat.STATE_PLAYING);
    sia.put(RemoteControlClient.PLAYSTATE_PAUSED, PlaybackStateCompat.STATE_PAUSED);
    sia.put(RemoteControlClient.PLAYSTATE_ERROR, PlaybackStateCompat.STATE_ERROR);
    sia.put(RemoteControlClient.PLAYSTATE_REWINDING, PlaybackStateCompat.STATE_REWINDING);
    sia.put(RemoteControlClient.PLAYSTATE_FAST_FORWARDING, PlaybackStateCompat.STATE_FAST_FORWARDING);
    sia.put(RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS, PlaybackStateCompat.STATE_SKIPPING_TO_NEXT);
    sia.put(RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS, PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS);
    return sia;//from  w ww .  j av  a 2  s  .  c o  m
}

From source file:Main.java

/**
 * internal method to handle the selections if items are added / removed
 *
 * @param positions     the positions map which should be adjusted
 * @param startPosition the global index of the first element modified
 * @param endPosition   the global index up to which the modification changed the indices (should be MAX_INT if we check til the end)
 * @param adjustBy      the value by which the data was shifted
 * @return the adjusted map/*from ww  w .j a  v a  2s  .  co  m*/
 */
public static SparseIntArray adjustPosition(SparseIntArray positions, int startPosition, int endPosition,
        int adjustBy) {
    SparseIntArray newPositions = new SparseIntArray();

    for (int i = 0, size = positions.size(); i < size; i++) {
        int position = positions.keyAt(i);

        //if our current position is not within the bounds to check for we can add it
        if (position < startPosition || position > endPosition) {
            newPositions.put(position, positions.valueAt(i));
        } else if (adjustBy > 0) {
            //if we added items and we are within the bounds we can simply add the adjustBy to our entry
            newPositions.put(position + adjustBy, positions.valueAt(i));
        } else if (adjustBy < 0) {
            //if we removed items and we are within the bounds we have to check if the item was removed
            //adjustBy is negative in this case
            if (position > startPosition + adjustBy && position <= startPosition) {
                ;//we are within the removed items range we don't add this item anymore
            } else {
                //otherwise we adjust our position
                newPositions.put(position + adjustBy, positions.valueAt(i));
            }
        }
    }

    return newPositions;
}

From source file:es.uniovi.imovil.fcrtrainer.highscores.HighscoreManager.java

private static ArrayList<Highscore> trim(ArrayList<Highscore> highscores, int maxNumberHighscores) {
    ArrayList<Highscore> trimmedHighscores = new ArrayList<Highscore>();
    SparseIntArray highscoresPerExercise = new SparseIntArray();

    Collections.sort(highscores);
    Collections.reverse(highscores);

    for (int i = 0; i < highscores.size(); i++) {
        int exercise = highscores.get(i).getExercise();
        if (highscoresPerExercise.get(exercise) != 0) {
            int numHighscores = highscoresPerExercise.get(exercise);
            if (numHighscores < maxNumberHighscores) {
                highscoresPerExercise.put(exercise, numHighscores + 1);
                trimmedHighscores.add(highscores.get(i));
            }// w ww  .jav  a  2  s  . c om
        } else {
            highscoresPerExercise.put(exercise, 1);
            trimmedHighscores.add(highscores.get(i));
        }
    }

    return trimmedHighscores;
}

From source file:com.xperia64.timidityae.Globals.java

public static SparseIntArray validBuffers(int[] rates, boolean stereo, boolean sixteen) {
    SparseIntArray buffers = new SparseIntArray();
    for (int rate : rates) {
        buffers.put(rate,
                AudioTrack.getMinBufferSize(rate,
                        (stereo) ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO,
                        (sixteen) ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT));
    }/*  w w  w . j a v  a  2  s. c o m*/
    return buffers;
    /*HashMap<Integer, Integer> buffers = new HashMap<Integer, Integer>();
    for(int rate : rates)
    {
       buffers.put(rate, AudioTrack.getMinBufferSize(rate, (stereo)?AudioFormat.CHANNEL_OUT_STEREO:AudioFormat.CHANNEL_OUT_MONO, (sixteen)?AudioFormat.ENCODING_PCM_16BIT:AudioFormat.ENCODING_PCM_8BIT));
    }
    return buffers;*/
}

From source file:altermarkive.uploader.Config.java

@SuppressWarnings("unused")
public int[] initiate(int[] types, String[] vendors, String[] names, int[] delays, float[] resolutions,
        int[] sizes) {
    SparseIntArray indices = new SparseIntArray();
    for (int i = MIN_TYPE; i <= MAX_TYPE; i++) {
        indices.put(i, 0);
    }//from   www. j  ava2 s .c  o  m
    int[] periods = new int[types.length];
    Arrays.fill(periods, 0);
    for (int i = 0; i < types.length; i++) {
        String identifier = String.format("%d, %s, %s", types[i], vendors[i], names[i]);
        if (types[i] < MIN_TYPE || MAX_TYPE < types[i] || sizes[i] == 0) {
            String message = String.format("Ignored sensor: %s", identifier);
            Log.i(TAG, message);
            continue;
        }
        // Find the period and update sensor index
        int index = indices.get(types[i]);
        periods[i] = sampling(types[i], index);
        indices.put(types[i], index + 1);
        // Update the name of the sensor
        naming(types[i], index, names[i]);
        // Clip period based on minimum delay reported
        if (0 < periods[i]) {
            periods[i] = Math.max(periods[i], delays[i] / 1000);
            String message = String.format("The period for sensor #%d (%s) is %d", i, identifier, periods[i]);
            Log.i(TAG, message);
        }
    }
    sampler.data().initiate(sizes, periods, storing());
    try {
        String report = Report.report(sampler.context(), types, vendors, names, resolutions, delays, null,
                null);
        Storage.writeText("device.json", report);
    } catch (JSONException exception) {
        String trace = Log.getStackTraceString(exception);
        String message = String.format("Failed to report on device specification:\n%s", trace);
        Log.e(TAG, message);
    }
    return periods;
}

From source file:br.liveo.ndrawer.MainActivity.java

@Override
public void onInt(Bundle savedInstanceState) {
    //Creation of the list items is here

    // set listener {required}
    this.setNavigationListener(this);

    //First item of the position selected from the list
    this.setDefaultStartPositionNavigation(1);

    // name of the list items
    mListNameItem = new ArrayList<>();
    mListNameItem.add(0, getString(R.string.inbox));
    mListNameItem.add(1, getString(R.string.starred));
    mListNameItem.add(2, getString(R.string.sent_mail));
    mListNameItem.add(3, getString(R.string.drafts));
    mListNameItem.add(4, getString(R.string.more_markers)); //This item will be a subHeader
    mListNameItem.add(5, getString(R.string.trash));
    mListNameItem.add(6, getString(R.string.spam));

    // icons list items
    List<Integer> mListIconItem = new ArrayList<>();
    mListIconItem.add(0, R.drawable.ic_inbox_black_24dp);
    mListIconItem.add(1, R.drawable.ic_star_black_24dp); //Item no icon set 0
    mListIconItem.add(2, R.drawable.ic_send_black_24dp); //Item no icon set 0
    mListIconItem.add(3, R.drawable.ic_drafts_black_24dp);
    mListIconItem.add(4, 0); //When the item is a subHeader the value of the icon 0
    mListIconItem.add(5, R.drawable.ic_delete_black_24dp);
    mListIconItem.add(6, R.drawable.ic_report_black_24dp);

    //{optional} - Among the names there is some subheader, you must indicate it here
    List<Integer> mListHeaderItem = new ArrayList<>();
    mListHeaderItem.add(4);/*from   w  ww  .  j  a v  a 2 s .  co  m*/

    //{optional} - Among the names there is any item counter, you must indicate it (position) and the value here
    SparseIntArray mSparseCounterItem = new SparseIntArray(); //indicate all items that have a counter
    mSparseCounterItem.put(0, 7);
    mSparseCounterItem.put(1, 123);
    mSparseCounterItem.put(6, 250);

    //If not please use the FooterDrawer use the setFooterVisible(boolean visible) method with value false
    this.setFooterInformationDrawer(R.string.settings, R.drawable.ic_settings_black_24dp);

    this.setNavigationAdapter(mListNameItem, mListIconItem, mListHeaderItem, mSparseCounterItem);
}

From source file:yang.mobile.activity.MainActivity.java

@Override
public void onInt(Bundle savedInstanceState) {
    //Creation of the list items is here

    // set listener {required}
    this.setNavigationListener(this);

    //First item of the position selected from the list
    this.setDefaultStartPositionNavigation(1);

    // name of the list items
    mListNameItem = new ArrayList<>();
    mListNameItem.add(0, "");
    mListNameItem.add(1, "??");
    mListNameItem.add(2, "");
    mListNameItem.add(3, "");
    mListNameItem.add(4, "");
    mListNameItem.add(5, "");
    mListNameItem.add(6, "");

    fragmentList.add(FragmentHome.class);
    fragmentList.add(FragmentHome.class);

    // icons list items
    List<Integer> mListIconItem = new ArrayList<>();
    mListIconItem.add(0, R.drawable.ic_inbox_black_24dp);
    mListIconItem.add(1, R.drawable.ic_star_black_24dp); //Item no icon set 0
    mListIconItem.add(2, R.drawable.ic_send_black_24dp); //Item no icon set 0
    mListIconItem.add(3, R.drawable.ic_drafts_black_24dp);
    mListIconItem.add(4, R.drawable.ic_send_black_24dp); //When the item is a subHeader the value of the icon 0
    mListIconItem.add(5, R.drawable.ic_delete_black_24dp);
    mListIconItem.add(6, R.drawable.ic_report_black_24dp);

    //{optional} - Among the names there is some subheader, you must indicate it here
    List<Integer> mListHeaderItem = new ArrayList<>();
    mListHeaderItem.add(4);//from ww  w .j  a v  a2 s.c  om

    //{optional} - Among the names there is any item counter, you must indicate it (position) and the value here
    SparseIntArray mSparseCounterItem = new SparseIntArray(); //indicate all items that have a counter
    mSparseCounterItem.put(0, 7);
    mSparseCounterItem.put(1, 123);
    mSparseCounterItem.put(6, 250);

    //If not please use the FooterDrawer use the setFooterVisible(boolean visible) method with value false
    this.setFooterInformationDrawer(R.string.settings, R.drawable.ic_settings_black_24dp);

    this.setNavigationAdapter(mListNameItem, mListIconItem);
}

From source file:android.databinding.ViewDataBinding.java

/** @hide */
protected static void setTo(SparseIntArray list, int index, int value) {
    if (list == null || index < 0 || index >= list.size()) {
        return;//from   ww  w .  j av a 2 s  .c om
    }
    list.put(index, value);
}