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

The following examples show how to use app.akexorcist.bluetotohspp.library.DeviceList. 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: MainActivity.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    Handler delayedDisconnect = new Handler() {
        public void handleMessage(Message msg) {
            if (AppState.getInstance().conn != null) {
                AppState.getInstance().conn.disconnect();
            }
        }
    };

    switch (id) {
        case R.id.menuBTConnect:
            bt.setDeviceTarget(BluetoothState.DEVICE_OTHER);
            Intent intent = new Intent(getApplicationContext(), DeviceList.class);
            startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE);
            break;
        case R.id.menuUDPConnect:
            preferWifiAndConnectUDP();
            break;
        case R.id.menuUSBConnect:
            checkUSBPermissionsAndConnectIfAllowed();
            break;
        case R.id.menuDisconnect:
            AppState.getInstance().onBeforeDisconnect();
            delayedDisconnect.sendEmptyMessageDelayed(0, 100);
            break;
    }

    return super.onOptionsItemSelected(item);
}
 
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: Droid2JoyStick   Source File: BluetoothManager.java    License: Apache License 2.0 4 votes vote down vote up
public void openBluetoothConnection(Activity activity) {
    Intent intent = new Intent(activity, DeviceList.class);
    activity.startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE);
}
 
Example 4
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); 
       		}
       	}
       }); 
}