Search in sources :

Example 1 with ActivityUser

use of nodomain.freeyourgadget.gadgetbridge.model.ActivityUser in project Gadgetbridge by Freeyourgadget.

the class SleepAlarmWidget method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);
    if (ACTION.equals(intent.getAction())) {
        int userSleepDuration = new ActivityUser().getSleepDuration();
        // current timestamp
        GregorianCalendar calendar = new GregorianCalendar();
        // add preferred sleep duration
        calendar.add(Calendar.HOUR_OF_DAY, userSleepDuration);
        // overwrite the first alarm and activate it
        GBAlarm alarm = GBAlarm.createSingleShot(0, true, calendar);
        alarm.store();
        if (GBApplication.isRunningLollipopOrLater()) {
            setAlarmViaAlarmManager(context, calendar.getTimeInMillis());
        }
        int hours = calendar.get(Calendar.HOUR_OF_DAY);
        int minutes = calendar.get(Calendar.MINUTE);
        GB.toast(context, String.format(context.getString(R.string.appwidget_alarms_set), hours, minutes), Toast.LENGTH_SHORT, GB.INFO);
    }
}
Also used : GBAlarm(nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm) GregorianCalendar(java.util.GregorianCalendar) ActivityUser(nodomain.freeyourgadget.gadgetbridge.model.ActivityUser)

Example 2 with ActivityUser

use of nodomain.freeyourgadget.gadgetbridge.model.ActivityUser in project Gadgetbridge by Freeyourgadget.

the class PebbleProtocol method encodeActivateHealth.

byte[] encodeActivateHealth(boolean activate) {
    byte[] blob;
    if (activate) {
        ByteBuffer buf = ByteBuffer.allocate(9);
        buf.order(ByteOrder.LITTLE_ENDIAN);
        ActivityUser activityUser = new ActivityUser();
        Integer heightMm = activityUser.getHeightCm() * 10;
        buf.putShort(heightMm.shortValue());
        Integer weigthDag = activityUser.getWeightKg() * 100;
        buf.putShort(weigthDag.shortValue());
        //activate tracking
        buf.put((byte) 0x01);
        //activity Insights
        buf.put((byte) 0x00);
        //sleep Insights
        buf.put((byte) 0x00);
        buf.put((byte) activityUser.getAge());
        buf.put((byte) activityUser.getGender());
        blob = buf.array();
    } else {
        blob = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    }
    return encodeBlobdb("activityPreferences", BLOBDB_INSERT, BLOBDB_PREFERENCES, blob);
}
Also used : ActivityUser(nodomain.freeyourgadget.gadgetbridge.model.ActivityUser) ByteBuffer(java.nio.ByteBuffer)

Example 3 with ActivityUser

use of nodomain.freeyourgadget.gadgetbridge.model.ActivityUser in project Gadgetbridge by Freeyourgadget.

the class MiBandCoordinator method getConfiguredUserInfo.

/**
     * Returns the user info from the user configured data in the preferences.
     *
     * @param miBandAddress
     * @throws IllegalArgumentException when the user info can not be created
     */
public static UserInfo getConfiguredUserInfo(String miBandAddress) throws IllegalArgumentException {
    ActivityUser activityUser = new ActivityUser();
    Prefs prefs = GBApplication.getPrefs();
    UserInfo info = UserInfo.create(miBandAddress, prefs.getString(MiBandConst.PREF_USER_ALIAS, null), activityUser.getGender(), activityUser.getAge(), activityUser.getHeightCm(), activityUser.getWeightKg(), 0);
    return info;
}
Also used : ActivityUser(nodomain.freeyourgadget.gadgetbridge.model.ActivityUser) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs)

Example 4 with ActivityUser

use of nodomain.freeyourgadget.gadgetbridge.model.ActivityUser in project Gadgetbridge by Freeyourgadget.

the class DBHelper method getUser.

/**
     * Looks up the user entity in the database. If a user exists already, it will
     * be updated with the current preferences values. If no user exists yet, it will
     * be created in the database.
     *
     * Note: so far there is only ever a single user; there is no multi-user support yet
     * @param session
     * @return the User entity
     */
@NonNull
public static User getUser(DaoSession session) {
    ActivityUser prefsUser = new ActivityUser();
    UserDao userDao = session.getUserDao();
    User user;
    List<User> users = userDao.loadAll();
    if (users.isEmpty()) {
        user = createUser(prefsUser, session);
    } else {
        // TODO: multiple users support?
        user = users.get(0);
        ensureUserUpToDate(user, prefsUser, session);
    }
    ensureUserAttributes(user, prefsUser, session);
    return user;
}
Also used : User(nodomain.freeyourgadget.gadgetbridge.entities.User) ActivityUser(nodomain.freeyourgadget.gadgetbridge.model.ActivityUser) UserDao(nodomain.freeyourgadget.gadgetbridge.entities.UserDao) ActivityUser(nodomain.freeyourgadget.gadgetbridge.model.ActivityUser) NonNull(android.support.annotation.NonNull)

Example 5 with ActivityUser

use of nodomain.freeyourgadget.gadgetbridge.model.ActivityUser in project Gadgetbridge by Freeyourgadget.

the class DBHelper method createUser.

@NonNull
private static User createUser(ActivityUser prefsUser, DaoSession session) {
    User user = new User();
    ensureUserUpToDate(user, prefsUser, session);
    return user;
}
Also used : User(nodomain.freeyourgadget.gadgetbridge.entities.User) ActivityUser(nodomain.freeyourgadget.gadgetbridge.model.ActivityUser) NonNull(android.support.annotation.NonNull)

Aggregations

ActivityUser (nodomain.freeyourgadget.gadgetbridge.model.ActivityUser)5 NonNull (android.support.annotation.NonNull)2 User (nodomain.freeyourgadget.gadgetbridge.entities.User)2 ByteBuffer (java.nio.ByteBuffer)1 GregorianCalendar (java.util.GregorianCalendar)1 UserDao (nodomain.freeyourgadget.gadgetbridge.entities.UserDao)1 GBAlarm (nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm)1 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)1