Android Open Source - Netball Base Team 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   w w  w  .  j a v a  2  s.c o m
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import com.prisch.R;
import com.prisch.model.Player;
import com.prisch.model.Position;
import com.prisch.views.TeamAdapter;

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

public abstract class BaseTeamActivity extends Activity {

    // List of Positions that have not yet been assigned
    private List<Position> outstandingPositions = new LinkedList<Position>();

    // Map from a Player's ID to the Position currently assigned to that Player
    private Map<Long, Position> playerPositionMap = new HashMap<Long, Position>(7);

    private ListView listView;
    private TeamAdapter teamAdapter;

    // ===== Constructor =====

    protected BaseTeamActivity() {
        for (Position position : Position.values()) {
            outstandingPositions.add(position);
        }
    }

    // ===== Abstract Operations =====

    protected abstract TeamAdapter createAdapter();

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

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

        teamAdapter = createAdapter();
        listView = (ListView)findViewById(R.id.listview_players);
        listView.setAdapter(teamAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (getAdapter().getItem(position) instanceof Player) {
                    togglePlayerPosition(id);
                }
            }
        });

        getActionBar().setCustomView(R.layout.actionbar_selectteam);
        getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

        updateActionBar();
    }

    // ===== Accessors =====

    protected TeamAdapter getAdapter() {
        return teamAdapter;
    }

    protected Map<Long, Position> getPlayerPositionMap() {
        return playerPositionMap;
    }

    protected View findDoneButton() {
        return findViewById(R.id.custombutton_selectDone);
    }

    // ===== Operations =====

    protected void initialisePlayerPositionMap(Map<Long, Position> playerPositionMap) {
        this.playerPositionMap = playerPositionMap;
        this.teamAdapter.setPlayerPositionMap(playerPositionMap);

        for (Position position : playerPositionMap.values()) {
            outstandingPositions.remove(position);
        }

        updateActionBar();
    }

    private void togglePlayerPosition(long playerId) {
        if (playerPositionMap.containsKey(playerId)) {
            Position previousPosition = playerPositionMap.remove(playerId);
            outstandingPositions.add(0, previousPosition);
        } else if (!outstandingPositions.isEmpty()) {
            Position currentPosition = outstandingPositions.remove(0);
            playerPositionMap.put(playerId, currentPosition);
        }

        getAdapter().setPlayerPositionMap(playerPositionMap);
        updateActionBar();
    }

    private void updateActionBar() {
        TextView instructionText = (TextView)findViewById(R.id.text_selectPosition);
        View acceptButton = findViewById(R.id.custombutton_selectDone);

        if (outstandingPositions.isEmpty()) {
            instructionText.setText("");
            acceptButton.setEnabled(true);
        } else {
            instructionText.setText("Select the " + outstandingPositions.get(0));
            acceptButton.setEnabled(false);
        }
    }
}




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