List of usage examples for android.widget TableLayout addView
@Override public void addView(View child)
From source file:org.onebusaway.android.ui.ArrivalsListAdapterStyleB.java
@Override protected void initView(final View view, CombinedArrivalInfoStyleB combinedArrivalInfoStyleB) { final ArrivalInfo stopInfo = combinedArrivalInfoStyleB.getArrivalInfoList().get(0); final ObaArrivalInfo arrivalInfo = stopInfo.getInfo(); final Context context = getContext(); LayoutInflater inflater = LayoutInflater.from(context); TextView routeName = (TextView) view.findViewById(R.id.routeName); TextView destination = (TextView) view.findViewById(R.id.routeDestination); // TableLayout that we will fill with TableRows of arrival times TableLayout arrivalTimesLayout = (TableLayout) view.findViewById(R.id.arrivalTimeLayout); arrivalTimesLayout.removeAllViews(); Resources r = view.getResources(); ImageButton starBtn = (ImageButton) view.findViewById(R.id.route_star); starBtn.setColorFilter(r.getColor(R.color.theme_primary)); ImageButton mapImageBtn = (ImageButton) view.findViewById(R.id.mapImageBtn); mapImageBtn.setColorFilter(r.getColor(R.color.theme_primary)); ImageButton routeMoreInfo = (ImageButton) view.findViewById(R.id.route_more_info); routeMoreInfo.setColorFilter(r.getColor(R.color.switch_thumb_normal_material_dark)); starBtn.setImageResource(/*ww w . j a va 2 s . co m*/ stopInfo.isRouteAndHeadsignFavorite() ? R.drawable.focus_star_on : R.drawable.focus_star_off); starBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Show dialog for setting route favorite RouteFavoriteDialogFragment dialog = new RouteFavoriteDialogFragment.Builder( stopInfo.getInfo().getRouteId(), stopInfo.getInfo().getHeadsign()) .setRouteShortName(stopInfo.getInfo().getShortName()) .setRouteLongName(stopInfo.getInfo().getRouteLongName()) .setStopId(stopInfo.getInfo().getStopId()) .setFavorite(!stopInfo.isRouteAndHeadsignFavorite()).build(); dialog.setCallback(new RouteFavoriteDialogFragment.Callback() { @Override public void onSelectionComplete(boolean savedFavorite) { if (savedFavorite) { mFragment.refreshLocal(); } } }); dialog.show(mFragment.getFragmentManager(), RouteFavoriteDialogFragment.TAG); } }); // Setup map mapImageBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mFragment.showRouteOnMap(stopInfo); } }); // Setup more routeMoreInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mFragment.showListItemMenu(view, stopInfo); } }); routeName.setText(arrivalInfo.getShortName()); destination.setText(MyTextUtils.toTitleCase(arrivalInfo.getHeadsign())); // Loop through the arrival times and create the TableRows that contains the data for (int i = 0; i < combinedArrivalInfoStyleB.getArrivalInfoList().size(); i++) { final ArrivalInfo arrivalRow = combinedArrivalInfoStyleB.getArrivalInfoList().get(i); final ObaArrivalInfo tempArrivalInfo = arrivalRow.getInfo(); long scheduledTime = tempArrivalInfo.getScheduledArrivalTime(); // Create a new row to be added final TableRow tr = (TableRow) inflater.inflate(R.layout.arrivals_list_tr_template_style_b, null); // Layout and views to inflate from XML templates RelativeLayout layout; TextView scheduleView, estimatedView, statusView; View divider; if (i == 0) { // Use larger styled layout/view for next arrival time layout = (RelativeLayout) inflater.inflate(R.layout.arrivals_list_rl_template_style_b_large, null); scheduleView = (TextView) inflater .inflate(R.layout.arrivals_list_tv_template_style_b_schedule_large, null); estimatedView = (TextView) inflater .inflate(R.layout.arrivals_list_tv_template_style_b_estimated_large, null); statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_large, null); } else { // Use smaller styled layout/view for further out times layout = (RelativeLayout) inflater.inflate(R.layout.arrivals_list_rl_template_style_b_small, null); scheduleView = (TextView) inflater .inflate(R.layout.arrivals_list_tv_template_style_b_schedule_small, null); estimatedView = (TextView) inflater .inflate(R.layout.arrivals_list_tv_template_style_b_estimated_small, null); statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_small, null); } // Set arrival times and status in views scheduleView.setText(DateUtils.formatDateTime(context, scheduledTime, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT)); if (arrivalRow.getPredicted()) { long eta = arrivalRow.getEta(); if (eta == 0) { estimatedView.setText(R.string.stop_info_eta_now); } else { estimatedView.setText(eta + " min"); } } else { estimatedView.setText(R.string.stop_info_eta_unknown); } statusView.setText(arrivalRow.getStatusText()); int colorCode = arrivalRow.getColor(); statusView.setBackgroundResource(R.drawable.round_corners_style_b_status); GradientDrawable d = (GradientDrawable) statusView.getBackground(); d.setColor(context.getResources().getColor(colorCode)); int alpha; if (i == 0) { // Set next arrival alpha = (int) (1.0f * 255); // X percent transparency } else { // Set smaller rows alpha = (int) (.35f * 255); // X percent transparency } d.setAlpha(alpha); // Set padding on status view int pSides = UIUtils.dpToPixels(context, 5); int pTopBottom = UIUtils.dpToPixels(context, 2); statusView.setPadding(pSides, pTopBottom, pSides, pTopBottom); // Add TextViews to layout layout.addView(scheduleView); layout.addView(statusView); layout.addView(estimatedView); // Make sure the TextViews align left/center/right of parent relative layout RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) scheduleView.getLayoutParams(); params1.addRule(RelativeLayout.ALIGN_PARENT_LEFT); params1.addRule(RelativeLayout.CENTER_VERTICAL); scheduleView.setLayoutParams(params1); RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) statusView.getLayoutParams(); params2.addRule(RelativeLayout.CENTER_IN_PARENT); // Give status view a little extra margin int p = UIUtils.dpToPixels(context, 3); params2.setMargins(p, p, p, p); statusView.setLayoutParams(params2); RelativeLayout.LayoutParams params3 = (RelativeLayout.LayoutParams) estimatedView.getLayoutParams(); params3.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); params3.addRule(RelativeLayout.CENTER_VERTICAL); estimatedView.setLayoutParams(params3); // Add layout to TableRow tr.addView(layout); // Add the divider, if its not the first row if (i != 0) { int dividerHeight = UIUtils.dpToPixels(context, 1); divider = inflater.inflate(R.layout.arrivals_list_divider_template_style_b, null); divider.setLayoutParams( new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, dividerHeight)); arrivalTimesLayout.addView(divider); } // Add click listener tr.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mFragment.showListItemMenu(tr, arrivalRow); } }); // Add TableRow to container layout arrivalTimesLayout.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT)); } // Show or hide reminder for this trip ContentValues values = null; if (mTripsForStop != null) { values = mTripsForStop.getValues(arrivalInfo.getTripId()); } if (values != null) { String reminderName = values.getAsString(ObaContract.Trips.NAME); TextView reminder = (TextView) view.findViewById(R.id.reminder); if (reminderName.length() == 0) { reminderName = context.getString(R.string.trip_info_noname); } reminder.setText(reminderName); Drawable d = reminder.getCompoundDrawables()[0]; d = DrawableCompat.wrap(d); DrawableCompat.setTint(d.mutate(), view.getResources().getColor(R.color.theme_primary)); reminder.setCompoundDrawables(d, null, null, null); reminder.setVisibility(View.VISIBLE); } else { // Explicitly set reminder to invisible because we might be reusing // this view. View reminder = view.findViewById(R.id.reminder); reminder.setVisibility(View.GONE); } }
From source file:com.example.drugsformarinemammals.Dose_Information.java
public void show_dose(ArrayList<Dose_Data> dose, TableLayout dose_table, TableRow dose_data, String drug_name, String group_name, String animal_family, String animal_name, String animal_category, ArrayList<String> notes, ArrayList<String> references, ArrayList<Article_Reference> references_index) { String doseAmount;//from w w w .ja va 2 s.c om String dosePosology; String doseRoute; String doseBookReference; String doseArticleReference; for (int k = 0; k < dose.size(); k++) { if (k > 0) { dose_data = new TableRow(this); } doseAmount = dose.get(k).getAmount(); dosePosology = dose.get(k).getPosology(); doseRoute = dose.get(k).getRoute(); doseBookReference = dose.get(k).getBookReference(); doseArticleReference = dose.get(k).getArticleReference(); //Dose amount data TextView textView_animal_dose_amount = new TextView(this); textView_animal_dose_amount.setText(doseAmount); textView_animal_dose_amount.setSingleLine(false); textView_animal_dose_amount.setTextColor(Color.BLACK); textView_animal_dose_amount.setTextSize(15); textView_animal_dose_amount.setTypeface(Typeface.SANS_SERIF); TableRow.LayoutParams paramsDoseAmount = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsDoseAmount.gravity = Gravity.CENTER; dose_data.addView(textView_animal_dose_amount, paramsDoseAmount); //Dose posology data TextView textView_animal_dose_posology = new TextView(this); textView_animal_dose_posology.setText(dosePosology); textView_animal_dose_posology.setSingleLine(false); textView_animal_dose_posology.setTextColor(Color.BLACK); textView_animal_dose_posology.setTextSize(15); textView_animal_dose_posology.setTypeface(Typeface.SANS_SERIF); TableRow.LayoutParams paramsDosePosology = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsDosePosology.gravity = Gravity.CENTER; if ((screenWidth < 600 && !isCollapsed(drug_name, group_name, animal_family, "Posology")) || screenWidth >= 600) dose_data.addView(textView_animal_dose_posology, paramsDosePosology); //Dose route data TextView textView_animal_dose_route = new TextView(this); textView_animal_dose_route.setText(doseRoute); textView_animal_dose_route.setSingleLine(false); textView_animal_dose_route.setTextColor(Color.BLACK); textView_animal_dose_route.setTextSize(15); textView_animal_dose_route.setTypeface(Typeface.SANS_SERIF); if (screenWidth >= 600) { TableRow.LayoutParams paramsDoseRoute = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsDoseRoute.gravity = Gravity.CENTER; dose_data.addView(textView_animal_dose_route, paramsDoseRoute); } else { TableRow.LayoutParams paramsDoseRoute = new TableRow.LayoutParams(30, TableRow.LayoutParams.WRAP_CONTENT); paramsDoseRoute.gravity = Gravity.CENTER; dose_data.addView(textView_animal_dose_route, paramsDoseRoute); } //Dose reference data TextView textView_animal_dose_reference = new TextView(this); if (!doseBookReference.equals("")) textView_animal_dose_reference.setText(doseBookReference); else if (!doseArticleReference.equals("")) { if (!references.contains(doseArticleReference)) { references.add(references.size(), doseArticleReference); Article_Reference article_reference = new Article_Reference(reference_index, doseArticleReference); references_index.add(references_index.size(), article_reference); reference_index++; } int article_index = references.indexOf(doseArticleReference); textView_animal_dose_reference.setText("(" + references_index.get(article_index).getIndex() + ")"); } textView_animal_dose_reference.setSingleLine(false); textView_animal_dose_reference.setTextColor(Color.BLACK); textView_animal_dose_reference.setTextSize(15); textView_animal_dose_reference.setTypeface(Typeface.SANS_SERIF); if (screenWidth >= 600) { TableRow.LayoutParams paramsDoseReference = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsDoseReference.gravity = Gravity.CENTER; dose_data.addView(textView_animal_dose_reference, paramsDoseReference); } else { TableRow.LayoutParams paramsDoseReference = new TableRow.LayoutParams(150, TableRow.LayoutParams.WRAP_CONTENT); paramsDoseReference.gravity = Gravity.CENTER; dose_data.addView(textView_animal_dose_reference, paramsDoseReference); } //Specific note index ArrayList<String> specific_notes = new ArrayList<String>(); specific_notes = helper.read_specific_notes(drug_name, group_name, animal_name, animal_family, animal_category, doseAmount, dosePosology, doseRoute, doseBookReference, doseArticleReference); String index = ""; for (int m = 0; m < specific_notes.size(); m++) { String note = specific_notes.get(m); if (!notes.contains(note)) { notes.add(notes.size(), note); } index += "(" + (notes.indexOf(note) + 1) + ") "; } TextView textView_specific_note_index = new TextView(this); textView_specific_note_index.setText(index); textView_specific_note_index.setSingleLine(false); textView_specific_note_index.setTextColor(Color.BLACK); textView_specific_note_index.setTextSize(15); textView_specific_note_index.setTypeface(Typeface.SANS_SERIF); if (screenWidth >= 600 && screenWidth < 720) { TableRow.LayoutParams paramsSpecificNoteIndex = new TableRow.LayoutParams(150, TableRow.LayoutParams.WRAP_CONTENT); paramsSpecificNoteIndex.gravity = Gravity.CENTER; dose_data.addView(textView_specific_note_index, paramsSpecificNoteIndex); } else if (screenWidth >= 720) { TableRow.LayoutParams paramsSpecificNoteIndex = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsSpecificNoteIndex.gravity = Gravity.CENTER; dose_data.addView(textView_specific_note_index, paramsSpecificNoteIndex); } else { TableRow.LayoutParams paramsSpecificNoteIndex = new TableRow.LayoutParams(100, TableRow.LayoutParams.WRAP_CONTENT); paramsSpecificNoteIndex.gravity = Gravity.CENTER; if ((screenWidth < 600 && !isCollapsed(drug_name, group_name, animal_family, "Note")) || screenWidth >= 600) dose_data.addView(textView_specific_note_index, paramsSpecificNoteIndex); } dose_table.addView(dose_data); } }