List of usage examples for android.util SparseArray SparseArray
public SparseArray()
From source file:com.irccloud.android.Notifications.java
private void load() { mNotifications = new ArrayList<Notification>(); mNetworks = new SparseArray<String>(); mLastSeenEIDs = new SparseArray<Long>(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()); if (prefs.contains("notifications_json")) { try {/*from ww w. java2s. c o m*/ JSONArray array = new JSONArray(prefs.getString("networks_json", "[]")); for (int i = 0; i < array.length(); i++) { JSONObject o = array.getJSONObject(i); mNetworks.put(o.getInt("cid"), o.getString("network")); } array = new JSONArray(prefs.getString("lastseeneids_json", "[]")); for (int i = 0; i < array.length(); i++) { JSONObject o = array.getJSONObject(i); mLastSeenEIDs.put(o.getInt("bid"), o.getLong("eid")); } synchronized (mNotifications) { array = new JSONArray(prefs.getString("notifications_json", "[]")); for (int i = 0; i < array.length(); i++) { JSONObject o = array.getJSONObject(i); Notification n = new Notification(); n.bid = o.getInt("bid"); n.cid = o.getInt("cid"); n.eid = o.getLong("eid"); n.nick = o.getString("nick"); n.message = o.getString("message"); n.chan = o.getString("chan"); n.buffer_type = o.getString("buffer_type"); n.message_type = o.getString("message_type"); n.network = mNetworks.get(n.cid); if (o.has("shown")) n.shown = o.getBoolean("shown"); mNotifications.add(n); } Collections.sort(mNotifications, new comparator()); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:org.videolan.vlc.gui.audio.AudioBrowserListAdapter.java
public AudioBrowserListAdapter(Activity context, int itemType) { mMediaItemMap = new ArrayMap<>(); mSeparatorItemMap = new ArrayMap<>(); mItems = new ArrayList<>(); mSections = new SparseArray<>(); mContext = context;/*w ww. ja v a 2 s . c o m*/ if (itemType != ITEM_WITHOUT_COVER && itemType != ITEM_WITH_COVER) throw new IllegalArgumentException(); mItemType = itemType; SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); mAlignMode = Integer.valueOf(preferences.getString("audio_title_alignment", "0")); }
From source file:fr.cph.chicago.parser.XmlParser.java
/** * Parse arrivals//from w w w . j a v a 2s . co m * * @param is the xml string * @param trainData the train data * @return a list of train arrival * @throws ParserException the parser exception */ @NonNull public final synchronized SparseArray<TrainArrival> parseArrivals(@NonNull final InputStream is, @NonNull final TrainData trainData) throws ParserException { final SparseArray<TrainArrival> arrivals = new SparseArray<>(); try { parser.setInput(is, "UTF-8"); int eventType = parser.getEventType(); XmlArrivalTrainTag tag = null; //Date tmst = null; //Integer errCd = null; //String errNum = null; String tagName = null; Integer staId = null; while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { tagName = parser.getName(); switch (tagName) { case "tmst": tag = XmlArrivalTrainTag.TMST; break; case "errCd": tag = XmlArrivalTrainTag.ERRCD; break; case "errNm": tag = XmlArrivalTrainTag.ERRNM; break; case "eta": tag = XmlArrivalTrainTag.ETA; break; default: tag = XmlArrivalTrainTag.OTHER; break; } } else if (eventType == XmlPullParser.END_TAG) { tag = null; } else if (eventType == XmlPullParser.TEXT) { final String text = parser.getText(); switch (tag) { case ETA: break; case OTHER: switch (tagName) { case "staId": { staId = Integer.parseInt(text); final TrainArrival arri = arrivals.get(staId, new TrainArrival()); //arri.setErrorCode(errCd); //arri.setErrorMessage(errNum); //arri.setTimeStamp(tmst); List<Eta> etas = arri.getEtas(); if (etas == null) { etas = new ArrayList<>(); arri.setEtas(etas); } final Eta eta = new Eta(); final Optional<Station> station = trainData.getStation(staId); eta.setStation(station.orElse(new Station())); etas.add(eta); arrivals.append(staId, arri); break; } case "stpId": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); final Stop stop = trainData.getStop(Integer.parseInt(text)); currentEta.setStop(stop); } break; } case "staNm": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.getStation().setName(text); } break; } case "stpDe": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.getStop().setDescription(text); } break; } case "rn": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setRunNumber(Integer.parseInt(text)); } break; } case "rt": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setRouteName(TrainLine.fromXmlString(text)); } break; } case "destSt": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); final Integer i = Integer.parseInt(text); currentEta.setDestSt(i); } break; } case "destNm": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); if ("See train".equalsIgnoreCase(text) && currentEta.getStop().getDescription().contains("Loop") && currentEta.getRouteName() == TrainLine.GREEN) { currentEta.setDestName("Loop"); } else if ("See train".equalsIgnoreCase(text) && currentEta.getStop().getDescription().contains("Loop") && currentEta.getRouteName() == TrainLine.BROWN) { currentEta.setDestName("Loop"); } else if ("Loop, Midway".equalsIgnoreCase(text) && currentEta.getRouteName() == TrainLine.BROWN) { currentEta.setDestName("Loop"); } else { currentEta.setDestName(text); } } break; } case "trDr": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setTrainRouteDirectionCode(Integer.parseInt(text)); } break; } case "prdt": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setPredictionDate(simpleDateFormatTrain.parse(text)); } break; } case "arrT": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setArrivalDepartureDate(simpleDateFormatTrain.parse(text)); } break; } case "isApp": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setApp(BooleanUtils.toBoolean(Integer.parseInt(text))); } break; } case "isSch": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setSch(BooleanUtils.toBoolean(Integer.parseInt(text))); } break; } case "isDly": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setDly(BooleanUtils.toBoolean(Integer.parseInt(text))); } break; } case "isFlt": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setFlt(BooleanUtils.toBoolean(Integer.parseInt(text))); } break; } case "flags": break; case "lat": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); final Position position = new Position(); position.setLatitude(Double.parseDouble(text)); currentEta.setPosition(position); } break; } case "lon": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); final Position position = currentEta.getPosition(); position.setLongitude(Double.parseDouble(text)); } break; } case "heading": { final TrainArrival arri = arrivals.get(staId, null); if (arri != null) { final Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setHeading(Integer.parseInt(text)); } break; } } break; case TMST: //tmst = simpleDateFormatTrain.parse(text); break; case ERRCD: //errCd = Integer.parseInt(text); break; case ERRNM: //errNum = text; break; default: break; } } eventType = parser.next(); } } catch (final XmlPullParserException | ParseException | IOException e) { Log.e(TAG, e.getMessage(), e); throw new ParserException(TrackerException.ERROR, e); } finally { IOUtils.closeQuietly(is); } return arrivals; }
From source file:com.quarterfull.newsAndroid.ListView.SubscriptionExpandableListAdapter.java
public SubscriptionExpandableListAdapter(Context mContext, DatabaseConnectionOrm dbConn, ListView listView) { favIconHandler = new FavIconHandler(mContext); this.inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.mContext = mContext; this.dbConn = dbConn; mTextColorLightTheme = ContextCompat.getColor(mContext, R.color.slider_listview_text_color_light_theme); unreadCountFeeds = new SparseArray<>(); unreadCountFolders = new SparseArray<>(); starredCountFeeds = new SparseArray<>(); mCategoriesArrayList = new ArrayList<>(); mItemsArrayList = new SparseArray<>(); this.listView = listView; }
From source file:fr.cph.chicago.xml.Xml.java
/** * Parse arrivals/*w ww . j a v a 2 s . c om*/ * * @param xml * the xml string * @param data * the train data * @return a list of train arrival * @throws ParserException * the parser exception */ public final SparseArray<TrainArrival> parseArrivals(final String xml, final TrainData data) throws ParserException { InputStream is = new ByteArrayInputStream(xml.getBytes()); SparseArray<TrainArrival> arrivals = null; try { parser.setInput(is, "UTF-8"); int eventType = parser.getEventType(); XmlArrivalTrainTag tag = null; Date tmst = null; Integer errCd = null; String errNum = null; String tagName = null; Integer staId = null; while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_DOCUMENT) { arrivals = new SparseArray<TrainArrival>(); } else if (eventType == XmlPullParser.START_TAG) { tagName = parser.getName(); if (tagName.equals("tmst")) { tag = XmlArrivalTrainTag.TMST; } else if (tagName.equals("errCd")) { tag = XmlArrivalTrainTag.ERRCD; } else if (tagName.equals("errNm")) { tag = XmlArrivalTrainTag.ERRNM; } else if (tagName.equals("eta")) { tag = XmlArrivalTrainTag.ETA; } else { tag = XmlArrivalTrainTag.OTHER; } } else if (eventType == XmlPullParser.END_TAG) { tag = null; } else if (eventType == XmlPullParser.TEXT) { String text = parser.getText(); switch (tag) { case ETA: break; case OTHER: if (tagName.equals("staId")) { staId = Integer.valueOf(text); TrainArrival arri = arrivals.get(staId, new TrainArrival()); arri.setErrorCode(errCd); arri.setErrorMessage(errNum); arri.setTimeStamp(tmst); List<Eta> etas = arri.getEtas(); if (etas == null) { etas = new ArrayList<Eta>(); arri.setEtas(etas); } Eta eta = new Eta(); Station station = data.getStation(Integer.valueOf(text)); eta.setStation(station); etas.add(eta); arrivals.append(staId, arri); } else if (tagName.equals("stpId")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); Stop stop = data.getStop(Integer.valueOf(text)); currentEta.setStop(stop); } } else if (tagName.equals("staNm")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); Station station = currentEta.getStation(); station.setName(text); } } else if (tagName.equals("stpDe")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); Stop stop = currentEta.getStop(); stop.setDescription(text); } } else if (tagName.equals("rn")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setRunNumber(Integer.valueOf(text)); } } else if (tagName.equals("rt")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); TrainLine line = TrainLine.fromXmlString(text); currentEta.setRouteName(line); } } else if (tagName.equals("destSt")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); Integer i = Integer.valueOf(text); currentEta.setDestSt(i); } } else if (tagName.equals("destNm")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setDestName(text); } } else if (tagName.equals("trDr")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setTrainRouteDirectionCode(Integer.valueOf(text)); } } else if (tagName.equals("prdt")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setPredictionDate(dfTrain.parse(text)); } } else if (tagName.equals("arrT")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setArrivalDepartureDate(dfTrain.parse(text)); } } else if (tagName.equals("isApp")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setIsApp(BooleanUtils.toBoolean(Integer.valueOf(text))); } } else if (tagName.equals("isSch")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setIsSch(BooleanUtils.toBoolean(Integer.valueOf(text))); } } else if (tagName.equals("isDly")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setIsDly(BooleanUtils.toBoolean(Integer.valueOf(text))); } } else if (tagName.equals("isFlt")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setIsFlt(BooleanUtils.toBoolean(Integer.valueOf(text))); } } else if (tagName.equals("flags")) { } else if (tagName.equals("lat")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); Position position = new Position(); position.setLatitude(Double.valueOf(text)); currentEta.setPosition(position); } } else if (tagName.equals("lon")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); Position position = currentEta.getPosition(); position.setLongitude(Double.valueOf(text)); } } else if (tagName.equals("heading")) { TrainArrival arri = arrivals.get(staId, null); if (arri != null) { Eta currentEta = arri.getEtas().get(arri.getEtas().size() - 1); currentEta.setHeading(Integer.valueOf(text)); } } break; case TMST: tmst = dfTrain.parse(text); break; case ERRCD: errCd = Integer.valueOf(text); break; case ERRNM: errNum = text; break; default: break; } } eventType = parser.next(); } } catch (XmlPullParserException e) { throw new ParserException(TrackerException.ERROR, e); } catch (ParseException e) { throw new ParserException(TrackerException.ERROR, e); } catch (IOException e) { throw new ParserException(TrackerException.ERROR, e); } return arrivals; }
From source file:edu.nd.darts.cimon.CimonListView.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cimonlist);/*from w w w. j av a2s. c o m*/ category = getIntent().getExtras().getInt("key"); list = this.getExpandableListView(); list.setGroupIndicator(null); handler = new Handler(); switch (category) { case Metrics.TYPE_SYSTEM: adminObserver = SystemObserver.getInstance(); break; case Metrics.TYPE_SENSOR: adminObserver = SensorObserver.getInstance(); break; case Metrics.TYPE_USER: adminObserver = UserObserver.getInstance(); break; default: if (DebugLog.ERROR) Log.e(TAG, "CimonListView.onCreate - unknown category:" + category); } // this.setListAdapter(new SystemAdapter(this, ActiveMonitor.getInstance().getSystems())); getSupportLoaderManager().initLoader(0, null, this); adapter = new CimonListAdapter(this, adminObserver); this.setListAdapter(adapter); backgroundThread.start(); if (getApplicationContext().bindService(new Intent(NDroidService.class.getName()), mConnection, Context.BIND_AUTO_CREATE)) { if (DebugLog.DEBUG) Log.d(TAG, "CimonListView.onCreate - bind service. category:" + category); } else { if (DebugLog.DEBUG) Log.d(TAG, "CimonListView.onCreate - bind service failed. category:" + category); } monitorReports = new SparseArray<MonitorReport>(); /* backgroundHandler = new Handler(backgroundThread.getLooper()); backgroundHandler.post(new Runnable() { public void run() { serviceList = MetricService.getServices(category); } });*/ }
From source file:edu.umich.flowfence.service.NamespaceSharedPrefs.java
private NamespaceSharedPrefs(SharedPreferences basePrefs, String taintSetNamespace, Set<String> taintNamespaces) { mTaintSetNamespace = taintSetNamespace; mTaintNamespaces = taintNamespaces;// w w w . ja v a 2 s .c o m mBasePrefs = basePrefs; mKnownTaints = new SparseArray<>(); mListener = registerListener(); }
From source file:org.akop.crosswords.Storage.java
private Storage() { mPuzzleCache = new SparseArray<>(); mStateCache = new SparseArray<>(); mGson = new GsonBuilder().registerTypeAdapter(DateTime.class, new DateTimeAdapter()) .setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create(); }
From source file:com.conferenceengineer.android.iosched.ui.ScheduleFragment.java
private void loadActionModeState(Bundle state) { if (state != null && state.containsKey(STATE_ACTION_MODE)) { mActionModeStarted = true;/* w ww . ja v a 2 s .c o m*/ mActionMode = ((ActionBarActivity) getActivity()).startSupportActionMode(this); String[] data = state.getStringArray(STATE_ACTION_MODE); if (data != null) { mSelectedItemData = new SparseArray<String>(); mSelectedItemData.put(BlocksQuery.STARRED_SESSION_ID, data[0]); mSelectedItemData.put(BlocksQuery.STARRED_SESSION_TITLE, data[1]); mSelectedItemData.put(BlocksQuery.STARRED_SESSION_HASHTAGS, data[2]); mSelectedItemData.put(BlocksQuery.STARRED_SESSION_URL, data[3]); mSelectedItemData.put(BlocksQuery.STARRED_SESSION_ROOM_ID, data[4]); } } }
From source file:fr.eoit.parameter.Mining.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (DbUtil.hasAtLeastOneRow(cursor) && loader.getId() == LOADER_ID) { Log.d(LOG_TAG, "Reading cursor..."); while (!cursor.isAfterLast()) { AsteroidItemBean item = getItem(cursor); ItemBeanWithMaterials mineral = new ItemBeanWithMaterials(); mineral.id = cursor/* w w w. j a v a2 s .c om*/ .getInt(cursor.getColumnIndexOrThrow(ItemMaterials.COLUMN_NAME_MATERIAL_ITEM_ID)); mineral.quantity = cursor.getInt(cursor.getColumnIndexOrThrow(ItemMaterials.COLUMN_NAME_QUANTITY)); if (asteroids.containsKey(item.id)) { ((AsteroidItemBean) asteroids.get(item.id)).addMineral(mineral); } else { asteroids.append(item); item.addMineral(mineral); } cursor.moveToNext(); } asteroidMap = new SparseArray<TreeSet<ItemBeanWithMaterials>>(); asteroidMap.append(EOITConst.Items.TRITANIUM, new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.TRITANIUM))); asteroidMap.append(EOITConst.Items.PYERITE, new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.PYERITE))); asteroidMap.append(EOITConst.Items.MEXALLON, new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.MEXALLON))); asteroidMap.append(EOITConst.Items.ISOGEN, new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.ISOGEN))); asteroidMap.append(EOITConst.Items.NOCXIUM, new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.NOCXIUM))); asteroidMap.append(EOITConst.Items.ZYDRINE, new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.ZYDRINE))); asteroidMap.append(EOITConst.Items.MEGACYTE, new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.MEGACYTE))); asteroidMap.append(EOITConst.Items.MORPHITE, new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.MORPHITE))); asteroids.populateSet(asteroidMap.get(EOITConst.Items.TRITANIUM)); asteroids.populateSet(asteroidMap.get(EOITConst.Items.PYERITE)); asteroids.populateSet(asteroidMap.get(EOITConst.Items.MEXALLON)); asteroids.populateSet(asteroidMap.get(EOITConst.Items.ISOGEN)); asteroids.populateSet(asteroidMap.get(EOITConst.Items.NOCXIUM)); asteroids.populateSet(asteroidMap.get(EOITConst.Items.ZYDRINE)); asteroids.populateSet(asteroidMap.get(EOITConst.Items.MEGACYTE)); asteroids.populateSet(asteroidMap.get(EOITConst.Items.MORPHITE)); Log.d(LOG_TAG, "Finish reading cursor..."); } }