Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case Constants.MESSAGE_STATE_CHANGE:
Log.d(TAG, "Change State");
switch (msg.arg1) {
case BluetoothService.STATE_CONNECTED:
Log.d(TAG, "Connected");
Toast.makeText(this, R.string.title_connected, Toast.LENGTH_SHORT).show();
break;
case BluetoothService.STATE_CONNECTING:
Log.d(TAG, "Connecting");
Toast.makeText(this, R.string.title_connecting, Toast.LENGTH_SHORT).show();
break;
case BluetoothService.STATE_LISTEN:
case BluetoothService.STATE_NONE:
Log.d(TAG, "Fail");
Toast.makeText(this, R.string.title_not_connected, Toast.LENGTH_SHORT).show();
break;
}
break;
case Constants.MESSAGE_READ:
Log.d(TAG, "Read");
process((byte[]) msg.obj, msg.arg1);
break;
case Constants.MESSAGE_DEVICE_NAME:
// save the connected device's name
connectedDeviceName = msg.getData().getString(Constants.DEVICE_NAME);
Toast.makeText(this, "Connected to "
+ connectedDeviceName, Toast.LENGTH_SHORT).show();
break;
}
return false;
}
private void process(byte[] rxPacket, int bytes) {
for(int i = 0; i < bytes; i++) {
switch(rxPacket[i]) {
case START_POINT:
rxFlag = true;
break;
case END_POINT:
rxFlag = false;
break;
default:
if(rxFlag) {
switch(rxPacket[i]) {
case 'H':
emotionView.setImageResource(R.drawable.figure_happy);
break;
case 'A':
emotionView.setImageResource(R.drawable.figure_angry);
break;
case 'D':
emotionView.setImageResource(R.drawable.figure_depressed);
break;
case 'R':
emotionView.setImageResource(R.drawable.figure_sleeping);
break;
case 'N':
emotionView.setImageResource(R.drawable.figure_standing);
break;
}
}
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment