Android Open Source - RaceTimer Runner 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;
/*  w  ww  .  j  av a  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.AdapterView;
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.GraphViewSeries;
import com.jjoe64.graphview.LineGraphView;
import com.liamfruzyna.android.racetimer.AppData;
import com.liamfruzyna.android.racetimer.R;
import com.liamfruzyna.android.racetimer.objects.Event;
import com.liamfruzyna.android.racetimer.objects.Runner;

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

/**
 * Created by mail929 on 9/13/14.
 * A Fragment that shows a runners performances
 */
public class RunnerFragment extends Fragment
{
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.runner, container, false);

        //locally saves the current runner
        final Runner runner = AppData.runners.get(getArguments().getInt("key"));

        //init view widgets
        TextView name = (TextView) view.findViewById(R.id.name);
        TextView team = (TextView) view.findViewById(R.id.team);
        ListView times = (ListView) view.findViewById(R.id.times);
        LinearLayout grapharea = (LinearLayout) view.findViewById(R.id.graph);
        GraphView gView = new LineGraphView(getActivity(), "");

        //builds a string with all the teams the runner is on
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < runner.teams.size(); i++)
        {
            sb.append(AppData.teams.get(runner.teams.get(i)).shortName);
            if(i < runner.teams.size() - 1)
            {
                sb.append(", ");
            }
        }

        //sets textviews to appropriate data
        name.setText(runner.name);
        team.setText(sb.toString());

        //creates a 2 lists of data for the events
        //eventData is [runners meet number, meets event number]
        //events is [meet shortName, level, distance, final time]
        final List<Integer[]> eventData = new ArrayList<Integer[]>();
        final List<String[]> events = new ArrayList<String[]>();
        for(int i = 0; i < runner.times.size(); i++)
        {
            for(int j = 0; j < AppData.meets.size(); j++)
            {
                if(runner.times.get(i).meetId == j)
                {
                    for(int l = 0; l < AppData.meets.get(j).events.size(); l++)
                    {
                        if(runner.times.get(i).eventId == l)
                        {
                            Event event = AppData.meets.get(j).events.get(l);
                            eventData.add(new Integer[]{j, l});
                            if(runner.getTime(j, l).checkPoints.size() > 0)
                            {
                                events.add(new String[]{AppData.meets.get(j).shortName, event.level, Double.toString(event.distance), runner.getTime(j, l).checkPoints.get(runner.getTime(j, l).checkPoints.size()-1)});
                            }
                        }
                    }
                }
            }
        }
        //its finally over

        //creates a graph with all the runners times
        GraphViewSeries series = new GraphViewSeries(new GraphView.GraphViewData[]{});
        List<String> meets = new ArrayList<String>();
        for(int i = 0; i < events.size(); i++)
        {
            meets.add(events.get(i)[0]);
            series.appendData(new GraphView.GraphViewData(i+1, AppData.getTime(events.get(i)[3])), false);
        }
        gView.addSeries(series);
        gView.setHorizontalLabels(meets.toArray(new String[meets.size()]));
        grapharea.addView(gView);

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

                //init view widgets
                TextView name = (TextView) view.findViewById(R.id.eventName);
                TextView level = (TextView) view.findViewById(R.id.eventLevel);
                TextView distance = (TextView) view.findViewById(R.id.eventDistance);
                TextView time = (TextView) view.findViewById(R.id.totalTime);

                //set appropriate data to textviews
                name.setText(events.get(position)[0]);
                level.setText(events.get(position)[1]);
                distance.setText(events.get(position)[2]);
                time.setText(events.get(position)[3]);
                return view;
            }
        });

        //listen for a time to be selected
        times.setOnItemClickListener(new AdapterView.OnItemClickListener()
        {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
            {
                //go to that time
                Fragment tf = new EventFragment();
                Bundle args = new Bundle();
                args.putInt("event", eventData.get(i)[1]);
                args.putInt("meet", eventData.get(i)[0]);
                args.putInt("runner", runner.id);
                tf.setArguments(args);
                FragmentManager fragmentManager = getFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.container, tf).commit();
            }
        });
        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