1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 10:05:49 +01:00

Mi2: configurable time format (12h/24h)

Fixes #573
This commit is contained in:
cpfeiffer 2017-03-03 22:14:28 +01:00
parent 72801af0e7
commit 82ea5702c5
9 changed files with 70 additions and 2 deletions

View File

@ -96,6 +96,15 @@ public class MiBand2Coordinator extends MiBandCoordinator {
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() {
Prefs prefs = GBApplication.getPrefs();
return prefs.getBoolean(MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT, true);

View File

@ -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_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;

View File

@ -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_DEVICE_TIME_OFFSET_HOURS = "mi_device_time_offset_hours";
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_MIBAND_SETUP_BT_PAIRING = "mi_setup_bt_pairing";

View File

@ -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.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_TIMEFORMAT;
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_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);
activateDisplayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override

View File

@ -0,0 +1,6 @@
package nodomain.freeyourgadget.gadgetbridge.devices.miband;
public enum TimeFormat {
FORMAT_12_HOURS,
FORMAT_24_HOURS
}

View File

@ -7,7 +7,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v4.content.LocalBroadcastManager;
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.MiBandDateConverter;
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.entities.DaoSession;
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.NotificationUtils;
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_COUNT;
@ -1269,6 +1268,9 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
case MiBandConst.PREF_MI2_DATEFORMAT:
setDateDisplay(builder);
break;
case MiBandConst.PREF_MI2_TIMEFORMAT:
setTimeFormat(builder);
break;
case MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT:
setActivateDisplayOnLiftWrist(builder);
break;
@ -1312,6 +1314,20 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
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) {
boolean enable = MiBand2Coordinator.getActivateDisplayOnLiftWrist();
LOG.info("Setting activate display on lift wrist to " + enable);
@ -1328,6 +1344,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
enableFurtherNotifications(builder, true);
requestBatteryInfo(builder);
setDateDisplay(builder);
setTimeFormat(builder);
setWearLocation(builder);
setFitnessGoal(builder);
setActivateDisplayOnLiftWrist(builder);

View File

@ -135,6 +135,15 @@
<item>@string/p_dateformat_datetime</item>
</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">
<item>@string/unit_metric</item>
<item>@string/unit_imperial</item>

View File

@ -396,4 +396,5 @@
<string name="pref_screen_notification_profile_alarm_clock">Alarm Clock</string>
<string name="StringUtils_sender"> (%1$s)</string>
<string name="find_device_you_found_it">You found it!</string>
<string name="miband2_prefs_timeformat">Mi2: Time Format</string>
</resources>

View File

@ -56,6 +56,14 @@
android:title="@string/miband2_prefs_dateformat"
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>