mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Fossil Q: Add dev preference for saving raw activity files
This commit is contained in:
committed by
Arjan Schrijver
parent
9093f730a2
commit
4a7f17599b
+5
@@ -264,12 +264,16 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
@Override
|
||||
public DeviceSpecificSettings getDeviceSpecificSettings(final GBDevice device) {
|
||||
final DeviceSpecificSettings deviceSpecificSettings = new DeviceSpecificSettings();
|
||||
// Q Hybrid watches, without eInk screen
|
||||
if (!isHybridHR(device)) {
|
||||
deviceSpecificSettings.addRootScreen(R.xml.devicesettings_fossilqhybrid_legacy);
|
||||
deviceSpecificSettings.addRootScreen(R.xml.devicesettings_fossilhybridhr_vibration);
|
||||
// deviceSpecificSettings.addRootScreen(R.xml.devicesettings_fossilhybridhr_calibration); // TODO
|
||||
final List<Integer> developer = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.DEVELOPER);
|
||||
developer.add(R.xml.devicesettings_fossilhybrids_dev);
|
||||
return deviceSpecificSettings;
|
||||
}
|
||||
// Gen 1 and Gen 6 HR Hybrid watches, with eInk screen
|
||||
final List<Integer> generic = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.GENERIC);
|
||||
// Firmware version specific settings
|
||||
final Version firmwareVersion = getFirmwareVersion(device);
|
||||
@@ -296,6 +300,7 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
notifications.add(R.xml.devicesettings_transliteration);
|
||||
notifications.add(R.xml.devicesettings_custom_deviceicon);
|
||||
final List<Integer> developer = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.DEVELOPER);
|
||||
developer.add(R.xml.devicesettings_fossilhybrids_dev);
|
||||
developer.add(R.xml.devicesettings_fossilhybridhr_dev);
|
||||
return deviceSpecificSettings;
|
||||
}
|
||||
|
||||
+40
-2
@@ -36,6 +36,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.DateFormat;
|
||||
@@ -111,6 +113,7 @@ public class FossilWatchAdapter extends WatchAdapter {
|
||||
public final String CONFIG_ITEM_BUTTONS = "buttons";
|
||||
|
||||
private int lastButtonIndex = -1;
|
||||
protected boolean saveRawActivityFiles = false;
|
||||
|
||||
protected final Logger LOG = LoggerFactory.getLogger(getClass().getSimpleName());
|
||||
|
||||
@@ -151,6 +154,8 @@ public class FossilWatchAdapter extends WatchAdapter {
|
||||
public void initialize() {
|
||||
timeoutThread.start();
|
||||
|
||||
saveRawActivityFiles = getDeviceSpecificPreferences().getBoolean("save_raw_activity_files", false);
|
||||
|
||||
playPairingAnimation();
|
||||
|
||||
queueWrite(new RequestMtuRequest(512), false);
|
||||
@@ -393,6 +398,8 @@ public class FossilWatchAdapter extends WatchAdapter {
|
||||
|
||||
@Override
|
||||
public void setStepGoal(int stepGoal) {
|
||||
LOG.info("setStepGoal called with value: {}", stepGoal);
|
||||
|
||||
queueWrite(new ConfigurationPutRequest(new ConfigurationPutRequest.DailyStepGoalConfigItem(stepGoal), this) {
|
||||
@Override
|
||||
public void onFilePut(boolean success) {
|
||||
@@ -403,7 +410,7 @@ public class FossilWatchAdapter extends WatchAdapter {
|
||||
}, false);
|
||||
}
|
||||
|
||||
private void setVibrationStrengthFromConfig() {
|
||||
protected void setVibrationStrengthFromConfig() {
|
||||
Prefs prefs = new Prefs(getDeviceSpecificPreferences());
|
||||
int vibrationStrengh = prefs.getInt(DeviceSettingsPreferenceConst.PREF_VIBRATION_STRENGH_PERCENTAGE, 2);
|
||||
if (vibrationStrengh > 0) {
|
||||
@@ -539,6 +546,21 @@ public class FossilWatchAdapter extends WatchAdapter {
|
||||
throw new UnsupportedOperationException("Model " + modelNumber + " not supported");
|
||||
}
|
||||
|
||||
protected void writeFile(String dirname, String fileName, byte[] value) {
|
||||
File activityDir = new File(getContext().getExternalFilesDir(null), dirname);
|
||||
activityDir.mkdir();
|
||||
File f = new File(activityDir, fileName);
|
||||
try {
|
||||
f.createNewFile();
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
fos.write(value);
|
||||
fos.close();
|
||||
LOG.debug("Saved raw activity file: " + f.getName());
|
||||
} catch (IOException e) {
|
||||
LOG.error("file error", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchActivityData() {
|
||||
queueWrite(new FileLookupAndGetRequest(FileHandle.ACTIVITY_FILE, this) {
|
||||
@@ -560,6 +582,10 @@ public class FossilWatchAdapter extends WatchAdapter {
|
||||
|
||||
provider.addGBActivitySamples(samples);
|
||||
|
||||
if (saveRawActivityFiles) {
|
||||
writeFile("activity_qhybrid", String.valueOf(System.currentTimeMillis()), fileData);
|
||||
}
|
||||
|
||||
queueWrite(new FileDeleteRequest(getHandle()));
|
||||
GB.updateTransferNotification(null, "", false, 100, getContext());
|
||||
GB.signalActivityDataFinish(getDeviceSupport().getDevice());
|
||||
@@ -631,8 +657,20 @@ public class FossilWatchAdapter extends WatchAdapter {
|
||||
|
||||
@Override
|
||||
public void onSendConfiguration(String config) {
|
||||
setStepGoal(new ActivityUser().getStepsGoal());
|
||||
switch (config) {
|
||||
case DeviceSettingsPreferenceConst.PREF_VIBRATION_STRENGH_PERCENTAGE: {
|
||||
setVibrationStrengthFromConfig();
|
||||
break;
|
||||
}
|
||||
case DeviceSettingsPreferenceConst.PREF_HYBRID_HR_SAVE_RAW_ACTIVITY_FILES: {
|
||||
saveRawActivityFiles = getDeviceSpecificPreferences().getBoolean("save_raw_activity_files", false);
|
||||
break;
|
||||
}
|
||||
case ActivityUser.PREF_USER_STEPS_GOAL: {
|
||||
setStepGoal(new ActivityUser().getStepsGoal());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-26
@@ -218,7 +218,6 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
super(deviceSupport);
|
||||
}
|
||||
|
||||
private boolean saveRawActivityFiles = false;
|
||||
private boolean notifiedAboutMissingNavigationApp = false;
|
||||
|
||||
HashMap<String, Bitmap> appIconCache = new HashMap<>();
|
||||
@@ -562,15 +561,6 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
private void setVibrationStrengthFromConfig() {
|
||||
Prefs prefs = new Prefs(getDeviceSpecificPreferences());
|
||||
int vibrationStrengh = prefs.getInt(DeviceSettingsPreferenceConst.PREF_VIBRATION_STRENGH_PERCENTAGE, 2);
|
||||
if (vibrationStrengh > 0) {
|
||||
vibrationStrengh = (vibrationStrengh + 1) * 25; // Seems 0,50,75,100 are working...
|
||||
}
|
||||
setVibrationStrength((short) (vibrationStrengh));
|
||||
}
|
||||
|
||||
private void setUnitsConfig() {
|
||||
final DistanceUnit distanceUnit = GBApplication.getPrefs().getDistanceUnit();
|
||||
int value = 8; // dont know what this bit means but it was set for me before tampering
|
||||
@@ -1316,8 +1306,9 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
}
|
||||
|
||||
if (saveRawActivityFiles) {
|
||||
writeFile(String.valueOf(System.currentTimeMillis()), fileData);
|
||||
writeFile("activity_hr", String.valueOf(System.currentTimeMillis()), fileData);
|
||||
}
|
||||
|
||||
queueWrite(new FileDeleteRequest(fileHandle));
|
||||
GB.updateTransferNotification(null, "", false, 100, getContext());
|
||||
GB.signalActivityDataFinish(getDeviceSupport().getDevice());
|
||||
@@ -1347,21 +1338,6 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
});
|
||||
}
|
||||
|
||||
private void writeFile(String fileName, byte[] value) {
|
||||
File activityDir = new File(getContext().getExternalFilesDir(null), "activity_hr");
|
||||
activityDir.mkdir();
|
||||
File f = new File(activityDir, fileName);
|
||||
try {
|
||||
f.createNewFile();
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
fos.write(value);
|
||||
fos.close();
|
||||
GB.toast("saved file data", Toast.LENGTH_SHORT, GB.INFO);
|
||||
} catch (IOException e) {
|
||||
LOG.error("file error", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncSettings() {
|
||||
if (connectionMode == CONNECTION_MODE.NOT_AUTHENTICATED) {
|
||||
GB.toast(getContext().getString(R.string.fossil_hr_unavailable_unauthed), Toast.LENGTH_LONG, GB.ERROR);
|
||||
|
||||
@@ -2,13 +2,6 @@
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="save_raw_activity_files"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_qhybrid_save_raw_activity_files"
|
||||
android:icon="@drawable/ic_date_range" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="dangerous_external_intents"
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="save_raw_activity_files"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_qhybrid_save_raw_activity_files"
|
||||
android:icon="@drawable/ic_date_range" />
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
||||
Reference in New Issue
Block a user