Example usage for android.util SparseIntArray SparseIntArray

List of usage examples for android.util SparseIntArray SparseIntArray

Introduction

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

Prototype

public SparseIntArray() 

Source Link

Document

Creates a new SparseIntArray containing no mappings.

Usage

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);/*from w  w w.java2 s  .  c  o m*/
        } else {
            map.put(i, 0);
        }
    }
    return map;
}

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   www.  ja  v  a 2  s. com*/
    return countMap;
}

From source file:com.norman0406.slimgress.API.Knobs.WeaponRangeKnobs.java

public WeaponRangeKnobs(JSONObject json) throws JSONException {
    super(json);/*from w w w.j  a v  a2s . c o m*/

    JSONObject ultraStrikeDamageRangeMap = json.getJSONObject("ultraStrikeDamageRangeMap");
    mUltraStrikeDamageRangeMap = new SparseIntArray();
    Iterator<?> it1 = ultraStrikeDamageRangeMap.keys();
    while (it1.hasNext()) {
        String strKey = (String) it1.next();
        Integer key = Integer.parseInt(strKey);
        mUltraStrikeDamageRangeMap.put(key, ultraStrikeDamageRangeMap.getInt(strKey));
    }

    JSONObject xmpDamageRangeMap = json.getJSONObject("xmpDamageRangeMap");
    mXmpDamageRangeMap = new SparseIntArray();
    Iterator<?> it2 = xmpDamageRangeMap.keys();
    while (it2.hasNext()) {
        String strKey = (String) it2.next();
        Integer key = Integer.parseInt(strKey);
        mXmpDamageRangeMap.put(key, xmpDamageRangeMap.getInt(strKey));
    }
}

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   w  w  w. ja  va2  s. c  o 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:at.wada811.android.library.demos.loader.LoaderListAdapter.java

public LoaderListAdapter(Context context, LoaderManager loaderManager) {
    super(context, android.R.layout.simple_list_item_1);
    mContext = context;//from   ww  w.ja v a2  s  .com
    mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mLoaderManager = loaderManager;
    mHandler = new Handler();
    mLoaderIds = new SparseIntArray();
}

From source file:com.mobile.godot.core.controller.CoreController.java

public synchronized void pop(String username) {

    String servlet = "PopMessage";
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("username", username));
    SparseIntArray mMessageMap = new SparseIntArray();
    mMessageMap.append(HttpURLConnection.HTTP_OK, GodotMessage.Core.MESSAGE_READ);

    GodotAction action = new GodotAction(servlet, params, mMessageMap, mHandler);
    Thread tAction = new Thread(action);
    tAction.start();/*from w  ww . j  av a  2s. co m*/

}

From source file:com.mobile.godot.core.controller.LoginController.java

public synchronized void login(LoginBean login) {

    String servlet = "Login";
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("username", login.getUsername()));
    params.add(new BasicNameValuePair("password", login.getPassword()));
    SparseIntArray mMessageMap = new SparseIntArray();
    mMessageMap.append(HttpURLConnection.HTTP_OK, GodotMessage.Session.LOGGED_IN);
    mMessageMap.append(HttpURLConnection.HTTP_UNAUTHORIZED, GodotMessage.Session.NOT_LOGGED);

    GodotAction action = new GodotAction(servlet, params, mMessageMap, mHandler);
    Thread tAction = new Thread(action);
    tAction.start();/*w  w  w  . ja v a  2  s . c  o  m*/

}

From source file:com.mobile.godot.core.controller.CoreController.java

public synchronized void approach(String username, String carName) {

    String servlet = "Approach";
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("username", username));
    params.add(new BasicNameValuePair("carName", carName));
    SparseIntArray mMessageMap = new SparseIntArray();
    mMessageMap.append(HttpURLConnection.HTTP_ACCEPTED, GodotMessage.Core.DRIVER_UPDATED);
    mMessageMap.append(HttpURLConnection.HTTP_CREATED, GodotMessage.Core.MESSAGE_SENT);
    mMessageMap.append(HttpURLConnection.HTTP_NOT_FOUND, GodotMessage.Core.CAR_NOT_FOUND);
    mMessageMap.append(HttpURLConnection.HTTP_UNAUTHORIZED, GodotMessage.Error.UNAUTHORIZED);

    GodotAction action = new GodotAction(servlet, params, mMessageMap, mHandler);
    Thread tAction = new Thread(action);
    tAction.start();/*from   w w w.jav a  2 s. com*/

}

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;//w  w  w  .  j a v a 2 s .c  om
}

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);/*  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, mListHeaderItem, mSparseCounterItem);
}