1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 04:46:51 +01:00

Mi2: follow 12h/24h system configuration

=> Remove custom preference option, #573
This commit is contained in:
cpfeiffer 2017-03-03 22:32:54 +01:00
parent 82ea5702c5
commit 09967b2006
7 changed files with 8 additions and 64 deletions

View File

@ -96,15 +96,6 @@ 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

@ -18,7 +18,6 @@ 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,13 +21,11 @@ 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;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_SETUP_BT_PAIRING;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_ALIAS;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefKey;
@ -64,20 +62,6 @@ 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

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

View File

@ -8,6 +8,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.support.v4.content.LocalBroadcastManager;
import android.text.format.DateFormat;
import android.widget.Toast;
import org.apache.commons.lang3.ArrayUtils;
@ -38,7 +39,6 @@ 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;
@ -1261,16 +1261,13 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
@Override
public void onSendConfiguration(String config) {
TransactionBuilder builder = null;
TransactionBuilder builder;
try {
builder = performInitialized("Sending configuration for option: " + config);
switch (config) {
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;
@ -1315,15 +1312,12 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
}
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;
boolean is24Format = DateFormat.is24HourFormat(getContext());
LOG.info("Setting 24h time format to " + is24Format);
if (is24Format) {
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand2Service.DATEFORMAT_TIME_24_HOURS);
} else {
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand2Service.DATEFORMAT_TIME_12_HOURS);
}
return this;
}

View File

@ -135,15 +135,6 @@
<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

@ -56,15 +56,6 @@
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>
<PreferenceCategory