public ArrayList<Opponent> getStoredOpponents() { ArrayList<Opponent> opponents = new ArrayList<Opponent>(); String json = mPrefs.getString(OPPONENTS, OPPONENTS_EMPTY); Log.d(TAG, "Got Opponent Json: " + json); try { JSONArray idsArray = new JSONArray(json); for (int i = 0, l = idsArray.length(); i < l; i++) { JSONObject jo = idsArray.getJSONObject(i); Player p = mDB.getPlayerByPin(jo.getInt(JSON_OPPONENT_PIN)); if (p != null) { Opponent op = new Opponent( p, (float) jo.getDouble(JSON_OPPONENT_WIN), jo.getInt(JSON_OPPONENT_COLOR), jo.getInt(JSON_OPPONENT_HANDICAP)); opponents.add(op); } } } catch (JSONException e) { Log.e(TAG, "Error parsing opponents: " + e.getLocalizedMessage()); e.printStackTrace(); } return opponents; }
public Player getStoredPlayer() { return mDB.getPlayerByPin(mPrefs.getInt(PLAYER, 0)); }