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);
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations