Beispiel #1
0
 /**
  * Handles what happens when user clicks the login button
  *
  * @param view Button that is pressed
  */
 public void loginButton(final View view) {
   // Try to login
   String usernameString;
   try {
     usernameString = lp.loginButton();
   } catch (InternetConnectionException e) {
     e.fillInStackTrace();
     Log.i("Leaderboard", "triggering internet connection error screen");
     Intent intent = new Intent(this, ErrorScreen.class);
     intent.putExtra("error", R.layout.activity_connection_error_lb);
     startActivity(intent);
     return;
   }
   // If login was successful, go to the multiplayer game
   if (!usernameString.equals("")) {
     exitLoginPopup(view);
     relativeUserScore();
   }
 }
Beispiel #2
0
  /**
   * Called when the user wants to view his/her score relative to other players
   *
   * @param view the button clicked
   */
  public void relativeUserScore() {
    // set up the Parse database and have the user log in if not already
    currentUser = ParseUser.getCurrentUser();
    if (currentUser == null) {
      Log.i("Leaderboard", "user begins logging in");
      buildPopup(false);
    } else {
      Log.i("Leaderboard", "user is logged in");

      // make a new MultiLeaderBoardModel with the given username
      try {
        mlb.setPlayer(currentUser.getString("username"));
      } catch (InternetConnectionException e) {
        e.fillInStackTrace();
        Log.i("Leaderboard", "triggering internet connection error screen");
        Intent intent = new Intent(this, ErrorScreen.class);
        intent.putExtra("error", R.layout.activity_connection_error_lb);
        startActivity(intent);
        return;
      }
      int userRank = mlb.getRank();
      // inform the user that he/she has no scores yet

      if (userRank <= 0) {
        InterfaceUtils.buildAlertDialog(this, R.string.no_scores_title, R.string.no_scores_msg);
        return;
      }
      int highestRank = mlb.getHighestRelScoreRank();
      // get the relative position of the user with the passed in NUM_RELATIVE
      ScoreEntry[] relativeEntrys = mlb.getRelativeScores();

      // add the relativeScore tab
      Fragment currentFragment =
          RelativeUserScoreTab.newInstance(relativeEntrys, userRank, highestRank);
      FragmentTransaction fst = getSupportFragmentManager().beginTransaction();
      fst.replace(R.id.leaderboard_layout, currentFragment);
      fst.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
      fst.commit();
    }
  }
Beispiel #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    Log.i("Leaderboard", "entered leaderboard");

    // set the layout for the parent activity which contains the fragments
    setContentView(R.layout.activity_leaderboard);

    // Initialize the database according to whether it's a test or not.
    Log.d("Leaderboard: Using Test Database", "" + TitlePage.useTestDB);
    if (TitlePage.useTestDB) { // The Testing Database on Parse
      Parse.initialize(
          this,
          "E8hfMLlgnEWvPw1auMOvGVsrTp1C6eSoqW1s6roq",
          "hzPRfP284H5GuRzIFDhVxX6iR9sgTwg4tJU08Bez");
    } else { // The Real App Database on Parse
      Parse.initialize(
          this,
          "Iy4JZxlewoSxswYgOEa6vhOSRgJkGIfDJ8wj8FtM",
          "SVlq5dqYQ4FemgUfA7zdQvdIHOmKBkc5bXoI7y0C");
    }

    lp = new LoginPopup(currentUser);

    // set up the action bar for the different tabs
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.Tab singlePlayerTab = actionBar.newTab().setText(R.string.single_player_tab);
    ActionBar.Tab multiPlayerTab = actionBar.newTab().setText(R.string.multi_player_tab);
    ActionBar.Tab relativeUserScoreTab = actionBar.newTab().setText(R.string.relative_tab);

    // get the list of scores from the model and send it to each of the tabs

    lb = new SingleLeaderBoardModel(getApplicationContext());
    try {
      mlb = new MultiLeaderBoardModel();
    } catch (InternetConnectionException e) {
      e.fillInStackTrace();
      Log.i("Leaderboard", "triggering internet connection error screen");
      Intent intent = new Intent(this, ErrorScreen.class);
      intent.putExtra("error", R.layout.activity_connection_error_lb);
      startActivity(intent);
      return;
    }

    // need to get the username to pass into the leaderboard
    Fragment singlePlayerFragment = SingleplayerTab.newInstance(lb.getTopScores());
    Fragment multiPlayerFragment = MultiplayerTab.newInstance("", mlb.getTopScores());
    Fragment relativeUserScoreFragment = RelativeUserScoreTab.emptyNewInstance();

    singlePlayerTab.setTabListener(new LBTabListener(singlePlayerFragment, "singleplayer"));
    multiPlayerTab.setTabListener(new LBTabListener(multiPlayerFragment, "multiplayer"));
    relativeUserScoreTab.setTabListener(new LBTabListener(relativeUserScoreFragment, "relative"));

    actionBar.addTab(singlePlayerTab);
    actionBar.addTab(multiPlayerTab);
    actionBar.addTab(relativeUserScoreTab);
  }