mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 18:15:49 +01:00
Amazfit Bip: allow to set displayed menu item in firmware >=0.1.1.14
NOTE: - You will have to be connected while doing the changes in preferences (FIXME) - It might not work at all since I did not test after the latest changes :P
This commit is contained in:
parent
c036701722
commit
e1ef2455dc
@ -18,7 +18,6 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
@ -29,16 +28,13 @@ import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.widget.Toast;
|
||||
@ -47,7 +43,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -65,6 +60,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DISPLAY_ITEMS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_HEIGHT_CM;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_SLEEP_DURATION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_STEPS_GOAL;
|
||||
@ -330,6 +326,20 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
||||
}
|
||||
});
|
||||
|
||||
final Preference displayPages = findPreference("bip_display_items");
|
||||
displayPages.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||
invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GBApplication.deviceService().onSendConfiguration(PREF_MI2_DISPLAY_ITEMS);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// Get all receivers of Media Buttons
|
||||
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
|
||||
|
||||
|
@ -19,7 +19,9 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service.DISPLAY_ITEM_BIT_CLOCK;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service.ENDPOINT_DISPLAY;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service.ENDPOINT_DISPLAY_ITEMS;
|
||||
|
||||
public class AmazfitBipService {
|
||||
public static final UUID UUID_CHARACTERISTIC_WEATHER = UUID.fromString("0000000e-0000-3512-2118-0009af100700");
|
||||
@ -40,4 +42,6 @@ public class AmazfitBipService {
|
||||
public static final byte COMMAND_ACTIVITY_DATA_TYPE_SPORTS_DETAILS = 0x06;
|
||||
|
||||
public static final byte[] COMMAND_ACK_FIND_PHONE_IN_PROGRESS = new byte[]{ENDPOINT_DISPLAY, 0x14, 0x00, 0x00};
|
||||
|
||||
public static final byte[] COMMAND_CHANGE_SCREENS = new byte[]{ENDPOINT_DISPLAY_ITEMS, DISPLAY_ITEM_BIT_CLOCK, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.SimpleTimeZone;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -55,6 +56,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationS
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.FetchActivityOperation;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.FetchSportsSummaryOperation;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Version;
|
||||
|
||||
@ -129,14 +131,52 @@ public class AmazfitBipSupport extends MiBand2Support {
|
||||
|
||||
@Override
|
||||
protected AmazfitBipSupport setDisplayItems(TransactionBuilder builder) {
|
||||
/*
|
||||
LOG.info("Enabling all display items");
|
||||
if (gbDevice.getType() != DeviceType.AMAZFITBIP) {
|
||||
return this; // Disable for Cor for now
|
||||
}
|
||||
if (gbDevice.getFirmwareVersion() == null) {
|
||||
LOG.warn("Device not initialized yet, won't set menu items");
|
||||
return this;
|
||||
}
|
||||
|
||||
// This will brick the watch, don't enable it!
|
||||
byte[] data = new byte[]{ENDPOINT_DISPLAY_ITEMS, (byte) 0xff, 0x01, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
||||
Version version = new Version(gbDevice.getFirmwareVersion());
|
||||
if (version.compareTo(new Version("0.1.1.14")) <= 0) {
|
||||
LOG.warn("Won't set menu items since firmware is too low to be safe");
|
||||
return this;
|
||||
}
|
||||
|
||||
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), data);
|
||||
*/
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
Set<String> pages = prefs.getStringSet("bip_display_items", null);
|
||||
LOG.info("Setting display items to " + (pages == null ? "none" : pages));
|
||||
byte[] command = AmazfitBipService.COMMAND_CHANGE_SCREENS.clone();
|
||||
|
||||
if (pages != null) {
|
||||
if (pages.contains("status")) {
|
||||
command[1] |= 0x02;
|
||||
}
|
||||
if (pages.contains("activity")) {
|
||||
command[1] |= 0x04;
|
||||
}
|
||||
if (pages.contains("weather")) {
|
||||
command[1] |= 0x08;
|
||||
}
|
||||
if (pages.contains("alarm")) {
|
||||
command[1] |= 0x10;
|
||||
}
|
||||
if (pages.contains("timer")) {
|
||||
command[1] |= 0x20;
|
||||
}
|
||||
if (pages.contains("compass")) {
|
||||
command[1] |= 0x40;
|
||||
}
|
||||
if (pages.contains("settings")) {
|
||||
command[1] |= 0x80;
|
||||
}
|
||||
if (pages.contains("alipay")) {
|
||||
command[2] |= 0x01;
|
||||
}
|
||||
}
|
||||
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -145,7 +185,6 @@ public class AmazfitBipSupport extends MiBand2Support {
|
||||
if (gbDevice.getFirmwareVersion() == null) {
|
||||
LOG.warn("Device not initialized yet, so not sending weather info");
|
||||
return;
|
||||
|
||||
}
|
||||
boolean supportsConditionString = false;
|
||||
|
||||
|
@ -183,6 +183,37 @@
|
||||
<item>@string/p_battery</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_bip_display_items">
|
||||
<item>@string/menuitem_status</item>
|
||||
<item>@string/menuitem_activity</item>
|
||||
<item>@string/menuitem_weather</item>
|
||||
<item>@string/menuitem_alarm</item>
|
||||
<item>@string/menuitem_timer</item>
|
||||
<item>@string/menuitem_compass</item>
|
||||
<item>@string/menuitem_settings</item>
|
||||
<item>@string/menuitem_alipay</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_bip_display_items_values">
|
||||
<item>@string/p_menuitem_status</item>
|
||||
<item>@string/p_menuitem_activity</item>
|
||||
<item>@string/p_menuitem_weather</item>
|
||||
<item>@string/p_menuitem_alarm</item>
|
||||
<item>@string/p_menuitem_timer</item>
|
||||
<item>@string/p_menuitem_compass</item>
|
||||
<item>@string/p_menuitem_settings</item>
|
||||
<item>@string/p_menuitem_alipay</item>
|
||||
</string-array>
|
||||
<string-array name="pref_bip_display_items_default">
|
||||
<item>@string/p_menuitem_status</item>
|
||||
<item>@string/p_menuitem_activity</item>
|
||||
<item>@string/p_menuitem_weather</item>
|
||||
<item>@string/p_menuitem_alarm</item>
|
||||
<item>@string/p_menuitem_timer</item>
|
||||
<item>@string/p_menuitem_compass</item>
|
||||
<item>@string/p_menuitem_settings</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_entries_unit_system">
|
||||
<item>@string/unit_metric</item>
|
||||
<item>@string/unit_imperial</item>
|
||||
|
@ -344,6 +344,8 @@
|
||||
<string name="clock">Clock</string>
|
||||
<string name="heart_rate">Heart rate</string>
|
||||
<string name="battery">Battery</string>
|
||||
|
||||
|
||||
<string name="liveactivity_live_activity">Live activity</string>
|
||||
<string name="weeksteps_today_steps_description">Steps today, target: %1$s</string>
|
||||
<string name="pref_title_dont_ack_transfer">Do not ACK activity data transfer</string>
|
||||
@ -552,4 +554,14 @@
|
||||
|
||||
<string name="choose_auto_export_location">Choose export location</string>
|
||||
<string name="notification_channel_name">Gadgetbridge notifications</string>
|
||||
|
||||
<!-- Menus on the smart device -->
|
||||
<string name="menuitem_status">Status</string>
|
||||
<string name="menuitem_activity">Activity</string>
|
||||
<string name="menuitem_weather">Weather</string>
|
||||
<string name="menuitem_alarm">Alarm</string>
|
||||
<string name="menuitem_timer">Timer</string>
|
||||
<string name="menuitem_compass">Compass</string>
|
||||
<string name="menuitem_settings">Settings</string>
|
||||
<string name="menuitem_alipay">Alipay</string>
|
||||
</resources>
|
||||
|
@ -19,6 +19,15 @@
|
||||
<item name="p_heart_rate" type="string">heart_rate</item>
|
||||
<item name="p_battery" type="string">battery</item>
|
||||
|
||||
<item name="p_menuitem_status" type="string">status</item>
|
||||
<item name="p_menuitem_activity" type="string">activity</item>
|
||||
<item name="p_menuitem_weather" type="string">weather</item>
|
||||
<item name="p_menuitem_alarm" type="string">alarm</item>
|
||||
<item name="p_menuitem_timer" type="string">timer</item>
|
||||
<item name="p_menuitem_compass" type="string">compass</item>
|
||||
<item name="p_menuitem_settings" type="string">settings</item>
|
||||
<item name="p_menuitem_alipay" type="string">alipay</item>
|
||||
|
||||
<item name="p_off" type="string">off</item>
|
||||
<item name="p_on" type="string">on</item>
|
||||
<item name="p_automatic" type="string">automatic</item>
|
||||
|
@ -193,6 +193,14 @@
|
||||
android:key="amazfitbip_language"
|
||||
android:summary="%s"
|
||||
android:title="@string/pref_title_language" />
|
||||
<MultiSelectListPreference
|
||||
android:dialogTitle="@string/mi2_prefs_display_items"
|
||||
android:defaultValue="@array/pref_bip_display_items_default"
|
||||
android:entries="@array/pref_bip_display_items"
|
||||
android:entryValues="@array/pref_bip_display_items_values"
|
||||
android:key="bip_display_items"
|
||||
android:summary="@string/mi2_prefs_display_items_summary"
|
||||
android:title="@string/mi2_prefs_display_items"/>
|
||||
</PreferenceScreen>
|
||||
<PreferenceScreen
|
||||
android:icon="@drawable/ic_device_pebble"
|
||||
|
Loading…
Reference in New Issue
Block a user