Skip to content

Instantly share code, notes, and snippets.

@esaounkine
Created April 29, 2011 12:42
Show Gist options
  • Save esaounkine/948238 to your computer and use it in GitHub Desktop.
Save esaounkine/948238 to your computer and use it in GitHub Desktop.
Intent to start navigation activity - util
static final int TABLE_DIALOG = 0;
ArrayList<TableRow> rows;
String tableDialogTime;
int tableDialogTableHeaderColor;
int tableDialogTableHeaderIcon;
Dialog dialog;
/**
* Pops up a dialog to show a table.
* @param rows
*/
public void showTableDialog(ArrayList<TableRow> rows, String time, int headerColor, int headerIcon) {
this.rows = rows;
this.tableDialogTableHeaderColor = headerColor;
this.tableDialogTableHeaderIcon = headerIcon;
activityHandler.post(new Runnable() {
@Override
public void run() {
showDialog(TABLE_DIALOG);
}
});
}
public Dialog onCreateDialog(int id) {
switch(id) {
case TABLE_DIALOG:
dialog = new Dialog(this, R.style.TableDialog);
dialog.setContentView(R.layout.table_dialog);
break;
default:
dialog = null;
}
return dialog;
}
public void onPrepareDialog(int id, Dialog dialog) {
if(id == TABLE_DIALOG) {
//set icon
((ImageView) dialog.findViewById(R.id.table_dialog_icon)).setBackgroundDrawable(getResources().getDrawable(tableDialogTableHeaderIcon));
//set background for the whole header
dialog.findViewById(R.id.table_dialog_header).setBackgroundColor(tableDialogTableHeaderColor);
//set title
TextView titleField = (TextView) dialog.findViewById(R.id.table_dialog_title);
titleField.setText(title);
//set up the header for the table on a separate TableLayout (it's a separate TableLayout, so that it doesn't scroll along with the rest of the scrollable area)
TableLayout tableHeader = (TableLayout) dialog.findViewById(R.id.table_header);
tableHeader.removeAllViews();
tableHeader.addView(rows.get(0));
//set up the table
TableLayout table = (TableLayout) dialog.findViewById(R.id.table_dialog_layout);
//clean up old entries (on re-invoke)
table.removeAllViews();
//populate table rows: add rows with separator inbetween
for(int i = 1; i < rows.size(); i++) {
int colorAmount = i % 2 == 0? 230 : 200;
TableRow row = rows.get(i);
row.setBackgroundColor(Color.rgb(colorAmount, colorAmount, colorAmount));
table.addView(row);
//add a separator after each line
View separator = new View(dialog.getContext());
separator.setBackgroundColor(Color.rgb(77, 77, 77));
separator.setMinimumHeight(2);
table.addView(separator);
}
}
}
private TextView recyclableTextView;
public TextView makePoiTableRowWithText(CharSequence text, boolean bold, int widthInPercentOfScreenWidth) {
recyclableTextView = new TextView(this);
recyclableTextView.setText(text);
recyclableTextView.setTypeface(bold? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
recyclableTextView.setTextColor(Color.BLACK);
recyclableTextView.setTextSize(20);
recyclableTextView.setWidth(widthInPercentOfScreenWidth * screenWidth / 100);
recyclableTextView.setPadding(5, 5, 5, 5);
return recyclableTextView;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment