Search in sources :

Example 6 with PlayerScore

use of com.nolanlawson.keepscore.db.PlayerScore in project KeepScore by nolanlawson.

the class OrganizePlayersActivity method setDataResultAndExit.

private void setDataResultAndExit() {
    Intent data = new Intent();
    data.putParcelableArrayListExtra(EXTRA_PLAYER_SCORES, new ArrayList<PlayerScore>(adapter.getItems()));
    setResult(RESULT_OK, data);
    finish();
}
Also used : Intent(android.content.Intent) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 7 with PlayerScore

use of com.nolanlawson.keepscore.db.PlayerScore in project KeepScore by nolanlawson.

the class SerializationTest method createRandomPlayerScores.

private List<PlayerScore> createRandomPlayerScores() {
    int numPlayers = random.nextInt(8) + 2;
    List<PlayerScore> playerScores = new ArrayList<PlayerScore>();
    for (int i = 0; i < numPlayers; i++) {
        PlayerScore playerScore = new PlayerScore();
        int score = random.nextInt(100) + 30;
        playerScore.setScore(score);
        playerScore.setHistory(createRandomHistory(score));
        playerScore.setName(Long.toString(random.nextLong(), 16));
        playerScore.setPlayerNumber(i);
        playerScore.setPlayerColor(PlayerColor.BUILT_INS[random.nextInt(PlayerColor.BUILT_INS.length)]);
        playerScores.add(playerScore);
    }
    return playerScores;
}
Also used : ArrayList(java.util.ArrayList) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 8 with PlayerScore

use of com.nolanlawson.keepscore.db.PlayerScore in project KeepScore by nolanlawson.

the class GamesBackupSerializer method serializeAsRawXml.

private static String serializeAsRawXml(GamesBackup gamesBackup) {
    XmlSerializer serializer = Xml.newSerializer();
    StringWriter writer = new StringWriter();
    try {
        serializer.setOutput(writer);
        serializer.startDocument("UTF-8", true);
        serializer.startTag("", Tag.GamesBackup.name());
        addTag(serializer, Tag.gameCount, gamesBackup.getGameCount());
        addTag(serializer, Tag.version, gamesBackup.getVersion());
        addTag(serializer, Tag.automatic, gamesBackup.isAutomatic());
        addTag(serializer, Tag.backupFilename, gamesBackup.getFilename());
        addTag(serializer, Tag.dateBackupSaved, gamesBackup.getDateSaved());
        serializer.startTag("", Tag.Games.name());
        for (Game game : gamesBackup.getGames()) {
            serializer.startTag("", Tag.Game.name());
            addTag(serializer, Tag.dateGameSaved, game.getDateSaved());
            addTag(serializer, Tag.dateGameStarted, game.getDateStarted());
            addTag(serializer, Tag.gameName, game.getName());
            serializer.startTag("", Tag.PlayerScores.name());
            for (PlayerScore playerScore : game.getPlayerScores()) {
                serializer.startTag("", Tag.PlayerScore.name());
                addTag(serializer, Tag.playerName, playerScore.getName());
                addTag(serializer, Tag.score, playerScore.getScore());
                addTag(serializer, Tag.playerNumber, playerScore.getPlayerNumber());
                Pair<String, String> historyAsStrings = Delta.toJoinedStrings(playerScore.getHistory());
                addTag(serializer, Tag.history, historyAsStrings.getFirst());
                addTag(serializer, Tag.historyTimestamps, historyAsStrings.getSecond());
                addTag(serializer, Tag.lastUpdate, Long.toString(playerScore.getLastUpdate()));
                addTag(serializer, Tag.color, PlayerColor.serialize(playerScore.getPlayerColor()));
                serializer.endTag("", Tag.PlayerScore.name());
            }
            serializer.endTag("", Tag.PlayerScores.name());
            serializer.endTag("", Tag.Game.name());
        }
        serializer.endTag("", Tag.Games.name());
        serializer.endTag("", Tag.GamesBackup.name());
        serializer.endDocument();
        return writer.toString();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Game(com.nolanlawson.keepscore.db.Game) StringWriter(java.io.StringWriter) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) XmlSerializer(org.xmlpull.v1.XmlSerializer) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 9 with PlayerScore

use of com.nolanlawson.keepscore.db.PlayerScore in project KeepScore by nolanlawson.

the class HistoryPlayerTableFragment method createByPlayerTableLayout.

private void createByPlayerTableLayout(Activity activity) {
    // 'by player' table is a simple 2-column table with a vertical divider
    int counter = 0;
    List<PlayerScore> playerScores = game.getPlayerScores();
    for (int i = 0; i < playerScores.size(); i += 2) {
        PlayerScore leftPlayer = playerScores.get(i);
        PlayerScore rightPlayer = i + 1 < playerScores.size() ? playerScores.get(i + 1) : null;
        // create the header
        TableRow headerRow = new TableRow(activity);
        headerRow.addView(createListHeader(headerRow, leftPlayer.toDisplayName(activity), true, false));
        headerRow.addView(createDividerView(headerRow));
        headerRow.addView(createListHeader(headerRow, rightPlayer == null ? " " : rightPlayer.toDisplayName(activity), true, false));
        byPlayerTableLayout.addView(headerRow);
        // create the body
        Iterator<HistoryItem> leftHistoryItems = HistoryItem.createFromPlayerScore(leftPlayer, activity).iterator();
        Iterator<HistoryItem> rightHistoryItems = rightPlayer == null ? Collections.<HistoryItem>emptyList().iterator() : HistoryItem.createFromPlayerScore(rightPlayer, activity).iterator();
        while (leftHistoryItems.hasNext() || rightHistoryItems.hasNext()) {
            HistoryItem leftItem = leftHistoryItems.hasNext() ? leftHistoryItems.next() : null;
            HistoryItem rightItem = rightHistoryItems.hasNext() ? rightHistoryItems.next() : null;
            TableRow tableRow = new TableRow(activity);
            tableRow.addView(createHistoryItemView(tableRow, leftItem, R.layout.history_item_wide, counter, true, activity));
            tableRow.addView(createDividerView(tableRow));
            tableRow.addView(createHistoryItemView(tableRow, rightItem, R.layout.history_item_wide, counter, true, activity));
            byPlayerTableLayout.addView(tableRow);
            counter++;
        }
    }
}
Also used : TableRow(android.widget.TableRow) HistoryItem(com.nolanlawson.keepscore.data.HistoryItem) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 10 with PlayerScore

use of com.nolanlawson.keepscore.db.PlayerScore in project KeepScore by nolanlawson.

the class HistoryRoundTableFragment method createByRoundTableLayout.

private void createByRoundTableLayout(Activity activity) {
    // i.e. not the "divider" or "row header" columns
    for (int i = 0; i < game.getPlayerScores().size(); i++) {
        byRoundTableLayout.setColumnShrinkable((i * 2) + 2, true);
        byRoundTableLayout.setColumnStretchable((i * 2) + 2, true);
    }
    // the 'by round' adapter simply needs each player name as a first
    // header row, and then after that you just go round-by-round
    // summing up the values and displaying the diff, e.g.:
    // p1, p2, p3, p4
    // 0, 0, 0, 0
    // +5, +3, -2, +10
    // 5, 3, 2, 10
    // etc.
    List<PlayerScore> playerScores = game.getPlayerScores();
    int historyItemLayoutId = playerScores.size() <= MAX_COLUMNS_FOR_WIDE_LIST_LAYOUT ? R.layout.history_item_wide : playerScores.size() <= MAX_COLUMNS_FOR_REGULAR_TALL_LIST_LAYOUT ? R.layout.history_item_tall : R.layout.history_item_extra_tall;
    // create the first row
    TableRow headerRow = new TableRow(activity);
    headerRow.addView(createListHeader(headerRow, " ", false, false));
    for (PlayerScore playerScore : playerScores) {
        headerRow.addView(createDividerView(headerRow));
        headerRow.addView(createListHeader(headerRow, playerScore.toDisplayName(activity), true, false));
    }
    // add a column to the right with an epsilon sign (for the round total
    // sum)
    headerRow.addView(createDividerView(headerRow));
    headerRow.addView(createListHeader(headerRow, getString(R.string.CONSTANT_text_epsilon), false, true));
    byRoundTableLayout.addView(headerRow);
    List<HistoryItem> collatedHistoryItems = getCollatedHistoryItems(activity);
    for (int i = 0; i < collatedHistoryItems.size(); i += playerScores.size()) {
        int rowId = (i / playerScores.size());
        TableRow tableRow = new TableRow(activity);
        // add a column for the round number
        // first
        String roundName = (i == 0) ? "" : Integer.toString(rowId);
        // row is  just
        // the starting score
        tableRow.addView(createRowHeader(tableRow, roundName));
        // add in all the history items from this round
        int sum = 0;
        for (int j = i; j < i + playerScores.size(); j++) {
            HistoryItem historyItem = collatedHistoryItems.get(j);
            View historyItemAsView = createHistoryItemView(tableRow, historyItem, historyItemLayoutId, rowId, true, activity);
            tableRow.addView(createDividerView(tableRow));
            tableRow.addView(historyItemAsView);
            sum += historyItem == null ? 0 : historyItem.getDelta();
        }
        // add in the round total (sum)
        tableRow.addView(createDividerView(tableRow));
        if (i == 0) {
            // first row is just the starting score
            HistoryItem bogusHistoryItem = new HistoryItem(0, sum, true);
            tableRow.addView(createHistoryItemView(tableRow, bogusHistoryItem, historyItemLayoutId, rowId, false, activity));
        } else {
            tableRow.addView(createSumView(tableRow, historyItemLayoutId, rowId, sum));
        }
        byRoundTableLayout.addView(tableRow);
    }
}
Also used : TableRow(android.widget.TableRow) HistoryItem(com.nolanlawson.keepscore.data.HistoryItem) TextView(android.widget.TextView) View(android.view.View) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Aggregations

PlayerScore (com.nolanlawson.keepscore.db.PlayerScore)19 Delta (com.nolanlawson.keepscore.db.Delta)5 Game (com.nolanlawson.keepscore.db.Game)5 ArrayList (java.util.ArrayList)5 View (android.view.View)3 TextView (android.widget.TextView)3 HistoryItem (com.nolanlawson.keepscore.data.HistoryItem)3 IOException (java.io.IOException)3 SparseArray (android.util.SparseArray)2 ImageView (android.widget.ImageView)2 TableRow (android.widget.TableRow)2 PlayerView (com.nolanlawson.keepscore.widget.PlayerView)2 LineChartLine (com.nolanlawson.keepscore.widget.chart.LineChartLine)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 Intent (android.content.Intent)1 LayoutInflater (android.view.LayoutInflater)1 OnClickListener (android.view.View.OnClickListener)1 ImageButton (android.widget.ImageButton)1 EditablePlayerAdapter (com.nolanlawson.keepscore.data.EditablePlayerAdapter)1 RecordedChange (com.nolanlawson.keepscore.data.RecordedChange)1