Search in sources :

Example 41 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class UsersPreferences method updateUserPreferences.

private void updateUserPreferences() {
    OpenScale openScale = OpenScale.getInstance(getActivity().getApplicationContext());
    int selectedUserId = openScale.getSelectedScaleUserId();
    getPreferenceScreen().removeAll();
    List<ScaleUser> scaleUserList = openScale.getScaleUserList();
    for (ScaleUser scaleUser : scaleUserList) {
        Preference prefUser = new Preference(getActivity());
        prefUser.setOnPreferenceClickListener(new onClickListenerUserSelect());
        if (scaleUser.getId() == selectedUserId) {
            prefUser.setTitle("> " + scaleUser.getUserName());
        } else {
            prefUser.setTitle(scaleUser.getUserName());
        }
        prefUser.setKey(Integer.toString(scaleUser.getId()));
        getPreferenceScreen().addPreference(prefUser);
    }
    Preference prefAddUser = new Preference(getActivity());
    prefAddUser.setOnPreferenceClickListener(new onClickListenerAddUser());
    prefAddUser.setTitle("+ " + getResources().getString(R.string.label_add_user));
    getPreferenceScreen().addPreference(prefAddUser);
}
Also used : Preference(android.preference.Preference) ScaleUser(com.health.openscale.core.datatypes.ScaleUser) OpenScale(com.health.openscale.core.OpenScale)

Example 42 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class OverviewFragment method updateUserSelection.

private void updateUserSelection() {
    currentScaleUser = OpenScale.getInstance(getContext()).getSelectedScaleUser();
    userSelectedData = null;
    spinUserAdapter.clear();
    List<ScaleUser> scaleUserList = OpenScale.getInstance(getContext()).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);
    userLineSeparator.setVisibility(visibility);
}
Also used : ScaleUser(com.health.openscale.core.datatypes.ScaleUser)

Example 43 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class BluetoothBeurerBF700_800 method nextInitCmd.

@Override
boolean nextInitCmd(int stateNr) {
    switch(stateNr) {
        case 0:
            // Initialize data
            currentScaleUserId = -1;
            countRegisteredScaleUsers = -1;
            maxRegisteredScaleUser = -1;
            seenUsers = new TreeSet<>();
            // Setup notification
            setNotificationOn(CUSTOM_SERVICE_1, CUSTOM_CHARACTERISTIC_WEIGHT, CLIENT_CHARACTERISTICS_CONFIGURATION);
            break;
        case 1:
            // Say "Hello" to the scale
            writeBytes(new byte[] { (byte) 0xf6, (byte) 0x01 });
            break;
        case 2:
            // Update timestamp of the scale
            updateDateTimeBeurer();
            break;
        case 3:
            // Set measurement unit
            setUnitCommand();
            break;
        case 4:
            // Request general user information
            writeBytes(new byte[] { (byte) 0xf7, (byte) 0x33 });
            break;
        case 5:
            // Wait for ack of all users
            if (seenUsers.size() < countRegisteredScaleUsers || (countRegisteredScaleUsers == -1)) {
                // Request this state again
                setNextCmd(stateNr);
                break;
            }
            // Check if not found/unknown
            if (currentScaleUserId == 0) {
                // Unknown user, request creation of new user
                if (countRegisteredScaleUsers == maxRegisteredScaleUser) {
                    setBtMachineState(BT_MACHINE_STATE.BT_CLEANUP_STATE);
                    Log.d(TAG, "Cannot create additional scale user");
                    sendMessage(R.string.error_max_scale_users, 0);
                    break;
                }
                // Request creation of user
                final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
                // We can only use up to 3 characters and have to handle them uppercase
                int maxIdx = selectedUser.getUserName().length() >= 3 ? 3 : selectedUser.getUserName().length();
                byte[] nick = selectedUser.getUserName().toUpperCase().substring(0, maxIdx).getBytes();
                // activity level: 1 - 5
                byte activity = 2;
                Log.d(TAG, "Create User:" + selectedUser.getUserName());
                writeBytes(new byte[] { (byte) 0xf7, (byte) 0x31, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) (seenUsers.size() > 0 ? Collections.max(seenUsers) + 1 : 101), nick[0], nick[1], nick[2], (byte) selectedUser.getBirthday().getYear(), (byte) selectedUser.getBirthday().getMonth(), (byte) selectedUser.getBirthday().getDate(), (byte) selectedUser.getBodyHeight(), (byte) (((selectedUser.getGender().isMale() ? 1 : 0) << 7) | activity) });
            } else {
                // Get existing user information
                Log.d(TAG, "Request getUserInfo " + currentScaleUserId);
                writeBytes(new byte[] { (byte) 0xf7, (byte) 0x36, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) currentScaleUserId });
            }
            Log.d(TAG, "scaleuserid:" + currentScaleUserId + " registered users: " + countRegisteredScaleUsers + " extracted users: " + seenUsers.size());
            break;
        case 6:
            break;
        default:
            // Finish init if everything is done
            return false;
    }
    return true;
}
Also used : ScaleUser(com.health.openscale.core.datatypes.ScaleUser)

Example 44 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class BluetoothBeurerBF700_800 method setUnitCommand.

private void setUnitCommand() {
    byte[] command = SET_UNIT_COMMAND;
    final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
    switch(selectedUser.getScaleUnit()) {
        case KG:
            command[2] = (byte) 0x01;
            break;
        case LB:
            command[2] = (byte) 0x02;
            break;
        case ST:
            command[3] = (byte) 0x04;
            break;
    }
    Log.d(TAG, "Setting unit " + selectedUser.getScaleUnit().toString());
    writeBytes(command);
}
Also used : ScaleUser(com.health.openscale.core.datatypes.ScaleUser)

Example 45 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class BluetoothExingtechY1 method nextInitCmd.

@Override
boolean nextInitCmd(int stateNr) {
    switch(stateNr) {
        case 0:
            setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
            break;
        case 1:
            final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
            // 00 - male; 01 - female
            byte gender = selectedUser.getGender().isMale() ? (byte) 0x00 : (byte) 0x01;
            // cm
            byte height = (byte) (selectedUser.getBodyHeight() & 0xff);
            byte age = (byte) (selectedUser.getAge(new Date()) & 0xff);
            int userId = selectedUser.getId();
            byte[] cmdByte = { (byte) 0x10, (byte) userId, gender, age, height };
            writeBytes(WEIGHT_MEASUREMENT_SERVICE, CMD_MEASUREMENT_CHARACTERISTIC, cmdByte);
            break;
        default:
            return false;
    }
    return true;
}
Also used : ScaleUser(com.health.openscale.core.datatypes.ScaleUser) Date(java.util.Date)

Aggregations

ScaleUser (com.health.openscale.core.datatypes.ScaleUser)69 ScaleMeasurement (com.health.openscale.core.datatypes.ScaleMeasurement)23 Date (java.util.Date)21 Calendar (java.util.Calendar)9 OpenScale (com.health.openscale.core.OpenScale)8 ParseException (java.text.ParseException)6 Converters (com.health.openscale.core.utils.Converters)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)3 SimpleDateFormat (java.text.SimpleDateFormat)3 AlertDialog (android.app.AlertDialog)2 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 Uri (android.net.Uri)2 ArrayAdapter (android.widget.ArrayAdapter)2 Spinner (android.widget.Spinner)2 TableRow (android.widget.TableRow)2 TextView (android.widget.TextView)2