Android Open Source - Netball Game Stats Activity






From Project

Back to project page Netball.

License

The source code is released under:

GNU General Public License

If you think the Android project Netball 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.prisch.activities;
//from ww  w.j av a2s  .co m
import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.app.LoaderManager;
import android.content.Loader;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import com.prisch.R;
import com.prisch.fragments.PositionStatsFragment;
import com.prisch.loaders.GameStatsLoader;
import com.prisch.model.GameStats;
import com.prisch.model.PlayerStats;
import com.prisch.model.Position;
import com.prisch.views.GameStatsAdapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GameStatsActivity extends FragmentActivity implements LoaderManager.LoaderCallbacks<GameStats>, ActionBar.TabListener {

    public static final String GAME_ID_KEY = "GAME_ID_KEY";

    private final static int GAME_STATS_LOADER = 0;

    private ViewPager viewPager;
    private Map<Position, PositionStatsFragment> positionFragmentMap;

    // ===== Lifecycle Methods =====

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gamestats);

        final ActionBar actionBar = getActionBar();
        initializeFragments();

        GameStatsAdapter adapter = new GameStatsAdapter(getSupportFragmentManager(), positionFragmentMap);
        viewPager = (ViewPager)findViewById(R.id.pager_gamestats);
        viewPager.setAdapter(adapter);

        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
            }

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                // Nothing needed
            }

            @Override
            public void onPageScrollStateChanged(int state) {
                // Nothing needed
            }
        });

        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        for (Position position : Position.values()) {
            ActionBar.Tab tab = actionBar.newTab().setText(position.getAcronym()).setTabListener(this);
            actionBar.addTab(tab);
        }

        getLoaderManager().initLoader(GAME_STATS_LOADER, null, this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.gamestats, menu);
        return true;
    }

    @Override
    public Loader<GameStats> onCreateLoader(int id, Bundle args) {
        Long gameId = getIntent().getLongExtra(GAME_ID_KEY, 0);
        return new GameStatsLoader(this, gameId);
    }

    @Override
    public void onLoadFinished(Loader<GameStats> loader, GameStats data) {
        Map<Position, List<PlayerStats>> positionStatsMap = data.getPlayerStatsByPosition();
        for (Position position : positionFragmentMap.keySet()) {
            PositionStatsFragment fragment = positionFragmentMap.get(position);
            fragment.setData(positionStatsMap.get(position));
        }
    }

    @Override
    public void onLoaderReset(Loader<GameStats> loader) {
        for (PositionStatsFragment fragment : positionFragmentMap.values()) {
            fragment.clearData();
        }
    }

    @Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
        viewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
        // Nothing needed
    }

    @Override
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
        // Nothing needed
    }

    // ===== Helper Methods =====

    private void initializeFragments() {
        positionFragmentMap = new HashMap<Position, PositionStatsFragment>();
        for (Position position : Position.values()) {
            positionFragmentMap.put(position, new PositionStatsFragment(this));
        }
    }
}




Java Source Code List

com.prisch.activities.ActionsActivity.java
com.prisch.activities.BaseTeamActivity.java
com.prisch.activities.DashboardActivity.java
com.prisch.activities.GameStatsActivity.java
com.prisch.activities.GamesActivity.java
com.prisch.activities.PlayersActivity.java
com.prisch.activities.PositionsActivity.java
com.prisch.activities.SubstitutionActivity.java
com.prisch.activities.TeamActivity.java
com.prisch.content.DatabaseHelper.java
com.prisch.content.NetballContentProvider.java
com.prisch.controls.ActionButton.java
com.prisch.fragments.PositionStatsFragment.java
com.prisch.loaders.GameStatsLoader.java
com.prisch.model.Action.java
com.prisch.model.GameStats.java
com.prisch.model.Game.java
com.prisch.model.OpponentAction.java
com.prisch.model.OpponentRecord.java
com.prisch.model.PlayerStats.java
com.prisch.model.Player.java
com.prisch.model.Position.java
com.prisch.model.Record.java
com.prisch.model.TeamMember.java
com.prisch.repositories.GameRepository.java
com.prisch.repositories.OpponentRecordRepository.java
com.prisch.repositories.PlayerRepository.java
com.prisch.repositories.RecordRepository.java
com.prisch.repositories.StatsRepository.java
com.prisch.repositories.TeamMemberRepository.java
com.prisch.util.DateUtils.java
com.prisch.views.GameAdapter.java
com.prisch.views.GameStatsAdapter.java
com.prisch.views.PlayerStatsAdapter.java
com.prisch.views.PlayerStatsListItem.java
com.prisch.views.TeamAdapter.java