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++;
}
}
}
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);
}
}
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();
}
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();
}
}
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();
}
Aggregations