mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-25 08:40:43 +02:00
Mi Band 3: Band screen unlock
This commit is contained in:
parent
b671289a49
commit
338251597b
@ -63,6 +63,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
|||||||
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_DISPLAY_ITEMS;
|
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_ENABLE_TEXT_NOTIFICATIONS;
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI3_BAND_SCREEN_UNLOCK;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_HEIGHT_CM;
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_HEIGHT_CM;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_SLEEP_DURATION;
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_SLEEP_DURATION;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_STEPS_GOAL;
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_STEPS_GOAL;
|
||||||
@ -390,6 +391,21 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final Preference miBand3ScreenUnlock = findPreference(PREF_MI3_BAND_SCREEN_UNLOCK);
|
||||||
|
miBand3ScreenUnlock.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||||
|
invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
GBApplication.deviceService().onSendConfiguration(PREF_MI3_BAND_SCREEN_UNLOCK);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
final Preference miBand3DisplayItems = findPreference("miband3_display_items");
|
final Preference miBand3DisplayItems = findPreference("miband3_display_items");
|
||||||
miBand3DisplayItems.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
miBand3DisplayItems.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@ -24,12 +24,15 @@ import android.support.annotation.NonNull;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
public class MiBand3Coordinator extends HuamiCoordinator {
|
public class MiBand3Coordinator extends HuamiCoordinator {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(MiBand3Coordinator.class);
|
private static final Logger LOG = LoggerFactory.getLogger(MiBand3Coordinator.class);
|
||||||
@ -70,4 +73,9 @@ public class MiBand3Coordinator extends HuamiCoordinator {
|
|||||||
public boolean supportsWeather() {
|
public boolean supportsWeather() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean getBandScreenUnlock() {
|
||||||
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
|
return prefs.getBoolean(MiBandConst.PREF_MI3_BAND_SCREEN_UNLOCK, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,11 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3;
|
package nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3;
|
||||||
|
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService.DISPLAY_ITEM_BIT_CLOCK;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService.DISPLAY_ITEM_BIT_CLOCK;
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService.ENDPOINT_DISPLAY;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService.ENDPOINT_DISPLAY_ITEMS;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService.ENDPOINT_DISPLAY_ITEMS;
|
||||||
|
|
||||||
public class MiBand3Service {
|
public class MiBand3Service {
|
||||||
public static final byte[] COMMAND_CHANGE_SCREENS = new byte[]{ENDPOINT_DISPLAY_ITEMS, DISPLAY_ITEM_BIT_CLOCK, 0x30, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
public static final byte[] COMMAND_CHANGE_SCREENS = new byte[]{ENDPOINT_DISPLAY_ITEMS, DISPLAY_ITEM_BIT_CLOCK, 0x30, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
|
||||||
|
public static final byte[] COMMAND_ENABLE_BAND_SCREEN_UNLOCK = new byte[]{ENDPOINT_DISPLAY, 0x16, 0x00, 0x01};
|
||||||
|
public static final byte[] COMMAND_DISABLE_BAND_SCREEN_UNLOCK = new byte[]{ENDPOINT_DISPLAY, 0x16, 0x00, 0x00};
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,7 @@ public final class MiBandConst {
|
|||||||
public static final String PREF_MI2_INACTIVITY_WARNINGS_DND_END = "mi2_inactivity_warnings_dnd_end";
|
public static final String PREF_MI2_INACTIVITY_WARNINGS_DND_END = "mi2_inactivity_warnings_dnd_end";
|
||||||
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";
|
||||||
|
|
||||||
|
public static final String PREF_MI3_BAND_SCREEN_UNLOCK = "mi3_band_screen_unlock";
|
||||||
|
|
||||||
public static final String ORIGIN_INCOMING_CALL = "incoming_call";
|
public static final String ORIGIN_INCOMING_CALL = "incoming_call";
|
||||||
public static final String ORIGIN_ALARM_CLOCK = "alarm_clock";
|
public static final String ORIGIN_ALARM_CLOCK = "alarm_clock";
|
||||||
|
@ -18,6 +18,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband3;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -28,10 +29,13 @@ import java.util.Set;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3Coordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3FWHelper;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3FWHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3Service;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3Service;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
public class MiBand3Support extends AmazfitBipSupport {
|
public class MiBand3Support extends AmazfitBipSupport {
|
||||||
@ -71,6 +75,45 @@ public class MiBand3Support extends AmazfitBipSupport {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSendConfiguration(String config) {
|
||||||
|
TransactionBuilder builder;
|
||||||
|
try {
|
||||||
|
builder = performInitialized("Sending configuration for option: " + config);
|
||||||
|
switch (config) {
|
||||||
|
case MiBandConst.PREF_MI3_BAND_SCREEN_UNLOCK:
|
||||||
|
setBandScreenUnlock(builder);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
super.onSendConfiguration(config);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
builder.queue(getQueue());
|
||||||
|
} catch (IOException e) {
|
||||||
|
GB.toast("Error setting configuration", Toast.LENGTH_LONG, GB.ERROR, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private MiBand3Support setBandScreenUnlock(TransactionBuilder builder) {
|
||||||
|
boolean enable = MiBand3Coordinator.getBandScreenUnlock();
|
||||||
|
LOG.info("Setting band screen unlock to " + enable);
|
||||||
|
|
||||||
|
if (enable) {
|
||||||
|
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand3Service.COMMAND_ENABLE_BAND_SCREEN_UNLOCK);
|
||||||
|
} else {
|
||||||
|
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand3Service.COMMAND_DISABLE_BAND_SCREEN_UNLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void phase2Initialize(TransactionBuilder builder) {
|
||||||
|
super.phase2Initialize(builder);
|
||||||
|
LOG.info("phase2Initialize...");
|
||||||
|
setBandScreenUnlock(builder);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException {
|
public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException {
|
||||||
return new MiBand3FWHelper(uri, context);
|
return new MiBand3FWHelper(uri, context);
|
||||||
|
@ -426,7 +426,8 @@
|
|||||||
<string name="mi2_prefs_inactivity_warnings_dnd_summary">Disable the inactivity warnings for a time interval</string>
|
<string name="mi2_prefs_inactivity_warnings_dnd_summary">Disable the inactivity warnings for a time interval</string>
|
||||||
<string name="mi2_prefs_do_not_disturb_start">Start time</string>
|
<string name="mi2_prefs_do_not_disturb_start">Start time</string>
|
||||||
<string name="mi2_prefs_do_not_disturb_end">End time</string>
|
<string name="mi2_prefs_do_not_disturb_end">End time</string>
|
||||||
|
<string name="mi3_prefs_band_screen_unlock">Band screen unlock"</string>
|
||||||
|
<string name="mi3_prefs_band_screen_unlock_summary">Swipe up to unlock the band\'s screen</string>
|
||||||
<string name="automatic">Automatic</string>
|
<string name="automatic">Automatic</string>
|
||||||
<string name="simplified_chinese">Simplified Chinese</string>
|
<string name="simplified_chinese">Simplified Chinese</string>
|
||||||
<string name="traditional_chinese">Traditional Chinese</string>
|
<string name="traditional_chinese">Traditional Chinese</string>
|
||||||
|
@ -208,10 +208,16 @@
|
|||||||
android:summary="@string/mi2_prefs_display_items_summary"
|
android:summary="@string/mi2_prefs_display_items_summary"
|
||||||
android:title="@string/mi2_prefs_display_items"/>
|
android:title="@string/mi2_prefs_display_items"/>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
<!--
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
android:icon="@drawable/ic_device_miband2"
|
android:icon="@drawable/ic_device_miband2"
|
||||||
android:title="@string/preferences_miband3_settings">
|
android:title="@string/preferences_miband3_settings">
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="mi3_band_screen_unlock"
|
||||||
|
android:summary="@string/mi3_prefs_band_screen_unlock_summary"
|
||||||
|
android:title="@string/mi3_prefs_band_screen_unlock" />
|
||||||
|
<!--
|
||||||
<MultiSelectListPreference
|
<MultiSelectListPreference
|
||||||
android:dialogTitle="@string/mi2_prefs_display_items"
|
android:dialogTitle="@string/mi2_prefs_display_items"
|
||||||
android:defaultValue="@array/pref_miband3_display_items_default"
|
android:defaultValue="@array/pref_miband3_display_items_default"
|
||||||
@ -220,8 +226,8 @@
|
|||||||
android:key="miband3_display_items"
|
android:key="miband3_display_items"
|
||||||
android:summary="@string/mi2_prefs_display_items_summary"
|
android:summary="@string/mi2_prefs_display_items_summary"
|
||||||
android:title="@string/mi2_prefs_display_items"/>
|
android:title="@string/mi2_prefs_display_items"/>
|
||||||
</PreferenceScreen>
|
|
||||||
-->
|
-->
|
||||||
|
</PreferenceScreen>
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
android:icon="@drawable/ic_device_hplus"
|
android:icon="@drawable/ic_device_hplus"
|
||||||
android:title="@string/preferences_amazfitbip_settings">
|
android:title="@string/preferences_amazfitbip_settings">
|
||||||
|
Loading…
Reference in New Issue
Block a user