use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.
the class ScreenshotRecorder method getTestUser.
private ScaleUser getTestUser() {
ScaleUser user = new ScaleUser();
user.setUserName("Test");
user.setBodyHeight(180);
user.setInitialWeight(80.0f);
user.setGoalWeight(60.0f);
Calendar birthday = Calendar.getInstance();
birthday.add(Calendar.YEAR, -28);
birthday.set(birthday.get(Calendar.YEAR), Calendar.JANUARY, 19, 0, 0, 0);
birthday.set(Calendar.MILLISECOND, 0);
user.setBirthday(birthday.getTime());
Calendar goalDate = Calendar.getInstance();
goalDate.add(Calendar.YEAR, 1);
goalDate.set(goalDate.get(Calendar.YEAR), Calendar.JANUARY, 31, 0, 0, 0);
goalDate.set(Calendar.MILLISECOND, 0);
user.setGoalDate(goalDate.getTime());
return user;
}
use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.
the class BluetoothMiScale method parseBytes.
private void parseBytes(byte[] weightBytes) {
try {
final byte ctrlByte = weightBytes[0];
final boolean isWeightRemoved = isBitSet(ctrlByte, 7);
final boolean isStabilized = isBitSet(ctrlByte, 5);
final boolean isLBSUnit = isBitSet(ctrlByte, 0);
final boolean isCattyUnit = isBitSet(ctrlByte, 4);
// Only if the value is stabilized and the weight is *not* removed, the date is valid
if (isStabilized && !isWeightRemoved) {
final int year = ((weightBytes[4] & 0xFF) << 8) | (weightBytes[3] & 0xFF);
final int month = (int) weightBytes[5];
final int day = (int) weightBytes[6];
final int hours = (int) weightBytes[7];
final int min = (int) weightBytes[8];
final int sec = (int) weightBytes[9];
float weight;
if (isLBSUnit || isCattyUnit) {
weight = (float) (((weightBytes[2] & 0xFF) << 8) | (weightBytes[1] & 0xFF)) / 100.0f;
} else {
weight = (float) (((weightBytes[2] & 0xFF) << 8) | (weightBytes[1] & 0xFF)) / 200.0f;
}
String date_string = year + "/" + month + "/" + day + "/" + hours + "/" + min;
Date date_time = new SimpleDateFormat("yyyy/MM/dd/HH/mm").parse(date_string);
// Is the year plausible? Check if the year is in the range of 20 years...
if (validateDate(date_time, 20)) {
final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser();
ScaleMeasurement scaleBtData = new ScaleMeasurement();
scaleBtData.setWeight(Converters.toKilogram(weight, selectedUser.getScaleUnit()));
scaleBtData.setDateTime(date_time);
addScaleMeasurement(scaleBtData);
} else {
Timber.e("Invalid Mi scale weight year %d", year);
}
}
} catch (ParseException e) {
setBluetoothStatus(UNEXPECTED_ERROR, "Error while decoding bluetooth date string (" + e.getMessage() + ")");
}
}
use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.
the class BluetoothTrisaBodyAnalyze method onScaleMeasurumentReceived.
private void onScaleMeasurumentReceived(byte[] data) {
ScaleUser user = OpenScale.getInstance().getSelectedScaleUser();
ScaleMeasurement measurement = parseScaleMeasurementData(data, user);
if (measurement == null) {
Timber.e("Failed to parse scale measure measurement data: %s", byteInHex(data));
return;
}
addScaleMeasurement(measurement);
}
use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.
the class WidgetConfigure method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setResult(RESULT_CANCELED);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
setContentView(R.layout.widget_configuration);
OpenScale openScale = OpenScale.getInstance();
// Set up user spinner
final Spinner userSpinner = findViewById(R.id.widget_user_spinner);
List<String> users = new ArrayList<>();
final List<Integer> userIds = new ArrayList<>();
for (ScaleUser scaleUser : openScale.getScaleUserList()) {
users.add(scaleUser.getUserName());
userIds.add(scaleUser.getId());
}
// Hide user selector when there's only one user
if (users.size() == 1) {
TableRow row = (TableRow) userSpinner.getParent();
row.setVisibility(View.GONE);
} else if (users.isEmpty()) {
users.add(getResources().getString(R.string.info_no_selected_user));
userIds.add(-1);
findViewById(R.id.widget_save).setEnabled(false);
}
ArrayAdapter<String> userAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, users);
userAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
userSpinner.setAdapter(userAdapter);
// Set up measurement spinner
final Spinner measurementSpinner = findViewById(R.id.widget_measurement_spinner);
List<String> measurements = new ArrayList<>();
final List<String> measurementKeys = new ArrayList<>();
for (MeasurementView measurementView : MeasurementView.getMeasurementList(this, MeasurementView.DateTimeOrder.NONE)) {
if (measurementView.isVisible()) {
measurements.add(measurementView.getName().toString());
measurementKeys.add(measurementView.getKey());
}
}
ArrayAdapter<String> measurementAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, measurements);
measurementAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
measurementSpinner.setAdapter(measurementAdapter);
findViewById(R.id.widget_save).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int userId = userIds.get(userSpinner.getSelectedItemPosition());
String measurementKey = measurementKeys.get(measurementSpinner.getSelectedItemPosition());
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putInt(WidgetProvider.getUserIdPreferenceName(appWidgetId), userId).putString(WidgetProvider.getMeasurementPreferenceName(appWidgetId), measurementKey).apply();
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { appWidgetId });
sendBroadcast(intent);
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}
});
}
use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.
the class OverviewFragment method updateUserSelection.
private void updateUserSelection() {
currentScaleUser = OpenScale.getInstance().getSelectedScaleUser();
spinUserAdapter.clear();
List<ScaleUser> scaleUserList = OpenScale.getInstance().getScaleUserList();
int posUser = 0;
for (ScaleUser scaleUser : scaleUserList) {
spinUserAdapter.add(scaleUser.getUserName());
if (scaleUser.getId() == currentScaleUser.getId()) {
posUser = spinUserAdapter.getCount() - 1;
}
}
spinUser.setSelection(posUser, true);
// Hide user selector when there is only one user
int visibility = spinUserAdapter.getCount() < 2 ? View.GONE : View.VISIBLE;
txtTitleUser.setVisibility(visibility);
spinUser.setVisibility(visibility);
}
Aggregations