Activate the display when lifting the wrist #323

Configurable, defaults to true
This commit is contained in:
cpfeiffer 2016-11-13 21:33:43 +01:00
parent 00a71f53b3
commit d8145a52f9
7 changed files with 54 additions and 3 deletions

View File

@ -67,4 +67,9 @@ public class MiBand2Coordinator extends MiBandCoordinator {
} }
return DateTimeDisplay.DATE_TIME; return DateTimeDisplay.DATE_TIME;
} }
public static boolean getActivateDisplayOnLiftWrist() {
Prefs prefs = GBApplication.getPrefs();
return prefs.getBoolean(MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT, true);
}
} }

View File

@ -297,6 +297,9 @@ public class MiBand2Service {
public static final byte[] COMMAND_ENABLE_HR_SLEEP_MEASUREMENT = new byte[]{0x15, 0x00, 0x01}; public static final byte[] COMMAND_ENABLE_HR_SLEEP_MEASUREMENT = new byte[]{0x15, 0x00, 0x01};
public static final byte[] COMMAND_DISABLE_HR_SLEEP_MEASUREMENT = new byte[]{0x15, 0x00, 0x00}; public static final byte[] COMMAND_DISABLE_HR_SLEEP_MEASUREMENT = new byte[]{0x15, 0x00, 0x00};
public static final byte[] COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{0x06, 0x05, 0x00, 0x01};
public static final byte[] COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{0x06, 0x05, 0x00, 0x00};
static { static {
MIBAND_DEBUG = new HashMap<>(); MIBAND_DEBUG = new HashMap<>();

View File

@ -18,8 +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_ACTIVATE_DISPLAY_ON_LIFT = "mi2_activate_display_on_lift_wrist";
public static final String PREF_TRY_SMS = "mi_try_sms";
public static final String ORIGIN_INCOMING_CALL = "incoming_call"; public static final String ORIGIN_INCOMING_CALL = "incoming_call";

View File

@ -18,6 +18,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
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_DATEFORMAT; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DATEFORMAT;
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;
@ -45,11 +46,12 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
return true; return true;
} }
}); });
final Preference setDateFormat = findPreference(PREF_MI2_DATEFORMAT); final Preference setDateFormat = findPreference(PREF_MI2_DATEFORMAT);
setDateFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { setDateFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newVal) { public boolean onPreferenceChange(Preference preference, Object newVal) {
getListView().post(new Runnable() { // delayed execution so that the preferences are applied first invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
GBApplication.deviceService().onSendConfiguration(PREF_MI2_DATEFORMAT); GBApplication.deviceService().onSendConfiguration(PREF_MI2_DATEFORMAT);
@ -58,6 +60,27 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
return true; return true;
} }
}); });
final Preference activateDisplayOnLift = findPreference(PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT);
activateDisplayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
invokeLater(new Runnable() {
@Override
public void run() {
GBApplication.deviceService().onSendConfiguration(PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT);
}
});
return true;
}
});
}
/**
* delayed execution so that the preferences are applied first
*/
private void invokeLater(Runnable runnable) {
getListView().post(runnable);
} }
@Override @Override

View File

@ -1168,6 +1168,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_ACTIVATE_DISPLAY_ON_LIFT:
setActivateDisplayOnLiftWrist(builder);
break;
} }
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
@ -1193,11 +1196,23 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return this; return this;
} }
private MiBand2Support setActivateDisplayOnLiftWrist(TransactionBuilder builder) {
boolean enable = MiBand2Coordinator.getActivateDisplayOnLiftWrist();
LOG.info("Setting activate display on lift wrist to " + enable);
if (enable) {
builder.write(getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC3), MiBand2Service.COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST);
} else {
builder.write(getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC3), MiBand2Service.COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST);
}
return this;
}
public void phase2Initialize(TransactionBuilder builder) { public void phase2Initialize(TransactionBuilder builder) {
LOG.info("phase2Initialize..."); LOG.info("phase2Initialize...");
enableFurtherNotifications(builder, true); enableFurtherNotifications(builder, true);
setDateDisplay(builder); setDateDisplay(builder);
setWearLocation(builder); setWearLocation(builder);
setActivateDisplayOnLiftWrist(builder);
setHeartrateSleepSupport(builder); setHeartrateSleepSupport(builder);
} }

View File

@ -348,4 +348,5 @@
<string name="miband2_prefs_dateformat">Mi2: Date Format</string> <string name="miband2_prefs_dateformat">Mi2: Date Format</string>
<string name="dateformat_time">Time</string> <string name="dateformat_time">Time</string>
<string name="dateformat_date_time"><![CDATA[Time & Date]]></string> <string name="dateformat_date_time"><![CDATA[Time & Date]]></string>
<string name="mi2_prefs_activate_display_on_lift">Activate display upon lift</string>
</resources> </resources>

View File

@ -43,6 +43,11 @@
android:maxLength="2" android:maxLength="2"
android:title="@string/miband_prefs_device_time_offset_hours" /> android:title="@string/miband_prefs_device_time_offset_hours" />
<CheckBoxPreference
android:defaultValue="true"
android:key="mi2_activate_display_on_lift_wrist"
android:title="@string/mi2_prefs_activate_display_on_lift" />
<ListPreference <ListPreference
android:defaultValue="@string/p_dateformat_time" android:defaultValue="@string/p_dateformat_time"
android:entries="@array/mi2_dateformats" android:entries="@array/mi2_dateformats"