Back to project page RaceTimer.
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.
package com.liamfruzyna.android.racetimer.fragments; // w w w . j a v a 2 s .c om import android.app.Fragment; import android.app.FragmentManager; import android.graphics.Color; import android.os.Bundle; import android.view.Gravity; 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.Runner; import com.liamfruzyna.android.racetimer.objects.Team; import java.util.ArrayList; import java.util.List; /** * Created by mail929 on 9/13/14. * A Fragment that shows a teams runners and meets as well as a graph of runner times */ public class TeamFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.team, container, false); //locally saves the current team Team team = AppData.teams.get(getArguments().getInt("key")); //init view widgetes TextView name = (TextView) view.findViewById(R.id.name); TextView shortName = (TextView) view.findViewById(R.id.shortName); LinearLayout grapharea = (LinearLayout) view.findViewById(R.id.graph); GraphView gView = new LineGraphView(getActivity(), ""); ListView events = (ListView) view.findViewById(R.id.eventList); //sets textviews to their appropriate data name.setText(team.name); shortName.setText(team.shortName); //creates graph of all the runners on the team with times from all their events for(int i = 0; i < AppData.runners.size(); i++) { Runner runner = AppData.runners.get(i); GraphViewSeries series = new GraphViewSeries(new GraphView.GraphViewData[]{}); List<String> meets = new ArrayList<String>(); for(int j = 0; j < runner.times.size(); j++) { meets.add(AppData.meets.get(runner.times.get(j).meetId).shortName); List<Double> times = AppData.getTimes(runner.times.get(j)); if(times.size() > 0) { series.appendData(new GraphView.GraphViewData(j + 1, times.get(times.size() - 1)), false); } } gView.setHorizontalLabels(meets.toArray(new String[meets.size()])); gView.addSeries(series); } grapharea.addView(gView); //creates a list of all the meets, its conviently named teamEvents because I just want to confuse myself final List<String> teamEvents = new ArrayList<String>(); for(int i = 0; i < team.meets.size(); i++) { teamEvents.add(AppData.meets.get(team.meets.get(i)).name); } //listview of events... er.. I mean meets events.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, teamEvents) { public View getView(final int position, View convertView, ViewGroup parent) { //basic setup, see InRaceFragment.runnersL.setAdapter View view; if (convertView == null) { LayoutInflater infl = (LayoutInflater) getActivity().getSystemService(getActivity().LAYOUT_INFLATER_SERVICE); convertView = infl.inflate(android.R.layout.simple_list_item_1, parent, false); } view = super.getView(position, convertView, parent); //init textview and put the meet name TextView text = (TextView) view.findViewById(android.R.id.text1); text.setText(teamEvents.get(position)); return view; } }); //listens for one of the meet to be clicked events.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { //brings you to that meet Fragment mf = new MeetFragment(); Bundle args = new Bundle(); args.putInt("key", i); mf.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.container, mf).commit(); } }); //creates a list of the teams runners ListView runners = (ListView) view.findViewById(R.id.runnerList); final List<String> teamRunners = new ArrayList<String>(); for(int i = 0; i < team.runners.size(); i++) { teamRunners.add(AppData.runners.get(team.runners.get(i)).name); } //listview of runners runners.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, teamRunners) { public View getView(final int position, View convertView, ViewGroup parent) { //basic setup, see InRaceFragment.runnersL.setAdapter View view; if (convertView == null) { LayoutInflater infl = (LayoutInflater) getActivity().getSystemService(getActivity().LAYOUT_INFLATER_SERVICE); convertView = infl.inflate(android.R.layout.simple_list_item_1, parent, false); } view = super.getView(position, convertView, parent); //init textview and put the runner name TextView text = (TextView) view.findViewById(android.R.id.text1); text.setText(teamRunners.get(position)); return view; } }); //listens for one of the meet to be clicked runners.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { //then brings you to it Fragment rf = new RunnerFragment(); Bundle args = new Bundle(); args.putInt("key", i); rf.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.container, rf).commit(); } }); return view; } }