Android Open Source - RaceTimer Event Fragment






From Project

Back to project page RaceTimer.

License

The source code is released under:

GNU General Public License

If you think the Android project RaceTimer 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

package com.liamfruzyna.android.racetimer.fragments;
//from  w  w  w .  j a va  2s  . c  o m
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphViewDataInterface;
import com.jjoe64.graphview.GraphViewSeries;
import com.jjoe64.graphview.LineGraphView;
import com.liamfruzyna.android.racetimer.AppData;
import com.liamfruzyna.android.racetimer.R;
import com.liamfruzyna.android.racetimer.objects.Time;


import java.util.ArrayList;
import java.util.List;

/**
 * Created by mail929 on 9/27/14.
 * A Fragment that shows a runners performance in a single event
 */
public class EventFragment extends Fragment
{

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

        //save ids that are sent in as arguments
        int eventId = getArguments().getInt("event");
        int meetId = getArguments().getInt("meet");
        int runnerId = getArguments().getInt("runner");

        //init view widgets
        TextView runner = (TextView) view.findViewById(R.id.runnerName);
        TextView meet = (TextView) view.findViewById(R.id.meetName);
        TextView level = (TextView) view.findViewById(R.id.level);
        TextView distance = (TextView) view.findViewById(R.id.distance);
        ListView cps = (ListView) view.findViewById(R.id.cpList);
        LinearLayout grapharea = (LinearLayout) view.findViewById(R.id.graph);
        GraphView gView = new LineGraphView(getActivity(), "");

        //sets textviews to appropriate data
        runner.setText(AppData.runners.get(runnerId).name);
        meet.setText(AppData.meets.get(meetId).shortName);
        level.setText(AppData.meets.get(meetId).events.get(eventId).level);
        distance.setText(Double.toString(AppData.meets.get(meetId).events.get(eventId).distance));

        //locally save time data
        Time time = AppData.runners.get(runnerId).getTime(meetId, eventId);

        //create graph of checkpoint times
        GraphViewSeries series = new GraphViewSeries(new GraphView.GraphViewData[]{});
        for(int i = 0; i < AppData.getTimes(time).size(); i++)
        {
            series.appendData(new GraphView.GraphViewData(i+1, AppData.getTimes(time).get(i)), false);
        }
        gView.addSeries(series);
        gView.getGraphViewStyle().setNumHorizontalLabels(time.checkPoints.size());
        gView.setManualYAxisBounds(AppData.getMax(AppData.getTimes(time)) + AppData.getDif(AppData.getTimes(time))/4,
                AppData.getMin(AppData.getTimes(time)) - AppData.getDif(AppData.getTimes(time))/4);
        grapharea.addView(gView);

        //create a list of checkpoint data [checkpoint distance, checkpoint time]
        final List<String[]> cpData = new ArrayList<String[]>();
        for(int i = 0; i < time.checkPoints.size(); i++)
        {
            if(i < time.checkPoints.size() - 1)
            {
                cpData.add(new String[]{Double.toString(AppData.meets.get(meetId).events.get(eventId).checkPoints.get(i)), time.checkPoints.get(i)});
            }
            else
            {
                cpData.add(new String[]{Double.toString(AppData.meets.get(meetId).events.get(eventId).distance), time.checkPoints.get(i)});
            }
        }

        //listview of checkpoints
        cps.setAdapter(new ArrayAdapter<String[]>(getActivity(), R.layout.cp_list_item, R.id.distance, cpData)
        {
            public View getView(final int position, View convertView, ViewGroup parent)
            {
                //basic setup
                View view;
                if(convertView == null)
                {
                    LayoutInflater infl = (LayoutInflater) getActivity().getSystemService(getActivity().LAYOUT_INFLATER_SERVICE);
                    convertView = infl.inflate(R.layout.cp_list_item, parent, false);
                }
                view = super.getView(position, convertView, parent);

                //init view widgets
                TextView distance = (TextView) view.findViewById(R.id.distance);
                TextView time = (TextView) view.findViewById(R.id.time);

                //set textviews to appropriate data
                distance.setText(cpData.get(position)[0]);
                time.setText(cpData.get(position)[1]);
                return view;
            }
        });
        return view;
    }
}




Java Source Code List

com.liamfruzyna.android.racetimer.AppData.java
com.liamfruzyna.android.racetimer.ApplicationTest.java
com.liamfruzyna.android.racetimer.Fab.java
com.liamfruzyna.android.racetimer.RTActivity.java
com.liamfruzyna.android.racetimer.fragments.AddEventFragment.java
com.liamfruzyna.android.racetimer.fragments.AddMeetFragment.java
com.liamfruzyna.android.racetimer.fragments.AddTeamFragment.java
com.liamfruzyna.android.racetimer.fragments.EventFragment.java
com.liamfruzyna.android.racetimer.fragments.HomeFragment.java
com.liamfruzyna.android.racetimer.fragments.InRaceFragment.java
com.liamfruzyna.android.racetimer.fragments.MeetFragment.java
com.liamfruzyna.android.racetimer.fragments.RunnerFragment.java
com.liamfruzyna.android.racetimer.fragments.TeamFragment.java
com.liamfruzyna.android.racetimer.objects.Event.java
com.liamfruzyna.android.racetimer.objects.Meet.java
com.liamfruzyna.android.racetimer.objects.Runner.java
com.liamfruzyna.android.racetimer.objects.Team.java
com.liamfruzyna.android.racetimer.objects.Time.java