From ed85fd5011c51342bae9fe07db4dd2dd733ca8bb Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Mon, 29 Feb 2016 20:54:39 +0100 Subject: [PATCH] convert byte and short values related to activity tracking to int This avoids a lot of problems because java - does not know unsigned values - jvm and dalvic do not internally support byte and short - sqlite does not know them either --- .../gadgetbridge/GBApplication.java | 12 +++---- .../charts/AbstractChartFragment.java | 7 ++-- .../activities/charts/CustomBarChart.java | 1 + .../charts/LiveActivityFragment.java | 4 +-- .../activities/charts/SleepChartFragment.java | 1 - .../charts/WeekStepsChartFragment.java | 1 - .../database/ActivityDatabaseHandler.java | 25 ++++++++------- .../gadgetbridge/database/DBHandler.java | 4 +-- .../database/schema/ActivityDBUpdate_6.java | 5 --- .../devices/DeviceCoordinator.java | 12 ++++++- .../gadgetbridge/devices/SampleProvider.java | 20 ++++++------ .../devices/UnknownDeviceCoordinator.java | 8 ++--- .../devices/miband/MiBandSampleProvider.java | 8 ++--- .../devices/miband/MiBandService.java | 6 ++-- .../gadgetbridge/devices/miband/UserInfo.java | 6 ++-- .../devices/pebble/HealthSampleProvider.java | 30 ++++++++--------- .../devices/pebble/MisfitSampleProvider.java | 8 ++--- .../pebble/MorpheuzSampleProvider.java | 8 ++--- .../PebbleGadgetBridgeSampleProvider.java | 2 +- .../externalevents/SMSReceiver.java | 2 -- .../gadgetbridge/impl/GBActivitySample.java | 32 +++++++++---------- .../gadgetbridge/model/ActivityKind.java | 4 +-- .../gadgetbridge/model/ActivitySample.java | 8 ++--- .../gadgetbridge/model/ActivityUser.java | 8 ++--- .../gadgetbridge/model/CalendarEvents.java | 12 +++---- .../service/DeviceSupportFactory.java | 3 -- .../service/btle/AbstractBTLEOperation.java | 4 +++ .../gadgetbridge/service/btle/BtLEQueue.java | 2 +- .../service/btle/GattCallback.java | 4 +-- .../service/devices/miband/DeviceInfo.java | 2 +- .../service/devices/miband/MiBandSupport.java | 29 +++++++++-------- .../operations/AbstractMiBandOperation.java | 3 +- .../operations/FetchActivityOperation.java | 2 +- .../operations/UpdateFirmwareOperation.java | 4 +-- .../pebble/AppMessageHandlerGBPebble.java | 8 ++--- .../pebble/AppMessageHandlerMisfit.java | 4 +-- .../pebble/AppMessageHandlerMorpheuz.java | 2 +- .../AppMessageHandlerTimeStylePebble.java | 4 +-- .../devices/pebble/DatalogSession.java | 2 +- .../pebble/DatalogSessionHealthSleep.java | 1 - .../pebble/DatalogSessionHealthSteps.java | 15 ++++----- .../gadgetbridge/util/DeviceHelper.java | 1 - 42 files changed, 163 insertions(+), 161 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index af43c296..20e79bed 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -261,26 +261,26 @@ public class GBApplication extends Application { private void migratePrefs(int oldVersion) { SharedPreferences.Editor editor = sharedPrefs.edit(); - switch (oldVersion) { + switch (oldVersion) { case 0: String legacyGender = sharedPrefs.getString("mi_user_gender", null); String legacyHeight = sharedPrefs.getString("mi_user_height_cm", null); String legacyWeigth = sharedPrefs.getString("mi_user_weight_kg", null); - String legacyYOB = sharedPrefs.getString("mi_user_year_of_birth",null); - if(legacyGender != null) { + String legacyYOB = sharedPrefs.getString("mi_user_year_of_birth", null); + if (legacyGender != null) { int gender = "male".equals(legacyGender) ? 1 : "female".equals(legacyGender) ? 0 : 2; editor.putString(ActivityUser.PREF_USER_GENDER, Integer.toString(gender)); editor.remove("mi_user_gender"); } - if(legacyHeight != null) { + if (legacyHeight != null) { editor.putString(ActivityUser.PREF_USER_HEIGHT_CM, legacyHeight); editor.remove("mi_user_height_cm"); } - if(legacyWeigth != null) { + if (legacyWeigth != null) { editor.putString(ActivityUser.PREF_USER_WEIGHT_KG, legacyWeigth); editor.remove("mi_user_weight_kg"); } - if(legacyYOB != null) { + if (legacyYOB != null) { editor.putString(ActivityUser.PREF_USER_YEAR_OF_BIRTH, legacyYOB); editor.remove("mi_user_year_of_birth"); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java index 886aa25e..c4775c50 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java @@ -12,7 +12,6 @@ import android.view.View; import com.github.mikephil.charting.charts.BarLineChartBase; import com.github.mikephil.charting.charts.Chart; -import com.github.mikephil.charting.charts.CombinedChart; import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BarDataSet; @@ -29,7 +28,6 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; -import java.util.Collections; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashSet; @@ -86,6 +84,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment { } public abstract String getTitle(); + public boolean supportsHeartrate() { return supportsHeartrateChart; } @@ -166,7 +165,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment { protected ChartsHost getChartsHost() { return (ChartsHost) getActivity(); } - + private void setEndDate(Date date) { getChartsHost().setEndDate(date); } @@ -447,7 +446,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment { } activityEntries.add(createBarEntry(value, i)); if (hr) { - heartrateEntries.add(createLineEntry(sample.getCustomShortValue(), i)); + heartrateEntries.add(createLineEntry(sample.getCustomValue(), i)); } String xLabel = ""; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/CustomBarChart.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/CustomBarChart.java index 78830278..131f130f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/CustomBarChart.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/CustomBarChart.java @@ -49,6 +49,7 @@ public class CustomBarChart extends BarChart { /** * Call this to set the next value for the Entry to be animated. * Call animateY() when ready to do that. + * * @param nextValue */ public void setSingleEntryYValue(float nextValue) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/LiveActivityFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/LiveActivityFragment.java index 2e9d29b9..d7b2ca24 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/LiveActivityFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/LiveActivityFragment.java @@ -315,9 +315,9 @@ public class LiveActivityFragment extends AbstractChartFragment { List xLabels = new ArrayList<>(); List colors = new ArrayList<>(); - entries.add(new BarEntry(0,0)); + entries.add(new BarEntry(0, 0)); entries.add(entry); - entries.add(new BarEntry(0,2)); + entries.add(new BarEntry(0, 2)); colors.add(akActivity.color); colors.add(akActivity.color); colors.add(akActivity.color); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/SleepChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/SleepChartFragment.java index 17411ff6..6b9a7561 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/SleepChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/SleepChartFragment.java @@ -8,7 +8,6 @@ import android.view.View; import android.view.ViewGroup; import com.github.mikephil.charting.animation.Easing; -import com.github.mikephil.charting.charts.BarLineChartBase; import com.github.mikephil.charting.charts.Chart; import com.github.mikephil.charting.charts.CombinedChart; import com.github.mikephil.charting.charts.PieChart; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekStepsChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekStepsChartFragment.java index c3c565f7..927a499b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekStepsChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekStepsChartFragment.java @@ -6,7 +6,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.github.mikephil.charting.charts.BarLineChartBase; import com.github.mikephil.charting.charts.Chart; import com.github.mikephil.charting.charts.CombinedChart; import com.github.mikephil.charting.charts.PieChart; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/ActivityDatabaseHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/ActivityDatabaseHandler.java index 2df3759d..97023cdd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/ActivityDatabaseHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/ActivityDatabaseHandler.java @@ -22,15 +22,15 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.util.GB; import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.DATABASE_NAME; +import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_CUSTOM_SHORT; import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_INTENSITY; import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_PROVIDER; import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_STEPS; import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TIMESTAMP; import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TYPE; -import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_CUSTOM_SHORT; import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_GBACTIVITYSAMPLES; -public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandler { +public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandler { private static final Logger LOG = LoggerFactory.getLogger(ActivityDatabaseHandler.class); @@ -102,7 +102,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa values.put(KEY_PROVIDER, sample.getProvider().getID()); values.put(KEY_INTENSITY, sample.getRawIntensity()); values.put(KEY_STEPS, sample.getSteps()); - values.put(KEY_CUSTOM_SHORT, sample.getCustomShortValue()); + values.put(KEY_CUSTOM_SHORT, sample.getCustomValue()); values.put(KEY_TYPE, sample.getRawKind()); db.insert(TABLE_GBACTIVITYSAMPLES, null, values); @@ -112,14 +112,15 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa /** * Adds the a new sample to the database * - * @param timestamp the timestamp of the same, second-based! - * @param provider the SampleProvider ID - * @param intensity the sample's raw intensity value - * @param steps the sample's steps value - * @param kind the raw activity kind of the sample + * @param timestamp the timestamp of the same, second-based! + * @param provider the SampleProvider ID + * @param intensity the sample's raw intensity value + * @param steps the sample's steps value + * @param kind the raw activity kind of the sample + * @param customShortValue */ @Override - public void addGBActivitySample(int timestamp, byte provider, short intensity, short steps, byte kind, short customShortValue) { + public void addGBActivitySample(int timestamp, int provider, int intensity, int steps, int kind, int customShortValue) { if (intensity < 0) { LOG.error("negative intensity received, ignoring"); intensity = 0; @@ -164,7 +165,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa statement.bindLong(3, activitySample.getRawIntensity()); statement.bindLong(4, activitySample.getSteps()); statement.bindLong(5, activitySample.getRawKind()); - statement.bindLong(6, activitySample.getCustomShortValue()); + statement.bindLong(6, activitySample.getCustomValue()); statement.execute(); } db.setTransactionSuccessful(); @@ -242,7 +243,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa } StringBuilder builder = new StringBuilder(" and ("); - byte[] dbActivityTypes = ActivityKind.mapToDBActivityTypes(activityTypes, provider); + int[] dbActivityTypes = ActivityKind.mapToDBActivityTypes(activityTypes, provider); for (int i = 0; i < dbActivityTypes.length; i++) { builder.append(" type=").append(dbActivityTypes[i]); if (i + 1 < dbActivityTypes.length) { @@ -254,7 +255,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHa } @Override - public void changeStoredSamplesType(int timestampFrom, int timestampTo, byte kind, SampleProvider provider) { + public void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind, SampleProvider provider) { try (SQLiteDatabase db = this.getReadableDatabase()) { String sql = "UPDATE " + TABLE_GBACTIVITYSAMPLES + " SET " + KEY_TYPE + "= ? WHERE " + KEY_PROVIDER + " = ? AND " diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/DBHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/DBHandler.java index 7dfeb5c8..42aa64de 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/DBHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/DBHandler.java @@ -24,13 +24,13 @@ public interface DBHandler { List getSleepSamples(int tsFrom, int tsTo, SampleProvider provider); - void addGBActivitySample(int timestamp, byte provider, short intensity, short steps, byte kind, short heartrate); + void addGBActivitySample(int timestamp, int provider, int intensity, int steps, int kind, int heartrate); void addGBActivitySamples(ActivitySample[] activitySamples); SQLiteDatabase getWritableDatabase(); - void changeStoredSamplesType(int timestampFrom, int timestampTo, byte kind, SampleProvider provider); + void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind, SampleProvider provider); int fetchLatestTimestamp(SampleProvider provider); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/ActivityDBUpdate_6.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/ActivityDBUpdate_6.java index c805e352..483f556d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/ActivityDBUpdate_6.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/ActivityDBUpdate_6.java @@ -2,15 +2,10 @@ package nodomain.freeyourgadget.gadgetbridge.database.schema; import android.database.sqlite.SQLiteDatabase; -import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript; import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_CUSTOM_SHORT; -import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_PROVIDER; -import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_STEPS; -import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TIMESTAMP; import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_GBACTIVITYSAMPLES; -import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_STEPS_PER_DAY; /** * Adds a column "customShort" to the table "GBActivitySamples" diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java index 8619875d..fc5ea93e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java @@ -12,7 +12,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; * This interface is implemented at least once for every supported gadget device. * It allows Gadgetbridge to generically deal with different kinds of devices * without actually knowing the details of any device. - * + *

* Instances will be created as needed and asked whether they support a given * device. If a coordinator answers true, it will be used to assist in handling * the given device. @@ -22,6 +22,7 @@ public interface DeviceCoordinator { /** * Checks whether this candidate handles the given candidate. + * * @param candidate * @return true if this coordinator handles the given candidate. */ @@ -29,6 +30,7 @@ public interface DeviceCoordinator { /** * Checks whether this candidate handles the given device. + * * @param device * @return true if this coordinator handles the given device. */ @@ -36,6 +38,7 @@ public interface DeviceCoordinator { /** * Returns the kind of device type this coordinator supports. + * * @return */ DeviceType getDeviceType(); @@ -43,6 +46,7 @@ public interface DeviceCoordinator { /** * Returns the Activity class to be started in order to perform a pairing of a * given device. + * * @return */ Class getPairingActivity(); @@ -50,6 +54,7 @@ public interface DeviceCoordinator { /** * Returns the Activity class that will be used as the primary activity * for the given device. + * * @return */ Class getPrimaryActivity(); @@ -57,6 +62,7 @@ public interface DeviceCoordinator { /** * Returns true if activity data fetching is supported by the device * (with this coordinator). + * * @return */ boolean supportsActivityDataFetching(); @@ -65,6 +71,7 @@ public interface DeviceCoordinator { * Returns true if activity data fetching is supported AND possible at this * very moment. This will consider the device state (being connected/disconnected/busy...) * etc. + * * @param device * @return */ @@ -72,6 +79,7 @@ public interface DeviceCoordinator { /** * Returns the sample provider for the device being supported. + * * @return */ SampleProvider getSampleProvider(); @@ -79,6 +87,7 @@ public interface DeviceCoordinator { /** * Finds an install handler for the given uri that can install the given * uri on the device being managed. + * * @param uri * @param context * @return the install handler or null if that uri cannot be installed on the device @@ -87,6 +96,7 @@ public interface DeviceCoordinator { /** * Returns true if this device/coordinator supports taking screenshots. + * * @return */ boolean supportsScreenshots(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/SampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/SampleProvider.java index ad99cfea..78463d02 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/SampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/SampleProvider.java @@ -1,19 +1,19 @@ package nodomain.freeyourgadget.gadgetbridge.devices; public interface SampleProvider { - byte PROVIDER_MIBAND = 0; - byte PROVIDER_PEBBLE_MORPHEUZ = 1; - byte PROVIDER_PEBBLE_GADGETBRIDGE = 2; - byte PROVIDER_PEBBLE_MISFIT = 3; - byte PROVIDER_PEBBLE_HEALTH = 4; + int PROVIDER_MIBAND = 0; + int PROVIDER_PEBBLE_MORPHEUZ = 1; + int PROVIDER_PEBBLE_GADGETBRIDGE = 2; + int PROVIDER_PEBBLE_MISFIT = 3; + int PROVIDER_PEBBLE_HEALTH = 4; - byte PROVIDER_UNKNOWN = 100; + int PROVIDER_UNKNOWN = 100; - int normalizeType(byte rawType); + int normalizeType(int rawType); - byte toRawActivityKind(int activityKind); + int toRawActivityKind(int activityKind); - float normalizeIntensity(short rawIntensity); + float normalizeIntensity(int rawIntensity); - byte getID(); + int getID(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java index ce690f7c..052c1730 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java @@ -15,22 +15,22 @@ public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator { private static final class UnknownSampleProvider implements SampleProvider { @Override - public int normalizeType(byte rawType) { + public int normalizeType(int rawType) { return ActivityKind.TYPE_UNKNOWN; } @Override - public byte toRawActivityKind(int activityKind) { + public int toRawActivityKind(int activityKind) { return 0; } @Override - public float normalizeIntensity(short rawIntensity) { + public float normalizeIntensity(int rawIntensity) { return 0; } @Override - public byte getID() { + public int getID() { return PROVIDER_UNKNOWN; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandSampleProvider.java index 95026cb0..6cde07e1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandSampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandSampleProvider.java @@ -23,7 +23,7 @@ public class MiBandSampleProvider implements SampleProvider { private final float movementDivisor = 180.0f; //256.0f; @Override - public int normalizeType(byte rawType) { + public int normalizeType(int rawType) { switch (rawType) { case TYPE_DEEP_SLEEP: return ActivityKind.TYPE_DEEP_SLEEP; @@ -42,7 +42,7 @@ public class MiBandSampleProvider implements SampleProvider { } @Override - public byte toRawActivityKind(int activityKind) { + public int toRawActivityKind(int activityKind) { switch (activityKind) { case ActivityKind.TYPE_ACTIVITY: return TYPE_ACTIVITY; @@ -59,12 +59,12 @@ public class MiBandSampleProvider implements SampleProvider { } @Override - public float normalizeIntensity(short rawIntensity) { + public float normalizeIntensity(int rawIntensity) { return rawIntensity / movementDivisor; } @Override - public byte getID() { + public int getID() { return SampleProvider.PROVIDER_MIBAND; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandService.java index 295488cf..39d5bd69 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandService.java @@ -161,9 +161,9 @@ public class MiBandService { public static final byte COMMAND_SET_REALTIME_STEP = 0x10; // Test HR - public static final byte COMMAND_SET_HR_SLEEP = 0x0; - public static final byte COMMAND_SET__HR_CONTINUOUS = 0x1; - public static final byte COMMAND_SET_HR_MANUAL = 0x2; + public static final byte COMMAND_SET_HR_SLEEP = 0x0; + public static final byte COMMAND_SET__HR_CONTINUOUS = 0x1; + public static final byte COMMAND_SET_HR_MANUAL = 0x2; /* FURTHER COMMANDS: unchecked therefore left commented diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/UserInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/UserInfo.java index 9aa098bc..e17f5c2e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/UserInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/UserInfo.java @@ -1,11 +1,11 @@ package nodomain.freeyourgadget.gadgetbridge.devices.miband; +import java.util.Arrays; + import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.DeviceInfo; import nodomain.freeyourgadget.gadgetbridge.util.CheckSums; -import java.util.Arrays; - public class UserInfo { private final String btAddress; @@ -91,7 +91,7 @@ public class UserInfo { aliasFrom = 11; } - byte[] aliasBytes = alias.substring(0, Math.min(alias.length(), 19-aliasFrom)).getBytes(); + byte[] aliasBytes = alias.substring(0, Math.min(alias.length(), 19 - aliasFrom)).getBytes(); System.arraycopy(aliasBytes, 0, sequence, aliasFrom, aliasBytes.length); byte[] crcSequence = Arrays.copyOf(sequence, 19); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/HealthSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/HealthSampleProvider.java index c557bbad..b62abe16 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/HealthSampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/HealthSampleProvider.java @@ -4,27 +4,27 @@ import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; public class HealthSampleProvider implements SampleProvider { - public static final byte TYPE_DEEP_SLEEP = 5; - public static final byte TYPE_LIGHT_SLEEP = 4; - public static final byte TYPE_ACTIVITY = -1; + public static final int TYPE_DEEP_SLEEP = 5; + public static final int TYPE_LIGHT_SLEEP = 4; + public static final int TYPE_ACTIVITY = -1; protected final float movementDivisor = 8000f; @Override - public int normalizeType(byte rawType) { + public int normalizeType(int rawType) { switch (rawType) { - case TYPE_DEEP_SLEEP: - return ActivityKind.TYPE_DEEP_SLEEP; - case TYPE_LIGHT_SLEEP: - return ActivityKind.TYPE_LIGHT_SLEEP; - case TYPE_ACTIVITY: - default: - return ActivityKind.TYPE_UNKNOWN; - } + case TYPE_DEEP_SLEEP: + return ActivityKind.TYPE_DEEP_SLEEP; + case TYPE_LIGHT_SLEEP: + return ActivityKind.TYPE_LIGHT_SLEEP; + case TYPE_ACTIVITY: + default: + return ActivityKind.TYPE_UNKNOWN; + } } @Override - public byte toRawActivityKind(int activityKind) { + public int toRawActivityKind(int activityKind) { switch (activityKind) { case ActivityKind.TYPE_ACTIVITY: return TYPE_ACTIVITY; @@ -40,13 +40,13 @@ public class HealthSampleProvider implements SampleProvider { @Override - public float normalizeIntensity(short rawIntensity) { + public float normalizeIntensity(int rawIntensity) { return rawIntensity / movementDivisor; } @Override - public byte getID() { + public int getID() { return SampleProvider.PROVIDER_PEBBLE_HEALTH; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/MisfitSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/MisfitSampleProvider.java index 608f9771..bce42a37 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/MisfitSampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/MisfitSampleProvider.java @@ -7,24 +7,24 @@ public class MisfitSampleProvider implements SampleProvider { protected final float movementDivisor = 300f; @Override - public int normalizeType(byte rawType) { + public int normalizeType(int rawType) { return (int) rawType; } @Override - public byte toRawActivityKind(int activityKind) { + public int toRawActivityKind(int activityKind) { return (byte) activityKind; } @Override - public float normalizeIntensity(short rawIntensity) { + public float normalizeIntensity(int rawIntensity) { return rawIntensity / movementDivisor; } @Override - public byte getID() { + public int getID() { return SampleProvider.PROVIDER_PEBBLE_MISFIT; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/MorpheuzSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/MorpheuzSampleProvider.java index e9bdf7a0..bbe0a331 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/MorpheuzSampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/MorpheuzSampleProvider.java @@ -13,7 +13,7 @@ public class MorpheuzSampleProvider implements SampleProvider { protected float movementDivisor = 5000f; @Override - public int normalizeType(byte rawType) { + public int normalizeType(int rawType) { switch (rawType) { case TYPE_DEEP_SLEEP: return ActivityKind.TYPE_DEEP_SLEEP; @@ -28,7 +28,7 @@ public class MorpheuzSampleProvider implements SampleProvider { } @Override - public byte toRawActivityKind(int activityKind) { + public int toRawActivityKind(int activityKind) { switch (activityKind) { case ActivityKind.TYPE_ACTIVITY: return TYPE_ACTIVITY; @@ -43,12 +43,12 @@ public class MorpheuzSampleProvider implements SampleProvider { } @Override - public float normalizeIntensity(short rawIntensity) { + public float normalizeIntensity(int rawIntensity) { return rawIntensity / movementDivisor; } @Override - public byte getID() { + public int getID() { return SampleProvider.PROVIDER_PEBBLE_MORPHEUZ; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleGadgetBridgeSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleGadgetBridgeSampleProvider.java index 028201ac..b047fdb4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleGadgetBridgeSampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleGadgetBridgeSampleProvider.java @@ -8,7 +8,7 @@ public class PebbleGadgetBridgeSampleProvider extends MorpheuzSampleProvider { } @Override - public byte getID() { + public int getID() { return SampleProvider.PROVIDER_PEBBLE_GADGETBRIDGE; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/SMSReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/SMSReceiver.java index 664e44e9..a2dd09a3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/SMSReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/SMSReceiver.java @@ -9,8 +9,6 @@ import android.os.PowerManager; import android.preference.PreferenceManager; import android.telephony.SmsMessage; -import java.util.ArrayList; - import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationType; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBActivitySample.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBActivitySample.java index 6ade2e63..895b903b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBActivitySample.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBActivitySample.java @@ -7,21 +7,21 @@ import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils; public class GBActivitySample implements ActivitySample { private final int timestamp; private final SampleProvider provider; - private final short intensity; - private final short steps; - private final byte type; - private final short customShortValue; + private final int intensity; + private final int steps; + private final int type; + private final int customValue; - public GBActivitySample(SampleProvider provider, int timestamp, short intensity, short steps, byte type) { - this(provider, timestamp, intensity, steps, type, (short) 0); + public GBActivitySample(SampleProvider provider, int timestamp, int intensity, int steps, int type) { + this(provider, timestamp, intensity, steps, type, 0); } - public GBActivitySample(SampleProvider provider, int timestamp, short intensity, short steps, byte type, short customShortValue) { + public GBActivitySample(SampleProvider provider, int timestamp, int intensity, int steps, int type, int customValue) { this.timestamp = timestamp; this.provider = provider; this.intensity = intensity; this.steps = steps; - this.customShortValue = customShortValue; + this.customValue = customValue; this.type = type; validate(); } @@ -36,8 +36,8 @@ public class GBActivitySample implements ActivitySample { if (timestamp < 0) { throw new IllegalArgumentException("timestamp must be >= 0"); } - if (customShortValue < 0) { - throw new IllegalArgumentException("customShortValue must be >= 0"); + if (customValue < 0) { + throw new IllegalArgumentException("customValue must be >= 0"); } } @@ -52,7 +52,7 @@ public class GBActivitySample implements ActivitySample { } @Override - public short getRawIntensity() { + public int getRawIntensity() { return intensity; } @@ -62,12 +62,12 @@ public class GBActivitySample implements ActivitySample { } @Override - public short getSteps() { + public int getSteps() { return steps; } @Override - public byte getRawKind() { + public int getRawKind() { return type; } @@ -77,8 +77,8 @@ public class GBActivitySample implements ActivitySample { } @Override - public short getCustomShortValue() { - return customShortValue; + public int getCustomValue() { + return customValue; } @Override @@ -87,7 +87,7 @@ public class GBActivitySample implements ActivitySample { "timestamp=" + DateTimeUtils.formatDateTime(DateTimeUtils.parseTimeStamp(timestamp)) + ", intensity=" + getIntensity() + ", steps=" + getSteps() + - ", customShortValue=" + getCustomShortValue() + + ", customValue=" + getCustomValue() + ", type=" + getKind() + '}'; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java index a857c9d0..df7bbce3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java @@ -14,8 +14,8 @@ public class ActivityKind { public static final int TYPE_SLEEP = TYPE_LIGHT_SLEEP | TYPE_DEEP_SLEEP; public static final int TYPE_ALL = TYPE_ACTIVITY | TYPE_SLEEP | TYPE_NOT_WORN; - public static byte[] mapToDBActivityTypes(int types, SampleProvider provider) { - byte[] result = new byte[3]; + public static int[] mapToDBActivityTypes(int types, SampleProvider provider) { + int[] result = new int[3]; int i = 0; if ((types & ActivityKind.TYPE_ACTIVITY) != 0) { result[i++] = provider.toRawActivityKind(TYPE_ACTIVITY); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySample.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySample.java index b515c5ef..117a8a7a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySample.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySample.java @@ -18,7 +18,7 @@ public interface ActivitySample { /** * Returns the raw activity kind value as recorded by the SampleProvider */ - byte getRawKind(); + int getRawKind(); /** * Returns the activity kind value as recorded by the SampleProvider @@ -30,7 +30,7 @@ public interface ActivitySample { /** * Returns the raw intensity value as recorded by the SampleProvider */ - short getRawIntensity(); + int getRawIntensity(); /** * Returns the normalized intensity value between 0 and 1 @@ -40,7 +40,7 @@ public interface ActivitySample { /** * Returns the number of steps performed during the period of this sample */ - short getSteps(); + int getSteps(); - short getCustomShortValue(); + int getCustomValue(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityUser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityUser.java index f2c87c49..aa4a09b4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityUser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityUser.java @@ -29,28 +29,28 @@ public class ActivityUser { public static final String PREF_USER_WEIGHT_KG = "activity_user_weight_kg"; public int getActivityUserWeightKg() { - if(activityUserWeightKg == null) { + if (activityUserWeightKg == null) { fetchPreferences(); } return activityUserWeightKg; } public int getActivityUserGender() { - if(activityUserGender == null) { + if (activityUserGender == null) { fetchPreferences(); } return activityUserGender; } public int getActivityUserYearOfBirth() { - if(activityUserYearOfBirth == null) { + if (activityUserYearOfBirth == null) { fetchPreferences(); } return activityUserYearOfBirth; } public int getActivityUserHeightCm() { - if(activityUserHeightCm == null) { + if (activityUserHeightCm == null) { fetchPreferences(); } return activityUserHeightCm; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/CalendarEvents.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/CalendarEvents.java index 61c5b7ba..1e814062 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/CalendarEvents.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/CalendarEvents.java @@ -22,7 +22,7 @@ public class CalendarEvents { // needed for miband: // time - private static final String[] EVENT_INSTANCE_PROJECTION = new String[] { + private static final String[] EVENT_INSTANCE_PROJECTION = new String[]{ Instances._ID, Instances.BEGIN, Instances.END, @@ -67,9 +67,9 @@ public class CalendarEvents { evtCursor.getString(5), evtCursor.getString(6), evtCursor.getString(7) - ); + ); calendarEventList.add(calEvent); - } while(evtCursor.moveToNext()); + } while (evtCursor.moveToNext()); return true; } @@ -100,7 +100,7 @@ public class CalendarEvents { } public int getBeginSeconds() { - return (int)(begin/1000); + return (int) (begin / 1000); } public long getEnd() { @@ -112,11 +112,11 @@ public class CalendarEvents { } public int getDurationSeconds() { - return (int)((getDuration())/1000); + return (int) ((getDuration()) / 1000); } public short getDurationMinutes() { - return (short)(getDurationSeconds()/60); + return (short) (getDurationSeconds() / 60); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceSupportFactory.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceSupportFactory.java index 55765588..6bc07789 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceSupportFactory.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceSupportFactory.java @@ -1,7 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.service; import android.bluetooth.BluetoothAdapter; -import android.bluetooth.BluetoothDevice; import android.content.Context; import android.widget.Toast; @@ -11,10 +10,8 @@ import java.util.EnumSet; import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; -import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleSupport; -import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.GB; public class DeviceSupportFactory { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEOperation.java index 3c2387c0..b7a7e938 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/AbstractBTLEOperation.java @@ -36,6 +36,7 @@ public abstract class AbstractBTLEOperation * Performs this operation. The whole operation is asynchronous, i.e. * this method quickly returns before the actual operation is finished. * Calls #prePerform() and, if successful, #doPerform(). + * * @throws IOException */ @Override @@ -48,6 +49,7 @@ public abstract class AbstractBTLEOperation /** * Hook for subclasses to perform something before #doPerform() is invoked. + * * @throws IOException */ protected void prePerform() throws IOException { @@ -58,6 +60,7 @@ public abstract class AbstractBTLEOperation * successfully. * Note that subclasses HAVE TO call #operationFinished() when the entire * opreation is done (successful or not). + * * @throws IOException */ protected abstract void doPerform() throws IOException; @@ -65,6 +68,7 @@ public abstract class AbstractBTLEOperation /** * You MUST call this method when the operation has finished, either * successfull or unsuccessfully. + * * @throws IOException */ protected void operationFinished() throws IOException { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BtLEQueue.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BtLEQueue.java index 4af53e70..b74cdbfd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BtLEQueue.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BtLEQueue.java @@ -422,7 +422,7 @@ public final class BtLEQueue { for (byte b : characteristic.getValue()) { content += String.format(" 0x%1x", b); } - LOG.debug("characteristic changed: " + characteristic.getUuid() + " value: " + content ); + LOG.debug("characteristic changed: " + characteristic.getUuid() + " value: " + content); } if (!checkCorrectGattInstance(gatt, "characteristic changed")) { return; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/GattCallback.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/GattCallback.java index ec5afed5..3089856b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/GattCallback.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/GattCallback.java @@ -74,7 +74,7 @@ public interface GattCallback { * @see BluetoothGattCallback#onDescriptorRead(BluetoothGatt, BluetoothGattDescriptor, int) */ void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, - int status); + int status); /** * @param gatt @@ -83,7 +83,7 @@ public interface GattCallback { * @see BluetoothGattCallback#onDescriptorWrite(BluetoothGatt, BluetoothGattDescriptor, int) */ void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, - int status); + int status); // // /** // * @see BluetoothGattCallback#onReliableWriteCompleted(BluetoothGatt, int) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/DeviceInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/DeviceInfo.java index 18ffe2f9..d7a64de0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/DeviceInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/DeviceInfo.java @@ -41,7 +41,7 @@ public class DeviceInfo extends AbstractInfo { public static int getInt(byte[] data, int from, int len) { int ret = 0; - for(int i = 0; i < len; ++i) { + for (int i = 0; i < len; ++i) { ret |= (data[from + i] & 255) << i * 8; } return ret; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java index f4d97a70..f35d983e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java @@ -141,7 +141,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { // is not available. And at this point, we don't even know whether we support it, because // no device info is available yet. We would have to do the check in a custom NotifyAction. // if (supportsHeartRate()) { - builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT), enable); + builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT), enable); // } return this; @@ -206,12 +206,12 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { static final byte[] reboot = new byte[]{MiBandService.COMMAND_REBOOT}; - static final byte[] startHeartMeasurementManual = new byte[]{ 0x15, MiBandService.COMMAND_SET_HR_MANUAL, 1}; - static final byte[] stopHeartMeasurementManual = new byte[]{ 0x15, MiBandService.COMMAND_SET_HR_MANUAL, 0}; - static final byte[] startHeartMeasurementContinuous = new byte[]{ 0x15, MiBandService.COMMAND_SET__HR_CONTINUOUS, 1}; - static final byte[] stopHeartMeasurementContinuous = new byte[]{ 0x15, MiBandService.COMMAND_SET__HR_CONTINUOUS, 0}; - static final byte[] startHeartMeasurementSleep = new byte[]{ 0x15, MiBandService.COMMAND_SET_HR_SLEEP, 1}; - static final byte[] stopHeartMeasurementSleep = new byte[]{ 0x15, MiBandService.COMMAND_SET_HR_SLEEP, 0}; + static final byte[] startHeartMeasurementManual = new byte[]{0x15, MiBandService.COMMAND_SET_HR_MANUAL, 1}; + static final byte[] stopHeartMeasurementManual = new byte[]{0x15, MiBandService.COMMAND_SET_HR_MANUAL, 0}; + static final byte[] startHeartMeasurementContinuous = new byte[]{0x15, MiBandService.COMMAND_SET__HR_CONTINUOUS, 1}; + static final byte[] stopHeartMeasurementContinuous = new byte[]{0x15, MiBandService.COMMAND_SET__HR_CONTINUOUS, 0}; + static final byte[] startHeartMeasurementSleep = new byte[]{0x15, MiBandService.COMMAND_SET_HR_SLEEP, 1}; + static final byte[] stopHeartMeasurementSleep = new byte[]{0x15, MiBandService.COMMAND_SET_HR_SLEEP, 0}; static final byte[] startRealTimeStepsNotifications = new byte[]{MiBandService.COMMAND_SET_REALTIME_STEPS_NOTIFICATION, 1}; static final byte[] stopRealTimeStepsNotifications = new byte[]{MiBandService.COMMAND_SET_REALTIME_STEPS_NOTIFICATION, 0}; @@ -283,6 +283,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } return this; }*/ + /** * Part of device initialization process. Do not call manually. * @@ -531,6 +532,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { LOG.error("Unable to reboot MI", ex); } } + @Override public void onHearRateTest() { if (supportsHeartRate()) { @@ -673,11 +675,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) { handleRealtimeSteps(characteristic.getValue()); } else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) { - handleRealtimeSteps(characteristic.getValue()); - } else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) { + handleRealtimeSteps(characteristic.getValue()); + } else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) { logHeartrate(characteristic.getValue()); - } - else { + } else { LOG.info("Unhandled characteristic changed: " + characteristicUUID); logMessageContent(characteristic.getValue()); } @@ -698,7 +699,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) { logHeartrate(characteristic.getValue()); } else { - LOG.info("Unhandled characteristic read: "+ characteristicUUID); + LOG.info("Unhandled characteristic read: " + characteristicUUID); logMessageContent(characteristic.getValue()); } } @@ -927,11 +928,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { if (availableSlots > 0) { CalendarEvents upcomingEvents = new CalendarEvents(); - List mEvents = upcomingEvents.getCalendarEventList(getContext()); + List mEvents = upcomingEvents.getCalendarEventList(getContext()); int iteration = 0; ArrayList alarmList = new ArrayList<>(); - for(CalendarEvents.CalendarEvent mEvt : mEvents) { + for (CalendarEvents.CalendarEvent mEvt : mEvents) { if (iteration >= availableSlots || iteration > 2) { break; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/AbstractMiBandOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/AbstractMiBandOperation.java index ffabce53..2f6577d7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/AbstractMiBandOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/operations/AbstractMiBandOperation.java @@ -41,8 +41,9 @@ public abstract class AbstractMiBandOperation extends AbstractBTLEOperation 0) && (i % 50 == 0)) { builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), new byte[]{MiBandService.COMMAND_SYNC}); - builder.add(new SetProgressAction("Firmware update in progress", true, (int)(((float) firmwareProgress) / len * 100), getContext())); + builder.add(new SetProgressAction("Firmware update in progress", true, (int) (((float) firmwareProgress) / len * 100), getContext())); } - LOG.info("Firmware update progress:" + firmwareProgress + " total len:" + len + " progress:" + (int)(((float) firmwareProgress) / len * 100)); + LOG.info("Firmware update progress:" + firmwareProgress + " total len:" + len + " progress:" + (int) (((float) firmwareProgress) / len * 100)); } if (!(len % packetLength == 0)) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerGBPebble.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerGBPebble.java index 10655018..f3ac052f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerGBPebble.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerGBPebble.java @@ -52,10 +52,10 @@ public class AppMessageHandlerGBPebble extends AppMessageHandler { db = GBApplication.acquireDB(); while (samples_remaining-- > 0) { short sample = samplesBuffer.getShort(); - byte type = (byte) ((sample & 0xe000) >>> 13); - byte intensity = (byte) ((sample & 0x1f80) >>> 7); - byte steps = (byte) (sample & 0x007f); - db.addGBActivitySample(timestamp + offset_seconds, SampleProvider.PROVIDER_PEBBLE_GADGETBRIDGE, (short) (intensity & 0xff), (short) (steps & 0xff), type, (short)0); + int type = ((sample & 0xe000) >>> 13); + int intensity = ((sample & 0x1f80) >>> 7); + int steps = (sample & 0x007f); + db.addGBActivitySample(timestamp + offset_seconds, SampleProvider.PROVIDER_PEBBLE_GADGETBRIDGE, intensity, steps, type, 0); offset_seconds += 60; } } catch (GBException e) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMisfit.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMisfit.java index 96c53cf4..daa0b020 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMisfit.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMisfit.java @@ -75,7 +75,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler { short sample = buf.getShort(); int steps = 0; int intensity = 0; - byte activityKind = ActivityKind.TYPE_UNKNOWN; + int activityKind = ActivityKind.TYPE_UNKNOWN; if (((sample & 0x83ff) == 0x0001) && ((sample & 0xff00) <= 0x4800)) { // sleep seems to be from 0x2401 to 0x4801 (0b0IIIII0000000001) where I = intensity ? @@ -101,7 +101,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler { totalSteps += steps; LOG.info("got steps for sample " + i + " : " + steps + "(" + Integer.toHexString(sample & 0xffff) + ")"); - activitySamples[i] = new GBActivitySample(sampleProvider, timestamp + i * 60, (short) intensity, (short) steps, activityKind); + activitySamples[i] = new GBActivitySample(sampleProvider, timestamp + i * 60, intensity, steps, activityKind); } LOG.info("total steps for above period: " + totalSteps); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMorpheuz.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMorpheuz.java index 4507fbc4..3d22a4d1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMorpheuz.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMorpheuz.java @@ -93,7 +93,7 @@ public class AppMessageHandlerMorpheuz extends AppMessageHandler { DBHandler db = null; try { db = GBApplication.acquireDB(); - db.addGBActivitySample(recording_base_timestamp + index * 600, SampleProvider.PROVIDER_PEBBLE_MORPHEUZ, intensity, (byte) 0, type, (short)0); + db.addGBActivitySample(recording_base_timestamp + index * 600, SampleProvider.PROVIDER_PEBBLE_MORPHEUZ, intensity, (byte) 0, type, (short) 0); } catch (GBException e) { LOG.error("Error acquiring database", e); } finally { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java index 13bf8430..11b8cf78 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java @@ -77,7 +77,7 @@ public class AppMessageHandlerTimeStylePebble extends AppMessageHandler { //byte[] weatherMessage=encodeTimeStylePebbleWeather(); - ByteBuffer buf = ByteBuffer.allocate(ackMessage.length + testMessage.length ); + ByteBuffer buf = ByteBuffer.allocate(ackMessage.length + testMessage.length); // encode ack and put in front of push message (hack for acknowledging the last message) buf.put(ackMessage); @@ -98,7 +98,7 @@ public class AppMessageHandlerTimeStylePebble extends AppMessageHandler { return weatherMessage; } - @Override + @Override public GBDeviceEvent[] handleMessage(ArrayList> pairs) { GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes(); sendBytes.encodedBytes = encodeTimeStylePebbleConfig(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSession.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSession.java index 00f67721..2b07d944 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSession.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSession.java @@ -19,7 +19,7 @@ class DatalogSession { this.itemSize = itemSize; } - boolean handleMessage (ByteBuffer buf, int length) { + boolean handleMessage(ByteBuffer buf, int length) { return true; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionHealthSleep.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionHealthSleep.java index a2ec192a..8528287f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionHealthSleep.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionHealthSleep.java @@ -1,6 +1,5 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble; -import android.database.sqlite.SQLiteDatabase; import android.widget.Toast; import org.slf4j.Logger; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionHealthSteps.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionHealthSteps.java index 6ce8bd09..81bb4319 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionHealthSteps.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/DatalogSessionHealthSteps.java @@ -1,8 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble; -import android.database.sqlite.SQLiteDatabase; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,7 +59,8 @@ public class DatalogSessionHealthSteps extends DatalogSession { for (int recordIdx = 0; recordIdx < recordNum; recordIdx++) { datalogMessage.position(beginOfRecordPosition + recordIdx * recordLength); //we may not consume all the bytes of a record - stepsRecords[recordIdx] = new StepsRecord(timestamp, datalogMessage.get(), datalogMessage.get(), datalogMessage.getShort(), datalogMessage.get(), datalogMessage.get()); + stepsRecords[recordIdx] = new StepsRecord(timestamp, datalogMessage.get() & 0xff, datalogMessage.get() & 0xff, datalogMessage.getShort() & 0xffff); + datalogMessage.getShort(); // skip timestamp += 60; } @@ -82,7 +81,7 @@ public class DatalogSessionHealthSteps extends DatalogSession { sampleProvider, stepsRecord.timestamp, stepsRecord.intensity, - (short) (stepsRecord.steps & 0xff), + stepsRecord.steps, sampleProvider.toRawActivityKind(ActivityKind.TYPE_ACTIVITY)); } @@ -100,11 +99,11 @@ public class DatalogSessionHealthSteps extends DatalogSession { private class StepsRecord { int timestamp; - byte steps; - byte orientation; - short intensity; + int steps; + int orientation; + int intensity; - public StepsRecord(int timestamp, byte steps, byte orientation, short intensity, byte throwAway1, byte throwAway2) { + public StepsRecord(int timestamp, int steps, int orientation, int intensity) { this.timestamp = timestamp; this.steps = steps; this.orientation = orientation; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java index ae7ee58e..b3aad4b7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java @@ -8,7 +8,6 @@ import android.preference.PreferenceManager; import android.widget.Toast; import java.util.ArrayList; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set;