コード例 #1
0
  @Override
  protected void onResume() {
    super.onResume();

    // Performing this check in onResume() covers the case in which BT was
    // not enabled during onStart(), so we were paused to enable it...
    // onResume() will be called when ACTION_REQUEST_ENABLE activity returns.
    if (mCommandService != null) {
      if (mCommandService.getState() == BluetoothCommandService.STATE_NONE) {
        mCommandService.start();
      }
    }
  }
コード例 #2
0
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   switch (requestCode) {
     case REQUEST_CONNECT_DEVICE:
       // When DeviceListActivity returns with a device to connect
       if (resultCode == Activity.RESULT_OK) {
         // Get the device MAC address
         String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
         // Get the BLuetoothDevice object
         BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
         // Attempt to connect to the device
         mCommandService.connect(device);
         arrayPlayer.clear();
         arrayAdapter.clear();
         arrayAdapter.notifyDataSetChanged();
       }
       break;
     case REQUEST_ENABLE_BT:
       // When the request to enable Bluetooth returns
       if (resultCode == Activity.RESULT_OK) {
         // Bluetooth is now enabled, so set up a chat session
         setupCommand();
       } else {
         // User did not enable Bluetooth or an error occured
         Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show();
         finish();
       }
   }
 }
コード例 #3
0
 private void sendStartGame() {
   JSONObject jObject = new JSONObject();
   try {
     jObject.put("message", GlobalVariables.START);
     JSONObject JsonO = null;
     jObject.put("Data", JsonO);
     mCommandService.write(jObject.toString().getBytes());
   } catch (JSONException e) {
     e.printStackTrace();
   }
 }
コード例 #4
0
 private void sendJoinGame(String nameClient) {
   JSONObject jObject = new JSONObject();
   try {
     jObject.put("message", GlobalVariables.JOIN_CLIENT);
     JSONObject jsonO = new JSONObject();
     jsonO.put("JoinServer", nameClient);
     jObject.put("Data", jsonO);
     mCommandService.write(jObject.toString().getBytes());
   } catch (JSONException e) {
     e.printStackTrace();
   }
 }
コード例 #5
0
 private void sendServerCreate(String nameServer) {
   JSONObject jObject = new JSONObject();
   try {
     jObject.put("message", GlobalVariables.SERVER_CREATE);
     JSONObject ob = new JSONObject();
     ob.put("ServerCreate", nameServer);
     jObject.put("Data", ob);
     mCommandService.write(jObject.toString().getBytes());
   } catch (JSONException e) {
     e.printStackTrace();
   }
 }
コード例 #6
0
 private void sendMapIndex(int mapIndex) {
   JSONObject jObject = new JSONObject();
   try {
     jObject.put("message", GlobalVariables.MAPS);
     JSONObject JsonO = new JSONObject();
     JsonO.put("MapIndex", mapIndex);
     jObject.put("Data", JsonO);
     mCommandService.write(jObject.toString().getBytes());
   } catch (JSONException e) {
     e.printStackTrace();
   }
 }
コード例 #7
0
  @Override
  protected void onDestroy() {
    super.onDestroy();

    if (mCommandService != null) mCommandService.stop();
  }