private Pair<Bitmap, Track> getRandomBitmap(List<Track> tracks) { Track track = null; Bitmap bitmap = null; int randomIndex = 0; if (tracks.size() > 0) { randomIndex = roulette.nextInt(tracks.size()); track = tracks.get(randomIndex); if (track != null) { try { bitmap = retrieveBitmap(new URL(track.getWaveformUrl())); } catch (MalformedURLException e) { e.printStackTrace(); } } } return new Pair<Bitmap, Track>(bitmap, track); }
private List<Track> convertJsonToTracks(String responseAsString) { List<Track> tracks = new ArrayList<Track>(); try { JSONArray tracksArray = new JSONArray(responseAsString); for (int i = 0; i < tracksArray.length(); i++) { JSONObject track = (JSONObject) tracksArray.get(i); Log.d(TAG, "Parsing JSON response: [" + track.toString() + "]"); tracks.add(Track.fromJSON(track)); } } catch (JSONException e) { Log.e(TAG, "Could not obtains tracks from response", e); } return tracks; }