import android.content.Intent; import android.os.Bundle; import ketai.net.bluetooth.*; import ketai.ui.*; import ketai.net.*; PFont fontMy; KetaiBluetooth bt; KetaiList klist; boolean isConfiguring = true; String info = ""; int rectColFactor = 0; ArrayList devicesDiscovered = new ArrayList(); //******************************************************************** // The following code is required to enable bluetooth at startup. //******************************************************************** void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); bt = new KetaiBluetooth(this); } void onActivityResult(int requestCode, int resultCode, Intent data) { bt.onActivityResult(requestCode, resultCode, data); } void setup() { size(displayWidth, displayHeight); //frameRate(10); orientation(PORTRAIT); background(0); //start listening for BT connections bt.start(); //at app start select device… isConfiguring = true; //font size fontMy = createFont("SansSerif", 40); textFont(fontMy); } void draw() { //---------------------- At app start select device to connect to // If not BT is configured yet but in the process of configuration if (isConfiguring) { //-------------------- This stuff is for us to select the intended device // ketai lib's UI list is used ArrayList names; background(78, 93, 75); klist = new KetaiList(this, bt.getPairedDeviceNames()); isConfiguring = false; // make the "configuring" status false as we have successfully configured } else { //After configuration everything happens here //first set a new background to say we are connecetd background(150, 150, 150); fill(0); noStroke(); textAlign(LEFT); text(info, 100, 104); //fill(255, 23, 76, rectColFactor); //rect((displayWidth/2) - 200, (displayHeight/2) - 200, 400, 400); } } //------------------------ For killing the list after you've selected a device to pair void onKetaiListSelection(KetaiList klist) { String selection = klist.getSelection(); bt.connectToDeviceByName(selection); //dispose of list for now klist = null; } //------------------------ Call back method to manage data received void onBluetoothDataEvent(String who, byte[] data) { if (isConfiguring) { return; } //received info = new String(data); //rectColFactor = Integer.parseInt(info); }