1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 18:45:49 +01:00

Huami: If no menu items were ever configured with Gadgetbridge use our default and do not disable everything on connect

Fixes #1853
This commit is contained in:
Andreas Shimokawa 2020-05-12 22:42:19 +02:00
parent c5e64d0def
commit e844f81056
6 changed files with 52 additions and 30 deletions

View File

@ -35,7 +35,6 @@ import java.text.SimpleDateFormat;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.Set;
import de.greenrobot.dao.query.QueryBuilder; import de.greenrobot.dao.query.QueryBuilder;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
@ -192,11 +191,6 @@ public abstract class HuamiCoordinator extends AbstractDeviceCoordinator {
return getTimePreference(HuamiConst.PREF_DISCONNECT_NOTIFICATION_END, "00:00", deviceAddress); return getTimePreference(HuamiConst.PREF_DISCONNECT_NOTIFICATION_END, "00:00", deviceAddress);
} }
public static Set<String> getDisplayItems(String deviceAddress) {
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress);
return prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, null);
}
public static boolean getUseCustomFont(String deviceAddress) { public static boolean getUseCustomFont(String deviceAddress) {
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress); SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress);
return prefs.getBoolean(HuamiConst.PREF_USE_CUSTOM_FONT, false); return prefs.getBoolean(HuamiConst.PREF_USE_CUSTOM_FONT, false);

View File

@ -22,6 +22,7 @@ import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
@ -37,9 +38,11 @@ import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
@ -2134,7 +2137,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
} }
protected HuamiSupport setDisplayItems(TransactionBuilder builder) { protected HuamiSupport setDisplayItems(TransactionBuilder builder) {
Set<String> pages = HuamiCoordinator.getDisplayItems(gbDevice.getAddress()); SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
Set<String> pages = prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(R.array.pref_mi2_display_items_default))));
LOG.info("Setting display items to " + (pages == null ? "none" : pages)); LOG.info("Setting display items to " + (pages == null ? "none" : pages));
byte[] data = HuamiService.COMMAND_CHANGE_SCREENS.clone(); byte[] data = HuamiService.COMMAND_CHANGE_SCREENS.clone();
@ -2155,9 +2160,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
if (pages.contains(MiBandConst.PREF_MI2_DISPLAY_ITEM_BATTERY)) { if (pages.contains(MiBandConst.PREF_MI2_DISPLAY_ITEM_BATTERY)) {
data[HuamiService.SCREEN_CHANGE_BYTE] |= HuamiService.DISPLAY_ITEM_BIT_BATTERY; data[HuamiService.SCREEN_CHANGE_BYTE] |= HuamiService.DISPLAY_ITEM_BIT_BATTERY;
} }
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), data);
} }
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), data);
return this; return this;
} }

View File

@ -18,15 +18,20 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip; package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipFWHelper;
@ -74,7 +79,9 @@ public class AmazfitBipSupport extends HuamiSupport {
return this; return this;
} }
Set<String> pages = HuamiCoordinator.getDisplayItems(gbDevice.getAddress()); SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
Set<String> pages = prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(R.array.pref_bip_display_items_default))));
LOG.info("Setting display items to " + (pages == null ? "none" : pages)); LOG.info("Setting display items to " + (pages == null ? "none" : pages));
byte[] command = AmazfitBipService.COMMAND_CHANGE_SCREENS.clone(); byte[] command = AmazfitBipService.COMMAND_CHANGE_SCREENS.clone();
@ -112,9 +119,9 @@ public class AmazfitBipSupport extends HuamiSupport {
if (pages.contains("shortcut_alipay")) { if (pages.contains("shortcut_alipay")) {
shortcut_alipay = true; shortcut_alipay = true;
} }
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
setShortcuts(builder, shortcut_weather, shortcut_alipay);
} }
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
setShortcuts(builder, shortcut_weather, shortcut_alipay);
return this; return this;
} }

View File

@ -17,15 +17,20 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitcor; package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitcor;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitcor.AmazfitCorFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitcor.AmazfitCorFWHelper;
@ -39,9 +44,10 @@ public class AmazfitCorSupport extends AmazfitBipSupport {
@Override @Override
protected AmazfitCorSupport setDisplayItems(TransactionBuilder builder) { protected AmazfitCorSupport setDisplayItems(TransactionBuilder builder) {
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
Set<String> pages = HuamiCoordinator.getDisplayItems(getDevice().getAddress()); Set<String> pages = prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(R.array.pref_cor_display_items_default))));
LOG.info("Setting display items to " + (pages == null ? "none" : pages)); LOG.info("Setting display items to " + (pages == null ? "none" : pages));
byte[] command = AmazfitCorService.COMMAND_CHANGE_SCREENS.clone(); byte[] command = AmazfitCorService.COMMAND_CHANGE_SCREENS.clone();
if (pages != null) { if (pages != null) {
@ -72,8 +78,9 @@ public class AmazfitCorSupport extends AmazfitBipSupport {
if (pages.contains("music")) { if (pages.contains("music")) {
command[2] |= 0x02; command[2] |= 0x02;
} }
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
} }
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
return this; return this;
} }

View File

@ -17,17 +17,21 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgts; package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgts;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts.AmazfitGTSFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts.AmazfitGTSFWHelper;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
@ -70,7 +74,8 @@ public class AmazfitGTSSupport extends AmazfitBipSupport {
return this; return this;
} }
Set<String> pages = HuamiCoordinator.getDisplayItems(gbDevice.getAddress()); SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
Set<String> pages = prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(R.array.pref_gts_display_items_default))));
LOG.info("Setting display items to " + (pages == null ? "none" : pages)); LOG.info("Setting display items to " + (pages == null ? "none" : pages));
byte[] command = new byte[]{ byte[] command = new byte[]{
0x1E, 0x1E,
@ -114,8 +119,8 @@ public class AmazfitGTSSupport extends AmazfitBipSupport {
pos += 4; pos += 4;
} }
} }
writeToChunked(builder, 2, command);
} }
writeToChunked(builder, 2, command);
return this; return this;
} }

View File

@ -17,6 +17,7 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband3; package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband3;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.widget.Toast; import android.widget.Toast;
@ -24,19 +25,22 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3Coordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3FWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3FWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3Service; import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3Service;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -52,7 +56,8 @@ public class MiBand3Support extends AmazfitBipSupport {
@Override @Override
protected MiBand3Support setDisplayItems(TransactionBuilder builder) { protected MiBand3Support setDisplayItems(TransactionBuilder builder) {
Set<String> pages = HuamiCoordinator.getDisplayItems(gbDevice.getAddress()); SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
Set<String> pages = prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(R.array.pref_miband3_display_items_default))));
LOG.info("Setting display items to " + (pages == null ? "none" : pages)); LOG.info("Setting display items to " + (pages == null ? "none" : pages));
byte[] command = MiBand3Service.COMMAND_CHANGE_SCREENS.clone(); byte[] command = MiBand3Service.COMMAND_CHANGE_SCREENS.clone();
@ -91,15 +96,14 @@ public class MiBand3Support extends AmazfitBipSupport {
command[2] |= 0x01; command[2] |= 0x01;
command[11] = pos++; command[11] = pos++;
} }
} for (int i = 4; i <= 11; i++) {
if (command[i] == 0) {
for (int i = 4; i <= 11; i++) { command[i] = pos++;
if (command[i] == 0) { }
command[i] = pos++;
} }
}
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), command); builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
}
return this; return this;
} }