Пример #1
0
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
      case ConnectionHandler.REQUEST_ENABLE_BT:
        {
          if (resultCode == Activity.RESULT_OK) {
            Toast.makeText(this, "Successfully enabled bluetooth.", Toast.LENGTH_SHORT).show();
            btHandler.onBtEnabled();
          } else {
            Toast.makeText(
                    this,
                    "Could not enable bluetooth, War Yachts will now exit.",
                    Toast.LENGTH_LONG)
                .show();
            btHandler.reset();
            finish();
          }
          break;
        }
      case ConnectionHandler.REQUEST_ENABLE_DISCOVERY:
        {
          if (resultCode == ConnectionHandler.DEFAULT_DISCOVERY_TIME) {
            // Notify the user that discovery was enabled,
            Toast.makeText(
                    this,
                    "Successfully enabled discovery, waiting for connection",
                    Toast.LENGTH_SHORT)
                .show();
            // Set up connection listener in ConnectionHandler
            btHandler.onDiscoveryEnabled();
            // Create game for when a connection is established
            prepareHostGameInstanceCallback.onCallback();
          } else {
            Toast.makeText(
                    this,
                    "Could not enable discovery. Try searching instead of hosting.",
                    Toast.LENGTH_SHORT)
                .show();
            btHandler.reset();
          }
          break;
        }
      default:
        {
          // We obviously don't know what this is about, maybe someone
          // above does

          // TAKE ME OUT
          // HOW TO PRINT TO SCREEN
          Toast.makeText(
                  getBaseContext(),
                  "UNHANDLED REQUEST CODE, WE SHOULD NOT BE HERE!",
                  Toast.LENGTH_SHORT)
              .show();

          super.onActivityResult(requestCode, resultCode, data);
        }
    }
  }
Пример #2
0
  // Called when user pushes the back button
  @Override
  public void onBackPressed() {
    // Reset busy and stop performing connection activities
    btHandler.reset();

    // If the scenario doesn't handle back presses, pass it up
    if (currentScenario == null || !currentScenario.handleBackPress()) super.onBackPressed();
  }
Пример #3
0
 @Override
 public void onCallback() {
   btHandler.reset();
   nextScenario =
       new StartMenuScenario(
           WarYachtsActivity.this, startMenuScene, prepareLoadGameInstanceCallback);
   transitionHandler =
       new ComposedTransitionHandler(
           WarYachtsActivity.this,
           camera,
           currentScenario,
           nextScenario,
           switchScenarioCallback);
 }
Пример #4
0
 @Override
 public void onCallback() {
   btHandler.listen();
   nextScenario =
       new GameInstanceScenario(
           WarYachtsActivity.this,
           gameInstanceScene,
           prepareStartMenuCallback,
           prepareVictoryCallback,
           prepareDefeatCallback,
           btHandler,
           false,
           false);
   transitionHandler =
       new ComposedTransitionHandler(
           WarYachtsActivity.this,
           camera,
           currentScenario,
           nextScenario,
           switchScenarioCallback);
 }