Search in sources :

Example 16 with PlayerScore

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

the class OrganizePlayersActivity method setUpWidgets.

private void setUpWidgets() {
    okButton = (Button) findViewById(R.id.button_ok);
    okButton.setOnClickListener(this);
    cancelButton = (Button) findViewById(R.id.button_cancel);
    cancelButton.setOnClickListener(this);
    adapter = new EditablePlayerAdapter(this, game.getPlayerScores());
    setListAdapter(adapter);
    adapter.setOnChangeListener(new Runnable() {

        @Override
        public void run() {
            // update the Add Player button if necessary
            supportInvalidateOptionsMenu();
        }
    });
    adapter.setOnDeleteListener(new Callback<PlayerScore>() {

        @Override
        public void onCallback(PlayerScore playerScore) {
            // i.e. there's something the user might regret deleting
            if (playerScore.getHistory() != null && playerScore.getHistory().size() > 0) {
                deletedPlayersToWarnAbout.add(playerScore.toDisplayName(OrganizePlayersActivity.this).toString());
            }
        }
    });
    ((DragSortListView) getListView()).setDropListener(adapter);
}
Also used : EditablePlayerAdapter(com.nolanlawson.keepscore.data.EditablePlayerAdapter) DragSortListView(com.nolanlawson.keepscore.widget.dragndrop.DragSortListView) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 17 with PlayerScore

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

the class OrganizePlayersActivity method addNewPlayer.

private void addNewPlayer(CharSequence name) {
    PlayerScore playerScore = new PlayerScore();
    playerScore.setId(-1);
    playerScore.setName(StringUtil.nullToEmpty(name));
    playerScore.setPlayerNumber(adapter.getCount());
    playerScore.setScore(PreferenceHelper.getIntPreference(R.string.CONSTANT_pref_initial_score, R.string.CONSTANT_pref_initial_score_default, this));
    playerScore.setHistory(new ArrayList<Delta>());
    playerScore.setPlayerColor(PlayerColor.BUILT_INS[playerScore.getPlayerNumber() % PlayerColor.BUILT_INS.length]);
    adapter.add(playerScore);
    adapter.notifyDataSetChanged();
}
Also used : Delta(com.nolanlawson.keepscore.db.Delta) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 18 with PlayerScore

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

the class HistoryTimelineFragment method createTimelineLayout.

private void createTimelineLayout(Activity activity) {
    List<String> xAxisLabels = new ArrayList<String>();
    SparseArray<SparseArray<Long>> smoothedData = smoothData(game);
    List<LineChartLine> data = new ArrayList<LineChartLine>();
    for (PlayerScore playerScore : game.getPlayerScores()) {
        data.add(new LineChartLine(playerScore.toDisplayName(activity).toString(), new ArrayList<Integer>()));
    }
    long[] lastPlayerScores = new long[game.getPlayerScores().size()];
    for (int i = 0; i < smoothedData.size(); i++) {
        int timeSinceStart = smoothedData.keyAt(i);
        xAxisLabels.add(TimeUtil.formatSeconds(timeSinceStart));
        SparseArray<Long> scores = smoothedData.get(timeSinceStart);
        for (int playerIdx = 0; playerIdx < game.getPlayerScores().size(); playerIdx++) {
            Long scoreObj = scores.get(playerIdx);
            // just give the player a zero-delta (i.e. previous score) for this "round" if no changes
            long score = scoreObj == null ? lastPlayerScores[playerIdx] : scoreObj;
            List<Integer> dataPoints = data.get(playerIdx).getDataPoints();
            dataPoints.add((int) score);
            lastPlayerScores[playerIdx] = score;
        }
    }
    timelineChartView.setLineColors(createLineColors(game, activity));
    timelineChartView.setxAxisLabels(xAxisLabels);
    log.d("x labels are %s", xAxisLabels);
    timelineChartView.loadData(data);
}
Also used : ArrayList(java.util.ArrayList) LineChartLine(com.nolanlawson.keepscore.widget.chart.LineChartLine) SparseArray(android.util.SparseArray) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 19 with PlayerScore

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

the class GamesBackupSerializer method deserialize.

@SuppressWarnings("incomplete-switch")
public static GamesBackup deserialize(String xmlData) {
    int parserEvent = -1;
    XmlPullParser parser = null;
    Tag tag = null;
    GamesBackup gamesBackup = new GamesBackup();
    gamesBackup.setGames(new ArrayList<Game>());
    Game game = null;
    PlayerScore playerScore = null;
    Map<String, String> attributes = null;
    try {
        // calls service (referenced in url) to request XML serialized data
        parser = XmlHelper.loadData(xmlData);
        parserEvent = parser.getEventType();
        while (parserEvent != XmlPullParser.END_DOCUMENT) {
            switch(parserEvent) {
                case XmlPullParser.START_TAG:
                    tag = Tag.valueOf(parser.getName());
                    switch(tag) {
                        case Game:
                            game = new Game();
                            game.setPlayerScores(new ArrayList<PlayerScore>());
                            break;
                        case PlayerScore:
                            playerScore = new PlayerScore();
                            break;
                    }
                    // null or empty marker
                    if (parser.getAttributeCount() != -1) {
                        attributes = getAttributes(parser);
                    }
                    break;
                case XmlPullParser.END_TAG:
                    tag = Tag.valueOf(parser.getName());
                    switch(tag) {
                        case Game:
                            gamesBackup.getGames().add(game);
                            break;
                        case PlayerScore:
                            game.getPlayerScores().add(playerScore);
                            break;
                    }
                    break;
                case XmlPullParser.TEXT:
                    String text = parser.getText();
                    if (!StringUtil.isEmptyOrWhitespace(text)) {
                        handleText(text, tag, attributes, gamesBackup, game, playerScore);
                    }
                    break;
            }
            parserEvent = parser.next();
        }
    } catch (XmlPullParserException e) {
        log.e(e, "unexpected");
    } catch (IOException e) {
        log.e(e, "unexpected");
    }
    applyVersionFixes(gamesBackup);
    // return de-serialized game backup
    return gamesBackup;
}
Also used : Game(com.nolanlawson.keepscore.db.Game) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) 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