1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-24 10:56:50 +01:00

Makibes HR3: Make settings per-device

Also so some minor cleanups on Makibes HR3 code
This commit is contained in:
Andreas Shimokawa 2019-10-02 23:45:19 +02:00
parent 64edc6f87c
commit 21a287f6b1
7 changed files with 39 additions and 59 deletions

View File

@ -0,0 +1,5 @@
package nodomain.freeyourgadget.gadgetbridge.activities.devicesettings;
public class DeviceSettingsPreferenceConst {
public static final String PREF_TIMEFORMAT = "timeformat";
}

View File

@ -210,6 +210,4 @@ public final class MakibesHR3Constants {
// If this is sent after {@link CMD_FACTORY_RESET}, it's a shutdown, not a reboot.
// Rebooting resets the watch face and wallpaper.
public static final byte CMD_REBOOT = (byte) 0xff;
public static final String PREF_TIMEFORMAT = "makibes_hr3_timeformat";
}

View File

@ -16,26 +16,21 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.makibeshr3;
/*
* @author Alejandro Ladera Chamorro &lt;11555126+tiparega@users.noreply.github.com&gt;
*/
import android.app.Activity;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
@ -45,26 +40,24 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getContext;
/**
* Pseudo Coordinator for the Q8, a sub type of the HPLUS devices
*/
public class MakibesHR3Coordinator extends AbstractDeviceCoordinator {
protected static Prefs prefs = GBApplication.getPrefs();
private static final Logger LOG = LoggerFactory.getLogger(MakibesHR3Coordinator.class);
public static byte getTimeMode(String address) {
String tmode = prefs.getString(MakibesHR3Constants.PREF_TIMEFORMAT, getContext().getString(R.string.p_timeformat_24h));
public static byte getTimeMode(String deviceAddress) {
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress);
LoggerFactory.getLogger(MakibesHR3Coordinator.class).debug("tmode is " + tmode);
String tmode = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, getContext().getString(R.string.p_timeformat_24h));
if(tmode.equals(getContext().getString(R.string.p_timeformat_24h))) {
LOG.debug("tmode is " + tmode);
if (getContext().getString(R.string.p_timeformat_24h).equals(tmode)) {
return MakibesHR3Constants.ARG_SET_TIMEMODE_24H;
}else{
} else {
return MakibesHR3Constants.ARG_SET_TIMEMODE_12H;
}
}
@ -179,4 +172,10 @@ public class MakibesHR3Coordinator extends AbstractDeviceCoordinator {
return null;
}
@Override
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
return new int[]{
R.xml.devicesettings_timeformat
};
}
}

View File

@ -17,14 +17,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.miband;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.Version;
public final class MiBandConst {
private static final Logger LOG = LoggerFactory.getLogger(MiBandConst.class);
public static final String PREF_USER_ALIAS = "mi_user_alias";
public static final String PREF_MIBAND_WEARSIDE = "mi_wearside";

View File

@ -8,8 +8,6 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.devices.makibeshr3.MakibesHR3Constants;
@ -22,10 +20,8 @@ import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.btle.Transaction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
@ -33,7 +29,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport {
private static final Logger LOG = LoggerFactory.getLogger(MakibesHR3DeviceSupport.class);
public BluetoothGattCharacteristic ctrlCharacteristic = null;
private BluetoothGattCharacteristic ctrlCharacteristic = null;
public MakibesHR3DeviceSupport() {
super(LOG);
@ -370,16 +366,12 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport {
private byte[] craftData(byte command, byte[] data) {
byte[] result = new byte[MakibesHR3Constants.DATA_TEMPLATE.length + data.length];
for (int i = 0; i < MakibesHR3Constants.DATA_TEMPLATE.length; ++i) {
result[i] = MakibesHR3Constants.DATA_TEMPLATE[i];
}
System.arraycopy(MakibesHR3Constants.DATA_TEMPLATE, 0, result, 0, MakibesHR3Constants.DATA_TEMPLATE.length);
result[MakibesHR3Constants.DATA_ARGUMENT_COUNT_INDEX] = (byte) (data.length + 3);
result[MakibesHR3Constants.DATA_COMMAND_INDEX] = command;
for (int i = 0; i < data.length; ++i) {
result[MakibesHR3Constants.DATA_ARGUMENTS_INDEX + i] = data[i];
}
System.arraycopy(data, 0, result, 6, data.length);
return result;
}
@ -423,9 +415,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport {
byte[] segment = new byte[segmentLength];
for (int j = 0; j < segmentLength; ++j) {
segment[j] = indexedData[segmentStart + j];
}
System.arraycopy(indexedData, segmentStart, segment, 0, segmentLength);
builder.write(characteristic, segment);
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:defaultValue="24h"
android:entries="@array/pref_timeformat_entries"
android:entryValues="@array/pref_timeformat_values"
android:icon="@drawable/ic_access_time"
android:key="timeformat"
android:summary="%s"
android:title="@string/pref_title_timeformat" />
</androidx.preference.PreferenceScreen>

View File

@ -587,26 +587,6 @@
</PreferenceScreen>
<PreferenceScreen
android:icon="@drawable/ic_device_hplus"
android:key="pref_key_hplus"
android:title="@string/preferences_makibes_hr3_settings">
<PreferenceCategory
android:key="pref_category_makibes_hr3_general"
android:title="@string/pref_header_general">
<ListPreference
android:defaultValue="24h"
android:entries="@array/pref_timeformat_entries"
android:entryValues="@array/pref_timeformat_values"
android:key="makibes_hr3_timeformat"
android:title="@string/pref_title_timeformat"
android:summary="%s" />
</PreferenceCategory>
</PreferenceScreen>
<PreferenceScreen
android:icon="@drawable/ic_device_h30_h10"
android:key="pref_key_id115"