use of android.widget.TableRow in project chefly_android by chef-ly.
the class DialogPopUp method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//Remove title bar from dialog
Window w = getDialog().getWindow();
if (w != null) {
w.requestFeature(Window.FEATURE_NO_TITLE);
}
if (showTitle) {
TextView title = (TextView) view.findViewById(R.id.title);
title.setText(getArguments().getString("title"));
title.setVisibility(View.VISIBLE);
}
Button exit = (Button) view.findViewById(R.id.exit);
exit.bringToFront();
exit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getDialog().dismiss();
}
});
TableLayout table = (TableLayout) view.findViewById(R.id.table);
ArrayList<String> data = getArguments().getStringArrayList("data");
Context c = getContext();
TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
int leftMargin = 30;
int topMargin = 1;
int rightMargin = 55;
int bottomMargin = 1;
tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
int color1 = getColor(c, R.color.table_color1);
int color2 = getColor(c, R.color.table_color2);
int count = 0;
if (data != null) {
for (String s : data) {
TableRow row = new TableRow(getContext());
row.setLayoutParams(tableRowParams);
row.setBackgroundColor(count % 2 == 0 ? color1 : color2);
row.setPadding(10, 5, 10, 5);
TextView text = new TextView(c);
text.setText(s);
text.setTextColor(getColor(c, R.color.black));
text.setTextSize((getResources().getDimension(R.dimen.text_small) / getResources().getDisplayMetrics().density));
text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
text.setPadding(10, 5, 10, 5);
row.addView(text);
table.addView(row);
count++;
}
} else {
TableRow row = new TableRow(getContext());
row.setLayoutParams(tableRowParams);
row.setBackgroundColor(count % 2 == 0 ? color1 : color2);
row.setPadding(10, 5, 10, 5);
TextView text = new TextView(c);
text.setText("No data available");
text.setTextColor(getColor(c, R.color.black));
text.setTextSize((getResources().getDimension(R.dimen.text_medium) / getResources().getDisplayMetrics().density));
text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
text.setPadding(10, 5, 10, 5);
row.addView(text);
table.addView(row);
}
}
use of android.widget.TableRow in project android_frameworks_base by crdroidandroid.
the class AddColumn method onCreate.
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.add_column_in_table);
final Button addRowButton = (Button) findViewById(R.id.add_row_button);
addRowButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final TableLayout table = (TableLayout) findViewById(R.id.table);
final TableRow newRow = new TableRow(AddColumn.this);
for (int i = 0; i < 4; i++) {
final TextView view = new TextView(AddColumn.this);
view.setText("Column " + (i + 1));
view.setPadding(3, 3, 3, 3);
newRow.addView(view, new TableRow.LayoutParams());
}
table.addView(newRow, new TableLayout.LayoutParams());
newRow.requestLayout();
}
});
}
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 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 android_frameworks_base by ParanoidAndroid.
the class AddColumnTest method testWidths.
@MediumTest
public void testWidths() throws Exception {
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
getInstrumentation().waitForIdleSync();
TableRow row1 = (TableRow) mTable.getChildAt(0);
TableRow row2 = (TableRow) mTable.getChildAt(1);
assertTrue(row1.getChildCount() < row2.getChildCount());
for (int i = 0; i < row1.getChildCount(); i++) {
assertEquals(row2.getChildAt(i).getWidth(), row1.getChildAt(i).getWidth());
}
}
Aggregations