List of usage examples for android.util SparseIntArray get
public int get(int key)
0
if no such mapping has been made. 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)); }/*from w ww . j a va2s. c o m*/ } else { highscoresPerExercise.put(exercise, 1); trimmedHighscores.add(highscores.get(i)); } } return trimmedHighscores; }
From source file:com.xperia64.timidityae.Globals.java
public static boolean updateBuffers(int[] rata) { if (rata != null) { SparseIntArray buffMap = Globals.validBuffers(rata, prefs.getString("sdlChanValue", "2").equals("2"), true/*prefs.getString("tplusBits", "16").equals("16")*/); int realMin = buffMap.get(Integer.parseInt(prefs.getString("tplusRate", Integer.toString(AudioTrack.getNativeOutputSampleRate(AudioTrack.MODE_STREAM))))); if (buff < realMin) { prefs.edit().putString("tplusBuff", Integer.toString(buff = realMin)).commit(); return false; }/*from ww w . j a v a2 s. co m*/ } return true; }
From source file:android.databinding.ViewDataBinding.java
/** @hide */ protected static int getFromList(SparseIntArray list, int index) { if (list == null || index < 0) { return 0; }//from w w w. java 2 s . com return list.get(index); }
From source file:io.fabric.samples.cannonball.activity.PoemBuilderActivity.java
private void createPoem() { if (poemContainer.getChildCount() > 0) { final String poemText = getPoemText(); final SparseIntArray imgList = poemTheme.getImageList(); // the line below seems weird, but relies on the fact that the index of SparseIntArray could be any integer final int poemImage = imgList .keyAt(imgList.indexOfValue(imgList.get(poemImagePager.getCurrentItem() + 1))); Crashlytics.setString(App.CRASHLYTICS_KEY_POEM_TEXT, poemText); Crashlytics.setInt(App.CRASHLYTICS_KEY_POEM_IMAGE, poemImage); AppService.createPoem(getApplicationContext(), poemText, poemImage, poemTheme.getDisplayName(), dateFormat.format(Calendar.getInstance().getTime())); } else {/*from w w w.j a v a 2 s .c o m*/ Toast.makeText(getApplicationContext(), getResources().getString(R.string.toast_wordless_poem), Toast.LENGTH_SHORT).show(); Crashlytics.log("PoemBuilder: User tried to create poem without words on it"); } }
From source file:galilei.kelimekavanozu.activity.PoemBuilderActivity.java
private void createPoem() { if (poemContainer.getChildCount() > 0) { final String poemText = getPoemText(); final SparseIntArray imgList = poemTheme.getImageList(); // the line below seems weird, but relies on the fact that the index of SparseIntArray could be any integer final int poemImage = imgList .keyAt(imgList.indexOfValue(imgList.get(poemImagePager.getCurrentItem() + 1))); Crashlytics.setString(App.CRASHLYTICS_KEY_POEM_TEXT, poemText); Crashlytics.setInt(App.CRASHLYTICS_KEY_POEM_IMAGE, poemImage); Answers.getInstance().logCustom( new CustomEvent("clicked save poem").putCustomAttribute("poem size", poemText.length()) .putCustomAttribute("poem theme", poemTheme.getDisplayName()) .putCustomAttribute("poem image", poemImage)); AppService.createPoem(getApplicationContext(), poemText, poemImage, poemTheme.getDisplayName(), dateFormat.format(Calendar.getInstance().getTime())); } else {//from w w w. j a v a 2s. c o m Toast.makeText(getApplicationContext(), getResources().getString(R.string.toast_wordless_poem), Toast.LENGTH_SHORT).show(); Crashlytics.log("PoemBuilder: User tried to create poem without words on it"); } }
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 ww. j a v a 2 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:org.voidsink.anewjkuapp.fragment.CalendarFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { mAdapter.clear();/*from w w w. jav a 2 s. co m*/ 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:net.naonedbus.manager.impl.FavoriManager.java
/** * Remplacer les favoris par ceux de la liste * //from ww w . ja v a 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:com.google.android.flexbox.FlexboxHelper.java
/** * Returns if any of the children's {@link FlexItem#getOrder()} attributes are * changed from the last measurement.// w ww .j a va2s. c om * * @return {@code true} if changed from the last measurement, {@code false} otherwise. */ boolean isOrderChangedFromLastMeasurement(SparseIntArray orderCache) { int childCount = mFlexContainer.getFlexItemCount(); if (orderCache.size() != childCount) { return true; } for (int i = 0; i < childCount; i++) { View view = mFlexContainer.getFlexItemAt(i); if (view == null) { continue; } FlexItem flexItem = (FlexItem) view.getLayoutParams(); if (flexItem.getOrder() != orderCache.get(i)) { return true; } } return false; }
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 w ww . j a v a2 s. 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()) { 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(); }