Merge branch 'joserebelo-mi2-display-items'
This commit is contained in:
commit
18926e6bbd
|
@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
|
@ -117,6 +118,11 @@ public class MiBand2Coordinator extends MiBandCoordinator {
|
|||
return prefs.getBoolean(MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT, true);
|
||||
}
|
||||
|
||||
public static Set<String> getDisplayItems() {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
return prefs.getStringSet(MiBandConst.PREF_MI2_DISPLAY_ITEMS, null);
|
||||
}
|
||||
|
||||
public static boolean getRotateWristToSwitchInfo() {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
return prefs.getBoolean(MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO, false);
|
||||
|
|
|
@ -145,6 +145,19 @@ public class MiBand2Service {
|
|||
|
||||
public static final byte ICON_HIGH_PRIORITY = 0x7;
|
||||
|
||||
public static byte ENDPOINT_DISPLAY_ITEMS = 0x0a;
|
||||
|
||||
public static byte DISPLAY_ITEM_BIT_CLOCK = 0x01;
|
||||
public static byte DISPLAY_ITEM_BIT_STEPS = 0x02;
|
||||
public static byte DISPLAY_ITEM_BIT_DISTANCE = 0x04;
|
||||
public static byte DISPLAY_ITEM_BIT_CALORIES= 0x08;
|
||||
public static byte DISPLAY_ITEM_BIT_HEART_RATE = 0x10;
|
||||
public static byte DISPLAY_ITEM_BIT_BATTERY = 0x20;
|
||||
|
||||
// Second byte must be a bitwise OR combination of the above
|
||||
// The clock can't be disabled
|
||||
public static int SCREEN_CHANGE_BYTE = 1;
|
||||
public static final byte[] COMMAND_CHANGE_SCREENS = new byte[]{ENDPOINT_DISPLAY_ITEMS, DISPLAY_ITEM_BIT_CLOCK, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
|
||||
|
||||
public static byte ENDPOINT_DISPLAY = 0x06;
|
||||
|
||||
|
|
|
@ -35,6 +35,13 @@ public final class MiBandConst {
|
|||
public static final String PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION = "mi_hr_sleep_detection";
|
||||
public static final String PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS = "mi_device_time_offset_hours";
|
||||
public static final String PREF_MI2_DATEFORMAT = "mi2_dateformat";
|
||||
public static final String PREF_MI2_DISPLAY_ITEMS = "mi2_display_items";
|
||||
public static final String PREF_MI2_DISPLAY_ITEM_CLOCK = "clock";
|
||||
public static final String PREF_MI2_DISPLAY_ITEM_STEPS = "steps";
|
||||
public static final String PREF_MI2_DISPLAY_ITEM_DISTANCE = "distance";
|
||||
public static final String PREF_MI2_DISPLAY_ITEM_CALORIES = "calories";
|
||||
public static final String PREF_MI2_DISPLAY_ITEM_HEART_RATE = "heart_rate";
|
||||
public static final String PREF_MI2_DISPLAY_ITEM_BATTERY = "battery";
|
||||
public static final String PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT = "mi2_activate_display_on_lift_wrist";
|
||||
public static final String PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO = "mi2_rotate_wrist_to_switch_info";
|
||||
public static final String PREF_MI2_ENABLE_TEXT_NOTIFICATIONS = "mi2_enable_text_notifications";
|
||||
|
|
|
@ -39,6 +39,7 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.OR
|
|||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_INCOMING_CALL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DATEFORMAT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DISPLAY_ITEMS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ENABLE_TEXT_NOTIFICATIONS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ADDRESS;
|
||||
|
@ -81,6 +82,20 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
|||
}
|
||||
});
|
||||
|
||||
final Preference displayPages = findPreference(PREF_MI2_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;
|
||||
}
|
||||
});
|
||||
|
||||
final Preference activateDisplayOnLift = findPreference(PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT);
|
||||
activateDisplayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
|
|
|
@ -38,6 +38,7 @@ import java.util.ArrayList;
|
|||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -1078,6 +1079,9 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||
case MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT:
|
||||
setActivateDisplayOnLiftWrist(builder);
|
||||
break;
|
||||
case MiBandConst.PREF_MI2_DISPLAY_ITEMS:
|
||||
setDisplayItems(builder);
|
||||
break;
|
||||
case MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO:
|
||||
setRotateWristToSwitchInfo(builder);
|
||||
break;
|
||||
|
@ -1142,6 +1146,34 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||
return this;
|
||||
}
|
||||
|
||||
private MiBand2Support setDisplayItems(TransactionBuilder builder) {
|
||||
Set<String> pages = MiBand2Coordinator.getDisplayItems();
|
||||
LOG.info("Setting display items to " + (pages == null ? "none" : pages));
|
||||
|
||||
byte[] data = MiBand2Service.COMMAND_CHANGE_SCREENS.clone();
|
||||
|
||||
if (pages != null) {
|
||||
if (pages.contains(MiBandConst.PREF_MI2_DISPLAY_ITEM_STEPS)) {
|
||||
data[MiBand2Service.SCREEN_CHANGE_BYTE] |= MiBand2Service.DISPLAY_ITEM_BIT_STEPS;
|
||||
}
|
||||
if (pages.contains(MiBandConst.PREF_MI2_DISPLAY_ITEM_DISTANCE)) {
|
||||
data[MiBand2Service.SCREEN_CHANGE_BYTE] |= MiBand2Service.DISPLAY_ITEM_BIT_DISTANCE;
|
||||
}
|
||||
if (pages.contains(MiBandConst.PREF_MI2_DISPLAY_ITEM_CALORIES)) {
|
||||
data[MiBand2Service.SCREEN_CHANGE_BYTE] |= MiBand2Service.DISPLAY_ITEM_BIT_CALORIES;
|
||||
}
|
||||
if (pages.contains(MiBandConst.PREF_MI2_DISPLAY_ITEM_HEART_RATE)) {
|
||||
data[MiBand2Service.SCREEN_CHANGE_BYTE] |= MiBand2Service.DISPLAY_ITEM_BIT_HEART_RATE;
|
||||
}
|
||||
if (pages.contains(MiBandConst.PREF_MI2_DISPLAY_ITEM_BATTERY)) {
|
||||
data[MiBand2Service.SCREEN_CHANGE_BYTE] |= MiBand2Service.DISPLAY_ITEM_BIT_BATTERY;
|
||||
}
|
||||
}
|
||||
|
||||
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), data);
|
||||
return this;
|
||||
}
|
||||
|
||||
private MiBand2Support setRotateWristToSwitchInfo(TransactionBuilder builder) {
|
||||
boolean enable = MiBand2Coordinator.getRotateWristToSwitchInfo();
|
||||
LOG.info("Setting rotate wrist to cycle info to " + enable);
|
||||
|
@ -1161,6 +1193,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||
setTimeFormat(builder);
|
||||
setWearLocation(builder);
|
||||
setFitnessGoal(builder);
|
||||
setDisplayItems(builder);
|
||||
setRotateWristToSwitchInfo(builder);
|
||||
setActivateDisplayOnLiftWrist(builder);
|
||||
setHeartrateSleepSupport(builder);
|
||||
|
|
|
@ -270,6 +270,9 @@
|
|||
<string name="chart_steps">Passos</string>
|
||||
<string name="calories">Calorias</string>
|
||||
<string name="distance">Distância</string>
|
||||
<string name="clock">Relógio</string>
|
||||
<string name="heart_rate">Ritmo Cardíaco</string>
|
||||
<string name="battery">Bateria</string>
|
||||
<string name="liveactivity_live_activity">Atividade em tempo real</string>
|
||||
<string name="weeksteps_today_steps_description">Passos hoje, objetivo: %1$s</string>
|
||||
<string name="pref_title_dont_ack_transfer">Não confirmar a transferência de dados de atividade</string>
|
||||
|
@ -297,6 +300,8 @@
|
|||
<string name="miband2_prefs_dateformat">Mi2: Formato da Data</string>
|
||||
<string name="dateformat_time">Hora</string>
|
||||
<string name="dateformat_date_time"><![CDATA[Hora & Data]]></string>
|
||||
<string name="mi2_prefs_display_items">Items do ecrã</string>
|
||||
<string name="mi2_prefs_display_items_summary">Escolher os items a mostrar no ecrã</string>
|
||||
<string name="mi2_prefs_activate_display_on_lift">Ativar ecrã do dispositivo quando o levantar</string>
|
||||
<string name="mi2_prefs_rotate_wrist_to_switch_info">Rodar o pulso para mudar de ecrã</string>
|
||||
<string name="FetchActivityOperation_about_to_transfer_since">Prestes a transferir dados desde %1$s</string>
|
||||
|
|
|
@ -135,6 +135,28 @@
|
|||
<item>@string/p_dateformat_datetime</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_mi2_display_items">
|
||||
<item>@string/chart_steps</item>
|
||||
<item>@string/distance</item>
|
||||
<item>@string/calories</item>
|
||||
<item>@string/heart_rate</item>
|
||||
<item>@string/battery</item>
|
||||
</string-array>
|
||||
<string-array name="pref_mi2_display_items_values">
|
||||
<item>@string/p_steps</item>
|
||||
<item>@string/p_distance</item>
|
||||
<item>@string/p_calories</item>
|
||||
<item>@string/p_heart_rate</item>
|
||||
<item>@string/p_battery</item>
|
||||
</string-array>
|
||||
<string-array name="pref_mi2_display_items_default">
|
||||
<item>@string/p_steps</item>
|
||||
<item>@string/p_distance</item>
|
||||
<item>@string/p_calories</item>
|
||||
<item>@string/p_heart_rate</item>
|
||||
<item>@string/p_battery</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_entries_unit_system">
|
||||
<item>@string/unit_metric</item>
|
||||
<item>@string/unit_imperial</item>
|
||||
|
|
|
@ -315,6 +315,9 @@
|
|||
<string name="chart_steps">Steps</string>
|
||||
<string name="calories">Calories</string>
|
||||
<string name="distance">Distance</string>
|
||||
<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>
|
||||
|
@ -343,6 +346,8 @@
|
|||
<string name="miband2_prefs_dateformat">Mi2: Date Format</string>
|
||||
<string name="dateformat_time">Time</string>
|
||||
<string name="dateformat_date_time"><![CDATA[Time & Date]]></string>
|
||||
<string name="mi2_prefs_display_items">Display items</string>
|
||||
<string name="mi2_prefs_display_items_summary">Choose the items displayed on the band screen</string>
|
||||
<string name="mi2_prefs_activate_display_on_lift">Activate display upon lift</string>
|
||||
<string name="mi2_prefs_rotate_wrist_to_switch_info">Rotate wrist to switch info</string>
|
||||
<string name="FetchActivityOperation_about_to_transfer_since">About to transfer data since %1$s</string>
|
||||
|
|
|
@ -12,6 +12,13 @@
|
|||
<item name="p_dateformat_time" type="string">dateformat_time</item>
|
||||
<item name="p_dateformat_datetime" type="string">dateformat_datetime</item>
|
||||
|
||||
<item name="p_clock" type="string">clock</item>
|
||||
<item name="p_steps" type="string">steps</item>
|
||||
<item name="p_distance" type="string">distance</item>
|
||||
<item name="p_calories" type="string">calories</item>
|
||||
<item name="p_heart_rate" type="string">heart_rate</item>
|
||||
<item name="p_battery" type="string">battery</item>
|
||||
|
||||
<item name="p_unit_metric" type="string">metric</item>
|
||||
<item name="p_unit_imperial" type="string">imperial</item>
|
||||
|
||||
|
|
|
@ -43,6 +43,15 @@
|
|||
android:maxLength="2"
|
||||
android:title="@string/miband_prefs_device_time_offset_hours" />
|
||||
|
||||
<MultiSelectListPreference
|
||||
android:dialogTitle="@string/mi2_prefs_display_items"
|
||||
android:defaultValue="@array/pref_mi2_display_items_default"
|
||||
android:entries="@array/pref_mi2_display_items"
|
||||
android:entryValues="@array/pref_mi2_display_items_values"
|
||||
android:key="mi2_display_items"
|
||||
android:summary="@string/mi2_prefs_display_items_summary"
|
||||
android:title="@string/mi2_prefs_display_items"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="mi2_activate_display_on_lift_wrist"
|
||||
|
|
Loading…
Reference in New Issue