mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 10:35:50 +01:00
parent
72801af0e7
commit
82ea5702c5
@ -96,6 +96,15 @@ public class MiBand2Coordinator extends MiBandCoordinator {
|
|||||||
return DateTimeDisplay.DATE_TIME;
|
return DateTimeDisplay.DATE_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TimeFormat getTimeFormat(Context context) throws IllegalArgumentException {
|
||||||
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
|
String timeFormat = context.getString(R.string.p_timeformat_am_pm);
|
||||||
|
if (timeFormat.equals(prefs.getString(MiBandConst.PREF_MI2_TIMEFORMAT, timeFormat))) {
|
||||||
|
return TimeFormat.FORMAT_12_HOURS;
|
||||||
|
}
|
||||||
|
return TimeFormat.FORMAT_24_HOURS;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean getActivateDisplayOnLiftWrist() {
|
public static boolean getActivateDisplayOnLiftWrist() {
|
||||||
Prefs prefs = GBApplication.getPrefs();
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
return prefs.getBoolean(MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT, true);
|
return prefs.getBoolean(MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT, true);
|
||||||
|
@ -98,6 +98,8 @@ public class MiBand2Service {
|
|||||||
|
|
||||||
public static final byte[] DATEFORMAT_DATE_TIME = new byte[] { COMMAND_DATEFORMAT, 0x0a, 0x0, 0x03 };
|
public static final byte[] DATEFORMAT_DATE_TIME = new byte[] { COMMAND_DATEFORMAT, 0x0a, 0x0, 0x03 };
|
||||||
public static final byte[] DATEFORMAT_TIME = new byte[] { COMMAND_DATEFORMAT, 0x0a, 0x0, 0x0 };
|
public static final byte[] DATEFORMAT_TIME = new byte[] { COMMAND_DATEFORMAT, 0x0a, 0x0, 0x0 };
|
||||||
|
public static final byte[] DATEFORMAT_TIME_12_HOURS = new byte[] { COMMAND_DATEFORMAT, 0x02, 0x0, 0x0 };
|
||||||
|
public static final byte[] DATEFORMAT_TIME_24_HOURS = new byte[] { COMMAND_DATEFORMAT, 0x02, 0x0, 0x1 };
|
||||||
|
|
||||||
public static final byte RESPONSE = 0x10;
|
public static final byte RESPONSE = 0x10;
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ 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_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_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_DATEFORMAT = "mi2_dateformat";
|
||||||
|
public static final String PREF_MI2_TIMEFORMAT = "mi2_timeformat";
|
||||||
public static final String PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT = "mi2_activate_display_on_lift_wrist";
|
public static final String PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT = "mi2_activate_display_on_lift_wrist";
|
||||||
public static final String PREF_MIBAND_SETUP_BT_PAIRING = "mi_setup_bt_pairing";
|
public static final String PREF_MIBAND_SETUP_BT_PAIRING = "mi_setup_bt_pairing";
|
||||||
|
|
||||||
|
@ -21,6 +21,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.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_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_DATEFORMAT;
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_TIMEFORMAT;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ADDRESS;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ADDRESS;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_FITNESS_GOAL;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_FITNESS_GOAL;
|
||||||
@ -63,6 +64,20 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final Preference setTimeFormat = findPreference(PREF_MI2_TIMEFORMAT);
|
||||||
|
setTimeFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||||
|
invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
GBApplication.deviceService().onSendConfiguration(PREF_MI2_TIMEFORMAT);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
final Preference activateDisplayOnLift = findPreference(PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT);
|
final Preference activateDisplayOnLift = findPreference(PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT);
|
||||||
activateDisplayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
activateDisplayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
package nodomain.freeyourgadget.gadgetbridge.devices.miband;
|
||||||
|
|
||||||
|
public enum TimeFormat {
|
||||||
|
FORMAT_12_HOURS,
|
||||||
|
FORMAT_24_HOURS
|
||||||
|
}
|
@ -7,7 +7,6 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@ -39,6 +38,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandDateConverter;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandDateConverter;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.TimeFormat;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||||
@ -84,7 +84,6 @@ import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
|
||||||
|
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.DEFAULT_VALUE_FLASH_COLOUR;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.DEFAULT_VALUE_FLASH_COLOUR;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.DEFAULT_VALUE_FLASH_COUNT;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.DEFAULT_VALUE_FLASH_COUNT;
|
||||||
@ -1269,6 +1268,9 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
case MiBandConst.PREF_MI2_DATEFORMAT:
|
case MiBandConst.PREF_MI2_DATEFORMAT:
|
||||||
setDateDisplay(builder);
|
setDateDisplay(builder);
|
||||||
break;
|
break;
|
||||||
|
case MiBandConst.PREF_MI2_TIMEFORMAT:
|
||||||
|
setTimeFormat(builder);
|
||||||
|
break;
|
||||||
case MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT:
|
case MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT:
|
||||||
setActivateDisplayOnLiftWrist(builder);
|
setActivateDisplayOnLiftWrist(builder);
|
||||||
break;
|
break;
|
||||||
@ -1312,6 +1314,20 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MiBand2Support setTimeFormat(TransactionBuilder builder) {
|
||||||
|
TimeFormat timeFormat = MiBand2Coordinator.getTimeFormat(getContext());
|
||||||
|
LOG.info("Setting time format to " + timeFormat);
|
||||||
|
switch (timeFormat) {
|
||||||
|
case FORMAT_12_HOURS:
|
||||||
|
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand2Service.DATEFORMAT_TIME_12_HOURS);
|
||||||
|
break;
|
||||||
|
case FORMAT_24_HOURS:
|
||||||
|
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand2Service.DATEFORMAT_TIME_24_HOURS);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
private MiBand2Support setActivateDisplayOnLiftWrist(TransactionBuilder builder) {
|
private MiBand2Support setActivateDisplayOnLiftWrist(TransactionBuilder builder) {
|
||||||
boolean enable = MiBand2Coordinator.getActivateDisplayOnLiftWrist();
|
boolean enable = MiBand2Coordinator.getActivateDisplayOnLiftWrist();
|
||||||
LOG.info("Setting activate display on lift wrist to " + enable);
|
LOG.info("Setting activate display on lift wrist to " + enable);
|
||||||
@ -1328,6 +1344,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
enableFurtherNotifications(builder, true);
|
enableFurtherNotifications(builder, true);
|
||||||
requestBatteryInfo(builder);
|
requestBatteryInfo(builder);
|
||||||
setDateDisplay(builder);
|
setDateDisplay(builder);
|
||||||
|
setTimeFormat(builder);
|
||||||
setWearLocation(builder);
|
setWearLocation(builder);
|
||||||
setFitnessGoal(builder);
|
setFitnessGoal(builder);
|
||||||
setActivateDisplayOnLiftWrist(builder);
|
setActivateDisplayOnLiftWrist(builder);
|
||||||
|
@ -135,6 +135,15 @@
|
|||||||
<item>@string/p_dateformat_datetime</item>
|
<item>@string/p_dateformat_datetime</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="mi2_timeformats">
|
||||||
|
<item>@string/timeformat_24h</item>
|
||||||
|
<item>@string/timeformat_am_pm</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="mi2_timeformat_values">
|
||||||
|
<item>@string/p_timeformat_24h</item>
|
||||||
|
<item>@string/p_timeformat_am_pm</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="pref_entries_unit_system">
|
<string-array name="pref_entries_unit_system">
|
||||||
<item>@string/unit_metric</item>
|
<item>@string/unit_metric</item>
|
||||||
<item>@string/unit_imperial</item>
|
<item>@string/unit_imperial</item>
|
||||||
|
@ -396,4 +396,5 @@
|
|||||||
<string name="pref_screen_notification_profile_alarm_clock">Alarm Clock</string>
|
<string name="pref_screen_notification_profile_alarm_clock">Alarm Clock</string>
|
||||||
<string name="StringUtils_sender"> (%1$s)</string>
|
<string name="StringUtils_sender"> (%1$s)</string>
|
||||||
<string name="find_device_you_found_it">You found it!</string>
|
<string name="find_device_you_found_it">You found it!</string>
|
||||||
|
<string name="miband2_prefs_timeformat">Mi2: Time Format</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -56,6 +56,14 @@
|
|||||||
android:title="@string/miband2_prefs_dateformat"
|
android:title="@string/miband2_prefs_dateformat"
|
||||||
android:summary="%s" />
|
android:summary="%s" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="@string/p_timeformat_24h"
|
||||||
|
android:entries="@array/mi2_timeformats"
|
||||||
|
android:entryValues="@array/mi2_timeformat_values"
|
||||||
|
android:key="mi2_timeformat"
|
||||||
|
android:title="@string/miband2_prefs_timeformat"
|
||||||
|
android:summary="%s" />
|
||||||
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user