Java Code Examples for app.akexorcist.bluetotohspp.library.BluetoothSPP

The following examples show how to use app.akexorcist.bluetotohspp.library.BluetoothSPP. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Chorus-RF-Laptimer   Source File: BTService.java    License: MIT License 6 votes vote down vote up
@Override
public void setConnectionListener(final ConnectionListener listener) {
    mBT.setBluetoothConnectionListener(new BluetoothSPP.BluetoothConnectionListener() {
        @Override
        public void onDeviceConnected(String name, String address) {
            listener.onConnected(name);
        }

        @Override
        public void onDeviceDisconnected() {
            listener.onDisconnected();
        }

        @Override
        public void onDeviceConnectionFailed() {
            listener.onConnectionFailed("");
        }
    });

    mBT.setOnDataReceivedListener(new BluetoothSPP.OnDataReceivedListener() {
        @Override
        public void onDataReceived(byte[] data, String message) {
            listener.onDataReceived(message);
        }
    });
}
 
Example 2
Source Project: BluetoothSPPLibrary   Source File: DeviceListActivity.java    License: Apache License 2.0 5 votes vote down vote up
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_devicelist);

    bt = new BluetoothSPP(this);

    if(!bt.isBluetoothAvailable()) {
        Toast.makeText(getApplicationContext()
                , "Bluetooth is not available"
                , Toast.LENGTH_SHORT).show();
        finish();
    }

    bt.setOnDataReceivedListener(new OnDataReceivedListener() {
        public void onDataReceived(byte[] data, String message) {
            Log.i("Check", "Length : " + data.length);
            Log.i("Check", "Message : " + message);
        }
    });

    Button btnConnect = (Button)findViewById(R.id.btnConnect);
    btnConnect.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
            if(bt.getServiceState() == BluetoothState.STATE_CONNECTED) {
                bt.disconnect();
            } else {
                Intent intent = new Intent(DeviceListActivity.this, DeviceList.class);
                intent.putExtra("bluetooth_devices", "Bluetooth devices");
                intent.putExtra("no_devices_found", "No device");
                intent.putExtra("scanning", "Scanning");
                intent.putExtra("scan_for_devices", "Search");
                intent.putExtra("select_device", "Select");
                intent.putExtra("layout_list", R.layout.device_layout_list);
                intent.putExtra("layout_text", R.layout.device_layout_text);
                startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE);
            }
        }
    });
}
 
Example 3
Source Project: Chorus-RF-Laptimer   Source File: BTService.java    License: MIT License 4 votes vote down vote up
BTService(Context context, byte delimiter) {
    mBT = new BluetoothSPP(context, delimiter);
}
 
Example 4
Source Project: Chorus-RF-Laptimer   Source File: BTService.java    License: MIT License 4 votes vote down vote up
void setDataReceiveListener(BluetoothSPP.OnDataReceivedListener listener) {
    mBT.setOnDataReceivedListener(listener);
}
 
Example 5
Source Project: Chorus-RF-Laptimer   Source File: BTService.java    License: MIT License 4 votes vote down vote up
void setConnectionListener(BluetoothSPP.BluetoothConnectionListener listener) {
    mBT.setBluetoothConnectionListener(listener);
}
 
Example 6
Source Project: Droid2JoyStick   Source File: BluetoothManager.java    License: Apache License 2.0 4 votes vote down vote up
public BluetoothManager(Context context) {
    bt = new BluetoothSPP(context);
}
 
Example 7
Source Project: BluetoothSPPLibrary   Source File: SimpleActivity.java    License: Apache License 2.0 4 votes vote down vote up
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_simple);
	
	bt = new BluetoothSPP(this);

	if(!bt.isBluetoothAvailable()) {
		Toast.makeText(getApplicationContext()
				, "Bluetooth is not available"
				, Toast.LENGTH_SHORT).show();
           finish();
	}
	
	bt.setOnDataReceivedListener(new OnDataReceivedListener() {
		public void onDataReceived(byte[] data, String message) {
			Toast.makeText(SimpleActivity.this, message, Toast.LENGTH_SHORT).show();
		}
	});
	
	bt.setBluetoothConnectionListener(new BluetoothConnectionListener() {
		public void onDeviceConnected(String name, String address) {
			Toast.makeText(getApplicationContext()
					, "Connected to " + name + "\n" + address
					, Toast.LENGTH_SHORT).show();
		}

		public void onDeviceDisconnected() {
			Toast.makeText(getApplicationContext()
					, "Connection lost", Toast.LENGTH_SHORT).show();
		}

		public void onDeviceConnectionFailed() {
			Toast.makeText(getApplicationContext()
					, "Unable to connect", Toast.LENGTH_SHORT).show();
		}
	});
	
	Button btnConnect = (Button)findViewById(R.id.btnConnect);
	btnConnect.setOnClickListener(new OnClickListener(){
       	public void onClick(View v){
       		if(bt.getServiceState() == BluetoothState.STATE_CONNECTED) {
       			bt.disconnect();
       		} else {
                   Intent intent = new Intent(getApplicationContext(), DeviceList.class);
                   startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE); 
       		}
       	}
       }); 
}
 
Example 8
Source Project: BluetoothSPPLibrary   Source File: TerminalActivity.java    License: Apache License 2.0 4 votes vote down vote up
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_terminal);
    Log.i("Check", "onCreate");

    textRead = (TextView)findViewById(R.id.textRead);
    textStatus = (TextView)findViewById(R.id.textStatus);
    etMessage = (EditText)findViewById(R.id.etMessage);

    bt = new BluetoothSPP(this);

    if(!bt.isBluetoothAvailable()) {
        Toast.makeText(getApplicationContext()
                , "Bluetooth is not available"
                , Toast.LENGTH_SHORT).show();
        finish();
    }

    bt.setOnDataReceivedListener(new OnDataReceivedListener() {
        public void onDataReceived(byte[] data, String message) {
            textRead.append(message + "\n");
        }
    });

    bt.setBluetoothConnectionListener(new BluetoothConnectionListener() {
        public void onDeviceDisconnected() {
            textStatus.setText("Status : Not connect");
            menu.clear();
            getMenuInflater().inflate(R.menu.menu_connection, menu);
        }

        public void onDeviceConnectionFailed() {
            textStatus.setText("Status : Connection failed");
        }

        public void onDeviceConnected(String name, String address) {
            textStatus.setText("Status : Connected to " + name);
            menu.clear();
            getMenuInflater().inflate(R.menu.menu_disconnection, menu);
        }
    });
}