2020-01-09 10:44:32 +01:00
|
|
|
/* Copyright (C) 2015-2020 Andreas Shimokawa, Carsten Pfeiffer, Daniele
|
2017-03-10 14:53:19 +01:00
|
|
|
Gobbetti
|
|
|
|
|
|
|
|
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/>. */
|
2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.model;
|
2015-07-14 00:29:32 +02:00
|
|
|
|
2017-10-19 21:52:38 +02:00
|
|
|
import android.content.Context;
|
|
|
|
|
2020-08-16 23:45:52 +02:00
|
|
|
import androidx.annotation.DrawableRes;
|
|
|
|
|
2015-07-14 00:29:32 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
2017-10-19 21:52:38 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
2015-07-14 00:29:32 +02:00
|
|
|
|
|
|
|
public class ActivityKind {
|
2016-07-27 23:34:13 +02:00
|
|
|
public static final int TYPE_NOT_MEASURED = -1;
|
2020-08-16 23:45:52 +02:00
|
|
|
public static final int TYPE_UNKNOWN = 0x00000000;
|
|
|
|
public static final int TYPE_ACTIVITY = 0x00000001;
|
|
|
|
public static final int TYPE_LIGHT_SLEEP = 0x00000002;
|
|
|
|
public static final int TYPE_DEEP_SLEEP = 0x00000004;
|
|
|
|
public static final int TYPE_NOT_WORN = 0x00000008;
|
|
|
|
public static final int TYPE_RUNNING = 0x00000010;
|
|
|
|
public static final int TYPE_WALKING = 0x00000020;
|
|
|
|
public static final int TYPE_SWIMMING = 0x00000040;
|
|
|
|
public static final int TYPE_CYCLING = 0x00000080;
|
|
|
|
public static final int TYPE_TREADMILL = 0x00000100;
|
|
|
|
public static final int TYPE_EXERCISE = 0x00000200;
|
|
|
|
public static final int TYPE_SWIMMING_OPENWATER = 0x00000400;
|
|
|
|
public static final int TYPE_INDOOR_CYCLING = 0x00000800;
|
|
|
|
public static final int TYPE_ELLIPTICAL_TRAINER = 0x00001000;
|
|
|
|
public static final int TYPE_JUMP_ROPING = 0x00002000;
|
|
|
|
public static final int TYPE_YOGA = 0x00004000;
|
2020-09-07 21:40:20 +02:00
|
|
|
public static final int TYPE_SOCCER = 0x00008000;
|
|
|
|
public static final int TYPE_ROWING_MACHINE = 0x00010000;
|
|
|
|
public static final int TYPE_CRICKET = 0x00020000;
|
|
|
|
public static final int TYPE_BASKETBALL = 0x00040000;
|
|
|
|
public static final int TYPE_PINGPONG = 0x00080000;
|
|
|
|
public static final int TYPE_BADMINTON = 0x00100000;
|
2021-01-22 22:14:11 +01:00
|
|
|
public static final int TYPE_STRENGTH_TRAINING = 0x00200000;
|
2015-08-28 14:35:22 +02:00
|
|
|
|
2021-01-22 22:14:11 +01:00
|
|
|
private static final int TYPES_COUNT = 24;
|
2018-11-01 23:16:14 +01:00
|
|
|
|
2015-07-14 00:29:32 +02:00
|
|
|
public static final int TYPE_SLEEP = TYPE_LIGHT_SLEEP | TYPE_DEEP_SLEEP;
|
2015-08-28 14:54:49 +02:00
|
|
|
public static final int TYPE_ALL = TYPE_ACTIVITY | TYPE_SLEEP | TYPE_NOT_WORN;
|
2015-07-14 00:29:32 +02:00
|
|
|
|
2016-02-29 20:54:39 +01:00
|
|
|
public static int[] mapToDBActivityTypes(int types, SampleProvider provider) {
|
2018-11-01 23:16:14 +01:00
|
|
|
int[] result = new int[TYPES_COUNT];
|
2015-07-14 00:29:32 +02:00
|
|
|
int i = 0;
|
|
|
|
if ((types & ActivityKind.TYPE_ACTIVITY) != 0) {
|
2015-07-27 23:49:53 +02:00
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_ACTIVITY);
|
2015-07-14 00:29:32 +02:00
|
|
|
}
|
|
|
|
if ((types & ActivityKind.TYPE_DEEP_SLEEP) != 0) {
|
2015-07-27 23:49:53 +02:00
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_DEEP_SLEEP);
|
2015-07-14 00:29:32 +02:00
|
|
|
}
|
|
|
|
if ((types & ActivityKind.TYPE_LIGHT_SLEEP) != 0) {
|
2015-07-27 23:49:53 +02:00
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_LIGHT_SLEEP);
|
2015-07-14 00:29:32 +02:00
|
|
|
}
|
2015-08-28 14:54:49 +02:00
|
|
|
if ((types & ActivityKind.TYPE_NOT_WORN) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_NOT_WORN);
|
|
|
|
}
|
2017-10-19 21:52:38 +02:00
|
|
|
if ((types & ActivityKind.TYPE_RUNNING) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_RUNNING);
|
|
|
|
}
|
|
|
|
if ((types & ActivityKind.TYPE_WALKING) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_WALKING);
|
|
|
|
}
|
|
|
|
if ((types & ActivityKind.TYPE_SWIMMING) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_SWIMMING);
|
|
|
|
}
|
2017-10-31 23:39:49 +01:00
|
|
|
if ((types & ActivityKind.TYPE_CYCLING) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_CYCLING);
|
2017-10-19 21:52:38 +02:00
|
|
|
}
|
2017-11-03 21:54:48 +01:00
|
|
|
if ((types & ActivityKind.TYPE_TREADMILL) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_TREADMILL);
|
|
|
|
}
|
2019-01-28 00:22:11 +01:00
|
|
|
if ((types & ActivityKind.TYPE_EXERCISE) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_EXERCISE);
|
|
|
|
}
|
2020-08-16 23:45:52 +02:00
|
|
|
if ((types & ActivityKind.TYPE_SWIMMING_OPENWATER) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_SWIMMING_OPENWATER);
|
|
|
|
}
|
|
|
|
if ((types & ActivityKind.TYPE_INDOOR_CYCLING) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_INDOOR_CYCLING);
|
|
|
|
}
|
|
|
|
if ((types & ActivityKind.TYPE_ELLIPTICAL_TRAINER) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_ELLIPTICAL_TRAINER);
|
|
|
|
}
|
|
|
|
if ((types & ActivityKind.TYPE_JUMP_ROPING) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_JUMP_ROPING);
|
|
|
|
}
|
|
|
|
if ((types & ActivityKind.TYPE_YOGA) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_YOGA);
|
|
|
|
}
|
2021-01-22 22:14:11 +01:00
|
|
|
if ((types & ActivityKind.TYPE_ROWING_MACHINE) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_ROWING_MACHINE);
|
|
|
|
}
|
|
|
|
if ((types & ActivityKind.TYPE_CRICKET) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_CRICKET);
|
|
|
|
}
|
|
|
|
if ((types & ActivityKind.TYPE_BASKETBALL) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_BASKETBALL);
|
|
|
|
}
|
|
|
|
if ((types & ActivityKind.TYPE_PINGPONG) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_PINGPONG);
|
|
|
|
}
|
|
|
|
if ((types & ActivityKind.TYPE_BADMINTON) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_BADMINTON);
|
|
|
|
}
|
|
|
|
if ((types & ActivityKind.TYPE_STRENGTH_TRAINING) != 0) {
|
|
|
|
result[i++] = provider.toRawActivityKind(TYPE_STRENGTH_TRAINING);
|
|
|
|
}
|
|
|
|
|
2015-07-14 00:29:32 +02:00
|
|
|
return Arrays.copyOf(result, i);
|
|
|
|
}
|
|
|
|
|
2017-10-19 21:52:38 +02:00
|
|
|
public static String asString(int kind, Context context) {
|
|
|
|
switch (kind) {
|
|
|
|
case TYPE_NOT_MEASURED:
|
|
|
|
return context.getString(R.string.activity_type_not_measured);
|
|
|
|
case TYPE_ACTIVITY:
|
|
|
|
return context.getString(R.string.activity_type_activity);
|
|
|
|
case TYPE_LIGHT_SLEEP:
|
|
|
|
return context.getString(R.string.activity_type_light_sleep);
|
|
|
|
case TYPE_DEEP_SLEEP:
|
|
|
|
return context.getString(R.string.activity_type_deep_sleep);
|
|
|
|
case TYPE_NOT_WORN:
|
|
|
|
return context.getString(R.string.activity_type_not_worn);
|
|
|
|
case TYPE_RUNNING:
|
|
|
|
return context.getString(R.string.activity_type_running);
|
|
|
|
case TYPE_WALKING:
|
|
|
|
return context.getString(R.string.activity_type_walking);
|
|
|
|
case TYPE_SWIMMING:
|
|
|
|
return context.getString(R.string.activity_type_swimming);
|
2017-10-31 23:39:49 +01:00
|
|
|
case TYPE_CYCLING:
|
2017-10-19 21:52:38 +02:00
|
|
|
return context.getString(R.string.activity_type_biking);
|
2017-11-03 21:54:48 +01:00
|
|
|
case TYPE_TREADMILL:
|
|
|
|
return context.getString(R.string.activity_type_treadmill);
|
2019-01-28 00:22:11 +01:00
|
|
|
case TYPE_EXERCISE:
|
|
|
|
return context.getString(R.string.activity_type_exercise);
|
2020-08-16 23:45:52 +02:00
|
|
|
case TYPE_SWIMMING_OPENWATER:
|
|
|
|
return context.getString(R.string.activity_type_swimming_openwater);
|
|
|
|
case TYPE_INDOOR_CYCLING:
|
|
|
|
return context.getString(R.string.activity_type_indoor_cycling);
|
|
|
|
case TYPE_ELLIPTICAL_TRAINER:
|
|
|
|
return context.getString(R.string.activity_type_elliptical_trainer);
|
|
|
|
case TYPE_JUMP_ROPING:
|
|
|
|
return context.getString(R.string.activity_type_jump_roping);
|
|
|
|
case TYPE_YOGA:
|
|
|
|
return context.getString(R.string.activity_type_yoga);
|
2020-09-07 21:40:20 +02:00
|
|
|
case TYPE_SOCCER:
|
|
|
|
return context.getString(R.string.activity_type_soccer);
|
|
|
|
case TYPE_ROWING_MACHINE:
|
|
|
|
return context.getString(R.string.activity_type_rowing_machine);
|
|
|
|
case TYPE_CRICKET:
|
|
|
|
return context.getString(R.string.activity_type_cricket);
|
|
|
|
case TYPE_BASKETBALL:
|
|
|
|
return context.getString(R.string.activity_type_basketball);
|
|
|
|
case TYPE_PINGPONG:
|
|
|
|
return context.getString(R.string.activity_type_pingpong);
|
|
|
|
case TYPE_BADMINTON:
|
|
|
|
return context.getString(R.string.activity_type_badminton);
|
2021-01-22 22:14:11 +01:00
|
|
|
case TYPE_STRENGTH_TRAINING:
|
|
|
|
return context.getString(R.string.activity_type_strength_training);
|
2017-10-19 21:52:38 +02:00
|
|
|
case TYPE_UNKNOWN:
|
|
|
|
default:
|
|
|
|
return context.getString(R.string.activity_type_unknown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@DrawableRes
|
|
|
|
public static int getIconId(int kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case TYPE_NOT_MEASURED:
|
|
|
|
return R.drawable.ic_activity_not_measured;
|
|
|
|
case TYPE_LIGHT_SLEEP:
|
2019-08-14 07:55:10 +02:00
|
|
|
return R.drawable.ic_activity_sleep;
|
2017-10-19 21:52:38 +02:00
|
|
|
case TYPE_DEEP_SLEEP:
|
2019-08-14 07:55:10 +02:00
|
|
|
return R.drawable.ic_activity_sleep;
|
2017-10-19 21:52:38 +02:00
|
|
|
case TYPE_RUNNING:
|
|
|
|
return R.drawable.ic_activity_running;
|
|
|
|
case TYPE_WALKING:
|
|
|
|
return R.drawable.ic_activity_walking;
|
2017-10-31 23:39:49 +01:00
|
|
|
case TYPE_CYCLING:
|
2017-10-19 21:52:38 +02:00
|
|
|
return R.drawable.ic_activity_biking;
|
2017-11-03 21:54:48 +01:00
|
|
|
case TYPE_TREADMILL:
|
2020-08-25 14:04:28 +02:00
|
|
|
return R.drawable.ic_activity_threadmill;
|
2020-08-16 23:45:52 +02:00
|
|
|
case TYPE_EXERCISE:
|
2019-08-14 07:55:10 +02:00
|
|
|
return R.drawable.ic_activity_exercise;
|
2020-08-16 23:45:52 +02:00
|
|
|
case TYPE_SWIMMING:
|
|
|
|
case TYPE_SWIMMING_OPENWATER:
|
2019-08-14 07:55:10 +02:00
|
|
|
return R.drawable.ic_activity_swimming;
|
2020-08-16 23:45:52 +02:00
|
|
|
case TYPE_INDOOR_CYCLING:
|
2020-08-25 14:04:28 +02:00
|
|
|
return R.drawable.ic_activity_bike_trainer;
|
2020-08-16 23:45:52 +02:00
|
|
|
case TYPE_ELLIPTICAL_TRAINER:
|
2020-08-25 14:04:28 +02:00
|
|
|
return R.drawable.ic_activity_eliptical;
|
2020-08-16 23:45:52 +02:00
|
|
|
case TYPE_JUMP_ROPING:
|
2020-08-25 14:04:28 +02:00
|
|
|
return R.drawable.ic_activity_rope_jump;
|
2020-08-16 23:45:52 +02:00
|
|
|
case TYPE_YOGA:
|
2020-08-17 14:13:48 +02:00
|
|
|
return R.drawable.ic_activity_yoga;
|
2020-09-07 21:40:20 +02:00
|
|
|
case TYPE_SOCCER:
|
2020-09-17 21:34:03 +02:00
|
|
|
return R.drawable.ic_activity_soccer;
|
2020-09-07 21:40:20 +02:00
|
|
|
case TYPE_ROWING_MACHINE:
|
2020-09-17 21:34:03 +02:00
|
|
|
return R.drawable.ic_activity_rowing;
|
2020-09-07 21:40:20 +02:00
|
|
|
case TYPE_CRICKET:
|
2020-09-17 21:34:03 +02:00
|
|
|
return R.drawable.ic_activity_cricket;
|
2020-09-07 21:40:20 +02:00
|
|
|
case TYPE_BASKETBALL:
|
2020-09-17 21:34:03 +02:00
|
|
|
return R.drawable.ic_activity_basketball;
|
2020-09-07 21:40:20 +02:00
|
|
|
case TYPE_PINGPONG:
|
2020-09-17 21:34:03 +02:00
|
|
|
return R.drawable.ic_activity_pingpong;
|
2020-09-07 21:40:20 +02:00
|
|
|
case TYPE_BADMINTON:
|
2020-09-17 21:34:03 +02:00
|
|
|
return R.drawable.ic_activity_badmington;
|
2021-01-22 22:14:11 +01:00
|
|
|
case TYPE_STRENGTH_TRAINING:
|
|
|
|
return R.drawable.ic_activity_unknown_small; //FIXME: find icon
|
2020-09-07 21:40:20 +02:00
|
|
|
|
2017-10-19 21:52:38 +02:00
|
|
|
case TYPE_NOT_WORN: // fall through
|
|
|
|
case TYPE_ACTIVITY: // fall through
|
|
|
|
case TYPE_UNKNOWN: // fall through
|
|
|
|
default:
|
2020-10-12 23:10:59 +02:00
|
|
|
return R.drawable.ic_activity_unknown_small;
|
2017-10-19 21:52:38 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-14 00:29:32 +02:00
|
|
|
}
|