Exemplo n.º 1
0
  public List<Players> getAllPlayers() {
    if (_local) {
      SQLiteDatabase db = this.getReadableDatabase();
      List<Players> players = new ArrayList<Players>();
      String selectPlayerQuery = "SELECT * FROM " + TABLE_PLAYERS;

      Log.i(LOG, selectPlayerQuery);

      Cursor c = db.rawQuery(selectPlayerQuery, null);

      if (c != null && c.moveToFirst()) {

        do {
          // create the instance of Players using cursor information
          Players player = new Players();
          player.setpid(c.getLong(c.getColumnIndex(KEY_P_ID)));
          player.settid(c.getLong(c.getColumnIndex(KEY_T_ID)));
          player.setpname((c.getString(c.getColumnIndex(KEY_P_NAME))));
          player.setpnum((c.getInt(c.getColumnIndex(KEY_P_NUM))));

          // adding to players list
          players.add(player);
        } while (c.moveToNext());
      }
      return players;
    } else {
      return _net.getAllPlayers();
    }
  }
Exemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_team);

    _playerList = (LinearLayout) findViewById(R.id.playerList);
    findViewById(R.id.addPlayer).setOnClickListener(addPlayerListener);
    findViewById(R.id.editPlayer).setOnClickListener(editPlayerListener);
    findViewById(R.id.deletePlayer).setOnClickListener(deletePlayerListener);
    findViewById(R.id.confirmTeam).setOnClickListener(confirmTeamListener);

    String teamEditor = getIntent().getStringExtra(StaticFinalVars.CREATE_EDIT);
    _sportType = getIntent().getStringExtra(StaticFinalVars.SPORT_TYPE);
    _loggedIn = getIntent().getBooleanExtra(StaticFinalVars.LOGIN_STATUS, false);

    // databases
    if (_sportType.equals("basketball")) {
      _db = new BasketballDatabaseHelper(this);
    } else if (_sportType.equals("soccer")) {
      _db = new SoccerDatabaseHelper(this);
    } else if (_sportType.equals("hockey")) {
      _db = new HockeyDatabaseHelper(this);
    } else if (_sportType.equals("football")) {
      _db = new FootballDatabaseHelper(this);
    }

    if (!teamEditor.equals("")) {
      _editing = true;

      // Pull info from database and add to scroll view
      ArrayList<Teams> teams = (ArrayList<Teams>) _db.getAllTeams();
      for (Teams t : teams) {
        if (t.gettname().equals(teamEditor)) {
          _curTeam = t;
          t_id = _curTeam.gettid();
          break;
        }
      }

      // pull abbr and coach name
      ((EditText) findViewById(R.id.teamNameEditText)).setText(teamEditor);
      ((EditText) findViewById(R.id.teamAbbrEditText)).setText(_curTeam.getabbv());
      ((EditText) findViewById(R.id.coachNameEditText)).setText(_curTeam.getcname());

      // get List of players on curTeam from database
      ArrayList<Players> players = (ArrayList<Players>) _db.getPlayersTeam2(t_id);
      // add players names and numbers to view
      for (Players p : players) {
        _playerList.addView(newPlayerItem(p.getpname(), ((Integer) p.getpnum()).toString()));
      }

      _oldTeamName = teamEditor;
    }
  }
Exemplo n.º 3
0
  public int updatePlayer(Players player) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_T_ID, player.gettid());
    values.put(KEY_P_NAME, player.getpname());
    values.put(KEY_P_NUM, player.getpnum());
    if (!_local) {
      _net.updatePlayer(player);
    }
    return db.update(
        TABLE_PLAYERS, values, KEY_P_ID + " = ?", new String[] {String.valueOf(player.getpid())});
  }
Exemplo n.º 4
0
 @Override
 public void onClick(View view) {
   if (_viewSelected != null) {
     ArrayList<Players> players = (ArrayList<Players>) _db.getPlayersTeam2(t_id);
     Players curPlayer = null;
     String oldPName =
         ((TextView) ((LinearLayout) _viewSelected).getChildAt(1)).getText().toString();
     for (Players p : players) {
       if (oldPName.equals(p.getpname())) {
         curPlayer = p;
         break;
       }
     }
     _db.deletePlayer(curPlayer.getpid());
     _playerList.removeView(_viewSelected);
     _viewSelected = null;
   }
 }
  public long createGame(Games game) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_HOME_ID, game.gethomeid());
    values.put(KEY_AWAY_ID, game.getawayid());
    values.put(KEY_DATE, game.getDate());

    values.put(KEY_HOME_SHOTS, 0);
    values.put(KEY_HOME_SOG, 0);
    values.put(KEY_HOME_GOALS, 0);
    values.put(KEY_HOME_AST, 0);
    values.put(KEY_HOME_PEN_MINOR, 0);
    values.put(KEY_HOME_PEN_MAJOR, 0);
    values.put(KEY_HOME_PEN_MISCONDUCT, 0);
    values.put(KEY_HOME_SAVES, 0);
    values.put(KEY_HOME_GOALS_ALLOWED, 0);

    values.put(KEY_AWAY_SHOTS, 0);
    values.put(KEY_AWAY_SOG, 0);
    values.put(KEY_AWAY_GOALS, 0);
    values.put(KEY_AWAY_AST, 0);
    values.put(KEY_AWAY_PEN_MINOR, 0);
    values.put(KEY_AWAY_PEN_MAJOR, 0);
    values.put(KEY_AWAY_PEN_MISCONDUCT, 0);
    values.put(KEY_AWAY_SAVES, 0);
    values.put(KEY_AWAY_GOALS_ALLOWED, 0);

    // insert row
    long g_id = db.insert(TABLE_GAMES, null, values);

    List<Players> home_players = getPlayersTeam(game.gethomeid());
    List<Players> away_players = getPlayersTeam(game.getawayid());

    for (Players player : home_players) {
      createGameStats(player.getpid(), g_id);
    }
    for (Players player : away_players) {
      createGameStats(player.getpid(), g_id);
    }

    return g_id;
  }
  @SuppressWarnings("unchecked")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stats);

    _team = (Teams) getIntent().getSerializableExtra(StaticFinalVars.TEAM_INFO);
    _players = (ArrayList<Players>) getIntent().getSerializableExtra(StaticFinalVars.PLAYERS_INFO);
    g_id = (Long) getIntent().getSerializableExtra(StaticFinalVars.GAME_ID);
    _name = getIntent().getStringExtra(StaticFinalVars.PLAYER_NAME);
    _home = getIntent().getBooleanExtra(StaticFinalVars.HOME_OR_AWAY, true);
    _shots =
        (ArrayList<ShotChartCoords>) getIntent().getSerializableExtra(StaticFinalVars.SHOT_CHART);
    // NEW
    _hockey_db = new HockeyDatabaseHelper(HockeyIndividualStatActivity.this);

    _player = getIntent().getStringExtra(StaticFinalVars.PLAYER);
    _team2 = (Teams) getIntent().getSerializableExtra(StaticFinalVars.TEAM_INFO2);
    // AVE
    _games = (ArrayList<BasketballGames>) getIntent().getSerializableExtra(StaticFinalVars.GAMES);
    _average = getIntent().getBooleanExtra(StaticFinalVars.AVERAGE, false);

    if (_name != null) {
      if (_shots.isEmpty() && !_name.equals(_team.getabbv() + " Stats")) {
        _shots = (ArrayList<ShotChartCoords>) _hockey_db.getAllTeamShotsGame(_team.gettid(), g_id);
      } else if (_shots.isEmpty() && !_name.equals(_team2.getabbv() + " Stats")) {
        _shots = (ArrayList<ShotChartCoords>) _hockey_db.getAllTeamShotsGame(_team2.gettid(), g_id);
      } else if (_shots.isEmpty() && !_name.equals("All Players")) {
        Players p2 = null;
        for (Players p : _players) {
          if (p.getpname().equals(_name)) {
            p2 = p;
            break;
          }
        }
        long t_id = -1;
        if (p2.gettid() == _team.gettid()) {
          t_id = _team.gettid();
        } else if (p2.gettid() == _team2.gettid()) {
          t_id = _team2.gettid();
        }
        _shots = (ArrayList<ShotChartCoords>) _hockey_db.getAllTeamShotsGame(t_id, g_id);
      }
    }
    if (_player != null) {
      if (_shots.isEmpty() && !_player.equals("All Players")) {
        Players p2 = null;
        for (Players p : _players) {
          if (p.getpname().equals(_player)) {
            p2 = p;
            break;
          }
        }
        long t_id = -1;
        if (p2.gettid() == _team.gettid()) {
          t_id = _team.gettid();
        } else if (p2.gettid() == _team2.gettid()) {
          t_id = _team2.gettid();
        }
        _shots = (ArrayList<ShotChartCoords>) _hockey_db.getAllTeamShotsGame(t_id, g_id);
      }
    }

    // END NEW
    _gameInfo = (GameInfo) getIntent().getSerializableExtra(StaticFinalVars.GAME_INFO);
    int value = getIntent().getIntExtra(StaticFinalVars.DISPLAY_TYPE, 0);

    _hockey_db = new HockeyDatabaseHelper(getApplicationContext());
    _game = (HockeyGames) _hockey_db.getGame(g_id);

    _pager = (ViewPager) findViewById(R.id.statsPager);
    if (_average) {
      _pagerAdapter = new HockeyIndividualStatPageAdapter(getSupportFragmentManager(), 1);
    } else {
      _pagerAdapter = new HockeyIndividualStatPageAdapter(getSupportFragmentManager(), 2);
    }
    _pager.setAdapter(_pagerAdapter);
    _pager.setCurrentItem(value);
  }