//center vertical
@Override
        protected void onPostExecute(Void param) {
            if (pageDOM == null) {
                return; // instead of try-catch
            }
            Elements tierTables = pageDOM.getElementsByClass("wikitable");
            // calculate the width of the images to be displayed later on
            Display display = activity.getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            int screenWidth = size.x;
            int scaleWidth = screenWidth / 10; // set it to be 1/10 of the screen width
            int tableIndex = tierMap.get(category).get(tier);
            Element tierTable = tierTables.get(tableIndex);
            TableLayout table = new TableLayout(activity);
            Elements rows = tierTable.getElementsByTag("tbody").first().getElementsByTag("tr"); // get all rows in each table
            int countRow = 0;
            for (Element row : rows) {
                countRow++;
                if (countRow == 1) {
                    // row 1 is the column headers. This may be different in the DOM in browser
                    continue;
                }
                else {
                    Elements cells = row.getElementsByTag("td");
                    TableRow tr = new TableRow(activity);
                    ImageView imgView = new ImageView(activity); tr.addView(imgView);
                    // get the thubnail image src
                    Element link = row.getElementsByTag("a").first();
                    String imgSrc = link.getElementsByTag("img").first().attr("data-src");
                    if (imgSrc == null || imgSrc.equals("")) imgSrc = link.getElementsByTag("img").first().attr("src");
                    imgView.setLayoutParams(new TableRow.LayoutParams(scaleWidth, (int) (scaleWidth*1.5))); // the height's not exact
                    imgView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                    // get the scaled image link and display it
                    String newScaledLink = Util.getScaledWikiaImageLink(imgSrc, scaleWidth);
                    ImageLoader.getInstance().displayImage(newScaledLink, imgView);
                    String famName = cells.get(2).text();
                    TextView tv = new TextView(activity);
                    tv.setText(famName);
                    tr.addView(tv);
                    tr.setGravity(0x10); //center vertical
                    table.addView(tr);
                    tr.setTag(famName);
                    tr.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(activity, FamDetailActivity.class);
                            intent.putExtra(MainActivity.FAM_NAME, (String) v.getTag());
                            activity.startActivity(intent);
                        }
                    });
                }
            }
            layout.addView(table);
            //TODO: center the spinner horizontally
            //remove the spinner
            ProgressBar progressBar = (ProgressBar) activity.findViewById(R.id.progressBar_tierTable);
            layout.removeView(progressBar);
        }
tv.setText(famName);
tr.addView(tv);
tr.setGravity(0x10); //center vertical
table.addView(tr);
tr.setTag(famName);
if (imgSrc == null || imgSrc.equals("")) imgSrc = link.getElementsByTag("img").first().attr("src");
imgView.setLayoutParams(new TableRow.LayoutParams(scaleWidth, (int) (scaleWidth*1.5))); // the height's not exact
imgView.setScaleType(ImageView.ScaleType.FIT_CENTER);
// get the scaled image link and display it
String newScaledLink = Util.getScaledWikiaImageLink(imgSrc, scaleWidth);
ImageLoader.getInstance().displayImage(newScaledLink, imgView);
String famName = cells.get(2).text();
TextView tv = new TextView(activity);
tv.setText(famName);
tr.addView(tv);
tr.setGravity(0x10); //center vertical
table.addView(tr);
tr.setTag(famName);
tr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(activity, FamDetailActivity.class);
intent.putExtra(MainActivity.FAM_NAME, (String) v.getTag());
activity.startActivity(intent);
}
});
// row 1 is the column headers. This may be different in the DOM in browser
continue;
}
else {
Elements cells = row.getElementsByTag("td");
TableRow tr = new TableRow(activity);
ImageView imgView = new ImageView(activity); tr.addView(imgView);
// get the thubnail image src
Element link = row.getElementsByTag("a").first();
String imgSrc = link.getElementsByTag("img").first().attr("data-src");
if (imgSrc == null || imgSrc.equals("")) imgSrc = link.getElementsByTag("img").first().attr("src");
imgView.setLayoutParams(new TableRow.LayoutParams(scaleWidth, (int) (scaleWidth*1.5))); // the height's not exact
imgView.setScaleType(ImageView.ScaleType.FIT_CENTER);
// get the scaled image link and display it
String newScaledLink = Util.getScaledWikiaImageLink(imgSrc, scaleWidth);
ImageLoader.getInstance().displayImage(newScaledLink, imgView);
String famName = cells.get(2).text();
TextView tv = new TextView(activity);
tv.setText(famName);
tr.addView(tv);
tr.setGravity(0x10); //center vertical
table.addView(tr);
tr.setTag(famName);
tr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(activity, FamDetailActivity.class);
intent.putExtra(MainActivity.FAM_NAME, (String) v.getTag());
activity.startActivity(intent);
}
});
}
}
layout.addView(table);
//TODO: center the spinner horizontally
//remove the spinner
ProgressBar progressBar = (ProgressBar) activity.findViewById(R.id.progressBar_tierTable);
layout.removeView(progressBar);
}