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: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,//from   w ww .  jav a2  s. c o  m
                AudioTrack.getMinBufferSize(rate,
                        (stereo) ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO,
                        (sixteen) ? AudioFormat.ENCODING_PCM_16BIT : AudioFormat.ENCODING_PCM_8BIT));
    }
    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:com.mobile.godot.core.controller.CoreController.java

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

    String servlet = "RemoveCoOwner";
    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_REMOVED);
    mMessageMap.append(HttpURLConnection.HTTP_UNAUTHORIZED, GodotMessage.Error.UNAUTHORIZED);

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

}

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

public synchronized void findCarByDriver(String username) {

    String servlet = "FindCarByDriver";
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("username", username));
    SparseIntArray mMessageMap = new SparseIntArray();
    mMessageMap.append(HttpURLConnection.HTTP_OK, GodotMessage.Entity.CAR_BY_DRIVER_FOUND);
    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  ww.j av a2  s.co m*/

}

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

public synchronized void findCarsByOwner(String username) {

    String servlet = "FindCarsByOwner";
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("username", username));
    SparseIntArray mMessageMap = new SparseIntArray();
    mMessageMap.append(HttpURLConnection.HTTP_OK, GodotMessage.Entity.CARS_BY_OWNER_FOUND);
    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  a2s  .  c  o  m*/

}

From source file:net.naonedbus.manager.impl.FavoriManager.java

/**
 * Remplacer les favoris par ceux de la liste
 * /*from w w  w . j  a  va 2s  .co  m*/
 * @param contentResolver
 * @param container
 */
private void fromList(final ContentResolver contentResolver, final FavoriContainer container) {
    final ArretManager arretManager = ArretManager.getInstance();
    final GroupeManager groupeManager = GroupeManager.getInstance();
    final SparseIntArray groupeMapping = new SparseIntArray();

    // Delete old items
    contentResolver.delete(FavoriProvider.CONTENT_URI, null, null);
    contentResolver.delete(GroupeProvider.CONTENT_URI, null, null);

    // Add new items
    for (final net.naonedbus.rest.container.FavoriContainer.Groupe g : container.groupes) {
        final Groupe groupe = new Groupe();
        groupe.setNom(g.nom);
        groupe.setOrdre(g.ordre);

        final int idLocal = groupeManager.add(contentResolver, groupe).intValue();
        groupeMapping.put(g.id, idLocal);
    }

    Integer itemId;
    final Favori.Builder builder = new Favori.Builder();
    for (final net.naonedbus.rest.container.FavoriContainer.Favori f : container.favoris) {
        builder.setCodeArret(f.codeArret);
        builder.setCodeSens(f.codeSens);
        builder.setCodeLigne(f.codeLigne);
        builder.setNomFavori(f.nomFavori);

        itemId = arretManager.getIdByFavori(contentResolver, builder.build());
        if (itemId != null) {
            builder.setId(itemId);
            addFavori(contentResolver, builder.build());

            // Associer aux groupes
            final List<Integer> favoriGroupes = f.idGroupes;
            if (favoriGroupes != null)
                for (final Integer idGroupe : favoriGroupes) {
                    if (groupeMapping.indexOfKey(idGroupe) > -1) {
                        groupeManager.addFavoriToGroup(contentResolver, groupeMapping.get(idGroupe), itemId);
                    }
                }
        }
    }
}

From source file:org.voidsink.anewjkuapp.fragment.CalendarFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mAdapter.clear();//from   w w  w  .  jav a2s  . c  om

    Account mAccount = AppUtils.getAccount(getContext());
    if (mAccount != null) {
        // fetch calendar colors
        final SparseIntArray mColors = new SparseIntArray();
        ContentResolver cr = getContext().getContentResolver();
        Cursor cursor = cr.query(CalendarContractWrapper.Calendars.CONTENT_URI(), new String[] {
                CalendarContractWrapper.Calendars._ID(), CalendarContractWrapper.Calendars.CALENDAR_COLOR() },
                null, null, null);
        if (cursor != null) {
            while (cursor.moveToNext()) {
                mColors.put(cursor.getInt(0), cursor.getInt(1));
            }
            cursor.close();
        }

        List<CalendarListEvent> mEvents = new ArrayList<>();

        if (data != null) {
            data.moveToFirst();
            data.moveToPrevious();
            while (data.moveToNext()) {
                mEvents.add(new CalendarListEvent(getContext(), data.getLong(CalendarUtils.COLUMN_EVENT_ID),
                        mColors.get(data.getInt(CalendarUtils.COLUMN_EVENT_CAL_ID)),
                        data.getString(CalendarUtils.COLUMN_EVENT_TITLE),
                        data.getString(CalendarUtils.COLUMN_EVENT_DESCRIPTION),
                        data.getString(CalendarUtils.COLUMN_EVENT_LOCATION),
                        data.getLong(CalendarUtils.COLUMN_EVENT_DTSTART),
                        data.getLong(CalendarUtils.COLUMN_EVENT_DTEND),
                        data.getInt(CalendarUtils.COLUMN_EVENT_ALL_DAY) == 1));
            }
        }

        mAdapter.addAll(mEvents);
    }

    mAdapter.notifyDataSetChanged();

    finishProgress();
}

From source file:org.voidsink.anewjkuapp.fragment.CalendarFragment2.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    ArrayList<WeekViewEvent> events = mWeekViewLoader.getEvents(loader.getId());
    events.clear();/*from  www. ja v a 2s  .com*/

    Account mAccount = AppUtils.getAccount(getContext());
    if (mAccount != null) {
        // fetch calendar colors
        final SparseIntArray mColors = new SparseIntArray();
        ContentResolver cr = getContext().getContentResolver();
        Cursor cursor = cr.query(CalendarContractWrapper.Calendars.CONTENT_URI(), new String[] {
                CalendarContractWrapper.Calendars._ID(), CalendarContractWrapper.Calendars.CALENDAR_COLOR() },
                null, null, null);
        if (cursor != null) {
            while (cursor.moveToNext()) {
                int color = cursor.getInt(1);

                double lastContrast = ColorUtils.calculateContrast(color, mWeekView.getEventTextColor());
                //Log.d(TAG, String.format("color=%d %d %d, contrast=%f", Color.red(color), Color.green(color), Color.blue(color), lastContrast));

                while (lastContrast < 1.6) {
                    float[] hsv = new float[3];

                    Color.colorToHSV(color, hsv);
                    hsv[2] = Math.max(0f, hsv[2] - 0.033f); // darken
                    color = Color.HSVToColor(hsv);

                    lastContrast = ColorUtils.calculateContrast(color, mWeekView.getEventTextColor());
                    //Log.d(TAG, String.format("new color=%d %d %d, contrast=%f", Color.red(color), Color.green(color), Color.blue(color), lastContrast));

                    if (hsv[2] == 0)
                        break;
                }

                mColors.put(cursor.getInt(0), color);
            }
            cursor.close();
        }

        if (data != null) {
            data.moveToFirst();
            data.moveToPrevious();
            while (data.moveToNext()) {

                boolean allDay = data.getInt(CalendarUtils.COLUMN_EVENT_ALL_DAY) == 1;

                Calendar startTime = Calendar.getInstance();
                if (allDay) {
                    startTime.setTimeZone(TimeZone.getTimeZone("UTC"));
                }
                startTime.setTimeInMillis(data.getLong(CalendarUtils.COLUMN_EVENT_DTSTART));

                Calendar endTime = Calendar.getInstance();
                if (allDay) {
                    endTime.setTimeZone(TimeZone.getTimeZone("UTC"));
                }
                endTime.setTimeInMillis(data.getLong(CalendarUtils.COLUMN_EVENT_DTEND));
                if (allDay && endTime.getTimeInMillis() % DateUtils.DAY_IN_MILLIS == 0) {
                    endTime.add(Calendar.MILLISECOND, -1);
                }

                WeekViewEvent event = new WeekViewEvent(data.getLong(CalendarUtils.COLUMN_EVENT_ID),
                        data.getString(CalendarUtils.COLUMN_EVENT_TITLE),
                        data.getString(CalendarUtils.COLUMN_EVENT_LOCATION), startTime, endTime, allDay);

                event.setColor(mColors.get(data.getInt(CalendarUtils.COLUMN_EVENT_CAL_ID)));

                events.add(event);
            }
        }
    }

    mWeekView.notifyDatasetChanged();
}

From source file:org.chromium.chrome.browser.tabmodel.TabPersistentStore.java

/**
 * Restore saved state. Must be called before any tabs are added to the list.
 *
 * This will read the metadata file for the current TabPersistentStore and the metadata file
 * from another TabPersistentStore if applicable. When restoreTabs() is called, tabs from both
 * will be restored into this instance./*from   w  w w  . ja  v  a 2 s . c  om*/
 *
 * @param ignoreIncognitoFiles Whether to skip loading incognito tabs.
 */
public void loadState(boolean ignoreIncognitoFiles) {
    long time = SystemClock.uptimeMillis();

    // If a cleanup task is in progress, cancel it before loading state.
    mPersistencePolicy.cancelCleanupInProgress();

    waitForMigrationToFinish();
    logExecutionTime("LoadStateTime", time);

    mCancelNormalTabLoads = false;
    mCancelIncognitoTabLoads = ignoreIncognitoFiles;
    mNormalTabsRestored = new SparseIntArray();
    mIncognitoTabsRestored = new SparseIntArray();
    try {
        long timeLoadingState = SystemClock.uptimeMillis();
        assert mTabModelSelector.getModel(true).getCount() == 0;
        assert mTabModelSelector.getModel(false).getCount() == 0;
        checkAndUpdateMaxTabId();
        DataInputStream stream;
        if (mPrefetchTabListTask != null) {
            long timeWaitingForPrefetch = SystemClock.uptimeMillis();
            stream = mPrefetchTabListTask.get();

            // Restore the tabs for this TabPeristentStore instance if the tab metadata file
            // exists.
            if (stream != null) {
                logExecutionTime("LoadStateInternalPrefetchTime", timeWaitingForPrefetch);
                mLoadInProgress = true;
                readSavedStateFile(stream,
                        createOnTabStateReadCallback(mTabModelSelector.isIncognitoSelected(), false), null,
                        false);
                logExecutionTime("LoadStateInternalTime", timeLoadingState);
            }
        }

        // Restore the tabs for the other TabPeristentStore instance if its tab metadata file
        // exists.
        if (mPrefetchTabListToMergeTask != null) {
            long timeMergingState = SystemClock.uptimeMillis();
            stream = mPrefetchTabListToMergeTask.get();
            if (stream != null) {
                logExecutionTime("MergeStateInternalFetchTime", timeMergingState);
                mPersistencePolicy.setMergeInProgress(true);
                readSavedStateFile(stream, createOnTabStateReadCallback(mTabModelSelector.isIncognitoSelected(),
                        mTabsToRestore.size() == 0 ? false : true), null, true);
                logExecutionTime("MergeStateInternalTime", timeMergingState);
                RecordUserAction.record("Android.MergeState.ColdStart");
            }
        }
    } catch (Exception e) {
        // Catch generic exception to prevent a corrupted state from crashing app on startup.
        Log.d(TAG, "loadState exception: " + e.toString(), e);
    }

    if (mObserver != null)
        mObserver.onInitialized(mTabsToRestore.size());
}

From source file:org.chromium.chrome.browser.tabmodel.TabPersistentStore.java

/**
 * Merge the tabs of the other Chrome instance into this instance by reading its tab metadata
 * file and tab state files.// ww  w  .j  a  v a 2 s.  co  m
 *
 * This method should be called after a change in activity state indicates that a merge is
 * necessary. #loadState() will take care of merging states on application cold start if needed.
 *
 * If there is currently a merge or load in progress then this method will return early.
 */
public void mergeState() {
    if (mLoadInProgress || mPersistencePolicy.isMergeInProgress() || !mTabsToRestore.isEmpty()) {
        Log.e(TAG, "Tab load still in progress when merge was attempted.");
        return;
    }

    // Initialize variables.
    mCancelNormalTabLoads = false;
    mCancelIncognitoTabLoads = false;
    mNormalTabsRestored = new SparseIntArray();
    mIncognitoTabsRestored = new SparseIntArray();

    try {
        long time = SystemClock.uptimeMillis();
        // Read the tab state metadata file.
        DataInputStream stream = startFetchTabListTask(AsyncTask.SERIAL_EXECUTOR,
                mPersistencePolicy.getStateToBeMergedFileName()).get();

        // Return early if the stream is null, which indicates there isn't a second instance
        // to merge.
        if (stream == null)
            return;
        logExecutionTime("MergeStateInternalFetchTime", time);
        mPersistencePolicy.setMergeInProgress(true);
        readSavedStateFile(stream, createOnTabStateReadCallback(mTabModelSelector.isIncognitoSelected(), true),
                null, true);
        logExecutionTime("MergeStateInternalTime", time);
    } catch (Exception e) {
        // Catch generic exception to prevent a corrupted state from crashing app.
        Log.d(TAG, "meregeState exception: " + e.toString(), e);
    }

    // Restore the tabs from the second activity asynchronously.
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            mMergeTabCount = mTabsToRestore.size();
            mRestoreMergedTabsStartTime = SystemClock.uptimeMillis();
            restoreTabs(false);
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:org.catrobat.catroid.uitest.util.UiTestUtils.java

private static void initBrickCategoryMap() {
    brickCategoryMap = new SparseIntArray();

    //brickCategoryMap.put(R.string.brick_place_at_x, R.string.category_motion);
    brickCategoryMap.put(R.string.brick_set_x, R.string.category_motion);
    brickCategoryMap.put(R.string.brick_set_y, R.string.category_motion);
    brickCategoryMap.put(R.string.brick_change_x_by, R.string.category_motion);
    brickCategoryMap.put(R.string.brick_change_y_by, R.string.category_motion);
    brickCategoryMap.put(R.string.brick_go_back, R.string.category_motion);
    brickCategoryMap.put(R.string.brick_come_to_front, R.string.category_motion);
    brickCategoryMap.put(R.string.brick_if_on_edge_bounce, R.string.category_motion);
    //brickCategoryMap.put(R.string.brick_move_n_steps, R.string.category_motion);
    brickCategoryMap.put(R.string.brick_turn_left, R.string.category_motion);
    brickCategoryMap.put(R.string.brick_turn_right, R.string.category_motion);
    brickCategoryMap.put(R.string.brick_point_in_direction, R.string.category_motion);
    brickCategoryMap.put(R.string.brick_point_to, R.string.category_motion);
    brickCategoryMap.put(R.string.brick_glide, R.string.category_motion);

    brickCategoryMap.put(R.string.brick_set_look, R.string.category_looks);
    brickCategoryMap.put(R.string.brick_set_size_to, R.string.category_looks);
    brickCategoryMap.put(R.string.brick_change_size_by, R.string.category_looks);
    brickCategoryMap.put(R.string.brick_hide, R.string.category_looks);
    brickCategoryMap.put(R.string.brick_show, R.string.category_looks);
    brickCategoryMap.put(R.string.brick_set_transparency, R.string.category_looks);
    brickCategoryMap.put(R.string.brick_set_brightness, R.string.category_looks);
    brickCategoryMap.put(R.string.brick_change_brightness, R.string.category_looks);
    brickCategoryMap.put(R.string.brick_clear_graphic_effect, R.string.category_looks);
    //brickCategoryMap.put(R.string.brick_say, R.string.category_looks);
    //brickCategoryMap.put(R.string.brick_think, R.string.category_looks);

    brickCategoryMap.put(R.string.brick_play_sound, R.string.category_sound);
    brickCategoryMap.put(R.string.brick_stop_all_sounds, R.string.category_sound);
    brickCategoryMap.put(R.string.brick_set_volume_to, R.string.category_sound);
    brickCategoryMap.put(R.string.brick_change_volume_by, R.string.category_sound);
    brickCategoryMap.put(R.string.brick_speak, R.string.category_sound);

    brickCategoryMap.put(R.string.brick_when_started, R.string.category_control);
    brickCategoryMap.put(R.string.brick_when, R.string.category_control);
    brickCategoryMap.put(R.string.brick_wait, R.string.category_control);
    brickCategoryMap.put(R.string.brick_broadcast_receive, R.string.category_control);
    brickCategoryMap.put(R.string.brick_broadcast, R.string.category_control);
    brickCategoryMap.put(R.string.brick_broadcast_wait, R.string.category_control);
    brickCategoryMap.put(R.string.brick_note, R.string.category_control);
    brickCategoryMap.put(R.string.brick_forever, R.string.category_control);
    brickCategoryMap.put(R.string.brick_repeat, R.string.category_control);
    brickCategoryMap.put(R.string.brick_if_begin, R.string.category_control);
    brickCategoryMap.put(R.string.brick_change_variable, R.string.category_data);
    brickCategoryMap.put(R.string.brick_set_variable, R.string.category_data);

    brickCategoryMap.put(R.string.nxt_brick_motor_move, R.string.category_lego_nxt);
}