Android Open Source - miner Connection Master






From Project

Back to project page miner.

License

The source code is released under:

Apache License

If you think the Android project miner 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.kolomiyets.miner.bt;
/*  ww  w .  j a v a  2 s. co  m*/
import java.io.IOException;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
import android.util.Log;

import com.kolomiyets.miner.Miner;
import com.kolomiyets.miner.bt.notification.NotificationManager;

public class ConnectionMaster extends ConnectionBase {

  String TAG = ConnectionMaster.class.getSimpleName();
  
  private BluetoothServerSocket mmServerSocket;
  
  public ConnectionMaster(NotificationManager notificationManager) {
    super(notificationManager);
  }

  @Override
  BluetoothSocket doConnection() {
    
    BluetoothSocket socket = null;
    
    BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
    try {
      mmServerSocket = bt.listenUsingInsecureRfcommWithServiceRecord(bt.getName(), MINER_UUID);
        } catch (IOException e) { 
          e.printStackTrace();
          return null;
        }
        
        bt.cancelDiscovery();
    
    int count = 5;
        while (count --> 0 
            && !Thread.currentThread().isInterrupted() 
            && mmServerSocket!=null) {
            try {
              if(Miner.D) Log.d(TAG, "listening for device to connect...");
                socket = mmServerSocket.accept();
                if (socket != null) {
                  break;
                }
            } catch (IOException e) {
              e.printStackTrace();
              if(Thread.currentThread().isInterrupted()) break;
            }
            
            if(Thread.currentThread().isInterrupted()) break;
            
            try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        break;
      }
        }
        
        return socket;
  }

  @Override
  void doDisconnection(ConnectionProcessor connectionProcessor) {
    if(Miner.D) Log.d(TAG, "terminating connection...");
    try {
      if(connectionProcessor!=null){
        final ConnectionProcessor _connectionProcessor = connectionProcessor;
        connectionProcessor = null;
        _connectionProcessor.stop();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    try {
      if(mmServerSocket!=null){
        final BluetoothServerSocket _mmServerSocket = mmServerSocket;
        mmServerSocket = null;
        _mmServerSocket.close();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

}




Java Source Code List

com.kolomiyets.miner.MinerActivity.java
com.kolomiyets.miner.Miner.java
com.kolomiyets.miner.bt.BtStateMonitor.java
com.kolomiyets.miner.bt.ConnectionBase.java
com.kolomiyets.miner.bt.ConnectionManager.java
com.kolomiyets.miner.bt.ConnectionMaster.java
com.kolomiyets.miner.bt.ConnectionProcessor.java
com.kolomiyets.miner.bt.ConnectionSlave.java
com.kolomiyets.miner.bt.EConnectMethod.java
com.kolomiyets.miner.bt.IBtEnableCallback.java
com.kolomiyets.miner.bt.IRequestBtResult.java
com.kolomiyets.miner.bt.notification.BtListener.java
com.kolomiyets.miner.bt.notification.BtNotificationCmd.java
com.kolomiyets.miner.bt.notification.BtNotificationConnect.java
com.kolomiyets.miner.bt.notification.BtNotificationDiscoveryDevice.java
com.kolomiyets.miner.bt.notification.BtNotificationDiscoveryState.java
com.kolomiyets.miner.bt.notification.BtNotificationDiscovery.java
com.kolomiyets.miner.bt.notification.BtNotificationHandshake.java
com.kolomiyets.miner.bt.notification.BtNotificationPower.java
com.kolomiyets.miner.bt.notification.BtNotificationState.java
com.kolomiyets.miner.bt.notification.BtNotification.java
com.kolomiyets.miner.bt.notification.EConnectionSate.java
com.kolomiyets.miner.bt.notification.NotificationManager.java
com.kolomiyets.miner.bt.protocol.CmdBase.java
com.kolomiyets.miner.bt.protocol.CmdFactory.java
com.kolomiyets.miner.bt.protocol.CmdFieldState.java
com.kolomiyets.miner.bt.protocol.CmdGameState.java
com.kolomiyets.miner.bt.protocol.CmdGameTeam.java
com.kolomiyets.miner.bt.protocol.CmdHandshake.java
com.kolomiyets.miner.bt.protocol.CmdPing.java
com.kolomiyets.miner.bt.protocol.CmdResponse.java
com.kolomiyets.miner.bt.protocol.ECmdName.java
com.kolomiyets.miner.bt.protocol.EGameState.java
com.kolomiyets.miner.dialog.DialogProvider.java
com.kolomiyets.miner.dialog.EDialogType.java
com.kolomiyets.miner.dialog.IDialogResult.java
com.kolomiyets.miner.screen.PlayGroundBase.java
com.kolomiyets.miner.screen.PlayGroundMiner.java
com.kolomiyets.miner.screen.PlayGroundSapper.java
com.kolomiyets.miner.screen.ScreenBase.java
com.kolomiyets.miner.screen.ScreenConnectingGame.java
com.kolomiyets.miner.screen.ScreenCreateGame.java
com.kolomiyets.miner.screen.ScreenDevices.java
com.kolomiyets.miner.screen.ScreenManager.java
com.kolomiyets.miner.screen.ScreenSelectPlayer.java
com.kolomiyets.miner.view.GridCell.java