Android Open Source - RaceTimer Home 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  va2s. c  o  m
import android.app.Fragment;
import android.app.FragmentManager;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
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.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.liamfruzyna.android.racetimer.AppData;
import com.liamfruzyna.android.racetimer.Fab;
import com.liamfruzyna.android.racetimer.R;

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

/**
 * Created by mail929 on 9/13/14.
 * A Fragment that shows all the teams
 */
public class HomeFragment extends Fragment
{

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

        //init view widgets
        final Fab fab = (Fab) view.findViewById(R.id.fab);
        ListView teams = (ListView) view.findViewById(R.id.teamsList);

        //set up fab (Floating Action Button)
        fab.setFabDrawable(getResources().getDrawable(R.drawable.ic_action_add));
        fab.setFabColor(getResources().getColor(R.color.fab_blue));
        fab.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                //takes you to adda team when clicked
                Fragment tf = new AddTeamFragment();
                FragmentManager fragmentManager = getFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.container, tf).commit();
            }
        });

        //creates a list of team names
        final List<String> savedTeams = new ArrayList<String>();
        for(int i = 0; i < AppData.teams.size(); i++)
        {
            savedTeams.add(AppData.teams.get(i).name + " (" + AppData.teams.get(i).shortName + ")");
        }

        //listview of teams
        teams.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, savedTeams) {
            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(android.R.layout.simple_list_item_1, parent, false);
                }
                view = super.getView(position, convertView, parent);

                //init textview and add team name
                TextView text = (TextView) view.findViewById(android.R.id.text1);
                text.setText(savedTeams.get(position));
                return view;
            }
        });

        //listens for you to choose a team
        teams.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                //goes to that team
                Fragment tf = new TeamFragment();
                Bundle args = new Bundle();
                args.putInt("key", i);
                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