mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-25 17:42:29 +02:00
Add support to send arbitrary messages to openScale user.
This can be used to send any string with an argument which will be string.format() replaced.
This commit is contained in:
@@ -35,7 +35,9 @@ import java.util.Queue;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class BluetoothCommunication {
|
public abstract class BluetoothCommunication {
|
||||||
public enum BT_STATUS_CODE {BT_RETRIEVE_SCALE_DATA, BT_INIT_PROCESS, BT_CONNECTION_ESTABLISHED, BT_CONNECTION_LOST, BT_NO_DEVICE_FOUND, BT_UNEXPECTED_ERROR };
|
public enum BT_STATUS_CODE {BT_RETRIEVE_SCALE_DATA, BT_INIT_PROCESS, BT_CONNECTION_ESTABLISHED,
|
||||||
|
BT_CONNECTION_LOST, BT_NO_DEVICE_FOUND, BT_UNEXPECTED_ERROR, BT_SCALE_MESSAGE
|
||||||
|
};
|
||||||
public enum BT_MACHINE_STATE {BT_INIT_STATE, BT_CMD_STATE, BT_CLEANUP_STATE}
|
public enum BT_MACHINE_STATE {BT_INIT_STATE, BT_CMD_STATE, BT_CLEANUP_STATE}
|
||||||
|
|
||||||
protected Context context;
|
protected Context context;
|
||||||
@@ -125,6 +127,16 @@ public abstract class BluetoothCommunication {
|
|||||||
callbackBtHandler.obtainMessage(BT_STATUS_CODE.BT_RETRIEVE_SCALE_DATA.ordinal(), scaleData).sendToTarget();
|
callbackBtHandler.obtainMessage(BT_STATUS_CODE.BT_RETRIEVE_SCALE_DATA.ordinal(), scaleData).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send message to openScale user
|
||||||
|
*
|
||||||
|
* @param msg the string id to be send
|
||||||
|
* @param value the value to be used
|
||||||
|
*/
|
||||||
|
protected void sendMessage(int msg, Object value) {
|
||||||
|
callbackBtHandler.obtainMessage(BT_STATUS_CODE.BT_SCALE_MESSAGE.ordinal(), msg, 0, value).sendToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the Bluetooth initialized process supported.
|
* Is the Bluetooth initialized process supported.
|
||||||
*
|
*
|
||||||
|
@@ -244,6 +244,10 @@ public class MainActivity extends ActionBarActivity implements
|
|||||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_connection_error) + ": " + msg.obj, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_connection_error) + ": " + msg.obj, Toast.LENGTH_SHORT).show();
|
||||||
Log.e("OpenScale", "Bluetooth unexpected error: " + msg.obj);
|
Log.e("OpenScale", "Bluetooth unexpected error: " + msg.obj);
|
||||||
break;
|
break;
|
||||||
|
case BT_SCALE_MESSAGE:
|
||||||
|
String toastMessage = String.format(getResources().getString(msg.arg1), msg.obj);
|
||||||
|
Toast.makeText(getApplicationContext(), toastMessage, Toast.LENGTH_LONG).show();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user