Example #1
0
 @SuppressWarnings("unchecked")
 public void addData(int value, String name) {
   Data data = new Data();
   data.value = value;
   data.name = name;
   this.data.add(data);
 }
  @Override
  public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
    if (cursor != null) {
      ContentResolver contentResolver = getContentResolver();
      mData = new ArrayList<Data>(cursor.getCount());

      if (cursor.moveToFirst()) {
        while (!cursor.isAfterLast()) {
          Data item = new Data();

          item.id = cursor.getLong(cursor.getColumnIndex(DataContract.Players._ID));
          item.name = cursor.getString(cursor.getColumnIndex(DataContract.Players.NAME));

          Cursor c =
              contentResolver.query(
                  Uri.withAppendedPath(DataContract.Players.CONTENT_URI, item.id + "/stats"),
                  new String[] {
                    "COUNT(*) AS " + COLUMN_GAMES_PLAYED,
                    "SUM(" + DataContract.Stats.GOALS_FOR + ") AS " + COLUMN_GOALS_FOR,
                    "SUM(" + DataContract.Stats.GOALS_AGAINST + ") AS " + COLUMN_GOALS_AGAINST,
                    "SUM(" + DataContract.Stats.SCORE + ") AS " + COLUMN_WINS
                  },
                  null,
                  null,
                  null);

          if (c.moveToFirst()) {
            item.gamesPlayed = c.getInt(c.getColumnIndex(COLUMN_GAMES_PLAYED));
            item.goalsFor = c.getInt(c.getColumnIndex(COLUMN_GOALS_FOR));
            item.goalsAgainst = c.getInt(c.getColumnIndex(COLUMN_GOALS_AGAINST));
            item.wins = c.getInt(c.getColumnIndex(COLUMN_WINS));
            item.losses = item.gamesPlayed - item.wins;
            c.close();
          }

          c =
              contentResolver.query(
                  Uri.withAppendedPath(DataContract.Players.CONTENT_URI, item.id + "/rating"),
                  new String[] {DataContract.Ratings.RATING},
                  null,
                  null,
                  null);

          if (c.moveToFirst()) {
            item.rating = c.getInt(c.getColumnIndex(DataContract.Ratings.RATING));
            c.close();
          }

          mData.add(item);
          cursor.moveToNext();
        }
      }

      updateListView();
    }
  }
Example #3
0
  @Override
  public void prettyOut() {
    StringBuilder st = new StringBuilder(String.format("Sudoku -- %s\n", data.name()));
    st.append("\t");
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        st.append(rows[i][j].getValue()).append(" ");
      }
      st.append("\n\t");
    }

    System.out.println(st.toString());
  }