List of usage examples for android.widget TableRow setPadding
public void setPadding(int left, int top, int right, int bottom)
From source file:pro.dbro.bart.TheActivity.java
public void displayRouteResponse(routeResponse routeResponse) { // Log.d("displayRouteResponse","Is this real?: "+routeResponse.toString()); // Previously, if the device's locale wasn't in Pacific Standard Time // Responses with all expired routes could present, causing a looping refresh cycle // This is now remedied by coercing response dates into PST boolean expiredResponse = false; if (routeResponse.routes.size() == 0) { Log.d("displayRouteResponse", "no routes to display"); expiredResponse = true;/*from w w w.ja v a 2 s .c om*/ } if (timer != null) timer.cancel(); // cancel previous timer timerViews = new ArrayList(); // release old ETA text views maxTimer = 0; try { tableLayout.removeAllViews(); //Log.v("DATE",new Date().toString()); long now = new Date().getTime(); if (!expiredResponse) { fareTv.setVisibility(0); fareTv.setText("$" + routeResponse.routes.get(0).fare); for (int x = 0; x < routeResponse.routes.size(); x++) { route thisRoute = routeResponse.routes.get(x); TableRow tr = (TableRow) View.inflate(c, R.layout.tablerow, null); tr.setPadding(0, 20, 0, 0); LinearLayout legLayout = (LinearLayout) View.inflate(c, R.layout.routelinearlayout, null); for (int y = 0; y < thisRoute.legs.size(); y++) { TextView trainTv = (TextView) View.inflate(c, R.layout.tabletext, null); trainTv.setPadding(0, 0, 0, 0); trainTv.setTextSize(20); trainTv.setGravity(3); // set left gravity // If route has multiple legs, generate "Transfer At [station name]" and "To [train name] " rows for each leg after the first if (y > 0) { trainTv.setText("transfer at " + BART.REVERSE_STATION_MAP .get(((leg) thisRoute.legs.get(y - 1)).disembarkStation.toLowerCase())); trainTv.setPadding(0, 0, 0, 0); legLayout.addView(trainTv); trainTv.setTextSize(14); trainTv = (TextView) View.inflate(c, R.layout.tabletext, null); trainTv.setPadding(0, 0, 0, 0); trainTv.setTextSize(20); trainTv.setGravity(3); // set left gravity trainTv.setText("to " + BART.REVERSE_STATION_MAP .get(((leg) thisRoute.legs.get(y)).trainHeadStation.toLowerCase())); } else { // For first route leg, display "Take [train name]" row trainTv.setText("take " + BART.REVERSE_STATION_MAP.get(((leg) thisRoute.legs.get(y)).trainHeadStation)); } legLayout.addView(trainTv); } if (thisRoute.legs.size() == 1) { legLayout.setPadding(0, 10, 0, 0); // Address detination train and ETA not aligning } tr.addView(legLayout); // Prepare ETA TextView TextView arrivalTimeTv = (TextView) View.inflate(c, R.layout.tabletext, null); arrivalTimeTv.setPadding(10, 0, 0, 0); //Log.v("DEPART_DATE",thisRoute.departureDate.toString()); // Don't report a train that may JUST be leaving with a negative ETA long eta; if (thisRoute.departureDate.getTime() - now <= 0) { eta = 0; } else { eta = thisRoute.departureDate.getTime() - now; } if (eta > maxTimer) { maxTimer = eta; } // Set timeTv Tag to departure date for interpretation by ViewCountDownTimer arrivalTimeTv.setTag(thisRoute.departureDate.getTime()); // Print arrival as time, not eta if greater than BART.ETA_THRESHOLD_MS if (thisRoute.departureDate.getTime() - now > BART.ETA_IN_MINUTES_THRESHOLD_MS) { SimpleDateFormat sdf = new SimpleDateFormat("h:mm a"); arrivalTimeTv.setText(sdf.format(thisRoute.departureDate)); arrivalTimeTv.setTextSize(20); } // Display ETA as minutes until arrival else { arrivalTimeTv.setTextSize(36); // Display eta less than 1m as "<1" if (eta < 60 * 1000) arrivalTimeTv.setText("<1"); // TODO - remove this? Does countdown tick on start else arrivalTimeTv.setText(String.valueOf(eta / (1000 * 60))); // TODO - remove this? Does countdown tick on start // Add the timerView to the list of views to be passed to the ViewCountDownTimer timerViews.add(arrivalTimeTv); } //new ViewCountDownTimer(arrivalTimeTv, eta, 60*1000).start(); tr.addView(arrivalTimeTv); // Set the Row View (containing train names and times) Tag to the route it represents tr.setTag(thisRoute); tableLayout.addView(tr); tr.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { Log.d("RouteViewTag", ((route) arg0.getTag()).toString()); usherRoute = (route) arg0.getTag(); TextView guidanceTv = (TextView) View.inflate(c, R.layout.tabletext, null); guidanceTv.setText(Html.fromHtml(getString(R.string.service_prompt))); guidanceTv.setTextSize(18); guidanceTv.setPadding(0, 0, 0, 0); new AlertDialog.Builder(c).setTitle("Route Guidance").setIcon(R.drawable.ic_launcher) .setView(guidanceTv).setPositiveButton(R.string.service_start_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent i = new Intent(c, UsherService.class); //i.putExtra("departure", ((leg)usherRoute.legs.get(0)).boardStation); //Log.v("SERVICE","Starting"); if (usherServiceIsRunning()) { stopService(i); } startService(i); } }) .setNeutralButton("Cancel", null).show(); return true; // consumed the long click } }); tr.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { int index = tableLayout.indexOfChild(arg0); // index of clicked view. Expanded view will always be +1 route thisRoute = (route) arg0.getTag(); if (!thisRoute.isExpanded) { // if route not expanded thisRoute.isExpanded = true; LinearLayout routeDetail = (LinearLayout) View.inflate(c, R.layout.routedetail, null); TextView arrivalTv = (TextView) View.inflate(c, R.layout.tabletext, null); SimpleDateFormat curFormater = new SimpleDateFormat("h:mm a"); //arrivalTv.setTextColor(0xFFC9C7C8); arrivalTv.setText("arrives " + curFormater.format(thisRoute.arrivalDate)); arrivalTv.setTextSize(20); routeDetail.addView(arrivalTv); ImageView bikeIv = (ImageView) View.inflate(c, R.layout.bikeimage, null); if (!thisRoute.bikes) { bikeIv.setImageResource(R.drawable.no_bicycle); } routeDetail.addView(bikeIv); tableLayout.addView(routeDetail, index + 1); } else { thisRoute.isExpanded = false; tableLayout.removeViewAt(index + 1); } } }); } // end route iteration } // end expiredResponse check // expiredResponse == True // If a late-night routeResponse includes the next morning's routes, they will be // presented with HH:MM ETAs, instead of minutes // Else if a late-night routeResponse includes routes from earlier in the evening // We will display "This route has stopped for tonight" else { String message = "This route has stopped for tonight"; TextView specialScheduleTextView = (TextView) View.inflate(c, R.layout.tabletext, null); specialScheduleTextView.setText(message); specialScheduleTextView.setPadding(0, 0, 0, 0); tableLayout.addView(specialScheduleTextView); } if (routeResponse.specialSchedule != null) { ImageView specialSchedule = (ImageView) View.inflate(c, R.layout.specialschedulelayout, null); specialSchedule.setTag(routeResponse.specialSchedule); specialSchedule.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { TextView specialScheduleTv = (TextView) View.inflate(c, R.layout.tabletext, null); specialScheduleTv.setPadding(0, 0, 0, 0); specialScheduleTv.setText(Html.fromHtml(arg0.getTag().toString())); specialScheduleTv.setTextSize(16); specialScheduleTv.setMovementMethod(LinkMovementMethod.getInstance()); new AlertDialog.Builder(c).setTitle("Route Alerts").setIcon(R.drawable.warning) .setView(specialScheduleTv).setPositiveButton("Okay!", null).show(); } }); tableLayout.addView(specialSchedule); } // Don't set timer if response is expired if (!expiredResponse) { timer = new ViewCountDownTimer(timerViews, "route", maxTimer, 30 * 1000); timer.start(); } } catch (Throwable t) { Log.d("displayRouteResponseError", t.getStackTrace().toString()); } }
From source file:pro.dbro.bart.TheActivity.java
public void displayEtdResponse(etdResponse etdResponse) { if (timer != null) timer.cancel(); // cancel previous timer long now = new Date().getTime(); timerViews = new ArrayList(); // release old ETA text views maxTimer = 0; // reset maxTimer fareTv.setText(""); fareTv.setVisibility(View.GONE); tableLayout.removeAllViews();//from w w w. ja v a 2 s . c om String lastDestination = ""; // Display the alert ImageView and create a click listener to display alert html if (etdResponse.message != null) { // If the response message matches the response for a closed station, // Display "Closed for tonight" and time of next train, if available. if (etdResponse.message.contains("No data matched your criteria.")) { String message = "This station is closed for tonight"; TextView specialScheduleTextView = (TextView) View.inflate(c, R.layout.tabletext, null); specialScheduleTextView.setPadding(0, 0, 0, 0); if (etdResponse.etds != null && etdResponse.etds.size() > 0) { Date nextTrain = new Date(etdResponse.date.getTime() + ((etd) etdResponse.etds.get(0)).minutesToArrival * 60 * 1000); SimpleDateFormat sdf = new SimpleDateFormat("KK:MM a"); message += ". Next train at " + sdf.format(nextTrain); } specialScheduleTextView.setText(message); tableLayout.addView(specialScheduleTextView); } else { // Create an imageview that spawns an alertDialog with BART message ImageView specialScheduleImageView = (ImageView) View.inflate(c, R.layout.specialschedulelayout, null); // Tag the specialScheduleImageView with the message html specialScheduleImageView.setTag(Html.fromHtml(etdResponse.message)); // Set the OnClickListener for the specialScheduleImageView to display the tagged message html specialScheduleImageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { TextView specialScheduleTv = (TextView) View.inflate(c, R.layout.tabletext, null); specialScheduleTv.setPadding(0, 0, 0, 0); specialScheduleTv.setText(Html.fromHtml(arg0.getTag().toString())); specialScheduleTv.setTextSize(16); specialScheduleTv.setMovementMethod(LinkMovementMethod.getInstance()); new AlertDialog.Builder(c).setTitle("Station Alerts").setIcon(R.drawable.warning) .setView(specialScheduleTv).setPositiveButton("Bummer", null).show(); } }); tableLayout.addView(specialScheduleImageView); } } TableRow tr = (TableRow) View.inflate(c, R.layout.tablerow_right, null); LinearLayout destinationRow = (LinearLayout) View.inflate(c, R.layout.destination_row, null); //TextView timeTv =(TextView) View.inflate(c, R.layout.tabletext, null); int numAlt = 0; for (int x = 0; x < etdResponse.etds.size(); x++) { if (etdResponse.etds.get(x) == null) break; etd thisEtd = (etd) etdResponse.etds.get(x); if (thisEtd.destination != lastDestination) { // new train destination numAlt = 0; tr = (TableRow) View.inflate(c, R.layout.tablerow_right, null); tr.setPadding(0, 0, 10, 0); destinationRow = (LinearLayout) View.inflate(c, R.layout.destination_row, null); TextView destinationTv = (TextView) View.inflate(c, R.layout.destinationlayout, null); if (x == 0) destinationTv.setPadding(0, 0, 0, 0); //bullet.setWidth(200); //destinationTv.setPadding(0, 0, 0, 0); destinationTv.setTextSize(28); destinationTv.setText(thisEtd.destination); TextView timeTv = (TextView) View.inflate(c, R.layout.tabletext, null); // Display eta less than 1m as "<1" if (thisEtd.minutesToArrival == 0) timeTv.setText("<1"); else timeTv.setText(String.valueOf(thisEtd.minutesToArrival)); timeTv.setSingleLine(false); timeTv.setTextSize(36); //timeTv.setPadding(30, 0, 0, 0); long counterTime = thisEtd.minutesToArrival * 60 * 1000; if (counterTime > maxTimer) { maxTimer = counterTime; } timeTv.setTag(counterTime + now); timerViews.add(timeTv); //new ViewCountDownTimer(timeTv, counterTime, 60*1000).start(); //text.setWidth(120); destinationRow.addView(destinationTv); //tr.addView(destinationTv); tr.addView(timeTv); tr.setTag(thisEtd); tableLayout.addView(destinationRow); tableLayout.addView(tr); tr.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { int index = tableLayout.indexOfChild(arg0); // index of clicked view. Expanded view will always be +1 etd thisEtd = (etd) arg0.getTag(); if (!thisEtd.isExpanded) { // if route not expanded thisEtd.isExpanded = true; LinearLayout routeDetail = (LinearLayout) View.inflate(c, R.layout.routedetail, null); TextView platformTv = (TextView) View.inflate(c, R.layout.tabletext, null); platformTv.setPadding(0, 0, 0, 0); platformTv.setText("platform " + thisEtd.platform); platformTv.setTextSize(20); routeDetail.addView(platformTv); ImageView bikeIv = (ImageView) View.inflate(c, R.layout.bikeimage, null); if (!thisEtd.bikes) bikeIv.setImageResource(R.drawable.no_bicycle); routeDetail.addView(bikeIv); tableLayout.addView(routeDetail, index + 1); } else { thisEtd.isExpanded = false; tableLayout.removeViewAt(index + 1); } } }); } else { // append next trains arrival time to existing destination display //timeTv.append(String.valueOf(", "+thisEtd.minutesToArrival)); numAlt++; TextView nextTimeTv = (TextView) View.inflate(c, R.layout.tabletext, null); //nextTimeTv.setTextSize(36-(5*numAlt)); nextTimeTv.setTextSize(36); nextTimeTv.setText(String.valueOf(thisEtd.minutesToArrival)); //nextTimeTv.setPadding(30, 0, 0, 0); if (numAlt == 1) //0xFFF06D2F C9C7C8 nextTimeTv.setTextColor(0xFFC9C7C8); else if (numAlt == 2) nextTimeTv.setTextColor(0xFFA8A7A7); long counterTime = thisEtd.minutesToArrival * 60 * 1000; nextTimeTv.setTag(counterTime + now); if (counterTime > maxTimer) { maxTimer = counterTime; } timerViews.add(nextTimeTv); //new ViewCountDownTimer(nextTimeTv, counterTime, 60*1000).start(); tr.addView(nextTimeTv); } lastDestination = thisEtd.destination; } // end for //scrolly.scrollTo(0, 0); // Avoid spamming bart.gov. Only re-ping if etd response is valid for at least 3m if (maxTimer > 1000 * 60 * 3) { timer = new ViewCountDownTimer(timerViews, "etd", maxTimer, 30 * 1000); timer.start(); } }
From source file:com.github.vseguip.sweet.contacts.SweetConflictResolveActivity.java
/** * @param fieldTable/* w w w .j a va 2s.c o m*/ * @param nameOfField * @param field */ private void addConflictRow(TableLayout fieldTable, final String nameOfField, final String fieldLocal, final String fieldRemote) { if (mCurrentLocal == null || mCurrentSugar == null) return; // String fieldLocal = mCurrentLocal.get(nameOfField); // String fieldRemote = mCurrentSugar.get(nameOfField); TableRow row = new TableRow(this); final Spinner sourceSelect = new Spinner(this); sourceSelect.setBackgroundResource(R.drawable.black_underline); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, this.getResources().getStringArray(R.array.conflict_sources)); spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sourceSelect.setAdapter(spinnerArrayAdapter); // Open the spinner when pressing any of the text fields OnClickListener spinnerOpener = new OnClickListener() { @Override public void onClick(View v) { sourceSelect.performClick(); } }; row.addView(sourceSelect); fieldTable.addView(row); row = new TableRow(this); TextView fieldName = new TextView(this); int stringId = this.getResources().getIdentifier(nameOfField, "string", this.getPackageName()); fieldName.setText(this.getString(stringId)); fieldName.setTextSize(16); fieldName.setPadding(fieldName.getPaddingLeft(), fieldName.getPaddingTop(), fieldName.getPaddingRight() + 10, fieldName.getPaddingBottom()); fieldName.setOnClickListener(spinnerOpener); row.addView(fieldName); final TextView fieldValueLocal = new TextView(this); fieldValueLocal.setText(fieldLocal); fieldValueLocal.setTextSize(16); row.addView(fieldValueLocal); fieldValueLocal.setOnClickListener(spinnerOpener); fieldTable.addView(row); row = new TableRow(this); row.addView(new TextView(this));// add dummy control final TextView fieldValueRemote = new TextView(this); fieldValueRemote.setText(fieldRemote); fieldValueRemote.setTextSize(16); fieldValueRemote.setOnClickListener(spinnerOpener); row.addView(fieldValueRemote); sourceSelect.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 0) { fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected); fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected); resolvedContacts[mPosResolved].set(nameOfField, fieldLocal); } else { fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected); fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected); resolvedContacts[mPosResolved].set(nameOfField, fieldRemote); } } @Override public void onNothingSelected(AdapterView<?> view) { } }); row.setPadding(row.getLeft(), row.getTop() + 5, row.getRight(), row.getBottom() + 10); // Restore appropiate selections according to resolved contact if (resolvedContacts[mPosResolved].get(nameOfField).equals(fieldLocal)) { sourceSelect.setSelection(0); } else { sourceSelect.setSelection(1); } fieldTable.addView(row); }