Android Open Source - hackfmi-ragdoll-physics Menu Activity






From Project

Back to project page hackfmi-ragdoll-physics.

License

The source code is released under:

GNU General Public License

If you think the Android project hackfmi-ragdoll-physics 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.midtownmadness.bubblecombat;
//w w  w  .  j a  v a 2 s.  com
import static com.midtownmadness.bubblecombat.Settings.EXTRA_SYNC_STAMP;

import java.io.IOException;

import junit.framework.Assert;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

import com.midtownmadness.bubblecombar.listeners.GameRoomListener;
import com.midtownmadness.bubblecombat.multiplay.MultiplayEvent;
import com.midtownmadness.bubblecombat.multiplay.MultiplayEventListener;
import com.midtownmadness.bubblecombat.multiplay.MultiplayManager;
import com.midtownmadness.bubblecombat.multiplay.MultiplayerGame;
import com.midtownmadness.bubblecombat.views.MenuView;

public class MenuActivity extends BaseActivity implements OnClickListener,
    MultiplayEventListener, GameRoomListener {

  private static final int REQUEST_CODE_BLUETOOTH_VISIBILITY = 0xFACE;

  private MultiplayManager multiplayManager;

  private BluetoothGamesAdapter gameAdapter;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    gameAdapter = new BluetoothGamesAdapter(this, -1);
    gameAdapter.setGameRoomListener(this);
    setContentView(new MenuView(this, this, gameAdapter));

    multiplayManager = (MultiplayManager) getSystemService(MultiplayManager.SERVICE_NAME);
    Assert.assertNotNull(multiplayManager);

    multiplayManager.addListener(this);
//    multiplayManager.searchForGames();
  }

  @Override
  public void onClick(View v) {
    switch (v.getId()) {
    case R.id.host_button:
      host();
      break;
    case R.id.quit_button:
      finish();
      break;
    case R.id.refresh_button:
      refresh();
      break;
    default:
      break;
    }
  }

  private void refresh() {
    multiplayManager.searchForGames();
  }

  private void host() {
    Intent getVisible = new Intent(
        BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    startActivityForResult(getVisible, REQUEST_CODE_BLUETOOTH_VISIBILITY);
  }

  private void play() {
    final Intent playIntent = new Intent(getApplicationContext(),
        GameActivity.class);
    startActivity(playIntent);
  }

  @Override
  public void onMultiplayEvent(final MultiplayEvent e, final int playerId) {
  }

  @Override
  public void onPlayerConnected(int playerId) {

  }

  @Override
  public void onGameDiscovered(final MultiplayerGame multiplayerGame) {
    runOnUiThread(new Runnable() {

      @Override
      public void run() {
        Toast.makeText(MenuActivity.this, multiplayerGame.toString(),
            Toast.LENGTH_LONG).show();
        gameAdapter.add(multiplayerGame);
        gameAdapter.notifyDataSetChanged();
      }
    });
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_BLUETOOTH_VISIBILITY) {
      if (resultCode > 0) {
        doHost();
      } else {
        toast("User has denied bluetooth hosting");
      }
    }
    super.onActivityResult(requestCode, resultCode, data);
  }

  private void doHost() {
    try {
      toast("Hosting game ");
      multiplayManager.host();
    } catch (IOException e) {
      e.printStackTrace();
      toast("Hosting has fucked up");
    }
  }

  @Override
  public void onGameSelected(MultiplayerGame model) {
    Toast.makeText(this, "Game connected " + model.toString(),
        Toast.LENGTH_SHORT).show();

    multiplayManager.joinGame();
  }

  @Override
  public void onGameSynced(MultiplayerGame game) {

  }

  @Override
  public void finish() {
    super.onGameClose();
    super.finish();
  }

  @Override
  public void onGameCommenced(final long syncStamp) {
    runOnUiThread(new Runnable() {
      @Override
      public void run() {
        final Intent gameIntent = new Intent(getApplicationContext(),
            GameActivity.class);

        gameIntent.putExtra(EXTRA_SYNC_STAMP, syncStamp);
        startActivity(gameIntent);
      }
    });
  }

  @Override
  public void onError() {
    toast(R.string.error_text);
    finish();
  }

}




Java Source Code List

com.midtownmadness.bubblecombar.listeners.GameRoomListener.java
com.midtownmadness.bubblecombar.model.GameModel.java
com.midtownmadness.bubblecombar.model.GamesAdapter.java
com.midtownmadness.bubblecombar.model.MockAdapter.java
com.midtownmadness.bubblecombat.BaseActivity.java
com.midtownmadness.bubblecombat.BluetoothGamesAdapter.java
com.midtownmadness.bubblecombat.GameActivity.java
com.midtownmadness.bubblecombat.GameView.java
com.midtownmadness.bubblecombat.GlobalContext.java
com.midtownmadness.bubblecombat.MenuActivity.java
com.midtownmadness.bubblecombat.MockMultiplayerGame.java
com.midtownmadness.bubblecombat.Settings.java
com.midtownmadness.bubblecombat.game.DrawThread.java
com.midtownmadness.bubblecombat.game.GameObject.java
com.midtownmadness.bubblecombat.game.GameWallObject.java
com.midtownmadness.bubblecombat.game.LevelObject.java
com.midtownmadness.bubblecombat.game.PlayerObject.java
com.midtownmadness.bubblecombat.multiplay.BaseStrategy.java
com.midtownmadness.bubblecombat.multiplay.BluetoothConnectException.java
com.midtownmadness.bubblecombat.multiplay.BluetoothMessage.java
com.midtownmadness.bubblecombat.multiplay.Callback.java
com.midtownmadness.bubblecombat.multiplay.ClientStrategy.java
com.midtownmadness.bubblecombat.multiplay.HostStrategy.java
com.midtownmadness.bubblecombat.multiplay.LoggingListener.java
com.midtownmadness.bubblecombat.multiplay.LooperThread.java
com.midtownmadness.bubblecombat.multiplay.MessageType.java
com.midtownmadness.bubblecombat.multiplay.MultiplayEventListener.java
com.midtownmadness.bubblecombat.multiplay.MultiplayEvent.java
com.midtownmadness.bubblecombat.multiplay.MultiplayManager.java
com.midtownmadness.bubblecombat.multiplay.MultiplayStrategy.java
com.midtownmadness.bubblecombat.multiplay.MultiplayUtil.java
com.midtownmadness.bubblecombat.multiplay.MultiplayerGame.java
com.midtownmadness.bubblecombat.multiplay.commobjects.GoMessageObject.java
com.midtownmadness.bubblecombat.physics.BodyCreationRequest.java
com.midtownmadness.bubblecombat.physics.BodyUserData.java
com.midtownmadness.bubblecombat.physics.CentralHurdle.java
com.midtownmadness.bubblecombat.physics.CollisionListener.java
com.midtownmadness.bubblecombat.physics.DefaultLevelBuilder.java
com.midtownmadness.bubblecombat.physics.LevelBuilder.java
com.midtownmadness.bubblecombat.physics.MovementRequest.java
com.midtownmadness.bubblecombat.physics.MovementStateRequest.java
com.midtownmadness.bubblecombat.physics.PhysicsRequest.java
com.midtownmadness.bubblecombat.physics.PhysicsService.java
com.midtownmadness.bubblecombat.views.MenuGameView.java
com.midtownmadness.bubblecombat.views.MenuView.java