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: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  www . j  av a  2  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: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);/*  w  w w .ja  va2 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:com.mobile.godot.core.controller.CoreController.java

public synchronized void register(UserBean user) {

    String servlet = "AddUser";
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("firstname", user.getFirstname()));
    params.add(new BasicNameValuePair("lastname", user.getLastname()));
    params.add(new BasicNameValuePair("mail", user.getMail()));
    params.add(new BasicNameValuePair("username", user.getUsername()));
    params.add(new BasicNameValuePair("password", user.getPassword()));
    SparseIntArray mMessageMap = new SparseIntArray();
    mMessageMap.append(HttpURLConnection.HTTP_OK, GodotMessage.Session.REGISTERED);
    mMessageMap.append(HttpURLConnection.HTTP_CONFLICT, GodotMessage.Error.CONFLICT);
    mMessageMap.append(HttpURLConnection.HTTP_NOT_ACCEPTABLE, GodotMessage.Error.UNACCEPTABLE);

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

}

From source file:nl.vincentketelaars.mexen.activities.RollDice.java

/** Called when the activity is first created. */
@Override//from   www . j  av  a 2  s  .c  o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Make title bar icon clickable, and go home
    getActionBar().setDisplayHomeAsUpEnabled(true);

    setVolumeControlStream(AudioManager.STREAM_MUSIC); // User can modify music volume
    soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
    soundMap = new SparseIntArray();
    soundMap.put(R.raw.roll, soundPool.load(this, R.raw.roll, 1)); // Note: If load returns 0 it failed

    activity = this;

    currentGame = new Game(currentMode);

    MGDbHelper = new MexGameDbHelper(this);

    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    getActionBar().setTitle(String.format(getResources().getString(R.string.roll_activity_name), numDice()));
}

From source file:com.bullmobi.message.services.media.MediaController2KitKat.java

/**
 * {@inheritDoc}/*from  w w  w  .j  av a 2 s  .c  om*/
 */
protected MediaController2KitKat(@NonNull Activity activity) {
    super(activity);

    SparseIntArray cachedStateSparse = sStateSparse.get();
    if (cachedStateSparse == null) {
        mStateSparse = new SparseIntArray();
        mStateSparse.put(RemoteControlClient.PLAYSTATE_BUFFERING, PlaybackStateCompat.STATE_BUFFERING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_PLAYING, PlaybackStateCompat.STATE_PLAYING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_PAUSED, PlaybackStateCompat.STATE_PAUSED);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_ERROR, PlaybackStateCompat.STATE_ERROR);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_REWINDING, PlaybackStateCompat.STATE_REWINDING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_FAST_FORWARDING,
                PlaybackStateCompat.STATE_FAST_FORWARDING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS,
                PlaybackStateCompat.STATE_SKIPPING_TO_NEXT);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS,
                PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS);

        // Cache sparse array
        sStateSparse = new WeakReference<>(mStateSparse);
    } else {
        mStateSparse = cachedStateSparse;
    }
}

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.  j  a v a  2s  .c  o  m*/
        } else {
            highscoresPerExercise.put(exercise, 1);
            trimmedHighscores.add(highscores.get(i));
        }
    }

    return trimmedHighscores;
}

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

public synchronized void addCar(CarBean car) {

    String servlet = "AddCar";
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("carName", car.getName()));
    params.add(new BasicNameValuePair("username", car.getOwnerUsername()));
    SparseIntArray mMessageMap = new SparseIntArray();
    mMessageMap.append(HttpURLConnection.HTTP_OK, GodotMessage.Entity.CAR_CREATED);
    mMessageMap.append(HttpURLConnection.HTTP_CONFLICT, GodotMessage.Error.CONFLICT);
    mMessageMap.append(HttpURLConnection.HTTP_NOT_ACCEPTABLE, GodotMessage.Error.UNACCEPTABLE);

    GodotAction action = new GodotAction(servlet, params, mMessageMap, mHandler);
    Thread tAction = new Thread(action);
    tAction.start();/* w ww .j av a2 s  . com*/

}

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

public synchronized void removeCar(String carName, LoginBean login) {

    String servlet = "RemoveCar";
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("carName", carName));
    params.add(new BasicNameValuePair("username", login.getUsername()));
    params.add(new BasicNameValuePair("password", login.getPassword()));
    SparseIntArray mMessageMap = new SparseIntArray();
    mMessageMap.append(HttpURLConnection.HTTP_OK, GodotMessage.Entity.CAR_REMOVED);
    mMessageMap.append(HttpURLConnection.HTTP_UNAUTHORIZED, GodotMessage.Error.UNAUTHORIZED);

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

}

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

public void genShuffledPlist() {
    shuffledIndices = new SparseIntArray();
    reverseShuffledIndices = new SparseIntArray();
    ArrayList<Integer> tmp = new ArrayList<Integer>();
    for (int i = 0; i < playList.size(); i++) {
        tmp.add(i);/*from  w  w w .ja v a2s.c  o  m*/
    }
    Collections.shuffle(tmp);

    for (int i = 0; i < playList.size(); i++) {
        shuffledIndices.put(i, tmp.get(i));
        reverseShuffledIndices.put(tmp.get(i), i);
    }
}

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

public synchronized void addCoOwner(String carName, String coOwnerUsername, LoginBean login) {

    String servlet = "AddCoOwner";
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("carName", carName));
    params.add(new BasicNameValuePair("coOwnerUsername", coOwnerUsername));
    params.add(new BasicNameValuePair("username", login.getUsername()));
    params.add(new BasicNameValuePair("password", login.getPassword()));
    SparseIntArray mMessageMap = new SparseIntArray();
    mMessageMap.append(HttpURLConnection.HTTP_OK, GodotMessage.Entity.COOWNER_ADDED);
    mMessageMap.append(HttpURLConnection.HTTP_UNAUTHORIZED, GodotMessage.Error.UNAUTHORIZED);
    mMessageMap.append(HttpURLConnection.HTTP_NOT_FOUND, GodotMessage.Error.NOT_FOUND);

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

}