2019-02-13 20:43:30 +01:00
|
|
|
/* Copyright (C) 2017-2019 Andreas Shimokawa, Carsten Pfeiffer
|
2018-06-25 18:35:46 +02:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2019-08-13 22:04:52 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami;
|
2017-10-31 23:39:49 +01:00
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
|
|
|
|
2019-08-13 22:04:52 +02:00
|
|
|
public enum HuamiSportsActivityType {
|
2017-11-05 00:08:39 +01:00
|
|
|
Outdoor(1),
|
2017-11-01 20:02:30 +01:00
|
|
|
Treadmill(2),
|
2017-11-05 00:08:39 +01:00
|
|
|
Walking(3),
|
2019-01-28 00:22:11 +01:00
|
|
|
Cycling(4),
|
2019-08-13 22:04:52 +02:00
|
|
|
Exercise(5),
|
|
|
|
Swimming(6);
|
2017-11-01 20:02:30 +01:00
|
|
|
private final int code;
|
|
|
|
|
2019-08-13 22:04:52 +02:00
|
|
|
HuamiSportsActivityType(final int code) {
|
2017-11-01 20:02:30 +01:00
|
|
|
this.code = code;
|
|
|
|
}
|
2017-10-31 23:39:49 +01:00
|
|
|
|
|
|
|
public int toActivityKind() {
|
|
|
|
switch (this) {
|
|
|
|
case Outdoor:
|
|
|
|
return ActivityKind.TYPE_RUNNING;
|
|
|
|
case Treadmill:
|
|
|
|
return ActivityKind.TYPE_TREADMILL;
|
|
|
|
case Cycling:
|
|
|
|
return ActivityKind.TYPE_CYCLING;
|
|
|
|
case Walking:
|
|
|
|
return ActivityKind.TYPE_WALKING;
|
2019-01-28 00:22:11 +01:00
|
|
|
case Exercise:
|
|
|
|
return ActivityKind.TYPE_EXERCISE;
|
2019-08-13 22:04:52 +02:00
|
|
|
case Swimming:
|
|
|
|
return ActivityKind.TYPE_SWIMMING;
|
2017-10-31 23:39:49 +01:00
|
|
|
}
|
|
|
|
throw new RuntimeException("Not mapped activity kind for: " + this);
|
|
|
|
}
|
|
|
|
|
2019-08-13 22:04:52 +02:00
|
|
|
public static HuamiSportsActivityType fromCode(int huamiCode) {
|
|
|
|
for (HuamiSportsActivityType type : values()) {
|
|
|
|
if (type.code == huamiCode) {
|
2017-11-01 20:02:30 +01:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
}
|
2019-08-13 22:04:52 +02:00
|
|
|
throw new RuntimeException("No matching HuamiSportsActivityType for code: " + huamiCode);
|
2017-11-01 20:02:30 +01:00
|
|
|
}
|
|
|
|
|
2019-08-13 22:04:52 +02:00
|
|
|
public static HuamiSportsActivityType fromActivityKind(int activityKind) {
|
2017-11-01 20:02:30 +01:00
|
|
|
switch (activityKind) {
|
2017-10-31 23:39:49 +01:00
|
|
|
case ActivityKind.TYPE_RUNNING:
|
|
|
|
return Outdoor;
|
|
|
|
case ActivityKind.TYPE_TREADMILL:
|
|
|
|
return Treadmill;
|
|
|
|
case ActivityKind.TYPE_CYCLING:
|
|
|
|
return Cycling;
|
|
|
|
case ActivityKind.TYPE_WALKING:
|
|
|
|
return Walking;
|
2019-01-28 00:22:11 +01:00
|
|
|
case ActivityKind.TYPE_EXERCISE:
|
|
|
|
return Exercise;
|
2019-08-13 22:04:52 +02:00
|
|
|
case ActivityKind.TYPE_SWIMMING:
|
|
|
|
return Swimming;
|
2017-10-31 23:39:49 +01:00
|
|
|
}
|
2017-11-01 20:02:30 +01:00
|
|
|
throw new RuntimeException("No matching activity activityKind: " + activityKind);
|
2017-10-31 23:39:49 +01:00
|
|
|
}
|
|
|
|
}
|