1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-08-24 16:21:16 +02:00

Amazfit Bip: allow enabling shortcuts (weather, Alipay)

This commit is contained in:
Andreas Shimokawa 2018-05-15 23:12:18 +02:00
parent e6748c34fc
commit 3b25181a32
5 changed files with 44 additions and 7 deletions

View File

@ -398,13 +398,18 @@ public class SettingsActivity extends AbstractSettingsActivity {
try {
return AndroidUtils.getFilePath(getApplicationContext(), uri);
} catch (IllegalArgumentException e) {
Cursor cursor = getContentResolver().query(
uri,
new String[] { DocumentsContract.Document.COLUMN_DISPLAY_NAME },
null, null, null, null
);
if (cursor != null && cursor.moveToFirst()) {
return cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME));
try {
Cursor cursor = getContentResolver().query(
uri,
new String[]{DocumentsContract.Document.COLUMN_DISPLAY_NAME},
null, null, null, null
);
if (cursor != null && cursor.moveToFirst()) {
return cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME));
}
}
catch (Exception fdfsdfds) {
LOG.warn("fuck");
}
}
return "";

View File

@ -150,6 +150,9 @@ public class AmazfitBipSupport extends MiBand2Support {
LOG.info("Setting display items to " + (pages == null ? "none" : pages));
byte[] command = AmazfitBipService.COMMAND_CHANGE_SCREENS.clone();
boolean shortcut_weather = false;
boolean shortcut_alipay = false;
if (pages != null) {
if (pages.contains("status")) {
command[1] |= 0x02;
@ -175,11 +178,32 @@ public class AmazfitBipSupport extends MiBand2Support {
if (pages.contains("alipay")) {
command[2] |= 0x01;
}
if (pages.contains("shortcut_weather")) {
shortcut_weather = true;
}
if (pages.contains("shortcut_alipay")) {
shortcut_alipay = true;
}
}
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
setShortcuts(builder, shortcut_weather, shortcut_alipay);
return this;
}
private void setShortcuts(TransactionBuilder builder, boolean weather, boolean alipay) {
LOG.info("Setting shortcuts: weather=" + weather + " alipay=" + alipay);
// Basically a hack to put weather first always, if alipay is the only enabled one
// there are actually two alipays set but the second one disabled.... :P
byte[] command = new byte[]{0x10,
(byte) ((alipay || weather) ? 0x80 : 0x00), (byte) (weather ? 0x02 : 0x01),
(byte) ((alipay && weather) ? 0x81 : 0x01), 0x01,
};
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
}
@Override
public void onSendWeather(WeatherSpec weatherSpec) {
if (gbDevice.getFirmwareVersion() == null) {

View File

@ -184,6 +184,8 @@
</string-array>
<string-array name="pref_bip_display_items">
<item>@string/menuitem_shortcut_alipay</item>
<item>@string/menuitem_shortcut_weather</item>
<item>@string/menuitem_status</item>
<item>@string/menuitem_activity</item>
<item>@string/menuitem_weather</item>
@ -195,6 +197,8 @@
</string-array>
<string-array name="pref_bip_display_items_values">
<item>@string/p_menuitem_shortcut_alipay</item>
<item>@string/p_menuitem_shortcut_weather</item>
<item>@string/p_menuitem_status</item>
<item>@string/p_menuitem_activity</item>
<item>@string/p_menuitem_weather</item>

View File

@ -558,6 +558,8 @@
<string name="notification_channel_name">Gadgetbridge notifications</string>
<!-- Menus on the smart device -->
<string name="menuitem_shortcut_alipay">Alipay (Shortcut)</string>
<string name="menuitem_shortcut_weather">Weather (Shortcut)</string>
<string name="menuitem_status">Status</string>
<string name="menuitem_activity">Activity</string>
<string name="menuitem_weather">Weather</string>

View File

@ -19,6 +19,8 @@
<item name="p_heart_rate" type="string">heart_rate</item>
<item name="p_battery" type="string">battery</item>
<item name="p_menuitem_shortcut_alipay" type="string">shortcut_alipay</item>
<item name="p_menuitem_shortcut_weather" type="string">shortcut_weather</item>
<item name="p_menuitem_status" type="string">status</item>
<item name="p_menuitem_activity" type="string">activity</item>
<item name="p_menuitem_weather" type="string">weather</item>