1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 21:06:50 +01:00

HPlus: add device specific preferences and icon

This commit is contained in:
João Paulo Barraca 2017-02-06 01:33:15 +00:00
parent cc917e97a6
commit a3cc84c01d
16 changed files with 146 additions and 26 deletions

View File

@ -134,6 +134,14 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
deviceImageView.setImageResource(R.drawable.ic_device_lovetoy_disabled);
}
break;
case HPLUS:
case MAKIBESF68:
if( device.isConnected()) {
deviceImageView.setImageResource(R.drawable.ic_device_hplus);
} else {
deviceImageView.setImageResource(R.drawable.ic_device_hplus_disabled);
}
break;
default:
if (device.isConnected()) {
deviceImageView.setImageResource(R.drawable.ic_launcher);

View File

@ -14,6 +14,8 @@ public final class HPlusConstants {
public static final UUID UUID_CHARACTERISTIC_MEASURE = UUID.fromString("14702853-620a-3973-7c78-9cfff0876abd");
public static final UUID UUID_SERVICE_HP = UUID.fromString("14701820-620a-3973-7c78-9cfff0876abd");
public static final byte ARG_WRIST_LEFT = 0; //Guess...
public static final byte ARG_WRIST_RIGHT = 1; //Guess...
public static final byte ARG_LANGUAGE_CN = 1;
public static final byte ARG_LANGUAGE_EN = 2;
@ -104,15 +106,11 @@ public final class HPlusConstants {
public static final String PREF_HPLUS_SCREENTIME = "hplus_screentime";
public static final String PREF_HPLUS_ALLDAYHR = "hplus_alldayhr";
public static final String PREF_HPLUS_HR = "hplus_hr_enable";
public static final String PREF_HPLUS_UNIT = "hplus_unit";
public static final String PREF_HPLUS_TIMEMODE = "hplus_timemode";
public static final String PREF_HPLUS_TIMEFORMAT = "hplus_timeformat";
public static final String PREF_HPLUS_WRIST = "hplus_wrist";
public static final String PREF_HPLUS_SWALERT = "hplus_sw_alert";
public static final String PREF_HPLUS_ALERT_TIME = "hplus_alert_time";
public static final String PREF_HPLUS_SIT_START_TIME = "hplus_sit_start_time";
public static final String PREF_HPLUS_SIT_END_TIME = "hplus_sit_end_time";
public static final String PREF_HPLUS_LANGUAGE = "hplus_language";
public static final Map<Character, Byte> transliterateMap = new HashMap<Character, Byte>(){
{

View File

@ -36,6 +36,9 @@ import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getContext;
public class HPlusCoordinator extends AbstractDeviceCoordinator {
protected static final Logger LOG = LoggerFactory.getLogger(HPlusCoordinator.class);
@ -144,16 +147,41 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
}
public static byte getLanguage(String address) {
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_LANGUAGE + "_" + address, HPlusConstants.ARG_LANGUAGE_EN);
String language = prefs.getString("language", "default");
Locale locale;
if (language.equals("default")) {
locale = Locale.getDefault();
} else {
locale = new Locale(language);
}
if (locale.getLanguage().equals(new Locale("cn").getLanguage())){
return HPlusConstants.ARG_LANGUAGE_CN;
}else{
return HPlusConstants.ARG_LANGUAGE_EN;
}
}
public static byte getTimeMode(String address) {
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_TIMEMODE + "_" + address, HPlusConstants.ARG_TIMEMODE_24H);
String tmode = prefs.getString(HPlusConstants.PREF_HPLUS_TIMEFORMAT, getContext().getString(R.string.p_timeformat_24h));
if(tmode.equals(getContext().getString(R.string.p_timeformat_24h))) {
return HPlusConstants.ARG_TIMEMODE_24H;
}else{
return HPlusConstants.ARG_TIMEMODE_12H;
}
}
public static byte getUnit(String address) {
return (byte) prefs.getInt(HPlusConstants.PREF_HPLUS_UNIT + "_" + address, 0);
String units = prefs.getString(HPlusConstants.PREF_HPLUS_UNIT, getContext().getString(R.string.p_unit_metric));
if(units.equals(getContext().getString(R.string.p_unit_metric))){
return HPlusConstants.ARG_UNIT_METRIC;
}else{
return HPlusConstants.ARG_UNIT_IMPERIAL;
}
}
public static byte getUserWeight(String address) {
@ -190,15 +218,17 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
}
public static byte getScreenTime(String address) {
return (byte) (prefs.getInt(HPlusConstants.PREF_HPLUS_SCREENTIME + "_" + address, 5) & 0xFF);
return (byte) (prefs.getInt(HPlusConstants.PREF_HPLUS_SCREENTIME, 5) & 0xFF);
}
public static byte getAllDayHR(String address) {
return (byte) (prefs.getInt(HPlusConstants.PREF_HPLUS_ALLDAYHR + "_" + address, HPlusConstants.ARG_HEARTRATE_ALLDAY_ON) & 0xFF);
}
Boolean value = (prefs.getBoolean(HPlusConstants.PREF_HPLUS_ALLDAYHR, true));
public static byte getHRState(String address) {
return (byte) (prefs.getInt(HPlusConstants.PREF_HPLUS_HR + "_" + address, HPlusConstants.ARG_HEARTRATE_MEASURE_ON) & 0xFF);
if(value){
return HPlusConstants.ARG_HEARTRATE_ALLDAY_ON;
}else{
return HPlusConstants.ARG_HEARTRATE_ALLDAY_OFF;
}
}
public static byte getSocial(String address) {
@ -208,15 +238,21 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
}
public static byte getUserWrist(String address) {
return (byte) (prefs.getInt(HPlusConstants.PREF_HPLUS_WRIST + "_" + address, 10) & 0xFF);
String value = prefs.getString(HPlusConstants.PREF_HPLUS_WRIST, getContext().getString(R.string.left));
if(value.equals(getContext().getString(R.string.left))){
return HPlusConstants.ARG_WRIST_LEFT;
}else{
return HPlusConstants.ARG_WRIST_RIGHT;
}
}
public static int getSITStartTime(String address) {
return prefs.getInt(HPlusConstants.PREF_HPLUS_SIT_START_TIME + "_" + address, 0);
return prefs.getInt(HPlusConstants.PREF_HPLUS_SIT_START_TIME, 0);
}
public static int getSITEndTime(String address) {
return prefs.getInt(HPlusConstants.PREF_HPLUS_SIT_END_TIME + "_" + address, 0);
return prefs.getInt(HPlusConstants.PREF_HPLUS_SIT_END_TIME, 0);
}
}

View File

@ -172,6 +172,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport setTimeMode(TransactionBuilder transaction) {
byte value = HPlusCoordinator.getTimeMode(getDevice().getAddress());
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.CMD_SET_TIMEMODE,
value
@ -333,15 +334,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
private HPlusSupport setAllDayHeart(TransactionBuilder transaction) {
byte value = HPlusCoordinator.getHRState(getDevice().getAddress());
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.CMD_SET_HEARTRATE_STATE,
value
});
value = HPlusCoordinator.getAllDayHR(getDevice().getAddress());
byte value = HPlusCoordinator.getAllDayHR(getDevice().getAddress());
transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.CMD_SET_ALLDAY_HRM,
@ -481,7 +474,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
@Override
public void onEnableRealtimeSteps(boolean enable) {
onEnableRealtimeHeartRateMeasurement(enable);
}
@Override

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -122,4 +122,24 @@
<item>@string/p_dateformat_datetime</item>
</string-array>
<string-array name="pref_entries_unit_system">
<item>@string/unit_metric</item>
<item>@string/unit_imperial</item>
</string-array>
<string-array name="pref_values_unit_system">
<item>@string/p_unit_metric</item>
<item>@string/p_unit_imperial</item>
</string-array>
<string-array name="pref_timeformat_entries">
<item>@string/timeformat_24h</item>
<item>@string/timeformat_am_pm</item>
</string-array>
<string-array name="pref_timeformat_values">
<item>@string/p_timeformat_24h</item>
<item>@string/p_timeformat_am_pm</item>
</string-array>
</resources>

View File

@ -142,6 +142,13 @@
<string name="pref_title_pebble_reconnect_attempts">Reconnection Attempts</string>
//HPlus Preferences
<string name="pref_title_unit_system">Units</string>
<string name="pref_title_timeformat">Time format</string>
<string name="pref_title_screentime">Screen on duration</string>
<string name="prefs_title_all_day_heart_rate">All day heart rate measurement</string>
<string name="preferences_hplus_settings">HPlus/Makibes Settings</string>
<string name="not_connected">not connected</string>
<string name="connecting">connecting</string>
<string name="connected">connected</string>
@ -382,4 +389,11 @@
<string name="weather_notification_label">Make sure that this skin is enabled in the Weather Notification app to get weather information on your Pebble.\n\nNo configuration is needed here.\n\nYou can enable the system weather app of your Pebble from the app management.\n\nSupported watchfaces will show the weather automatically.</string>
<string name="pref_title_setup_bt_pairing">Enable Bluetooth pairing</string>
<string name="pref_summary_setup_bt_pairing">Deactivate this if you have trouble connecting</string>
<string name="unit_metric">Metric</string>
<string name="unit_imperial">Imperial</string>
<string name="timeformat_24h">24H</string>
<string name="timeformat_am_pm">AM/PM</string>
</resources>

View File

@ -12,4 +12,10 @@
<item name="p_dateformat_time" type="string">dateformat_time</item>
<item name="p_dateformat_datetime" type="string">dateformat_datetime</item>
<item name="p_unit_metric" type="string">metric</item>
<item name="p_unit_imperial" type="string">imperial</item>
<item name="p_timeformat_24h" type="string">24h</item>
<item name="p_timeformat_am_pm" type="string">am/pm</item>
</resources>

View File

@ -388,6 +388,51 @@
android:title="Emulator Port" />
</PreferenceCategory>
</PreferenceScreen>
<PreferenceScreen
android:icon="@drawable/ic_device_hplus"
android:key="pref_key_hplus"
android:title="@string/preferences_hplus_settings">
<PreferenceCategory
android:key="pref_category_hplus_general"
android:title="@string/pref_header_general">
<ListPreference
android:defaultValue="left"
android:entries="@array/wearside"
android:entryValues="@array/wearside_values"
android:key="hplus_wrist"
android:title="@string/miband_prefs_wearside"
android:summary="%s" />
<ListPreference
android:defaultValue="24h"
android:entries="@array/pref_timeformat_entries"
android:entryValues="@array/pref_timeformat_values"
android:key="hplus_timeformat"
android:title="@string/pref_title_timeformat"
android:summary="%s" />
<EditTextPreference
android:defaultValue="5"
android:key="hplus_screentime"
android:title="@string/pref_title_screentime"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="hplus_alldayhr"
android:title="@string/prefs_title_all_day_heart_rate" />
<ListPreference
android:defaultValue="metric"
android:entries="@array/pref_entries_unit_system"
android:entryValues="@array/pref_values_unit_system"
android:key="hplus_unit"
android:title="@string/pref_title_unit_system"
android:summary="%s" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory