Android Open Source - tetravex-android Hi Score Table Fragment






From Project

Back to project page tetravex-android.

License

The source code is released under:

GNU General Public License

If you think the Android project tetravex-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 John Hunt <john.alma.hunt@gmail.com>
 */*  w ww .j a  va2s.  c  o m*/
 * This file is part of Tetravex Android.
 *
 * Tetravex Android is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tetravex Android is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Tetravex Android.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.github.tetravex_android.fragment;

import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.github.tetravex_android.Constants;
import com.github.tetravex_android.R;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Presents the view corresponding with a table from the database
 */
public class HiScoreTableFragment extends Fragment {

    private String mLabel;
    private Cursor mScoreCursor;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_score_table, container, false);

        // Set the label for the size of the board
        TextView tableSize = (TextView) rootView.findViewById(R.id.hi_score_board_size);
        tableSize.setText(mLabel);

        TableLayout table = (TableLayout) rootView.findViewById(R.id.hi_score_table_layout);

        // fill the table from the database cursor
        if (mScoreCursor != null) {
            // move cursor to first row, will return false if cursor is empty
            if (mScoreCursor.moveToFirst()) {
                do {
                    // set time from the database entry, format text
                    TextView timeTv = new TextView(rootView.getContext());
                    timeTv.setText(mScoreCursor.getString(Constants.DB_TIME_COL_IDX));
                    timeTv.setTextAppearance(rootView.getContext(), R.style.score_table_entry);

                    // set date from the database entry, format text
                    TextView dateTv = new TextView(rootView.getContext());
                    String unixTimeStr = mScoreCursor.getString(Constants.DB_DATE_COL_IDX);
                    long unixSeconds = Long.valueOf(unixTimeStr);
                    Date date = new Date(unixSeconds);
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    String formattedDate = sdf.format(date);
                    dateTv.setText(formattedDate);
                    dateTv.setTextAppearance(rootView.getContext(), R.style.score_table_entry);

                    // add the Views from the database entry to the TableLayout
                    TableRow row = new TableRow(rootView.getContext());
                    row.addView(timeTv);
                    row.addView(dateTv);
                    table.addView(row);

                    // add row separator
                    View spacerView = new View(rootView.getContext());
                    TableLayout.LayoutParams params = new TableLayout.LayoutParams();
                    params.width = TableLayout.LayoutParams.MATCH_PARENT;
                    params.height = 1;
                    spacerView.setLayoutParams(params);
                    spacerView.setBackgroundColor(getResources().getColor(R.color.tile_bkgnd_gray));
                    table.addView(spacerView);
                    // move to next row
                } while (mScoreCursor.moveToNext());
            }
        }

        return rootView;
    }

    /**
     * Accessor for the table indicator String
     *
     * @return the name of the table
     */
    public String getLabel() {
        return mLabel;
    }

    /**
     * Set the title of the table that will be displayed once the Fragment's layout is inflated
     *
     * @param tableIndicator the text to set
     */
    public void setLabel(String tableIndicator) {
        this.mLabel = tableIndicator;
    }

    /**
     * Set the cursor that will be used to iterate over the items in the table
     *
     * @param cursor the cursor to be set
     */
    public void setCursor(Cursor cursor) {
        this.mScoreCursor = cursor;
    }
}




Java Source Code List

com.github.tetravex_android.ApplicationTest.java
com.github.tetravex_android.Constants.java
com.github.tetravex_android.TetravexApp.java
com.github.tetravex_android.TetravexModule.java
com.github.tetravex_android.activity.DashboardActivity.java
com.github.tetravex_android.activity.HiScoreActivity.java
com.github.tetravex_android.activity.HowToActivity.java
com.github.tetravex_android.activity.LegalActivity.java
com.github.tetravex_android.activity.PauseActivity.java
com.github.tetravex_android.activity.PuzzleActivity.java
com.github.tetravex_android.activity.SettingsActivity.java
com.github.tetravex_android.data.BoardAdapter.java
com.github.tetravex_android.data.HiScoreManager.java
com.github.tetravex_android.domain.DatabaseBaseManager.java
com.github.tetravex_android.domain.DatabaseManager.java
com.github.tetravex_android.domain.five.FiveBaseManager.java
com.github.tetravex_android.domain.five.FiveBaseRecord.java
com.github.tetravex_android.domain.five.FiveManager.java
com.github.tetravex_android.domain.five.Five.java
com.github.tetravex_android.domain.four.FourBaseManager.java
com.github.tetravex_android.domain.four.FourBaseRecord.java
com.github.tetravex_android.domain.four.FourManager.java
com.github.tetravex_android.domain.four.Four.java
com.github.tetravex_android.domain.three.ThreeBaseManager.java
com.github.tetravex_android.domain.three.ThreeBaseRecord.java
com.github.tetravex_android.domain.three.ThreeManager.java
com.github.tetravex_android.domain.three.Three.java
com.github.tetravex_android.domain.two.TwoBaseManager.java
com.github.tetravex_android.domain.two.TwoBaseRecord.java
com.github.tetravex_android.domain.two.TwoManager.java
com.github.tetravex_android.domain.two.Two.java
com.github.tetravex_android.fragment.HiScoreTableFragment.java
com.github.tetravex_android.fragment.HowToFragment.java
com.github.tetravex_android.fragment.PageFragmentFactory.java
com.github.tetravex_android.game.Puzzle.java
com.github.tetravex_android.game.Score.java
com.github.tetravex_android.game.Tile.java