Search in sources :

Example 71 with TableRow

use of android.widget.TableRow 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 72 with TableRow

use of android.widget.TableRow 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)

Example 73 with TableRow

use of android.widget.TableRow in project drmips by brunonova.

the class DrMIPSActivity method refreshAssembledCodeTable.

/**
 * Refreshes the contents of the code table.
 */
private void refreshAssembledCodeTable() {
    while (// remove all rows except header
    tblAssembledCode.getChildCount() > 1) tblAssembledCode.removeViewAt(1);
    AssembledInstruction instruction;
    TableRow row;
    TextView address, assembled, code;
    String codeLine;
    CPU cpu = getCPU();
    for (int i = 0; i < cpu.getInstructionMemory().getNumberOfInstructions(); i++) {
        instruction = cpu.getInstructionMemory().getInstruction(i);
        row = new TableRow(this);
        row.setOnClickListener(assembledCodeRowOnClickListener);
        address = new TextView(this);
        address.setText(Util.formatDataAccordingToFormat(new Data(Data.DATA_SIZE, i * (Data.DATA_SIZE / 8)), cmbAssembledCodeFormat.getSelectedItemPosition()) + " ");
        address.setTextAppearance(this, android.R.style.TextAppearance_Medium);
        address.setTypeface(Typeface.MONOSPACE);
        assembled = new TextView(this);
        assembled.setText(Util.formatDataAccordingToFormat(new Data(Data.DATA_SIZE, instruction.getData().getValue()), cmbAssembledCodeFormat.getSelectedItemPosition()) + " ");
        assembled.setTextAppearance(this, android.R.style.TextAppearance_Medium);
        assembled.setTypeface(Typeface.MONOSPACE);
        code = new TextView(this);
        codeLine = instruction.getLineNumber() + ": ";
        for (String label : instruction.getLabels()) codeLine += label + ": ";
        codeLine += instruction.getCodeLine();
        code.setText(codeLine);
        code.setTextAppearance(this, android.R.style.TextAppearance_Medium);
        code.setTypeface(Typeface.MONOSPACE);
        row.addView(address);
        row.addView(assembled);
        row.addView(code);
        tblAssembledCode.addView(row);
    }
    refreshAssembledCodeTableValues();
}
Also used : TableRow(android.widget.TableRow) CPU(brunonova.drmips.simulator.CPU) TextView(android.widget.TextView) Data(brunonova.drmips.simulator.Data) AssembledInstruction(brunonova.drmips.simulator.AssembledInstruction)

Example 74 with TableRow

use of android.widget.TableRow in project drmips by brunonova.

the class DrMIPSActivity method refreshDataMemoryTable.

/**
 * Refreshes both the rows and values of the data memory table.
 */
private void refreshDataMemoryTable() {
    while (// remove all rows except header
    tblDataMemory.getChildCount() > 1) tblDataMemory.removeViewAt(1);
    CPU cpu = getCPU();
    if (cpu.hasDataMemory()) {
        TableRow row;
        TextView address, value;
        for (int i = 0; i < cpu.getDataMemory().getMemorySize(); i++) {
            row = new TableRow(this);
            row.setOnLongClickListener(dataMemoryRowOnLongClickListener);
            address = new TextView(this);
            address.setTextAppearance(this, android.R.style.TextAppearance_Medium);
            address.setTypeface(Typeface.MONOSPACE);
            value = new TextView(this);
            value.setTextAppearance(this, android.R.style.TextAppearance_Medium);
            value.setTypeface(Typeface.MONOSPACE);
            value.setGravity(Gravity.RIGHT);
            row.addView(address);
            row.addView(value);
            tblDataMemory.addView(row);
        }
        // refresh values
        refreshDataMemoryTableValues();
    }
}
Also used : TableRow(android.widget.TableRow) CPU(brunonova.drmips.simulator.CPU) TextView(android.widget.TextView)

Example 75 with TableRow

use of android.widget.TableRow in project drmips by brunonova.

the class DrMIPSActivity method refreshAssembledCodeTableValues.

/**
 * Refreshes the assembled code table highlights.
 */
private void refreshAssembledCodeTableValues() {
    TableRow row;
    CPU cpu = getCPU();
    for (int i = 0; i < cpu.getInstructionMemory().getNumberOfInstructions(); i++) {
        row = (TableRow) tblAssembledCode.getChildAt(i + 1);
        // Highlight instructions being executed
        if (i == cpu.getPC().getCurrentInstructionIndex())
            row.setBackgroundColor(Util.getThemeColor(this, getCPU().isPipeline() ? R.attr.ifColor : R.attr.instColor));
        else if (cpu.isPipeline()) {
            if (i == cpu.getIfIdReg().getCurrentInstructionIndex())
                row.setBackgroundColor(Util.getThemeColor(this, R.attr.idColor));
            else if (i == cpu.getIdExReg().getCurrentInstructionIndex())
                row.setBackgroundColor(Util.getThemeColor(this, R.attr.exColor));
            else if (i == cpu.getExMemReg().getCurrentInstructionIndex())
                row.setBackgroundColor(Util.getThemeColor(this, R.attr.memColor));
            else if (i == cpu.getMemWbReg().getCurrentInstructionIndex())
                row.setBackgroundColor(Util.getThemeColor(this, R.attr.wbColor));
            else
                // remove background color
                row.setBackgroundResource(0);
        } else
            // remove background color
            row.setBackgroundResource(0);
    }
    tblAssembledCode.requestLayout();
}
Also used : TableRow(android.widget.TableRow) CPU(brunonova.drmips.simulator.CPU)

Aggregations

TableRow (android.widget.TableRow)77 TextView (android.widget.TextView)53 TableLayout (android.widget.TableLayout)37 View (android.view.View)30 Button (android.widget.Button)11 ImageView (android.widget.ImageView)10 SuppressLint (android.annotation.SuppressLint)7 ScrollView (android.widget.ScrollView)7 CPU (brunonova.drmips.simulator.CPU)7 MediumTest (android.test.suitebuilder.annotation.MediumTest)6 CheckBox (android.widget.CheckBox)6 ViewGroup (android.view.ViewGroup)5 CompoundButton (android.widget.CompoundButton)5 ImageButton (android.widget.ImageButton)5 LinearLayout (android.widget.LinearLayout)5 ListView (android.widget.ListView)5 LayoutParams (android.widget.TableLayout.LayoutParams)5 SpannableStringBuilder (android.text.SpannableStringBuilder)4 ArrayList (java.util.ArrayList)4 Context (android.content.Context)3